Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disassembly view: allow to disable hex by moving it to a separate column #527

Closed
GitMensch opened this issue Oct 13, 2023 · 14 comments · Fixed by #566
Closed

Disassembly view: allow to disable hex by moving it to a separate column #527

GitMensch opened this issue Oct 13, 2023 · 14 comments · Fixed by #566

Comments

@GitMensch
Copy link
Contributor

GitMensch commented Oct 13, 2023

Follow-up to #516, to allow hiding it like KCachegrind
kcachegrind disassembly
as originally requested by @milianw in #523 (comment)

@lievenhey if possible, could you also have a look at how kcachegrind fills its disassembly view? [...] I also like that it splits up more of the content into columns one could individually hide (e.g. the hex stuff wouldn't be too interesting for me).

@milianw
Copy link
Member

milianw commented Oct 21, 2023

I pushed some improvements for the branch visualization now, which allows a similar compact visualization to what is shown in the screenshot above. more fine grained splitting of the disassembly column would still be appreciated

@GitMensch
Copy link
Contributor Author

GitMensch commented Oct 22, 2023

The recent additions (AppImage version 201 works, AppImage 211 doesn't) broke the disassembly with GNU objdump (GNU Binutils for Debian) 2.35.2:

1.6.1.211 appimage

I guess that's the effect of different objdump versions?🤔

Side note: Would it be reasonable to include the most recent objdump version into the appImage and use it by default from there?

@milianw
Copy link
Member

milianw commented Oct 22, 2023

can you please upload the raw output from objdump for the above command here? e.g. use strace to see how we run objdump internally, then do it manually from the CLI and pipe the output to a file, then upload here. then I can fix it - previously it was broken for objdump on my end... I guess the output simply isn't too stable and we need to support multiple formats somehow

@GitMensch
Copy link
Contributor Author

GitMensch commented Oct 22, 2023

I've tried, but there's no useful output in strace when running from the appinfo... while I extract and rerun that, I've created #535 which will help to get there faster in the next time and may also provide useful in general

... extracted appImage didn't help either:

$> LD_LIBRARY_PATH=/tmp/squashfs-root/usr/lib64:/tmp/squashfs-root/usr/lib PATH=/tmp/squashfs-root/usr/bin:$PATH strace hotspot 2>&1 | grep objdump
stat("/tmp/squashfs-root/usr/bin/objdump", 0x7fff61f1d470) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/objdump", 0x7fff61f1d470) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/objdump", 0x7fff61f1d470) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/objdump", 0x7fff61f1d470) = -1 ENOENT (No such file or directory)
stat("/usr/bin/objdump", {st_mode=S_IFREG|0755, st_size=464664, ...}) = 0
access("/usr/bin/objdump", X_OK)        = 0
read(33, "Usage: /usr/bin/objdump <option("..., 6420) = 6420
stat("/tmp/squashfs-root/usr/bin/objdump", 0x7fff61f1d3d0) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/objdump", 0x7fff61f1d3d0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/objdump", 0x7fff61f1d3d0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/objdump", 0x7fff61f1d3d0) = -1 ENOENT (No such file or directory)
stat("/usr/bin/objdump", {st_mode=S_IFREG|0755, st_size=464664, ...}) = 0
access("/usr/bin/objdump", X_OK)        = 0

After recognizing that the process path of objdump is resolved first, I've adjusted the PR to use that (so the additional stat calls are not needed)

@GitMensch
Copy link
Contributor Author

Here's a bit of output using the same parameters objdump -d -l -C --visualize-jumps from this machine:

objdump -d -l -C --start-address 0x17fe --stop-address  0x1884 --visualize-jumps $(which cobcrun)

/usr/bin/cobcrun:     file format elf64-x86-64


Disassembly of section .text:

00000000000017fe <_start@@Base+0x39e>:
    17fe:              48 8d 3d d3 0e 00 00     lea    0xed3(%rip),%rdi        # 26d8 <_IO_stdin_used@@Base+0x6d8>
    1805:              e9 46 f8 ff ff           jmpq   1050 <puts@plt>
    180a:              66 0f 1f 44 00 00        nopw   0x0(%rax,%rax,1)
    1810:              48 85 ff                 test   %rdi,%rdi
    1813:              0f 84 9f 00 00 00        je     18b8 <_start@@Base+0x458>
    1819:              41 56                    push   %r14
    181b:              41 55                    push   %r13
    181d:              4c 8d 35 a9 08 00 00     lea    0x8a9(%rip),%r14        # 20cd <_IO_stdin_used@@Base+0xcd>
    1824:              41 54                    push   %r12
    1826:              55                       push   %rbp
    1827:              49 89 fd                 mov    %rdi,%r13
    182a:              53                       push   %rbx
    182b:              49 89 fc                 mov    %rdi,%r12
    182e:              48 81 ec 00 20 00 00     sub    $0x2000,%rsp
    1835:          /-- eb 0c                    jmp    1843 <_start@@Base+0x3e3>
    1837:          |   66 0f 1f 84 00 00 00     nopw   0x0(%rax,%rax,1)
    183e:          |   00 00
    1840:       /--|-> 49 89 ec                 mov    %rbp,%r12
    1843:       |  \-> 49 8d 5c 24 01           lea    0x1(%r12),%rbx
    1848:       |      4c 89 f6                 mov    %r14,%rsi
    184b:       |      48 89 df                 mov    %rbx,%rdi
    184e:       |      e8 2d f8 ff ff           callq  1080 <strpbrk@plt>
    1853:       |      48 85 c0                 test   %rax,%rax
    1856:       |      48 89 c5                 mov    %rax,%rbp
    1859:       \----- 75 e5                    jne    1840 <_start@@Base+0x3e0>
    185b:              4d 39 e5                 cmp    %r12,%r13
    185e:              4c 89 ef                 mov    %r13,%rdi
    1861:              49 0f 44 dd              cmove  %r13,%rbx
    1865:              44 0f b6 33              movzbl (%rbx),%r14d
    1869:              c6 03 00                 movb   $0x0,(%rbx)
    186c:              e8 7f f8 ff ff           callq  10f0 <cob_strdup@plt>
    1871:              48 89 df                 mov    %rbx,%rdi
    1874:              49 89 c4                 mov    %rax,%r12
    1877:              44 88 33                 mov    %r14b,(%rbx)
    187a:              e8 71 f8 ff ff           callq  10f0 <cob_strdup@plt>
    187f:              41 80 3c 24 00           cmpb   $0x0,(%r12)

@lievenhey
Copy link
Contributor

normally -l should add some lines that reference the source code like this:

/opt/hotspot/tests/modeltests/disassembly/fib.cpp:2
    11cd:          /-------> f3 0f 1e fa                endbr64 
    11d1:          |         55                         push   %rbp
    11d2:          |         48 89 e5                   mov    %rsp,%rbp
    11d5:          |         41 54                      push   %r12
    11d7:          |         53                         push   %rbx
    11d8:          |         48 83 ec 10                sub    $0x10,%rsp
    11dc:          |         89 7d ec                   mov    %edi,-0x14(%rbp)
/opt/hotspot/tests/modeltests/disassembly/fib.cpp:3
    11df:          |         83 7d ec 00                cmpl   $0x0,-0x14(%rbp)
    11e3:          |     /-- 74 06                      je     11eb <_Z3fibi+0x1e>
/opt/hotspot/tests/modeltests/disassembly/fib.cpp:3 (discriminator 1)
    11e5:          |     |   83 7d ec 01                cmpl   $0x1,-0x14(%rbp)
    11e9:          |  /--|-- 75 0a                      jne    11f5 <_Z3fibi+0x28>
/opt/hotspot/tests/modeltests/disassembly/fib.cpp:4

@lievenhey
Copy link
Contributor

The recent additions (AppImage version 201 works, AppImage 211 doesn't) broke the disassembly with GNU objdump (GNU Binutils for Debian) 2.35.2:

1.6.1.211 appimage

I guess that's the effect of different objdump versions?🤔

Side note: Would it be reasonable to include the most recent objdump version into the appImage and use it by default from there?

line 8637 is highlighted which is a comment, that is somewhat strange, since comments don't have a source code reference. Therefor my guess is, that source code and binary are not in sync.

@lievenhey
Copy link
Contributor

@GitMensch can you send us the output of objdump -d -l -C --visualize-jumps --start-address 0x2573c --stop-address ..? That is the function you are trying to disassemble. The one that you send us is compiler generated and does not include any source references.

@GitMensch
Copy link
Contributor Author

GitMensch commented Oct 23, 2023

Therefor my guess is, that source code and binary are not in sync.

That's likely the case, still this is different in appimage 201:

appimage 201

The one that you send us is compiler generated and does not include any source references.

I see, because that's the system installed one, not the (outdated) one from the trace.
So far hotspot seems to only show the binary, name - where can I get the full path to it? If that's not available: please add that, even a context menu "Show in file system" would be useful (as partner to "Open in Editor" which is available on the symbols).

@GitMensch
Copy link
Contributor Author

GitMensch commented Oct 23, 2023

Nonetheless, I've derived the binary from what was shown under "Open in Editor"... (which is likely not that easy often, and cumbersome, so I hope for a way to see the binary path somewhere, guess I only missed that so far [the tooltip in caller/callee tab and in the summary "hotspot per file" would be useful]).

This seems to be the binary that was disassembled:

objdump -d -l -C --start-address 0x2573c --stop-address 0x258f1 --visualize-jumps /tmp/gnucobol-bug-hunting/libcob/.libs/libcob.so.4.2.0

libcob/.libs/libcob.so.4.2.0:     file format elf64-x86-64


Disassembly of section .text:

000000000002573c <cob_load_config>:
cob_load_config():
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8673
   2573c:                                55                     push   %rbp
   2573d:                                48 89 e5               mov    %rsp,%rbp
   25740:                                48 81 ec 20 20 00 00   sub    $0x2020,%rsp
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8676
   25747:                                c7 45 fc 01 00 00 00   movl   $0x1,-0x4(%rbp)
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8680
   2574e:                                48 8d 3d f0 8a 05 00   lea    0x58af0(%rip),%rdi        # 7e245 <cob_exception_tab_code+0x1d45>
   25755:                                e8 d6 d9 fe ff         callq  13130 <getenv@plt>
   2575a:                                48 89 45 e8            mov    %rax,-0x18(%rbp)
   2575e:                                48 83 7d e8 00         cmpq   $0x0,-0x18(%rbp)
   25763:                            /-- 0f 84 ae 00 00 00      je     25817 <cob_load_config+0xdb>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8680 (discriminator 1)
   25769:                            |   48 8b 45 e8            mov    -0x18(%rbp),%rax
   2576d:                            |   0f b6 00               movzbl (%rax),%eax
   25770:                            |   84 c0                  test   %al,%al
   25772:                            +-- 0f 84 9f 00 00 00      je     25817 <cob_load_config+0xdb>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8681
   25778:                            |   48 8b 4d e8            mov    -0x18(%rbp),%rcx
   2577c:                            |   48 8d 85 e0 df ff ff   lea    -0x2020(%rbp),%rax
   25783:                            |   ba ff 1f 00 00         mov    $0x1fff,%edx
   25788:                            |   48 89 ce               mov    %rcx,%rsi
   2578b:                            |   48 89 c7               mov    %rax,%rdi
   2578e:                            |   e8 8d dd fe ff         callq  13520 <strncpy@plt>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8682
   25793:                            |   c6 45 df 00            movb   $0x0,-0x21(%rbp)
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8683
   25797:                            |   c7 45 fc 00 00 00 00   movl   $0x0,-0x4(%rbp)
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8684
   2579e:                            |   48 8d 85 e0 df ff ff   lea    -0x2020(%rbp),%rax
   257a5:                            |   be 3a 00 00 00         mov    $0x3a,%esi
   257aa:                            |   48 89 c7               mov    %rax,%rdi
   257ad:                            |   e8 ee d8 fe ff         callq  130a0 <strchr@plt>
   257b2:                            |   48 85 c0               test   %rax,%rax
   257b5:                      /-----|-- 0f 84 68 01 00 00      je     25923 <cob_load_config+0x1e7>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8685
   257bb:                      |     |   48 8d 3d 96 8a 05 00   lea    0x58a96(%rip),%rdi        # 7e258 <cob_exception_tab_code+0x1d58>
   257c2:                      |     |   e8 c9 cd fe ff         callq  12590 <gettext@plt>
   257c7:                      |     |   48 89 c6               mov    %rax,%rsi
   257ca:                      |     |   48 8d 85 e0 df ff ff   lea    -0x2020(%rbp),%rax
   257d1:                      |     |   48 8d 0d 6d 8a 05 00   lea    0x58a6d(%rip),%rcx        # 7e245 <cob_exception_tab_code+0x1d45>
   257d8:                      |     |   48 89 c2               mov    %rax,%rdx
   257db:                      |     |   bf 00 00 00 00         mov    $0x0,%edi
   257e0:                      |     |   b8 00 00 00 00         mov    $0x0,%eax
   257e5:                      |     |   e8 0e 15 00 00         callq  26cf8 <conf_runtime_error>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8686
   257ea:                      |     |   48 8d 3d d5 88 05 00   lea    0x588d5(%rip),%rdi        # 7e0c6 <cob_exception_tab_code+0x1bc6>
   257f1:                      |     |   e8 9a cd fe ff         callq  12590 <gettext@plt>
   257f6:                      |     |   ba 3a 00 00 00         mov    $0x3a,%edx
   257fb:                      |     |   48 89 c6               mov    %rax,%rsi
   257fe:                      |     |   bf 01 00 00 00         mov    $0x1,%edi
   25803:                      |     |   b8 00 00 00 00         mov    $0x0,%eax
   25808:                      |     |   e8 eb 14 00 00         callq  26cf8 <conf_runtime_error>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8687
   2580d:                      |     |   b8 ff ff ff ff         mov    $0xffffffff,%eax
   25812:       /--------------|-----|-- e9 8d 03 00 00         jmpq   25ba4 <cob_load_config+0x468>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8691
   25817:       |              |     \-> 48 8d 3d 9d 87 05 00   lea    0x5879d(%rip),%rdi        # 7dfbb <cob_exception_tab_code+0x1abb>
   2581e:       |              |         e8 0d d9 fe ff         callq  13130 <getenv@plt>
   25823:       |              |         48 89 45 e8            mov    %rax,-0x18(%rbp)
   25827:       |              |         48 83 7d e8 00         cmpq   $0x0,-0x18(%rbp)
   2582c:       |              |  /----- 74 41                  je     2586f <cob_load_config+0x133>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8691 (discriminator 1)
   2582e:       |              |  |      48 8b 45 e8            mov    -0x18(%rbp),%rax
   25832:       |              |  |      0f b6 00               movzbl (%rax),%eax
   25835:       |              |  |      84 c0                  test   %al,%al
   25837:       |              |  +----- 74 36                  je     2586f <cob_load_config+0x133>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8692
   25839:       |              |  |      48 8b 55 e8            mov    -0x18(%rbp),%rdx
   2583d:       |              |  |      48 8d 85 e0 df ff ff   lea    -0x2020(%rbp),%rax
   25844:       |              |  |      4c 8d 0d 3b 8a 05 00   lea    0x58a3b(%rip),%r9        # 7e286 <cob_exception_tab_code+0x1d86>
   2584b:       |              |  |      41 b8 2f 00 00 00      mov    $0x2f,%r8d
   25851:       |              |  |      48 89 d1               mov    %rdx,%rcx
   25854:       |              |  |      48 8d 15 a2 89 05 00   lea    0x589a2(%rip),%rdx        # 7e1fd <cob_exception_tab_code+0x1cfd>
   2585b:       |              |  |      be ff 1f 00 00         mov    $0x1fff,%esi
   25860:       |              |  |      48 89 c7               mov    %rax,%rdi
   25863:       |              |  |      b8 00 00 00 00         mov    $0x0,%eax
   25868:       |              |  |      e8 53 c9 fe ff         callq  121c0 <snprintf@plt>
   2586d:       |              |  |  /-- eb 34                  jmp    258a3 <cob_load_config+0x167>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8694
   2586f:       |              |  \--|-> 48 8d 85 e0 df ff ff   lea    -0x2020(%rbp),%rax
   25876:       |              |     |   4c 8d 0d 09 8a 05 00   lea    0x58a09(%rip),%r9        # 7e286 <cob_exception_tab_code+0x1d86>
   2587d:       |              |     |   41 b8 2f 00 00 00      mov    $0x2f,%r8d
   25883:       |              |     |   48 8d 0d 46 87 05 00   lea    0x58746(%rip),%rcx        # 7dfd0 <cob_exception_tab_code+0x1ad0>
   2588a:       |              |     |   48 8d 15 6c 89 05 00   lea    0x5896c(%rip),%rdx        # 7e1fd <cob_exception_tab_code+0x1cfd>
   25891:       |              |     |   be ff 1f 00 00         mov    $0x1fff,%esi
   25896:       |              |     |   48 89 c7               mov    %rax,%rdi
   25899:       |              |     |   b8 00 00 00 00         mov    $0x0,%eax
   2589e:       |              |     |   e8 1d c9 fe ff         callq  121c0 <snprintf@plt>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8696
   258a3:       |              |     \-> c6 45 df 00            movb   $0x0,-0x21(%rbp)
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8697
   258a7:       |              |         c7 45 fc 01 00 00 00   movl   $0x1,-0x4(%rbp)
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8698
   258ae:       |              |         48 8d 85 e0 df ff ff   lea    -0x2020(%rbp),%rax
   258b5:       |              |         be 3a 00 00 00         mov    $0x3a,%esi
   258ba:       |              |         48 89 c7               mov    %rax,%rdi
   258bd:       |              |         e8 de d7 fe ff         callq  130a0 <strchr@plt>
   258c2:       |              |         48 85 c0               test   %rax,%rax
   258c5:       |              +-------- 74 5c                  je     25923 <cob_load_config+0x1e7>
/home/dev/GnuCOBOL/code_repo_fix_only/branches/gnucobol-3.x/libcob/common.c:8699
   258c7:       |              |         48 8d 3d 8a 89 05 00   lea    0x5898a(%rip),%rdi        # 7e258 <cob_exception_tab_code+0x1d58>
   258ce:       |              |         e8 bd cc fe ff         callq  12590 <gettext@plt>
   258d3:       |              |         48 89 c6               mov    %rax,%rsi
   258d6:       |              |         48 8d 85 e0 df ff ff   lea    -0x2020(%rbp),%rax
   258dd:       |              |         48 8d 0d d7 86 05 00   lea    0x586d7(%rip),%rcx        # 7dfbb <cob_exception_tab_code+0x1abb>
   258e4:       |              |         48 89 c2               mov    %rax,%rdx
   258e7:       |              |         bf 00 00 00 00         mov    $0x0,%edi
   258ec:       |              |         b8 00 00 00 00         mov    $0x0,%eax

As this doesn't visualize the tabs - find the output redirected attached: dump.log.

@lievenhey
Copy link
Contributor

X is also not handled
log.txt

@GitMensch
Copy link
Contributor Author

Thanks for posting the log, this highlighted the tabs which were missing in the output provided above, redid the objdump and attached its redirected output above.

@milianw
Copy link
Member

milianw commented Nov 11, 2023

@lievenhey I wonder how that should be visualized, and without a way to show our widget for an arbitrary objdump log file I also don't know how to test the visual rendering - do you have an idea?

I only found this marker, which seems to represent both, a jump source and a jump target, in _start but disassembling that from hotspot...

milianw added a commit that referenced this issue Nov 11, 2023
No visualization yet as I'm unsure how to replicate that in
the real world such that I can inspect the 'X' visually.

Relates-To: #527
@lievenhey
Copy link
Contributor

About testing, we could render into a pixmap and that diff it against a well known working one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants