11
votes

in Linux and Mac OS X I can use stepi and nexti to debug an application without debugging information.

On Mac OS X gdb shows the functions that are called inside the library, although sometimes advancing several assembler instructions in each stepi instruction.

On Linux, when I step into a dynamic library gdb gets lost. For instance, with puts() there are three assembler instructions inside puts(), once gdb reaches the jump at 0x080482bf, it fails with the message "No function contains program counter for selected frame".

0x080482ba in puts@plt ()
(gdb) disassemble
Dump of assembler code for function puts@plt:
0x080482b4 <puts@plt+0>:        jmp    *0x8049580
0x080482ba <puts@plt+6>:        push   $0x10
0x080482bf <puts@plt+11>:       jmp    0x8048284 <_init+48>
End of assembler dump.
(gdb) stepi
0x080482bf in puts@plt ()
(gdb) stepi
0x08048284 in ?? ()
(gdb) disassemble
No function contains program counter for selected frame.

Do you know how to debug these library calls with gdb.

1
Also, what happens when you use stepi on Linux? You say you can't step through the instructions at all, but you don't describe what actually happens. Can you post a sample session?Ori Pessach
Thank you, I am using Slackware 13.0 with its preinstalled gdb 6.8. I have clarified what happens.Freeman

1 Answers

13
votes

If GDB does not have debug symbols for the function you are trying to debug, GDB will not be able to determine the range of memory addresses to disassemble. To work around this, you can pass the range into the disassemble command. For example:

(gdb) p $pc
$4 = (void (*)()) 0x70c72d <_IO_puts+29>
(gdb) disassemble 0x70c72d 0x70c740
Dump of assembler code from 0x70c72d to 0x70c740:
0x0070c72d <_IO_puts+29>:   mov    %eax,(%esp)
0x0070c730 <_IO_puts+32>:   call   0x721f10 <strlen>
0x0070c735 <_IO_puts+37>:   mov    0x84c(%ebx),%edx
0x0070c73b <_IO_puts+43>:   cmpw   $0x0,(%edx)
0x0070c73f <_IO_puts+47>:   mov    %edx,-0x10(%ebp)
End of assembler dump.

There may be a way to install debug symbols. On my Ubuntu system, I installed the package libc6-dbg, which allows me to step into functions in the standard library.