I’m trying to debug a program which takes on the command line a couple of arguments.
Inside the main I print out the arguments as follows:
int main (int argc, char **argv)
{
for (int i = 0; i < argc; i++) {
printf("param%d=%s\n", i, argv[i]);
}
when I run my program without gdb, like this
"program img.jpg 1 2"
I get as output:
param0: program
param1: img.jpg
param2: 1
param3: 2
When I run it with gdb like this:
"program img.jpg 1 2"
I only get
param0: img.jpg
on one hand img.jpg should be param1, also param2 and 3 are missing.
Is there a special way to specify command line params to gdb that I’m missing?
You should specify parameters when you run the program.
First you should invoke the debugger with
Than you start the program also passing command line arguments:
Side note: I think this solution is more flexible than using the
--argsflag, because you can launch your program multiple times with different parameters without quitting the currentgdbinstance (e.g., you keep your breakpoints).