Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Xdebug on a docker container? #183

Open
MegaJ opened this issue Dec 18, 2024 · 1 comment
Open

PHP Xdebug on a docker container? #183

MegaJ opened this issue Dec 18, 2024 · 1 comment

Comments

@MegaJ
Copy link

MegaJ commented Dec 18, 2024

Hi, I really like this package! I used your config for local php debugging and it works great. I really appreciate all your work svannte!

Now I'm trying to get php debugging working through a docker container. I saw your notes on prefix-local and prefix-remote. But maybe I'm not using it right?

tl;dr somehow xdebug is looking for the breakpoint on my host environment, rather than inside the docker container; can't find it, so even though the connection is made, no breakpoints trigger.

I have the setup working through vscodium, and I have it alllmosttt working in dape. The issue appears that the path mapping between the docker container and my local directory's source code isn't working. For this setup, the container and my source code are on the same physical machine.

If there's more info I can provide that would help let me know. If you want a minimally reproducible config with a docker setup, that might take me some time but I can do it.

What I've tried

I looked at #127 #36 #23 for clues. I've looked at the dape events for jsonrpc output, and to my knowledge, I'm setting the config correctly and passing in pathMappings with the correct properties.

xdebug.ini

It's loaded and working on the container.

zend_extension=xdebug
[xdebug]
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.client_port=9003
xdebug.log="/tmp/xdebug.log"
xdebug.client_host=172.17.0.1 # for linux boxes, mac/windows use host.docker.internal

Breakpoints snag in vscodium with this config

This is a config in the launch.json

{
  "name": "Listen for Xdebug",
  "type": "php",
  "request": "launch",
  "port": 9003,
  "log": true,
  "pathMappings": {
    "/var/www/html/" : "${workspaceFolder}"
  }
},

Xdebug logs this, without error:

[20] [Step Debug] <- breakpoint_set -i 9 -t line -f file:///var/www/html/hello.php -n 25

The dape config

(add-to-list
   'dape-configs
   `(x44
     modes (php-mode php-ts-mode)
     command "node"
     command-args (,(expand-file-name "~/.emacs.d/debug-adapters/php-debug/extension/out/phpDebug.js"))
     prefix-local  ,(expand-file-name "~/src/php-proj/")
     prefix-remote "/var/www/html/"
     :request "launch"
     :type "php"
     ;; :localSourceRoot ,(expand-file-name "~/src/php-proj/")
     ;; :serverSourceRoot "/var/www/http/"
     ;; :
     :port 9003
     ;; :localfs t
     :pathMappings (:/var/www/http ,(expand-file-name "~/src/php-proj"))
     ))

Xdebug logs this, but the debugger somehow isn't realizing that it should use /var/www/http to look up its own files

[27] [Step Debug] <- breakpoint_set -i 6 -t line -f file:///home/box/src/hello.php -n 31
[27] [Step Debug] WARN: Breakpoint file name does not exist: /home/box/src/hello.php (No such file or directory).

one of the initial jsonrpc message logs looks roughly similar to the config in the launch.json:

{
  "type": "request",
  "seq": 2,
  "command": "launch",
  "arguments": {
    "request": "launch",
    "type": "php",
    "localSourceRoot": "/home/box/src/php-proj/",
    "serverSourceRoot": "/var/www/http/",
    "port": 9003,
    "workspaceFolder": "/home/box/src/php-proj/",
    "pathMappings": {
      "/var/www/http/": "/home/box/src/php-proj/"
    }
  }
}

Not sure where to debug further. Would love to know if someone else has got this working.

@svaante
Copy link
Owner

svaante commented Dec 23, 2024

Hey, Im glad that you enjoy dape.

There is two ways of doing it, ether let vscode-php-debug run on the local machine or remote.

On the local machine:
Run adapter: xdebug command-cwd "~/" prefix-local "/docker:my-docker-container:"

  • command-cwd "~/" Make sure that xdebug node adapter starts on local machine
  • prefix-local "/docker:my-docker-container:" Substitutes the docker prefix in emacs paths with ""

Dape has some capabilities to automatically add prefix-local with dape-default-config-functions but it does so if command-cwd is remote, which it is not. Therefore we need to do it manually.

This is probably always what the user want 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants