Skip to content

Commit a5fe6c7

Browse files
committed
[symbolizer] Change reaction on invalid input
If llvm-symbolizer finds a malformed command, it echoes it to the standard output. New versions of binutils (starting from 2.39) allow to specify an address by a symbols. Implementation of this feature in llvm-symbolizer makes the current reaction on invalid input inappropriate. Almost any invalid command may be treated as a symbol name, so the right reaction should be "symbol not found" in such case. The exception are commands that are recognized but have incorrect syntax, like "FILE:FILE:". The utility must produce descriptive diagnostic for such input and route it to the stderr. This change implements the new reaction on invalid input and is a prerequisite for implementation of symbol lookup in llvm-symbolizer. Differential Revision: https://reviews.llvm.org/D157210
1 parent db11fd8 commit a5fe6c7

File tree

19 files changed

+117
-104
lines changed

19 files changed

+117
-104
lines changed

llvm/docs/CommandGuide/llvm-symbolizer.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ symbolize logs containing :doc:`Symbolizer Markup </SymbolizerMarkupFormat>` via
1818

1919
If no address is specified on the command-line, it reads the addresses from
2020
standard input. If no input name is specified on the command-line, but addresses
21-
are, or if at any time an input value is not recognized, the input is simply
22-
echoed to the output.
21+
are, the first address value is treated as an input name. If an input value is not
22+
recognized, it reports that source information is not found.
2323

2424
Input names can be specified together with the addresses either on standard
2525
input or as positional arguments on the command-line. By default, input names

llvm/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ Changes to the Debug Info
148148
Changes to the LLVM tools
149149
---------------------------------
150150

151+
* llvm-symbolizer now treats invalid input as an address for which source
152+
information is not found.
153+
151154
Changes to LLDB
152155
---------------------------------
153156

llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class DIPrinter {
4747
virtual void print(const Request &Request,
4848
const std::vector<DILocal> &Locals) = 0;
4949

50-
virtual void printInvalidCommand(const Request &Request,
51-
StringRef Command) = 0;
52-
5350
virtual bool printError(const Request &Request,
5451
const ErrorInfoBase &ErrorInfo) = 0;
5552

@@ -83,7 +80,7 @@ class PlainPrinterBase : public DIPrinter {
8380
virtual void printFooter() {}
8481

8582
private:
86-
void printHeader(uint64_t Address);
83+
void printHeader(std::optional<uint64_t> Address);
8784

8885
public:
8986
PlainPrinterBase(raw_ostream &OS, ErrorHandler EH, PrinterConfig &Config)
@@ -95,8 +92,6 @@ class PlainPrinterBase : public DIPrinter {
9592
void print(const Request &Request,
9693
const std::vector<DILocal> &Locals) override;
9794

98-
void printInvalidCommand(const Request &Request, StringRef Command) override;
99-
10095
bool printError(const Request &Request,
10196
const ErrorInfoBase &ErrorInfo) override;
10297

@@ -147,8 +142,6 @@ class JSONPrinter : public DIPrinter {
147142
void print(const Request &Request,
148143
const std::vector<DILocal> &Locals) override;
149144

150-
void printInvalidCommand(const Request &Request, StringRef Command) override;
151-
152145
bool printError(const Request &Request,
153146
const ErrorInfoBase &ErrorInfo) override;
154147

llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ class SourceCode {
105105
}
106106
};
107107

108-
void PlainPrinterBase::printHeader(uint64_t Address) {
109-
if (Config.PrintAddress) {
108+
void PlainPrinterBase::printHeader(std::optional<uint64_t> Address) {
109+
if (Address.has_value() && Config.PrintAddress) {
110110
OS << "0x";
111-
OS.write_hex(Address);
111+
OS.write_hex(*Address);
112112
StringRef Delimiter = Config.Pretty ? ": " : "\n";
113113
OS << Delimiter;
114114
}
@@ -182,7 +182,7 @@ void PlainPrinterBase::print(const DILineInfo &Info, bool Inlined) {
182182
}
183183

184184
void PlainPrinterBase::print(const Request &Request, const DILineInfo &Info) {
185-
printHeader(*Request.Address);
185+
printHeader(Request.Address);
186186
print(Info, false);
187187
printFooter();
188188
}
@@ -260,11 +260,6 @@ void PlainPrinterBase::print(const Request &Request,
260260
printFooter();
261261
}
262262

263-
void PlainPrinterBase::printInvalidCommand(const Request &Request,
264-
StringRef Command) {
265-
OS << Command << '\n';
266-
}
267-
268263
bool PlainPrinterBase::printError(const Request &Request,
269264
const ErrorInfoBase &ErrorInfo) {
270265
ErrHandler(ErrorInfo, Request.ModuleName);
@@ -367,13 +362,6 @@ void JSONPrinter::print(const Request &Request,
367362
printJSON(std::move(Json));
368363
}
369364

370-
void JSONPrinter::printInvalidCommand(const Request &Request,
371-
StringRef Command) {
372-
printError(Request,
373-
StringError("unable to parse arguments: " + Command,
374-
std::make_error_code(std::errc::invalid_argument)));
375-
}
376-
377365
bool JSONPrinter::printError(const Request &Request,
378366
const ErrorInfoBase &ErrorInfo) {
379367
json::Object Json = toJSON(Request, ErrorInfo.message());

llvm/test/tools/llvm-symbolizer/debuginfod.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ RUN: FileCheck %s --check-prefix=FOUND
3939

4040
# Passing BUILDID twice is a syntax error.
4141
RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
42-
RUN: "BUILDID:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" | \
42+
RUN: "BUILDID:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" 2>&1| \
4343
RUN: FileCheck %s --check-prefix=BUILDIDBUILDID
44-
BUILDIDBUILDID: BUILDID:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d
44+
BUILDIDBUILDID: llvm-symbolizer{{.*}}: error: 'BUILDID:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d': duplicate input file specification prefix
4545

4646
# CODE should work preceding build ID.
4747
RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
@@ -63,16 +63,16 @@ NOTHINGFOUND-NEXT: ??:0:0
6363
# BUILDID shouldn't be parsed if --obj is given, just like regular filenames.
6464
RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
6565
RUN: --obj=%t/addr.exe \
66-
RUN: "BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" | \
66+
RUN: "BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" 2>&1 | \
6767
RUN: FileCheck %s --check-prefix=BUILDIDIGNORED
68-
BUILDIDIGNORED: BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d
68+
BUILDIDIGNORED: llvm-symbolizer{{.*}}: error: 'BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d': input file is already specified
6969

7070
# Providing both BUILDID and FILE is a syntax error.
7171
RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
72-
RUN: "BUILDID:FILE:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" | \
72+
RUN: "BUILDID:FILE:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" 2>&1 | \
7373
RUN: FileCheck %s --check-prefix=BUILDIDFILE
74-
BUILDIDFILE: BUILDID:FILE:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d
74+
BUILDIDFILE: llvm-symbolizer{{.*}}: error: 'BUILDID:FILE:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d': duplicate input file specification prefix
7575
RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-symbolizer \
76-
RUN: "FILE:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" | \
76+
RUN: "FILE:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d" 2>&1 | \
7777
RUN: FileCheck %s --check-prefix=FILEBUILDID
78-
FILEBUILDID: FILE:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d
78+
FILEBUILDID: llvm-symbolizer{{.*}}: error: 'FILE:BUILDID:127da749021c1fc1a58cba734a1f542cbe2b7ce4 0x40054d': duplicate input file specification prefix

llvm/test/tools/llvm-symbolizer/file-prefix.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ RUN: FileCheck %s --check-prefix=FOUND
44
FOUND: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
55

66
# Passing FILE twice is a syntax error.
7-
RUN: llvm-symbolizer "CODE FILE:FILE:%p/Inputs/addr.exe 0x40054d" | \
8-
RUN: FileCheck %s --check-prefix=FILEFILE
9-
FILEFILE: CODE FILE:FILE:{{.*}}/Inputs/addr.exe 0x40054d
7+
RUN: llvm-symbolizer "CODE FILE:FILE:%p/Inputs/addr.exe 0x40054d" 2>%t.err | count 0
8+
RUN: FileCheck %s --check-prefix=FILEFILE --input-file %t.err
9+
FILEFILE: llvm-symbolizer{{.*}}: error: 'CODE FILE:FILE:{{.*}}/Inputs/addr.exe 0x40054d': duplicate input file specification prefix

llvm/test/tools/llvm-symbolizer/flag-grouping.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ RUN: llvm-symbolizer -apCie %p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck
33
RUN: llvm-symbolizer -apCie=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
44
RUN: llvm-symbolizer -apCie%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
55

6-
CHECK: some text
6+
CHECK: ?? at ??:0:0
77
CHECK: 0x40054d: inctwo
88
CHECK: (inlined by) inc
99
CHECK (inlined by) main
10-
CHECK: some text2
10+
CHECK: ?? at ??:0:0

llvm/test/tools/llvm-symbolizer/flush-output.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ foo:
1414
# RUN: | FileCheck %s
1515

1616
# CHECK: flush-output.s:10
17-
# CHECK: bad
17+
# CHECK: ??:0

llvm/test/tools/llvm-symbolizer/functions.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
# NONE-NOT: foo
2727
# NONE: functions.cpp:2:0
2828

29-
# ERR: none
29+
# ERR: ??
30+
# ERR-NEXT: ??:0
3031

3132
# The assembly below is a stripped down version of the output of:
3233
# clang -S -g --target=x86_64-pc-linux

llvm/test/tools/llvm-symbolizer/input-base.test

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN: llvm-symbolizer -e %p/Inputs/addr.exe -a 0B1001000110100 | FileCheck %s
88
RUN: llvm-symbolizer -e %p/Inputs/addr.exe -a 0o11064 | FileCheck %s
99

1010
# llvm-symbolizer / StringRef::getAsInteger only accepts the 0o prefix in lowercase.
11-
RUN: llvm-symbolizer -e %p/Inputs/addr.exe -a 0O1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL-UPPER
11+
RUN: llvm-symbolizer -e %p/Inputs/addr.exe -a 0O1234 | FileCheck %s --check-prefix=INVALID
1212

1313
# llvm-addr2line always requires hexadecimal, but accepts an optional 0x prefix.
1414
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 0x1234 | FileCheck %s
@@ -17,17 +17,16 @@ RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 1234 | FileCheck %s
1717
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 01234 | FileCheck %s
1818
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 0b1010 | FileCheck %s --check-prefix=HEXADECIMAL-NOT-BINARY
1919
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 0B1010 | FileCheck %s --check-prefix=HEXADECIMAL-NOT-BINARY
20-
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 0o1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL-LOWER
21-
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 0O1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL-UPPER
20+
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 0o1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL
21+
RUN: llvm-addr2line -e %p/Inputs/addr.exe -a 0O1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL
2222

2323
CHECK: 0x1234
2424
CHECK-NEXT: ??
2525

26+
INVALID: ??
27+
INVALID-NEXT: ??:0
28+
2629
HEXADECIMAL-NOT-BINARY: 0xb1010
2730
HEXADECIMAL-NOT-BINARY: ??
2831

29-
INVALID-NOT-OCTAL-LOWER: 0o1234
30-
INVALID-NOT-OCTAL-LOWER-NOT: ??
31-
32-
INVALID-NOT-OCTAL-UPPER: 0O1234
33-
INVALID-NOT-OCTAL-UPPER-NOT: ??
32+
INVALID-NOT-OCTAL: ??:0

0 commit comments

Comments
 (0)