Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -86,18 +86,22 @@ public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {
String cpu = dbg.getCPU();
if (cpu.equals("amd64") || cpu.equals("x86_64")) {
AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP);
if (rsp == null) return null;
Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
if (rbp == null) return null;
Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
if (pc == null) return null;
return new BsdAMD64CFrame(dbg, rbp, pc);
return new BsdAMD64CFrame(dbg, rsp, rbp, pc);
} else if (cpu.equals("aarch64")) {
AARCH64ThreadContext context = (AARCH64ThreadContext) thread.getContext();
Address sp = context.getRegisterAsAddress(AARCH64ThreadContext.SP);
if (sp == null) return null;
Address fp = context.getRegisterAsAddress(AARCH64ThreadContext.FP);
if (fp == null) return null;
Address pc = context.getRegisterAsAddress(AARCH64ThreadContext.PC);
if (pc == null) return null;
return new BsdAARCH64CFrame(dbg, fp, pc);
return new BsdAARCH64CFrame(dbg, sp, fp, pc);
} else {
throw new DebuggerException(cpu + " is not yet supported");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, Red Hat Inc.
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
Expand All @@ -26,15 +26,19 @@

package sun.jvm.hotspot.debugger.bsd.aarch64;

import sun.jvm.hotspot.code.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.debugger.aarch64.*;
import sun.jvm.hotspot.debugger.bsd.*;
import sun.jvm.hotspot.debugger.cdbg.*;
import sun.jvm.hotspot.debugger.cdbg.basic.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.runtime.aarch64.*;

public final class BsdAARCH64CFrame extends BasicCFrame {
public BsdAARCH64CFrame(BsdDebugger dbg, Address fp, Address pc) {
public BsdAARCH64CFrame(BsdDebugger dbg, Address sp, Address fp, Address pc) {
super(dbg.getCDebugger());
this.sp = sp;
this.fp = fp;
this.pc = pc;
this.dbg = dbg;
Expand All @@ -54,28 +58,65 @@ public Address localVariableBase() {
return fp;
}

@Override
public CFrame sender(ThreadProxy thread) {
AARCH64ThreadContext context = (AARCH64ThreadContext) thread.getContext();
Address rsp = context.getRegisterAsAddress(AARCH64ThreadContext.SP);
return sender(thread, null, null, null);
}

if ((fp == null) || fp.lessThan(rsp)) {
return null;
@Override
public CFrame sender(ThreadProxy thread, Address nextSP, Address nextFP, Address nextPC) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it that for aarch64 these are all "next" arguments, but for AMD64 they are not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to declare like sender(ThreadProxy th, Address sp, Address fp, Address pc) as defined in CFrame, however name of parameters (sp, fp, pc) have already declared as class members in BsdAARCH64CFrame. Thus I added next as a prefix of parameter name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Looks like that was also the case with LunuxAARCH64CFrame.

// Check fp
// Skip if both nextFP and nextPC are given - do not need to load from fp.
if (nextFP == null && nextPC == null) {
if (fp == null) {
return null;
}

// Check alignment of fp
if (dbg.getAddressValue(fp) % (2 * ADDRESS_SIZE) != 0) {
return null;
}
}

// Check alignment of fp
if (dbg.getAddressValue(fp) % (2 * ADDRESS_SIZE) != 0) {
if (nextFP == null) {
nextFP = fp.getAddressAt(0);
}
if (nextFP == null) {
return null;
}

Address nextFP = fp.getAddressAt(0 * ADDRESS_SIZE);
if (nextFP == null || nextFP.lessThanOrEqual(fp)) {
return null;
if (nextPC == null) {
nextPC = fp.getAddressAt(ADDRESS_SIZE);
}
Address nextPC = fp.getAddressAt(1 * ADDRESS_SIZE);
if (nextPC == null) {
return null;
}
return new BsdAARCH64CFrame(dbg, nextFP, nextPC);

if (nextSP == null) {
CodeCache cc = VM.getVM().getCodeCache();
CodeBlob currentBlob = cc.findBlobUnsafe(pc());

// This case is different from HotSpot. See JDK-8371194 for details.
if (currentBlob != null && (currentBlob.isContinuationStub() || currentBlob.isNativeMethod())) {
// Use FP since it should always be valid for these cases.
// TODO: These should be walked as Frames not CFrames.
nextSP = fp.addOffsetTo(2 * ADDRESS_SIZE);
} else {
CodeBlob codeBlob = cc.findBlobUnsafe(nextPC);
boolean useCodeBlob = codeBlob != null && codeBlob.getFrameSize() > 0;
nextSP = useCodeBlob ? nextFP.addOffsetTo((2 * ADDRESS_SIZE) - codeBlob.getFrameSize()) : nextFP;
}
}
if (nextSP == null) {
return null;
}

return new BsdAARCH64CFrame(dbg, nextSP, nextFP, nextPC);
}

@Override
public Frame toFrame() {
return new AARCH64Frame(sp, fp, pc);
}

// package/class internals only
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, 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
Expand Down Expand Up @@ -29,10 +29,13 @@
import sun.jvm.hotspot.debugger.bsd.*;
import sun.jvm.hotspot.debugger.cdbg.*;
import sun.jvm.hotspot.debugger.cdbg.basic.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.runtime.amd64.*;

public final class BsdAMD64CFrame extends BasicCFrame {
public BsdAMD64CFrame(BsdDebugger dbg, Address rbp, Address rip) {
public BsdAMD64CFrame(BsdDebugger dbg, Address rsp, Address rbp, Address rip) {
super(dbg.getCDebugger());
this.rsp = rsp;
this.rbp = rbp;
this.rip = rip;
this.dbg = dbg;
Expand All @@ -52,32 +55,49 @@ public Address localVariableBase() {
return rbp;
}

@Override
public CFrame sender(ThreadProxy thread) {
AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP);
return sender(thread, null, null, null);
}

if ( (rbp == null) || rbp.lessThan(rsp) ) {
return null;
@Override
public CFrame sender(ThreadProxy thread, Address sp, Address fp, Address pc) {
// Check fp
// Skip if both fp and pc are given - do not need to load from rbp.
if (fp == null && pc == null) {
if (rbp == null) {
return null;
}

// Check alignment of rbp
if (dbg.getAddressValue(rbp) % ADDRESS_SIZE != 0) {
return null;
}
}

// Check alignment of rbp
if (dbg.getAddressValue(rbp) % ADDRESS_SIZE != 0) {
Address nextRSP = sp != null ? sp : rbp.addOffsetTo(2 * ADDRESS_SIZE);
if (nextRSP == null) {
return null;
}

Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE);
if (nextRBP == null || nextRBP.lessThanOrEqual(rbp)) {
Address nextRBP = fp != null ? fp : rbp.getAddressAt(0);
if (nextRBP == null) {
return null;
}
Address nextPC = rbp.getAddressAt( 1 * ADDRESS_SIZE);
Address nextPC = pc != null ? pc : rbp.getAddressAt(ADDRESS_SIZE);
if (nextPC == null) {
return null;
}
return new BsdAMD64CFrame(dbg, nextRBP, nextPC);
return new BsdAMD64CFrame(dbg, nextRSP, nextRBP, nextPC);
}

@Override
public Frame toFrame() {
return new AMD64Frame(rsp, rbp, rip);
}

// package/class internals only
private static final int ADDRESS_SIZE = 8;
private Address rsp;
private Address rip;
private Address rbp;
private BsdDebugger dbg;
Expand Down