| CSC448: Code Generation: GNU Debugger (GDB) Walk Through [12/14] | ![]() ![]() ![]() |
To use the GNU Debugger, we must tell the assembler to include debugging information:
$ gcc -Wa,--gstabs -o loop simplified-loop.s $ ./loop 3 2 1 0
A sample session with the debugger:
$ gdb ./loop
GNU gdb 5.0rh-5 Red Hat Linux 7.1
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux".
(gdb) help
List of classes of commands:
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands
Type "help" followed by a class name for a list of commands in that class.
Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.
(gdb) run
Starting program: /home/cpitcher/csc448/examples/src/runtime/./loop
3
2
1
0
Program exited normally.
(gdb) quit
$ gdb ./loop
GNU gdb 5.0rh-5 Red Hat Linux 7.1
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) list
1 .global main
2
3 .text
4 .align 4
5
6 main:
7 pushl %ebp
8 movl %esp, %ebp
9 subl $8, %esp
10
(gdb) list
11 movl $3, -4(%ebp)
12 jmp lab2
13 lab1:
14 pushl -4(%ebp)
15 pushl $somenameforthestring
16 call printf
17 addl $8, %esp
18 leal -4(%ebp), %eax
19 decl (%eax)
20 lab2:
(gdb) list
21 cmpl $0, -4(%ebp)
22 jns lab1
23
24 movl $0, %eax
25 leave
26 ret
27
28
29 .section .rodata
30
(gdb) break 7
Breakpoint 1 at 0x8048460: file simplified-loop.s, line 7.
(gdb) run
Starting program: /home/cpitcher/csc448/examples/src/runtime/./loop
Breakpoint 1, main () at simplified-loop.s:7
7 pushl %ebp
Current language: auto; currently asm
(gdb) run
Starting program: /home/cpitcher/csc448/examples/src/runtime/./loop
Breakpoint 1, main () at simplified-loop.s:7
7 pushl %ebp
Current language: auto; currently asm
(gdb) step
8 movl %esp, %ebp
(gdb) step
main () at simplified-loop.s:9
9 subl $8, %esp
(gdb) step
11 movl $3, -4(%ebp)
(gdb) step
12 jmp lab2
(gdb) step
21 cmpl $0, -4(%ebp)
(gdb) step
22 jns lab1
(gdb) step
14 pushl -4(%ebp)
(gdb) step
15 pushl $somenameforthestring
(gdb) step
16 call printf
(gdb) step
printf (format=0x8048508 "%d\n") at printf.c:32
32 printf.c: No such file or directory.
in printf.c
Current language: auto; currently c
(gdb) bt
#0 printf (format=0x8048508 "%d\n") at printf.c:32
#1 0x0804847c in lab1 () at simplified-loop.s:16
#2 0x40043177 in __libc_start_main (main=0x8048460 <main>, argc=1,
ubp_av=0xbffff8a4, init=0x80482e4 <_init>, fini=0x80484e0 <_fini>,
rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffff89c)
at ../sysdeps/generic/libc-start.c:129
(gdb) up
#1 0x0804847c in lab1 () at simplified-loop.s:16
16 call printf
Current language: auto; currently asm
(gdb) list
11 movl $3, -4(%ebp)
12 jmp lab2
13 lab1:
14 pushl -4(%ebp)
15 pushl $somenameforthestring
16 call printf
17 addl $8, %esp
18 leal -4(%ebp), %eax
19 decl (%eax)
20 lab2:
(gdb) break 17
Breakpoint 2 at 0x804847c: file simplified-loop.s, line 17.
(gdb) continue
Continuing.
3
Breakpoint 2, lab1 () at simplified-loop.s:17
17 addl $8, %esp
(gdb) clear 17
Deleted breakpoint 2
(gdb) continue
Continuing.
2
1
0
Program exited normally.
(gdb) quit