llvm-symbolizer: make name demangling a public static method of LLVMSymbolizer

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185143 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2013-06-28 12:06:25 +00:00
parent 4157466bdc
commit c071f89a77
2 changed files with 11 additions and 9 deletions

View File

@ -187,8 +187,8 @@ std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
uint64_t Size = 0; uint64_t Size = 0;
if (Opts.UseSymbolTable) { if (Opts.UseSymbolTable) {
if (ModuleInfo *Info = getOrCreateModuleInfo(ModuleName)) { if (ModuleInfo *Info = getOrCreateModuleInfo(ModuleName)) {
if (Info->symbolizeData(ModuleOffset, Name, Start, Size)) if (Info->symbolizeData(ModuleOffset, Name, Start, Size) && Opts.Demangle)
DemangleName(Name); Name = DemangleName(Name);
} }
} }
std::stringstream ss; std::stringstream ss;
@ -303,7 +303,8 @@ std::string LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo) const {
std::string FunctionName = LineInfo.getFunctionName(); std::string FunctionName = LineInfo.getFunctionName();
if (FunctionName == kDILineInfoBadString) if (FunctionName == kDILineInfoBadString)
FunctionName = kBadString; FunctionName = kBadString;
DemangleName(FunctionName); else if (Opts.Demangle)
FunctionName = DemangleName(FunctionName);
Result << FunctionName << "\n"; Result << FunctionName << "\n";
} }
std::string Filename = LineInfo.getFileName(); std::string Filename = LineInfo.getFileName();
@ -320,16 +321,17 @@ extern "C" char *__cxa_demangle(const char *mangled_name, char *output_buffer,
size_t *length, int *status); size_t *length, int *status);
#endif #endif
void LLVMSymbolizer::DemangleName(std::string &Name) const { std::string LLVMSymbolizer::DemangleName(const std::string &Name) {
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
if (!Opts.Demangle)
return;
int status = 0; int status = 0;
char *DemangledName = __cxa_demangle(Name.c_str(), 0, 0, &status); char *DemangledName = __cxa_demangle(Name.c_str(), 0, 0, &status);
if (status != 0) if (status != 0)
return; return Name;
Name = DemangledName; std::string Result = DemangledName;
free(DemangledName); free(DemangledName);
return Result;
#else
return Name;
#endif #endif
} }

View File

@ -56,6 +56,7 @@ public:
std::string std::string
symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset); symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset);
void flush(); void flush();
static std::string DemangleName(const std::string &Name);
private: private:
typedef std::pair<Binary*, Binary*> BinaryPair; typedef std::pair<Binary*, Binary*> BinaryPair;
@ -67,7 +68,6 @@ private:
ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName); ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName);
std::string printDILineInfo(DILineInfo LineInfo) const; std::string printDILineInfo(DILineInfo LineInfo) const;
void DemangleName(std::string &Name) const;
// Owns all the parsed binaries and object files. // Owns all the parsed binaries and object files.
SmallVector<Binary*, 4> ParsedBinariesAndObjects; SmallVector<Binary*, 4> ParsedBinariesAndObjects;