From 07e1a844959cd5c58f84eb5bd0e6cf58c9fdb313 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Sat, 8 May 2004 10:11:47 +0000 Subject: [PATCH] Use "objdump" to dump compiled native code. --- ChangeLog | 2 ++ jit/jit-dump.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b7e6e4..de55c3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,8 @@ into the public headers and add "jit_type_get_kind" so that front end code can classify types quickly. + * jit/jit-dump.c: use "objdump" to dump compiled native code. + 2004-05-07 Rhys Weatherley * dpas/dpas-function.c, dpas/dpas-internal.h, dpas/dpas-main.c, diff --git a/jit/jit-dump.c b/jit/jit-dump.c index 85cad4c..f56ab3f 100644 --- a/jit/jit-dump.c +++ b/jit/jit-dump.c @@ -21,6 +21,13 @@ #include "jit-internal.h" #include "jit-rules.h" #include +#include +#ifdef HAVE_STDLIB_H + #include +#endif +#ifdef HAVE_UNISTD_H + #include +#endif #if defined(JIT_BACKEND_INTERP) #include "jit-interp.h" @@ -617,7 +624,39 @@ static void dump_interp_code(FILE *stream, void **pc, void **end) } } -#endif /* JIT_BACKEND_INTERP */ +#else /* !JIT_BACKEND_INTERP */ + +/* + * Dump the native object code representation of a function. + * Can only dump to stdout or stderr at the moment. + */ +static void dump_object_code(FILE *stream, void *start, void *end) +{ + char cmdline[BUFSIZ]; + FILE *file = fopen("/tmp/libjit-dump.s", "w"); + unsigned char *pc = (unsigned char *)start; + if(!file) + { + return; + } + fflush(stream); + while(pc < (unsigned char *)end) + { + fprintf(file, ".byte %d\n", (int)(*pc)); + ++pc; + } + fclose(file); + sprintf(cmdline, "as /tmp/libjit-dump.s -o /tmp/libjit-dump.o;" + "objdump --adjust-vma=%ld -d /tmp/libjit-dump.o%s", + (long)(jit_nint)start, (stream == stderr ? " 1>&2" : "")); + system(cmdline); + unlink("/tmp/libjit-dump.s"); + unlink("/tmp/libjit-dump.o"); + putc('\n', stream); + fflush(stream); +} + +#endif /* !JIT_BACKEND_INTERP */ /*@ * @deftypefun void jit_dump_function ({FILE *} stream, jit_function_t func, {const char *} name) @@ -765,7 +804,7 @@ void jit_dump_function(FILE *stream, jit_function_t func, const char *name) (int)(interp->working_area)); dump_interp_code(stream, (void **)(interp + 1), (void **)end); #else - /* TODO: use objdump to dump native code */ + dump_object_code(stream, func->entry_point, end); #endif } -- 2.47.3