Commit ec1ed3a
authored
[XDebug Bridge] Load files in Devtools before running PHP with Xdebug enabled (#2527)
## Motivation for the change, related issues
Based on the following pull request :
- #2442
The first approach was to load Devtools when running a file with Xdebug
enabled PHP.wasm. Unfortunately, the user experience was not great. e.g.
files were loaded only when executed.
The new approach opens de Devtools Source panel with the relevant loaded
files ready to be manipulated.
Once the breakpoints are set, the PHP file can be executed and paused
with Xdebug enabled PHP.wasm.
## Implementation details
- DevTools Sources Opening : Devtools Source panel is automatically
opened when bridge starts.
- Console Instructions : A startup message guides users on how to debug
with the bridge.
- Source File Loading : Relevant PHP files are preloaded in DevTools for
inspection and breakpoints.
- Pending Breakpoints : Breakpoints set before Xdebug init are applied
once the session starts.
- URI Normalization : Paths are consistently mapped between Bridge, CDP,
and DBGP.
- CDP Command Buffer : CDP requests are buffered until the bridge is
fully initialized.
- `breakOnFirstLine` Option : Allows breaking on the first executed line
when no breakpoints exist.
- Test Coverage
## Testing Instructions with Xdebug Bridge
1. Run the devtools
```
npx xdebug-bridge
```
2. Connect to the devtools
```
Starting XDebug Bridge...
Connect Chrome DevTools to CDP at:
devtools://devtools/bundled/inspector.html?ws=localhost:9229
```
3. Set a breakpoint in a file
<img width="1920" height="656" alt="screenshot-001"
src="https://github.com/user-attachments/assets/3591ea63-7344-4a53-98ee-6ff70440dbaf"
/>
4. Run the PHP script with PHP.wasm CLI and Xdebug option
```
npx php-wasm-cli test.php --xdebug
```
<img width="1920" height="651" alt="screenshot-002"
src="https://github.com/user-attachments/assets/e5c9049d-c556-41b3-b99c-a9a2000f5da4"
/>
5. Resume script execution and repeat step 4 indefinitely
<img width="1919" height="667" alt="screenshot-003"
src="https://github.com/user-attachments/assets/aacfaf3d-0afb-497e-b5cd-8d3eb0ce98de"
/>
## Testing Instructions with PHP.wasm CLI
1. Run the script with Xdebug and Devtools options
```
npx php-wasm-cli test.php --experimental-devtools --xdebug
```
2. Connect to the devtools
```
Starting XDebug Bridge...
Connect Chrome DevTools to CDP at:
devtools://devtools/bundled/inspector.html?ws=localhost:9229
```
3. It will pause on the first breakable PHP code
<img width="1920" height="651" alt="screenshot-002"
src="https://github.com/user-attachments/assets/e5c9049d-c556-41b3-b99c-a9a2000f5da4"
/>
## Testing Instructions with PHP.wasm Node
1. Write the following script
```
import { PHP } from '@php-wasm/universal';
import { loadNodeRuntime } from '@php-wasm/node';
import { startBridge } from '@php-wasm/xdebug-bridge';
const php = new PHP(await loadNodeRuntime('8.4', {withXdebug: true}));
const bridge = await startBridge({phpInstance: php, breakOnFirstLine: true});
bridge.start();
await php.runStream({scriptPath: `test.php`});
```
1. Run the script with Node
```
node script.js
```
3. Connect to the devtools
```
Starting XDebug Bridge...
Connect Chrome DevTools to CDP at:
devtools://devtools/bundled/inspector.html?ws=localhost:9229
```
4. It will pause on the first breakable PHP code
<img width="1920" height="651" alt="screenshot-002"
src="https://github.com/user-attachments/assets/e5c9049d-c556-41b3-b99c-a9a2000f5da4"
/>
## Testing Instructions in `wordpress-playground`
1. Run the devtools
```
nx reset && nx run php-wasm-xdebug-bridge:dev --php-root /absolute/path/to/the/debuggable/directory
```
2. Connect to the devtools
```
Starting XDebug Bridge...
Connect Chrome DevTools to CDP at:
devtools://devtools/bundled/inspector.html?ws=localhost:9229
```
3. Set a breakpoint in a file
<img width="1920" height="656" alt="screenshot-001"
src="https://github.com/user-attachments/assets/3591ea63-7344-4a53-98ee-6ff70440dbaf"
/>
5. Run the PHP script
```
nx reset && nx run php-wasm-cli:dev /absolute/path/to/the/debuggable/directory/file.php --xdebug
```
<img width="1920" height="651" alt="screenshot-002"
src="https://github.com/user-attachments/assets/e5c9049d-c556-41b3-b99c-a9a2000f5da4"
/>
6. Resume script execution and repeat step 4 indefinitely
<img width="1919" height="667" alt="screenshot-003"
src="https://github.com/user-attachments/assets/aacfaf3d-0afb-497e-b5cd-8d3eb0ce98de"
/>1 parent 65029ca commit ec1ed3a
File tree
12 files changed
+316
-197
lines changed- packages/php-wasm
- cli/src
- xdebug-bridge
- src
- lib
- tests
12 files changed
+316
-197
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | 65 | | |
68 | 66 | | |
| 67 | + | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
| |||
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | | - | |
| 76 | + | |
78 | 77 | | |
79 | 78 | | |
80 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
41 | 68 | | |
42 | 69 | | |
43 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
| 16 | + | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 67 | + | |
75 | 68 | | |
76 | 69 | | |
77 | 70 | | |
78 | 71 | | |
79 | | - | |
80 | | - | |
| 72 | + | |
81 | 73 | | |
| 74 | + | |
82 | 75 | | |
83 | 76 | | |
0 commit comments