82

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kagali-san
  • 2,964
  • 7
  • 48
  • 87

5 Answers5

102

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
Telvas
  • 158
  • 8
Eric
  • 5,137
  • 4
  • 34
  • 31
  • 5
    This can be done for any command (but not aliases), documentation is available at https://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 Feb 18 '15 at 10:14
38
set confirm off

See gdb doc for details

ks1322
  • 33,961
  • 14
  • 109
  • 164
  • 2
    This does the job, but it also disables all other confirmations. – Uli Köhler Nov 05 '14 at 19:46
  • I [didn't need](https://stackoverflow.com/questions/75631484/gdb-doesnt-support-dwarf-5-macro-sections) to interact with `gdb`, so this worked for me. – x-yuri Mar 03 '23 at 20:50
15

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

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
13

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

gdb -ex="set confirm off" -ex=r --args ...
Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57
-4

Type:Ctrl + D

Before

xx@yy: ~>

(gdb)

After

(gdb) quit

Then

xx@yy: ~>

reg
  • 9