Print this page
cpp: make it easier to find macro sources
This is a dubiously useful hack, but invaluable when debugging the
preprocessor.
If CPP_DEBUG_DEFINITIONS is in the environment, output to stderr at
every macro definition its name, and the defining file and line number,
such that the operative definition of common macros (such as __P) can be
determined.

Split Close
Expand all
Collapse all
          --- old/cpp/cpp.c
          +++ new/cpp/cpp.c
↓ open down ↓ 813 lines elided ↑ open up ↑
 814  814          oldsavch=savch; /* to reclaim space if redefinition */
 815  815          ++flslvl; /* prevent macro expansion during 'define' */
 816  816          p=skipbl(p); pin=inp;
 817  817          if ((toktyp+COFF)[(int)*pin]!=IDENT) {
 818  818                  ppwarn("illegal macro name");
 819  819                  while (*inp!='\n')
 820  820                          p=skipbl(p);
 821  821                  return(p);
 822  822          }
 823  823          np=slookup(pin,p,1);
      824 +        if (getenv("CPP_DEBUG_DEFINITIONS") != NULL)
      825 +                fprintf(stderr, "*** defining %s at %s:%d\n",
      826 +                    np->name, fnames[ifno], lineno[ifno]);
 824  827          if ((oldval=np->value) != NULL)
 825  828                  savch=oldsavch; /* was previously defined */
 826  829          b=1; cf=pin;
 827  830          while (cf<p) {/* update macbit */
 828  831                  c= *cf++; xmac1(c,b,|=); b=(b+b)&0xFF;
 829  832                  if (cf!=p) {
 830  833                          xmac2(c,*cf,-1+(cf-pin),|=);
 831  834                  } else {
 832  835                          xmac2(c,0,-1+(cf-pin),|=);
 833  836                  }
↓ open down ↓ 720 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX