I'm working with the Android tutorial and I just got to the debugging section and I'm wondering what the purpose of a Breakpoint is. I can't tell just yet... is it actually stopping the app so I can be sure it runs up until that point, or can I set multiple breakpoints and use them开发者_如何学运维 as markers to "stop and go" from breakpoint to breakpoint checking my code?
A breakpoint is a place where the execution stops, and you can start inspecting the current situation in your debugger. This includes:
- the point has actually been reached
- the current values of all variables
- the ability to change manually all variables
- the current stacktrace - i.e. which methods were executed before the current one
- the ability to add and execute arbitrary code
- the ability to inspect the results of a method invocation, while not actually proceeding with the execution
In addition to that, you can manually step forward, line by line in your application. There are three options:
- step into - enters a method which is invoked in the current line
- step over - goes to the next line
- step return - returns from the current method (to the method that invoked it)
You can set multiple breakpoints if you have multiple places where you want to do any of the above.
Generally speaking, a debugger is a very upgraded version of using System.out.println(..)
or log.debug(..)
all over the place in order to make sure certain conditions are present. (thanks to BalusC for this point)
You can definitely set multiple breakpoints. The questions answered by the breakpoint (alongside all of Eclipse's other debug tooling) include not only "did it get here" but also "how did it get here" (the stack trace) and "with what values" (you can observe the variables while the code is paused).
精彩评论