blob: 89684ddef25e7424fb2436d4f2dfb9f9ad724696 [file] [log] [blame]
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +00001//===-- LLVMSymbolize.h ----------------------------------------- C++ -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Header for LLVM symbolization library.
11//
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_SYMBOLIZE_H
14#define LLVM_SYMBOLIZE_H
15
16#include "llvm/ADT/OwningPtr.h"
17#include "llvm/DebugInfo/DIContext.h"
18#include "llvm/Object/ObjectFile.h"
19#include "llvm/Support/MemoryBuffer.h"
20#include <map>
21#include <string>
22
23namespace llvm {
24
25using namespace object;
26
27namespace symbolize {
28
29class ModuleInfo;
30
31class LLVMSymbolizer {
32public:
33 struct Options {
34 bool UseSymbolTable : 1;
35 bool PrintFunctions : 1;
36 bool PrintInlining : 1;
37 bool Demangle : 1;
38 Options(bool UseSymbolTable = true, bool PrintFunctions = true,
39 bool PrintInlining = true, bool Demangle = true)
40 : UseSymbolTable(UseSymbolTable),
41 PrintFunctions(PrintFunctions),
42 PrintInlining(PrintInlining),
43 Demangle(Demangle) { }
44 };
45
46 LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) { }
47
48 // Returns the result of symbolization for module name/offset as
49 // a string (possibly containing newlines).
50 std::string symbolizeCode(const std::string &ModuleName,
51 uint64_t ModuleOffset);
52 std::string symbolizeData(const std::string &ModuleName,
53 uint64_t ModuleOffset);
54private:
55 ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName);
56 std::string printDILineInfo(DILineInfo LineInfo) const;
57 void DemangleName(std::string &Name) const;
58
59 typedef std::map<std::string, ModuleInfo*> ModuleMapTy;
60 ModuleMapTy Modules;
61 Options Opts;
Alexey Samsonov638c63c2013-02-04 15:55:26 +000062 static const char kBadString[];
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +000063};
64
65class ModuleInfo {
66 OwningPtr<ObjectFile> Module;
67 OwningPtr<DIContext> DebugInfoContext;
68 public:
69 ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
70 : Module(Obj), DebugInfoContext(DICtx) {}
71
72 DILineInfo symbolizeCode(
73 uint64_t ModuleOffset, const LLVMSymbolizer::Options& Opts) const;
74 DIInliningInfo symbolizeInlinedCode(
75 uint64_t ModuleOffset, const LLVMSymbolizer::Options& Opts) const;
76 bool symbolizeData(uint64_t ModuleOffset, std::string &Name,
77 uint64_t &Start, uint64_t &Size) const;
78
79 private:
80 bool getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
81 std::string &Name, uint64_t &Addr,
82 uint64_t &Size) const;
83};
84
85} // namespace symbolize
86} // namespace llvm
87
88#endif // LLVM_SYMBOLIZE_H