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 std::string DefaultArch;
43 std::vector<std::string> DsymHints;
44 std::string FallbackDebugPath;
48 LLVMSymbolizer() = default;
49 LLVMSymbolizer(const Options &Opts) : Opts(Opts) {}
55 Expected<DILineInfo> symbolizeCode(const ObjectFile &Obj,
56 object::SectionedAddress ModuleOffset);
57 Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
58 object::SectionedAddress ModuleOffset);
59 Expected<DIInliningInfo>
60 symbolizeInlinedCode(const std::string &ModuleName,
61 object::SectionedAddress ModuleOffset);
62 Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
63 object::SectionedAddress ModuleOffset);
64 Expected<std::vector<DILocal>>
65 symbolizeFrame(const std::string &ModuleName,
66 object::SectionedAddress ModuleOffset);
70 DemangleName(const std::string &Name,
71 const SymbolizableModule *DbiModuleDescriptor);
74 // Bundles together object file with code/data and object file with
75 // corresponding debug info. These objects can be the same.
76 using ObjectPair = std::pair<const ObjectFile *, const ObjectFile *>;
79 symbolizeCodeCommon(SymbolizableModule *Info,
80 object::SectionedAddress ModuleOffset);
82 /// Returns a SymbolizableModule or an error if loading debug info failed.
83 /// Only one attempt is made to load a module, and errors during loading are
84 /// only reported once. Subsequent calls to get module info for a module that
85 /// failed to load will return nullptr.
86 Expected<SymbolizableModule *>
87 getOrCreateModuleInfo(const std::string &ModuleName);
89 Expected<SymbolizableModule *>
90 createModuleInfo(const ObjectFile *Obj,
91 std::unique_ptr<DIContext> Context,
92 StringRef ModuleName);
94 ObjectFile *lookUpDsymFile(const std::string &Path,
95 const MachOObjectFile *ExeObj,
96 const std::string &ArchName);
97 ObjectFile *lookUpDebuglinkObject(const std::string &Path,
98 const ObjectFile *Obj,
99 const std::string &ArchName);
101 /// Returns pair of pointers to object and debug object.
102 Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path,
103 const std::string &ArchName);
105 /// Return a pointer to object file at specified path, for a specified
106 /// architecture (e.g. if path refers to a Mach-O universal binary, only one
107 /// object file from it will be returned).
108 Expected<ObjectFile *> getOrCreateObject(const std::string &Path,
109 const std::string &ArchName);
111 std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
113 /// Contains cached results of getOrCreateObjectPair().
114 std::map<std::pair<std::string, std::string>, ObjectPair>
115 ObjectPairForPathArch;
117 /// Contains parsed binary for each path, or parsing error.
118 std::map<std::string, OwningBinary<Binary>> BinaryForPath;
120 /// Parsed object file for path/architecture pair, where "path" refers
121 /// to Mach-O universal binary.
122 std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>>
123 ObjectForUBPathAndArch;
128 } // end namespace symbolize
129 } // end namespace llvm
131 #endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H