Debugging information in C macros
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
RE: Debugging information in C macros
> From: bas...@starynkevitch.net > On Tue, 10 May 2011 17:33:57 +0200 > Michael T wrote: > > 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: [...] > I am not a standard guru, but in my naive view this counts as one > single logical line (because backslash newline is handled by > preprocessing), so expansion of that macro invocation should be one > line also. > > Besides, I believe that there are lots of actual C code which depends > upon that behavior. Code like > #define my_fatal_at(Msg,Line) do { \ > printf ("%s:%d fatal error: %s\n", __FILE__, Line, Msg); \ > abort (); \ > } while(0); [...] Sadly that sounds rather convincing. Thanks for the answer and sorry for the noise. Regards, Michael
RE: Debugging information in C macros
> From: rasel...@hotmail.com > > From: bas...@starynkevitch.net > > On Tue, 10 May 2011 17:33:57 +0200 > > Michael T wrote: > > > 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: [...] > > Besides, I believe that there are lots of actual C code which depends > > upon that behavior. Code like > > #define my_fatal_at(Msg,Line) do { \ > > printf ("%s:%d fatal error: %s\n", __FILE__, Line, Msg); \ > > abort (); \ > > } while(0); [...] > Sadly that sounds rather convincing. Thanks for the answer and sorry for the > noise. Although thinking about it, __FILE__ and __LINE__ are also handled by the preprocessor, so they need not be affected by "#" lines. I'm sure there must be a reason though why gcc isn't doing this already. Regards, Michael
Bug: GCC riscv building fails at self-tests with specific march
I encountered a bug when trying to build a RISC-V GCC cross-compiler. I believe that the most relevant configure options that I used are: --disable-multilib --with-arch=rv32ia --with-abi=ilp32 However, I can post a full list if needed. I have the GCC git tree located at the path "/home/quantum/devel/git/gcc" and am building it inside the sub-directory "build1". It seems to fail when attempting to build the self-tests. Here is an excerpt from the build output: /home/quantum/devel/git/gcc/build1/./gcc/xgcc -B/home/quantum/devel/git/gcc/build1/./gcc/ -xc -nostdinc /dev/null -S -o /dev/null -fself-test=.././../gcc/testsuite/selftests /home/quantum/devel/git/gcc/build1/./gcc/xgcc -B/home/quantum/devel/git/gcc/build1/./gcc/ -xc++ -nostdinc /dev/null -S -o /dev/null -fself-test=.././../gcc/testsuite/selftests cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension It seems to be trying to build test suites that are in conflict with my march settings. Interestingly, I didn't have this issue when trying to build the release version tagged "releases/gcc-13.2.0". However, I wanted to use some newer features that were only merged less than a month ago. I tried to build the GIT tree and encountered this error. I attempted to bisect the issue and found that it only happens when gcc/DEV-PHASE is set to: experimental I'm not very familar with GCC's build system, but this suggests to me that the tests are only conditionally built on experimental/development codebase snapshots. Michael T. Kloos
Re: Bug: GCC riscv building fails at self-tests with specific march
Sorry for the formatting break. Resending... I encountered a bug when trying to build a RISC-V GCC cross-compiler. I believe that the most relevant configure options that I used are: --disable-multilib --with-arch=rv32ia --with-abi=ilp32 However, I can post a full list if needed. I have the GCC git tree located at the path "/home/quantum/devel/git/gcc" and am building it inside the sub-directory "build1". It seems to fail when attempting to build the self-tests. Here is an excerpt from the build output: /home/quantum/devel/git/gcc/build1/./gcc/xgcc -B/home/quantum/devel/git/gcc/build1/./gcc/ -xc -nostdinc /dev/null -S -o /dev/null -fself-test=.././../gcc/testsuite/selftests /home/quantum/devel/git/gcc/build1/./gcc/xgcc -B/home/quantum/devel/git/gcc/build1/./gcc/ -xc++ -nostdinc /dev/null -S -o /dev/null -fself-test=.././../gcc/testsuite/selftests cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension cc1plus: error: '-mdiv' requires '-march' to subsume the 'M' extension It seems to be trying to build test suites that are in conflict with my march settings. Interestingly, I didn't have this issue when trying to build the release version tagged "releases/gcc-13.2.0". However, I wanted to use some newer features that were only merged less than a month ago. I tried to build the GIT tree and encountered this error. I attempted to bisect the issue and found that it only happens when "gcc/DEV-PHASE" is set to: experimental I'm not very familar with GCC's build system, but this suggests to me that the tests are only conditionally built on experimental/development codebase snapshots. Michael T. Kloos