Hello all,
I was wondering if it is possible to improve the debugging information
generated by gcc when resolving C macros? Just as an example, when I
preprocessed the following C file:
extern int printf (__const char *__restrict __format, ...);
#define my_macro(i) \
do { \
*(i) = 1; \
*(i) += 2; \
} while(0)
int main(void)
{
int i = 0;
printf("i = %d\n", i);
my_macro(&i);
printf("i = %d\n", i);
return 0;
}
I got the following output:
# 1 "test.c"
# 1 ""
# 1 ""
# 1 "test.c"
extern int printf (__const char *__restrict __format, ...);
int main(void)
{
int i = 0;
printf("i = %d\n", i);
do { *(&i) = 1; *(&i) += 2; } while(0);
printf("i = %d\n", i);
return 0;
}
By adding a couple of "#" lines as follows I was able to much improve
the debugging experience:
# 1 "test.c"
# 1 ""
# 1 ""
# 1 "test.c"
extern int printf (__const char *__restrict __format, ...);
int main(void)
{
int i = 0;
printf("i = %d\n", i);
# 4 "test.c"
do {
# 5 "test.c"
*(&i) = 1;
# 6 "test.c"
*(&i) += 2;
# 7 "test.c"
} while(0);
# 14 "test.c"
printf("i = %d\n", i);
return 0;
}
I wonder whether this couldn't be done by the gcc preprocessor? Or does
standards compliance forbid this?
( [ http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html ] didn't
quite make this clear, and it isn't clear to me whether those "#" lines
are part of the standard.)
Regards,
Michael