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

Support Xdebug #314

Open
danielbachhuber opened this issue May 12, 2023 · 9 comments
Open

Support Xdebug #314

danielbachhuber opened this issue May 12, 2023 · 9 comments

Comments

@danielbachhuber
Copy link
Member

Xdebug is a common developer tool. It would be nice to (optionally) support it.

Done is:

  • It's possible to use Xdebug with wp-now.
@adamziel
Copy link
Collaborator

There's a decent chance XDebug would just work if PHP was built with the right flags. Anyone keen to give it a try?

@ibrokemycomputer
Copy link

@adamziel I'd love to give this a go, but due to my full-time job it might be a slow process.

However... "boss man" has been wanting us to start supporting WP projects since we've become so heavily invested in the CMS for our agency clients. So, we'll see.

A couple of things stand out right off the bat:

  • Depending on PHP version, the XDebug version needs to be either < || >= v3.
  • While we can follow the basic/common flags, it might be tricky to account for all use cases if it cant be customized via a user-supplied/project-specific config

@ibrokemycomputer
Copy link

@adamziel Actually, I take that back. It seems like consideration for this is tied to Issue WordPress/playground-tools#28

@adamziel
Copy link
Collaborator

@ibrokemycomputer actually XDebug support would be fantastic regardless of WordPress/playground-tools#28. You are the most welcome to give it a go!

It would require updating the Dockerfile which builds PHP - you will notice some PHP version-dependent behaviors are already in there.

As for config flags, Playground’s php-wasm supports setting php.ini flags so that would only be a matter of supporting custom php.ini in wp-now.

@adamziel adamziel changed the title Local Environment: Support Xdebug Support Xdebug May 31, 2023
@adamziel adamziel added [Type] Enhancement New feature or request and removed Local Environment labels Jun 1, 2023
@adamziel adamziel mentioned this issue Oct 4, 2023
10 tasks
@adamziel
Copy link
Collaborator

adamziel commented Oct 9, 2023

I was able to build xdebug extension to wasm:

$ git clone https://github.com/xdebug/xdebug.git
$ phpize
$ emconfigure ./configure
$ emmake make all
$ wasm2wat .libs/xdebug.so
// legit wat output

I had to patch the signature of these two functions and remove the final int from it:

  • xdebug_trace_flamegraph_function_exit
  • xdebug_trace_flamegraph_function_entry

I then tried to load it in @php-wasm/cli and got an error:

$ npx @php-wasm/cli -z ./.libs/xdebug.so
RuntimeError: Aborted(To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking). Build with -sASSERTIONS for more info.

I looked for some answers on the dynamic linking page, but didn't find any.

Emscripten changelogs suggest dlopen is available for modules compiled with the -sMAIN_MODULE flag.

Edit: I used the -sMAIN_MODULE flag and now PHP isn't crashing anymore. Yay! It still doesn't load the extension, but the error is now different:

Failed loading .libs/xdebug.so:  (null)

@adamziel
Copy link
Collaborator

adamziel commented Oct 10, 2023

I've built a minimal dlopen() example that works with Emscripten:

https://gist.github.com/adamziel/9c7d3302407294e12d9c1d1eaa54cdba

So it can work, yay! The key is indeed building with -sMAIN_MODULE.

The question now becomes: What goes wrong when we use it with PHP?

@adamziel
Copy link
Collaborator

Other than step-debugger, XDebug seems to be working in #831.

Anyone following this issue – would you rather get such a limited version of XDebug early and the step-by-step debugger support in one of the next iterations? Or is that step-by-step debugging the sole reason you're interested in XDebug?

@alexstandiford
Copy link

For me, step debugging is a pretty key component in that, but just having formatted var_dump would be a pretty big win, in my opinion.

I don't see any reason to hold off until it's all included, personally.

@adamziel
Copy link
Collaborator

adamziel commented Jan 11, 2024

Perfect! Let's not block the XDebug PR on the step debugger support. I can't promise any timeline, but the next step here is cleaning up and merging that PR 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Status: No status
Development

No branches or pull requests

4 participants