如何从外部分离gdb会话? [英] How can I detach a gdb session from outside?

查看:69
本文介绍了如何从外部分离gdb会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在后台使用以下命令启动gdb会话:

  gdb --batch --command =/tmp/my_automated_breakpoints.gdb -p pid_of_proces>&>/tmp/gdb-results.log& 

最后的& 使其在后台运行(由于此命令是由单个 ssh 命令发出的,因此此后立即关闭外壳)./p>

我可以使用 ps -aux |查找 gdb 会话的 pid .grep gdb .

但是:如何像使用(gdb)detach 命令在我面前进行终端会话一样,如何从正在运行的进程中优雅地分离此gdb会话?

当我使用 kill -9 gdb_pid 杀死gdb会话(而不是正在运行的进程本身)时,随后在运行的程序中会得到不需要的 SIGABRT .

>

重新启动服务对于我而言太耗时了.

如果使用此自动化脚本成功进行调试,则可以在批处理脚本中使用detach命令.但是,这不是我的情况:当会话期间出现一些错误时,我想分离/退出正在运行的gdb会话,因此我想从另一个终端会话中手动分离gdb.

解决方案

如果在后台#1终端上运行 gdb 命令,则始终可以带 gdb 通过运行命令 fg 返回到前台.然后,您可以像往常一样简单地按CTRL + C和 detach 即可正常停止调试会话.

假设#1终端现在被其他东西占用,并且您无法使用它,则可以向 gdb 进程发送 SIGHUP 信号以将其分离:

  sudo kill -s SIGHUP $ {pidof gdb) 

(如果您有多个gdb实例,请用实际的PID替换 $(pidof gdb))

I start a gdb session in the background with a command like this:

gdb --batch --command=/tmp/my_automated_breakpoints.gdb -p pid_of_proces> &> /tmp/gdb-results.log &

The & at the end lets it run in the background (and the shell is immediately closed afterwards as this command is issued by a single ssh command).

I can find out the pid of the gdb session with ps -aux | grep gdb.

However: How can I gracefully detach this gdb session from the running process just like I would if I had the terminal session in front of me with the (gdb) detach command?

When I kill the gdb session (and not the running process itself) with kill -9 gdb_pid, I get unwanted SIGABRTs afterwards in the running program.

A restart of the service is too time consuming for my purpose.

In case of a successful debugging session with this automated script I could use a detach command inside the batch script. This is however not my case: I want to detach/quit the running gdb session when there are some errors during the session, so I would like to gracefully detach gdb by hand from within another terminal session.

解决方案

If you run the gdb command from terminal #1 in the background, you can always bring gdb back into foreground by running the command fg. Then, you can simply CTRL+C and detach as always to stop the debugging session gracefully.

Assuming that terminal #1 is now occupied by something else and you cannot use it, You can send a SIGHUP signal to the gdb process to detach it:

sudo kill -s SIGHUP $(pidof gdb)

(Replace the $(pidof gdb) with the actual PID if you have more than one gdb instance)

这篇关于如何从外部分离gdb会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆