dev/vim/xdebug.md
2023-11-17 11:47:46 +02:00

122 lines
2.3 KiB
Markdown

# XDebug
- XDebug uses the DBGP protocol
## Install
```sh
dnf install php82-php-pecl-xdebug3
```
### Config
`/etc/php.d/90-xdebug.ini`
```ini
[XDebug]
zend_extension=/opt/remi/php82/root/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.mode=develop,gcstats,coverage,profile,debug
xdebug.client_host=localhost
xdebug.client_port=9003
xdebug.idekey="NVIM"
xdebug.log=/tmp/xdebug.log
xdebug.log_level = 7
; always initiate a debugging session
xdebug.start_with_request=yes
; activates if a "trigger" is present
;xdebug.start_with_request=trigger
```
`php -v`
```
PHP 8.2.12 (cli) (built: Oct 24 2023 19:22:16) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies
with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans
```
Show current settings
```sh
php -r 'xdebug_info();'
```
## Adapter
```sh
cd ~
git clone https://github.com/xdebug/vscode-php-debug.git
cd vscode-php-debug
npm install && npm run build
```
Debug adapter nvim plugin
`:MasonInstall php-debug-adapter`
Debug chrome plugin
(https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc)
to trigger debugger send the cookie `XDEBUG_SESSION=XDEBUG_ECLIPSE; Path=/; Expires=Sat, 27 Jul 2024 08:17:10 GMT;`
`.local/share/nvim/mason/packages/php-debug-adapter/extension/package.json`
```json
"port": {
"type": "number",
"description": "Port on which to listen for Xdebug",
"default": 9003
},
"php.debug.ideKey": {
"type": "string",
"default": "vsc",
"description": "A unique key that allows the proxy to match requests to your editor. Only used when proxy configuration includes replacement.",
"scope": "machine-overridable"
}
```
## Trigger
Xdebug will initiate a debug session in the presence of the XDEBUG_SESSION HTTP cookie.
You can pick any value for the cookie, unless xdebug.trigger_value is set.
A typical header looks like:
```
Cookie: XDEBUG_SESSION=start
```
To signal the debugger to initiate connections, Xdebug will look whether the XDEBUG_SESSION environment variable is present.
```
export XDEBUG_SESSION=1
```
Watch the logs
```sh
tail -f /tmp/xdebug.log
```
### Test
```sh
php --info
```
### debug
- port 9003 must not been blocked