Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jdwp support #61

Merged
merged 20 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ bpftools-arm64.tar.gz
bpftools-min-arm64.tar.gz
bpftools-x86_64.tar.gz
bpftools-min-x86_64.tar.gz

.flake8
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
Daquiver1 marked this conversation as resolved.
Show resolved Hide resolved
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
4 changes: 2 additions & 2 deletions projects/jdwp/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python_binary(


python_library(
name = "lib",
srcs = [],
name = "defs",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not projects/jdwp/defs/BUCK, but that is fine. In this case please keep the original name ("lib") and we should be good to go.

srcs = glob(["**/*.py"]),
visibility = ["PUBLIC"],
)
Empty file added projects/jdwp/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions projects/jdwp/defs/command_sets/reference_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

"""Command Set: ReferenceType."""


from projects.jdwp.defs.schema import Command, Field, Struct, CommandSet, Type
from projects.jdwp.defs.constants import ErrorType


Signature = Command(
name="Signature",
id=1,
out=Struct(
[
Field("refType", Type.REFERENCE_TYPE_ID, "The Reference type ID."),
]
),
reply=Struct(
[
Field(
"signature", Type.STRING, "The JNI signature for the reference type."
),
]
),
error={
ErrorType.INVALID_CLASS,
ErrorType.INVALID_OBJECT,
ErrorType.VM_DEAD,
},
)


ReferenceType = CommandSet(
name="ReferenceType",
id=2,
commands=[
Signature,
],
)
179 changes: 179 additions & 0 deletions projects/jdwp/defs/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

from enum import Enum, Flag


class ErrorType(Enum):
"""Error constants for JDWP."""

NONE = 0
INVALID_THREAD = 10
INVALID_THREAD_GROUP = 11
INVALID_PRIORITY = 12
THREAD_NOT_SUSPENDED = 13
THREAD_SUSPENDED = 14
THREAD_NOT_ALIVE = 15
INVALID_OBJECT = 20
INVALID_CLASS = 21
CLASS_NOT_PREPARED = 22
INVALID_METHODID = 23
INVALID_LOCATION = 24
INVALID_FIELDID = 25
INVALID_FRAMEID = 30
NO_MORE_FRAMES = 31
OPAQUE_FRAME = 32
NOT_CURRENT_FRAME = 33
TYPE_MISMATCH = 34
INVALID_SLOT = 35
DUPLICATE = 40
NOT_FOUND = 41
INVALID_MONITOR = 50
NOT_MONITOR_OWNER = 51
INTERRUPT = 52
INVALID_CLASS_FORMAT = 60
CIRCULAR_CLASS_DEFINITION = 61
FAILS_VERIFICATION = 62
ADD_METHOD_NOT_IMPLEMENTED = 63
SCHEMA_CHANGE_NOT_IMPLEMENTED = 64
INVALID_TYPESTATE = 65
HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66
DELETE_METHOD_NOT_IMPLEMENTED = 67
UNSUPPORTED_VERSION = 68
NAMES_DONT_MATCH = 69
CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70
METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71
NOT_IMPLEMENTED = 99
NULL_POINTER = 100
ABSENT_INFORMATION = 101
INVALID_EVENT_TYPE = 102
ILLEGAL_ARGUMENT = 103
OUT_OF_MEMORY = 110
ACCESS_DENIED = 111
VM_DEAD = 112
INTERNAL = 113
UNATTACHED_THREAD = 115
INVALID_TAG = 500
ALREADY_INVOKING = 502
INVALID_INDEX = 503
INVALID_LENGTH = 504
INVALID_STRING = 506
INVALID_CLASS_LOADER = 507
INVALID_ARRAY = 508
TRANSPORT_LOAD = 509
TRANSPORT_INIT = 510
NATIVE_METHOD = 511
INVALID_COUNT = 512


class ClassStatus(Enum):
"""ClassStatus constants for JDWP."""

VERIFIED = 1
PREPARED = 2
INITIALIZED = 4
ERROR = 8


class EventKind(Enum):
"""EventKind constants for JDWP."""

SINGLE_STEP = 1
BREAKPOINT = 2
FRAME_POP = 3
EXCEPTION = 4
USER_DEFINED = 5
THREAD_START = 6
THREAD_DEATH = 7
THREAD_END = 7
CLASS_PREPARE = 8
CLASS_UNLOAD = 9
CLASS_LOAD = 10
FIELD_ACCESS = 20
FIELD_MODIFICATION = 21
EXCEPTION_CATCH = 30
METHOD_ENTRY = 40
METHOD_EXIT = 41
METHOD_EXIT_WITH_RETURN_VALUE = 42
MONITOR_CONTENDED_ENTER = 43
MONITOR_CONTENDED_ENTERED = 44
MONITOR_WAIT = 45
MONITOR_WAITED = 46
VM_START = 90
VM_INIT = 90
VM_DEATH = 99
VM_DISCONNECTED = 100


class InvokeOptions(Flag):
"""Invoke options constants for JDWP."""

INVOKE_SINGLE_THREADED = 0x01
INVOKE_NONVIRTUAL = 0x02


class StepDepth(Enum):
"""StepDepth constants for JDWP."""

INTO = 0
OVER = 1
OUT = 2


class StepSize(Enum):
"""StepSize constants for JDWP."""

MIN = 0
LINE = 1


class SuspendPolicy(Enum):
"""SuspendPolicy constants for JDWP."""

NONE = 0
EVENT_THREAD = 1
ALL = 2


class SuspendStatus(Enum):
"""SuspendStatus constants for JDWP."""

SUSPEND_STATUS_SUSPENDED = 0x1


class Tag(Enum):
"""Tag constants for JDWP."""

ARRAY = 91
BYTE = 66
CHAR = 67
OBJECT = 76
FLOAT = 70
DOUBLE = 68
INT = 73
LONG = 74
SHORT = 83
VOID = 86
BOOLEAN = 90
STRING = 115
THREAD = 116
THREAD_GROUP = 103
CLASS_LOADER = 108
CLASS_OBJECT = 99


class ThreadStatus(Enum):
"""ThreadStatus constants for JDWP."""

ZOMBIE = 0
RUNNING = 1
SLEEPING = 2
MONITOR = 3
WAIT = 4


class TypeTag(Enum):
"""TypeTag constants for JDWP."""

CLASS = 1
INTERFACE = 2
ARRAY = 3
83 changes: 83 additions & 0 deletions projects/jdwp/defs/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

"""Basic types for JDWP messages."""

from dataclasses import dataclass
from typing import Optional
from enum import Enum
from collections.abc import Set, Sequence

from projects.jdwp.defs.constants import ErrorType


class PrimitiveType(Enum):
"""Primitive type class."""

STRING = "string"
INT = "int"
BYTE = "byte"
BOOLEAN = "boolean"
DICT = "dict"
REFERENCE_TYPE_ID = "referenceTypeID"
CLASS_LOADER = "classLoader"
FIELD_ID = "fieldID"
METHOD_ID = "methodID"
VALUE = "value"
INTERFACE_ID = "interfaceID"
CLASS_OBJECT_ID = "classObjectID"
TAGGED_OBJECT_ID = "taggedObjectID"
THREAD_ID = "threadID"
THREAD_GROUP_ID = "threadGroupID"
OBJECT_ID = "objectID"
LOCATION = "location"


class Array(Enum):
"""Array class type."""

pass


class TaggedUnion(Enum):
"""Tagged Union class type"""

pass


Type = PrimitiveType | Array | TaggedUnion


@dataclass(frozen=True)
class Field:
"""Field class."""

name: str
type: Type
description: str


@dataclass(frozen=True)
class Struct:
"""Struct class."""

fields: Sequence[Field]


@dataclass(frozen=True)
class Command:
"""Command class."""

name: str
id: int
out: Optional[Struct]
reply: Optional[Struct]
error: Set[ErrorType]


@dataclass(frozen=True)
class CommandSet:
"""Command set class."""

name: str
id: int
commands: Sequence[Command]