Skip to content

Commit 71fc6df

Browse files
committed
Fix for Windows
1 parent 1653999 commit 71fc6df

File tree

5 files changed

+82
-27
lines changed

5 files changed

+82
-27
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgCDebugger.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -69,11 +69,11 @@ public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {
6969
public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {
7070
if (dbg.getCPU().equals("amd64")) {
7171
AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
72-
Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
73-
if (rbp == null) return null;
72+
Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP);
73+
if (rsp == null) return null;
7474
Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
7575
if (pc == null) return null;
76-
return new WindowsAMD64CFrame(dbg, rbp, pc);
76+
return new WindowsAMD64CFrame(dbg, rsp, pc);
7777
} else {
7878
// unsupported CPU!
7979
return null;

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgDebugger.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -90,4 +90,10 @@ public long readCInteger(long address, long numBytes, boolean isUnsigned
9090
// public ThreadProxy getThreadForIdentifierAddress(Address addr);
9191

9292
public int getAddressSize();
93+
94+
public Address getFrameBase(Address sp, Address pc);
95+
96+
public static record SenderRegs(Address nextSP, Address nextPC) {};
97+
98+
public SenderRegs getSenderRegs(Address sp, Address pc);
9399
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgDebuggerLocal.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -229,6 +229,16 @@ public synchronized ClosestSymbol lookup(long address) {
229229
return lookupByAddress0(address);
230230
}
231231

232+
public synchronized Address getFrameBase(Address sp, Address pc) {
233+
long rawAddr = getFrameBase0(sp.asLongValue(), pc.asLongValue());
234+
return newAddress(rawAddr);
235+
}
236+
237+
public synchronized SenderRegs getSenderRegs(Address sp, Address pc) {
238+
long[] rawSenderRegs = getSenderRegs0(sp.asLongValue(), pc.asLongValue());
239+
return rawSenderRegs == null ? null : new SenderRegs(newAddress(rawSenderRegs[0]), newAddress(rawSenderRegs[1]));
240+
}
241+
232242
/** From the Debugger interface */
233243
public MachineDescription getMachineDescription() {
234244
return machDesc;
@@ -646,6 +656,8 @@ private native byte[] readBytesFromProcess0(long address, long numBytes)
646656
private native String consoleExecuteCommand0(String cmd);
647657
private native long lookupByName0(String objName, String symName);
648658
private native ClosestSymbol lookupByAddress0(long address);
659+
private native long getFrameBase0(long sp, long pc);
660+
private native long[] getSenderRegs0(long sp, long pc);
649661

650662
// helper called lookupByAddress0
651663
private ClosestSymbol createClosestSymbol(String symbol, long diff) {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/windows/amd64/WindowsAMD64CFrame.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,49 +31,39 @@
3131
import sun.jvm.hotspot.debugger.windbg.*;
3232

3333
public class WindowsAMD64CFrame extends BasicCFrame {
34-
private Address rbp;
34+
private Address rsp;
3535
private Address pc;
3636

3737
private static final int ADDRESS_SIZE = 8;
3838

3939
/** Constructor for topmost frame */
40-
public WindowsAMD64CFrame(WindbgDebugger dbg, Address rbp, Address pc) {
40+
public WindowsAMD64CFrame(WindbgDebugger dbg, Address rsp, Address pc) {
4141
super(dbg.getCDebugger());
42-
this.rbp = rbp;
42+
this.rsp = rsp;
4343
this.pc = pc;
4444
this.dbg = dbg;
4545
}
4646

4747
public CFrame sender(ThreadProxy thread) {
48-
AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
49-
Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP);
50-
51-
if ( (rbp == null) || rbp.lessThan(rsp) ) {
48+
WindbgDebugger.SenderRegs senderRegs = dbg.getSenderRegs(rsp, pc);
49+
if (senderRegs == null) {
5250
return null;
5351
}
54-
55-
// Check alignment of rbp
56-
if ( dbg.getAddressValue(rbp) % ADDRESS_SIZE != 0) {
57-
return null;
58-
}
59-
60-
Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE);
61-
if (nextRBP == null || nextRBP.lessThanOrEqual(rbp)) {
52+
if (senderRegs.nextSP() == null || senderRegs.nextSP().lessThanOrEqual(rsp)) {
6253
return null;
6354
}
64-
Address nextPC = rbp.getAddressAt( 1 * ADDRESS_SIZE);
65-
if (nextPC == null) {
55+
if (senderRegs.nextPC() == null) {
6656
return null;
6757
}
68-
return new WindowsAMD64CFrame(dbg, nextRBP, nextPC);
58+
return new WindowsAMD64CFrame(dbg, senderRegs.nextSP(), senderRegs.nextPC());
6959
}
7060

7161
public Address pc() {
7262
return pc;
7363
}
7464

7565
public Address localVariableBase() {
76-
return rbp;
66+
return dbg.getFrameBase(rsp, pc);
7767
}
7868

7969
private WindbgDebugger dbg;

src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -862,3 +862,50 @@ JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLoc
862862
CHECK_EXCEPTION_(0);
863863
return res;
864864
}
865+
866+
/*
867+
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
868+
* Method: getFrameBase0
869+
* Signature: (JJ)J
870+
*/
871+
JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_getFrameBase0
872+
(JNIEnv *env, jobject obj, jlong sp, jlong pc) {
873+
IDebugControl* ptrIDebugControl = (IDebugControl*)env->GetLongField(obj, ptrIDebugControl_ID);
874+
CHECK_EXCEPTION_(0);
875+
876+
DEBUG_STACK_FRAME frames;
877+
ULONG filled;
878+
HRESULT result = ptrIDebugControl->GetStackTrace(0, sp, pc, &frames, 1, &filled);
879+
880+
return (result != S_OK || filled != 1) ? 0 : frames.FrameOffset;
881+
}
882+
883+
/*
884+
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
885+
* Method: getSenderRegs0
886+
* Signature: (JJ)[J
887+
*/
888+
JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_getSenderRegs0
889+
(JNIEnv *env, jobject obj, jlong sp, jlong pc) {
890+
IDebugControl* ptrIDebugControl = (IDebugControl*)env->GetLongField(obj, ptrIDebugControl_ID);
891+
CHECK_EXCEPTION_(nullptr);
892+
893+
DEBUG_STACK_FRAME frames[2];
894+
ULONG filled;
895+
HRESULT dbg_result = ptrIDebugControl->GetStackTrace(0, sp, pc, frames, 2, &filled);
896+
if (dbg_result != S_OK || filled != 2) {
897+
return nullptr;
898+
}
899+
900+
jlongArray result = env->NewLongArray(2);
901+
CHECK_EXCEPTION_(nullptr);
902+
if (result == nullptr) {
903+
return nullptr;
904+
}
905+
906+
jlong regs[] = { static_cast<jlong>(frames[1].StackOffset), static_cast<jlong>(frames[1].InstructionOffset) };
907+
env->SetLongArrayRegion(result, 0, 2, regs);
908+
CHECK_EXCEPTION_(nullptr);
909+
910+
return result;
911+
}

0 commit comments

Comments
 (0)