2 ------------------- Getting Started with Debugger -------------------
9 All built-in debugger commands are un-ambiguous with their first
10 letters. Therefore, a single letter is sufficient to issue the command.
14 Use TAB to auto-complete.
18 For single line of PHP code, use "=" to print an expression's value, OR,
19 use "@" to execute an expression or statement without printing return
20 values, OR, start an assignment with "$" variable name.
22 For multi-line PHP code, type "<" then TAB. Now you can type or paste
23 multiple lines of code. Hit return to start a new line, then TAB. That
24 will auto-complete "?>" to finish the block. Hit return to execute.
28 Use "help" to read more about command details.
32 Use "info" and "list" commands to read more about source code.
36 Debugger is written with readline library, which has rich feature set,
37 including switching between emacs and vi editing mode. Please read its
38 [[ http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC1 |
39 documentation]] for more details.
42 2. Debugging local script
44 The command to run a script normally looks like this,
48 Simply add "-m debug" to run the script in debugger,
50 hhvm -m debug myscript.php
52 Once started, set breakpoints like this,
54 hphpd> break myscript.php:10
57 Then let it run, until it hits the breakpoints,
61 The debugger will highlight current statement or expression that is just
62 about to evaluate. Sometimes a statement is highlighted first, then
63 sub-expressions inside the statement are highlighted one after another
64 while repeating step commands.
66 At any breakpoints, examine variables or evaluate expressions,
71 hphpd> <?hh print $a; ?>
76 Optionally, modify variables like this,
79 hphpd> <?hh $a = 10; ?>
84 Then let it continue, until it hits more breakpoints,
88 Finally, quit debugger,
95 Connect to an HPHP server from command line,
97 hhvm -m debug -h mymachine.com
99 Or, connect from within debugger,
101 hphpd> machine connect mymachine.com
103 This will try to attach to a default sandbox on that machine.
104 "Attaching" means it will only debug web requests hitting that sandbox.
105 To switch to a different sandbox,
107 mymachine> machine list
108 mymachine> machine attach 2
110 In remote debugging mode, a breakpoint can be specific about an URL,
112 mymachine> break myscript.php:10@index.php
113 mymachine> break foo()@index.php
115 You may connect to more than one machine and breakpoints will be shared
119 4. Understanding dummy sandbox
121 When a web request hits a breakpoint, debugger will run in a "Web
122 Request" thread. Use "thread" command to display this information,
126 What will debugger use when there is no web request thread that's
127 active, but we need to set a breakpoint? We created so-called "dummy
128 sandbox", purely for taking debugger commands when there is no active
129 web request. When there is no active request, hit Ctrl-C to break into
130 the debugger, and use "thread" to display dummy sandbox thread's
136 In dummy sandbox, a PHP file can be pre-loaded, so that we can "info"
137 functions and classes and execute certain code. This file is specified
140 Eval.Debugger.StartupDocument = scripts/startup.php
142 Dummy sandbox will always use currently attached sandbox's PHP files.
143 When files are modified, simply reload them by
149 5. Colors and Configuration
151 By default, it will use emacs colors for dark background. To change
152 them, run debugger at least once, then look for ~/.hphpd.ini file.
153 Replace "Code" node with,
156 Code : Color.Palette.vim
159 Or, specify your own colors in different places of the configuration