2013-01-22 14:21:19 +00:00
|
|
|
//===-- LLVMSymbolize.h ----------------------------------------- C++ -----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Header for LLVM symbolization library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_SYMBOLIZER_LLVMSYMBOLIZE_H
|
|
|
|
#define LLVM_TOOLS_LLVM_SYMBOLIZER_LLVMSYMBOLIZE_H
|
2013-01-22 14:21:19 +00:00
|
|
|
|
2013-06-28 08:15:40 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2013-01-22 14:21:19 +00:00
|
|
|
#include "llvm/DebugInfo/DIContext.h"
|
2013-06-28 08:15:40 +00:00
|
|
|
#include "llvm/Object/MachOUniversal.h"
|
2013-01-22 14:21:19 +00:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2014-11-07 09:08:39 +00:00
|
|
|
#include "llvm/Support/DataExtractor.h"
|
2013-01-22 14:21:19 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include <map>
|
2014-04-22 05:26:14 +00:00
|
|
|
#include <memory>
|
2013-01-22 14:21:19 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2014-05-17 00:07:48 +00:00
|
|
|
typedef DILineInfoSpecifier::FunctionNameKind FunctionNameKind;
|
2013-01-22 14:21:19 +00:00
|
|
|
using namespace object;
|
|
|
|
|
|
|
|
namespace symbolize {
|
|
|
|
|
|
|
|
class ModuleInfo;
|
|
|
|
|
|
|
|
class LLVMSymbolizer {
|
|
|
|
public:
|
2013-02-15 08:54:47 +00:00
|
|
|
struct Options {
|
2013-01-22 14:21:19 +00:00
|
|
|
bool UseSymbolTable : 1;
|
2014-05-17 00:07:48 +00:00
|
|
|
FunctionNameKind PrintFunctions;
|
2013-01-22 14:21:19 +00:00
|
|
|
bool PrintInlining : 1;
|
|
|
|
bool Demangle : 1;
|
2013-06-28 08:15:40 +00:00
|
|
|
std::string DefaultArch;
|
2014-10-17 00:50:19 +00:00
|
|
|
std::vector<std::string> DsymHints;
|
2014-05-17 00:07:48 +00:00
|
|
|
Options(bool UseSymbolTable = true,
|
|
|
|
FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
|
2013-06-28 08:15:40 +00:00
|
|
|
bool PrintInlining = true, bool Demangle = true,
|
|
|
|
std::string DefaultArch = "")
|
2014-10-17 00:50:19 +00:00
|
|
|
: UseSymbolTable(UseSymbolTable),
|
|
|
|
PrintFunctions(PrintFunctions), PrintInlining(PrintInlining),
|
|
|
|
Demangle(Demangle), DefaultArch(DefaultArch) {}
|
2013-01-22 14:21:19 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 08:54:47 +00:00
|
|
|
LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
|
2013-06-28 15:08:29 +00:00
|
|
|
~LLVMSymbolizer() {
|
|
|
|
flush();
|
|
|
|
}
|
2013-01-22 14:21:19 +00:00
|
|
|
|
|
|
|
// Returns the result of symbolization for module name/offset as
|
|
|
|
// a string (possibly containing newlines).
|
2013-02-15 08:54:47 +00:00
|
|
|
std::string
|
|
|
|
symbolizeCode(const std::string &ModuleName, uint64_t ModuleOffset);
|
|
|
|
std::string
|
|
|
|
symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset);
|
2013-03-19 10:24:42 +00:00
|
|
|
void flush();
|
2013-06-28 12:06:25 +00:00
|
|
|
static std::string DemangleName(const std::string &Name);
|
2013-01-22 14:21:19 +00:00
|
|
|
private:
|
2014-10-17 00:50:19 +00:00
|
|
|
typedef std::pair<ObjectFile*, ObjectFile*> ObjectPair;
|
2013-06-28 08:15:40 +00:00
|
|
|
|
2013-01-22 14:21:19 +00:00
|
|
|
ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName);
|
2014-10-17 00:50:19 +00:00
|
|
|
ObjectFile *lookUpDsymFile(const std::string &Path, const MachOObjectFile *ExeObj,
|
|
|
|
const std::string &ArchName);
|
|
|
|
|
|
|
|
/// \brief Returns pair of pointers to object and debug object.
|
|
|
|
ObjectPair getOrCreateObjects(const std::string &Path,
|
|
|
|
const std::string &ArchName);
|
2013-06-28 08:15:40 +00:00
|
|
|
/// \brief Returns a parsed object file for a given architecture in a
|
|
|
|
/// universal binary (or the binary itself if it is an object file).
|
|
|
|
ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName);
|
|
|
|
|
2013-01-22 14:21:19 +00:00
|
|
|
std::string printDILineInfo(DILineInfo LineInfo) const;
|
|
|
|
|
2013-06-28 08:15:40 +00:00
|
|
|
// Owns all the parsed binaries and object files.
|
2014-04-22 05:26:14 +00:00
|
|
|
SmallVector<std::unique_ptr<Binary>, 4> ParsedBinariesAndObjects;
|
2014-08-19 18:44:46 +00:00
|
|
|
SmallVector<std::unique_ptr<MemoryBuffer>, 4> MemoryBuffers;
|
2014-10-31 21:37:49 +00:00
|
|
|
void addOwningBinary(OwningBinary<Binary> OwningBin) {
|
|
|
|
std::unique_ptr<Binary> Bin;
|
|
|
|
std::unique_ptr<MemoryBuffer> MemBuf;
|
|
|
|
std::tie(Bin, MemBuf) = OwningBin.takeBinary();
|
|
|
|
ParsedBinariesAndObjects.push_back(std::move(Bin));
|
|
|
|
MemoryBuffers.push_back(std::move(MemBuf));
|
2014-08-19 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 08:15:40 +00:00
|
|
|
// Owns module info objects.
|
2014-10-14 13:40:44 +00:00
|
|
|
std::map<std::string, ModuleInfo *> Modules;
|
|
|
|
std::map<std::pair<MachOUniversalBinary *, std::string>, ObjectFile *>
|
|
|
|
ObjectFileForArch;
|
2014-10-17 00:50:19 +00:00
|
|
|
std::map<std::pair<std::string, std::string>, ObjectPair>
|
|
|
|
ObjectPairForPathArch;
|
2013-06-28 08:15:40 +00:00
|
|
|
|
2013-01-22 14:21:19 +00:00
|
|
|
Options Opts;
|
2013-02-04 15:55:26 +00:00
|
|
|
static const char kBadString[];
|
2013-01-22 14:21:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ModuleInfo {
|
2013-02-15 08:54:47 +00:00
|
|
|
public:
|
2013-02-14 13:06:18 +00:00
|
|
|
ModuleInfo(ObjectFile *Obj, DIContext *DICtx);
|
2013-01-22 14:21:19 +00:00
|
|
|
|
2013-02-15 08:54:47 +00:00
|
|
|
DILineInfo symbolizeCode(uint64_t ModuleOffset,
|
|
|
|
const LLVMSymbolizer::Options &Opts) const;
|
2013-01-22 14:21:19 +00:00
|
|
|
DIInliningInfo symbolizeInlinedCode(
|
2013-02-15 08:54:47 +00:00
|
|
|
uint64_t ModuleOffset, const LLVMSymbolizer::Options &Opts) const;
|
|
|
|
bool symbolizeData(uint64_t ModuleOffset, std::string &Name, uint64_t &Start,
|
|
|
|
uint64_t &Size) const;
|
2013-01-22 14:21:19 +00:00
|
|
|
|
2013-02-15 08:54:47 +00:00
|
|
|
private:
|
2013-01-22 14:21:19 +00:00
|
|
|
bool getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
|
|
|
|
std::string &Name, uint64_t &Addr,
|
|
|
|
uint64_t &Size) const;
|
2014-11-07 09:08:39 +00:00
|
|
|
// For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
|
|
|
|
// (function descriptor) section and OpdExtractor refers to its contents.
|
|
|
|
void addSymbol(const SymbolRef &Symbol,
|
|
|
|
DataExtractor *OpdExtractor = nullptr,
|
|
|
|
uint64_t OpdAddress = 0);
|
2013-06-28 08:15:40 +00:00
|
|
|
ObjectFile *Module;
|
2014-03-06 05:51:42 +00:00
|
|
|
std::unique_ptr<DIContext> DebugInfoContext;
|
2013-02-14 13:06:18 +00:00
|
|
|
|
|
|
|
struct SymbolDesc {
|
|
|
|
uint64_t Addr;
|
2013-06-07 15:25:27 +00:00
|
|
|
// If size is 0, assume that symbol occupies the whole memory range up to
|
|
|
|
// the following symbol.
|
|
|
|
uint64_t Size;
|
2013-02-15 08:54:47 +00:00
|
|
|
friend bool operator<(const SymbolDesc &s1, const SymbolDesc &s2) {
|
2013-06-04 07:57:38 +00:00
|
|
|
return s1.Addr < s2.Addr;
|
2013-02-14 13:06:18 +00:00
|
|
|
}
|
|
|
|
};
|
2014-10-14 13:40:44 +00:00
|
|
|
std::map<SymbolDesc, StringRef> Functions;
|
|
|
|
std::map<SymbolDesc, StringRef> Objects;
|
2013-01-22 14:21:19 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 08:54:47 +00:00
|
|
|
} // namespace symbolize
|
|
|
|
} // namespace llvm
|
2013-01-22 14:21:19 +00:00
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#endif
|