Reputation: 1003
I'm using gdb for debugging I get a segmentation fault, and then I want to set another break point in the main function and run the program from the beginning however, although I have finished the current run and it shows "THe program is not being run"
when I input 'list'
it shows a code snippet of a libarary file it means currently I'm not in the main function
If I re-run the program, even if I set the break point at the beginning of the main() it still get segmentation fault, it means the program is running within the library file
so how to return to the main() function? thanks!
tips: I'm using libpcap.h and I have a '-lpcap' option when compiling
BTW, when I use break 9 to set a breakpoint at 9, gdb runs the program to the 11-th line? what is wrong with this inaccuracy? thanks!
Upvotes: 1
Views: 777
Reputation: 35825
If I re-run the program, even if I set the break point at the beginning of the main() it still get segmentation fault, it means the program is running within the library file
Actually it means that you either failed to set breakpoint on main
function or program execution not reaches main
and gets segmentation fault. Try the following steps:
-g
gcc option). Reset breakpoint and watch for any warnings from gdb.main
look at stack trace (bt
command in gdb). It is probably happening before main
and you will not see main
in stack trace.Upvotes: 0
Reputation: 11963
"BTW, when I use break 9 to set a breakpoint at 9, gdb runs the program to the 11-th line" - from this, and other information you've provided, it sounds like perhaps the source code is out of sync with gdb's mapping of addresses to source lines. Have you by any chance been editing the program? Have you recompiled it and restarted gdb? Have you seen any warnings similar to "executable is more recent than source"?
Upvotes: 0