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 !!!