87

Consider:

(gdb) q
A debugging session is active.

        Inferior 1 [process 9018] will be killed.

Quit anyway? (y or n) y

What is a .gdbinit option to make GDB always kill the running process at a quit request?

I know that GDB can attach to already-running processes, so it would be bad to kill them at quit. But for a processes started from it, a need to confirm your actions starts to annoy at a second quit.

5 Answers 5

110

Turning confirmation prompts off globally disabled many other useful checks, such as the one to ask you if you really want to delete all breakpoints when you type "delete".

It would be better to disable the prompt only for the quit command. You can do that by adding this hook to your ~/.gdbinit (for current user) or /etc/gdb/gdbinit (for all users):

define hook-quit
    set confirm off
end
3
  • 5
    This can be done for any command (but not aliases), documentation is available at sourceware.org/gdb/onlinedocs/gdb/Hooks.html define hookpost-handle set confirm on end could then also be useful to reverse the confirmation request after a command is handled.
    – Lekensteyn
    Commented Feb 18, 2015 at 10:14
  • is there something similar for lldb? Commented Jan 20 at 17:31
  • It would be great to set this via the command line (via -ex) but unfortunately I think this is impossible without an intermediate file (e.g., $HOME/.gdbinit or via --command somefile).
    – stefanct
    Commented Mar 28 at 15:41
40
set confirm off

See gdb doc for details

2
  • 2
    This does the job, but it also disables all other confirmations. Commented Nov 5, 2014 at 19:46
  • I didn't need to interact with gdb, so this worked for me.
    – x-yuri
    Commented Mar 3, 2023 at 20:50
18

Another option is to define a new command that quits without asking for confirmation:

define qquit
  set confirm off
  quit
end
document qquit
Quit without asking for confirmation.
end

Now you can use qquit or just qq to exit quickly, without changing the default behaviour of quit

1
  • Nice hint, even though it interprets the question a bit liberally. :) Commented May 11, 2015 at 19:47
14

In conclusion this will run the program directly and don't ask for quit confirmation:

gdb -ex="set confirm off" -ex=r --args ...
-4

Type:Ctrl + D

Before

xx@yy: ~>

(gdb)

After

(gdb) quit

Then

xx@yy: ~>

2
  • 2
    Your answer is very vague and does not help in solving the problem at hand. Commented Feb 22, 2021 at 20:55
  • nice. this also works on lldb Commented Jan 20 at 17:32

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