Author Topic: Variables in Heap: View values (debugger)  (Read 3970 times)

Offline myle

  • Single posting newcomer
  • *
  • Posts: 3
Variables in Heap: View values (debugger)
« on: April 26, 2008, 03:52:19 pm »
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.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Variables in Heap: View values (debugger)
« Reply #1 on: April 28, 2008, 10:05:01 am »
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 *[email protected]   (if your variable name is x and the array has 20 elements, type p *[email protected])

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."

Offline myle

  • Single posting newcomer
  • *
  • Posts: 3
Re: Variables in Heap: View values (debugger)
« Reply #2 on: April 28, 2008, 03:51:09 pm »
Thanks Thomas.
The values are shown in the debugger tab of Logs & others.