Skip to content

Commit 7b31a73

Browse files
committed
[Symbolizer] Ignore unknown additional symbolizer markup fields
The symbolizer markup syntax is structured such that fields require only previous fields for their interpretation; this was originally intended to make adding new fields a natural extension mechanism for existing elements. This codifies this into the spec and makes the behavior of the llvm-symbolizer match. Extra fields are now warned about, but ignored, rather than ignoring the whole element. Reviewed By: mcgrathr Differential Revision: https://reviews.llvm.org/D153821
1 parent 703c083 commit 7b31a73

File tree

6 files changed

+44
-31
lines changed

6 files changed

+44
-31
lines changed

llvm/docs/SymbolizerMarkupFormat.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ what they contain is specified for each element type.
143143
No markup elements or ANSI SGR control sequences are interpreted inside the
144144
contents of a field.
145145

146+
Implementations must ignore markup fields after those expected; this allows
147+
adding new fields to backwards-compatibly extend elements. Implementations need
148+
not ignore them silently, but the element should behave otherwise as if the
149+
fields were removed.
150+
146151
In the descriptions of each element type, ``printf``-style placeholders indicate
147152
field contents:
148153

llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class MarkupFilter {
123123
bool checkTag(const MarkupNode &Node) const;
124124
bool checkNumFields(const MarkupNode &Element, size_t Size) const;
125125
bool checkNumFieldsAtLeast(const MarkupNode &Element, size_t Size) const;
126-
bool checkNumFieldsAtMost(const MarkupNode &Element, size_t Size) const;
126+
void warnNumFieldsAtMost(const MarkupNode &Element, size_t Size) const;
127127

128128
void reportTypeError(StringRef Str, StringRef TypeName) const;
129129
void reportLocation(StringRef::iterator Loc) const;

llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ bool MarkupFilter::tryReset(const MarkupNode &Node,
133133
endAnyModuleInfoLine();
134134
for (const MarkupNode &Node : DeferredNodes)
135135
filterNode(Node);
136-
highlight();
137-
OS << "[[[reset]]]" << lineEnding();
138-
restoreColor();
136+
printRawElement(Node);
137+
OS << lineEnding();
139138

140139
Modules.clear();
141140
MMaps.clear();
@@ -239,8 +238,7 @@ bool MarkupFilter::tryPC(const MarkupNode &Node) {
239238
return false;
240239
if (!checkNumFieldsAtLeast(Node, 1))
241240
return true;
242-
if (!checkNumFieldsAtMost(Node, 2))
243-
return true;
241+
warnNumFieldsAtMost(Node, 2);
244242

245243
std::optional<uint64_t> Addr = parseAddr(Node.Fields[0]);
246244
if (!Addr)
@@ -293,8 +291,7 @@ bool MarkupFilter::tryBackTrace(const MarkupNode &Node) {
293291
return false;
294292
if (!checkNumFieldsAtLeast(Node, 2))
295293
return true;
296-
if (!checkNumFieldsAtMost(Node, 3))
297-
return true;
294+
warnNumFieldsAtMost(Node, 3);
298295

299296
std::optional<uint64_t> FrameNumber = parseFrameNumber(Node.Fields[0]);
300297
if (!FrameNumber)
@@ -655,10 +652,12 @@ bool MarkupFilter::checkTag(const MarkupNode &Node) const {
655652
bool MarkupFilter::checkNumFields(const MarkupNode &Element,
656653
size_t Size) const {
657654
if (Element.Fields.size() != Size) {
658-
WithColor::error(errs()) << "expected " << Size << " field(s); found "
659-
<< Element.Fields.size() << "\n";
655+
bool Warn = Element.Fields.size() > Size;
656+
WithColor(errs(), Warn ? HighlightColor::Warning : HighlightColor::Error)
657+
<< (Warn ? "warning: " : "error: ") << "expected " << Size
658+
<< " field(s); found " << Element.Fields.size() << "\n";
660659
reportLocation(Element.Tag.end());
661-
return false;
660+
return Warn;
662661
}
663662
return true;
664663
}
@@ -675,16 +674,14 @@ bool MarkupFilter::checkNumFieldsAtLeast(const MarkupNode &Element,
675674
return true;
676675
}
677676

678-
bool MarkupFilter::checkNumFieldsAtMost(const MarkupNode &Element,
679-
size_t Size) const {
680-
if (Element.Fields.size() > Size) {
681-
WithColor::error(errs())
682-
<< "expected at most " << Size << " field(s); found "
683-
<< Element.Fields.size() << "\n";
684-
reportLocation(Element.Tag.end());
685-
return false;
686-
}
687-
return true;
677+
void MarkupFilter::warnNumFieldsAtMost(const MarkupNode &Element,
678+
size_t Size) const {
679+
if (Element.Fields.size() <= Size)
680+
return;
681+
WithColor::warning(errs())
682+
<< "expected at most " << Size << " field(s); found "
683+
<< Element.Fields.size() << "\n";
684+
reportLocation(Element.Tag.end());
688685
}
689686

690687
void MarkupFilter::reportTypeError(StringRef Str, StringRef TypeName) const {

llvm/test/DebugInfo/symbolize-filter-markup-bt.test

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ CHECK: #0.1 0x0000000000000018 second /tmp[[SEP]]tmp.c:8:3 (a.o+0x8)
1818
CHECK: #0 0x0000000000000018 first /tmp[[SEP]]tmp.c:4:3 (a.o+0x8)
1919
CHECK: #0 0x0000000000000019 first /tmp[[SEP]]tmp.c:5:1 (a.o+0x9)
2020
CHECK: #0 0x00000000000000fe (a.o+0xee)
21+
22+
CHECK: #0 0x00000000000000fe (a.o+0xee)
23+
ERR: warning: expected at most 3 field(s); found 4
2124
CHECK: [[BEGIN]]bt:0:0x111[[END]]
25+
ERR: error: no mmap covers address
2226

2327
ERR: error: expected at least 2 field(s); found 0
24-
ERR: error: no mmap covers address
2528
ERR: error: expected PC type; found ''
26-
ERR: error: expected at most 3 field(s); found 4
2729

2830
;--- input
2931
{{{module:0:a.o:elf:abcdef}}}
@@ -34,10 +36,11 @@ ERR: error: expected at most 3 field(s); found 4
3436
{{{bt:0:0x19:pc}}}
3537
{{{bt:0:0xff}}}
3638

37-
{{{bt}}}
39+
{{{bt:0:0xff:pc:ext}}}
3840
{{{bt:0:0x111}}}
41+
42+
{{{bt}}}
3943
{{{bt:0:0:}}}
40-
{{{bt:0:0:pc:}}}
4144
;--- asm.s
4245
# Generated by running "clang -finline -g -S tmp.c" in the following tmp.c on
4346
# Linux x86_64:

llvm/test/DebugInfo/symbolize-filter-markup-pc.test

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ CHECK: first[/dir[[SEP:[/\\]]]tmp.c:3]
1414
CHECK: first[/dir[[SEP]]tmp.c:5]
1515
CHECK: first[/dir[[SEP]]tmp.c:4]
1616
CHECK: first[/dir[[SEP]]tmp.c:5]
17+
1718
CHECK: [[BEGIN]]pc:0xff[[END]]
1819
CHECK: [[BEGIN]]pc:0x100[[END]]
20+
CHECK: first[/dir[[SEP]]tmp.c:5]
21+
ERR: error: no mmap covers address
22+
ERR: warning: expected at most 2 field(s); found 3
1923

2024
ERR: error: expected at least 1 field(s); found 0
21-
ERR: error: no mmap covers address
2225
ERR: error: expected PC type; found ''
23-
ERR: error: expected at most 2 field(s); found 3
2426

2527
;--- input
2628
{{{module:0:a.o:elf:abcdef}}}
@@ -29,12 +31,13 @@ ERR: error: expected at most 2 field(s); found 3
2931
{{{pc:0x9}}}
3032
{{{pc:0x9:ra}}}
3133
{{{pc:0x9:pc}}}
34+
3235
{{{pc:0xff}}}
36+
{{{pc:0x100}}}
37+
{{{pc:0x9:pc:ext}}}
3338

3439
{{{pc}}}
35-
{{{pc:0x100}}}
3640
{{{pc:0x9:}}}
37-
{{{pc:0x9:pc:}}}
3841
;--- asm.s
3942
.text
4043
.file "tmp.c"

llvm/test/DebugInfo/symbolize-filter-markup-reset.test

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ CHECK: [[BEGIN:\[{3}]]ELF module #0x0 "a.o"; BuildID=ab [0x0-0x0](r)[[END:\]{3}]
88
CHECK: {{ }}[[BEGIN]]reset[[END]]
99
CHECK: [[BEGIN:\[{3}]]ELF module #0x0 "b.o"; BuildID=cd [0x1-0x1](r)[[END:\]{3}]]
1010

11-
ERR: error: expected 0 field(s); found 1
11+
CHECK: [[BEGIN]]reset:ext[[END]]
12+
ERR: warning: expected 0 field(s); found 1
13+
14+
CHECK: [[BEGIN:\[{3}]]ELF module #0x0 "a.o"; BuildID=ab [0x0-0x0](r)[[END:\]{3}]]
1215

1316
;--- log
1417
{{{reset}}}
@@ -18,4 +21,6 @@ ERR: error: expected 0 field(s); found 1
1821
{{{module:0:b.o:elf:cd}}}
1922
{{{mmap:0x1:1:load:0:r:0}}}
2023

21-
{{{reset:}}}
24+
{{{reset:ext}}}
25+
{{{module:0:a.o:elf:ab}}}
26+
{{{mmap:0:1:load:0:r:0}}}

0 commit comments

Comments
 (0)