hotspot/src/share/tools/hsdis/hsdis-demo.c
changeset 14384 801df8025142
parent 13873 7b72e3873785
child 35075 ca79cbf3f106
equal deleted inserted replaced
14382:5e86124b835d 14384:801df8025142
    83 
    83 
    84 /* don't disassemble after this point... */
    84 /* don't disassemble after this point... */
    85 
    85 
    86 #include "dlfcn.h"
    86 #include "dlfcn.h"
    87 
    87 
    88 #define DECODE_INSTRUCTIONS_NAME "decode_instructions_virtual"
    88 #define DECODE_INSTRUCTIONS_VIRTUAL_NAME "decode_instructions_virtual"
       
    89 #define DECODE_INSTRUCTIONS_NAME "decode_instructions"
    89 #define HSDIS_NAME               "hsdis"
    90 #define HSDIS_NAME               "hsdis"
    90 static void* decode_instructions_pv = 0;
    91 static void* decode_instructions_pv = 0;
       
    92 static void* decode_instructions_sv = 0;
    91 static const char* hsdis_path[] = {
    93 static const char* hsdis_path[] = {
    92   HSDIS_NAME"-"LIBARCH LIB_EXT,
    94   HSDIS_NAME"-"LIBARCH LIB_EXT,
    93   "./" HSDIS_NAME"-"LIBARCH LIB_EXT,
    95   "./" HSDIS_NAME"-"LIBARCH LIB_EXT,
    94 #ifdef TARGET_DIR
    96 #ifdef TARGET_DIR
    95   TARGET_DIR"/"HSDIS_NAME"-"LIBARCH LIB_EXT,
    97   TARGET_DIR"/"HSDIS_NAME"-"LIBARCH LIB_EXT,
    99 
   101 
   100 static const char* load_decode_instructions() {
   102 static const char* load_decode_instructions() {
   101   void* dllib = NULL;
   103   void* dllib = NULL;
   102   const char* *next_in_path = hsdis_path;
   104   const char* *next_in_path = hsdis_path;
   103   while (1) {
   105   while (1) {
   104     decode_instructions_pv = dlsym(dllib, DECODE_INSTRUCTIONS_NAME);
   106     decode_instructions_pv = dlsym(dllib, DECODE_INSTRUCTIONS_VIRTUAL_NAME);
   105     if (decode_instructions_pv != NULL)
   107     decode_instructions_sv = dlsym(dllib, DECODE_INSTRUCTIONS_NAME);
       
   108     if (decode_instructions_pv != NULL || decode_instructions_sv != NULL)
   106       return NULL;
   109       return NULL;
   107     if (dllib != NULL)
   110     if (dllib != NULL)
   108       return "plugin does not defined "DECODE_INSTRUCTIONS_NAME;
   111       return "plugin does not defined "DECODE_INSTRUCTIONS_VIRTUAL_NAME" and "DECODE_INSTRUCTIONS_NAME;
   109     for (dllib = NULL; dllib == NULL; ) {
   112     for (dllib = NULL; dllib == NULL; ) {
   110       const char* next_lib = (*next_in_path++);
   113       const char* next_lib = (*next_in_path++);
   111       if (next_lib == NULL)
   114       if (next_lib == NULL)
   112         return "cannot find plugin "HSDIS_NAME LIB_EXT;
   115         return "cannot find plugin "HSDIS_NAME LIB_EXT;
   113       dllib = dlopen(next_lib, RTLD_LAZY);
   116       dllib = dlopen(next_lib, RTLD_LAZY);
   211   const char* err = load_decode_instructions();
   214   const char* err = load_decode_instructions();
   212   if (err != NULL) {
   215   if (err != NULL) {
   213     printf("%s: %s\n", err, dlerror());
   216     printf("%s: %s\n", err, dlerror());
   214     exit(1);
   217     exit(1);
   215   }
   218   }
   216   printf("Decoding from %p to %p...\n", from, to);
   219   decode_func_vtype decode_instructions_v
   217   decode_instructions_ftype decode_instructions
   220     = (decode_func_vtype) decode_instructions_pv;
   218     = (decode_instructions_ftype) decode_instructions_pv;
   221   decode_func_stype decode_instructions_s
       
   222     = (decode_func_stype) decode_instructions_sv;
   219   void* res;
   223   void* res;
   220   if (raw && xml) {
   224   if (decode_instructions_pv != NULL) {
   221     res = (*decode_instructions)(from, to, (unsigned char*)from, to - from, simple_handle_event, stdout, NULL, stdout, options);
   225     printf("\nDecoding from %p to %p...with %s\n", from, to, DECODE_INSTRUCTIONS_VIRTUAL_NAME);
   222   } else if (raw) {
   226     if (raw) {
   223     res = (*decode_instructions)(from, to, (unsigned char*)from, to - from, simple_handle_event, stdout, NULL, stdout, options);
   227       res = (*decode_instructions_v)(from, to,
   224   } else {
   228                                      (unsigned char*)from, to - from,
   225     res = (*decode_instructions)(from, to, (unsigned char*)from, to - from,
   229                                      simple_handle_event, stdout,
   226                                  handle_event, (void*) event_cookie,
   230                                      NULL, stdout,
   227                                  fprintf_callback, stdout,
   231                                      options, 0);
   228                                  options);
   232     } else {
   229   }
   233       res = (*decode_instructions_v)(from, to,
   230   if (res != (void*)to)
   234                                     (unsigned char*)from, to - from,
   231     printf("*** Result was %p!\n", res);
   235                                      handle_event, (void*) event_cookie,
   232 }
   236                                      fprintf_callback, stdout,
       
   237                                      options, 0);
       
   238     }
       
   239     if (res != (void*)to)
       
   240       printf("*** Result was %p!\n", res);
       
   241   }
       
   242   void* sres;
       
   243   if (decode_instructions_sv != NULL) {
       
   244     printf("\nDecoding from %p to %p...with old decode_instructions\n", from, to, DECODE_INSTRUCTIONS_NAME);
       
   245     if (raw) {
       
   246       sres = (*decode_instructions_s)(from, to,
       
   247                                       simple_handle_event, stdout,
       
   248                                       NULL, stdout,
       
   249                                       options);
       
   250     } else {
       
   251       sres = (*decode_instructions_s)(from, to,
       
   252                                       handle_event, (void*) event_cookie,
       
   253                                       fprintf_callback, stdout,
       
   254                                       options);
       
   255     }
       
   256     if (sres != (void *)to)
       
   257       printf("*** Result of decode_instructions %p!\n", sres);
       
   258   }
       
   259 }