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.


 804         char *oldval,*oldsavch;
 805         char *formal[MAXFRM]; /* formal[n] is name of nth formal */
 806         char formtxt[BUFFERSIZ]; /* space for formal names */
 807 
 808         formtxt[0] = '\0';      /* Make lint quiet */
 809 
 810         if (savch>sbf+SBSIZE-BUFFERSIZ) {
 811                 pperror("too much defining");
 812                 return(p);
 813         }
 814         oldsavch=savch; /* to reclaim space if redefinition */
 815         ++flslvl; /* prevent macro expansion during 'define' */
 816         p=skipbl(p); pin=inp;
 817         if ((toktyp+COFF)[(int)*pin]!=IDENT) {
 818                 ppwarn("illegal macro name");
 819                 while (*inp!='\n')
 820                         p=skipbl(p);
 821                 return(p);
 822         }
 823         np=slookup(pin,p,1);



 824         if ((oldval=np->value) != NULL)
 825                 savch=oldsavch; /* was previously defined */
 826         b=1; cf=pin;
 827         while (cf<p) {/* update macbit */
 828                 c= *cf++; xmac1(c,b,|=); b=(b+b)&0xFF;
 829                 if (cf!=p) {
 830                         xmac2(c,*cf,-1+(cf-pin),|=);
 831                 } else {
 832                         xmac2(c,0,-1+(cf-pin),|=);
 833                 }
 834         }
 835         params=0; outp=inp=p; p=cotoken(p); pin=inp;
 836         formal[0] = ""; /* Prepare for hack at next line... */
 837         pf = formal;    /* Make gcc/lint quiet, pf only used with params!=0 */
 838         if (*pin=='(') {/* with parameters; identify the formals */
 839                 cf=formtxt; pf=formal;
 840                 for (;;) {
 841                         p=skipbl(p); pin=inp;
 842                         if (*pin=='\n') {
 843                                 --lineno[ifno];




 804         char *oldval,*oldsavch;
 805         char *formal[MAXFRM]; /* formal[n] is name of nth formal */
 806         char formtxt[BUFFERSIZ]; /* space for formal names */
 807 
 808         formtxt[0] = '\0';      /* Make lint quiet */
 809 
 810         if (savch>sbf+SBSIZE-BUFFERSIZ) {
 811                 pperror("too much defining");
 812                 return(p);
 813         }
 814         oldsavch=savch; /* to reclaim space if redefinition */
 815         ++flslvl; /* prevent macro expansion during 'define' */
 816         p=skipbl(p); pin=inp;
 817         if ((toktyp+COFF)[(int)*pin]!=IDENT) {
 818                 ppwarn("illegal macro name");
 819                 while (*inp!='\n')
 820                         p=skipbl(p);
 821                 return(p);
 822         }
 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]);
 827         if ((oldval=np->value) != NULL)
 828                 savch=oldsavch; /* was previously defined */
 829         b=1; cf=pin;
 830         while (cf<p) {/* update macbit */
 831                 c= *cf++; xmac1(c,b,|=); b=(b+b)&0xFF;
 832                 if (cf!=p) {
 833                         xmac2(c,*cf,-1+(cf-pin),|=);
 834                 } else {
 835                         xmac2(c,0,-1+(cf-pin),|=);
 836                 }
 837         }
 838         params=0; outp=inp=p; p=cotoken(p); pin=inp;
 839         formal[0] = ""; /* Prepare for hack at next line... */
 840         pf = formal;    /* Make gcc/lint quiet, pf only used with params!=0 */
 841         if (*pin=='(') {/* with parameters; identify the formals */
 842                 cf=formtxt; pf=formal;
 843                 for (;;) {
 844                         p=skipbl(p); pin=inp;
 845                         if (*pin=='\n') {
 846                                 --lineno[ifno];