Home Database Mysql Tutorial eclipse调试技巧

eclipse调试技巧

Jun 07, 2016 pm 03:36 PM
eclipse Can help app Skill solve identify debug

可以帮助识别和解决应用程序缺陷,在本文中,作者将使用大家常用的的开发工具Eclipse来调试Java应用程序。但这里介绍的调试方法基本都是通用的,也适用于NetBeans IDE,我们会把重点放在运行时上面。 在开始之前,推荐大家去看看Eclipse shortcuts这篇文章,

可以帮助识别和解决应用程序缺陷,在本文中,作者将使用大家常用的的开发工具Eclipse来调试Java应用程序。但这里介绍的调试方法基本都是通用的,也适用于NetBeans IDE,我们会把重点放在运行时上面。

在开始之前,推荐大家去看看Eclipse shortcuts这篇文章,它将会给你带来很多方便。在本文中使用的是Eclipse Juno版(Eclipse 4.2),在开始前给大家提3点建议!

不要使用System.out.println作为调试工具 把所有涉及到的组件日志级别激活并使用 使用日志分析器来读取日志

1.条件断点

如果你不知道如何添加断点,只需点击左边面板(行号前面)断点即被创建。在调试界面中,“断点”视图会把所有被创建的断点列出来。我们可以给它加一个布尔条件,也就是说,该断点会被激活并且如果布尔条件为真,就会执行该断点,否则将会跳过往下执行。

eclipse调试技巧

2.异常断点

在断点视图中,有一个J!标记按钮!我们可以使用该按钮来添加一个Java异常断点。例如,我们想让程序在遇到空指针异常(NullPointerException)时,仍然能继续调试,那么我们可以使用该按钮来添加一个异常断点!

eclipse调试技巧

3.监视点

这是一个非常好的功能,当选定的属性访问或修改程序时,程序会停止执行并允许进行调试。在Outline视图中选择一个类变量并从上下文菜单中选择切换监视点,属性监视点将会被创建,在断点(Breakpoints)视图中会把所有监视点用列表的形式显示出来。

eclipse调试技巧

4.评估/检查

按Ctrl+Shift+D或者Ctrl+Shift+I来显示选定变量或者表达式的值。我们也可以给一个变量或表达式添加永久观察点,当程序在调试时,这些观察点就会在表达式视图(Expression view)中显示出来。

eclipse调试技巧

5.修改变量值

在调试过程中,我们可以修改变量值。先选好一个变量然后进入变量视图(Variables view),根据变量类型在其对应的Value列里输入值即可。

eclipse调试技巧

6.在Main函数里面停止执行

在运行/调试设置中,编辑配置对话框中有“Main”这个选项卡,我们可以勾选“Stop in main”这个复选框。如果选中,那么在调试一个基于main方法的Java程序时,程序会在main方法第一行位置便停止执行。

eclipse调试技巧

7.环境变量

并不是在系统属性中添加环境变量,我们可以在编辑配置对话框中很方便地进行添加。

eclipse调试技巧

8.Drop to Frame

这也是我最喜欢的一个功能。调试期间,可以重新跳到调用堆栈框架的开始处执行,并且变量值也会回到最初。根据回档调整堆栈的深度,这个功能的主要用途是所有变量状态可以快速回到方法开始执行时候的样子,然后你可以重新进行一遍一遍执行,这样就可以在你关注的地方进行多次调试,但是在执行过程中也会产生一些副作用,比如插入到数据库里面的数据是无法删除的!

eclipse调试技巧

9.分布过滤

当我们进入(F5)方法的时候,我们还可以访问其外部库(比如java.*),我们可能不需要这个库,就可以在Perference选项卡页面添加一个过滤器来排除这个包。

eclipse调试技巧

10.进入、跳出和返回

我把这个放在最后一点,在调试过程中,这些是必须要了解(最好掌握)的东西:

F5——进入:移动到下一个步骤,如果当前行有一个方法调用,该控件将会跳转到被调用方法的第一行执行。

F6——跳出:移动到下一行。如果在当前行有方法调用,那么会直接移动到下一行执行。不会进入被调用方法体里面。

F7——返回:从当前方法中跳出,继续往下执行。

F8——移动到下一个断点处执行。

eclipse调试技巧

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Shazam app not working in iPhone: Fix Shazam app not working in iPhone: Fix Jun 08, 2024 pm 12:36 PM

Having issues with the Shazam app on iPhone? Shazam helps you find songs by listening to them. However, if Shazam isn't working properly or doesn't recognize the song, you'll have to troubleshoot it manually. Repairing the Shazam app won't take long. So, without wasting any more time, follow the steps below to resolve issues with Shazam app. Fix 1 – Disable Bold Text Feature Bold text on iPhone may be the reason why Shazam is not working properly. Step 1 – You can only do this from your iPhone settings. So, open it. Step 2 – Next, open the “Display & Brightness” settings there. Step 3 – If you find that “Bold Text” is enabled

Detailed explanation of C++ function debugging: How to debug problems in multi-threaded functions? Detailed explanation of C++ function debugging: How to debug problems in multi-threaded functions? May 02, 2024 pm 04:15 PM

C++ multi-thread debugging can use GDB: 1. Enable debugging information compilation; 2. Set breakpoints; 3. Use infothreads to view threads; 4. Use thread to switch threads; 5. Use next, stepi, and locals to debug. Actual case debugging deadlock: 1. Use threadapplyallbt to print the stack; 2. Check the thread status; 3. Single-step the main thread; 4. Use condition variables to coordinate access to solve the deadlock.

How to use LeakSanitizer to debug C++ memory leaks? How to use LeakSanitizer to debug C++ memory leaks? Jun 02, 2024 pm 09:46 PM

How to use LeakSanitizer to debug C++ memory leaks? Install LeakSanitizer. Enable LeakSanitizer via compile flag. Run the application and analyze the LeakSanitizer report. Identify memory allocation types and allocation locations. Fix memory leaks and ensure all dynamically allocated memory is released.

Shortcut to golang function debugging and analysis Shortcut to golang function debugging and analysis May 06, 2024 pm 10:42 PM

This article introduces shortcuts for Go function debugging and analysis, including: built-in debugger dlv, which is used to pause execution, check variables, and set breakpoints. Logging, use the log package to record messages and view them during debugging. The performance analysis tool pprof generates call graphs and analyzes performance, and uses gotoolpprof to analyze data. Practical case: Analyze memory leaks through pprof and generate a call graph to display the functions that cause leaks.

How to conduct concurrency testing and debugging in Java concurrent programming? How to conduct concurrency testing and debugging in Java concurrent programming? May 09, 2024 am 09:33 AM

Concurrency testing and debugging Concurrency testing and debugging in Java concurrent programming are crucial and the following techniques are available: Concurrency testing: Unit testing: Isolate and test a single concurrent task. Integration testing: testing the interaction between multiple concurrent tasks. Load testing: Evaluate an application's performance and scalability under heavy load. Concurrency Debugging: Breakpoints: Pause thread execution and inspect variables or execute code. Logging: Record thread events and status. Stack trace: Identify the source of the exception. Visualization tools: Monitor thread activity and resource usage.

How to debug PHP asynchronous code How to debug PHP asynchronous code May 31, 2024 am 09:08 AM

Tools for debugging PHP asynchronous code include: Psalm: a static analysis tool that can find potential errors. ParallelLint: A tool that inspects asynchronous code and provides recommendations. Xdebug: An extension for debugging PHP applications by enabling a session and stepping through the code. Other tips include using logging, assertions, running code locally, and writing unit tests.

PHP Debugging Errors: A Guide to Common Mistakes PHP Debugging Errors: A Guide to Common Mistakes Jun 05, 2024 pm 03:18 PM

Common PHP debugging errors include: Syntax errors: Check the code syntax to make sure there are no errors. Undefined variable: Before using a variable, make sure it is initialized and assigned a value. Missing semicolons: Add semicolons to all code blocks. Function is undefined: Check that the function name is spelled correctly and make sure the correct file or PHP extension is loaded.

Detailed explanation of C++ function debugging: How to debug problems in functions that contain exception handling? Detailed explanation of C++ function debugging: How to debug problems in functions that contain exception handling? Apr 30, 2024 pm 01:36 PM

C++ debugging functions that contain exception handling uses exception point breakpoints to identify exception locations. Use the catch command in gdb to print exception information and stack traces. Use the exception logger to capture and analyze exceptions, including messages, stack traces, and variable values.

See all articles