1

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!

2
  • Maybe the segfault happens before the program even gets to main.
    – aschepler
    Mar 15, 2013 at 12:44
  • how is it possible? for the first run, it ok until the 32-th line in the main function
    – user138126
    Mar 15, 2013 at 13:05

3 Answers 3

1

Simply re-issue the run command. You will lose program state, but not breakpoints which seems to match what you need.

1
  • re-run doesn't work, even if I set the break point at the very beginning of the main(). it is very strange!
    – user138126
    Mar 15, 2013 at 12:39
0

"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"?

1
  • I recompiled it and restarted gdb, the problem persists!
    – user138126
    Mar 15, 2013 at 13:24
0

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:

  1. Rebuild program from scratch with debug info (-g gcc option). Reset breakpoint and watch for any warnings from gdb.
  2. If program still crashes with breakpoint set on main look at stack trace (bt command in gdb). It is probably happening before main and you will not see main in stack trace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.