LLVM  5.0.0
Symbolize.h
Go to the documentation of this file.
1 //===- Symbolize.h ----------------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Header for LLVM symbolization library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
15 #define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
16 
18 #include "llvm/Object/Binary.h"
19 #include "llvm/Object/ObjectFile.h"
20 #include "llvm/Support/Error.h"
21 #include <algorithm>
22 #include <cstdint>
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 namespace llvm {
30 namespace symbolize {
31 
32 using namespace object;
33 
35 
37 public:
38  struct Options {
40  bool UseSymbolTable : 1;
41  bool Demangle : 1;
42  bool RelativeAddresses : 1;
43  std::string DefaultArch;
44  std::vector<std::string> DsymHints;
45 
47  bool UseSymbolTable = true, bool Demangle = true,
48  bool RelativeAddresses = false, std::string DefaultArch = "")
49  : PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
50  Demangle(Demangle), RelativeAddresses(RelativeAddresses),
51  DefaultArch(std::move(DefaultArch)) {}
52  };
53 
54  LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
55 
57  flush();
58  }
59 
60  Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
61  uint64_t ModuleOffset);
62  Expected<DIInliningInfo> symbolizeInlinedCode(const std::string &ModuleName,
63  uint64_t ModuleOffset);
64  Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
65  uint64_t ModuleOffset);
66  void flush();
67 
68  static std::string
69  DemangleName(const std::string &Name,
70  const SymbolizableModule *DbiModuleDescriptor);
71 
72 private:
73  // Bundles together object file with code/data and object file with
74  // corresponding debug info. These objects can be the same.
75  using ObjectPair = std::pair<ObjectFile *, ObjectFile *>;
76 
77  /// Returns a SymbolizableModule or an error if loading debug info failed.
78  /// Only one attempt is made to load a module, and errors during loading are
79  /// only reported once. Subsequent calls to get module info for a module that
80  /// failed to load will return nullptr.
82  getOrCreateModuleInfo(const std::string &ModuleName);
83 
84  ObjectFile *lookUpDsymFile(const std::string &Path,
85  const MachOObjectFile *ExeObj,
86  const std::string &ArchName);
87  ObjectFile *lookUpDebuglinkObject(const std::string &Path,
88  const ObjectFile *Obj,
89  const std::string &ArchName);
90 
91  /// \brief Returns pair of pointers to object and debug object.
92  Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path,
93  const std::string &ArchName);
94 
95  /// \brief Return a pointer to object file at specified path, for a specified
96  /// architecture (e.g. if path refers to a Mach-O universal binary, only one
97  /// object file from it will be returned).
98  Expected<ObjectFile *> getOrCreateObject(const std::string &Path,
99  const std::string &ArchName);
100 
101  std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
102 
103  /// \brief Contains cached results of getOrCreateObjectPair().
104  std::map<std::pair<std::string, std::string>, ObjectPair>
105  ObjectPairForPathArch;
106 
107  /// \brief Contains parsed binary for each path, or parsing error.
108  std::map<std::string, OwningBinary<Binary>> BinaryForPath;
109 
110  /// \brief Parsed object file for path/architecture pair, where "path" refers
111  /// to Mach-O universal binary.
112  std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>>
113  ObjectForUBPathAndArch;
114 
115  Options Opts;
116 };
117 
118 } // end namespace symbolize
119 } // end namespace llvm
120 
121 #endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
DILineInfoSpecifier::FunctionNameKind FunctionNameKind
This class is the base class for all object file types.
Definition: ObjectFile.h:189
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:99
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
static StringRef DefaultArch
const char * Name
std::vector< std::string > DsymHints
Definition: Symbolize.h:44
DINameKind FunctionNameKind
Definition: DIContext.h:105
Options(FunctionNameKind PrintFunctions=FunctionNameKind::LinkageName, bool UseSymbolTable=true, bool Demangle=true, bool RelativeAddresses=false, std::string DefaultArch="")
Definition: Symbolize.h:46
LLVMSymbolizer(const Options &Opts=Options())
Definition: Symbolize.h:54