1800b99b8Sopenharmony_ci/* 2800b99b8Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License. 5800b99b8Sopenharmony_ci * You may obtain a copy of the License at 6800b99b8Sopenharmony_ci * 7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8800b99b8Sopenharmony_ci * 9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and 13800b99b8Sopenharmony_ci * limitations under the License. 14800b99b8Sopenharmony_ci */ 15800b99b8Sopenharmony_ci 16800b99b8Sopenharmony_ci#ifndef UNWIND_LOC_H 17800b99b8Sopenharmony_ci#define UNWIND_LOC_H 18800b99b8Sopenharmony_ci 19800b99b8Sopenharmony_ci#include <cinttypes> 20800b99b8Sopenharmony_ci#include <string> 21800b99b8Sopenharmony_ci#include <vector> 22800b99b8Sopenharmony_ci 23800b99b8Sopenharmony_ci#include "dfx_regs_qut.h" 24800b99b8Sopenharmony_ci#include "unwind_define.h" 25800b99b8Sopenharmony_ci 26800b99b8Sopenharmony_cinamespace OHOS { 27800b99b8Sopenharmony_cinamespace HiviewDFX { 28800b99b8Sopenharmony_cienum RegLocEnum : uint8_t { 29800b99b8Sopenharmony_ci REG_LOC_UNUSED = 0, // register has same value as in prev. frame 30800b99b8Sopenharmony_ci REG_LOC_UNDEFINED, // register isn't saved at all 31800b99b8Sopenharmony_ci REG_LOC_VAL_OFFSET, // register that is the value, cfa = cfa + off 32800b99b8Sopenharmony_ci REG_LOC_MEM_OFFSET, // register saved at CFA-relative address, cfa = [r14 + off], r14 = [cfa + off] 33800b99b8Sopenharmony_ci REG_LOC_REGISTER, // register saved in another register, cfa = [r14], pc = [lr] 34800b99b8Sopenharmony_ci REG_LOC_VAL_EXPRESSION, // register value is expression result, r11 = cfa + expr_result 35800b99b8Sopenharmony_ci REG_LOC_MEM_EXPRESSION, // register stored in expression result, r11 = [cfa + expr_result] 36800b99b8Sopenharmony_ci}; 37800b99b8Sopenharmony_ci 38800b99b8Sopenharmony_cistruct RegLoc { 39800b99b8Sopenharmony_ci RegLocEnum type = REG_LOC_UNUSED; /* see DWARF_LOC_* macros. */ 40800b99b8Sopenharmony_ci intptr_t val = 0; 41800b99b8Sopenharmony_ci}; 42800b99b8Sopenharmony_ci 43800b99b8Sopenharmony_ci// saved register status after running call frame instructions 44800b99b8Sopenharmony_ci// it should describe how register saved 45800b99b8Sopenharmony_cistruct RegLocState { 46800b99b8Sopenharmony_ci RegLocState() { locs.resize(DfxRegsQut::GetQutRegsSize()); } 47800b99b8Sopenharmony_ci explicit RegLocState(size_t locsSize) { locs.resize(locsSize); } 48800b99b8Sopenharmony_ci ~RegLocState() = default; 49800b99b8Sopenharmony_ci 50800b99b8Sopenharmony_ci uintptr_t pcStart = 0; 51800b99b8Sopenharmony_ci uintptr_t pcEnd = 0; 52800b99b8Sopenharmony_ci uint32_t cfaReg = 0; // cfa = [r14] 53800b99b8Sopenharmony_ci union { 54800b99b8Sopenharmony_ci int32_t cfaRegOffset = 0; // cfa = cfa + offset 55800b99b8Sopenharmony_ci uintptr_t cfaExprPtr; // cfa = expr 56800b99b8Sopenharmony_ci }; 57800b99b8Sopenharmony_ci bool returnAddressUndefined = false; 58800b99b8Sopenharmony_ci bool returnAddressSame = false; 59800b99b8Sopenharmony_ci uint16_t returnAddressRegister = 0; // lr 60800b99b8Sopenharmony_ci std::vector<RegLoc> locs; 61800b99b8Sopenharmony_ci}; 62800b99b8Sopenharmony_ci} // namespace HiviewDFX 63800b99b8Sopenharmony_ci} // namespace OHOS 64800b99b8Sopenharmony_ci#endif 65