02. debugging of C language programs in Linux

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.