Common GDB Debugging commands and gdb debugging

Source: Internet
Author: User
Tags gdb debugger

Common GDB Debugging commands and gdb debugging

Add the-g option during program compilation to support gdb debugging.

For example:

$ Gcc-g example. c-o example. x

After compiling example. c using the preceding command, run the following command to debug gdb:

$ Gdb example. x

In gdb debugging, the following common commands are used:

$ List scale down to l

List the source code of the program, and list 10 lines each time. Press enter to repeat the previous command;

$ Run scale down to r

The program starts running. After r, you can add the program startup parameter to pause the program running at the breakpoint;

$ Continue is reduced to c

The program continues to run and stops at the next breakpoint;

Single-step debugging

$ Step is reduced to s

$ Next is reduced to n

The program continues to run to the next breakpoint;

$ Break is reduced to B

Set a breakpoint at a certain position of the program;

$ Info break is reduced to I B

View the breakpoint information;

Set/view running parameters

$ Set args ---/show args

Attach to the running process to be debugged .):

$ Gdb attatch pid

Specifying source directories

$ Dir dirname...

Output memory block data in hexadecimal format

$ X/28hx ---

Segment error debugging, core file example

Run the ulimit command to check whether the system configuration supports the dump core function. You can use ulimit-c or ulimit-a to view the configuration of the core file size. If it is 0, the system disables dump core. You can use ulimit-c unlimited to open the file. If a segment error occurs but no core dump exists, the system prohibits the generation of core files.

$ Gdb [exec file] [core file]

View stack information:

$ Bt

PS: For python programs in linux, you can use pdb for debugging!

Published by Windows Livewriter.


In linux, the l command in the gdb debugger is not clear about its usage.

Many, but the general commands are basically the same; understand the basic structure of Linux directories, how to name various hardware (I was confused by its naming rules for Hard Disk Partitions when I first came into contact with Linux), and how users interact with hardware through the Linux kernel; you can also find a Linux release, such as Ubuntu, which is currently quite popular, to familiarize yourself with how to configure its various services. If you are later engaged in development in Linux, then you can learn how to program in Linux, C/C ++, and so on, master the basic usage of the GCC/G ++ compiler, the GDB debugger, and learn to write Makefile to manage your project; recommended books: Linux Standard learning tutorial (for Red Hat Enterprise Linux 4, I have mentioned that the basic commands are similar, the configuration file is different in different releases in some places), "UNIX/Linux Programming Practice tutorial" (that is, Understanding UNIX/Linux Programming), and "UNIX environment advanced Programming" (that is, Advan Ced Programming In The UNIX Environment ). The first two articles are used for getting started. Now I have seen the second one. The last one has not been read yet. It is very thick. The comments are classic! If you want to learn more, find a direction, such as application layer development, driver layer development, and kernel research. Finally, I wish you success!
In addition, the webmaster group has products to buy, Which is cheap and guaranteed.

When programming in linux, use GDB for debugging and use the s command for single-step debugging. However, for example, if the printf function is available, it will enter and the command is returned

Finish

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.