hotspot/src/os/solaris/vm/os_solaris.cpp
changeset 26557 e399effe36f9
parent 25719 ef6312344da2
child 26698 2a7f85720535
child 26685 aa239a0dfbea
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp	Tue Sep 02 21:27:08 2014 -0400
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp	Wed Sep 03 14:43:49 2014 +0200
@@ -1722,41 +1722,54 @@
   return false;
 }
 
-// Prints the names and full paths of all opened dynamic libraries
-// for current process
-void os::print_dll_info(outputStream * st) {
+int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
   Dl_info dli;
-  void *handle;
+  // Sanity check?
+  if (dladdr(CAST_FROM_FN_PTR(void *, os::get_loaded_modules_info), &dli) == 0 ||
+      dli.dli_fname == NULL) {
+    return 1;
+  }
+
+  void * handle = dlopen(dli.dli_fname, RTLD_LAZY);
+  if (handle == NULL) {
+    return 1;
+  }
+
   Link_map *map;
-  Link_map *p;
-
-  st->print_cr("Dynamic libraries:"); st->flush();
-
-  if (dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli) == 0 ||
-      dli.dli_fname == NULL) {
-    st->print_cr("Error: Cannot print dynamic libraries.");
-    return;
-  }
-  handle = dlopen(dli.dli_fname, RTLD_LAZY);
-  if (handle == NULL) {
-    st->print_cr("Error: Cannot print dynamic libraries.");
-    return;
-  }
   dlinfo(handle, RTLD_DI_LINKMAP, &map);
   if (map == NULL) {
-    st->print_cr("Error: Cannot print dynamic libraries.");
-    return;
-  }
-
-  while (map->l_prev != NULL)
+    dlclose(handle);
+    return 1;
+  }
+
+  while (map->l_prev != NULL) {
     map = map->l_prev;
+  }
 
   while (map != NULL) {
-    st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
+    // Iterate through all map entries and call callback with fields of interest
+    if(callback(map->l_name, (address)map->l_addr, (address)0, param)) {
+      dlclose(handle);
+      return 1;
+    }
     map = map->l_next;
   }
 
   dlclose(handle);
+  return 0;
+}
+
+int _print_dll_info_cb(const char * name, address base_address, address top_address, void * param) {
+  outputStream * out = (outputStream *) param;
+  out->print_cr(PTR_FORMAT " \t%s", base_address, name);
+  return 0;
+}
+
+void os::print_dll_info(outputStream * st) {
+  st->print_cr("Dynamic libraries:"); st->flush();
+  if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) {
+    st->print_cr("Error: Cannot print dynamic libraries.");
+  }
 }
 
   // Loads .dll/.so and