You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*An introduction to debugging PHP code with phpdbg*
4
4
5
5
phpdbg provides an interactive environment to debug PHP; it is implemented and distributed as a SAPI module - just as the CLI interface.
6
6
7
7

8
8
9
-
phpdbg integrates with, and initializes the Zend environment; from the moment the console is open you can start to manipulate the environment in order to prepare your debugging session. phpdbg may feel familiar to other debuggers, but now is a good time to ask for help:
9
+
phpdbg integrates with, and initializes, the Zend environment; from the moment the console is open you can start to manipulate the environment in order to prepare your debugging session. If you have used other debuggers, phpdbg should hopefully feel familiar, but you can always ask for `help`:
10
10
11
11

12
12
13
-
phpdbg provides detailed help for all of the supported commands (that are not really obvious).
13
+
phpdbg provides help for all of the supported commands.
14
14
15
-
Breaking Execution
15
+
Breaking execution
16
16
==================
17
17
*Telling phpdbg when to stop ...*
18
18
19
-
In order to debug your code, execution must be interrupted at a very specific points during execution, and allow access to, and inspection of, the execution environment. For extreme circumstances, and geeks (me included), phpdbg can step through the execution of your script, showing you information about every opcode the vm executes, including the address (in case you need to break at that specific point on the next execution).
19
+
In order to debug your code, execution must be interrupted at very specific points during execution, and allow access to, and inspection of, the execution environment. phpdbg can step through the execution of your script, showing you information about every opcode the VM executes, including the address (in case you need to break at that specific point on the next execution).
20
20
21
-
phpdbg provides many options for specifying breakpoints, as illustrated by a screenshot of the help menu for the break command:
21
+
phpdbg provides many options for specifying breakpoints:
22
22
23
23

24
24
25
-
In those cases where you wish to program your breakpoints in userland, phpdbg includes a userland API, in the shape of two simple functions:
25
+
phpdbg also includes a userland API to enable working with breakpoints from within your PHP code:
26
26
27
27
```php
28
28
/**
@@ -41,17 +41,17 @@ proto void phpdbg_break(void);
41
41
proto void phpdbg_clear(void);
42
42
```
43
43
44
-
Inspecting the Environment
44
+
Inspecting the environment
45
45
==========================
46
46
*Finding out what went wrong*
47
47
48
-
When a breakpoint is reached, control is passed back to the phpdbg console (you!), execution will not continue until the *next* command is issued, a breakpoint being reached looks something like:
48
+
When a breakpoint is reached, control is passed back to the phpdbg console, execution will not continue until the *next* command is issued, a breakpoint being reached looks something like:
Now is the time to get down to some serious evil(), er, I mean eval()
52
+
Now is the time to get down to some serious `evil()`, er, I mean `eval()`.
53
53
54
-
Direct access to eval allows you to change _anything_ at _any_ time during execution. Helpful printing and listing commands help you to make sense of addresses and remind you of the names of the variables you want to var_dump !!
54
+
Direct access to `eval()` allows you to change _anything_ at _any_ time during execution. Helpful printing and listing commands help you to make sense of addresses and remind you of the names of the variables you want to `var_dump()`!
55
55
56
56
Library code for this section:
57
57
@@ -67,37 +67,38 @@ class phpdbg {
67
67
68
68
$dbg = new phpdbg();
69
69
70
-
var_dump(
71
-
$dbg->isGreat("PHP Rocks !!"));
70
+
var_dump($dbg->isGreat("PHP Rocks !!"));
72
71
?>
73
72
```
74
73
75
-
Being Precise
74
+
Being precise
76
75
=============
77
76
*Don't be sloppy, ever ... true story*
78
77
79
-
Actually the ability to break at function entry, or even on a single statement, is not always exact enough. A single statement may be many opcodes, and it could be any of those instructions that are ruining your day. So, phpdbg allows you to specify an exact opcode address, and provides the ability to view the instructions of any method or function before execution occurs.
78
+
The ability to break at function entry, or even on a single statement, is not always exact enough. A single statement may have many opcodes and it could be any of those instructions that are ruining your day. phpdbg allows you to specify an exact opcode address and provides the ability to view the instructions of any method or function before execution occurs.
80
79
81
-
Looking up addresses is made easy by the *print* command
80
+
Looking up addresses is made easy by the `print` command
For simple scripts, like the library code in the last section, and times when you want as much verboseness as possible, the following might be an option:
84
+
For simple scripts, like the library code in the last section, and times when you want as much detail as possible, the `quiet` flag can be changed to `0` (default is `1`):
Mocking a specific environment is childs play, simply include a bootstrap file before you run, or have your code include it, an example of such a file can be found in the repository:
92
+
Mocking a specific environment is child's play; simply include a bootstrap file before you run, or have your code include it.
93
+
94
+
An example of such a file can be found in the repository:
0 commit comments