Performing step operations and inspecting variables

You can now perform different step operations (step over, step in, and step out) using the toolbar icons at the top, or using keyboard shortcuts. Open the drop-down on the Run menu to learn about the menu and toolbar shortcuts for debugging. Typically, you would inspect variables or perform step operations to verify whether the execution flow is correct and then continue the execution by clicking the Resume button or by using the menu/keyboard shortcut.

In the Debug tab (refer to Figure 6.8), you can see all the threads and inspect the stack frames of each thread when the debugger is suspended. Stack frames of a thread show you the path of a program execution in that thread until the point that the debugger was suspended after hitting a breakpoint or due to step operations. In a multithreaded application, such as a Tomcat web container, more than one thread might have been suspended at a time and each might have different stack frames. When debugging a multithreaded application, make sure that you have selected the required thread in the Debug tab before selecting options to step over/in/out or resume.

Often, you step into a method and realize that the values are not what you expect and you want to rerun statements in the current method to investigate them. In such cases, you can drop to any previous stack frame and start over.

For example, let's say that in the preceding example we step into the DatabaseConnectionFactory.getConnectionFactory().getConnection method. When we step in, the debugger first steps into the getConnectionFactory method, and in the next step-in operation, it steps into the getConnection method. Suppose, when we are in the getConnection method that we want to go back and check what happened in the getConnectionFactory method for something that we might have missed earlier (although in this simple example, not much happens in the getConnectionFactory method; it should just serve as an example). We can go back to the getCourses method and start over the execution of getConnectionFactory and getConnection. In the Debug tab, right-click on the CourseDAO.getCourses() stack frame and select Drop to Frame, as shown in the following screenshot:

Figure 6.9 Drop to Frame

The debugger discards all the stack frames above the selected frame, and the execution drops back to the selected frame; in this case, in the getCourses method of the CourseDAO class. You can then step over again into the getConnection method. Note that only stack variables and their values are discarded when you drop to frame. Any changes made to reference objects that are not on the stack are not rolled back.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.0.145