invoking functions while debugging with Visual Studio 2005?
Asked Answered
C

7

10

Here's something I know is probably possible but I've never managed to do
In VS2005(C++), While debugging, to be able to invoke a function from the code which I'm debugging.
This feature is sometimes essential when debugging complex data structures which can't be explored easily using just the normal capabilities of the watch window.
The watch window seem to allow writing function calls but every time I try it it gives me one error or another.

Error: symbol "func" not found
Error: argument list does not match function
Error: member function not present

Did anyone ever succeed in making this work properly? What am I missing here?

Edit: clearly, the function called should be a symbol that exists in the current scope the debugger is in.

Clements answered 7/11, 2008 at 2:18 Comment(0)
C
11

Ok, Here's what I found
CXX0040 means that "The C expression evaluator does not support implicit conversions involving constructor calls."
CXX0047 means that "Overloaded functions can be called only if there is an exact parameter match or a match that does not require the construction of an object."

So combined it means that If I want to call a function none of the arguments should have an implicit conversion and none of the arguments should need a construction.
"implicit conversion" in this context seem to include trivial things like converting 'String' to 'const String&'.
"construction" seem to include trivial copy-construction. so passing by value anything that is not a primitive type will result in an error.

So this basically leaves functions that take only primitive types or pointers.
I have just tested this theory successfully.

So if you want to be able to call a method from the watch window, add an overload which takes only pointers and primitives and in the watch window pass the arguments appropriately. To pass an object that is not a primitive pass its address.

Clements answered 7/11, 2008 at 2:45 Comment(1)
I has come here in the search how to invoke a particular function in VS for the time of debug (btw, I'm work with C#), it was hard to find, so I'll leave a comment here: How to call a function in Visual Studio debugger: open «Debug→Window→Immediate», and just write in the «Immediate» window a function to evaluate.Macur
T
0

The watch window is limited by the context wherein your current code is, e.g., when your code enters a function and you try to access another function that is hidden from the scope of your current function, it won't work.

If you invoke a function in the watch window, make sure that it is visible and accessible from the current scope.

Tonetic answered 7/11, 2008 at 2:21 Comment(2)
This is not an issue. any function I try to invoke is visible from the current code point.Clements
Do specify that fact in your question then. I should have clarified instead of answered, apparently.Tonetic
G
0

To my knowledge, you can't execute code from the Watch window while debugging unmanaged C++. This does work for C# (and probably VB.NET and managed C++, but I'm not positive on that). So likely it allows it because it works for some languages, but not others.

Glare answered 7/11, 2008 at 2:22 Comment(1)
Would it hurt then that the error message would say something like "sorry, only works for managed code?". uh.Clements
D
0

We find this works in a very hit and miss manner. Some very simple functions (incl. member functions) work, typically simple property getters. Other more complex functions don't work and give an error.

I've never been able to discern the precise rules ...

Denadenae answered 7/11, 2008 at 2:34 Comment(0)
W
0

I haven't tested this, but I always thought that was what the immediate window was for (executing code)

Cameron

Washbowl answered 7/11, 2008 at 3:23 Comment(0)
M
0

It's the "Immediate" window that you want. And you're limited to what's visible from where your current breakpoint is. Local variables, and functions on that class (or globals)

Mara answered 7/11, 2008 at 3:55 Comment(0)
I
0

In my experience, there are some shortcomings with the immediate window. You can't call your classes' member functions if the classes come from a different DLL, but get misleading error messages. If anything is in the same DLL (e.g. by statically linking in all other stuff), calling members is fairly reliable. But complex stuff may or may not work, as mentioned by others.

Introspect answered 7/11, 2008 at 8:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.