Skip to content

Commit

Permalink
Fix JDWP ThreadReference.frames
Browse files Browse the repository at this point in the history
* Fix case where the length is unspecified but the start frame is > 0
* Return error packets on invalid parameters
  • Loading branch information
gilles-duboscq committed Dec 20, 2024
1 parent dc50bc4 commit 048ee0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class ErrorCodes {
public static final int ABSENT_INFORMATION = 101;
public static final int INVALID_EVENT_TYPE = 102;
public static final int INTERNAL = 113;
public static final int INVALID_INDEX = 503;
public static final int INVALID_LENGTH = 504;
public static final int INVALID_STRING = 506;
public static final int INVALID_CLASS_LOADER = 507;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2111,8 +2111,7 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
}

int startFrame = input.readInt();
int length = input.readInt();
final int requestedLength = length;
int requestedLength = input.readInt();

controller.fine(() -> "requesting frames for thread: " + controller.getContext().getThreadName(thread));
controller.fine(() -> "startFrame requested: " + startFrame);
Expand All @@ -2127,13 +2126,21 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
}

CallFrame[] frames = suspendedInfo.getStackFrames();

if (length == -1 || length > frames.length) {
length = frames.length;
if (startFrame < 0 || startFrame >= frames.length) {
reply.errorCode(ErrorCodes.INVALID_INDEX);
return new CommandResult(reply);
}
int length;
if (requestedLength == -1) {
length = frames.length - startFrame;
} else if (requestedLength < 0 || startFrame + requestedLength > frames.length) {
reply.errorCode(ErrorCodes.INVALID_LENGTH);
return new CommandResult(reply);
} else {
length = requestedLength;
}
reply.writeInt(length);
final int finalLength = length;
controller.fine(() -> "returning " + finalLength + " frames for thread: " + controller.getContext().getThreadName(thread));
controller.fine(() -> "returning " + length + " frames for thread: " + controller.getContext().getThreadName(thread));

for (int i = startFrame; i < startFrame + length; i++) {
CallFrame frame = frames[i];
Expand Down

0 comments on commit 048ee0a

Please sign in to comment.