[llvm-symbolizer] Print out non-address lines verbatim.

Differential Revision: http://reviews.llvm.org/D15876

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257115 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mike Aizatsky 2016-01-07 23:57:41 +00:00
parent a1505f1072
commit ba07fc7f19
4 changed files with 30 additions and 16 deletions

View File

@ -11,9 +11,9 @@ DESCRIPTION
:program:`llvm-symbolizer` reads object file names and addresses from standard
input and prints corresponding source code locations to standard output.
If object file is specified in command line, :program:`llvm-symbolizer` reads
only addresses from standard input. This
program uses debug info sections and symbol table in the object files.
If object file is specified in command line, :program:`llvm-symbolizer`
processes only addresses from standard input, the rest is output verbatim.
This program uses debug info sections and symbol table in the object files.
EXAMPLE
--------

View File

@ -1 +1,3 @@
some text
0x40054d
some text2

View File

@ -20,11 +20,15 @@
RUN: llvm-symbolizer -print-address -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
RUN: llvm-symbolizer -inlining -print-address -pretty-print -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck --check-prefix="PRETTY" %s
#CHECK: some text
#CHECK: 0x40054d
#CHECK: main
#CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
#CHECK: some text2
#
#PRETTY: some text
#PRETTY: {{[0x]+}}40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3:3
#PRETTY: (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7:0
#PRETTY (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14:0
#PRETTY: some text2

View File

@ -89,18 +89,14 @@ static bool error(std::error_code ec) {
return true;
}
static bool parseCommand(bool &IsData, std::string &ModuleName,
uint64_t &ModuleOffset) {
static bool parseCommand(StringRef InputString, bool &IsData,
std::string &ModuleName, uint64_t &ModuleOffset) {
const char *kDataCmd = "DATA ";
const char *kCodeCmd = "CODE ";
const int kMaxInputStringLength = 1024;
const char kDelimiters[] = " \n";
char InputString[kMaxInputStringLength];
if (!fgets(InputString, sizeof(InputString), stdin))
return false;
const char kDelimiters[] = " \n\r";
IsData = false;
ModuleName = "";
char *pos = InputString;
const char *pos = InputString.data();
if (strncmp(pos, kDataCmd, strlen(kDataCmd)) == 0) {
IsData = true;
pos += strlen(kDataCmd);
@ -117,7 +113,7 @@ static bool parseCommand(bool &IsData, std::string &ModuleName,
if (*pos == '"' || *pos == '\'') {
char quote = *pos;
pos++;
char *end = strchr(pos, quote);
const char *end = strchr(pos, quote);
if (!end)
return false;
ModuleName = std::string(pos, end - pos);
@ -158,13 +154,25 @@ int main(int argc, char **argv) {
}
LLVMSymbolizer Symbolizer(Opts);
bool IsData = false;
std::string ModuleName;
uint64_t ModuleOffset;
DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None,
ClPrettyPrint);
while (parseCommand(IsData, ModuleName, ModuleOffset)) {
const int kMaxInputStringLength = 1024;
char InputString[kMaxInputStringLength];
while (true) {
if (!fgets(InputString, sizeof(InputString), stdin))
break;
bool IsData = false;
std::string ModuleName;
uint64_t ModuleOffset = 0;
if (!parseCommand(StringRef(InputString), IsData, ModuleName,
ModuleOffset)) {
outs() << InputString;
continue;
}
if (ClPrintAddress) {
outs() << "0x";
outs().write_hex(ModuleOffset);