Skip to content

[ xdebug ] Configure xdebug for PhpStorm compatibility#2747

Merged
adamziel merged 5 commits intotrunkfrom
configure-xdebug-for-phpstorm-compatibility
Oct 8, 2025
Merged

[ xdebug ] Configure xdebug for PhpStorm compatibility#2747
adamziel merged 5 commits intotrunkfrom
configure-xdebug-for-phpstorm-compatibility

Conversation

@mho22
Copy link
Collaborator

@mho22 mho22 commented Oct 7, 2025

Motivation for the change, related issues

This pull request aims to add and modify Xdebug related elements in order for Xdebug with PHP.wasm ASYNCIFY to run step debugging in PHPStorm without crashing.

Implementation details

  • Correction of two crashes with Error [RuntimeError]: unreachable by adding :
+ zend_observer_fcall_end_prechecked
+ zend_throw_exception_object
  • Correction of one crash with Error [RuntimeError]: null function or function signature mismatch by removing :
- 'xdebug.start_upon_error=yes'

That setting was not necessary after all :

Initialize a debugging session when a PHP Notice or Warning is emitted, or when a Throwable is thrown.

  • Some refactoring to maintain consistency across build.js files

@mho22 mho22 changed the title Configure xdebug for phpstorm compatibility [ xdebug ] Configure xdebug for phpstorm compatibility Oct 7, 2025
@mho22 mho22 mentioned this pull request Oct 7, 2025
18 tasks
@mho22
Copy link
Collaborator Author

mho22 commented Oct 7, 2025

I will need to rebuild every version of PHP.wasm Node JSPI and ASYNCIFY.

@mho22 mho22 force-pushed the configure-xdebug-for-phpstorm-compatibility branch from a39fd0c to 75aa9e5 Compare October 7, 2025 22:00
@mho22 mho22 marked this pull request as ready for review October 7, 2025 22:35
@mho22 mho22 marked this pull request as draft October 7, 2025 22:35
@mho22 mho22 requested a review from adamziel October 8, 2025 00:04
@mho22 mho22 marked this pull request as ready for review October 8, 2025 07:40
@adamziel
Copy link
Collaborator

adamziel commented Oct 8, 2025

For the record : It is currently not possible to use Xdebug with PHP.wasm in JSPI mode in PHPStorm since it asks for invoke_iiii when debugging server is on. It returns the following error :

I was curious what other exports we might be missing so I've inspected xdebug.so with wasm2wat and got these imports:

> wasm2wat packages/php-wasm /node/jspi/extensions/xdebug/8_4/xdebug.so | grep '(import' | grep '"env"' | awk '{print $3}' | sort | tee xdebug-imports.txt
  (import "env" "zend_get_module_version" (func (;0;) (type 2)))
  (import "env" "zend_register_ini_entries_ex" (func (;1;) (type 4)))
  (import "env" "zend_error" (func (;2;) (type 5)))
  (import "env" "getenv" (func (;3;) (type 2)))
  (import "env" "strchr" (func (;4;) (type 3)))
...200 lines...

(I am only keeping the imports coming from "env" as that's the one that are not shipped with xdebug itself).

Then I got the list of exports from PHP 8.4 JSPI:

$ wasm2wat --enable-all packages/php-wasm/node/jspi/8_4_13/php_8_4.wasm | grep '(export'  | awk '{print $2}' | sort | tee php-exports.txt 
  (export "__wasm_call_ctors" (func $__wasm_call_ctors))
  (export "php_time" (func $php_time))
  (export "gettimeofday" (func $__gettimeofday))
  (export "time" (func $__time))
  (export "php_date_get_date_ce" (func $php_date_get_date_ce))
  (export "php_date_get_immutable_ce" (func $php_date_get_immutable_ce))
  (export "php_date_get_interface_ce" (func $php_date_get_interface_ce))
  (export "php_date_get_timezone_ce" (func $php_date_get_timezone_ce))
...20k lines...

Then I computed a list of "env" xdebug imports that don't have a corresponding env export:

$  grep -v -f php-exports.txt xdebug-imports.txt
"__indirect_function_table"
"__memory_base"
"__stack_pointer"
"__table_base"
"emscripten_longjmp"
"exit"
"getaddrinfo"
"invoke_ii"
"invoke_iiii"
"invoke_iiiiii"
"invoke_v"
"memory"
"wasm_recv"
"wasm_setsockopt"

It seems like "wasm_setsockopt", "wasm_recv", etc. are taken care of by the runtime – since we're able to connect to XDebug. That leaves us with a bunch of invoke_* calls.

@adamziel
Copy link
Collaborator

adamziel commented Oct 8, 2025

It seems we're building XDebug without -sSUPPORT_LONGJMP=wasm -fwasm-exceptions which is why it relies on invoke_* calls. Did we try using those build options there?

@adamziel
Copy link
Collaborator

adamziel commented Oct 8, 2025

I've added those flags and the build seems to have worked, let me try it in phpstorm 🤞

@adamziel
Copy link
Collaborator

adamziel commented Oct 8, 2025

It worked! I'll rebuild all JSPI extensions

@mho22
Copy link
Collaborator Author

mho22 commented Oct 8, 2025

This is fantastic! I should have thought of that. Thank you @adamziel. Do you think this can be considered ready to be merged?

@adamziel adamziel merged commit 8ae1ac7 into trunk Oct 8, 2025
28 checks passed
@adamziel adamziel deleted the configure-xdebug-for-phpstorm-compatibility branch October 8, 2025 21:46
@adamziel
Copy link
Collaborator

adamziel commented Oct 8, 2025

🚢

@mho22 mho22 changed the title [ xdebug ] Configure xdebug for phpstorm compatibility [ xdebug ] Configure xdebug for PhpStorm compatibility Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants