调用gdb自动将参数传递给正在调试的程序 [英] Invoke gdb to automatically pass arguments to the program being debugged

查看:146
本文介绍了调用gdb自动将参数传递给正在调试的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个脚本(在某些情况下)将执行gdb并自动运行一些带有一些参数Y的程序X.一旦程序执行完毕,用户应该保持在gdb的提示符下,直到s / he显式地退出它。

I'd like to write a script that (under certain conditions) will execute gdb and automatically run some program X with some set of arguments Y. Once the program has finished executing the user should remain at gdb's prompt until s/he explicitly exits it.

执行此操作的一种方法是让脚本将run命令加参数Y输出到某个文件F,然后让脚本像这样调用gdb :

One way to do this would be to have the script output the run command plus arguments Y to some file F and then have the script invoke gdb like this:

gdb X < F

但是有没有办法在不引入临时文件的情况下执行此操作?

But is there a way to do this without introducing a temporary file?

谢谢。

Thanks.

推荐答案

如果你想通过GDB运行一些命令然后让它退出或者运行完成,只需要执行

If you want to run some commands through GDB and then have it exit or run to completion, just do

echo commands | gdb X

如果您想在运行这些命令后将它留在命令提示符处,可以执行

If you want to leave it at the command prompt after running those commands, you can do

(echo commands; cat) | gdb X

这导致将命令回显给GDB,然后键入 cat 进程,它将stdin复制到标准输出,它被传送到GDB中。

This results in echoing the commands to GDB, and then you type into the cat process, which copies its stdin to stdout, which is piped into GDB.

这篇关于调用gdb自动将参数传递给正在调试的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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