summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-09-21 10:54:14 +0000
committerAlexey Samsonov <samsonov@google.com>2012-09-21 10:54:14 +0000
commit26ce094b819e51773eb1e0f9b80bfc70c44cf37d (patch)
treed78bb7bd07d931cf8cf98155674ba280a7da8b22 /utils
parent47a953e75f0dd4ce91da5c6bb0e87490727a59e6 (diff)
[Sanitizer] llvm-symbolizer: enable accessing symbol table (libObject is fixed in r164365) and replace string with std::string
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@164367 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/llvm-symbolizer/llvm-symbolizer.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/utils/llvm-symbolizer/llvm-symbolizer.cpp b/utils/llvm-symbolizer/llvm-symbolizer.cpp
index fb52247de..199690ac3 100644
--- a/utils/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/utils/llvm-symbolizer/llvm-symbolizer.cpp
@@ -34,12 +34,9 @@
using namespace llvm;
using namespace object;
-using std::string;
-// FIXME: Enable --use-symbol-table by default when the bug in libObject's
-// Symbol::getAddress is fixed.
static cl::opt<bool>
-UseSymbolTable("use-symbol-table", cl::init(false),
+UseSymbolTable("use-symbol-table", cl::init(true),
cl::desc("Prefer names in symbol table to names "
"in debug info"));
@@ -73,9 +70,9 @@ static uint32_t getDILineInfoSpecifierFlags() {
return Flags;
}
-static void patchFunctionNameInDILineInfo(const string &NewFunctionName,
+static void patchFunctionNameInDILineInfo(const std::string &NewFunctionName,
DILineInfo &LineInfo) {
- string FileName = LineInfo.getFileName();
+ std::string FileName = LineInfo.getFileName();
LineInfo = DILineInfo(StringRef(FileName), StringRef(NewFunctionName),
LineInfo.getLine(), LineInfo.getColumn());
}
@@ -95,7 +92,7 @@ class ModuleInfo {
}
// Override function name from symbol table if necessary.
if (PrintFunctions && UseSymbolTable) {
- string Function;
+ std::string Function;
if (getFunctionNameFromSymbolTable(ModuleOffset, Function)) {
patchFunctionNameInDILineInfo(Function, LineInfo);
}
@@ -119,7 +116,7 @@ class ModuleInfo {
i != n; i++) {
DILineInfo LineInfo = InlinedContext.getFrame(i);
if (i == n - 1) {
- string Function;
+ std::string Function;
if (getFunctionNameFromSymbolTable(ModuleOffset, Function)) {
patchFunctionNameInDILineInfo(Function, LineInfo);
}
@@ -132,7 +129,7 @@ class ModuleInfo {
}
private:
bool getFunctionNameFromSymbolTable(size_t Address,
- string &FunctionName) const {
+ std::string &FunctionName) const {
assert(Module);
error_code ec;
for (symbol_iterator si = Module->begin_symbols(),
@@ -156,7 +153,7 @@ class ModuleInfo {
}
};
-typedef std::map<string, ModuleInfo*> ModuleMapTy;
+typedef std::map<std::string, ModuleInfo*> ModuleMapTy;
typedef ModuleMapTy::iterator ModuleMapIter;
typedef ModuleMapTy::const_iterator ModuleMapConstIter;
} // namespace
@@ -183,7 +180,7 @@ static bool getObjectEndianness(const ObjectFile *Obj,
return true;
}
-static ModuleInfo *getOrCreateModuleInfo(const string &ModuleName) {
+static ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName) {
ModuleMapIter I = Modules.find(ModuleName);
if (I != Modules.end())
return I->second;
@@ -250,10 +247,10 @@ extern "C" char *__cxa_demangle(const char *mangled_name, char *output_buffer,
static void printDILineInfo(DILineInfo LineInfo) {
// By default, DILineInfo contains "<invalid>" for function/filename it
// cannot fetch. We replace it to "??" to make our output closer to addr2line.
- static const string kDILineInfoBadString = "<invalid>";
- static const string kSymbolizerBadString = "??";
+ static const std::string kDILineInfoBadString = "<invalid>";
+ static const std::string kSymbolizerBadString = "??";
if (PrintFunctions) {
- string FunctionName = LineInfo.getFunctionName();
+ std::string FunctionName = LineInfo.getFunctionName();
if (FunctionName == kDILineInfoBadString)
FunctionName = kSymbolizerBadString;
if (Demangle) {
@@ -267,7 +264,7 @@ static void printDILineInfo(DILineInfo LineInfo) {
}
outs() << FunctionName << "\n";
}
- string Filename = LineInfo.getFileName();
+ std::string Filename = LineInfo.getFileName();
if (Filename == kDILineInfoBadString)
Filename = kSymbolizerBadString;
outs() << Filename <<
@@ -276,7 +273,7 @@ static void printDILineInfo(DILineInfo LineInfo) {
"\n";
}
-static void symbolize(string ModuleName, string ModuleOffsetStr) {
+static void symbolize(std::string ModuleName, std::string ModuleOffsetStr) {
ModuleInfo *Info = getOrCreateModuleInfo(ModuleName);
uint64_t Offset = 0;
if (Info == 0 ||
@@ -299,8 +296,8 @@ static void symbolize(string ModuleName, string ModuleOffsetStr) {
outs().flush();
}
-static bool parseModuleNameAndOffset(string &ModuleName,
- string &ModuleOffsetStr) {
+static bool parseModuleNameAndOffset(std::string &ModuleName,
+ std::string &ModuleOffsetStr) {
static const int kMaxInputStringLength = 1024;
static const char kDelimiters[] = " \n";
char InputString[kMaxInputStringLength];
@@ -326,8 +323,8 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, "llvm symbolizer for compiler-rt\n");
ToolInvocationPath = argv[0];
- string ModuleName;
- string ModuleOffsetStr;
+ std::string ModuleName;
+ std::string ModuleOffsetStr;
while (parseModuleNameAndOffset(ModuleName, ModuleOffsetStr)) {
symbolize(ModuleName, ModuleOffsetStr);
}