Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remember my choice for display as array in Eclipse C/C++

Tags:

eclipse-cdt

In debug mode of Eclipse for C/C++, you can right-click on any watched expression that is a pointer and select "display as array". Then you're prompted for the array bounds and for the rest of this debug run, the watched expression is being displayed as an array according to these bounds.

When I terminate the process and start debugging again, it remembers my watched expressions, but pointers that were previously displayed as arrays will now be mere pointers again and hence, I have to re-cast all pointers in each debug run. In a recent project, this has become very tiresome.

Is there a way to make Eclipse remember the "display as array" choices for watched expressions?

like image 758
Jesko Hüttenhain Avatar asked Oct 24 '12 13:10

Jesko Hüttenhain


1 Answers

You have to be able to encode the fact that you want to look at the pointer as an array in the expression string itself.

Say you have an array as int* and you want to look at (most at) its first 4 elements.

In the Expressions tab, use one of the two following syntaxes supported by GDB:

  • (*arr @ 4)
  • ((int[4])*arr)

The surrounding (...) parens above are important.

You can do this in the Expressions tabs (watches), but not in the Variables tab.

watching pointer as array

like image 85
vladr Avatar answered Oct 08 '22 08:10

vladr