2

I had this bite me in a certain sensitive spot this evening, and would like some clarification. As karlphillip said in this question, the executable sees the argument list as

Consider: ./program file.txt

argv[0] is "program"
argv[1] is "file.txt"

However, in the gdb debugger, for the program ./lc1 f1.txt, the arglist shows as

arg[0] is "/home/jason/Project 6/lc1"
arg[1] is "lc1"
arg[2] is "f1.txt"

Why the discrepancy between the two arglists?

1 Answer 1

3

I can't reproduce that error. How are you running it on the gdb prompt?

I'm guessing you have

(gdb) run lc1 f1.txt

which is wrong. In the gdb prompt, it's supposed to be

(gdb) run f1.txt

That will reconcile with your normal execution.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it. I was entering the first option in the gdb command line. Funny thing, it was my prof that showed us that way of starting an executable in the debugger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.