Skip to content

Commit

Permalink
More tests, make all commands cloneable, other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
necauqua committed May 29, 2023
1 parent fa9be24 commit d253b59
Show file tree
Hide file tree
Showing 21 changed files with 565 additions and 222 deletions.
6 changes: 3 additions & 3 deletions src/commands/array_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::jdwp_command;

/// Returns the number of components in a given array.
#[jdwp_command(i32, 13, 1)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct Length {
/// The array object ID
array_id: ArrayID,
Expand All @@ -17,7 +17,7 @@ pub struct Length {
///
/// The specified range must be within the bounds of the array.
#[jdwp_command(ArrayRegion, 13, 2)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct GetValues {
/// The array object ID
array_id: ArrayID,
Expand All @@ -38,7 +38,7 @@ pub struct GetValues {
/// value's type to the array component type and the array component type must
/// be loaded.
#[jdwp_command((), 13, 3)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct SetValues {
/// The array object ID
array_id: ArrayID,
Expand Down
27 changes: 27 additions & 0 deletions src/commands/array_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use jdwp_macros::JdwpReadable;

use super::jdwp_command;

use crate::{
codec::JdwpWritable,
enums::Tag,
types::{ArrayID, ArrayTypeID},
};

/// Creates a new array object of this type with a given length.
#[jdwp_command(4, 1)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct NewInstance {
/// The array type of the new instance
array_type_id: ArrayTypeID,
/// The length of the array
length: i32,
}

#[derive(Debug, JdwpReadable)]
pub struct NewInstanceReply {
// should always be Tag::Array
_tag: Tag,
/// The newly created array object
pub new_array: ArrayID,
}
27 changes: 27 additions & 0 deletions src/commands/class_loader_reference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use jdwp_macros::{jdwp_command, JdwpWritable};

use crate::types::{ClassLoaderID, TaggedReferenceTypeID};

/// Returns a list of all classes which this class loader has been requested
/// to load.
///
/// This class loader is considered to be an initiating class loader for
/// each class in the returned list. The list contains each reference
/// type defined by this loader and any types for which loading was
/// delegated by this class loader to another class loader.
///
/// The visible class list has useful properties with respect to the type
/// namespace.
///
/// A particular type name will occur at most once in the list.
///
/// Each field or variable declared with that type name in a class defined
/// by this class loader must be resolved to that single type.
///
/// No ordering of the returned list is guaranteed.
#[jdwp_command(Vec<TaggedReferenceTypeID>, 14, 1)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct VisibleClasses {
/// The class loader object ID
class_loader_id: ClassLoaderID,
}
11 changes: 11 additions & 0 deletions src/commands/class_object_reference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use jdwp_macros::{jdwp_command, JdwpWritable};

use crate::types::{ClassObjectID, TaggedReferenceTypeID};

/// Returns the reference type reflected by this class object.
#[jdwp_command(TaggedReferenceTypeID, 17, 1)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct ReflectedType {
/// The class object
class_object_id: ClassObjectID,
}
8 changes: 4 additions & 4 deletions src/commands/class_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{JdwpReadable, JdwpWritable};
///
/// The return is null if the class is java.lang.Object.
#[jdwp_command(Option<ClassID>, 3, 1)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct Superclass {
/// The class type ID.
class_id: ClassID,
Expand All @@ -31,7 +31,7 @@ pub struct Superclass {
/// For object values, there must exist a widening reference conversion from the
/// value's type to thefield's type and the field's type must be loaded.
#[jdwp_command((), 3, 2)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct SetValues {
/// The class type ID.
class_id: ClassID,
Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct SetValues {
/// method invocation continues.
#[jdwp_command(3, 3)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct InvokeMethod {
/// The class type ID.
class_id: ClassID,
Expand All @@ -103,7 +103,7 @@ pub struct InvokeMethod {
}

#[jdwp_command(3, 4)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct NewInstance {
/// The class type ID.
class_id: ClassID,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/event_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
/// which are automatically generated events - see
/// [Composite](super::event::Composite) command for further details.
#[jdwp_command(RequestID, 15, 1)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct Set {
/// Event kind to request. Some events may require a capability in order to
/// be requested.
Expand Down Expand Up @@ -61,7 +61,7 @@ pub struct Set {
/// Automatically generated events do not have a corresponding event request
/// and may not be cleared using this command.
#[jdwp_command((), 15, 2)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct Clear {
/// Event kind to clear
event_kind: EventKind,
Expand All @@ -71,5 +71,5 @@ pub struct Clear {

/// Removes all set breakpoints, a no-op if there are no breakpoints set.
#[jdwp_command((), 15, 3)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct ClearAllBreakpoints;
67 changes: 67 additions & 0 deletions src/commands/interface_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use jdwp_macros::{jdwp_command, JdwpWritable};

use crate::{
enums::InvokeOptions,
types::{InterfaceID, InvokeMethodReply, MethodID, ThreadID, Value},
};

/// Invokes a static method. The method must not be a static initializer.
/// The method must be a member of the interface type.
///
/// Since JDWP version 1.8
///
/// The method invocation will occur in the specified thread. Method
/// invocation can occur only if the specified thread has been suspended by
/// an event. Method invocation is not supported when the target VM has been
/// suspended by the front-end.
///
/// The specified method is invoked with the arguments in the specified
/// argument list. The method invocation is synchronous; the reply packet is
/// not sent until the invoked method returns in the target VM. The return
/// value (possibly the void value) is included in the reply packet. If the
/// invoked method throws an exception, the exception object ID is set in
/// the reply packet; otherwise, the exception object ID is null.
///
/// For primitive arguments, the argument value's type must match the
/// argument's type exactly. For object arguments, there must exist a
/// widening reference conversion from the argument value's type to the
/// argument's type and the argument's type must be loaded.
///
/// By default, all threads in the target VM are resumed while the method is
/// being invoked if they were previously suspended by an event or by a
/// command. This is done to prevent the deadlocks that will occur if any of
/// the threads own monitors that will be needed by the invoked method. It
/// is possible that breakpoints or other events might occur during the
/// invocation. Note, however, that this implicit resume acts exactly like
/// the ThreadReference resume command, so if the thread's suspend count is
/// greater than 1, it will remain in a suspended state during the
/// invocation. By default, when the invocation completes, all threads in
/// the target VM are suspended, regardless their state before the
/// invocation.
///
/// The resumption of other threads during the invoke can be prevented by
/// specifying the SINGLE_THREADED bit flag in the options field;
/// however, there is no protection against or recovery from the deadlocks
/// described above, so this option should be used with great caution. Only
/// the specified thread will be resumed (as described for all threads
/// above). Upon completion of a single threaded invoke, the invoking thread
/// will be suspended once again. Note that any threads started during the
/// single threaded invocation will not be suspended when the invocation
/// completes.
// If the target VM is disconnected during the invoke (for example, through the VirtualMachine
// [Dispose](super::virtual_machine::Dispose) command) the method invocation continues.
#[jdwp_command(5, 1)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct InvokeMethod {
/// The interface type ID
interface_id: InterfaceID,
/// The thread in which to invoke
thread_id: ThreadID,
/// The method to invoke
method_id: MethodID,
/// The argument values
arguments: Vec<Value>,
/// Invocation options
options: InvokeOptions,
}
10 changes: 5 additions & 5 deletions src/commands/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::jdwp_command;
/// The line number information is constant unless a new class definition is
/// installed using [RedefineClasses](super::virtual_machine::RedefineClasses).
#[jdwp_command(6, 1)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct LineTable {
/// The class.
reference_type_id: ReferenceTypeID,
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct Line {
/// For instance methods, the "this" reference is included in the table. Also,
/// synthetic variables may be present.
#[jdwp_command(6, 2)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct VariableTable {
/// The class.
reference_type_id: ReferenceTypeID,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct Variable {
/// Requires `canGetBytecodes` capability - see
/// [CapabilitiesNew](super::virtual_machine::CapabilitiesNew).
#[jdwp_command(Vec<u8>, 6, 3)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct Bytecodes {
/// The class.
reference_type_id: ReferenceTypeID,
Expand All @@ -111,7 +111,7 @@ pub struct Bytecodes {
/// their bytecodes are the same except for indices into the constant pool and
/// the referenced constants are equal.
#[jdwp_command(bool, 6, 4)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct IsObsolete {
/// The class.
reference_type_id: ReferenceTypeID,
Expand All @@ -129,7 +129,7 @@ pub struct IsObsolete {
///
/// Since JDWP version 1.5.
#[jdwp_command(6, 5)]
#[derive(Debug, JdwpWritable)]
#[derive(Debug, Clone, JdwpWritable)]
pub struct VariableTableWithGeneric {
/// The class.
reference_type_id: ReferenceTypeID,
Expand Down
107 changes: 8 additions & 99 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,121 +1,30 @@
use std::fmt::Debug;

use jdwp_macros::jdwp_command;

use crate::{
codec::{JdwpReadable, JdwpWritable},
types::ClassObjectID,
CommandId,
};

use crate::{enums::Tag, types::*};

pub mod array_type {
use super::*;

/// Creates a new array object of this type with a given length.
#[jdwp_command(4, 1)]
#[derive(Debug, JdwpWritable)]
pub struct NewInstance {
/// The array type of the new instance
array_type_id: ArrayTypeID,
/// The length of the array
length: i32,
}

#[derive(Debug, JdwpReadable)]
pub struct NewInstanceReply {
// should always be Tag::Array
_tag: Tag,
/// The newly created array object
pub new_array: ArrayID,
}
}

pub mod class_loader_reference {
use super::*;

/// Returns a list of all classes which this class loader has been requested
/// to load.
///
/// This class loader is considered to be an initiating class loader for
/// each class in the returned list. The list contains each reference
/// type defined by this loader and any types for which loading was
/// delegated by this class loader to another class loader.
///
/// The visible class list has useful properties with respect to the type
/// namespace.
///
/// A particular type name will occur at most once in the list.
///
/// Each field or variable declared with that type name in a class defined
/// by this class loader must be resolved to that single type.
///
/// No ordering of the returned list is guaranteed.
#[jdwp_command(Vec<TaggedReferenceTypeID>, 14, 1)]
#[derive(Debug, JdwpWritable)]
pub struct VisibleClasses {
/// The class loader object ID
class_loader_id: ClassLoaderID,
}
}

pub mod class_object_reference {
use super::*;

/// Returns the reference type reflected by this class object.
#[jdwp_command(TaggedReferenceTypeID, 17, 1)]
#[derive(Debug, JdwpWritable)]
pub struct ReflectedType {
/// The class object
class_object_id: ClassObjectID,
}
}

pub mod string_reference {
use super::*;

/// Returns the characters contained in the string.
#[jdwp_command(String, 10, 1)]
#[derive(Debug, JdwpWritable)]
pub struct Value {
/// The String object ID
string_object: ObjectID,
}
}

/// This module is defined to mirror the JDWP command set, which is empty
pub mod field {}

pub mod interface_type {
use super::*;

#[jdwp_command(5, 1)]
#[derive(Debug, JdwpWritable)]
pub struct InvokeMethod {
/// The interface type ID
interface_id: InterfaceID,
/// The thread in which to invoke
thread_id: ThreadID,
/// The method to invoke
method_id: MethodID,
/// Invocation options
arguments: Vec<Value>,
}
}

pub mod array_reference;
pub mod array_type;
pub mod class_loader_reference;
pub mod class_object_reference;
pub mod class_type;
pub mod event;
pub mod event_request;
pub mod interface_type;
pub mod method;
pub mod object_reference;
pub mod reference_type;
pub mod stack_frame;
pub mod string_reference;
pub mod thread_group_reference;
pub mod thread_reference;
pub mod virtual_machine;

/// This module is defined to mirror the JDWP command set, which is empty
pub mod field {}

pub trait Command {
const ID: CommandId;

Expand Down
Loading

0 comments on commit d253b59

Please sign in to comment.