开发者

Problem debugging a macro in visual studio

I am having trouble debugging a macro in C. When I try to set a breakpoint, I get the 开发者_如何学编程message: "Breakpoint will not be hit. No executable code associated with this line..." The funny thing is I can debug everything else in the file, just not this macro. I have correctly loaded all the symbol files, cleaned and rebuilt, and turned off optimizations. Any ideas as to why debugging this macro is not working?


Not knowing enough context (it might be helpful to see the definition, invocation and where you're trying to set the breakpoint), here are a few guesses:

Are you setting the breakpoint in the macro definition or where it is called? If you set it in the definition, then that is exactly the error you would see. The definition is telling the preprocessor to do substitutions elsewhere in your code, so by the time the code reaches the compiler, the line with #define on it has been replaced with a blank line.

If you are correctly setting the breakpoint at the point it's used, are you sure that you're using the definition of the macro you think you are, and that the macro isn't conditional compiled to produce no code? This is a common method of disabling some things (e.g. debug output) and will give no executable code on the line calling it (unless there is other executable code around it). One way to check this is to put a #error line right next to the macro definition - if it is being used then the compiler will spit out an error.

Remember that macros functions are simply text substitutions, and so calling them puts all of their code on the one line of the invocation (each and every invocation).. You can't actually debug them (in the sense of stepping into a 'multiline' macro function), you can only step past them comparing the before and after state. This is one of the major reasons why complicated macro functions can be a bad idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜