如何使用 gdb 单步执行 #define 语句
我正在使用 gcc 编译器。我正在编写的代码经常涉及在单个 #define 指令中编写大量语句。例如以下内容:
#include<stdio.h>
#define DO_RR(x) do { \
for(i=0;i<x; i++) \
printf("%d", i); \
}while(0);
int main() {
int i=0;
DO_RR(5)
return 0;
}
现在我希望能够单步执行 DO_RR 中的语句。但是,当我尝试它时,控件直接从 main 中的 DO_RR 语句跳转到下一个语句,并且不单步执行。是否有办法实现在预处理器块内进行单步执行?
I am using gcc compiler. I am working on a code that frequently involves writing chunks of statements inside a single #define directive. For example the following :
#include<stdio.h>
#define DO_RR(x) do { \
for(i=0;i<x; i++) \
printf("%d", i); \
}while(0);
int main() {
int i=0;
DO_RR(5)
return 0;
}
Now I want to be able to single step through the statements in DO_RR. However when I try it, the control jumps directly from DO_RR statement in main to the next statement and does not single step. Is there anyway to achieve stepping inside the preprocessor blocks ?
你不能,#defines 由预处理器扩展并且不存在于代码中。
You cannot, #defines are expanded by the preprocessor and are not present in the code.