• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef UNWIND_LOC_H
16 #define UNWIND_LOC_H
17 
18 #include <cinttypes>
19 #include <string>
20 #include <vector>
21 #include "dfx_regs_qut.h"
22 #include "unwind_define.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 enum RegLocEnum : uint8_t {
27     REG_LOC_UNUSED = 0,     // register has same value as in prev. frame
28     REG_LOC_UNDEFINED,      // register isn't saved at all
29     REG_LOC_VAL_OFFSET,     // register that is the value, cfa = cfa + off
30     REG_LOC_MEM_OFFSET,     // register saved at CFA-relative address, cfa = [r14 + off], r14 = [cfa + off]
31     REG_LOC_REGISTER,       // register saved in another register, cfa = [r14], pc = [lr]
32     REG_LOC_VAL_EXPRESSION, // register value is expression result, r11 = cfa + expr_result
33     REG_LOC_MEM_EXPRESSION, // register stored in expression result, r11 = [cfa + expr_result]
34 };
35 
36 struct RegLoc {
37     RegLocEnum type = REG_LOC_UNUSED; /* see DWARF_LOC_* macros. */
38     intptr_t val = 0;
39 };
40 
41 // saved register status after running call frame instructions
42 // it should describe how register saved
43 struct RegLocState {
RegLocStateRegLocState44     RegLocState() { locs.resize(DfxRegsQut::GetQutRegsSize()); }
RegLocStateRegLocState45     explicit RegLocState(size_t locsSize) { locs.resize(locsSize); }
46     ~RegLocState() = default;
47 
48     uintptr_t pcStart = 0;
49     uintptr_t pcEnd = 0;
50     uint32_t cfaReg = 0; // cfa = [r14]
51     union {
52         int32_t cfaRegOffset = 0; // cfa = cfa + offset
53         uintptr_t cfaExprPtr; // cfa = expr
54     };
55     bool isPcSet = false;
56     uintptr_t pseudoReg = 0;
57     std::vector<RegLoc> locs;
58 };
59 } // namespace HiviewDFX
60 } // namespace OHOS
61 #endif
62