diff options
Diffstat (limited to 'clang-r353983/include/llvm/DebugInfo/Symbolize')
3 files changed, 224 insertions, 0 deletions
diff --git a/clang-r353983/include/llvm/DebugInfo/Symbolize/DIPrinter.h b/clang-r353983/include/llvm/DebugInfo/Symbolize/DIPrinter.h new file mode 100644 index 00000000..71663f30 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/Symbolize/DIPrinter.h @@ -0,0 +1,53 @@ +//===- llvm/DebugInfo/Symbolize/DIPrinter.h ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares the DIPrinter class, which is responsible for printing +// structures defined in DebugInfo/DIContext.h +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H +#define LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H + +#include "llvm/Support/raw_ostream.h" + +namespace llvm { +struct DILineInfo; +class DIInliningInfo; +struct DIGlobal; + +namespace symbolize { + +class DIPrinter { + raw_ostream &OS; + bool PrintFunctionNames; + bool PrintPretty; + int PrintSourceContext; + bool Verbose; + bool Basenames; + + void print(const DILineInfo &Info, bool Inlined); + void printContext(const std::string &FileName, int64_t Line); + +public: + DIPrinter(raw_ostream &OS, bool PrintFunctionNames = true, + bool PrintPretty = false, int PrintSourceContext = 0, + bool Verbose = false, bool Basenames = false) + : OS(OS), PrintFunctionNames(PrintFunctionNames), + PrintPretty(PrintPretty), PrintSourceContext(PrintSourceContext), + Verbose(Verbose), Basenames(Basenames) {} + + DIPrinter &operator<<(const DILineInfo &Info); + DIPrinter &operator<<(const DIInliningInfo &Info); + DIPrinter &operator<<(const DIGlobal &Global); +}; +} +} + +#endif + diff --git a/clang-r353983/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h b/clang-r353983/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h new file mode 100644 index 00000000..f0862d0b --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h @@ -0,0 +1,46 @@ +//===- SymbolizableModule.h -------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares the SymbolizableModule interface. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H +#define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H + +#include "llvm/DebugInfo/DIContext.h" +#include <cstdint> + +namespace llvm { +namespace symbolize { + +using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind; + +class SymbolizableModule { +public: + virtual ~SymbolizableModule() = default; + + virtual DILineInfo symbolizeCode(uint64_t ModuleOffset, + FunctionNameKind FNKind, + bool UseSymbolTable) const = 0; + virtual DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset, + FunctionNameKind FNKind, + bool UseSymbolTable) const = 0; + virtual DIGlobal symbolizeData(uint64_t ModuleOffset) const = 0; + + // Return true if this is a 32-bit x86 PE COFF module. + virtual bool isWin32Module() const = 0; + + // Returns the preferred base of the module, i.e. where the loader would place + // it in memory assuming there were no conflicts. + virtual uint64_t getModulePreferredBase() const = 0; +}; + +} // end namespace symbolize +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H diff --git a/clang-r353983/include/llvm/DebugInfo/Symbolize/Symbolize.h b/clang-r353983/include/llvm/DebugInfo/Symbolize/Symbolize.h new file mode 100644 index 00000000..4e57fe43 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/Symbolize/Symbolize.h @@ -0,0 +1,125 @@ +//===- Symbolize.h ----------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Header for LLVM symbolization library. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H +#define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H + +#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h" +#include "llvm/Object/Binary.h" +#include "llvm/Object/ObjectFile.h" +#include "llvm/Support/Error.h" +#include <algorithm> +#include <cstdint> +#include <map> +#include <memory> +#include <string> +#include <utility> +#include <vector> + +namespace llvm { +namespace symbolize { + +using namespace object; + +using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind; + +class LLVMSymbolizer { +public: + struct Options { + FunctionNameKind PrintFunctions; + bool UseSymbolTable : 1; + bool Demangle : 1; + bool RelativeAddresses : 1; + std::string DefaultArch; + std::vector<std::string> DsymHints; + std::string FallbackDebugPath; + + Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName, + bool UseSymbolTable = true, bool Demangle = true, + bool RelativeAddresses = false, std::string DefaultArch = "", + std::string FallbackDebugPath = "") + : PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable), + Demangle(Demangle), RelativeAddresses(RelativeAddresses), + DefaultArch(std::move(DefaultArch)), + FallbackDebugPath(std::move(FallbackDebugPath)) {} + }; + + LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {} + + ~LLVMSymbolizer() { + flush(); + } + + Expected<DILineInfo> symbolizeCode(const std::string &ModuleName, + uint64_t ModuleOffset, + StringRef DWPName = ""); + Expected<DIInliningInfo> symbolizeInlinedCode(const std::string &ModuleName, + uint64_t ModuleOffset, + StringRef DWPName = ""); + Expected<DIGlobal> symbolizeData(const std::string &ModuleName, + uint64_t ModuleOffset); + void flush(); + + static std::string + DemangleName(const std::string &Name, + const SymbolizableModule *DbiModuleDescriptor); + +private: + // Bundles together object file with code/data and object file with + // corresponding debug info. These objects can be the same. + using ObjectPair = std::pair<ObjectFile *, ObjectFile *>; + + /// Returns a SymbolizableModule or an error if loading debug info failed. + /// Only one attempt is made to load a module, and errors during loading are + /// only reported once. Subsequent calls to get module info for a module that + /// failed to load will return nullptr. + Expected<SymbolizableModule *> + getOrCreateModuleInfo(const std::string &ModuleName, StringRef DWPName = ""); + + ObjectFile *lookUpDsymFile(const std::string &Path, + const MachOObjectFile *ExeObj, + const std::string &ArchName); + ObjectFile *lookUpDebuglinkObject(const std::string &Path, + const ObjectFile *Obj, + const std::string &ArchName); + + /// Returns pair of pointers to object and debug object. + Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path, + const std::string &ArchName); + + /// Return a pointer to object file at specified path, for a specified + /// architecture (e.g. if path refers to a Mach-O universal binary, only one + /// object file from it will be returned). + Expected<ObjectFile *> getOrCreateObject(const std::string &Path, + const std::string &ArchName); + + std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules; + + /// Contains cached results of getOrCreateObjectPair(). + std::map<std::pair<std::string, std::string>, ObjectPair> + ObjectPairForPathArch; + + /// Contains parsed binary for each path, or parsing error. + std::map<std::string, OwningBinary<Binary>> BinaryForPath; + + /// Parsed object file for path/architecture pair, where "path" refers + /// to Mach-O universal binary. + std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>> + ObjectForUBPathAndArch; + + Options Opts; +}; + +} // end namespace symbolize +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H |
