Debugging your software project with the Eclipse platform

Source: Internet
Author: User

Debugging is a job that programmers can't avoid. There are many ways to debug a method, but ultimately, you find the code that throws the error. For example, fragmentation failures are considered one of the most common errors in Linux applications. This error occurs when a program attempts to access memory that is not assigned to it and terminates because of a segmented violation.

To fix this error, you need to find the line of code that raised the behavior. Once you find the line of code that has the problem, it is also helpful to know the context in which the error was raised and its associated values, variables, and methods. Using the debugger makes finding this information fairly straightforward.

Eclipse Debugger and Debug view

The Eclipse platform features a built-in Java debugger that provides all of the standard debugging features, including the ability to step through, set breakpoints and values, check variables and values, and suspend and resume threads. In addition, you can debug applications running on a remote machine. The Eclipse platform is primarily a Java development environment, but its architecture is also open to other programming languages. As you will see below, the Debug view of the same Eclipse can also be used in the C and C + + programming languages.

The Eclipse Platform Workbench (Eclipse Platform Workbench) and its tools are built on the Java development tools (JDT) component. These components provide Eclipse with the following features:

1. Project Management Tools

2, Perspective and view

3, builder, editor, search and build capabilities

4, debugger

The Eclipse debugger itself exists as a standard plug-in included in the eclipse binaries. Eclipse also has a special debug view that allows you to manage the debugging and running of programs in the workbench. It displays the stack frame of its suspend thread for each target in the Debug. The individual lines in the program appear as nodes of the tree, while the Debug view displays the processes for each of the running targets in the Cheng. If a thread is suspended, its stack frame is displayed as a child element.

Before you start using the Eclipse debugger, assume that you have installed the appropriate Java SDK/JRE (I recommend that you use Java VM 1.4) and the Eclipse platform SDK 2.0/2.1, and both are working properly.

In general, it is a good idea to use Eclipse samples to test debugging options first. If you want to develop and debug a C + + project, you will also need to obtain and install the C + + development tool (C + + Development TOOL,CDT). For a link to the Java Sdk/jre, Eclipse Platform and sample, and CDT, figure 1 shows the general view of the Debug user interface.

Figure 1. General view of the Eclipse Debug View user interface

Debugging Java

Before you can debug your project, you need to compile and run the code completely. You first need to create a run configuration for your application and confirm that it starts properly. After that, you will need to use Run > Debug ... menu to set the Debug configuration in the same way. You also need to select the classes that are used by the debugger as the main Java class (see Figure 2). For a project, there are several debugging configurations you want to have. When the debugger starts (through Run > Debug ...). , opens it in a new window, and you are ready to start debugging.

Figure 2. To set the main Java class for a project in a debug configuration

The following are sample instructions for the most common Eclipse debugging operations:

Set breakpoints

When you start the application for debugging, Eclipse automatically switches to the debug perspective. Undoubtedly, the most common debugging process is to set breakpoints to allow you to check variables and values in conditional statements and loops. To set a breakpoint in the Package Explorer view of the Java perspective, double-click the selected source code file to open it in the editor. Iterate through all the code and place the cursor on the tag bar (on the left side of the editor area) of the line that contains the suspicious code. Double-click to set breakpoints (see also Figure 3).

Figure 3. You can see two breakpoint markers on the left edge of the editor

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.