How do I pass a command line argument while starti

2019-01-10 18: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 gui and pass command line arguments.

4条回答
ら.Afraid
2楼-- · 2019-01-10 18:32

I'm using gdb 7.1.1, as --help show:

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

IMHO the order is a bit unintuitive at first.

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-10 18:35

Try

gdb --args InsertionSortWithErrors arg1toinsort arg2toinsort
查看更多
Viruses.
4楼-- · 2019-01-10 18:43

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

(gdb) set args file1 file2

and inspect it with

(gdb) show args
查看更多
三岁会撩人
5楼-- · 2019-01-10 18:49

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
查看更多
登录 后发表回答