SL / EN

Setting up Xdebug in Emacs

Table of Contents

Reasoning

I believe not having set Debugging is the main reason I don't use Emacs professionally. Working with Drupal PHPStorm by JetBrains seems like an industry standard. I've got Emacs keybinding enabled but that's far from where I'd like to be and the main reason for the use of Emacs is ideological - I don't want to use proprietary software that I don't have control over.

One of the things that kept me from setting up Xdebug in Emacs was the number of solutions provided and a necessity to pick one. There's to much to choose from and this gives me an anxiety, since every time you make a decision you also have to make a time investment to set it up and learn the usage.

Here are the options:

project state last commit notes
Geben Minimally maintained 3 years ago  
RealGUD Xdebug   4 years ago Parent repo is active
dap-mode very active    
dape very active   Diff with dap-mode.

dap-mode

Spacemacs' PHP layer suggests either geben or dap-mode. The former is minimally maintained which crosses it out. The later was covered by Systemcrafters which is another reason to try it out.

Setting up

Install two new layers in Spacemacs: LSP, DAP (alongside with pre-enabled PHP).

  • Main information I got from PHP layer (Debugging section)
    • Run M-x dap-php-setup in .php file
    • SPC m d b a Set up a breakpoint
    • SPC m d d d Select a debug template
    • php -d xdebug.idekey=PHPSTORM -d xdebug.start_with_request=yes -d xdebug.mode=debug -d xdebug.client_host=127.0.0.1 -d xdebug.client_port=9000 bin/phpunit ./path/to/Test.php
  • DAP mode configuration docs for PHP

Problems

Warning (emacs): Initialize request failed: listen EADDRINUSE: address already in use :::9003

$ sudo lsof -i -P -n | grep LISTEN
node      809510    lio   18u  IPv6 10160118      0t0  TCP *:9003 (LISTEN)

almost Wasn't able to set it up.

I started looking into dape, but one last time I checked my local php configuration and set up the xdebug properly there (I also had to switch php version because I did not use the most recent one for some testing I did a while ago sudo update-alternatives --set php /usr/bin/php8.3).

Now I'm getting the stops on breakpoints.

Next steps

  • Check if console is available

Date: 2025-01-05 Sun 00:00

Emacs 30.0.92 (Org mode 9.7.11)