C: const initializer and debugging symbols -


in code reviews ask option (1) below used results in symbol being created (for debugging) whereas (2) , (3) not appear @ least gcc , icc. (1) not true const , cannot used on compilers array size. there better option includes debug symbols , const c?

symbols:

gcc f.c -ggdb3 -g ; nm  -a a.out | grep _sym 0000000100000f3c s _syma 0000000100000f3c - 04 0000 stsym _syma 

code:

static const int syma = 1;  // 1  #define symb 2 // 2  enum { symc = 3 }; // 3 

gdb output:

(gdb) p syma $1 = 1  (gdb) p symb no symbol "symb" in current context.  (gdb) p symc no symbol "symc" in current context. 

and completeness, source:

#include <stdio.h>  static const int syma = 1;  #define symb 2  enum { symc = 3 };  int main (int   argc, char *argv[]) {     printf("syma %d symb %d symc %d\n", syma, symb, symc);     return (0); } 

the -ggdb3 option should giving macro debugging information. different kind of debugging information (it has different - tells debugger how expand macro, possibly including arguments , # , ## operators) can't see nm.

if goal have shows in nm, guess can't use macro. that's silly goal; should want have works in debugger, right? try print symc in gdb , see if works.

since macros can redefined, gdb requires program stopped @ location macro existed can find correct definition. in program:

#include <stdio.h> int main(void) {   #define x 1   printf("%d\n", x);   #undef x   printf("---\n");   #define x 2   printf("%d\n", x); } 

if break on first printf , print x you'll 1; next second printf , gdb tell there no x; next again , show 2.

also gdb command info macro foo can useful, if foo macro takes arguments , want see definition rather expand specific set of arguments. , if macro expands that's not expression, gdb can't print info macro thing can it.

for better inspection of raw debugging information, try objdump -w instead of nm.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -