0

I always use GDB in an interactive session (gdb --args <program>)

Two questions:

  1. Is it possible to configure .gdbinit to automatically generate the core dump file?

  2. Related to first Q, if the program crashes is there a GDB session command to manually generate the core dump file?

1 Answer 1

1

Is it possible to configure .gdbinit to automatically generate the core dump file?

Maybe: configure to generate the core dump when ?

if the program crashes is there a GDB session command to manually generate the core dump file?

(gdb) help gcore
generate-core-file, gcore
Save a core file with the current state of the debugged process.
Usage: generate-core-file [FILENAME]
Argument is optional filename.  Default filename is 'core.PROCESS_ID'.

Update:

i'd like to auto-generate the core file on receiving a SIGABRT/segmentation fault etc?

The only way I know is to set up a signal handler for all signals of interest, set a breakpoint on the signal handler, and add commands to that breakpoint. Something along the lines of:

struct sigaction sa{};
sa.sa_handler = my_handler;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGABRT, &sa, NULL);
...
(gdb) break my_handler
(gdb) commands $bpnum
gcore
end

(Above commands should work from ~/.gdbinit as well.)

Sign up to request clarification or add additional context in comments.

4 Comments

In response to your question: i'd like to auto-generate the core file on receiving a SIGABRT/segmentation fault etc? Anything where the program cannot continue
@intrigued_66 I've updated the answer.
Would catch signal not work for this?
@ssbssa Looks like you are right: "One reason that catch signal can be more useful than handle is that you can attach commands and conditions to the catchpoint."

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.