scc

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

commit a0ff16f88c045a2bc99df704e5fcd029aac89173
parent 1f617a389401a5a3f7d5a6a93e0d497ade6dde0d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 28 Aug 2019 15:42:38 +0100

[libmach] Add pc2line() mock

This is only a mock version of pc2line() because the target
is not implementing it.

Diffstat:
Minclude/scc/scc/mach.h | 1+
Msrc/cmd/Makefile | 3+--
Msrc/cmd/addr2line.c | 6+++---
Msrc/libmach/Makefile | 1+
Msrc/libmach/coff32/Makefile | 2+-
Msrc/libmach/coff32/coff32.c | 2+-
Msrc/libmach/coff32/coff32.h | 2+-
Dsrc/libmach/coff32/coff32addr2line.c | 11-----------
Asrc/libmach/coff32/coff32pc2line.c | 11+++++++++++
Msrc/libmach/libmach.h | 2+-
Asrc/libmach/pc2line.c | 11+++++++++++
11 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -52,6 +52,7 @@ extern int readobj(Obj *obj, FILE *fp); extern int writeobj(Obj *obj, FILE *fp); extern int strip(Obj *obj); +extern int pc2line(Obj *obj, unsigned long long pc, char *fname, int *ln); extern Symbol *getsym(Obj *obj, long *index, Symbol *sym); extern Section *getsec(Obj *obj, long *index, Section *sec); diff --git a/src/cmd/Makefile b/src/cmd/Makefile @@ -10,8 +10,7 @@ TARGET = $(BINDIR)/nm \ $(BINDIR)/ranlib \ $(BINDIR)/objdump \ $(BINDIR)/objcopy \ - -# $(BINDIR)/addr2line \ + $(BINDIR)/addr2line \ DIRS = as scc diff --git a/src/cmd/addr2line.c b/src/cmd/addr2line.c @@ -40,7 +40,7 @@ addr2line(Obj *obj, char *s) return; } - if ((*obj->ops->addr2line)(obj, addr, fname, &line) < 0) { + if (pc2line(obj, addr, fname, &line) < 0) { error("not matching line"); return; } @@ -88,12 +88,12 @@ loadexe(char *fname) return NULL; } - if ((obj = objnew(t)) == NULL) { + if ((obj = newobj(t)) == NULL) { error("out of memory"); return NULL; } - if ((*obj->ops->read)(obj, fp) < 0) { + if (readobj(obj, fp) < 0) { error("file corrupted"); return NULL; } diff --git a/src/libmach/Makefile b/src/libmach/Makefile @@ -16,6 +16,7 @@ OBJS = mach.o \ getsym.o \ getsec.o \ strip.o \ + pc2line.o \ pack.o \ unpack.o \ setindex.o \ diff --git a/src/libmach/coff32/Makefile b/src/libmach/coff32/Makefile @@ -15,7 +15,7 @@ OBJS = coff32.o \ coff32xgetidx.o \ coff32setidx.o \ coff32getidx.o \ - coff32addr2line.o \ + coff32pc2line.o \ coff32getsym.o \ coff32getsec.o \ diff --git a/src/libmach/coff32/coff32.c b/src/libmach/coff32/coff32.c @@ -11,7 +11,7 @@ struct objops coff32 = { .read = coff32read, .getidx = coff32getidx, .setidx = coff32setidx, - .addr2line = coff32addr2line, + .pc2line = coff32pc2line, .strip = coff32strip, .del = coff32del, .write = coff32write, diff --git a/src/libmach/coff32/coff32.h b/src/libmach/coff32/coff32.h @@ -28,7 +28,7 @@ extern int coff32new(Obj *obj); extern int coff32read(Obj *obj, FILE *fp); extern int coff32setidx(long nsyms, char **names, long *offs, FILE *fp); extern int coff32getidx(long *nsyms, char ***namep, long **offsp, FILE *fp); -extern int coff32addr2line(Obj *, unsigned long long , char *, int *); +extern int coff32pc2line(Obj *, unsigned long long , char *, int *); extern int coff32strip(Obj *obj); extern void coff32del(Obj *obj); extern int coff32write(Obj *obj, FILE *fp); diff --git a/src/libmach/coff32/coff32addr2line.c b/src/libmach/coff32/coff32addr2line.c @@ -1,11 +0,0 @@ -#include <stdio.h> - -#include <scc/mach.h> - -#include "../libmach.h" - -int -coff32addr2line(Obj *obj, unsigned long long addr, char *fname, int *line) -{ - return -1; -} diff --git a/src/libmach/coff32/coff32pc2line.c b/src/libmach/coff32/coff32pc2line.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +#include <scc/mach.h> + +#include "../libmach.h" + +int +coff32pc2line(Obj *obj, unsigned long long addr, char *fname, int *line) +{ + return -1; +} diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -34,7 +34,7 @@ struct objops { int (*write)(Obj *obj, FILE *fp); int (*strip)(Obj *obj); - int (*addr2line)(Obj *, unsigned long long , char *, int *); + int (*pc2line)(Obj *, unsigned long long , char *, int *); Symbol *(*getsym)(Obj *obj, long *index, Symbol *sym); Section *(*getsec)(Obj *obj, long *index, Section *sec); diff --git a/src/libmach/pc2line.c b/src/libmach/pc2line.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +#include <scc/mach.h> + +#include "libmach.h" + +int +pc2line(Obj *obj, unsigned long long pc, char *fname, int *ln) +{ + return (*obj->ops->pc2line)(obj, pc, fname, ln); +}