Debug multi-file projects using GDB

Source: Internet
Author: User

In the past, GDB debugging was used only to debug a single file. During DHCP secondary relay, gdb debugging was required for the entire project. I found that I could not! Now, I am able to share it with you on my blog.

The following describes how to debug the isc dhcp code.

 

Start dhcrelay: sudo gdb dhcrelay

Because dhcrelay must be enabled with parameters, set args: set args-d-I eth0-m forward 192.168.10.1 is used.

In the main function, the breakpoint position is set in the subcontract function. This is B dhcrelay. c: 362 (note: the position of this line is where the dispatch function is called, and the implementation of the dispatch function is .. /dispatch in the common directory. c)

In the dispatch. the dispatch function in c sets a breakpoint here, so it is necessary to load the common directory (the reason why many files have not been debugged before is that this line of command will not be executed): DIR .. /common

Check the number of rows of the dispatch function: list dispatch. c: dispatch (you can see that the dispatch function is in line 86)

In the dispatch function, set the breakpoint: B dispatch. c: 86.

Finally, start the program and run: run

 

NOTE: If dispatch. c file and dhcrelay. c files in the same directory do not need to use DIR .. /common to specify the directory. After the breakpoint is set, enter s at the gdb prompt and press enter to enter the dispatch. c file !!!

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.