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

Commit ff7c978

Browse files
committed
[LLVMSymbolize] Move printing the description of a global into a separate function. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251669 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b0ed17b commit ff7c978

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

include/llvm/DebugInfo/DIContext.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ class DIInliningInfo {
6565
}
6666
};
6767

68+
/// DIGlobal - container for description of a global variable.
69+
struct DIGlobal {
70+
std::string Name;
71+
uint64_t Start;
72+
uint64_t Size;
73+
74+
DIGlobal() : Name("<invalid>"), Start(0), Size(0) {}
75+
};
76+
6877
/// A DINameKind is passed to name search methods to specify a
6978
/// preference regarding the type of name resolution the caller wants.
7079
enum class DINameKind { None, ShortName, LinkageName };

include/llvm/DebugInfo/Symbolize/SymbolizableModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class SymbolizableModule {
3737
virtual DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,
3838
FunctionNameKind FNKind,
3939
bool UseSymbolTable) const = 0;
40-
virtual bool symbolizeData(uint64_t ModuleOffset, std::string &Name,
41-
uint64_t &Start, uint64_t &Size) const = 0;
40+
virtual DIGlobal symbolizeData(uint64_t ModuleOffset) const = 0;
4241

4342
// Return true if this is a 32-bit x86 PE COFF module.
4443
virtual bool isWin32Module() const = 0;

include/llvm/DebugInfo/Symbolize/Symbolize.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class LLVMSymbolizer {
8080

8181
std::string printDILineInfo(DILineInfo LineInfo,
8282
const SymbolizableModule *ModInfo) const;
83+
std::string printDIGlobal(DIGlobal Global,
84+
const SymbolizableModule *ModInfo) const;
8385

8486
// Owns all the parsed binaries and object files.
8587
SmallVector<std::unique_ptr<Binary>, 4> ParsedBinariesAndObjects;

lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ DIInliningInfo SymbolizableObjectFile::symbolizeInlinedCode(
239239
return PatchedInlinedContext;
240240
}
241241

242-
bool SymbolizableObjectFile::symbolizeData(uint64_t ModuleOffset,
243-
std::string &Name, uint64_t &Start,
244-
uint64_t &Size) const {
245-
return getNameFromSymbolTable(SymbolRef::ST_Data, ModuleOffset, Name, Start,
246-
Size);
242+
DIGlobal SymbolizableObjectFile::symbolizeData(uint64_t ModuleOffset) const {
243+
DIGlobal Res;
244+
getNameFromSymbolTable(SymbolRef::ST_Data, ModuleOffset, Res.Name, Res.Start,
245+
Res.Size);
246+
return Res;
247247
}
248248

249249
} // namespace symbolize

lib/DebugInfo/Symbolize/SymbolizableObjectFile.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class SymbolizableObjectFile : public SymbolizableModule {
3333
DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,
3434
FunctionNameKind FNKind,
3535
bool UseSymbolTable) const override;
36-
bool symbolizeData(uint64_t ModuleOffset, std::string &Name, uint64_t &Start,
37-
uint64_t &Size) const override;
36+
DIGlobal symbolizeData(uint64_t ModuleOffset) const override;
3837

3938
// Return true if this is a 32-bit x86 PE COFF module.
4039
bool isWin32Module() const override;

lib/DebugInfo/Symbolize/Symbolize.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ static bool error(std::error_code ec) {
5656
}
5757

5858

59+
// By default, DILineInfo contains "<invalid>" for function/filename it
60+
// cannot fetch. We replace it to "??" to make our output closer to addr2line.
61+
static const char kDILineInfoBadString[] = "<invalid>";
62+
5963
const char LLVMSymbolizer::kBadString[] = "??";
6064

6165
std::string LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
@@ -88,23 +92,18 @@ std::string LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
8892

8993
std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
9094
uint64_t ModuleOffset) {
91-
std::string Name = kBadString;
92-
uint64_t Start = 0;
93-
uint64_t Size = 0;
9495
if (Opts.UseSymbolTable) {
9596
if (SymbolizableModule *Info = getOrCreateModuleInfo(ModuleName)) {
9697
// If the user is giving us relative addresses, add the preferred base of
9798
// the object to the offset before we do the query. It's what DIContext
9899
// expects.
99100
if (Opts.RelativeAddresses)
100101
ModuleOffset += Info->getModulePreferredBase();
101-
if (Info->symbolizeData(ModuleOffset, Name, Start, Size) && Opts.Demangle)
102-
Name = DemangleName(Name, Info);
102+
DIGlobal Global = Info->symbolizeData(ModuleOffset);
103+
return printDIGlobal(Global, Info);
103104
}
104105
}
105-
std::stringstream ss;
106-
ss << Name << "\n" << Start << " " << Size << "\n";
107-
return ss.str();
106+
return printDIGlobal(DIGlobal(), nullptr);
108107
}
109108

110109
void LLVMSymbolizer::flush() {
@@ -359,9 +358,6 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
359358
std::string
360359
LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo,
361360
const SymbolizableModule *ModInfo) const {
362-
// By default, DILineInfo contains "<invalid>" for function/filename it
363-
// cannot fetch. We replace it to "??" to make our output closer to addr2line.
364-
static const std::string kDILineInfoBadString = "<invalid>";
365361
std::stringstream Result;
366362
if (Opts.PrintFunctions != FunctionNameKind::None) {
367363
std::string FunctionName = LineInfo.FunctionName;
@@ -378,6 +374,20 @@ LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo,
378374
return Result.str();
379375
}
380376

377+
std::string
378+
LLVMSymbolizer::printDIGlobal(DIGlobal Global,
379+
const SymbolizableModule *ModInfo) const {
380+
std::stringstream Result;
381+
std::string Name = Global.Name;
382+
if (Name == kDILineInfoBadString)
383+
Name = kBadString;
384+
else if (Opts.Demangle)
385+
Name = DemangleName(Name, ModInfo);
386+
Result << Name << "\n";
387+
Result << Global.Start << " " << Global.Size << "\n";
388+
return Result.str();
389+
}
390+
381391
// Undo these various manglings for Win32 extern "C" functions:
382392
// cdecl - _foo
383393
// stdcall - _foo@12
@@ -442,7 +452,7 @@ std::string LLVMSymbolizer::DemangleName(const std::string &Name,
442452
return (result == 0) ? Name : std::string(DemangledName);
443453
}
444454
#endif
445-
if (ModInfo->isWin32Module())
455+
if (ModInfo && ModInfo->isWin32Module())
446456
return std::string(demanglePE32ExternCFunc(Name));
447457
return Name;
448458
}

0 commit comments

Comments
 (0)