8056242: Add function to return structured information about loaded libraries

Return structured information about loaded libraries.

Reviewed-by: sla, dsamersoff
This commit is contained in:
Fredrik Arvidsson 2014-09-03 14:43:49 +02:00 committed by Staffan Larsen
parent 88eb5fb4d6
commit 07001d0332
5 changed files with 169 additions and 163 deletions

View file

@ -1722,41 +1722,54 @@ bool os::dll_address_to_library_name(address addr, char* buf,
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;
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 ||
// Sanity check?
if (dladdr(CAST_FROM_FN_PTR(void *, os::get_loaded_modules_info), &dli) == 0 ||
dli.dli_fname == NULL) {
st->print_cr("Error: Cannot print dynamic libraries.");
return;
return 1;
}
handle = dlopen(dli.dli_fname, RTLD_LAZY);
void * handle = dlopen(dli.dli_fname, RTLD_LAZY);
if (handle == NULL) {
st->print_cr("Error: Cannot print dynamic libraries.");
return;
return 1;
}
Link_map *map;
dlinfo(handle, RTLD_DI_LINKMAP, &map);
if (map == NULL) {
st->print_cr("Error: Cannot print dynamic libraries.");
return;
dlclose(handle);
return 1;
}
while (map->l_prev != NULL)
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