1 //===- Symbolize.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 // Header for LLVM symbolization library.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
14 #define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
16 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
17 #include "llvm/Object/Binary.h"
18 #include "llvm/Object/ObjectFile.h"
19 #include "llvm/Support/Error.h"
31 using namespace object
;
33 using FunctionNameKind
= DILineInfoSpecifier::FunctionNameKind
;
35 class LLVMSymbolizer
{
38 FunctionNameKind PrintFunctions
= FunctionNameKind::LinkageName
;
39 bool UseSymbolTable
= true;
41 bool RelativeAddresses
= false;
42 bool UntagAddresses
= false;
43 std::string DefaultArch
;
44 std::vector
<std::string
> DsymHints
;
45 std::string FallbackDebugPath
;
49 LLVMSymbolizer() = default;
50 LLVMSymbolizer(const Options
&Opts
) : Opts(Opts
) {}
56 Expected
<DILineInfo
> symbolizeCode(const ObjectFile
&Obj
,
57 object::SectionedAddress ModuleOffset
);
58 Expected
<DILineInfo
> symbolizeCode(const std::string
&ModuleName
,
59 object::SectionedAddress ModuleOffset
);
60 Expected
<DIInliningInfo
>
61 symbolizeInlinedCode(const std::string
&ModuleName
,
62 object::SectionedAddress ModuleOffset
);
63 Expected
<DIGlobal
> symbolizeData(const std::string
&ModuleName
,
64 object::SectionedAddress ModuleOffset
);
65 Expected
<std::vector
<DILocal
>>
66 symbolizeFrame(const std::string
&ModuleName
,
67 object::SectionedAddress ModuleOffset
);
71 DemangleName(const std::string
&Name
,
72 const SymbolizableModule
*DbiModuleDescriptor
);
75 // Bundles together object file with code/data and object file with
76 // corresponding debug info. These objects can be the same.
77 using ObjectPair
= std::pair
<const ObjectFile
*, const ObjectFile
*>;
80 symbolizeCodeCommon(SymbolizableModule
*Info
,
81 object::SectionedAddress ModuleOffset
);
83 /// Returns a SymbolizableModule or an error if loading debug info failed.
84 /// Only one attempt is made to load a module, and errors during loading are
85 /// only reported once. Subsequent calls to get module info for a module that
86 /// failed to load will return nullptr.
87 Expected
<SymbolizableModule
*>
88 getOrCreateModuleInfo(const std::string
&ModuleName
);
90 Expected
<SymbolizableModule
*>
91 createModuleInfo(const ObjectFile
*Obj
,
92 std::unique_ptr
<DIContext
> Context
,
93 StringRef ModuleName
);
95 ObjectFile
*lookUpDsymFile(const std::string
&Path
,
96 const MachOObjectFile
*ExeObj
,
97 const std::string
&ArchName
);
98 ObjectFile
*lookUpDebuglinkObject(const std::string
&Path
,
99 const ObjectFile
*Obj
,
100 const std::string
&ArchName
);
102 /// Returns pair of pointers to object and debug object.
103 Expected
<ObjectPair
> getOrCreateObjectPair(const std::string
&Path
,
104 const std::string
&ArchName
);
106 /// Return a pointer to object file at specified path, for a specified
107 /// architecture (e.g. if path refers to a Mach-O universal binary, only one
108 /// object file from it will be returned).
109 Expected
<ObjectFile
*> getOrCreateObject(const std::string
&Path
,
110 const std::string
&ArchName
);
112 std::map
<std::string
, std::unique_ptr
<SymbolizableModule
>> Modules
;
114 /// Contains cached results of getOrCreateObjectPair().
115 std::map
<std::pair
<std::string
, std::string
>, ObjectPair
>
116 ObjectPairForPathArch
;
118 /// Contains parsed binary for each path, or parsing error.
119 std::map
<std::string
, OwningBinary
<Binary
>> BinaryForPath
;
121 /// Parsed object file for path/architecture pair, where "path" refers
122 /// to Mach-O universal binary.
123 std::map
<std::pair
<std::string
, std::string
>, std::unique_ptr
<ObjectFile
>>
124 ObjectForUBPathAndArch
;
129 } // end namespace symbolize
130 } // end namespace llvm
132 #endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H