This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] Enable assembly highlighting in llvm-objdump
ClosedPublic

Authored by JDevlieghere on Aug 30 2023, 1:58 PM.

Details

Summary

Enable assembly highlighting in llvm-objdump.

Diff Detail

Event Timeline

JDevlieghere created this revision.Aug 30 2023, 1:58 PM
JDevlieghere requested review of this revision.Aug 30 2023, 1:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2023, 1:58 PM
JDevlieghere retitled this revision from [llvm-objcopy] Add flags to force enable/disable color output to [llvm-objdump] Add flags to force enable/disable color output.

Move test

JDevlieghere edited the summary of this revision. (Show Details)Aug 30 2023, 2:04 PM

GNU objdump from 2.39 onwards provides --disassembler-color=on. I wonder whether we want similar option names, but I can see that --disassembler-color=on is long and inconvenient..

GNU objdump from 2.39 onwards provides --disassembler-color=on. I wonder whether we want similar option names, but I can see that --disassembler-color=on is long and inconvenient..

I expect this flag to be mostly used for writing tests so I'm not too worried about being verbose. FWIW I ended up going for the two separate flags because no other objdump options take a predefined set of options (there's a few ones that take arbitrary strings such as --debug-vars= or --arch-name=) but if we feel that something like --disassembler-color={on, off, auto} is the right thing to do, then I'm happy to go that route.

GNU objdump from 2.39 onwards provides --disassembler-color=on. I wonder whether we want similar option names, but I can see that --disassembler-color=on is long and inconvenient..

I expect this flag to be mostly used for writing tests so I'm not too worried about being verbose. FWIW I ended up going for the two separate flags because no other objdump options take a predefined set of options (there's a few ones that take arbitrary strings such as --debug-vars= or --arch-name=) but if we feel that something like --disassembler-color={on, off, auto} is the right thing to do, then I'm happy to go that route.

Sounds good. objdump uses terminal instead of auto.

% objdump --help
...
      --disassembler-color=off       Disable disassembler color output. (default)
      --disassembler-color=terminal  Enable disassembler color output if displaying on a terminal.
      --disassembler-color=on        Enable disassembler color output.
      --disassembler-color=extended  Use 8-bit colors in disassembler output.

GNU objdump from 2.39 onwards provides --disassembler-color=on. I wonder whether we want similar option names, but I can see that --disassembler-color=on is long and inconvenient..

I expect this flag to be mostly used for writing tests so I'm not too worried about being verbose. FWIW I ended up going for the two separate flags because no other objdump options take a predefined set of options (there's a few ones that take arbitrary strings such as --debug-vars= or --arch-name=) but if we feel that something like --disassembler-color={on, off, auto} is the right thing to do, then I'm happy to go that route.

Sounds good. objdump uses terminal instead of auto.

% objdump --help
...
      --disassembler-color=off       Disable disassembler color output. (default)
      --disassembler-color=terminal  Enable disassembler color output if displaying on a terminal.
      --disassembler-color=on        Enable disassembler color output.
      --disassembler-color=extended  Use 8-bit colors in disassembler output.

Perfect, I'll mirror that. Thanks!

Don't forget to add any new options to the llvm-objdump command guide.

JDevlieghere retitled this revision from [llvm-objdump] Add flags to force enable/disable color output to [llvm-objdump] Enable assembly highlighting in llvm-objdump.
JDevlieghere edited the summary of this revision. (Show Details)
jhenderson added inline comments.Sep 1 2023, 12:35 AM
llvm/docs/CommandGuide/llvm-objdump.rst
183

Is this really a -M option, given that that is the option for --disassembler-options?

187–189

It's probably worth highlighting which of these is the default.

JDevlieghere marked 2 inline comments as done.

Address @jhenderson's feedback.

llvm/docs/CommandGuide/llvm-objdump.rst
183

No, good catch. That's a copy/paste error.

jhenderson accepted this revision.Sep 1 2023, 7:59 AM

LGTM. Please wait for @MaskRay too.

This revision is now accepted and ready to land.Sep 1 2023, 7:59 AM
MaskRay accepted this revision.Sep 1 2023, 9:16 AM

Thanks!

This revision was landed with ongoing or failed builds.Sep 1 2023, 9:32 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Sep 1 2023, 10:05 AM

This breaks tests on windows: http://45.33.8.238/win/83747/step_11.txt

Please take a look and revert for now if it takes a while to fix.

This breaks tests on windows: http://45.33.8.238/win/83747/step_11.txt

Please take a look and revert for now if it takes a while to fix.

Should be fixed by 7678a322196b.

dyung added a subscriber: dyung.Sep 1 2023, 10:34 AM

The newly added test tools/llvm-objdump/MachO/arm64-disassembly-color.s is failing if AArch64 backend is not available, sounds like a REQUIRES is needed?

https://lab.llvm.org/buildbot/#/builders/139/builds/48856

******************** TEST 'LLVM :: tools/llvm-objdump/MachO/arm64-disassembly-color.s' FAILED ********************
Exit Code: 1
Command Output (stderr):
--
+ : 'RUN: at line 1'
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-mc -triple arm64-apple-macosx /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/tools/llvm-objdump/MachO/arm64-disassembly-color.s -filetype=obj -o /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/test/tools/llvm-objdump/MachO/Output/arm64-disassembly-color.s.tmp
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-mc: error: unable to get target for 'arm64-apple-macosx', see --version and --triple.
--
********************
thakis added a comment.EditedSep 1 2023, 10:41 AM

Should be fixed by 7678a322196b.

Yup, thanks!

JDevlieghere added a comment.EditedSep 1 2023, 11:06 AM

The newly added test tools/llvm-objdump/MachO/arm64-disassembly-color.s is failing if AArch64 backend is not available, sounds like a REQUIRES is needed?

https://lab.llvm.org/buildbot/#/builders/139/builds/48856

******************** TEST 'LLVM :: tools/llvm-objdump/MachO/arm64-disassembly-color.s' FAILED ********************
Exit Code: 1
Command Output (stderr):
--
+ : 'RUN: at line 1'
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-mc -triple arm64-apple-macosx /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/tools/llvm-objdump/MachO/arm64-disassembly-color.s -filetype=obj -o /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/test/tools/llvm-objdump/MachO/Output/arm64-disassembly-color.s.tmp
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-mc: error: unable to get target for 'arm64-apple-macosx', see --version and --triple.
--
********************

Yup, let me add that!

edit: Should be fixed by a23b9b7ef134.

This is a very welcomed change! Have I really not run the disassembler since this landed?