scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit a8ee619de91a3d5c8e54f7601c0bfe7f08546c4e
parent 4830eb16ae153c0ef348a2d69e21f89b3191b238
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 23 Aug 2019 08:10:28 +0100

[libmach] Add addr2line Objops method

Diffstat:
Minclude/scc/scc/mach.h | 2+-
Msrc/cmd/addr2line.c | 8++++----
Dsrc/libmach/addr2line.c | 10----------
Msrc/libmach/coff32/Makefile | 1+
Msrc/libmach/coff32/coff32.c | 1+
Msrc/libmach/coff32/coff32.h | 1+
Asrc/libmach/coff32/coff32addr2line.c | 11+++++++++++
7 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -47,6 +47,7 @@ struct objsymdef { struct objops { int (*new)(Obj *obj); int (*read)(Obj *obj, FILE *fp); + int (*addr2line)(Obj *, unsigned long long , char *, int *); int (*setidx)(long nsyms, Objsymdef *def, FILE *fp); int (*getidx)(long *nsyms, Objsymdef **def, FILE *fp); }; @@ -83,4 +84,3 @@ extern long armember(FILE *fp, char *member); extern int objaddseg(Obj *obj, void *seg); extern int objsync(Obj *obj); extern int objreloc(Obj *obj, char *sect, void *rel); -extern int addr2line(Obj *obj, unsigned long long addr, char *fname, int *line); diff --git a/src/cmd/addr2line.c b/src/cmd/addr2line.c @@ -27,7 +27,7 @@ error(char *fmt, ...) } static void -translate(Obj *obj, char *s) +addr2line(Obj *obj, char *s) { int line; unsigned long long addr; @@ -40,7 +40,7 @@ translate(Obj *obj, char *s) return; } - if (!addr2line(obj, addr, fname, &line)) { + if ((*obj->ops->addr2line)(obj, addr, fname, &line) < 0) { error("not matching line"); return; } @@ -128,10 +128,10 @@ main(int argc, char *argv[]) if (argc > 0) { for ( ; *argv; ++argv) - translate(obj, *argv); + addr2line(obj, *argv); } else { while ((ln = getline()) != NULL) - translate(obj, ln); + addr2line(obj, ln); } fflush(stdout); diff --git a/src/libmach/addr2line.c b/src/libmach/addr2line.c @@ -1,10 +0,0 @@ -#include <stdio.h> - -#include <scc/mach.h> - -int -addr2line(Obj *obj, unsigned long long addr, char *fname, int *line) -{ - /* TODO */ - return -1; -} diff --git a/src/libmach/coff32/Makefile b/src/libmach/coff32/Makefile @@ -16,6 +16,7 @@ OBJS = coff32.o \ coff32setidx.o \ coff32getidx.o \ coff32sync.o \ + coff32addr2line.o \ all: $(OBJS) diff --git a/src/libmach/coff32/coff32.c b/src/libmach/coff32/coff32.c @@ -10,4 +10,5 @@ Objops coff32 = { .read = coff32read, .getidx = coff32getidx, .setidx = coff32setidx, + .addr2line = coff32addr2line, }; diff --git a/src/libmach/coff32/coff32.h b/src/libmach/coff32/coff32.h @@ -28,6 +28,7 @@ extern int coff32new(Obj *obj); extern int coff32read(Obj *obj, FILE *fp); extern int coff32setidx(long nsymbols, Objsymdef *head, FILE *fp); extern int coff32getidx(long *nsyms, Objsymdef **def, FILE *fp); +extern int coff32addr2line(Obj *, unsigned long long , char *, int *); extern int coff32xsetidx(int order, long nsyms, Objsymdef *head, FILE *fp); extern int coff32xgetidx(int order, long *nsyms, Objsymdef **def, FILE *fp); diff --git a/src/libmach/coff32/coff32addr2line.c b/src/libmach/coff32/coff32addr2line.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +#include <scc/mach.h> + +#include "../libmach.h" + +int +coff32addr2line(Obj *obj, unsigned long long addr, char *fname, int *line) +{ + return -1; +}