How do I pass a command line argument while starting up GDB in Linux?

女生的网名这么多〃 提交于 2020-01-19 02:34:25

问题


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.

I want to be able to get the debugger+the GUIand pass command line arguments.


回答1:


Once gdb starts, you can run the program using "r args".

So if you are running your code by:

$ executablefile arg1 arg2 arg3 

Debug it on gdb by:

$ gdb executablefile  
(gdb) r arg1 arg2 arg3



回答2:


Try

gdb --args InsertionSortWithErrors arg1toinsort arg2toinsort



回答3:


I'm using GDB7.1.1, as --help shows:

gdb [options] --args executable-file [inferior-arguments ...]

IMHO, the order is a bit unintuitive at first.




回答4:


Another option, once inside the GDB shell, before running the program, you can do

(gdb) set args file1 file2

and inspect it with:

(gdb) show args


来源:https://stackoverflow.com/questions/14494957/how-do-i-pass-a-command-line-argument-while-starting-up-gdb-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!