防止调试会话在每次低级退出后暂停

Cra*_*ger 5 debugging gdb multiple-processes

我正在使用gdb非常方便的多劣支持来调试进程树:

(gdb) set detach-on-fork off
(gdb) set schedule-multiple on
(gdb) set follow-fork-mode parent
(gdb) break PostgresMain
(gdb) break PostmasterMain
Run Code Online (Sandbox Code Playgroud)

现在需要让事情运行,直到我在一些尚未产生的劣势中遇到未来的断点之一。

但是,gdb每当低级正常退出时似乎“有帮助”暂停,或者至少阻止对低级的清理以便其父级wait()可以返回:

(gdb) c
[New process 16505]
process 16505 is executing new program: /home/craig/pg/bdr/bin/pg_config
Reading symbols from /home/craig/pg/bdr/bin/pg_config...done.
[Inferior 2 (process 16505) exited normally]
(gdb) info inferior
  Num  Description       Executable        
* 2    <null>            /home/craig/pg/bdr/bin/pg_config 
  1    process 16501     /usr/bin/make     
(gdb) inferior 1
[Switching to inferior 1 [process 16501] (/usr/bin/make)]
[Switching to thread 1 (process 16501)] 
#0  0x0000003bc68bc502 in __libc_wait (stat_loc=0x7fffffffbc78) at ../sysdeps/unix/sysv/linux/wait.c:30
30          return INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
(gdb)
Run Code Online (Sandbox Code Playgroud)

所以我必须无休止地:

(gdb) inferior 1
(gdb) c
Run Code Online (Sandbox Code Playgroud)

继续。大约 70 次,在我在一个孩子的孩子的孩子中达到所需的断点之前。

认为正在发生的事情是gdb将进程退出视为停止事件,并且由于non-stop设置为off(默认值),当一个线程停止时,它会停止所有下级线程中的所有线程。但是,这个劣势已经终止,不是正常的停止事件,所以不能就cont这样,必须先切换到另一个进程。

有什么方法可以阻止 gdb 在每个低级出口暂停?我会一直期待follow-fork-mode parentschedule-multiple on这样的伎俩,但gdb似乎仍想停止时的劣势退出。

我想我正在寻找诸如“跳过过程退出”之类的东西,或者我可以更改处理程序策略的虚拟信号,因此它不会停止。


set non-stop on 似乎它应该是正确的答案,但我怀疑它因多个劣势而被破坏。

如果我使用non-stop on,那么在第一个退出陷阱之后,gdb的内部状态表明低级 1 正在运行:

(gdb) info inferior
  Num  Description       Executable        
* 1    process 20540     /usr/bin/make     
(gdb) info thread
  Id   Target Id         Frame 
* 1    process 20540 "make" (running)
(gdb) cont
Continuing.
Cannot execute this command while the selected thread is running.
Run Code Online (Sandbox Code Playgroud)

但内核认为它被阻止ptrace_stop

$ ps -o "cmd,wchan" -p 20540
CMD                         WCHAN
/usr/bin/make check         ptrace_stop
Run Code Online (Sandbox Code Playgroud)

...它gdb在分离或被杀死之前不会取得任何进展。进程的信号被忽略,并且interruptingdb无效。


GNU gdb (GDB) Fedora 7.7.1-18.fc20在 x86_64 上使用。

Cra*_*ger 7

在偶然发现一篇顺便引用它的帖子后,我发现缺少的魔法就set target-async on在旁边set non-stop on

正如预期的那样,不间断模式意味着每当劣等退出时,gdb 都不会停止一切。target-async需要使其在 gdb 7.7 上真正正常工作;这是 7.8 上的默认值。

所以完整的咒语是:

set detach-on-fork off
set schedule-multiple on
set follow-fork-mode parent
set non-stop on
set target-async on
Run Code Online (Sandbox Code Playgroud)

对于 7.8,删除target-async on并添加 来减少噪音set print symbol-loading off