Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 32e078b

Browse files
committed
[LLVMSymbolize] Move ModuleInfo into a separate class (SymbolizableModule).
Summary: This is mostly NFC. It is a first step in cleaning up LLVMSymbolize library. It removes "ModuleInfo" class which bundles together ObjectFile and its debug info context in favor of: * abstract SymbolizableModule in public headers; * SymbolizableObjectFile subclass in implementation. Additionally, SymbolizableObjectFile is now created via factory, so we can properly detect object parsing error at this stage instead of keeping the broken half-parsed object. As a next step, we would be able to propagate the error all the way back to the library user. Further improvements might include: * factoring out the logic of finding appropriate file with debug info for a given object file, and caching all parsed object files into a separate class [A]. * factoring out DILineInfo rendering [B]. This would make what is now a heavyweight "LLVMSymbolizer" a relatively straightforward class, that calls into [A] to turn filepath into a SymbolizableModule, delegates actual symbolization to concrete SymbolizableModule implementation, and lets [C] render the result. Reviewers: dblaikie, echristo, rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14099 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251662 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d97fb08 commit 32e078b

File tree

6 files changed

+416
-270
lines changed

6 files changed

+416
-270
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===-- SymbolizableModule.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+
// This file declares the SymbolizableModule interface.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
#ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H
14+
#define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H
15+
16+
#include "llvm/DebugInfo/DIContext.h"
17+
#include <memory>
18+
#include <string>
19+
20+
namespace llvm {
21+
namespace object {
22+
class ObjectFile;
23+
}
24+
}
25+
26+
namespace llvm {
27+
namespace symbolize {
28+
29+
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
30+
31+
class SymbolizableModule {
32+
public:
33+
virtual ~SymbolizableModule() {}
34+
virtual DILineInfo symbolizeCode(uint64_t ModuleOffset,
35+
FunctionNameKind FNKind,
36+
bool UseSymbolTable) const = 0;
37+
virtual DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,
38+
FunctionNameKind FNKind,
39+
bool UseSymbolTable) const = 0;
40+
virtual bool symbolizeData(uint64_t ModuleOffset, std::string &Name,
41+
uint64_t &Start, uint64_t &Size) const = 0;
42+
43+
// Return true if this is a 32-bit x86 PE COFF module.
44+
virtual bool isWin32Module() const = 0;
45+
46+
// Returns the preferred base of the module, i.e. where the loader would place
47+
// it in memory assuming there were no conflicts.
48+
virtual uint64_t getModulePreferredBase() const = 0;
49+
};
50+
51+
} // namespace symbolize
52+
} // namespace llvm
53+
54+
#endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H

include/llvm/DebugInfo/Symbolize/Symbolize.h

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
#include "llvm/ADT/SmallVector.h"
1717
#include "llvm/DebugInfo/DIContext.h"
18+
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
1819
#include "llvm/Object/MachOUniversal.h"
1920
#include "llvm/Object/ObjectFile.h"
20-
#include "llvm/Support/DataExtractor.h"
2121
#include "llvm/Support/MemoryBuffer.h"
2222
#include <map>
2323
#include <memory>
@@ -28,7 +28,6 @@ namespace symbolize {
2828

2929
using namespace object;
3030
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
31-
class ModuleInfo;
3231

3332
class LLVMSymbolizer {
3433
public:
@@ -61,13 +60,15 @@ class LLVMSymbolizer {
6160
std::string
6261
symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset);
6362
void flush();
64-
static std::string DemangleName(const std::string &Name, ModuleInfo *ModInfo);
63+
static std::string DemangleName(const std::string &Name,
64+
const SymbolizableModule *ModInfo);
6565

6666
private:
6767
typedef std::pair<ObjectFile*, ObjectFile*> ObjectPair;
6868

69-
ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName);
70-
ObjectFile *lookUpDsymFile(const std::string &Path, const MachOObjectFile *ExeObj,
69+
SymbolizableModule *getOrCreateModuleInfo(const std::string &ModuleName);
70+
ObjectFile *lookUpDsymFile(const std::string &Path,
71+
const MachOObjectFile *ExeObj,
7172
const std::string &ArchName);
7273

7374
/// \brief Returns pair of pointers to object and debug object.
@@ -77,7 +78,8 @@ class LLVMSymbolizer {
7778
/// universal binary (or the binary itself if it is an object file).
7879
ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName);
7980

80-
std::string printDILineInfo(DILineInfo LineInfo, ModuleInfo *ModInfo) const;
81+
std::string printDILineInfo(DILineInfo LineInfo,
82+
const SymbolizableModule *ModInfo) const;
8183

8284
// Owns all the parsed binaries and object files.
8385
SmallVector<std::unique_ptr<Binary>, 4> ParsedBinariesAndObjects;
@@ -90,7 +92,7 @@ class LLVMSymbolizer {
9092
MemoryBuffers.push_back(std::move(MemBuf));
9193
}
9294

93-
std::map<std::string, std::unique_ptr<ModuleInfo>> Modules;
95+
std::map<std::string, std::unique_ptr<SymbolizableModule>> Modules;
9496
std::map<std::pair<MachOUniversalBinary *, std::string>, ObjectFile *>
9597
ObjectFileForArch;
9698
std::map<std::pair<std::string, std::string>, ObjectPair>
@@ -100,51 +102,6 @@ class LLVMSymbolizer {
100102
static const char kBadString[];
101103
};
102104

103-
class ModuleInfo {
104-
public:
105-
ModuleInfo(ObjectFile *Obj, std::unique_ptr<DIContext> DICtx);
106-
107-
DILineInfo symbolizeCode(uint64_t ModuleOffset, FunctionNameKind FNKind,
108-
bool UseSymbolTable) const;
109-
DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,
110-
FunctionNameKind FNKind,
111-
bool UseSymbolTable) const;
112-
bool symbolizeData(uint64_t ModuleOffset, std::string &Name, uint64_t &Start,
113-
uint64_t &Size) const;
114-
115-
// Return true if this is a 32-bit x86 PE COFF module.
116-
bool isWin32Module() const;
117-
118-
// Returns the preferred base of the module, i.e. where the loader would place
119-
// it in memory assuming there were no conflicts.
120-
uint64_t getModulePreferredBase() const;
121-
122-
private:
123-
bool getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
124-
std::string &Name, uint64_t &Addr,
125-
uint64_t &Size) const;
126-
// For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
127-
// (function descriptor) section and OpdExtractor refers to its contents.
128-
void addSymbol(const SymbolRef &Symbol, uint64_t SymbolSize,
129-
DataExtractor *OpdExtractor = nullptr,
130-
uint64_t OpdAddress = 0);
131-
void addCoffExportSymbols(const COFFObjectFile *CoffObj);
132-
ObjectFile *Module;
133-
std::unique_ptr<DIContext> DebugInfoContext;
134-
135-
struct SymbolDesc {
136-
uint64_t Addr;
137-
// If size is 0, assume that symbol occupies the whole memory range up to
138-
// the following symbol.
139-
uint64_t Size;
140-
friend bool operator<(const SymbolDesc &s1, const SymbolDesc &s2) {
141-
return s1.Addr < s2.Addr;
142-
}
143-
};
144-
std::map<SymbolDesc, StringRef> Functions;
145-
std::map<SymbolDesc, StringRef> Objects;
146-
};
147-
148105
} // namespace symbolize
149106
} // namespace llvm
150107

lib/DebugInfo/Symbolize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_llvm_library(LLVMSymbolize
2+
SymbolizableObjectFile.cpp
23
Symbolize.cpp
34

45
ADDITIONAL_HEADER_DIRS

0 commit comments

Comments
 (0)