Re: argc - cant access memory

Jim Blandy
2007-07-11T17:41:41Z

Hadron <rileyrg@googlemail.com> writes:
> I get the message after stepping over the first line in main and then
> when I get to line 3 (in main) then I get
>
> #0 main (argc=191860, argv=0xb7f49850) at hello.c:94
>
> (94 is the line "glutInitWindowSize (250, 250);" in main)
>
> If you say this is normal behaviour then fine, but I haven't experienced
> it before. I would be interested to hear if you get the same.

This really looks like what happens when you debug optimized code.
The compiler emits debugging information that doesn't accurately
relate the machine code it generated to the original source. If this
is the case, there isn't much a debugger can do about it. You might
try re-compiling without optimization.

But the make fragment you posted didn't look like it was compiled with
optimization. Without optimization, the compiler is supposed to
generate code which behaves as expected under the debugger; from the
GCC manual:

Without any optimization option, the compiler's goal is to reduce
the cost of compilation and to make debugging produce the expected
results. Statements are independent: if you stop the program with
a breakpoint between statements, you can then assign a new value
to any variable or change the program counter to any other
statement in the function and get exactly the results you would
expect from the source code.