Tour of the debugger features.

Once the excitement of getting the debugger to work dies down, you'll want to know what features are available to make your life debugging Drupal easier. The following pages give you a flavour of those features with examples of usiing them with Drupal.

Common commands in a debugger

The following commands are common in most debuggers, and anyone who has used a debugger in another language, e.g. C, Perl will feel at home.

 

debug commands panel

These are reading from left to right: Step In , Step Over, Step Out, Go/Continue, break now, Stop, Detach

Step In

This will follow the code, so that if you step into a line containing a require statement or a function call, pressing this button will cause the debugger to go to the include file for a require statement, or the file containing the function definition for function calls.

Step Over

This will not follow the code, it will step over to the next line to execute. This is the most common action, and certainly you'd generally want to step over require statements.

Step Out

Allows you to step out of a function or include file. Useful if you accidentally stepped into something or you've seen enough and want to return to where the include file or function was called from.

Go/Continue

Usually you would use this one if you have some breakpoints set up. Under such circumstances you want to let the debugger continue execution as you know the debugger will halt when the next break point is reached.

Stop

Stop debugging. You may have seen enough to know the case of your problem or you are just fed up!

Detach

Stop the debugging process, but instead of stopping continue execution of the program.

Break Time!

Going through every line of code is not the most efficient way to debug, sooner than than later you'll want to start debugging at a particular line in a file or function, eventually with practice you'll be wanting to start debugging when certain criteria has been met.

Load the file you want to debug, if it is not already loaded in Komodo.

Komodo debugger load file - watch
Once loaded You will notice we can see a nice navigation window on the left, and below this Komodo displays the currently selected function's comments. This is useful for navigating the Drupal code. Here is a custom module I wrote, in the navigator window.
Komodo debugger code browser
The easiest way to add a breakpoint is to click on the grey area to the left of the text editor window. This will create a red breakpoint. Click it again and it becomes a red circle filled white to denote the break point is still there but the debugger will not break at that line. Click it once more to delete it, and once more again to reinstate the breakpoint.
Komodo debugger add a break point
Control-mouseclick or click and hold over a breakpoint in the breakpoint tab page will bring up a menu which alls us to set more properties for the breakpoint. Select Properties
Komodo debugger modify a break point
Having selected Properties the following dialog window will appear. Now we can make our break point a conditional breakpoint so that we only break whenever our condition is true.
Komodo debugger modifying the break point
Here we have set a condition to only break if the $op is ever equal to the value 'load'. Of course we could have just set a break point within the case 'load' to achieve the same thing.
Click OK and now you will see the conditional setting display in the Breakpoints tabpage.
Komodo debugger add a conditional break point - after
Once you get the hang of the breakpoints you will be able to control exactly when you break.

Variables and their values

Drupal has some pretty big nested data structures, so this feature is a nice way to see those values. Click on the Locals tabpage.

 

Komodo debugger local variables
Arrays can be expanded/collapsed by clicking on the triangles. This makes it alot easier to navigate the local variables.
Also these variables can be changed by clicking on a variable, then clicking on the pencil icon, or by pulling up the context menu, by either ctrl-clicking or click and hold on a variable.
Komodo change local variable

Watch it!

Watching variables is a common task programmers wish to employ when debugging. Usually the scenairo is that you want to know why a certain variable gets a certain value.

To add a variable to the watch list, first select the Watch tab on the bottom left of Komodo. Now click the square dotted icon with the yellow highlight on the top left of it. This will bring up the following dialog. In here type the variable name you wish to add to the watch list.

debugger watch 1
Now we can debug as normal, I've added a breakpoint just after the $return variable gets set.
debugger watch 2
After clicking the Go/Continue debugger command button, the execution breaks at the next break point. Whenever any of our watched variables get changed, the watch window updates. So here we can now see the current value of $return.
debugger watch 3
But that is not all. With Watch we can change the value of a watched variable thus changing how the rest of the program will execute. To do this click on the variable in the Watch window, then click on the pencil icon. (It is the one to the left of the add watch variable icon).
debugger watch 4
Watch is useful though its features are covered by the Locals and Globals tabs, however sometimes you just want to focus on a small subset of variables so watching just the one you are interested in is alot easier than having to watch the whole set of variables in your program.

Call Stack

a Call Stack is a special stack which stores information about the functions/subroutines in a computer program which are currently being executed. It is a stack because when one function calls another, rather than simply jumping to another part of the program.

We can see a call stack in Komodo. Clicking on entries in the Call Stack will cause the text editor section to jump to that particular function definition.

 

Komodo Call Stack

Here we can see that the main section in file index.php at line 15 called the function menu_execute_active_handler in file menu.inc at line 396. The Call Stack helps you to follow the flow of execution of the program.

Browse Drupal functions

Komodo is a good way to browse the php code, and functions in particular.

Komodo browsing functions

Then when you click on function, you can view the comments for that function. Notice the search form, typing in part of the function name will filter the window to only show functions which contain the search text. Here I typed 'cache'...

Komodo browsing functions - clicked
Also double clicking on a function in the view on the left of Komodo will make the text editor part on the right jump to that function definition.

 

Removing the breaks, stop debugging and detaching.

To remove breakpoints , view the current breakpoints in the Breakpoints tabpage. Click on the breakpoint you wish to remove and then click on the red circle icon with a black cross. To delete all breakpoints click on the icon with two red circles and a black cross. To toggle whether a breakpoint is active or not, click on the icon with the red and white circle.

 

removing breakpoints
To Stop Debugging, Click on the dark blue square on the right hand side in the Debug tabpage.
Stop and Detach Buttons

To detach debugging, i.e. continue execution but not in debug mode, click on the dark blue square with an arrow pointing out to the right.