ref: 9332f34cf7bae72b9ccaa290cae5a1eec3f34f3d
parent: 200269262ccb43af46f6357140df8a232dad256d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 23 04:10:28 EDT 2019
[libmach] Add addr2line Objops method
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -47,6 +47,7 @@
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 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);
--- a/src/cmd/addr2line.c
+++ b/src/cmd/addr2line.c
@@ -27,7 +27,7 @@
}
static void
-translate(Obj *obj, char *s)
+addr2line(Obj *obj, char *s)
{
int line;
unsigned long long addr;
@@ -40,7 +40,7 @@
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 @@
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);
--- a/src/libmach/addr2line.c
+++ /dev/null
@@ -1,10 +1,0 @@
-#include <stdio.h>
-
-#include <scc/mach.h>
-
-int
-addr2line(Obj *obj, unsigned long long addr, char *fname, int *line)
-{
- /* TODO */
- return -1;
-}
--- a/src/libmach/coff32/Makefile
+++ b/src/libmach/coff32/Makefile
@@ -16,6 +16,7 @@
coff32setidx.o \
coff32getidx.o \
coff32sync.o \
+ coff32addr2line.o \
all: $(OBJS)
--- a/src/libmach/coff32/coff32.c
+++ b/src/libmach/coff32/coff32.c
@@ -10,4 +10,5 @@
.read = coff32read,
.getidx = coff32getidx,
.setidx = coff32setidx,
+ .addr2line = coff32addr2line,
};
--- a/src/libmach/coff32/coff32.h
+++ b/src/libmach/coff32/coff32.h
@@ -28,6 +28,7 @@
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);
--- /dev/null
+++ b/src/libmach/coff32/coff32addr2line.c
@@ -1,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;
+}