@@ -838,6 +838,17 @@ int os::current_process_id() {
838
838
839
839
const char * os::dll_file_extension () { return JNI_LIB_SUFFIX; }
840
840
841
+ static int local_dladdr (const void * addr, Dl_info* info) {
842
+ #ifdef __APPLE__
843
+ if (addr == (void *)-1 ) {
844
+ // dladdr() in macOS12/Monterey returns success for -1, but that addr
845
+ // value should not be allowed to work to avoid confusion.
846
+ return 0 ;
847
+ }
848
+ #endif
849
+ return dladdr (addr, info);
850
+ }
851
+
841
852
// This must be hard coded because it's the system's temporary
842
853
// directory not the java application's temp directory, ala java.io.tmpdir.
843
854
#ifdef __APPLE__
@@ -877,19 +888,15 @@ bool os::address_is_in_vm(address addr) {
877
888
return false ;
878
889
}
879
890
880
-
881
- #define MACH_MAXSYMLEN 256
882
-
883
891
bool os::dll_address_to_function_name (address addr, char *buf,
884
892
int buflen, int *offset,
885
893
bool demangle) {
886
894
// buf is not optional, but offset is optional
887
895
assert (buf != NULL , " sanity check" );
888
896
889
897
Dl_info dlinfo;
890
- char localbuf[MACH_MAXSYMLEN];
891
898
892
- if (dladdr ((void *)addr, &dlinfo) != 0 ) {
899
+ if (local_dladdr ((void *)addr, &dlinfo) != 0 ) {
893
900
// see if we have a matching symbol
894
901
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL ) {
895
902
if (!(demangle && Decoder::demangle (dlinfo.dli_sname , buf, buflen))) {
@@ -898,6 +905,14 @@ bool os::dll_address_to_function_name(address addr, char *buf,
898
905
if (offset != NULL ) *offset = addr - (address)dlinfo.dli_saddr ;
899
906
return true ;
900
907
}
908
+
909
+ #ifndef __APPLE__
910
+ // The 6-parameter Decoder::decode() function is not implemented on macOS.
911
+ // The Mach-O binary format does not contain a "list of files" with address
912
+ // ranges like ELF. That makes sense since Mach-O can contain binaries for
913
+ // than one instruction set so there can be more than one address range for
914
+ // each "file".
915
+
901
916
// no matching symbol so try for just file info
902
917
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL ) {
903
918
if (Decoder::decode ((address)(addr - (address)dlinfo.dli_fbase ),
@@ -906,6 +921,10 @@ bool os::dll_address_to_function_name(address addr, char *buf,
906
921
}
907
922
}
908
923
924
+ #else // __APPLE__
925
+ #define MACH_MAXSYMLEN 256
926
+
927
+ char localbuf[MACH_MAXSYMLEN];
909
928
// Handle non-dynamic manually:
910
929
if (dlinfo.dli_fbase != NULL &&
911
930
Decoder::decode (addr, localbuf, MACH_MAXSYMLEN, offset,
@@ -915,6 +934,9 @@ bool os::dll_address_to_function_name(address addr, char *buf,
915
934
}
916
935
return true ;
917
936
}
937
+
938
+ #undef MACH_MAXSYMLEN
939
+ #endif // __APPLE__
918
940
}
919
941
buf[0 ] = ' \0 ' ;
920
942
if (offset != NULL ) *offset = -1 ;
@@ -929,7 +951,7 @@ bool os::dll_address_to_library_name(address addr, char* buf,
929
951
930
952
Dl_info dlinfo;
931
953
932
- if (dladdr ((void *)addr, &dlinfo) != 0 ) {
954
+ if (local_dladdr ((void *)addr, &dlinfo) != 0 ) {
933
955
if (dlinfo.dli_fname != NULL ) {
934
956
jio_snprintf (buf, buflen, " %s" , dlinfo.dli_fname );
935
957
}
0 commit comments