【正文】
Tool Interface) ? VM — 虛擬機(jī)( Virtual Sun Microsystem 的 Java Platform Debugger Architecture (JPDA) 技術(shù)是一個(gè)多層架構(gòu),使您能夠在各種環(huán)境中輕松調(diào)試 Java 應(yīng)用程序。本文概述了設(shè)置遠(yuǎn)程應(yīng)用程序調(diào)試的特性和示例。s set in Window Preferences Java Compiler. Figure 1. Debug options in Eclipse Debug an application remotely We are ready to start debugging an application remotely. Let39。Debug Java applications remotely with Eclipse Use the power of the Eclipse IDE to spread around your Java application debugging Level: Intermediate Charles Lu (), Software Engineer, IBM 09 Dec 2020 You don39。s do it step by step: 1. Create a Java project with a simple class We create a simple class for debugging purpose. Listing 4 shows the sample code. Listing 4. Sample code for debugging package 。 遠(yuǎn)程調(diào)試對(duì)應(yīng)用程序開發(fā)十分有用。 JPDA 由兩個(gè)接口(分 別是 JVM Tool Interface 和 JDI)、一個(gè)協(xié)議( Java Debug Wire Protocol)和兩個(gè)用于合并它們的軟件組件(后端和前端)組成。 提供了兩個(gè)傳輸機(jī)制:套接字傳輸和共享內(nèi)存?zhèn)鬏?。但如果連接到 V5 以前的 VM,只能選擇 Xdebug 和 Xrunjdwp。參見 參考資料 獲得關(guān)于 Eclipse JDT 和 Java JDI 技術(shù)的信息。在這個(gè)例子中,我們?cè)? (This is a test.)。 作為調(diào)試服務(wù)器的目標(biāo) VM 下面這個(gè)示例遠(yuǎn)程調(diào)用 Java 應(yīng)用程序作為調(diào)試服務(wù)器,并在端口 8000 監(jiān)聽套接字連接。在這里,您可以使用標(biāo)準(zhǔn)的調(diào)試特性,比如設(shè)置斷點(diǎn)和值、單步執(zhí)行等。 ? 隨時(shí)關(guān)注 developerWorks 的 技術(shù)活動(dòng)和網(wǎng)絡(luò)廣播 。 。 ? 查閱最近將在全球舉辦的面向 IBM 開放源碼開發(fā)人員的研討會(huì)、交易展覽、網(wǎng)絡(luò)廣播和其他 活動(dòng) 。介紹了如何設(shè)置 Java 應(yīng)用程序以調(diào)用遠(yuǎn)程調(diào)試,并幫助您理解 Eclipse 提供的連接器。 清單 6. Eclipse 連接套接字模式下的 VM 調(diào)用示例 java Xdebug Xrunjdwp:transport=dt_socket,server=y,address=8000 jar 使用遠(yuǎn)程啟動(dòng)配置啟動(dòng) Eclipse,并指定遠(yuǎn)程應(yīng)用程序的目標(biāo) VM 地址。 圖 2. 在 Eclipse 中設(shè)置斷點(diǎn) 3. 從本地調(diào)試應(yīng)用程序 在調(diào)試應(yīng)用程序之前,確保已經(jīng)為項(xiàng)目啟用圖 1 中描述的調(diào)試選項(xiàng)。要了解 Eclipse 提供的遠(yuǎn)程連接類型,您可以轉(zhuǎn)到 Eclipse 菜單并選擇 Run Debug Configurations...,在 Remote Java Application 中添加一個(gè)啟動(dòng)配置,然后從下拉列表中選擇連接器。 transport 這里通常使用套接字傳輸。隨后,另一端將連接到監(jiān)聽器并建立一個(gè)連接。 JPDA 不僅能夠用于桌面系統(tǒng),而且能夠在嵌入式系統(tǒng)上很好地工作。其他情況包括:運(yùn)行在內(nèi)存小或 CUP 性能低的設(shè)備上的 Java 應(yīng) 用程序(比如移動(dòng)設(shè)備),或者開發(fā)人員想要將應(yīng)用程序和開發(fā)環(huán)境分開,等等。 } } 2. Set a breakpoint Set a breakpoint in the code. In this example, we set the breakpoint in the line (This is a test.)。t have it already, download Eclipse (Ganymede). In Ganymede, the socket listening connector has been added to the Remote Java Application launchconfiguration type. Eclipse39。: socket transport and shared memory transport. Available connectors: ? Socketattaching connector ? Sharedmemory attaching connector ? Socketlistening connector ? Sharedmemory listening connector ? Commandline launching connector In establishing a connection between a debugger application and target VM, one side acts as a server and listens for a connection. At some later time, the other side attaches to the listener and establishes a connection. The connections allow the debugger application or the target VM to act as a server. The munications among processes can be running on one machine or different machines. The problem with debugging a Java program remotely is not in the debugger front end but the remote Java back end. Unfortunately, there is not much information about this in the Eclipse help system. In fact, JDI and JVMTI are implemented by Eclipse and the Java runtime environment, respectively. The only thing we are concerned with is the JDWP, which contains the information to municate with the JVMTI and JDI. The JDWP contains many arguments that have been added to invoke the application for the remote Java application. Following are some of the arguments used in this article. Xdebug Enables debugging features. Xrunjdwp:suboptions Loads the implementation of JDWP in the target VM. It uses a transport and the JDWP protocol to municate with a separate debugger application. Specific suboptions are described below. Starting from Java V5, you can use the agentlib:jdwp option, instead of Xdebug and Xrunjdwp. But if you have to connect to the VM prior to V5, Xdebug and Xrunjdwp will be the only choice. Following are brief descriptions of the Xrunjdwp suboptions. transport Generally, socket transport is used. But sharedmemory transport can also be used on the Windows platform, if available. server If the value is y, the target application listens for a debugger application to attach. Otherwise, it attaches to a debugger application at the specified address. address This is the transport address for the connection. If the server is n, attempt to attach to a debugger application at this address. Otherwise, listen for a connection at this port. suspend If the value is y, the target VM will be suspended until the debugger application connects. For detailed explanations for each debug setting, refer to the JPDA documentation (see Resources). Listing 2 shows an example of how to launch a VM in debug mode and listen for a socket connection at port 8765. Listing 2. Target VM acts as a debug server Xdebug Xrunjdwp:transport=dt_socket,server=y,address=8765 Listing 3 shows how to attach to a running debugger application using a socket on host at port 8000. Listing 3. Target VM acts as a debug client Xdebug Xrunjdwp:transport=dt_socket,address=:8000 Remote debugging features in Eclipse Eclipse is a graphical Java debugger front end. The JDI is implemented in bundle. In this article, we don39。S_CMP=EDU 使用