-
Notifications
You must be signed in to change notification settings - Fork 350
[ php-wasm ] Add xdebug
dynamic extension to @php-wasm/node JSPI
#2248
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
Merged
adamziel
merged 46 commits into
WordPress:trunk
from
mho22:add-xdebug-support-to-php-wasm-node-jspi
Jul 2, 2025
Merged
Changes from 19 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
0136d51
Added -fPIC to libintl
mho22 f6f6a97
Set php-wasm as a main module and enable dynamic linking
mho22 990f945
Implement XDebug as zend extension, compile and build
mho22 aa63703
Remove artifacts
mho22 8e87691
Correct merge conflicts
mho22 6f82103
Build xdebug with nx command and PHP_VERSION arg
mho22 fcfebd3
Add a withXdebug option in loadNodeRuntime
mho22 6c14976
Create separate file for supported php versions
mho22 f0e2d7c
Add proper ini entries and mount current working directory in with-xd…
mho22 77ddbda
Compile all php-wasm and xdebug extensions
mho22 460c878
Prevent Xdebug to be loaded in Asyncify
mho22 29520ea
Add tests
mho22 549f04f
Remove socket connection error and recompile php
mho22 c6411e4
Correct conflicts
mho22 491d0bb
Correct lint errors and add tests to CI
mho22 b3cc02c
Added temporary new job test-unit-jspi
mho22 fefc94c
Add last test on DBGP communication
mho22 ffcf2c4
Correct conflicts
mho22 c382bef
Correct errors and clean unused code
mho22 e19f292
Correct Errors and make improvements
mho22 bd0729c
Merge branch 'trunk' into add-xdebug-support-to-php-wasm-node-jspi
mho22 522a7ea
Add previous emscriptenOptions in new ones
mho22 ffe001f
Correct errors and implement modifications
mho22 2fe9bbe
Apply new filepath for built and unbuilt version
mho22 143c23c
Unbundle sqlite3 in PHP 7.3 and 7.2
mho22 a1eee4f
Document multiple processes like sqlite <7.4 and esbuild path replace…
mho22 63733cf
Implement an 'import-url' Vite plugin and an ESBuild plugin to handle…
mho22 f3fb08a
wrap zend_list_free Zend function to avoid function signature mismatc…
mho22 eccb56f
minor modifications
mho22 037a25b
Add comment and test for function signature mismatch
mho22 8e7b5c9
correct merge conflicts from trunk
mho22 dc7afb4
Merge branch 'trunk' into add-xdebug-support-to-php-wasm-node-jspi
mho22 1e66704
remove only from the unknown function signature mismatch test
mho22 654df4a
Recompile Asyncify PHP versions with aditional asyncify imports
mho22 02b80ed
Merge branch 'trunk' into add-xdebug-support-to-php-wasm-node-jspi
mho22 454e740
Try to solve failing checks
mho22 eec8621
add env variable in ci
mho22 afcfae0
experiment use of max_old_space_size with runner
mho22 82b6e58
add aftereach in tests which disposes PHP wasm runtime
mho22 3ffdd92
improve aftereach which disposes PHP wasm runtime
mho22 aa53bc3
improve aftereach which disposes PHP wasm runtime
mho22 e5e453b
add php-networking in ci jobs list
mho22 f4c2388
Tweak some timeouts to make the checks pass
mho22 7418095
Tweak some timeouts to make the checks pass
mho22 3763dbc
Tweak some timeouts to make the checks pass
mho22 57d15a6
Merge branch 'trunk' into add-xdebug-support-to-php-wasm-node-jspi
mho22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
# Passing extra flags breaks the version check | ||
if [[ "$@" == "-v" ]]; then | ||
export EMCC_FLAGS="" | ||
fi | ||
|
||
# Convert args to an array for filtering | ||
args=("${@}") | ||
|
||
# Remove flags that we do not want to pass to emcc | ||
if [[ -n "${EMCC_SKIP:-}" ]]; then | ||
for ((i=0; i < ${#args[@]}; i++)); do | ||
if [[ " ${EMCC_SKIP[*]} " =~ " ${args[$i]} " ]]; then | ||
unset 'args[i]' | ||
fi | ||
done | ||
fi | ||
|
||
# Remove duplicate library references to avoid linking errors. | ||
# Begin at end because we generally want dependencies to come last, | ||
# and if two things depend on a lib, we want the lib to come after both. | ||
declare -A seen_libs | ||
for ((i=${#args[@]} - 1; i >= 0; i--)); do | ||
# Skip empty args because array may be sparse | ||
[[ -z "${args[$i]:-}" ]] && continue | ||
|
||
arg=${args[i]} | ||
if ( | ||
[[ "$arg" =~ ^-l([a-z]|[A-Z]|[0-9]|[\-_])+$ ]] || | ||
[[ "$arg" =~ (^|/)lib([a-z]|[A-Z]|[0-9]|[\-_])+\.a$ ]] | ||
); then | ||
if [[ -v seen_libs["$arg"] ]]; then | ||
unset 'args[i]' | ||
else | ||
seen_libs["$arg"]=1 | ||
fi | ||
fi | ||
done | ||
|
||
/root/emsdk/upstream/emscripten/emcc2 "${args[@]}" ${EMCC_FLAGS:-} |
220 changes: 220 additions & 0 deletions
220
packages/php-wasm/compile/base-image/print-wasm-imports-and-exports.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
#include <stdio.h> | ||
mho22 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#define WASM_MAGIC 0x6D736100 | ||
#define WASM_VERSION 0x1 | ||
|
||
// Section IDs | ||
#define IMPORT_SECTION 2 | ||
#define EXPORT_SECTION 7 | ||
|
||
typedef struct { | ||
uint32_t magic; | ||
uint32_t version; | ||
} wasm_header_t; | ||
|
||
typedef struct { | ||
uint8_t id; | ||
uint32_t size; | ||
} section_header_t; | ||
|
||
// Read LEB128 encoded unsigned integer | ||
uint32_t read_leb128(FILE *fp) { | ||
uint32_t result = 0; | ||
uint32_t shift = 0; | ||
uint8_t byte; | ||
|
||
do { | ||
byte = fgetc(fp); | ||
result |= ((byte & 0x7f) << shift); | ||
shift += 7; | ||
} while (byte & 0x80); | ||
|
||
return result; | ||
} | ||
|
||
// Read string from wasm binary | ||
char* read_string(FILE *fp) { | ||
uint32_t len = read_leb128(fp); | ||
char *str = malloc(len + 1); | ||
fread(str, 1, len, fp); | ||
str[len] = '\0'; | ||
return str; | ||
} | ||
|
||
void parse_imports(FILE *fp) { | ||
uint32_t count = read_leb128(fp); | ||
printf("[\n"); | ||
|
||
for (uint32_t i = 0; i < count; i++) { | ||
char *module = read_string(fp); | ||
char *name = read_string(fp); | ||
uint8_t kind = fgetc(fp); | ||
|
||
printf(" {\n"); | ||
printf(" \"module\": \"%s\",\n", module); | ||
printf(" \"name\": \"%s\",\n", name); | ||
printf(" \"kind\": \"0x%02x\",\n", kind); | ||
|
||
// Parse import type based on kind | ||
switch(kind) { | ||
case 0x00: // Function | ||
printf(" \"type\": \"function\",\n"); | ||
printf(" \"typeIndex\": %d\n", read_leb128(fp)); | ||
break; | ||
case 0x01: { // Table | ||
printf(" \"type\": \"table\",\n"); | ||
// Skip table type but include in JSON | ||
uint8_t elemType = fgetc(fp); | ||
uint8_t flags = fgetc(fp); | ||
uint32_t initial = read_leb128(fp); | ||
printf(" \"elementType\": \"0x%02x\",\n", elemType); | ||
printf(" \"initial\": %d", initial); | ||
if (flags & 0x01) { | ||
uint32_t max = read_leb128(fp); | ||
printf(",\n \"maximum\": %d\n", max); | ||
} else { | ||
printf("\n"); | ||
} | ||
break; | ||
} | ||
case 0x02: { // Memory | ||
printf(" \"type\": \"memory\",\n"); | ||
uint8_t flags = fgetc(fp); | ||
uint32_t initial = read_leb128(fp); | ||
printf(" \"initial\": %d", initial); | ||
if (flags & 0x01) { | ||
uint32_t max = read_leb128(fp); | ||
printf(",\n \"maximum\": %d\n", max); | ||
} else { | ||
printf("\n"); | ||
} | ||
break; | ||
} | ||
case 0x03: { // Global | ||
printf(" \"type\": \"global\",\n"); | ||
uint8_t valueType = fgetc(fp); | ||
uint8_t mutability = fgetc(fp); | ||
printf(" \"valueType\": \"0x%02x\",\n", valueType); | ||
printf(" \"mutable\": %s\n", mutability ? "true" : "false"); | ||
break; | ||
} | ||
} | ||
|
||
free(module); | ||
free(name); | ||
|
||
if (i < count - 1) { | ||
printf(" },\n"); | ||
} else { | ||
printf(" }\n"); | ||
} | ||
} | ||
|
||
printf(" ]"); | ||
} | ||
|
||
void parse_exports(FILE *fp) { | ||
printf("[\n"); | ||
|
||
// Read number of exports | ||
uint32_t count = read_leb128(fp); | ||
|
||
for (uint32_t i = 0; i < count; i++) { | ||
// Read export name | ||
uint32_t name_len = read_leb128(fp); | ||
char* name = malloc(name_len + 1); | ||
fread(name, 1, name_len, fp); | ||
name[name_len] = '\0'; | ||
|
||
// Read export kind and index | ||
uint8_t kind = fgetc(fp); | ||
uint32_t index = read_leb128(fp); | ||
|
||
printf(" {\n"); | ||
printf(" \"name\": \"%s\",\n", name); | ||
printf(" \"kind\": %d,\n", kind); | ||
printf(" \"index\": %d\n", index); | ||
|
||
if (i < count - 1) { | ||
printf(" },\n"); | ||
} else { | ||
printf(" }\n"); | ||
} | ||
|
||
free(name); | ||
} | ||
|
||
printf(" ]"); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
if (argc != 2) { | ||
fprintf(stderr, "Usage: %s <wasm file>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
FILE *fp = fopen(argv[1], "rb"); | ||
if (!fp) { | ||
perror("Failed to open file"); | ||
return 1; | ||
} | ||
|
||
// Read and verify header | ||
wasm_header_t header; | ||
fread(&header, sizeof(header), 1, fp); | ||
|
||
if (header.magic != WASM_MAGIC || header.version != WASM_VERSION) { | ||
fprintf(stderr, "Invalid WASM file\n"); | ||
fclose(fp); | ||
return 1; | ||
} | ||
|
||
printf("{\n"); | ||
|
||
// Find imports and exports sections | ||
int found_imports = 0; | ||
int found_exports = 0; | ||
|
||
while (!feof(fp) && (!found_imports || !found_exports)) { | ||
section_header_t section; | ||
section.id = fgetc(fp); | ||
if (feof(fp)) break; | ||
|
||
section.size = read_leb128(fp); | ||
|
||
if (section.id == IMPORT_SECTION) { | ||
printf(" \"imports\": "); | ||
parse_imports(fp); | ||
found_imports = 1; | ||
if (!found_exports) { | ||
printf(","); | ||
} | ||
printf("\n"); | ||
} else if (section.id == EXPORT_SECTION) { | ||
printf(" \"exports\": "); | ||
parse_exports(fp); | ||
found_exports = 1; | ||
if (!found_imports) { | ||
printf(","); | ||
} | ||
printf("\n"); | ||
} else { | ||
// Skip other sections | ||
fseek(fp, section.size, SEEK_CUR); | ||
} | ||
} | ||
|
||
if (!found_imports) { | ||
printf(" \"imports\": []\n"); | ||
} | ||
if (!found_exports) { | ||
printf(" \"exports\": []\n"); | ||
} | ||
|
||
printf("}\n"); | ||
|
||
fclose(fp); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+5.05 MB
(220%)
packages/php-wasm/compile/libintl/jspi/dist/root/lib/lib/libicui18n.a
Binary file not shown.
Binary file modified
BIN
+96.8 KB
(290%)
packages/php-wasm/compile/libintl/jspi/dist/root/lib/lib/libicuio.a
Binary file not shown.
Binary file modified
BIN
+52.2 KB
(110%)
packages/php-wasm/compile/libintl/jspi/dist/root/lib/lib/libicutest.a
Binary file not shown.
Binary file modified
BIN
+516 KB
(220%)
packages/php-wasm/compile/libintl/jspi/dist/root/lib/lib/libicutu.a
Binary file not shown.
Binary file modified
BIN
+3.03 MB
(220%)
packages/php-wasm/compile/libintl/jspi/dist/root/lib/lib/libicuuc.a
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.