GDB program debugging

Source: Internet
Author: User

GDB is a powerful program debugging tool released by GNU. It provides three functions:

1. Start the program debugging.

2. Let the program being debugged stop at the specified position

3. When the program is stopped, you can view the running status of the program.


Example:

1. compile and generate an executable file:

Gcc-g hello. c-o hello

2. Start GDB

Gdb hello

3. Set breakpoints in the main function

Break main

4. Run the program

Run


Common GDB commands

Gdb hello Start GDB
File hello Load file name
List (l)
View programs
Breakb) function name Add a breakpoint at the function entry
Break (B) row number

Add a breakpoint to a specified row

Break (B) File Name: row number Add a breakpoint to the specified row of the specified file
Break (B) row number if condition When the condition is true, the breakpoint at the specified row number takes effect.
Info break View All set breakpoints
Delete breakpoint number Delete breakpoint
Run (r) Start running the program
Next (n)
A single-step running program does not enter the sub-function)
Steps)

One-step program running

Continue (c) Continue running the program
Print (p) variable name
View specified variable values
Finish
Run the program until the current function ends.
Watch variable name
Monitor specified variables
Quit (q)
Exit gdb

#include<stdio.h>#define MAX_RECORD_NUMBER 10int record[MAX_RECORD_NUMBER] ={12,76,48,62,94,17,37,52,69,32};swap(int* x,int* y){    int temp;    temp = *x;    *x = *y;    *y = temp;}int main(){    int i,j;    for(i=0;i<MAX_RECORD_NUMBER-1;i++)    {        for(j=MAX_RECORD_NUMBER-1;j>1;j++)        {            if(record[j])<record[j-1]            {                swap(&record[j],&record[j-1]            }        }     }    for(i=0;i<MAX_RECORD_NUMBER-1;i++)    {        printf("%d",record[i]);    }      printf("\n");    return 0;}


Related Article

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.