How to Use GDB to debug programs in Linux

Source: Internet
Author: User
How to Use GDB to debug programs in Linux-general Linux technology-Linux programming and kernel information. For details, refer to the following section. In Linux, GDB is generally used for program debugging.

The following describes how to debug a program using gdb:

(1) Go to gdb for debugging:
Gdb + runs the compiled executable program-to enter the debugging mode. For example, gdb MiddlePublisher

(2) r + runtime parameters-start to run the executable program. For example, r-lxml2-f refile

(3) B + breakpoint-set the breakpoint for debugging. Two types: B CMSTask. cpp: 200 indicates that the breakpoint is set in line 200th OF THE CMSTask. cpp file. Another type: B TaskManager: buildPubWinTask indicates that it is stopped when the buildPubWinTask function is executed.

(4) cancel the breakpoint:
Dis 1 indicates canceling the first breakpoint
Dis 2 indicates canceling the second breakpoint

(5) view the breakpoint setting information: info B

(6) view the code details at the breakpoint stop: l

(7) You can directly compile the program in gdb, and then re-run the program, gdb will directly execute the newly compiled executable program. For example, execute make directly under gdb and then run it in Chongqing.

(8) follow up a function: s
If the breakpoint is set at a function entry. When the breakpoint is reached, type s to enter the function for internal debugging. If multiple functions exist, type S multiple times to enter the internal function.

PS:
1. Multiple windows are enabled on the SecureCRT remote logon interface. When switching between windows, use: Alt + 1, Alt + 2... to switch to 1st and 2nd windows.

2. Copy the copied content on the remote logon interface of SecureCRT Using Shift + Insert.

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.