Friday, 24 July 2009

Examing variables with the print command in gdb

I've been working on some code to allow me to save the state of my simulation to a file. Along the way I needed to check the value of a variable. The strange thing is that I was not able to examine it directly in gdb. However, I could examine it by calling a function which returned the value of the variable. I suspect that I am not understanding the print command in gdb properly.

(gdb) print fMaxCritters
$12 = 0
(gdb) print this->GetMaxCritters()
$13 = 8

2 comments:

  1. If the program is a quick one off, I put in a temporary printf() statement. If it's anything more serious, I use in-line tracing. I've just written an API for doing this, and would love some feed back: http://www.bigangrydog.com/tracedog/code_tracing.xhtml

    ReplyDelete
  2. Hi Andy,

    Yep, printf() is ever reliable. Thanks for letting me know about your in-line tracing API, I'll check it out soon!

    ReplyDelete