Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / DebugInfo / Symbolize / Symbolize.h
blob4e57fe43847811f2012f07558ad06470f3a20176
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.
11 //===----------------------------------------------------------------------===//
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/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>
28 namespace llvm {
29 namespace symbolize {
31 using namespace object;
33 using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
35 class LLVMSymbolizer {
36 public:
37 struct Options {
38 FunctionNameKind PrintFunctions;
39 bool UseSymbolTable : 1;
40 bool Demangle : 1;
41 bool RelativeAddresses : 1;
42 std::string DefaultArch;
43 std::vector<std::string> DsymHints;
44 std::string FallbackDebugPath;
46 Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
47 bool UseSymbolTable = true, bool Demangle = true,
48 bool RelativeAddresses = false, std::string DefaultArch = "",
49 std::string FallbackDebugPath = "")
50 : PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
51 Demangle(Demangle), RelativeAddresses(RelativeAddresses),
52 DefaultArch(std::move(DefaultArch)),
53 FallbackDebugPath(std::move(FallbackDebugPath)) {}
56 LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
58 ~LLVMSymbolizer() {
59 flush();
62 Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
63 uint64_t ModuleOffset,
64 StringRef DWPName = "");
65 Expected<DIInliningInfo> symbolizeInlinedCode(const std::string &ModuleName,
66 uint64_t ModuleOffset,
67 StringRef DWPName = "");
68 Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
69 uint64_t ModuleOffset);
70 void flush();
72 static std::string
73 DemangleName(const std::string &Name,
74 const SymbolizableModule *DbiModuleDescriptor);
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<ObjectFile *, ObjectFile *>;
81 /// Returns a SymbolizableModule or an error if loading debug info failed.
82 /// Only one attempt is made to load a module, and errors during loading are
83 /// only reported once. Subsequent calls to get module info for a module that
84 /// failed to load will return nullptr.
85 Expected<SymbolizableModule *>
86 getOrCreateModuleInfo(const std::string &ModuleName, StringRef DWPName = "");
88 ObjectFile *lookUpDsymFile(const std::string &Path,
89 const MachOObjectFile *ExeObj,
90 const std::string &ArchName);
91 ObjectFile *lookUpDebuglinkObject(const std::string &Path,
92 const ObjectFile *Obj,
93 const std::string &ArchName);
95 /// Returns pair of pointers to object and debug object.
96 Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path,
97 const std::string &ArchName);
99 /// Return a pointer to object file at specified path, for a specified
100 /// architecture (e.g. if path refers to a Mach-O universal binary, only one
101 /// object file from it will be returned).
102 Expected<ObjectFile *> getOrCreateObject(const std::string &Path,
103 const std::string &ArchName);
105 std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
107 /// Contains cached results of getOrCreateObjectPair().
108 std::map<std::pair<std::string, std::string>, ObjectPair>
109 ObjectPairForPathArch;
111 /// Contains parsed binary for each path, or parsing error.
112 std::map<std::string, OwningBinary<Binary>> BinaryForPath;
114 /// Parsed object file for path/architecture pair, where "path" refers
115 /// to Mach-O universal binary.
116 std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>>
117 ObjectForUBPathAndArch;
119 Options Opts;
122 } // end namespace symbolize
123 } // end namespace llvm
125 #endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H