如何在bash脚本中使用gdb使用命令行参数运行程序? [英] How do I run a program with commandline args using gdb within a bash script?

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

问题描述

在gdb上运行程序时,通常在运行命令中给出该程序的参数。有没有办法使用gdb来运行程序,并且在shell脚本中提供参数?

我在相关问题中看到了一个答案,提到我们可以在脚本开始执行后将gdb附加到程序中。但我必须'等待'程序。



我很好奇是否有其他方法可以做到这一点。


<你可以使用--args参数来运行gdb,

pre $ gdb --args executablename arg1 arg2 arg3

如果您想让它自动运行,请将一些命令放入文件(例如'run')并将其作为参数:-x / tmp / cmds。您可以使用-batch模式运行。

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

HTH


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

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

I'm curious whether there is any other way to do this.

解决方案

You can run gdb with --args parameter,

gdb --args executablename arg1 arg2 arg3

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

HTH

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

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