PaeneInsula
PaeneInsula

Reputation: 2100

Using #define in VS debugger: any way to hover and see values?

I am writing a C app using VS2010. I have the following #define:

#define wRow   Wksp[Session.wkspIndex]->Row

"Row" is an array of structures. So without the defines, it looks like this:

Wksp[Session.wkspIndex]->Row[1].value

Without the define, I can hover over "value" and see its value. But when I use the define, like this:

wRow[1].value

then hovering does nothing at all because (I assume) the debugger is too lazy to do the expansion that I defined.

Is there any way to tell the debugger to expand the #define so I can see its value? The same problem appears in the Watch window: I cannot enter wRow... but must use Wksp[Session.wkspIndex]->Row....

Upvotes: 6

Views: 3316

Answers (4)

OttoVonBrak
OttoVonBrak

Reputation: 149

On Linux simply use GDB and his expand macros capabilities

On windows I use https://www.jetbrains.com/resharper-cpp/ integrated into Visual Studio

Configuration Properties ->C/C++ ->Preprocessor->>YES also works but it is overkilling.

Upvotes: 0

Étienne
Étienne

Reputation: 5004

So basically you are asking how to get the value of this define: hovering in debug mode without define

the same way you would get the value of this variable: hovering in debug mode with define

In Visual Studio 2010, you can not get the value of a macro at debug time the same way you would get the value of a variable. Hovering over a variable actually has the same effect as entering the variable in the watch window, and this watch window is limited in what information it can access because of the format of Visual Studio debug symbols. If you enter the macro vRow in the watch window, you will get:

Error: symbol "vRow" not found

which is why nothing is shown when you hover over vRow.

To debug macro values with Visual Studio, you can set Preprocess to a file to yes in Configuration Properties ->C/C++ ->Preprocessor. Then the next time you compile your program Visual Studio will generate a .i file, which is the output of the preprocessor. By opening this .i file, you can see what is the actual expanded value of your macro, and enter this value in the watch window while you are debugging.

Upvotes: 2

TwoCode
TwoCode

Reputation: 127

I suggest using a compiler option to ease your debug...

#ifdef _DEBUG

<TYPE> *wRow = Wksp[Session.wkspIndex]->Row;

#else

#define wRow Wksp[Session.wkspIndex]->Row

#endif

Upvotes: 0

user694733
user694733

Reputation: 16047

I would really recommend using temporary pointer instead. They work a lot better with debuggers, and also respect the scope.

Something like:

void myFunc(void) {
    RowType * wRow = Wksp[Session.wkspIndex]->Row;
    wRow[1].value = 0; /* or whatever */
}

Upvotes: 1

Related Questions