You can useGcc-s test. cCommand to generate the assembly language file corresponding to test. C, in at&t format.
Xumh @ Ubuntu: ~ / CPP $
Gcc
-G-
O gdb. c // The-G parameter is used to Generate debug information.
Xumh @ Ubuntu: ~ / CPP $ ls
GDB. c myfirst test1.c test1.s
Xumh @ Ubuntu: ~ / CPP $
GDB // Use the gdb command to debug the generated GDBProgram
GNU GDB 6.8 - Debian
Copyright (c) 2008 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 "
(GDB)
List
1 // Test the implementation of GDBC LanguageSource program debugging
2
3 # Include < Stdio. h >
4 Int Main ( Int Argc, Char ** Argv)
5 {
6 Int Sum = 0 ;
7 Int I = 0 ;
8 For (; I < 10 ; I ++ )
9 Sum + = I;
10 Printf ( " The value is: % d. \ n " , Sum );
(GDB)
Break 9 //
You can also interrupt a function.
Breakpoint 1 At 0x4004b7 : File GDB. C, line 9 .
(GDB)
Run //
Execution Program
Starting program: / Home / Xumh / CPP / GDB
Breakpoint 1 , Main (argc = 1 , Argv = 0x7fff42873018 ) At GDB. C: 9
9 Sum + = I;
(GDB)Watch sum // Observe Variables
Hardware watchpoint 2 : Sum
(GDB) Watch I
Hardware watchpoint 3 : I
(GDB) Next // One-step execution
8 For (; I < 10 ; I ++ )
(GDB) Next
Hardware watchpoint 3 : I
Old Value = 0
New Value = 1
0x00000000004004c1 In Main (argc = 1 , Argv = 0x7fff42873018 ) At GDB. C: 8
8 For (; I < 10 ; I ++ )
(GDB) Next
Breakpoint1, Main (argc=1, Argv=0x7fff42873018) At GDB. C:9
9Sum+ =I;
(GDB) Next
Hardware watchpoint2: Sum
Old Value = 0
New Value= 1
Main (argc = 1 , Argv = 0x7fff42873018 ) At GDB. C: 8
8 For (; I < 10 ; I ++ )
(GDB) Next
Hardware watchpoint 3 : I
Old Value = 1
New Value = 2
0x00000000004004c1 In Main (argc = 1 , Argv = 0x7fff42873018 ) At GDB. C: 8
8 For (; I < 10 ; I ++ )
(GDB) Next
Breakpoint1, Main (argc=1, Argv=0x7fff42873018) At GDB. C:9
9Sum+ =I;
(GDB) Next
Hardware watchpoint2: Sum
Old Value= 1
New Value = 3
Main (argc = 1 , Argv = 0x7fff42873018 ) At GDB. C: 8
8 For (; I < 10 ; I ++ )
(GDB) Next
Hardware watchpoint 3 : I
Old Value = 2
New Value = 3
0x00000000004004c1 In Main (argc = 1 , Argv = 0x7fff42873018 ) At GDB. C: 8
8 For (; I < 10 ; I ++ )
(GDB) Next
Breakpoint1, Main (argc=1, Argv=0x7fff42873018) At GDB. C:9
9Sum+ =I;
(GDB) Next
Hardware watchpoint2: Sum
Old Value= 3
New Value = 6
Main (argc = 1 , Argv = 0x7fff42873018 ) At GDB. C: 8
8 For (; I < 10 ; I ++ )
(GDB)