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

查看:24
本文介绍了如何在 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

如果您希望它自动运行,请将一些命令放在文件中(例如运行")并将其作为参数:-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天全站免登陆