GDB Common Debug Commands

Source: Internet
Author: User

Add-G option at program compile time to support GDB debugging

Such as:

$ gcc-g Example.c-o example.x

After compiling the example.c with the above command, go to GDB debugging using the following command:

$ gdb example.x

In GDB debugging, the following commands are commonly used:

$ list Indent slightly l

List the program source code, each listing 10 lines, press Enter repeatedly run the previous command;

$ run shrinks slightly R

The program starts to run, after R can join the program startup parameters, the program runs to the breakpoint pause;

$ continue shrink slightly c

The program continues to run, pausing at the next breakpoint;

Single-Step debugging

$ step Indent slightly s

$ next shrinks slightly n

The program continues to run to the next breakpoint;

$ break shrinks slightly b

Set breakpoints at a certain point in the program;

$ info Break indent slightly i B

View breakpoint information;

Set/view Run parameters

$ set args---/show args

Load the running process for debugging (Attach to the running process to be debugged.) :

$ gdb attatch pid

Specifying source Directories

$ dir dirname ...

Output memory block data in hexadecimal

$ X/28HX---

Section error debugging, core file sample

Use the Ulimit command to see if the system is configured to support the functionality of dump core. With Ulimit-c or ulimit-a, you can see the configuration of the core file size, if 0, the system shuts down the dump core and can be opened by Ulimit-c Unlimited. If a segment error occurs, but there is no core dump, the system disables the creation of the core file.

$ GDB [exec file] [core file]

To view stack information:

$ bt

PS: For Python programs under Linux You can use the PDB to do debugging!

Published by Windows Livewriter.

GDB Common Debug Commands

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.