diff --git a/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp b/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp index fef9ea96552..5c7773809da 100644 --- a/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp +++ b/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -399,8 +399,11 @@ static bool setImageAndSymbolPath(JNIEnv* env, jobject obj) { IDebugSymbols* ptrIDebugSymbols = (IDebugSymbols*)env->GetLongField(obj, ptrIDebugSymbols_ID); CHECK_EXCEPTION_(false); - ptrIDebugSymbols->SetImagePath(imagePath); - ptrIDebugSymbols->SetSymbolPath(symbolPath); + COM_VERIFY_OK_(ptrIDebugSymbols->SetImagePath(imagePath), + "Windbg Error: SetImagePath failed!", false); + COM_VERIFY_OK_(ptrIDebugSymbols->SetSymbolPath(symbolPath), + "Windbg Error: SetSymbolPath failed!", false); + return true; } @@ -829,6 +832,8 @@ JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLoc return res; } +#define SYMBOL_BUFSIZE 512 + /* * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal * Method: lookupByName0 @@ -852,10 +857,22 @@ JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal if (ptrIDebugSymbols->GetOffsetByName(name, &offset) != S_OK) { return (jlong) 0; } + + // See JDK-8311993: WinDbg intermittently returns offset of "module!class::`vftable'" symbol + // when requested for decorated "class" or "class*" (i.e. "??_7class@@6B@"/"??_7class*@@6B@"). + // As a workaround check if returned symbol contains requested symbol. + ULONG64 disp = 0L; + char buf[SYMBOL_BUFSIZE]; + memset(buf, 0, sizeof(buf)); + if (ptrIDebugSymbols->GetNameByOffset(offset, buf, sizeof(buf), 0, &disp) == S_OK) { + if (strstr(buf, name) == nullptr) { + return (jlong)0; + } + } + return (jlong) offset; } -#define SYMBOL_BUFSIZE 512 /* * Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal * Method: lookupByAddress0