From 031c9ea85d5423ef1bb6b2647a77b8422b54c080 Mon Sep 17 00:00:00 2001 From: Robbin Ehn Date: Thu, 21 Mar 2024 11:40:56 +0100 Subject: [PATCH] windows logging --- src/hotspot/os/windows/os_windows.cpp | 36 ++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 2ddebc9bf6dee..675e7d1952525 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -1279,8 +1279,33 @@ void os::dll_unload(void *lib) { } } +static size_t format_message_fixup(char* buf, size_t end) { + if (end > 3) { + if (buf[end - 1] == '\n') end--; + if (buf[end - 1] == '\r') end--; + if (buf[end - 1] == '.') end--; + buf[end] = '\0'; + } + return end; +} + void* os::dll_lookup(void *lib, const char *name) { - return (void*)::GetProcAddress((HMODULE)lib, name); + void* ret = ::GetProcAddress((HMODULE)lib, name); + DWORD errval; + if ((errval = GetLastError()) != 0) { + char* buf[512]; + size_t n = (size_t)FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + errval, + 0, + buf, + (DWORD)sizeof(buf), + nullptr); + format_message_fixup(buf, n); + log_debug(os)("Symbol %s not found in dll: %s", name, buf); + } + return ret; } // Directory routines copied from src/win32/native/java/io/dirent_md.c @@ -2165,14 +2190,7 @@ size_t os::lasterror(char* buf, size_t len) { buf, (DWORD)len, nullptr); - if (n > 3) { - // Drop final '.', CR, LF - if (buf[n - 1] == '\n') n--; - if (buf[n - 1] == '\r') n--; - if (buf[n - 1] == '.') n--; - buf[n] = '\0'; - } - return n; + return format_message_fixup(buf, n); } if (errno != 0) {