summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-03-20 00:38:35 -0700
committerOri Bernstein <ori@eigenstate.org>2017-03-20 00:38:35 -0700
commit6c574d4fc09d60095b4d74e865a67a8b1d2b2270 (patch)
treeb5a78da1bf32fa7d780c3f71baecf5b68e7afcf7
parent5cf18de659c44f4287c103dd81298c5f6b7e0951 (diff)
downloadmc-6c574d4fc09d60095b4d74e865a67a8b1d2b2270.tar.gz
Step by line in gdb.
I guess it's a good idea.
-rw-r--r--6/asm.h56
-rw-r--r--6/gen.c12
-rw-r--r--6/gengas.c15
-rw-r--r--6/genp9.c7
-rw-r--r--6/insns.def12
-rw-r--r--6/isel.c25
-rw-r--r--6/main.c6
-rw-r--r--6/simp.c1
8 files changed, 91 insertions, 43 deletions
diff --git a/6/asm.h b/6/asm.h
index f9fa996..0c6e13e 100644
--- a/6/asm.h
+++ b/6/asm.h
@@ -131,39 +131,41 @@ struct Insn {
};
struct Func {
- char *name; /* function name */
- Type *type; /* type of function */
-
- Node **args; /* argument list */
- size_t nargs; /* number of args, including hidden ones */
- Htab *stkoff; /* Loc* -> int stkoff map */
- Htab *envoff; /* Loc* -> int envoff map */
- size_t stksz; /* stack size */
- Node *ret; /* return value */
-
- Cfg *cfg; /* flow graph */
- char isexport; /* is this exported from the asm? */
- char hasenv; /* do we have an environment? */
+ char *name; /* function name */
+ Srcloc loc; /* location of definition */
+ Type *type; /* type of function */
+
+ Node **args; /* argument list */
+ size_t nargs; /* number of args, including hidden ones */
+ Htab *stkoff; /* Loc* -> int stkoff map */
+ Htab *envoff; /* Loc* -> int envoff map */
+ size_t stksz; /* stack size */
+ Node *ret; /* return value */
+
+ Cfg *cfg; /* flow graph */
+ char isexport; /* is this exported from the asm? */
+ char hasenv; /* do we have an environment? */
};
struct Asmbb {
- int id; /* unique identifier */
- char **lbls; /* list of BB labels */
- size_t nlbls; /* number of labels */
- Insn **il; /* instructions */
- size_t ni; /* number of instructions */
-
- Bitset *pred; /* set of predecessor BB ids */
- Bitset *succ; /* set of successor BB ids */
- Bitset *use; /* registers used by this BB */
- Bitset *def; /* registers defined by this BB */
- Bitset *livein; /* variables live on entrance to BB */
- Bitset *liveout; /* variables live on exit from BB */
+ int id; /* unique identifier */
+ char **lbls; /* list of BB labels */
+ size_t nlbls; /* number of labels */
+ Insn **il; /* instructions */
+ size_t ni; /* number of instructions */
+
+ Bitset *pred; /* set of predecessor BB ids */
+ Bitset *succ; /* set of successor BB ids */
+ Bitset *use; /* registers used by this BB */
+ Bitset *def; /* registers defined by this BB */
+ Bitset *livein; /* variables live on entrance to BB */
+ Bitset *liveout; /* variables live on exit from BB */
};
/* instruction selection state */
struct Isel {
char *name;
+ char *cwd;
Cfg *cfg; /* cfg built with nodes */
@@ -255,8 +257,8 @@ void fillglobls(Stab *st, Htab *globls);
void simpglobl(Node *dcl, Htab *globls, Func ***fn, size_t *nfn, Node ***blob, size_t *nblob);
void selfunc(Isel *is, Func *fn, Htab *globls, Htab *strtab);
void gen(Node *file, char *out);
-void gengas(Node *file, char *out);
-void genp9(Node *file, char *out);
+void gengas(Node *file, FILE *fd);
+void genp9(Node *file, FILE *fd);
/* blob stuff */
Blob *mkblobpad(size_t sz);
diff --git a/6/gen.c b/6/gen.c
index 538bf50..2699b62 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -176,12 +176,20 @@ char *tydescid(char *buf, size_t bufsz, Type *ty)
void gen(Node *file, char *out)
{
+ FILE *fd;
+
+ fd = fopen(out, "w");
+ if (!fd)
+ die("Couldn't open fd %s", out);
+
switch (asmsyntax) {
case Plan9:
- genp9(file, out); break;
+ genp9(file, fd);
+ break;
case Gnugaself:
case Gnugasmacho:
- gengas(file, out); break;
+ gengas(file, fd);
+ break;
default:
die("unknown target"); break;
}
diff --git a/6/gengas.c b/6/gengas.c
index 3be3224..82e0bd2 100644
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -322,8 +322,10 @@ static void writeblob(FILE *fd, Blob *b)
static void genfunc(FILE *fd, Func *fn, Htab *globls, Htab *strtab)
{
Isel is = {0,};
+ char cwd[1024];
resetregs();
+ getcwd(cwd, sizeof cwd);
is.reglocs = mkht(varhash, vareq);
is.name = fn->name;
is.stkoff = fn->stkoff;
@@ -331,6 +333,7 @@ static void genfunc(FILE *fd, Func *fn, Htab *globls, Htab *strtab)
is.globls = globls;
is.ret = fn->ret;
is.cfg = fn->cfg;
+ is.cwd = strdup(cwd);
if (fn->hasenv)
is.envp = locreg(ModeQ);
@@ -397,14 +400,14 @@ void genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
}
}
-void gengas(Node *file, char *out)
+void gengas(Node *file, FILE *fd)
{
Htab *globls, *strtab;
Node *n, **blob;
Func **fn;
+ char dir[1024], *path;
size_t nfn, nblob;
size_t i;
- FILE *fd;
/* ensure that all physical registers have a loc created before any
* other locs, so that locmap[Physreg] maps to the Loc for the physreg
@@ -440,9 +443,11 @@ void gengas(Node *file, char *out)
}
popstab();
- fd = fopen(out, "w");
- if (!fd)
- die("Couldn't open fd %s", out);
+ getcwd(dir, sizeof dir);
+ for (i = 0; i < file->file.nfiles; i++) {
+ path = file->file.files[i];
+ fprintf(fd, ".file %zd \"%s/%s\"\n", i + 1, dir, path);
+ }
strtab = mkht(strlithash, strliteq);
fprintf(fd, ".data\n");
diff --git a/6/genp9.c b/6/genp9.c
index 10092f5..4db30eb 100644
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -500,14 +500,13 @@ static void genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
writeblob(fd, b, 0, lbl);
}
-void genp9(Node *file, char *out)
+void genp9(Node *file, FILE *fd)
{
Htab *globls, *strtab;
Node *n, **blob;
Func **fn;
size_t nfn, nblob;
size_t i;
- FILE *fd;
/* ensure that all physical registers have a loc created before any
* other locs, so that locmap[Physreg] maps to the Loc for the physreg
@@ -543,10 +542,6 @@ void genp9(Node *file, char *out)
}
popstab();
- fd = fopen(out, "w");
- if (!fd)
- die("Couldn't open fd %s", out);
-
strtab = mkht(strlithash, strliteq);
for (i = 0; i < nblob; i++)
genblob(fd, blob[i], globls, strtab);
diff --git a/6/insns.def b/6/insns.def
index 27b41ed..105aa10 100644
--- a/6/insns.def
+++ b/6/insns.def
@@ -375,6 +375,18 @@ Insn(Ilbl,
Use(None),
Def(None))
+Insn(Ifile,
+ "\t.file %v \"%v\"\n",
+ "\t//file: %V \"%V\"\n",
+ Use(None),
+ Def(None))
+
+Insn(Iloc,
+ "\t.loc %v\n",
+ "",
+ Use(None),
+ Def(None))
+
Insn(Icomment,
"\t#%v\n",
"\t//%V:\n",
diff --git a/6/isel.c b/6/isel.c
index cd1be01..a250886 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -1009,17 +1009,30 @@ static Asmbb *mkasmbb(Bb *bb)
void selfunc(Isel *is, Func *fn, Htab *globls, Htab *strtab)
{
+ int fileid, lastline;
Node *n;
Bb *bb;
size_t i, j;
char buf[128];
+ char *path;
for (i = 0; i < fn->cfg->nbb; i++)
lappend(&is->bb, &is->nbb, mkasmbb(fn->cfg->bb[i]));
is->curbb = is->bb[0];
+
+ fileid = fn->loc.file;
+ if (fileid >= 0 && fn->loc.line > 0) {
+ path = file->file.files[fileid];
+ bprintf(buf, sizeof buf, "%s/%s:%d", is->cwd, path, fn->loc.line);
+ g(is, Icomment, locstrlbl(buf), NULL);
+ bprintf(buf, sizeof buf, "%zd %d", fileid + 1, fn->loc.line);
+ g(is, Iloc, locstrlbl(buf), NULL);
+ }
+
prologue(is, fn, fn->stksz);
+ lastline = -1;
for (j = 0; j < fn->cfg->nbb - 1; j++) {
is->curbb = is->bb[j];
if (!is->bb[j])
@@ -1028,9 +1041,15 @@ void selfunc(Isel *is, Func *fn, Htab *globls, Htab *strtab)
for (i = 0; i < bb->nnl; i++) {
/* put in a comment that says where this line comes from */
n = bb->nl[i];
- bprintf(buf, sizeof buf, "bb = %ld, bbidx = %ld, %s:%d",
- j, i, file->file.files[n->loc.file], n->loc.line);
- g(is, Icomment, locstrlbl(buf), NULL);
+ fileid = n->loc.file;
+ if (n->loc.file >= 0 && n->loc.line != -1 && n->loc.line != lastline) {
+ lastline = n->loc.line;
+ path = file->file.files[fileid];
+ bprintf(buf, sizeof buf, "%s/%s:%d", is->cwd, path, n->loc.line);
+ g(is, Icomment, locstrlbl(buf), NULL);
+ bprintf(buf, sizeof buf, "%zd %d", fileid + 1, n->loc.line);
+ g(is, Iloc, locstrlbl(buf), NULL);
+ }
isel(is, fn->cfg->bb[j]->nl[i]);
}
}
diff --git a/6/main.c b/6/main.c
index 44d569e..40ceef6 100644
--- a/6/main.c
+++ b/6/main.c
@@ -98,6 +98,12 @@ static void assemble(char *asmsrc, char *path)
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
die("Couldn't run assembler");
}
+ /*
+ We don't want to keep the asm source around, but it's useful
+ for deubgging without mapping to line numbers.
+ */
+ if (asmsyntax != Plan9)
+ unlink(asmsrc);
}
static char *dirname(char *path)
diff --git a/6/simp.c b/6/simp.c
index 6f5a132..968d5f2 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -1387,6 +1387,7 @@ static Func *simpfn(Simp *s, char *name, Node *dcl)
fn = zalloc(sizeof(Func));
fn->name = strdup(name);
+ fn->loc = dcl->loc;
fn->type = dcl->decl.type;
fn->isexport = isexport(dcl);
fn->stksz = align(s->stksz, 8);