Code blocks debugger does not display class attributes when in member function - c++

I am trying to use Code::Blocks debugger, and I'd like to have access to the values of the class attributes when debugging one of its methods.
I know that when I used Visual Studio, I could unfold the argument "this" to see all the values of the class attributes.
Do you know if this is possible with Code::Blocks ? Or is there a workaround ?
I don't see myself debugging with Code::Blocks without this feature.
Thanks

You can manually put *this in the watches ( although I don't expect this kind of workaround to be the right final answer )

Related

How to resolve Qt Creator variable-“<not accessible>” behavior (Opencv)

As observed in the screenshot above, I have the problem that variables in the Locals and Expressions window in QT Creator are displayed as being . How can I get Qt Creator to show the values for the OpenCV filter functions?
QtCreator marks "not accessible" for the value, not for the variable. That means those variables are not initialized yet. Try to inspect the same values by adding another debugging point after the matrices are initialized.
I was getting this for a struct I had defined. I could see the contents of other structs, but not this particular one. It turned out that I was declaring the struct inside a function in my main window object. I just had to take the struct out of the function, just declaring it at global level before the function (not even bothering to put it in the header, although that's better practice). That was enough to allow me to see the values of a QList, that is itself still declared in the function in question.

is it possible to define user-defined variable in visual studio debug window?

For example, I want to check the following expression in debug watch window:
((MyClass1*)0xc56fbf0)->m_data1->m_data2
Is it possible to write something like:
v=0xc56fbf0
((MyClass1*)v)->m_data1->m_data2
It appears that this is not possible in the C++ code (you CAN do that in C# by declaring new variable in the Intermediate window).
However, there is an easy work-around: you can declare one (or few?) global variable of the needed type; call it something like WatchVar, and use it as you wish.

Exploring variables of complex types in Eclipse debugging C++

How do I explore the content of a variable of complex type, say, a multimap where key and value are also of some complex type, like some classes.
Debug can only show the value of the pointer, but not the content of the instance of multimap. I know in gdb, if you have a variable var, and it has a method, say, getAddress(), then you can do something like: p var->getAddress() to see the value retured by that function, Can I do something similar in Eclipse Debug?
Hope this helps:
Here is a way to use standard gdb commands from within Eclipse (a console where you can type them in):
Use gdb console in Eclipse
Here are the scripts Joachim mentioned (multimap is supported): http://sourceware.org/gdb/wiki/STLSupport

Visual Studio Debugger Watch problems

How can I find out the address of a variable on the stack in the visual studio debugger watch window (or elsewhere?)
Reading the variable works fine:
streets streets [11790](0x1c66a690 [...] std::vector<Street *,std::allocator<Street *> >
But prefixing with & doesn't give me an address:
&streets streets [11790](0x1c66a690 [...] std::vector<Street *,std::allocator<Street *> >
Also, trying to read the size doesn't work, why is that?
streets.size() CXX0075: Error: Cannot set up Function Evaluation
The program is compiled in debug mode.
The Visual Studio Debugger drives debugger watch, quick-watch, auto, and local variable views through a translation defined by schema in a file called autoexp.dat (depending on your VS version, the content therein can vary markedly). The file is located in your VS-InstallDir/Common7/Packages/Debugger folder (at least it is for VS2010 and VS2012).
Knowing this, a couple of ideas for you to try/consider:
Method One: Library Know-How
To access the actual address of the first element within the vector I ultimately just do this:
streets._Myfirst
if you know the number of elements you're going to view, you can use the array-expansion extension by:
streets._Myfirst,N
where N is the number of elements
Note: this only works as shown above with vectors. The practice is different depending on which container you are using. There are no-doubt simpler ways that are probably less dependent on the implementation of std::vector<>, but this is the simplest wasy I know how to get you up and debugging quickly.
Method Two: Scorched Earth
Under Tools/Options/Debugging/General is a list of features you can switch on and off. One of them you will find particularly useful to this question:
Show raw structure of objects in variable windows.
Turn this ON to see raw member variables of all structures and containers, including standard containers like std::vector<>. This effectively disables usage of the templates in autoexp.dat
To see the address, cast to a void *, like so: (void *)&streets.
This is Visual Studio's attempt to be helpful by showing you the pointed-to vector directly. A similar problem affects arrays of vectors.

Problem using accessors in V8

I'm writing a wrapper class around the V8 engine so that eventually I'll be able to do something like this
script->createClass("Test");
script->getClass("Test")->addFunction("funct1",testfunct1);
script->getClass("Test")->addVariable("x",setter,getter);
So far I can create classes and add functions to them and it works perfectly, however I have encountered a problem with adding variables.
My class template is stored as such
Persistent<Object> classInstance;
and I try to add an Accessor like this:
this->classInstance->SetAccessor(String::New(variableName),setter,getter);
Compiling this code gives me the error that v8::Object doesn't have a SetAccessor function (though I've seen doxygen documentation that says otherwise).
So my question is: How can I fix this? Is it possible to cast an Object to an ObjectTemplate?
SetAccessor on Object is available as of V8 2.2.12, which was released May 2010. (Before that, it was indeed only available on ObjectTemplate.) You should probably update your copy of V8.