ref: 547f3e403620e0b1686bb5dce005f4169dbc38e1
parent: 3cc0508834a26b517381707f4a448ecb4a3e43bd
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Aug 28 11:42:38 EDT 2019
[libmach] Add pc2line() mock This is only a mock version of pc2line() because the target is not implementing it.
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -52,6 +52,7 @@
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);
--- a/src/cmd/Makefile
+++ b/src/cmd/Makefile
@@ -10,8 +10,7 @@
$(BINDIR)/ranlib \
$(BINDIR)/objdump \
$(BINDIR)/objcopy \
-
-# $(BINDIR)/addr2line \
+ $(BINDIR)/addr2line \
DIRS = as scc
--- a/src/cmd/addr2line.c
+++ b/src/cmd/addr2line.c
@@ -40,7 +40,7 @@
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 @@
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;
}
--- a/src/libmach/Makefile
+++ b/src/libmach/Makefile
@@ -16,6 +16,7 @@
getsym.o \
getsec.o \
strip.o \
+ pc2line.o \
pack.o \
unpack.o \
setindex.o \
--- a/src/libmach/coff32/Makefile
+++ b/src/libmach/coff32/Makefile
@@ -15,7 +15,7 @@
coff32xgetidx.o \
coff32setidx.o \
coff32getidx.o \
- coff32addr2line.o \
+ coff32pc2line.o \
coff32getsym.o \
coff32getsec.o \
--- a/src/libmach/coff32/coff32.c
+++ b/src/libmach/coff32/coff32.c
@@ -11,7 +11,7 @@
.read = coff32read,
.getidx = coff32getidx,
.setidx = coff32setidx,
- .addr2line = coff32addr2line,
+ .pc2line = coff32pc2line,
.strip = coff32strip,
.del = coff32del,
.write = coff32write,
--- a/src/libmach/coff32/coff32.h
+++ b/src/libmach/coff32/coff32.h
@@ -28,7 +28,7 @@
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);
--- a/src/libmach/coff32/coff32addr2line.c
+++ /dev/null
@@ -1,11 +1,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;
-}
--- /dev/null
+++ b/src/libmach/coff32/coff32pc2line.c
@@ -1,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;
+}
--- a/src/libmach/libmach.h
+++ b/src/libmach/libmach.h
@@ -34,7 +34,7 @@
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);
--- /dev/null
+++ b/src/libmach/pc2line.c
@@ -1,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);
+}