News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Variables in Heap: View values (debugger)

Started by myle, April 26, 2008, 03:52:19 PM

Previous topic - Next topic

myle

I am running Ubuntu 8.04 and I have installed the Code::Blocks from the repositories:
deb http://lgp203.free.fr/ubuntu/ hardy universe
deb http://apt.wxwidgets.org/ hardy-wx main

The problem which I face is that I can't see the value of some specific position of an array allocated in heap (via new or malloc, I think I tried it both on C and C++). The local variables or the function arguments are properly shown in the Debug > Debugging Windows > Watches but not in Debug > Debugging Windows > Examine Memory if I write &var where var is a local variable. It displays nothing.
Same goes to the variables which are allocated dynamically but the problem is that I don't know any other way to see their values (using C::B)

I guess I am doing something wrong. What is it and how can I see the values of the variables?

Thanks for your replies,
if my question is silly, I am sorry but I am a newbie here.

thomas

The debugger doesn't have enough information to show the values. Neither does it know that the pointer points to an array, nor the array's size.

You can get it to print your array by sending a manual command to the debugger (last menu item in the debug menu):
p *array@size   (if your variable name is x and the array has 20 elements, type p *x@20)

http://www.delorie.com/gnu/docs/gdb/gdb_54.html
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

myle

Thanks Thomas.
The values are shown in the debugger tab of Logs & others.