aboutsummaryrefslogtreecommitdiff
path: root/emit.c
diff options
context:
space:
mode:
authorThomas Bracht Laumann Jespersen <[email protected]>2023-01-26 12:09:44 +0100
committerQuentin Carbonneaux <[email protected]>2023-06-06 18:44:51 +0200
commit0d929287d77ccc3fb52ca8bd072678b5ae2c81c8 (patch)
tree72cf91ec66052797059734c9d089a49a69b47122 /emit.c
parente493a7f23352f51acc0a1e12284ab19d7894488a (diff)
implement line number info tracking
Support "file" and "loc" directives. "file" takes a string (a file name) assigns it a number, sets the current file to that number and records the string for later. "loc" takes a single number and outputs location information with a reference to the current file.
Diffstat (limited to 'emit.c')
-rw-r--r--emit.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/emit.c b/emit.c
index 017c461..b880d67 100644
--- a/emit.c
+++ b/emit.c
@@ -207,3 +207,35 @@ macho_emitfin(FILE *f)
emitfin(f, sec);
}
+
+static uint32_t *file;
+static uint nfile;
+static uint curfile;
+
+void
+emitdbgfile(char *fn, FILE *f)
+{
+ uint32_t id;
+ uint n;
+
+ id = intern(fn);
+ for (n=0; n<nfile; n++)
+ if (file[n] == id) {
+ /* gas requires positive
+ * file numbers */
+ curfile = n + 1;
+ return;
+ }
+ if (!file)
+ file = vnew(0, sizeof *file, PHeap);
+ vgrow(&file, ++nfile);
+ file[nfile-1] = id;
+ curfile = nfile;
+ fprintf(f, ".file %u %s\n", curfile, fn);
+}
+
+void
+emitdbgloc(uint loc, FILE *f)
+{
+ fprintf(f, "\t.loc %u %u\n", curfile, loc);
+}