LLVM  10.0.0svn
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"
19 #include "llvm/Support/Error.h"
20 #include <algorithm>
21 #include <cstdint>
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 namespace llvm {
29 namespace symbolize {
30 
31 using namespace object;
32 
34 
36 public:
37  struct Options {
39  bool UseSymbolTable = true;
40  bool Demangle = true;
41  bool RelativeAddresses = false;
42  bool UntagAddresses = false;
43  std::string DefaultArch;
44  std::vector<std::string> DsymHints;
45  std::string FallbackDebugPath;
46  std::string DWPName;
47  };
48 
49  LLVMSymbolizer() = default;
50  LLVMSymbolizer(const Options &Opts) : Opts(Opts) {}
51 
53  flush();
54  }
55 
56  Expected<DILineInfo> symbolizeCode(const ObjectFile &Obj,
57  object::SectionedAddress ModuleOffset);
58  Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
59  object::SectionedAddress ModuleOffset);
61  symbolizeInlinedCode(const std::string &ModuleName,
62  object::SectionedAddress ModuleOffset);
63  Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
64  object::SectionedAddress ModuleOffset);
66  symbolizeFrame(const std::string &ModuleName,
67  object::SectionedAddress ModuleOffset);
68  void flush();
69 
70  static std::string
71  DemangleName(const std::string &Name,
72  const SymbolizableModule *DbiModuleDescriptor);
73 
74 private:
75  // Bundles together object file with code/data and object file with
76  // corresponding debug info. These objects can be the same.
77  using ObjectPair = std::pair<const ObjectFile *, const ObjectFile *>;
78 
80  symbolizeCodeCommon(SymbolizableModule *Info,
81  object::SectionedAddress ModuleOffset);
82 
83  /// Returns a SymbolizableModule or an error if loading debug info failed.
84  /// Only one attempt is made to load a module, and errors during loading are
85  /// only reported once. Subsequent calls to get module info for a module that
86  /// failed to load will return nullptr.
88  getOrCreateModuleInfo(const std::string &ModuleName);
89 
91  createModuleInfo(const ObjectFile *Obj,
92  std::unique_ptr<DIContext> Context,
93  StringRef ModuleName);
94 
95  ObjectFile *lookUpDsymFile(const std::string &Path,
96  const MachOObjectFile *ExeObj,
97  const std::string &ArchName);
98  ObjectFile *lookUpDebuglinkObject(const std::string &Path,
99  const ObjectFile *Obj,
100  const std::string &ArchName);
101 
102  /// Returns pair of pointers to object and debug object.
103  Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path,
104  const std::string &ArchName);
105 
106  /// Return a pointer to object file at specified path, for a specified
107  /// architecture (e.g. if path refers to a Mach-O universal binary, only one
108  /// object file from it will be returned).
109  Expected<ObjectFile *> getOrCreateObject(const std::string &Path,
110  const std::string &ArchName);
111 
112  std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
113 
114  /// Contains cached results of getOrCreateObjectPair().
115  std::map<std::pair<std::string, std::string>, ObjectPair>
116  ObjectPairForPathArch;
117 
118  /// Contains parsed binary for each path, or parsing error.
119  std::map<std::string, OwningBinary<Binary>> BinaryForPath;
120 
121  /// Parsed object file for path/architecture pair, where "path" refers
122  /// to Mach-O universal binary.
123  std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>>
124  ObjectForUBPathAndArch;
125 
126  Options Opts;
127 };
128 
129 } // end namespace symbolize
130 } // end namespace llvm
131 
132 #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:221
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:50
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
std::vector< std::string > DsymHints
Definition: Symbolize.h:44
DINameKind FunctionNameKind
Definition: DIContext.h:137
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48