9

I have a complex class, (MyClass), that has a function called ToString(), the function returns a string representation of the string.

I would like the visual studio visualiser to use that function to display the variable

This is my visualizer,

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="MyClass">
    <DisplayString>...</DisplayString> 
  </Type>
</AutoVisualizer>

If I use

...
  <DisplayString>{ToString}</DisplayString> 
...

The address of the function is returned, is it possible to display the result of the function?

If not, what would be the best way of displaying a string representation of the class?

liorda
  • 1,552
  • 2
  • 15
  • 38
FFMG
  • 1,208
  • 1
  • 10
  • 24

1 Answers1

5

Methods cannot be called.

From MSDN Forums:

Calling a function from the debugger is playing with fire. You are likely to deadlock on cross thread dependencies (even if you don't have any explicit cross thread dependencies, there are shared locks for things like memory allocation). This is why the C++ debugger has no support for implicit funceval

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • Guess it makes sense... but not ideal. – FFMG Dec 06 '15 at 04:44
  • 7
    Given that methods are supported in the watch window, and are supported by the default visualizer in other languages, I suspect that comment is more of an excuse than anything else. If someone could write a visualizer plugin for this that'd be grand. – c z Aug 31 '16 at 16:12
  • Why is accessing non-atomic data members within a class not the same fire? It could have cross-thread dependancies. I'm pretty bias'd here because I just want the functionality regardless though ;) – David Ledger Jul 10 '20 at 11:29
  • From my experimentation it seems VS2022 at least supports function calls in DisplayString, however as far as I can tell you always have to force evaluation interactively. Don't know if this amounts to a reversal of the MS position from the above quote or not. – Kristoffer Sjöö Nov 25 '22 at 10:10