我如何从gdb命令提示符执行外部命令? [英] How can I execute external commands from the gdb command prompt?

查看:284
本文介绍了我如何从gdb命令提示符执行外部命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gdb调试一个程序。每当我错过一个断点或决定添加另一个观察点时,我必须杀死这个进程并重新运行它。为了将现有的gdb附加到它,我使用 attach< pid> 。然而,我必须找出新进程的pid。



我今天的做法是暂停gdb,使用 ps -C <程序名称> ,然后返回到gdb附加到它。



有什么办法可以从gdb命令提示符而不退出到shell,这样我就可以在gdb里面做这样的事情:

 附加`ps -C < program_name>`

我正在使用linux。

(gdb)help shell

执行
行的其余部分作为shell命令。如果没有
参数,运行一个低级shell。


完成后,可以使用'exit'返回到gdb。

I am debugging a program using gdb. Whenever I miss a breakpoint or decide to add another watchpoint, I have to kill the process and rerun it. In order to attach the existing gdb to it, I use attach <pid>. However, I have to find out the pid of the new process.

The way I do that today is to suspend gdb, get the pid with ps -C <program_name> and then return to gdb to attach to it.

Is there any way to run a unix command from the gdb command prompt without exiting to the shell, so that I could do something like this from inside gdb:

attach `ps -C <program_name>`

I am working on linux.

解决方案

(gdb) help shell
Execute the rest of the line as a shell command. With no arguments, run an inferior shell.

After finish, you can use 'exit' to return to gdb.

这篇关于我如何从gdb命令提示符执行外部命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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