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"
26 using namespace object;
27 using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
29 class LLVMSymbolizer {
32 FunctionNameKind PrintFunctions;
33 bool UseSymbolTable : 1;
35 bool RelativeAddresses : 1;
36 std::string DefaultArch;
37 std::vector<std::string> DsymHints;
38 Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
39 bool UseSymbolTable = true, bool Demangle = true,
40 bool RelativeAddresses = false, std::string DefaultArch = "")
41 : PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
42 Demangle(Demangle), RelativeAddresses(RelativeAddresses),
43 DefaultArch(DefaultArch) {}
46 LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
51 ErrorOr<DILineInfo> symbolizeCode(const std::string &ModuleName,
52 uint64_t ModuleOffset);
53 ErrorOr<DIInliningInfo> symbolizeInlinedCode(const std::string &ModuleName,
54 uint64_t ModuleOffset);
55 ErrorOr<DIGlobal> symbolizeData(const std::string &ModuleName,
56 uint64_t ModuleOffset);
58 static std::string DemangleName(const std::string &Name,
59 const SymbolizableModule *ModInfo);
62 // Bundles together object file with code/data and object file with
63 // corresponding debug info. These objects can be the same.
64 typedef std::pair<ObjectFile*, ObjectFile*> ObjectPair;
66 ErrorOr<SymbolizableModule *>
67 getOrCreateModuleInfo(const std::string &ModuleName);
68 ObjectFile *lookUpDsymFile(const std::string &Path,
69 const MachOObjectFile *ExeObj,
70 const std::string &ArchName);
71 ObjectFile *lookUpDebuglinkObject(const std::string &Path,
72 const ObjectFile *Obj,
73 const std::string &ArchName);
75 /// \brief Returns pair of pointers to object and debug object.
76 ErrorOr<ObjectPair> getOrCreateObjectPair(const std::string &Path,
77 const std::string &ArchName);
79 /// \brief Return a pointer to object file at specified path, for a specified
80 /// architecture (e.g. if path refers to a Mach-O universal binary, only one
81 /// object file from it will be returned).
82 ErrorOr<ObjectFile *> getOrCreateObject(const std::string &Path,
83 const std::string &ArchName);
85 std::map<std::string, ErrorOr<std::unique_ptr<SymbolizableModule>>> Modules;
87 /// \brief Contains cached results of getOrCreateObjectPair().
88 std::map<std::pair<std::string, std::string>, ErrorOr<ObjectPair>>
89 ObjectPairForPathArch;
91 /// \brief Contains parsed binary for each path, or parsing error.
92 std::map<std::string, ErrorOr<OwningBinary<Binary>>> BinaryForPath;
94 /// \brief Parsed object file for path/architecture pair, where "path" refers
95 /// to Mach-O universal binary.
96 std::map<std::pair<std::string, std::string>, ErrorOr<std::unique_ptr<ObjectFile>>>
97 ObjectForUBPathAndArch;
102 } // namespace symbolize