In the unmanaged development world, you could observe the DWORD return value of a method by typing '@eax' into the watch window of the debugger.
Does anyone know of an equivalent shortcut in managed code?
Related point: I have learned that VS2008 SP1 supports $exception as a magic word in the watch window. Are there any other shortcuts that you know of?
-
I'm not sure if this is quite what you mean, but there are some other keywords that you can have printed out for tracepoints:
$ADDRESS address of current instruction $CALLER name of the previous function on the call stack $CALLSTACK entire call stack $FUNCTION name of the current function $PID process ID for current process $PNAME name of the current process $TID thread ID for current thread $TNAME name of the current thread
-
That list is excellent! Where did you get it?
The @eax part of my question concerns this situation:
Let's say you have this method in your code.
public int MyFunc() { return FnA() + FnB(); }
In unmanaged C++, you could put a breakpoint on the closing curly brace, type @eax in the watch window, and you would see the result of 'FnA() + FnB()'.
A workaround is to assign the return value of MyFunc() to a variable and to type the name of the variable into the watch window.
public int MyFunc() { var result = FnA() + FnB(); return result; }
While this is quite easy to do, not everyone does it. @eax was a great way to see the return value before you exited any function that returned a DWORD.
Thanks a lot for that list!
-
@EAX in managed code is a little tricky to implement since CIL has higher-order primitives for function returns (which happen semantically on the virtual execution stack).
That said, if your function is returning a value type and that type's size is less than or equal to 32-bits, then the @EAX will most likely still give you that value. (You may need to switch on mixed-mode debugging in order to see registers, I don't remember off the top of my head.) This of course falls apart for reference types, large value types, and inlined functions.
In short, I wish this was built into the debugger too!
-
The watch window tricks like @eax are called [Psuedovariables]. They are actually documented. I wrote a blog post about this and some other VS debugging items a few years ago. Format specifiers are typically highly useful.
For your specific question there is no psuedo variable for eax in managed code. There is however a register window which will actually have EAX and the other registers in it. It is questionable that this will be useful in many situations as I don't believe there is any way to cast the address to a managed type. You can however look at the layout in the memory window
0 comments:
Post a Comment