Chapter 9. hphpd: Interactive Debugging
HHVM comes with an interactive debugger called hphpd. In case you’re not familiar with the concept, an interactive debugger is a program that lets you control other programs, and inspect their state. You can set it to pause the controlled program at certain points (e.g., when execution enters a specific function, or reaches a specific line of code). You can look at the values of variables during execution and, in some cases, modify them. Interactive debuggers are powerful tools, and they can drastically increase the ease and efficiency of debugging a large, complex program, as compared to the trial-and-error workflow of printf
-debugging.
hphpd is also a read-eval-print loop (REPL) for PHP and Hack. You can interactively type in PHP and Hack code, in the context of your codebase (so you can use your library functions and so on), to try out small pieces of code.
If you’ve used other interactive debuggers like GDB or LLDB, you’ll find hphpd quite familiar. In fact, you may not even need to read this chapter; you can probably get started just using hphpd’s interactive help command, help
.
In this chapter, we’ll see how to use hphpd to debug scripts and web apps, how to configure it, and how to get the most out of it.
Getting Started
Start hphpd by typing hhvm -m debug
at a shell command line. Instead of executing any code, HHVM will display a welcome message and drop into the debugger prompt:
$ hhvm -m debug Welcome to HipHop Debugger! Type ...
Get Hack and HHVM now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.