JPDA Architecture Research 4-JDWP Transport Interface

Source: Internet
Author: User

Introduced:

The previous article mainly analyzes the format of packets transmitted by the JDWP layer, and this article focuses on how the JDWP layer is transmitted.


Analysis:

The implementation of the transmission is based on each JVM's own implementation, but what they have in common is that they are all implemented in C/s + +, and all jdwpTransport.h (the same file as the previous one). The implementation is based on our knowledge that it exists in the form of a DLL file (or so file under the UNIX platform). As we learned from the previous, JDWP layer has the agent is responsible for the packet and JVMTI function calls between the conversion, so it is logical to know that the Transport layer DLL file must also have an onload method, and let the agent start time to invoke.



Analyze how 1:agent accesses the VM environment?

The answer is through the environment pointer (environment pointer), which is returned to the agent in the OnLoad () method. This environment pointer is defined as follows:

struct _jdwptransportenv; #ifdef __cplusplustypedef _jdwptransportenv jdwptransportenv;...struct _JDWPTRANSPORTENV { const struct JDWPTRANSPORTNATIVEINTERFACE_ *functions;

So here you can see that the nature of the environment pointer is to get a set of native interfaces that can access the target VM environment.


Parses the onload () method that is called at 2:agent startup.

The method is signed as follows:

Jniexport jint jnicall jdwptransport_onload (JAVAVM *JVM, Jdwptransportcallback *callback, Jint version, jdwptransportenv** env);

From here we can see that the _onload method requires the following parameters:

JVM: It allows the agent to obtain JVM information through the GETJAVAVM method.

Callback: It is a pointer to a function table.

Version: It allows the agent to obtain the desired versions of the Jdwptransport.

Then the return value is in the fourth parameter, which is the environment pointer we want.

If the transport layer is initialized successfully, then the _onload method returns JNI_OK, otherwise the corresponding error code is returned.


An overview of the methods supported by the analysis 3:jdwptransport.

Because Jdwptransport needs to maintain the relationship between the debugger and target VMS, it has many methods. We look at several major categories.


Category 1: for managing connections

The main purpose of the method for managing connections is to establish and close connections to debugger.

A. Attach. It is primarily used to correlate to debugger and establish a trusted link between the debugger.

Step 1: Connect to the specified address

Step 2: The connection is successful, by swapping "jdwp-handshake" to ensure that the connection to debugger is indeed established.

/* 3:attach */jdwptransporterror (Jnicall *attach) (jdwptransportenv* env, const char* address, Jlong Attach_timeout, Jlong handshake_timeout);

As you can see, in addition to the environment pointers, it requires the following 3 parameters:

Address and Port of Address:debugger

Attach_timeout: Sets the connection timeout, in milliseconds. If set to 0, the description never times out.

Handshake_timeout: Sets the handshake timeout value, in milliseconds. If set to 0, the description never times out.


B.startlistening. It is mainly used to let the transmitter in listen mode so that it can listen to the connection from the debugger.

/* 4:startlistening */jdwptransporterror (Jnicall *startlistening) (jdwptransportenv* env, const char* Address , char** actual_address);

In addition to the environment pointers, it requires 1 parameters:

Address and Port of Address:debugger

Actualaddress: Returns a value that returns the address of the actual string form that the transmitter obtains from the address parameter.


C.stoplistening. It is primarily used to let the transmitter leave the listen mode so that it no longer listens for connections from the debugger.

/* 5:stoplistening */jdwptransporterror (Jnicall *stoplistening) (jdwptransportenv* env);


D.accept. It is primarily used to establish connections from debugger.

/* 6:accept */jdwptransporterror (Jnicall *accept) (jdwptransportenv* env, Jlong accept_timeout, Jlong Handshake_timeout);


E.isopen. It is used to test whether the debugger connection is on or off.

/* 7:isopen */Jboolean (Jnicall *isopen) (jdwptransportenv* env);


F.close. It is used to close the connection to the debugger.

/* 8:close */jdwptransporterror (Jnicall *close) (jdwptransportenv* env);



Category 2: Used to read packets from debugger and packets sent to debugger.

A. Readpacket. It is used to read packets from debugger in a state of open connection.

/* 9:readpacket */jdwptransporterror (Jnicall *readpacket) (jdwptransportenv* env, Jdwppacket *pkt);

It is important to note that the method only does a length check on the packet, not the integrity check.


B.writepacket. It is used to write packets to debugger when the connection is open.

/* 10:write Packet */jdwptransporterror (Jnicall *writepacket) (jdwptransportenv* env, const jdwppacket* PKT);


Category 3: Accessibility features.

A.getlasterror. It is used to return the last error represented by a string.

/* 11:getlasterror */jdwptransporterror (Jnicall *getlasterror) (jdwptransportenv* env, char** error);


B.getcapabilities. It is used to return all the support capabilities of the JDWP transmitter.

/* 2:get Capabilities */Jdwptransporterror (Jnicall *getcapabilities) (jdwptransportenv* env, JDWPTransportC Apabilities *capabilities_ptr);

The ability to enable and disable is indicated by a set of bitmap bits.

This article is from the "cohesion of parallel Lines" blog, please be sure to keep this source http://supercharles888.blog.51cto.com/609344/1587625

JPDA Architecture Research 4-JDWP Transport Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.