[llvm-objdump] - Import the test/Object/X86/no-start-symbol.test test case and rewrit...
[llvm-complete.git] / lib / DebugInfo / Symbolize / SymbolizableObjectFile.h
blob9cab94178c1b245d357355220a27819b3ce45259
1 //===- SymbolizableObjectFile.h ---------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the SymbolizableObjectFile class.
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
13 #define LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/DebugInfo/DIContext.h"
17 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
18 #include "llvm/Support/ErrorOr.h"
19 #include <cstdint>
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <system_error>
25 namespace llvm {
27 class DataExtractor;
29 namespace symbolize {
31 class SymbolizableObjectFile : public SymbolizableModule {
32 public:
33 static ErrorOr<std::unique_ptr<SymbolizableObjectFile>>
34 create(const object::ObjectFile *Obj, std::unique_ptr<DIContext> DICtx);
36 DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
37 FunctionNameKind FNKind,
38 bool UseSymbolTable) const override;
39 DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
40 FunctionNameKind FNKind,
41 bool UseSymbolTable) const override;
42 DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override;
43 std::vector<DILocal>
44 symbolizeFrame(object::SectionedAddress ModuleOffset) const override;
46 // Return true if this is a 32-bit x86 PE COFF module.
47 bool isWin32Module() const override;
49 // Returns the preferred base of the module, i.e. where the loader would place
50 // it in memory assuming there were no conflicts.
51 uint64_t getModulePreferredBase() const override;
53 private:
54 bool shouldOverrideWithSymbolTable(FunctionNameKind FNKind,
55 bool UseSymbolTable) const;
57 bool getNameFromSymbolTable(object::SymbolRef::Type Type, uint64_t Address,
58 std::string &Name, uint64_t &Addr,
59 uint64_t &Size) const;
60 // For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
61 // (function descriptor) section and OpdExtractor refers to its contents.
62 std::error_code addSymbol(const object::SymbolRef &Symbol,
63 uint64_t SymbolSize,
64 DataExtractor *OpdExtractor = nullptr,
65 uint64_t OpdAddress = 0);
66 std::error_code addCoffExportSymbols(const object::COFFObjectFile *CoffObj);
68 /// Search for the first occurence of specified Address in ObjectFile.
69 uint64_t getModuleSectionIndexForAddress(uint64_t Address) const;
71 const object::ObjectFile *Module;
72 std::unique_ptr<DIContext> DebugInfoContext;
74 struct SymbolDesc {
75 uint64_t Addr;
76 // If size is 0, assume that symbol occupies the whole memory range up to
77 // the following symbol.
78 uint64_t Size;
80 bool operator<(const SymbolDesc &RHS) const {
81 return Addr != RHS.Addr ? Addr < RHS.Addr : Size < RHS.Size;
84 std::vector<std::pair<SymbolDesc, StringRef>> Functions;
85 std::vector<std::pair<SymbolDesc, StringRef>> Objects;
87 SymbolizableObjectFile(const object::ObjectFile *Obj,
88 std::unique_ptr<DIContext> DICtx);
91 } // end namespace symbolize
93 } // end namespace llvm
95 #endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H