Home > Software design >  Visual Studio Debugger, interpreting memory without bound or as different types?
Visual Studio Debugger, interpreting memory without bound or as different types?

Time:09-29

I'm hoping to improve my debugging workflow by learning how to inspect values faster and with more clarity, but I'm having a big issue.

Visual Studio's C debugger makes some assumptions about my memory that aren't always true:

  • The "Type" of the value may not be how I want to see it's memory printed out

  • I may want to look at a cstring without 0 terminating the IDE's print out

  • There might be memory in front of the structure I want to look at

For instance, I might want to look at float value as 0x3f800000 instead of 1.0f, as seeing 0x0000803f instead of 4.60060298822e-41 makes it much easier to see there's an endian encoding issue naturally.

Or when tokenizing, I'll want to look at as many characters as I can scroll through, without NULL ending the print out, and possibly even look in front of this address.

It is possible to use array, 23 to print out 23 characters in array, but this is the only QoL feature I was able to find, and you have to make a bookmark for the variable, so it ends up being very clunky.

Are there any settings or extensions or features I missed, that could improve my ability to see memory in ways Visual Studio might not be able to predict for me?

CodePudding user response:

There are many questions here, sorry if I overlooked some.

For the type, Visual Studio's Watch window can cast. For example, if you have

float f = 1.23;

you can view it as float by just listing its name, or you can cast:

*(int*)&f   0x3f9d70a4  int

For the strings (and looking for memory around your variables) I suggest to use Memory view (Debug -> Windows -> Memory), you get four of those to look at different locations simultaneously. Or at the same location with different formatting. You can put an address of your variable there and some math (- some value). You can view as 1-, 2-, 4- or 8-byte values, Hex or Decimal, ANSI or Unicode, etc. Oh, and yes - you can scroll, pretty far.

For more complex types, you can use natvis

  • Related