Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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....

like image 606
PaeneInsula Avatar asked Nov 02 '22 14:11

PaeneInsula


2 Answers

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.

like image 195
Étienne Avatar answered Nov 08 '22 09:11

Étienne


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 */
}
like image 38
user694733 Avatar answered Nov 08 '22 08:11

user694733