This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: argc - cant access memory


On 10 July 2007 13:13, Hadron wrote:


> As for optimizing the arguments away, wouldn't this be the case for all
> the lines referencing argc in the main()? But is this the typical
> "error" for such a case?

  Ah, I've just recognised what's going on here, this is not optimisation,
that's a red herring.
 
> 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 is normal behaviour.  It's nothing to do with optimisation: it's just
that gdb breakpoints at the very start of the function epilogue, but none of
the arguments parameters are accessible in the expected places indicated by
the debug info until after the epilogue has created the stack frame, etc.

  Try this with any function you like: set a breakpoint on the very first line
- the one with the opening '{' of the function, run until you hit the
breakpoint.  You'll see nonsense in the locals and arguments.  Now use the
'next' function to step over the opening brace - which amounts to stepping
over the function epilogue - and suddenly all those variables will spring into
being with their correct values.

  It's a cosmetic glitch that gdb fails to say something like "not in scope"
before the prologue has completed.


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]