--- old/src/share/tools/hsdis/hsdis.c Wed Aug 26 18:20:03 2009 +++ new/src/share/tools/hsdis/hsdis.c Wed Aug 26 18:20:03 2009 @@ -28,12 +28,12 @@ */ #include "hsdis.h" - -#include #include #include #include #include +#include +#include #ifndef bool #define bool int @@ -47,6 +47,7 @@ /* disassemble_info.application_data object */ struct hsdis_app_data { + uintptr_t start_va, end_va; /* virtual address of data */ /* the arguments to decode_instructions */ uintptr_t start; uintptr_t end; event_callback_t event_callback; void* event_stream; @@ -89,14 +90,17 @@ #ifdef DLL_ENTRY DLL_ENTRY #endif -decode_instructions(void* start_pv, void* end_pv, - event_callback_t event_callback_arg, void* event_stream_arg, - printf_callback_t printf_callback_arg, void* printf_stream_arg, - const char* options) { +decode_instructions_virtual(void* start_va, + void* start_pv, void* end_pv, + event_callback_t event_callback_arg, void* event_stream_arg, + printf_callback_t printf_callback_arg, void* printf_stream_arg, + const char* options) { struct hsdis_app_data app_data; memset(&app_data, 0, sizeof(app_data)); app_data.start = (uintptr_t) start_pv; app_data.end = (uintptr_t) end_pv; + app_data.start_va = (uintptr_t) start_va; + app_data.end_va = app_data.start_va + app_data.end - app_data.start; app_data.event_callback = event_callback_arg; app_data.event_stream = event_stream_arg; app_data.printf_callback = printf_callback_arg; @@ -109,8 +113,8 @@ /* now reload everything from app_data: */ DECL_EVENT_CALLBACK(&app_data); DECL_PRINTF_CALLBACK(&app_data); - uintptr_t start = app_data.start; - uintptr_t end = app_data.end; + uintptr_t start = app_data.start_va; + uintptr_t end = app_data.end_va; uintptr_t p = start; (*event_callback)(event_stream, "insns", (void*)start); @@ -149,6 +153,20 @@ } } +void* +#ifdef DLL_ENTRY + DLL_ENTRY +#endif +decode_instructions(void* start_pv, void* end_pv, + event_callback_t event_callback_arg, void* event_stream_arg, + printf_callback_t printf_callback_arg, void* printf_stream_arg, + const char* options) { + return decode_instructions_virtual(start_pv, start_pv, end_pv, + event_callback_arg, event_stream_arg, + printf_callback_arg, printf_stream_arg, + options); +} + /* take the address of the function, for luck, and also test the typedef: */ const decode_instructions_ftype decode_instructions_address = &decode_instructions; @@ -189,8 +207,9 @@ bfd_byte* myaddr, unsigned int length, struct disassemble_info* dinfo) { - uintptr_t memaddr_p = (uintptr_t) memaddr; DECL_APP_DATA(dinfo); + // convert the virtual address membar into an address within memory buffer + uintptr_t memaddr_p = ((uintptr_t) memaddr) - app_data->start_va + app_data->start; if (memaddr_p + length > app_data->end) { /* read is out of bounds */ return EIO;