Search code examples
cvisual-studio-2012macrosbreakpoints

Set a breakpoint in a macro in Visual Studio


Is there a way to set a breakpoint for C code in Visual Studio inside a #define? When I set the breakpoint it isn't reached, and the rest code continues to be executed. For example:

#define YY_USER_ACTION sn_yylloc.first_line = sn_yylloc.last_line =sn_yylineno; \
sn_yylloc.first_column = sn_yycolumn; \
sn_yylloc.last_column = sn_yycolumn + sn_yyleng -1; \
sn_yycolumn += sn_yyleng;

The code is a lexer generated by Flex, but that's really of no importance.


Solution

  • This #define is being expanded by the preprocessor before compilation. What you could do is try to run with the Visual Studio debugger with this code instead of the original code (read this question about getting your hands on the preprocessed code).