src/share/tools/hsdis/hsdis-demo.c
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
*** old/src/share/tools/hsdis/hsdis-demo.c Thu Sep 17 16:09:21 2009
--- new/src/share/tools/hsdis/hsdis-demo.c Thu Sep 17 16:09:21 2009
*** 24,41 ****
--- 24,43 ----
/* hsdis-demo.c -- dump a range of addresses as native instructions
This demonstrates the protocol required by the HotSpot PrintAssembly option.
*/
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <inttypes.h>
+
#include "hsdis.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
void greet(const char*);
! void disassemble(void*, void*);
! void disassemble(uintptr_t, uintptr_t);
void end_of_file();
const char* options = NULL;
int raw = 0;
int xml = 0;
*** 60,70 ****
--- 62,77 ----
greeted = 1;
}
if (!greeted)
greet("world");
printf("...And now for something completely different:\n");
disassemble((void*) &main, (void*) &end_of_file);
+ #if defined(__ia64) || defined(__powerpc__)
+ /* On IA64 and PPC function pointers are pointers to function descriptors */
+ disassemble(*((uintptr_t*) &main, *((uintptr_t*) &end_of_file);
+ #else
+ disassemble((uintptr_t) &main, (uintptr_t) &end_of_file);
+ #endif
printf("Cheers!\n");
}
void greet(const char* whom) {
printf("Hello, %s!\n", whom);
*** 74,84 ****
--- 81,91 ----
/* don't disassemble after this point... */
#include "dlfcn.h"
! #define DECODE_INSTRUCTIONS_NAME "decode_instructions_virtual"
#define HSDIS_NAME "hsdis"
static void* decode_instructions_pv = 0;
static const char* hsdis_path[] = {
HSDIS_NAME"-"LIBARCH LIB_EXT,
"./" HSDIS_NAME"-"LIBARCH LIB_EXT,
*** 106,117 ****
--- 113,130 ----
}
}
static const char* lookup(void* addr) {
+ #if defined(__ia64) || defined(__powerpc__)
+ /* On IA64 and PPC function pointers are pointers to function descriptors */
#define CHECK_NAME(fn) \
+ if (addr == *((void**) &fn)) return #fn;
+ #else
+ #define CHECK_NAME(fn) \
if (addr == (void*) &fn) return #fn;
+ #endif
CHECK_NAME(main);
CHECK_NAME(greet);
return NULL;
}
*** 121,130 ****
--- 134,151 ----
(!strncmp(event, tag, sizeof(tag)-1) && \
(!event[sizeof(tag)-1] || strchr(" /", event[sizeof(tag)-1])))
static const char event_cookie[] = "event_cookie"; /* demo placeholder */
+ static void* simple_handle_event(void* cookie, const char* event, void* arg) {
+ if (MATCH(event, "/insn")) {
+ // follow each complete insn by a nice newline
+ printf("\n");
+ }
+ return NULL;
+ }
+
static void* handle_event(void* cookie, const char* event, void* arg) {
#define NS_DEMO "demo:"
if (cookie != event_cookie)
printf("*** bad event cookie %p != %p\n", cookie, event_cookie);
*** 160,173 ****
--- 181,192 ----
/* basic action for <insn>: */
printf(" %p\t", arg);
} else if (MATCH(event, "/insn")) {
/* basic action for </insn>:
(none, plugin puts the newline for us
*/
+ // follow each complete insn by a nice newline
+ printf("\n");
} else if (MATCH(event, "mach")) {
printf("Decoding for CPU '%s'\n", (char*) arg);
} else if (MATCH(event, "addr")) {
/* basic action for <addr/>: */
*** 184,194 ****
--- 203,213 ----
}
#define fprintf_callback \
(decode_instructions_printf_callback_ftype)&fprintf
! void disassemble(void* from, void* to) {
! void disassemble(uintptr_t from, uintptr_t to) {
const char* err = load_decode_instructions();
if (err != NULL) {
printf("%s: %s\n", err, dlerror());
exit(1);
}
*** 195,211 ****
--- 214,230 ----
printf("Decoding from %p to %p...\n", from, to);
decode_instructions_ftype decode_instructions
= (decode_instructions_ftype) decode_instructions_pv;
void* res;
if (raw && xml) {
! res = (*decode_instructions)(from, to, NULL, stdout, NULL, stdout, options);
! res = (*decode_instructions)(from, to, (unsigned char*)from, to - from, simple_handle_event, stdout, NULL, stdout, options);
} else if (raw) {
! res = (*decode_instructions)(from, to, NULL, NULL, NULL, stdout, options);
! res = (*decode_instructions)(from, to, (unsigned char*)from, to - from, simple_handle_event, stdout, NULL, stdout, options);
} else {
! res = (*decode_instructions)(from, to, (unsigned char*)from, to - from,
handle_event, (void*) event_cookie,
fprintf_callback, stdout,
options);
}
! if (res != (void*)to)
printf("*** Result was %p!\n", res);
}
src/share/tools/hsdis/hsdis-demo.c
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File