LLVM  15.0.0git
SymbolizableObjectFile.h
Go to the documentation of this file.
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.
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
13 #define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
14 
15 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Error.h"
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 namespace llvm {
26 
27 class DataExtractor;
28 
29 namespace symbolize {
30 
32 public:
34  create(const object::ObjectFile *Obj, std::unique_ptr<DIContext> DICtx,
35  bool UntagAddresses);
36 
38  DILineInfoSpecifier LineInfoSpecifier,
39  bool UseSymbolTable) const override;
41  DILineInfoSpecifier LineInfoSpecifier,
42  bool UseSymbolTable) const override;
43  DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override;
44  std::vector<DILocal>
45  symbolizeFrame(object::SectionedAddress ModuleOffset) const override;
46 
47  // Return true if this is a 32-bit x86 PE COFF module.
48  bool isWin32Module() const override;
49 
50  // Returns the preferred base of the module, i.e. where the loader would place
51  // it in memory assuming there were no conflicts.
52  uint64_t getModulePreferredBase() const override;
53 
54 private:
55  bool shouldOverrideWithSymbolTable(FunctionNameKind FNKind,
56  bool UseSymbolTable) const;
57 
58  bool getNameFromSymbolTable(uint64_t Address, std::string &Name,
59  uint64_t &Addr, uint64_t &Size,
60  std::string &FileName) const;
61  // For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
62  // (function descriptor) section and OpdExtractor refers to its contents.
63  Error addSymbol(const object::SymbolRef &Symbol, uint64_t SymbolSize,
64  DataExtractor *OpdExtractor = nullptr,
65  uint64_t OpdAddress = 0);
66  Error addCoffExportSymbols(const object::COFFObjectFile *CoffObj);
67 
68  /// Search for the first occurence of specified Address in ObjectFile.
69  uint64_t getModuleSectionIndexForAddress(uint64_t Address) const;
70 
72  std::unique_ptr<DIContext> DebugInfoContext;
73  bool UntagAddresses;
74 
75  struct SymbolDesc {
76  uint64_t Addr;
77  // If size is 0, assume that symbol occupies the whole memory range up to
78  // the following symbol.
79  uint64_t Size;
80 
82  // Non-zero if this is an ELF local symbol. See the comment in
83  // getNameFromSymbolTable.
84  uint32_t ELFLocalSymIdx;
85 
86  bool operator<(const SymbolDesc &RHS) const {
87  return Addr != RHS.Addr ? Addr < RHS.Addr : Size < RHS.Size;
88  }
89  };
90  std::vector<SymbolDesc> Symbols;
91  // (index, filename) pairs of ELF STT_FILE symbols.
92  std::vector<std::pair<uint32_t, StringRef>> FileSymbols;
93 
95  std::unique_ptr<DIContext> DICtx,
96  bool UntagAddresses);
97 };
98 
99 } // end namespace symbolize
100 
101 } // end namespace llvm
102 
103 #endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::symbolize::SymbolizableObjectFile::isWin32Module
bool isWin32Module() const override
Definition: SymbolizableObjectFile.cpp:218
llvm::DIInliningInfo
A format-neutral container for inlined code description.
Definition: DIContext.h:87
llvm::DILineInfoSpecifier
Controls which fields of DILineInfo container should be filled with data.
Definition: DIContext.h:139
StringRef.h
Error.h
llvm::symbolize::SymbolizableObjectFile::create
static Expected< std::unique_ptr< SymbolizableObjectFile > > create(const object::ObjectFile *Obj, std::unique_ptr< DIContext > DICtx, bool UntagAddresses)
Definition: SymbolizableObjectFile.cpp:31
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::DINameKind
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:135
llvm::symbolize::SymbolizableObjectFile::symbolizeCode
DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset, DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const override
Definition: SymbolizableObjectFile.cpp:269
llvm::symbolize::SymbolizableObjectFile::symbolizeData
DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override
Definition: SymbolizableObjectFile.cpp:324
llvm::symbolize::SymbolizableObjectFile
Definition: SymbolizableObjectFile.h:31
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::symbolize::SymbolizableModule
Definition: SymbolizableModule.h:23
SymbolizableModule.h
llvm::operator<
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:339
llvm::DILineInfo
A format-neutral container for source line information.
Definition: DIContext.h:31
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:228
uint32_t
llvm::symbolize::SymbolizableObjectFile::getModulePreferredBase
uint64_t getModulePreferredBase() const override
Definition: SymbolizableObjectFile.cpp:223
DIContext.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::DIGlobal
Container for description of a global variable.
Definition: DIContext.h:113
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::object::COFFObjectFile
Definition: COFF.h:799
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::DataExtractor
Definition: DataExtractor.h:41
llvm::object::SectionedAddress
Definition: ObjectFile.h:144
llvm::symbolize::SymbolizableObjectFile::symbolizeFrame
std::vector< DILocal > symbolizeFrame(object::SectionedAddress ModuleOffset) const override
Definition: SymbolizableObjectFile.cpp:341
llvm::object::SymbolRef
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: ObjectFile.h:167
llvm::symbolize::SymbolizableObjectFile::symbolizeInlinedCode
DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset, DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const override
Definition: SymbolizableObjectFile.cpp:293