简体   繁体   中英

Why does "gdb> disas /s main" not show me source code?

I start with a binary executable and I want to see the source code, not just the assembly code. Is this possible? The documentation at "https://sourceware.org/gdb/onlinedocs/gdb/Machine-Code.html" seems to generate the source code.
If it is possible, why is the source code not showing. I have set no breakpoints, the code is not striped. I have used the gdb command "disas /s main". A screen shot starting with some information about my configuration follow.

──(root㉿kali)-[/home/kali/Downloads]
└─# uname -a
Linux kali 5.15.0-kali3-amd64 #1 SMP Debian 5.15.15-2kali1 (2022-01-31) x86_64 GNU/Linux
                                                                                                                                                                                             
┌──(root㉿kali)-[/home/kali/Downloads]
└─# gdb -v               
GNU gdb (Debian 10.1-2) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
                                                                                                                                                                                             
┌──(root㉿kali)-[/home/kali/Downloads]
└─# file RE1_64bit 
RE1_64bit: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=8616e4f2a4a3c325c2a1f32b8ebb8366694f7a03, not stripped
                                                                                                                                                                                             
┌──(root㉿kali)-[/home/kali/Downloads]
└─# gdb RE1_64bit 
GNU gdb (Debian 10.1-2) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.                                                                                                                                            
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from RE1_64bit...
(No debugging symbols found in RE1_64bit)
(gdb) disas /s main
Dump of assembler code for function main:
   0x000000000040084e <+0>:     push   %rbp
   0x000000000040084f <+1>:     mov    %rsp,%rbp
   0x0000000000400852 <+4>:     sub    $0x40,%rsp
   0x0000000000400856 <+8>:     mov    %edi,-0x34(%rbp)
   0x0000000000400859 <+11>:    mov    %rsi,-0x40(%rbp)
   0x000000000040085d <+15>:    cmpl   $0x2,-0x34(%rbp)
   0x0000000000400861 <+19>:    je     0x400886 <main+56>
   0x0000000000400863 <+21>:    mov    -0x40(%rbp),%rax
   0x0000000000400867 <+25>:    mov    (%rax),%rax
   0x000000000040086a <+28>:    mov    %rax,%rsi
   0x000000000040086d <+31>:    mov    $0x4009a2,%edi
   0x0000000000400872 <+36>:    mov    $0x0,%eax
   0x0000000000400877 <+41>:    call   0x400580 <printf@plt>
   0x000000000040087c <+46>:    mov    $0x1,%edi
   0x0000000000400881 <+51>:    call   0x4005e0 <exit@plt>
   0x0000000000400886 <+56>:    mov    -0x40(%rbp),%rax
   0x000000000040088a <+60>:    add    $0x8,%rax
   0x000000000040088e <+64>:    mov    (%rax),%rax
   0x0000000000400891 <+67>:    mov    %rax,%rdi
   0x0000000000400894 <+70>:    call   0x400570 <strlen@plt>
   0x0000000000400899 <+75>:    cmp    $0x4,%rax
   0x000000000040089d <+79>:    je     0x4008c2 <main+116>
   0x000000000040089f <+81>:    mov    -0x40(%rbp),%rax
   0x00000000004008a3 <+85>:    mov    (%rax),%rax
   0x00000000004008a6 <+88>:    mov    %rax,%rsi
   0x00000000004008a9 <+91>:    mov    $0x4009a2,%edi
   0x00000000004008ae <+96>:    mov    $0x0,%eax
   0x00000000004008b3 <+101>:   call   0x400580 <printf@plt>
   0x00000000004008b8 <+106>:   mov    $0x1,%edi
   0x00000000004008bd <+111>:   call   0x4005e0 <exit@plt>
   0x00000000004008c2 <+116>:   movl   $0x0,-0x4(%rbp)
   0x00000000004008c9 <+123>:   mov    $0x4009b3,%edi
   0x00000000004008ce <+128>:   mov    $0x0,%eax
   0x00000000004008d3 <+133>:   call   0x400580 <printf@plt>
   0x00000000004008d8 <+138>:   lea    -0x30(%rbp),%rax
   0x00000000004008dc <+142>:   mov    %rax,%rdi
   0x00000000004008df <+145>:   call   0x4005d0 <gets@plt>
   0x00000000004008e4 <+150>:   cmpl   $0x0,-0x4(%rbp)
   0x00000000004008e8 <+154>:   je     0x4008f8 <main+170>
   0x00000000004008ea <+156>:   mov    -0x40(%rbp),%rax
   0x00000000004008ee <+160>:   mov    %rax,%rdi
   0x00000000004008f1 <+163>:   call   0x4006dd <fg>
   0x00000000004008f6 <+168>:   jmp    0x400902 <main+180>
   0x00000000004008f8 <+170>:   mov    $0x4009cd,%edi
   0x00000000004008fd <+175>:   call   0x400560 <puts@plt>
   0x0000000000400902 <+180>:   mov    $0x0,%eax
   0x0000000000400907 <+185>:   leave  
   0x0000000000400908 <+186>:   ret    
End of assembler dump.

As has been said in the comments, this line:

(No debugging symbols found in RE1_64bit)

indicates that the binary does not include any debug information, so you're not going to be able to match assembler code to source lines.

If the binary did include debug information then it would only contain a table mapping addresses in the binary to file names and line numbers. You would still need to have the actual source files in order to view the source lines, and, of course, the source files need to be the exact versions that were compiled into that specific binary, otherwise the line numbers in the debug information will not match up correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM