1 //===- SymbolizableObjectFile.h ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
23 #include <system_error>
31 class SymbolizableObjectFile
: public SymbolizableModule
{
33 static ErrorOr
<std::unique_ptr
<SymbolizableObjectFile
>>
34 create(const object::ObjectFile
*Obj
, std::unique_ptr
<DIContext
> DICtx
,
37 DILineInfo
symbolizeCode(object::SectionedAddress ModuleOffset
,
38 FunctionNameKind FNKind
,
39 bool UseSymbolTable
) const override
;
40 DIInliningInfo
symbolizeInlinedCode(object::SectionedAddress ModuleOffset
,
41 FunctionNameKind FNKind
,
42 bool UseSymbolTable
) const override
;
43 DIGlobal
symbolizeData(object::SectionedAddress ModuleOffset
) const override
;
45 symbolizeFrame(object::SectionedAddress ModuleOffset
) const override
;
47 // Return true if this is a 32-bit x86 PE COFF module.
48 bool isWin32Module() const override
;
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
;
55 bool shouldOverrideWithSymbolTable(FunctionNameKind FNKind
,
56 bool UseSymbolTable
) const;
58 bool getNameFromSymbolTable(object::SymbolRef::Type Type
, uint64_t Address
,
59 std::string
&Name
, uint64_t &Addr
,
60 uint64_t &Size
) 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 std::error_code
addSymbol(const object::SymbolRef
&Symbol
,
65 DataExtractor
*OpdExtractor
= nullptr,
66 uint64_t OpdAddress
= 0);
67 std::error_code
addCoffExportSymbols(const object::COFFObjectFile
*CoffObj
);
69 /// Search for the first occurence of specified Address in ObjectFile.
70 uint64_t getModuleSectionIndexForAddress(uint64_t Address
) const;
72 const object::ObjectFile
*Module
;
73 std::unique_ptr
<DIContext
> DebugInfoContext
;
78 // If size is 0, assume that symbol occupies the whole memory range up to
79 // the following symbol.
82 bool operator<(const SymbolDesc
&RHS
) const {
83 return Addr
!= RHS
.Addr
? Addr
< RHS
.Addr
: Size
< RHS
.Size
;
86 std::vector
<std::pair
<SymbolDesc
, StringRef
>> Functions
;
87 std::vector
<std::pair
<SymbolDesc
, StringRef
>> Objects
;
89 SymbolizableObjectFile(const object::ObjectFile
*Obj
,
90 std::unique_ptr
<DIContext
> DICtx
,
94 } // end namespace symbolize
96 } // end namespace llvm
98 #endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H