This is an archive of the discontinued LLVM Phabricator instance.

[symbolizer] Exit early if input file is absent
ClosedPublic

Authored by sepavloff on Jun 18 2023, 12:21 AM.

Details

Summary

If binary file specified as input with option --obj or -e is absent,
now llvm-addr2line exits immediately. This patch extends this behavior to
llvm-symbolizer. Previously llvm-symbolizer waited addresses from input
stream or command line in this case.

Diff Detail

Event Timeline

sepavloff created this revision.Jun 18 2023, 12:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2023, 12:21 AM
sepavloff requested review of this revision.Jun 18 2023, 12:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2023, 12:21 AM

@MaskRay/@dblaikie, do you have any thoughts on this behaviour change?

llvm/test/tools/llvm-symbolizer/errors.test
16 ↗(On Diff #532450)

Nit: delete blank line at EOF.

llvm/test/tools/llvm-symbolizer/output-style-json-code.test
7

This is possibly a case where we DO want the existing behaviour. The reasoning is that JSON output is intended to be 100% machine-readable.

@MaskRay/@dblaikie, do you have any thoughts on this behaviour change?

No strong feelings from me - doesn't seem like a super important thing to diverge from addr2line on, so probably god to be consistent?

MaskRay accepted this revision.EditedJun 21 2023, 10:38 PM

LGTM. llvm-symbolizer --obj=unexisting's previous behavior of waiting on stdin seems a bit weird. Perhaps it's that way to mimic

% cat non-existent -
cat: non-existent: No such file or directory
<wait on stdin>

but I not sure that is a useful/desirable behavior...

There is a time-of-check-to-time-of-use issue, but probably not important.

This revision is now accepted and ready to land.Jun 21 2023, 10:38 PM
This revision now requires review to proceed.Jun 22 2023, 4:06 PM
MaskRay accepted this revision.Jun 23 2023, 10:21 AM

LGTM.

llvm/test/tools/llvm-symbolizer/errors.test
1 ↗(On Diff #532450)

Note: I've moved this to input-file-err.test as the new name seems more specific about we use this test file.

llvm/test/tools/llvm-symbolizer/output-style-json-code.test
7

If we want to keep the test but make it more useful, we can specify two addresses on the command line and see how the error is presented. With the changes, the output is one JSON object with Error.

This revision is now accepted and ready to land.Jun 23 2023, 10:21 AM

If binary file specified as input with option --obj or -e was absent, [...]

The paragraph can be changed to say that now llvm-addr2line exits immediately. This patch extends the behavior to llvm-symbolizer.
Consider mentioning the behavior change for --output-style=JSON as well.

llvm-symbolizer --output-style=JSON -e nonexistent

Rebase the patch

sepavloff edited the summary of this revision. (Show Details)Jun 25 2023, 12:10 PM
sepavloff added inline comments.
llvm/test/tools/llvm-symbolizer/output-style-json-code.test
7

Both variants (old and new) are valid JSON files. When llvm-symbolizer processes address specified in command line, it also produces such JSON. I think this change in output could be considered as minor.

sepavloff updated this revision to Diff 534420.Jun 25 2023, 9:13 PM

Fix PDB test

jhenderson added inline comments.Jun 26 2023, 1:12 AM
llvm/test/tools/llvm-symbolizer/output-style-inlined.test
34–40
  1. In this test, we don't use a comment marker before the CHECK lines
  2. There's no need for two different check patterns. The output is identical.
llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
1–3

I think the point of this test was (in part) to show llvm-symbolizer's stdout output too. If that is now empty, you should check that explicitly.

sepavloff updated this revision to Diff 534472.Jun 26 2023, 2:49 AM

Fixed tests

sepavloff marked an inline comment as done.Jun 26 2023, 2:53 AM
sepavloff added inline comments.
llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
1–3

Previously the error message went to stderr, and the result of recognition to stdout. Now only error message presents. Attempt to feed empty stream to FileCheck results in error: FileCheck error: '<stdin>' is empty.

MaskRay added inline comments.Jun 26 2023, 9:54 AM
llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
1–3

If we want to explicitly test that stdout output is empty, we can use:

not llvm-symbolizer ... 2> %t.err | count 0
FileCheck --input-file=%t.err
jhenderson added inline comments.Jun 27 2023, 1:10 AM
llvm/test/tools/llvm-symbolizer/output-style-inlined.test
34–40

Super-nit: delete the extra spacing between NOT-EXIST and llvm-symbolizer as per my previous inline edit.

llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
4–5

This comment looks stale?

6

Rather than checking that some arbitrary error message is not emitted, better would be to make sure nothing is printed beyond what you expect, with --implicit-check-not={{.}}.

(This would have the added benefit of not needing the count 0 call, if you wanted, although I think @MaskRay's suggestion is cleaner for checking that stdout is empty.)

sepavloff updated this revision to Diff 534918.Jun 27 2023, 5:02 AM

Fixed test

sepavloff marked an inline comment as done.Jun 27 2023, 5:05 AM
sepavloff added inline comments.
llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
6

--implicit-check-not does not work, because input is empty and FileCheck complains, so used the method proposed by @MaskRay .

jhenderson added inline comments.Jun 27 2023, 5:36 AM
llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
3

As @MaskRay suggested, please use --input-file rather than stdin redirection: it is easier to manually run this command using the suggested syntax.

6

You misunderstand me. I meant adding --implicit-check-not in the FileCheck line that checked the combined stderr and stdout (which of necessity wouldn't be empty). However, I don't think it's necessary given you've adopted @MaskRay's suggestion.

sepavloff updated this revision to Diff 535016.Jun 27 2023, 9:17 AM

Fixed test

This revision was automatically updated to reflect the committed changes.
llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml