如何在Bash脚本中使用GDB运行带有命令行参数的程序? [英] How do I run a program with commandline arguments using GDB within a Bash script?

查看:112
本文介绍了如何在Bash脚本中使用GDB运行带有命令行参数的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GDB上运行程序时,通常在 run 命令中给出该程序的参数。有没有一种方法可以使用GDB运行程序并在shell脚本中提供参数?

When running a program on GDB, usually, the arguments for the program are given at the run command. Is there a way to run the program using GDB and as well as give arguments within a shell script?

我看到一个相关问题的答案,提到我们可以附加脚本开始执行后,将GDB添加到程序中。但是然后我将不得不等待该程序。

I saw an answer in a related question, mentioning that we can attach GDB to the program after the script starts executing. But then I will have to 'wait' the program.

还有另一种方法吗?

推荐答案

您可以使用--args参数运行gdb,

You can run gdb with --args parameter,

gdb --args executablename arg1 arg2 arg3

如果您希望它自动运行,请将一些命令放在文件中(例如'run' ),并将其作为参数:-x / tmp / cmds。可选地,您可以-batch模式运行。

If you want it to run automatically, place some commands in a file (e.g. 'run') and give it as argument: -x /tmp/cmds. Optionally you can run with -batch mode.

gdb -batch -x /tmp/cmds --args executablename arg1 arg2 arg3

这篇关于如何在Bash脚本中使用GDB运行带有命令行参数的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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