LLVM  10.0.0
Symbolize.h
Go to the documentation of this file.
1 //===- Symbolize.h ----------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Header for LLVM symbolization library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
14 #define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
15 
17 #include "llvm/Object/Binary.h"
18 #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 = true;
41  bool Demangle = true;
42  bool RelativeAddresses = false;
43  bool UntagAddresses = false;
44  std::string DefaultArch;
45  std::vector<std::string> DsymHints;
46  std::string FallbackDebugPath;
47  std::string DWPName;
48  std::vector<std::string> DebugFileDirectory;
49  };
50 
51  LLVMSymbolizer() = default;
52  LLVMSymbolizer(const Options &Opts) : Opts(Opts) {}
53 
55  flush();
56  }
57 
58  Expected<DILineInfo> symbolizeCode(const ObjectFile &Obj,
59  object::SectionedAddress ModuleOffset);
60  Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
61  object::SectionedAddress ModuleOffset);
63  symbolizeInlinedCode(const std::string &ModuleName,
64  object::SectionedAddress ModuleOffset);
65  Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
66  object::SectionedAddress ModuleOffset);
68  symbolizeFrame(const std::string &ModuleName,
69  object::SectionedAddress ModuleOffset);
70  void flush();
71 
72  static std::string
73  DemangleName(const std::string &Name,
74  const SymbolizableModule *DbiModuleDescriptor);
75 
76 private:
77  // Bundles together object file with code/data and object file with
78  // corresponding debug info. These objects can be the same.
79  using ObjectPair = std::pair<const ObjectFile *, const ObjectFile *>;
80 
82  symbolizeCodeCommon(SymbolizableModule *Info,
83  object::SectionedAddress ModuleOffset);
84 
85  /// Returns a SymbolizableModule or an error if loading debug info failed.
86  /// Only one attempt is made to load a module, and errors during loading are
87  /// only reported once. Subsequent calls to get module info for a module that
88  /// failed to load will return nullptr.
90  getOrCreateModuleInfo(const std::string &ModuleName);
91 
93  createModuleInfo(const ObjectFile *Obj,
94  std::unique_ptr<DIContext> Context,
95  StringRef ModuleName);
96 
97  ObjectFile *lookUpDsymFile(const std::string &Path,
98  const MachOObjectFile *ExeObj,
99  const std::string &ArchName);
100  ObjectFile *lookUpDebuglinkObject(const std::string &Path,
101  const ObjectFile *Obj,
102  const std::string &ArchName);
103  ObjectFile *lookUpBuildIDObject(const std::string &Path,
104  const ELFObjectFileBase *Obj,
105  const std::string &ArchName);
106 
107  /// Returns pair of pointers to object and debug object.
108  Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path,
109  const std::string &ArchName);
110 
111  /// Return a pointer to object file at specified path, for a specified
112  /// architecture (e.g. if path refers to a Mach-O universal binary, only one
113  /// object file from it will be returned).
114  Expected<ObjectFile *> getOrCreateObject(const std::string &Path,
115  const std::string &ArchName);
116 
117  std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
118 
119  /// Contains cached results of getOrCreateObjectPair().
120  std::map<std::pair<std::string, std::string>, ObjectPair>
121  ObjectPairForPathArch;
122 
123  /// Contains parsed binary for each path, or parsing error.
124  std::map<std::string, OwningBinary<Binary>> BinaryForPath;
125 
126  /// Parsed object file for path/architecture pair, where "path" refers
127  /// to Mach-O universal binary.
128  std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>>
129  ObjectForUBPathAndArch;
130 
131  Options Opts;
132 };
133 
134 } // end namespace symbolize
135 } // end namespace llvm
136 
137 #endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:23
DILineInfoSpecifier::FunctionNameKind FunctionNameKind
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
This class is the base class for all object file types.
Definition: ObjectFile.h:223
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:131
LLVMSymbolizer(const Options &Opts)
Definition: Symbolize.h:52
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
std::vector< std::string > DsymHints
Definition: Symbolize.h:45
DINameKind FunctionNameKind
Definition: DIContext.h:137
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
std::vector< std::string > DebugFileDirectory
Definition: Symbolize.h:48