views:

245

answers:

4

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?

+4  A: 

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
John Mulder
A: 
AlfredBr
+1  A: 

@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!

Frank Krueger
+2  A: 

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

Steve Steiner