1 //===-- Symbolize.h --------------------------------------------- C++ -----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Header for LLVM symbolization library.
12 //===----------------------------------------------------------------------===//
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/ObjectFile.h"
18 #include "llvm/Support/ErrorOr.h"
27 using namespace object;
28 using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
30 class LLVMSymbolizer {
33 FunctionNameKind PrintFunctions;
34 bool UseSymbolTable : 1;
36 bool RelativeAddresses : 1;
37 std::string DefaultArch;
38 std::vector<std::string> DsymHints;
39 Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
40 bool UseSymbolTable = true, bool Demangle = true,
41 bool RelativeAddresses = false, std::string DefaultArch = "")
42 : PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
43 Demangle(Demangle), RelativeAddresses(RelativeAddresses),
44 DefaultArch(std::move(DefaultArch)) {}
47 LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
52 Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
53 uint64_t ModuleOffset);
54 Expected<DIInliningInfo> symbolizeInlinedCode(const std::string &ModuleName,
55 uint64_t ModuleOffset);
56 Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
57 uint64_t ModuleOffset);
59 static std::string DemangleName(const std::string &Name,
60 const SymbolizableModule *ModInfo);
63 // Bundles together object file with code/data and object file with
64 // corresponding debug info. These objects can be the same.
65 typedef std::pair<ObjectFile*, ObjectFile*> ObjectPair;
67 /// Returns a SymbolizableModule or an error if loading debug info failed.
68 /// Only one attempt is made to load a module, and errors during loading are
69 /// only reported once. Subsequent calls to get module info for a module that
70 /// failed to load will return nullptr.
71 Expected<SymbolizableModule *>
72 getOrCreateModuleInfo(const std::string &ModuleName);
74 ObjectFile *lookUpDsymFile(const std::string &Path,
75 const MachOObjectFile *ExeObj,
76 const std::string &ArchName);
77 ObjectFile *lookUpDebuglinkObject(const std::string &Path,
78 const ObjectFile *Obj,
79 const std::string &ArchName);
81 /// \brief Returns pair of pointers to object and debug object.
82 Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path,
83 const std::string &ArchName);
85 /// \brief Return a pointer to object file at specified path, for a specified
86 /// architecture (e.g. if path refers to a Mach-O universal binary, only one
87 /// object file from it will be returned).
88 Expected<ObjectFile *> getOrCreateObject(const std::string &Path,
89 const std::string &ArchName);
91 std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
93 /// \brief Contains cached results of getOrCreateObjectPair().
94 std::map<std::pair<std::string, std::string>, ObjectPair>
95 ObjectPairForPathArch;
97 /// \brief Contains parsed binary for each path, or parsing error.
98 std::map<std::string, OwningBinary<Binary>> BinaryForPath;
100 /// \brief Parsed object file for path/architecture pair, where "path" refers
101 /// to Mach-O universal binary.
102 std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>>
103 ObjectForUBPathAndArch;
108 } // namespace symbolize