Get rid of "quit anyway" prompt using GDB: Just kill the process and quit

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.

15588 次浏览
set confirm off

See gdb doc for details

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

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

Type:Ctrl + D

Before

xx@yy: ~>

(gdb)

After

(gdb) quit

Then

xx@yy: ~>

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

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