• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 
16 #ifndef EXIDX_ENTRY_PARSER_H
17 #define EXIDX_ENTRY_PARSER_H
18 
19 #include <deque>
20 #include <memory>
21 #include <vector>
22 
23 #include "dfx_errors.h"
24 #include "dfx_memory.h"
25 #include "unwind_context.h"
26 #include "unwind_entry_parser.h"
27 
28 namespace OHOS {
29 namespace HiviewDFX {
30 struct ExidxContext {
31 public:
32     int32_t vsp = 0;
33     uint32_t transformedBits = 0;
34     std::vector<int32_t> regs;
35 
36     void Reset(size_t size = 0);
37     void Transform(uint32_t reg);
38     bool IsTransformed(uint32_t reg);
39     void AddUpVsp(int32_t imm);
40 };
41 
42 class ExidxEntryParser : public UnwindEntryParser {
43 public:
ExidxEntryParser(const std::shared_ptr<DfxMemory> & memory)44     explicit ExidxEntryParser(const std::shared_ptr<DfxMemory>& memory) : UnwindEntryParser(memory)
45     {
46         context_.Reset(DfxRegsQut::GetQutRegsSize());
47     }
48     ~ExidxEntryParser() override = default;
49 
50     bool Step(uintptr_t pc, const UnwindTableInfo& uti, std::shared_ptr<RegLocState> rs) override;
51 private:
52     struct DecodeTable {
53         uint8_t mask;
54         uint8_t result;
55         bool (ExidxEntryParser::*decoder)();
56     };
57     bool SearchEntry(uintptr_t pc, const UnwindTableInfo &uti, struct UnwindEntryInfo& uei) override;
58     bool Eval(uintptr_t entryOffset);
59     void FlushInstr();
60 
61     void LogRawData();
62     bool ExtractEntryData(uintptr_t entryOffset);
63     bool ExtractEntryTab(uintptr_t tabOffset);
64     bool ExtractEntryTabByPersonality(uintptr_t& tabOffset, uint32_t& data, uint8_t& tableCount);
65     bool GetOpCode();
66     bool Decode(DecodeTable decodeTable[], size_t size);
67     bool Decode00xxxxxx();
68     bool Decode01xxxxxx();
69     bool Decode1000iiiiiiiiiiii();
70     bool Decode1001nnnn();
71     bool Decode1010nnnn();
72     bool Decode10110000();
73     bool Decode101100010000iiii();
74     bool Decode10110010uleb128();
75     bool Decode10110011sssscccc();
76     bool Decode101101nn();
77     bool Decode10111nnn();
78     bool Decode11000110sssscccc();
79     bool Decode110001110000iiii();
80     bool Decode1100100nsssscccc();
81     bool Decode11001yyy();
82     bool Decode11000nnn();
83     bool Decode11010nnn();
84     bool Decode11xxxyyy();
85     bool DecodeSpare();
86     std::shared_ptr<RegLocState> rsState_;
87     ExidxContext context_;
88     std::deque<uint8_t> ops_;
89     uint8_t curOp_ = 0;
90     bool isPcSet_ = false;
91 };
92 } // namespace HiviewDFX
93 } // namespace OHOS
94 #endif
95