Discussion:
cannot set up function evaluation
(too old to reply)
e***@gmail.com
2006-05-17 13:58:28 UTC
Permalink
Hi,

I wrote a function that can be called from the watch window in the
debugger, I use this function to convert my (complicated) class to a
string:

--- cpp file ---
char *toString(MyClass *) { ... }

--- watch window ---
toString(myClassInstance)

This works well, but when I call this function with a derived class as
parameter, then I get the error
'cannot set up function evaluation'. This sometimes crashes my debugee
process and sometimes cause my function to stop working for the rest of
the debug session.

Does anybody have more info about this error message, and what I can do
to avoid it?

Thanks,
eli
Oleg Starodumov
2006-05-17 19:10:34 UTC
Permalink
Post by e***@gmail.com
I wrote a function that can be called from the watch window in the
debugger, I use this function to convert my (complicated) class to a
--- cpp file ---
char *toString(MyClass *) { ... }
--- watch window ---
toString(myClassInstance)
This works well, but when I call this function with a derived class as
parameter, then I get the error
'cannot set up function evaluation'. This sometimes crashes my debugee
process and sometimes cause my function to stop working for the rest of
the debug session.
Does anybody have more info about this error message, and what I can do
to avoid it?
It works for simple classes, so I would suspect that complexity of the class
is somehow related with the problem. What do you mean when you say that
the class is "complicated"? Probably it makes sense to try to reproduce it
with a similar test class and then try to simplify the class to see what causes
the problem.

You can also try to pass the raw address of the object of the derived class
to the function and see if it works that way.

Regards,
Oleg
[VC++ MVP http://www.debuginfo.com/]
e***@gmail.com
2006-05-18 06:56:26 UTC
Permalink
With complicated I mean: multiple inheritance. I think I know a bit
more about what is going on now:
my pointer to my base class is different from the pointer to the
derived class. I think the debugger ignores the type of the parameter
of my function and simple passes the pointer of the derived class
without casting it to the base class.
This causes the function to 'crash', apparently the debugger runs these
functions in some kind of protected environment and it sometimes has
difficulties to recover from a crash in this environment.

What I am looking for now is a way to avoid that my function is called
with a derived class as a parameter.
Also some documentation about what the debugger does exactly would be
very welcome, do you think Microsoft would be willing to provide such
information?

Anyway, thanks for your reply!
greetings,
eli
Oleg Starodumov
2006-05-18 08:03:44 UTC
Permalink
Post by e***@gmail.com
With complicated I mean: multiple inheritance.
That's what I suspected :)
Post by e***@gmail.com
my pointer to my base class is different from the pointer to the
derived class. I think the debugger ignores the type of the parameter
of my function and simple passes the pointer of the derived class
without casting it to the base class.
...
What I am looking for now is a way to avoid that my function is called
with a derived class as a parameter.
What happens if in Watch window you explicitly cast the pointer
to the type passed to the function?

toString((MyClass*)&obj)
Post by e***@gmail.com
Also some documentation about what the debugger does exactly would be
very welcome, do you think Microsoft would be willing to provide such
information?
Sorry, I don't know.

Oleg
e***@gmail.com
2006-05-18 08:39:18 UTC
Permalink
Post by Oleg Starodumov
Post by e***@gmail.com
What I am looking for now is a way to avoid that my function is called
with a derived class as a parameter.
What happens if in Watch window you explicitly cast the pointer
to the type passed to the function?
toString((MyClass*)&obj)
That works well, but it is easy to forget and if you forget it, the
debuggee might crash, so I need something more stable.

I'm now busy looking for a way to detect the type of the pointer by
looking at the raw memory (I have a pointer to the vtable), maybe I can
calculate the offset to the base class myself. If that doesn't work I
will possibly be able to detect that the pointer does not point to a
base class and simple give an error message.

Not nice, compiler dependant, but fun ;-)

greetings and thanks for your help,
eli
Ben Voigt
2006-06-13 22:50:06 UTC
Permalink
Post by e***@gmail.com
Post by Oleg Starodumov
Post by e***@gmail.com
What I am looking for now is a way to avoid that my function is called
with a derived class as a parameter.
What happens if in Watch window you explicitly cast the pointer
to the type passed to the function?
toString((MyClass*)&obj)
That works well, but it is easy to forget and if you forget it, the
debuggee might crash, so I need something more stable.
I'm now busy looking for a way to detect the type of the pointer by
looking at the raw memory (I have a pointer to the vtable), maybe I can
calculate the offset to the base class myself. If that doesn't work I
will possibly be able to detect that the pointer does not point to a
base class and simple give an error message.
Have you tried RTTI's typeid, which will grab your v-table pointer for you?
You will easily find out if the object is your base type.
dynamic_cast<MyClass*>(param) might also work wonders for you, although
that's a little more doubtful.
Post by e***@gmail.com
Not nice, compiler dependant, but fun ;-)
greetings and thanks for your help,
eli
Loading...