]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
Use "objdump" to dump compiled native code.
authorRhys Weatherley <rweather@southern-storm.com.au>
Sat, 8 May 2004 10:11:47 +0000 (10:11 +0000)
committerRhys Weatherley <rweather@southern-storm.com.au>
Sat, 8 May 2004 10:11:47 +0000 (10:11 +0000)
ChangeLog
jit/jit-dump.c

index 4b7e6e47d83b7ec7614b921d43bd6390a2ec4d6a..de55c3ee922aa2723335f03412a22c9e1f543f32 100644 (file)
--- 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  <rweather@southern-storm.com.au>
 
        * dpas/dpas-function.c, dpas/dpas-internal.h, dpas/dpas-main.c,
index 85cad4c7f3834b0af4d37cba5f8b885587b2d1bf..f56ab3fb5b3675f542aaa7e628a29556d41b99b8 100644 (file)
 #include "jit-internal.h"
 #include "jit-rules.h"
 #include <jit/jit-dump.h>
+#include <config.h>
+#ifdef HAVE_STDLIB_H
+       #include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
+       #include <unistd.h>
+#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
        }