Favolas
Favolas

Reputation: 7243

gdb debug with more than one argument

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.

Upvotes: 6

Views: 3099

Answers (3)

GoZoner
GoZoner

Reputation: 70225

Populate a .gdbinit with:

set args file1.pgm file2.pgm

then simply

gdb> run

Upvotes: 1

0xC0000022L
0xC0000022L

Reputation: 21319

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.

Upvotes: 8

geekosaur
geekosaur

Reputation: 61459

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

Upvotes: 1

Related Questions