Skip to content

Commit 6b65f98

Browse files
committed
[symbolizer] Address starting with a plus sign is valid.
this is also the same behaviour in gnu addr2line. Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
1 parent 85a6bed commit 6b65f98

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

llvm/test/tools/llvm-symbolizer/symbol-search.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-p
6565
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-prefix=NONEXISTENT %s
6666

6767
# If '+' is not preceded by a symbol, it is part of a symbol name, not an offset separator.
68-
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=NONEXISTENT %s
69-
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=NONEXISTENT %s
68+
# address starting with a `+` sign is a valid address
69+
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=CODE-CMD %s
70+
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=CODE-CMD %s
7071

7172
# Show that C++ mangled names may be specified.
7273
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so _ZL14static_func_01i | FileCheck --check-prefix=MULTI-CXX %s

llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,12 @@ static Error parseCommand(StringRef BinaryName, bool IsAddr2Line,
238238
bool StartsWithDigit = std::isdigit(AddrSpec.front());
239239

240240
// GNU addr2line assumes the address is hexadecimal and allows a redundant
241-
// "0x" or "0X" prefix; do the same for compatibility.
242-
if (IsAddr2Line)
243-
AddrSpec.consume_front("0x") || AddrSpec.consume_front("0X");
241+
// "0x" or "0X" prefix or with an optional `+` sign; do the same for
242+
// compatibility.
243+
if (IsAddr2Line) {
244+
AddrSpec.consume_front_insensitive("0x") ||
245+
AddrSpec.consume_front_insensitive("+0x");
246+
}
244247

245248
// If address specification is a number, treat it as a module offset.
246249
if (!AddrSpec.getAsInteger(IsAddr2Line ? 16 : 0, Offset)) {

0 commit comments

Comments
 (0)