How to use Sdebug (Xdebug) to debug Swoole. Now PHP8 and Xdebug3 have been released. It’s certainly not an easy thing to do if you’re still compatible with Xdebug.

So @codingHuang, a member of the Swoole team, developed a new debugging extension called Yasd, another Swoole debugger.

Here’s a quick overview of what the debugger does:

  1. Debugging coroutines
  2. Breakpoint debugging
  3. Breakpoint cache
  4. View the call stack
  5. Step through
  6. .

Stay tuned for more features ~ including PHP8 support and integrated IDE support.

Here’s how to use the debugger:

Install the extension

Yasd extensions need to be installed first

phpize --clean && \
phpize && \
./configure && \
make clean && \
make && \
make install
Copy the code

Set up the php.ini file:

zend_extension=yasd.so
Copy the code

View extended information:

php --ri yasd
Copy the code

Start debugging

After the installation is successful, add the -e parameter when you need to debug, for example

php -e test.php
Copy the code

You’ll see something like this

$ php -e test.php
[Welcome to yasd, the Swoole debugger]
[You can set breakpoint now]
>
Copy the code

Available commands

Then you can use some commands for debugging, all commands support priority fuzzy matching, such as Li, lis, list are equal to L, indicating that the source code is viewed.

Check source code list

l
Copy the code

To set breakpoints

B The absolute path to the file requires the line number of the breakpointCopy the code

By default, breakpoint information is stored in the cache file.breakpoints_file.log.

You can also specify the file name by modifying php.ini, for example:

yasd.breakpoints_file=yasd.log
Copy the code

If the cache file exists, breakpoint information in the file will be automatically loaded when debugging is started.

Delete breakpoint delete breakpoint

D The line number of the absolute path breakpoint for the fileCopy the code

If the absolute file path is not specified when you set or delete a breakpoint, the default path is the current file.

Run run

r
Copy the code

Step over

n
Copy the code

When you encounter a function, you don’t go inside the function

Step into

s
Copy the code

When it encounters a function, it goes inside the function

Jump out of the current function finish

f
Copy the code

View the call stack

bt
Copy the code

View all breakpoint info

i
Copy the code

Continue running

c
Copy the code

Exit the quit

q
Copy the code

Print variable

p
Copy the code

Variable names do not need $, for example:

p a
p this
p this->prop
Copy the code

View the current coroutine level

le
Copy the code

Little details

  • Print breakpoint formatfilename:lineno

If you are debugging in the IDE, you can just click to jump to the corresponding file

  • Automatic caching of breakpoint information

By default, breakpoint information is stored in the cache file.breakpoints_file.log. If the cache file exists, breakpoint information in the file is automatically loaded when debugging is started.

  • Set breakpoints and delete breakpoints

If the absolute file path is not specified, the current file is used by default.

  • Automatic repeat command

If you do not enter a command and press Enter, the previous command is displayed by default

  • More details for you to find out