Use the eclipse platform for debugging

Source: Internet
Author: User
Tags php debugger ibm developerworks gdb debugger pc world

Use eclipse to debug software projects

Document options

<Tr valign = "TOP"> <TD width = "8"> </TD> <TD width = "16"> </ TD> <TD class = "small" width = "122"> <p> <SPAN class = "Ast"> the required JavaScript document options are not displayed </span> </P> </TD> </tr>

Send this page as an email

Level: Intermediate

Chris aniszczyk, software engineer, IBM
Pawel Leszek (, independent software consultant, freelance

May 31, 2007

This article describes how to use the built-in functions of the eclipse platform to debug software projects. Debugging is a must for programmers. There are many debugging methods, but in the final analysis, it is to find out the code with bugs. For example, the most common error in Linux applications isSegment error (segmentation fault). When the program tries to access the memory that is not allocated to it, it will terminate because the segment is out of bounds. This error occurs. To fix such errors, you need to find the line of code that triggers the error. After finding the problematic code, you can understand the context, related values, variables, and methods of the error. It is very easy to use the debugger to find this information.

Editor's Note: Pawel Leszek was originally written below in May 2003, and then updated by Chris aniszczyk in April 2007.

Eclipse debugger and debug View

Eclipse SDK is a project for Java development tools (jdt). It has a built-in JAVA debugger that provides all the standard debugging functions, this includes step-by-step execution, breakpoint and value setting, checking variables and values, and suspending and restoring threads. In addition, you can debug the application program running on a remote machine. The eclipse platform is robust because debugging tools provided by the platform can be used by other programming languages for runtime in their respective languages. As shown below, the same eclipse debug view can also be used in C/C ++ programming languages.

The eclipse platform workbench and its tools are built around the jdt component, which provides eclipse with the following features:

  • Project management tools
  • Perspective and view
  • Constructor, editor, search, and build
  • Debugger

The eclipse debugger is a standard plug-in set in eclipse. Eclipse also has a special debug view for managing program debugging or running in the workbench. It displays the stack framework of suspended threads in each debugging target. Each thread in the program is displayed as a node in the tree, and the debug view shows the processes of each running target. If a thread is suspended, its stack frame is displayed as a child element.

Before using the eclipse debugger, assume that you have installed the appropriate Java SDK/JRE (I recommend using Java VM v1.4) and eclipse Platform SDK v3.3, and the operation of both is normal. In general, it is better to use the eclipse example to test the debugging options. To develop and debug a C/C ++ project, you also need to obtain and install C/C ++ development tools (C/C ++ development tools, CDT ). For more information about Java SDK/JRE, eclipse platform and examples, and CDT, see references. Figure 1 shows the general view of the debug perspective.

Figure 1. General View of the eclipse debug perspective

Debug Java programs

Before debugging a project, you must compile and run the code cleanly. First, create a running configuration for the application to ensure that the application can be started correctly. Then, you needRun> debugConfigure debugging in a similar way. You also need to select a class to use as the main Java class for debugging (see figure 2 ). You can configure multiple debugging configurations for a single project as needed. When the debugger is started (fromRun> debugIn a new window, you can start debugging.

Figure 2. Set the main Java class of the project in the debugging Configuration

Next, we will discuss some common debugging practices in eclipse.

Set breakpoints

When you start the application for debugging, eclipse automatically switches to the debug perspective. Undoubtedly, the most common debugging step is to set breakpoints so that you can check the variables and values in a condition statement or loop. To set a breakpoint in the package explorer view of the Java perspective, double-click the selected source code file and open it in an editor. Traverse the code, place the cursor on the mark bar of a line of suspicious code (on the left side of the editor area), and double-click to set the breakpoint.

Figure 3. Two breakpoints on the left of the Editor

NowRun> debugStart the debugging session. It is recommended that you do not place multiple statements on one row because it cannot be executed in one step or set a line breakpoint for multiple statements on the same row.

Figure 4. The arrow in the left margin of the view shows the row currently being executed

There is also a convenient breakpoint view to manage all breakpoints.

Figure 5. breakpoint View

Conditional breakpoint

Once you know where an error occurs, you may want to know what the program is doing before the program crashes. One method is to execute each line of the program in one step. Execute one line at a time until the line of code is run to the suspicious line. Sometimes it is best to run only a piece of code, stop it in the suspicious code, and check the data at this location. You can also declare a condition breakpoint that is triggered when the expression value changes (see figure 6 ). You can also use the Code help when entering a conditional expression.

Figure 6. Set a conditional breakpoint trigger

Calculate the expression value

To calculate the expression value in the debug perspective Editor, select the line of code that sets the breakpoint. In the context menuCTRL + Shift + IOr right-click the variable you are interested in (see figure 7) and select the inspect option. In the context of the current stack framework, the expression value is calculated and the result is displayed in the expressions view of the display window.

Figure 7. Using the inspect option to calculate the expression value

Cut activity code

The display view allows you to process activity code in a cut type (see figure 8 ). To process a variable, enter the variable name in the display view. The view will prompt you with a familiar content assistant.

Figure 8. display view

When the debugger stops at a breakpoint, you can select the step over option from the debug view toolbar (see figure 9) to continue the debugger session. This operation will go beyond the highlighted line of code and continue to execute the next line of code in the same method (or continue to execute the next line of code that calls the method of the current method ). Variables that change after the previous step are highlighted in a certain color (Yellow by default ). The color can be changed on the debug preferences page.

Figure 9. color change variable

To suspend the execution thread in the debug view, select a running thread and clickSuspend. The current call stack of this thread is displayed, and the currently executed code line is highlighted in the editor in the debug perspective. When a thread is suspended, place the cursor over the variable in the Java editor, and the value of this variable will be displayed in a small hover window. In this case, the top stack framework of the thread is automatically selected, and the visible variables are also displayed in the variables view. You can check variables by clicking the appropriate variable name in the variables view.

Hot Swap Error Correction: dynamic code correction

If Java Virtual Machine (JVM) v1.4 or a later version is run, eclipse supports a function called hotswap bug fixing, JVM v1.3 or a later version does not support this function. This function allows you to change the source code in a debugger Session, which is better than exiting the application, changing the code, re-compiling, and starting another debugging session. To use this function, modify the code in the editor and then re-debug it. JVM v1.4 is compatible with the Java platform debugger architecture (Java platform debugger architecture, JPDA. JPDA allows you to replace the modified Code in a running application. This is particularly useful if the application has been started for a long time or when it fails to be executed.

If the program has not been fully executed yet, select the terminate option in the context menu of the debug view. An easy mistake is to use DEBUG or run in a debugger session, rather than resume. This will start another debugger session instead of continuing the current session.

Back to Top

Remote debugging

The eclipse debugger provides an interesting option for debugging remote applications. It can connect to a remote VM running a Java application and connect itself to the application. The remote debugging session is roughly the same as the local debugging session. However, the remote debugging configuration must beRun> debugWindow to configure different settings. SelectRemote Java applicationOption, and then clickNew. In this way, a new remote STARTUP configuration is created, and three tabs are displayed: connect, source, and common.

In the Project Field on the connect tab, select the project to be referenced when you start the source code search. In the host field on the connect tab, enter the IP address or domain name of the remote host that runs the Java program. In the port field on the connect tab, enter the port on which the remote VM receives the connection. Generally, this port is specified when the remote VM is started. If you want the debugger to determine whether the terminate command is available in a remote session, you can select the allow termination of remote VM option. Select this option if you want to terminate the connected VM. Now, when you select the debug option, the debugger will try to connect to the remote Vm with the specified address or port, and the result will be displayed in the debug view.

If the startup program cannot connect to the VM at the specified address, an error message is displayed. Generally, whether the remote debugging function can be used depends entirely on the Java VM running on the remote host. Figure 10 shows the connection property settings for a remote debugging session.

Figure 10. Set the connection attribute of a remote debugging session

Back to Top

Debug other languages

Java is the most widely used language in eclipse, but eclipse is a scalable platform that supports many other languages. Eclipse supports C/C ++ through C/C ++ development tools (CDT. CDT extends the standard Eclipse debug view and adds the C/C ++ code debugging function. The CDT debug view can manage the debugging process of the C/C ++ project on the workbench. CDT does not have an internal debugger, but it provides a front-end of the GNU gdb debugger, which must be available locally. Other projects can provide their own debuggers, such as PHP development tools (PDT). See Figure 11.

Figure 11. php Debugger

Back to Top


The eclipse platform provides a built-in JAVA debugger with standard debugging functions, including step-by-step execution, breakpoint and value setting, variable and value checking, and thread suspension and restoration. It can also be used to debug applications running on a remote machine. The eclipse platform is mainly a Java development environment, but the eclipse debug view can also be used in C/C ++, PHP, and many other programming languages.

Back to Top

Thank you

Thanks to Taylor Anderson for drawing Figure 11.



  • For more information, see the original article on the developerworks global site.

  • Visit to obtain comprehensive information about the program and its usage.
  • Visit to learn about the changes in the eclipse community.
  • Learn about C/C ++ development tools from's CDT project.
  • View the Ajax tools framework (ATF) Flash page and project page to learn about JavaScript debugging.
  • Use this eclipsecon tutorial to learn about the eclipse debug framework.
  • View the "Recommended eclipse reading list ".
  • Browse all eclipse articles and tutorials on developerworks.
  • New eclipse users should check the eclipse beginners here.
  • See the Eclipse project resource center on IBM developerworks to expand your eclipse skills.
  • For interesting interviews and discussions with software developers, see the developerworks podcasts.
  • For details about the eclipse platform, see "getting started with the eclipse platform ".
  • Stay tuned to technical events and network broadcasts on developerworks.
  • View upcoming conferences, business exhibitions, network broadcasts, and other activities worldwide for IBM open source developers.
  • Visit the developerworks open source technology area and provide a large number of how-to information, tools, and project updates to help you develop with open source technology and use it with IBM products.

Obtain products and technologies

  • Download the latest eclipse technology from IBM alphaWorks.

  • Download the IBM product evaluation version and start using application development tools and middleware Products from DB2, Lotus, rational, Tivoli and websphere.
  • Use the IBM trial software to create your next open source code development project, which can be downloaded or obtained from a DVD.


  • View the eclipse CDT news group to learn about the development help for C/C ++ debugging. (Select this link to start the default Usenet news reader application and open eclipse. Tools. CDT .)

  • View eclipse ATF newsgroups for help on JavaScript debugging. (Select this link to start the default Usenet news reader application and open eclipse. WebTools. ATF .)
  • Check eclipse platform newsgroups and ask about debugging and eclipse Platform issues. (Select this link to start the default Usenet news reader application and open eclipse. Platform .)
  • Eclipse platform newsgroups should be your first stop to discuss eclipse issues. (Select this link to start the default Usenet news reader application and open eclipse. Platform .)
  • Eclipse newsgroups provides a lot of references for those who are interested in using and expanding eclipse.
  • Join the developerworks community by joining developerworks blogs.

Author Profile

Chris aniszczyk is a software engineer at IBM Lotus and is dedicated to osgi-related development. He is an open-source enthusiast and is committed to working on the Gentoo Linux release. He is also a contributor to some eclipse projects (PDE, ECF, emft. You can discuss with him about open source code and eclipse at any time.


Pawel Leszek is a writer of Studio B. He is an independent software consultant and writer specializing in Linux/win/Mac OS system architecture and management. He has many experience in operating systems, programming languages and network protocols, especially Lotus Domino and DB2. Pawel is also the author of a series of articles on LinuxWorld and a Linux columnist for PC world in Poland. Pawel lives in Warsaw with his wife and lovely little daughter. You can send an email ( directly to the author ).


Related Article

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: 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.