ref: cae3fc327c4969ad626fbbe90f00026e977671e0
parent: db7877e7b5317f8c3fef848096fbffd498f4eb69
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 7 06:48:23 EDT 2022
cc1: Allocate macro input before copying definition This change makes possible to trace a parameter expansion because if you run over the list of stacked inputs we can find an IMACRO input from any IPARAM input.
--- a/src/cmd/cc/cc1/cpp.c
+++ b/src/cmd/cc/cc1/cpp.c
@@ -211,6 +211,11 @@
char *s, *p, *arg, *bp;
int size, bufsiz;
+ if (mp->sym == symfile)
+ return sprintf(mp->buffer, "\"%s\" ", filenam);
+ if (mp->sym == symline)
+ return sprintf(mp->buffer, "%d ", lineno);
+
bp = mp->buffer;
bufsiz = mp->bufsiz;
for (s = mp->def; c = *s; ++s) {
@@ -322,6 +327,7 @@
mp->arglist = NULL;
mp->def = sym->u.s + 3;
mp->npars = 0;
+ mp->buffer = NULL;
if (sym->u.s)
mp->npars = atoi(sym->u.s);
@@ -333,7 +339,6 @@
{
int elen;
Macro *mp;
- char buffer[INPUTSIZ];
DBG("MACRO '%s' detected disexpand=%d hide=%d",
sym->name, disexpand, sym->hide);
@@ -343,28 +348,20 @@
mp = newmacro(sym);
mp->fname = filenam;
- mp->buffer = buffer;
- mp->bufsiz = INPUTSIZ-1;
- if (sym == symfile) {
- elen = sprintf(buffer, "\"%s\" ", filenam);
- goto substitute;
- }
- if (sym == symline) {
- elen = sprintf(buffer, "%d ", lineno);
- goto substitute;
- }
-
if (!parsepars(mp)) {
delmacro(mp);
return 0;
}
- elen = copymacro(mp);
-substitute:
- buffer[elen] = '\0';
- DBG("MACRO '%s' expanded to :'%s'", mp->sym->name, buffer);
addinput(IMACRO, mp, FAIL);
+ mp->buffer = input->line;
+ mp->bufsiz = INPUTSIZ-1;
+
+ elen = copymacro(mp);
+ mp->buffer[elen] = '\0';
+
+ DBG("MACRO '%s' expanded to :'%s'", mp->sym->name, mp->buffer);
return 1;
}
--- a/src/cmd/cc/cc1/lex.c
+++ b/src/cmd/cc/cc1/lex.c
@@ -85,7 +85,7 @@
fname = mp->fname;
buffer = mp->buffer;
hide(sym);
- DBG("INPUT: macro %s expanded to '%s'", sym->name, buffer);
+ DBG("INPUT: expanding macro %s", sym->name);
break;
case IPARAM:
fp = NULL;