Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb debug with more than one argument

Tags:

gdb

I have a program that reads one image file, makes some changes on that image and then stores it.

The program runs like this:

./main file1.pgm file2.pgm

I'm using the -g flag so I can use GDB.

Now when I try to run GDB like this

# gdb main file1.pgm file2.pgm

i'm getting this error:

Excess command line arguments ignored. (file2.pgm)

How can I solve this?

My main needs those two arguments.

like image 209
Favolas Avatar asked Apr 09 '12 14:04

Favolas


People also ask

How do I debug a program in gdb?

You may start GDB with its arguments, if any, in an environment of your choice. If you are doing native debugging, you may redirect your program's input and output, debug an already running process, or kill a child process. In order to debug a program effectively, you need to generate debugging information when you compile it.

Does GDB support fork debugging of multiple processes?

On most systems, GDB has no special support for debugging programs which create additional processes using the fork function. When a program forks, GDB will continue to debug the parent process and the child process will run unimpeded.

How does GDB read arguments other than options?

When GDB starts, it reads any arguments other than options as specifying an executable file and core file (or process ID). This is the same as if the arguments were specified by the `-se' and `-c' (or `-p' options respectively.

Can I use GDB with the second command-line argument?

Taking advantage of the second command-line argument requires a fairly complete operating system; when you use GDB as a remote debugger attached to a bare board, there may not be any notion of "process", and there is often no way to get a core dump. GDB will warn you if it is unable to attach or to read core dumps.


2 Answers

From the command line like this:

gdb --args ./main file1.pgm file2.pgm

run at the GDB prompt may be more flexible if you are scripting extensively.

like image 192
0xC0000022L Avatar answered Oct 21 '22 11:10

0xC0000022L


That's not how you pass arguments to a program to be run; it's taking file1.pgm as the name of a core file.

You want to use, within gdb,

gdb> :run file1.pgm file2.pgm
like image 33
geekosaur Avatar answered Oct 21 '22 11:10

geekosaur