Index: llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst =================================================================== --- llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst +++ llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst @@ -123,6 +123,12 @@ Strip directories when printing the file path. +.. option:: -adjust-vma= + + Add the specified offset to object file addresses when performing lookups. This + can be used to simplify lookups when the object is not loaded at a dynamically + relocated address. + EXIT STATUS ----------- Index: llvm/trunk/test/tools/llvm-symbolizer/adjust-vma.s =================================================================== --- llvm/trunk/test/tools/llvm-symbolizer/adjust-vma.s +++ llvm/trunk/test/tools/llvm-symbolizer/adjust-vma.s @@ -0,0 +1,39 @@ +# REQUIRES: x86-registered-target + +.type foo,@function +.size foo,12 +foo: + .space 10 + nop + nop + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -g + +# RUN: llvm-symbolizer 0xa 0xb --print-address --obj=%t.o \ +# RUN: | FileCheck %s --check-prefix=NORMAL +# RUN: llvm-symbolizer 0x10a 0x10b --print-address --adjust-vma 0x100 --obj=%t.o \ +# RUN: | FileCheck %s --check-prefix=ADJUST + +# Show that we can handle addresses less than the offset. +# RUN: llvm-symbolizer 0xa 0xb --print-address --adjust-vma 0xc --obj=%t.o \ +# RUN: | FileCheck %s --check-prefix=OVERFLOW + +# NORMAL: 0xa +# NORMAL-NEXT: foo +# NORMAL-NEXT: adjust-vma.s:7:0 +# NORMAL-EMPTY: +# NORMAL-NEXT: 0xb +# NORMAL-NEXT: foo +# NORMAL-NEXT: adjust-vma.s:8:0 + +# ADJUST: 0x10a +# ADJUST-NEXT: foo +# ADJUST-NEXT: adjust-vma.s:7:0 +# ADJUST-EMPTY: +# ADJUST-NEXT: 0x10b +# ADJUST-NEXT: foo +# ADJUST-NEXT: adjust-vma.s:8:0 + +# OVERFLOW: 0xa +# OVERFLOW-NEXT: ?? +# OVERFLOW-NEXT: ?? Index: llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp =================================================================== --- llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -134,6 +134,11 @@ static cl::opt ClVerbose("verbose", cl::init(false), cl::desc("Print verbose line info")); +// -adjust-vma +static cl::opt + ClAdjustVMA("adjust-vma", cl::init(0), cl::value_desc("offset"), + cl::desc("Add specified offset to object file addresses")); + static cl::list ClInputAddresses(cl::Positional, cl::desc("..."), cl::ZeroOrMore); @@ -201,6 +206,7 @@ StringRef Delimiter = ClPrettyPrint ? ": " : "\n"; outs() << Delimiter; } + ModuleOffset -= ClAdjustVMA; if (IsData) { auto ResOrErr = Symbolizer.symbolizeData(ModuleName, ModuleOffset); Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get());