Debugging PHP applications with HHVMIn the previous parts of this series we got you started with HHVM and showed how we could get the symfony standard edition running on HHVM. This time we will dive deeper into HHVM by using it to debug our application. For most people the easiest way of debugging a PHP application is to place
In this blog post we'll show you how to debug your PHP application using HHVM. We describe how you can step through your program, set and manage your breakpoints, how to inspect variables and take a peek at helpful features like conditional breakpoints.
A faulty programLet's start off by creating a "faulty" program we can debug. Create a simple
script and save it as
Running this example with Firing up the debuggerStart with running hhvm in debug mode using the following command:
HHVM starts and loads the program, but does not execute it yet. HHVM is waiting
for a command. Run the example by giving the Stepping through the programA first approach to debugging this program would be to walk through each step
of the execution. With You may have noticed that the debugger did not step into the divide() function.
To check out what is going on in divide(), we can use the The counterpart of Our first breakpointStepping through an entire program by hand is a bit cumbersome. In fact we want
HHVM to pause the script when it enters the divide() function. This can be done
by setting a breakpoint. A breakpoint is an intentional stop or pause placed in
a program. In HHVM we set a breakpoint with the
This will set a new breakpoint when HHVM enters the divide function. Start the
program again with the To continue the execution give the Other possibilities for setting breakpoints include:
Inspecting variablesWhen our program hits a breakpoint and pauses execution, we can inspect the
value of all variables in the current scope by using the
Continue ( Conditional breakpointsNow we know what causes the problem, we have to find out where In this case divide() is called only two times, but imagine a situation where
this function is called 1337 times. You definitely don't want to inspect and
continue that many times to find a situation where A conditional breakpoint only breaks the program when a certain condition is
met. The syntax in hhvm is In our case we're interested in the situation where
Then set a conditional breakpoint with:
Run the program and notice that HHVM doesn't break until Getting a traceNow we have found a point in our program where HHVM gives you a stack trace of the current breakpoint when you use the Managing breakpointsIf we place a lot of breakpoints we can lose track of all the breakpoints we
have set. HHVM provides a list of all breakpoints with the All breakpoints are given a number (e.g. 1), making it possible to remove a
breakpoint (
For a complete overview of all the possibilities use the Wrap upIn this post we've introduced you to debugging with HHVM. In the next blog post we'll move from debugging a cli program to debugging web requests! The HHVM debugger has been quite solid for us so far. The only improvement we could come up for now would be vim integration! |
|