8273967: gtest os.dll_address_to_function_and_library_name_vm fails on macOS12
Reviewed-by: stuefe, gziemski
This commit is contained in:
parent
a74a839af0
commit
92d2176362
src/hotspot
test/hotspot/gtest/runtime
@ -52,6 +52,12 @@ bool MachODecoder::demangle(const char* symbol, char *buf, int buflen) {
|
||||
|
||||
bool MachODecoder::decode(address addr, char *buf,
|
||||
int buflen, int *offset, const void *mach_base) {
|
||||
if (addr == (address)(intptr_t)-1) {
|
||||
// dladdr() in macOS12/Monterey returns success for -1, but that addr value
|
||||
// won't work in this function. Should have been handled by the caller.
|
||||
ShouldNotReachHere();
|
||||
return false;
|
||||
}
|
||||
struct symtab_command * symt = (struct symtab_command *)
|
||||
mach_find_command((struct mach_header_64 *)mach_base, LC_SYMTAB);
|
||||
if (symt == NULL) {
|
||||
|
@ -838,6 +838,17 @@ int os::current_process_id() {
|
||||
|
||||
const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; }
|
||||
|
||||
static int local_dladdr(const void* addr, Dl_info* info) {
|
||||
#ifdef __APPLE__
|
||||
if (addr == (void*)-1) {
|
||||
// dladdr() in macOS12/Monterey returns success for -1, but that addr
|
||||
// value should not be allowed to work to avoid confusion.
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return dladdr(addr, info);
|
||||
}
|
||||
|
||||
// This must be hard coded because it's the system's temporary
|
||||
// directory not the java application's temp directory, ala java.io.tmpdir.
|
||||
#ifdef __APPLE__
|
||||
@ -877,9 +888,6 @@ bool os::address_is_in_vm(address addr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#define MACH_MAXSYMLEN 256
|
||||
|
||||
bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
int buflen, int *offset,
|
||||
bool demangle) {
|
||||
@ -887,9 +895,8 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
assert(buf != NULL, "sanity check");
|
||||
|
||||
Dl_info dlinfo;
|
||||
char localbuf[MACH_MAXSYMLEN];
|
||||
|
||||
if (dladdr((void*)addr, &dlinfo) != 0) {
|
||||
if (local_dladdr((void*)addr, &dlinfo) != 0) {
|
||||
// see if we have a matching symbol
|
||||
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
|
||||
if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
|
||||
@ -898,6 +905,14 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
// The 6-parameter Decoder::decode() function is not implemented on macOS.
|
||||
// The Mach-O binary format does not contain a "list of files" with address
|
||||
// ranges like ELF. That makes sense since Mach-O can contain binaries for
|
||||
// than one instruction set so there can be more than one address range for
|
||||
// each "file".
|
||||
|
||||
// no matching symbol so try for just file info
|
||||
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
|
||||
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
|
||||
@ -906,6 +921,10 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
}
|
||||
}
|
||||
|
||||
#else // __APPLE__
|
||||
#define MACH_MAXSYMLEN 256
|
||||
|
||||
char localbuf[MACH_MAXSYMLEN];
|
||||
// Handle non-dynamic manually:
|
||||
if (dlinfo.dli_fbase != NULL &&
|
||||
Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset,
|
||||
@ -915,6 +934,9 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef MACH_MAXSYMLEN
|
||||
#endif // __APPLE__
|
||||
}
|
||||
buf[0] = '\0';
|
||||
if (offset != NULL) *offset = -1;
|
||||
@ -929,7 +951,7 @@ bool os::dll_address_to_library_name(address addr, char* buf,
|
||||
|
||||
Dl_info dlinfo;
|
||||
|
||||
if (dladdr((void*)addr, &dlinfo) != 0) {
|
||||
if (local_dladdr((void*)addr, &dlinfo) != 0) {
|
||||
if (dlinfo.dli_fname != NULL) {
|
||||
jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
|
||||
}
|
||||
|
@ -907,7 +907,7 @@ bool os::print_function_and_library_name(outputStream* st,
|
||||
addr = addr2;
|
||||
}
|
||||
}
|
||||
#endif // HANDLE_FUNCTION_DESCRIPTORS
|
||||
#endif // HAVE_FUNCTION_DESCRIPTORS
|
||||
|
||||
if (have_function_name) {
|
||||
// Print function name, optionally demangled
|
||||
|
@ -709,11 +709,7 @@ TEST_VM(os, pagesizes_test_print) {
|
||||
ASSERT_EQ(strcmp(expected, buffer), 0);
|
||||
}
|
||||
|
||||
#if defined(__APPLE__) // See JDK-8273967.
|
||||
TEST_VM(os, DISABLED_dll_address_to_function_and_library_name) {
|
||||
#else
|
||||
TEST_VM(os, dll_address_to_function_and_library_name) {
|
||||
#endif
|
||||
TEST_VM(os, dll_address_to_function_and_library_name) {
|
||||
char tmp[1024];
|
||||
char output[1024];
|
||||
stringStream st(output, sizeof(output));
|
||||
@ -726,8 +722,10 @@ TEST_VM(os, pagesizes_test_print) {
|
||||
#define LOG(...)
|
||||
|
||||
// Invalid addresses
|
||||
LOG("os::print_function_and_library_name(st, -1) expects FALSE.");
|
||||
address addr = (address)(intptr_t)-1;
|
||||
EXPECT_FALSE(os::print_function_and_library_name(&st, addr));
|
||||
LOG("os::print_function_and_library_name(st, NULL) expects FALSE.");
|
||||
addr = NULL;
|
||||
EXPECT_FALSE(os::print_function_and_library_name(&st, addr));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user