在 Linux 中启动 GDB 时如何传递命令行参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14494957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I pass a command line argument while starting up GDB in Linux?
提问by ShadyBears
I have to debug a program that has errors in it as part of my assignment. However, I must first pass command line arguments in order to solve this problem.
作为作业的一部分,我必须调试一个有错误的程序。但是,我必须首先传递命令行参数才能解决这个问题。
I do:
我愿意:
gdb -tui InsertionSortWithErrors
which works, but after that I don't know how to pass arguments. I used gdb -help
and it says something about --args
which I also tried and it didn't work.
哪个有效,但在那之后我不知道如何传递参数。我用过gdb -help
,它说一些--args
我也尝试过但没有用的东西。
I want to be able to get the debugger+the GUIand pass command line arguments.
我希望能够获得调试器+ GUI 并传递命令行参数。
采纳答案by ldav1s
Once gdb
starts, you can run the program using "r args".
一旦gdb
开始,你可以运行使用“R程序ARGS”。
So if you are running your code by:
因此,如果您通过以下方式运行代码:
$ executablefile arg1 arg2 arg3
Debug it on gdb
by:
gdb
通过以下方式调试它:
$ gdb executablefile
(gdb) r arg1 arg2 arg3
回答by Basile Starynkevitch
Try
尝试
gdb --args InsertionSortWithErrors arg1toinsort arg2toinsort
回答by Alex
I'm using GDB7.1.1, as --help
shows:
我正在使用 GDB7.1.1,如图--help
所示:
gdb [options] --args executable-file [inferior-arguments ...]
IMHO, the order is a bit unintuitive at first.
恕我直言,这个顺序起初有点不直观。
回答by Fernando Gonzalez Sanchez
Another option, once inside the GDB shell, before running the program, you can do
另一种选择,一旦进入 GDB shell,在运行程序之前,你可以这样做
(gdb) set args file1 file2
and inspect it with:
并检查它:
(gdb) show args