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 DWARF_ENTRY_PARSER_H 16 #define DWARF_ENTRY_PARSER_H 17 18 #include <cinttypes> 19 #include <memory> 20 #include <unordered_map> 21 #include "dwarf_define.h" 22 #include "dfx_errors.h" 23 #include "dfx_memory.h" 24 #include "dfx_regs.h" 25 #include "unwind_context.h" 26 #include "unwind_entry_parser.h" 27 28 namespace OHOS { 29 namespace HiviewDFX { 30 class DwarfEntryParser : public UnwindEntryParser { 31 public: DwarfEntryParser(const std::shared_ptr<DfxMemory> & memory)32 explicit DwarfEntryParser(const std::shared_ptr<DfxMemory>& memory) : UnwindEntryParser(memory) {} 33 ~DwarfEntryParser() override = default; 34 bool Step(uintptr_t pc, const UnwindTableInfo& uti, std::shared_ptr<RegLocState> rs) override; 35 protected: 36 bool SearchEntry(uintptr_t pc, const UnwindTableInfo& uti, UnwindEntryInfo& uei) override; 37 bool ParseFde(uintptr_t fdeAddr, uintptr_t fdePtr, FrameDescEntry& fdeInfo); 38 bool ParseCie(uintptr_t cieAddr, uintptr_t ciePtr, CommonInfoEntry& cieInfo); 39 private: 40 bool LinearSearchEntry(uintptr_t pc, const UnwindTableInfo& uti, UnwindEntryInfo& uei); 41 bool GetCieOrFde(uintptr_t& addr, FrameDescEntry& fdeInfo); 42 void ParseCieOrFdeHeader(uintptr_t& ptr, FrameDescEntry& fdeInfo, bool& isCieEntry); 43 bool FillInFde(uintptr_t ptr, FrameDescEntry& fdeInfo); 44 bool FillInCie(uintptr_t ptr, CommonInfoEntry& cieInfo); 45 void ParseAugData(uintptr_t& ptr, CommonInfoEntry& cieInfo, const std::vector<char>& augStr); 46 uint32_t cie32Value_ = 0; 47 uint64_t cie64Value_ = 0; 48 std::unordered_map<uintptr_t, FrameDescEntry> fdeEntries_; 49 std::unordered_map<uintptr_t, CommonInfoEntry> cieEntries_; 50 }; 51 } // nameapace HiviewDFX 52 } // nameapace OHOS 53 #endif 54