[ xdebug ] Map paths and skip paths with Xdebug 3.5#3115
[ xdebug ] Map paths and skip paths with Xdebug 3.5#3115brandonpayton merged 9 commits intotrunkfrom
Conversation
|
One issue I am facing while trying PHP 8.5 with Xdebug 3.5 is based on an if statement inside Xdebug's maps.c file on line /* For CLI scripts, only scan the current directory for map files */
if (strcmp(script_source, "Standard input code") == 0) {
size_t length;
char *current_directory = virtual_getcwd_ex(&length);
if (scan_directory_exists(current_directory)) {
scan_directory(current_directory);
}
efree(current_directory);
return;
}This is my script : import { PHP, __private__dont__use } from '@php-wasm/universal';
import { loadNodeRuntime } from '@php-wasm/node';
import fs from 'fs';
import { FSHelpers } from '@php-wasm/universal';
const php = new PHP(await loadNodeRuntime('8.5', { withXdebug: true }));
// php.mkdir( '/php/.xdebug' );
// php.writeFile( '/php/.xdebug/paths.map', "/internal/shared/ = SKIP\n./php/bar.php = SKIP\n./baz/ = SKIP\n" );
php.mkdir( '/.xdebug' );
php.writeFile( '/.xdebug/paths.map', "/internal/shared/ = SKIP\n./php/bar.php = SKIP\n./baz/ = SKIP\n" );
FSHelpers.copyRecursive( php[__private__dont__use].FS, `${process.cwd()}/php`, '/php' );
await php.runStream({ scriptPath: `/php/xdebug.php` });
fs.writeFileSync( 'xdebug.log', php.readFileAsText( '/tmp/xdebug.log' ) );Even if I use a script path with an existing file path |
|
I was wrong earlier and I discovered a possible issue to fix in Xdebug 3.5. The code it crosses is the following : These variables are responsible of finding the But it seems to be problematically related to the root directory. Explanation : If my current debugging directory is Ok. Now : If my current debugging directory is While - current_dir = parts->c > 2 ? xdebug_join(slash, parts, 0, parts->c - 2) : NULL;
+ current_dir = parts->c >= 2 ? xdebug_join(slash, parts, 0, parts->c - 2) : NULL;
- parent_dir = parts->c > 3 ? xdebug_join(slash, parts, 0, parts->c - 3) : NULL;
+ parent_dir = parts->c >= 3 ? xdebug_join(slash, parts, 0, parts->c - 3) : NULL;
- grand_dir = parts->c > 4 ? xdebug_join(slash, parts, 0, parts->c - 4) : NULL;
+ grand_dir = parts->c >= 4 ? xdebug_join(slash, parts, 0, parts->c - 4) : NULL;Simply replacing Resulting in : Which will then produce the right scan in xdebug_logs : This will help us create a /.xdebug directory at the root of our virtual filesystem since the Currently it gives us this : While with my suggestion : Edit : The Xdebug pull request is ready for review. |
|
Eureka! I found a way to :
in :
🎉 |
|
Linking to the XDebug PR for posterity xdebug/xdebug#1062 |
|
@mho22 That PR is great, thank you for contributing upstream! We don't have to wait for it to be merged, released, etc, too – we can just patch our XDebug version. |
0a68413 to
2e7fe43
Compare
|
I decided to split this pull request into two separate ones : this one for Xdebug 3.5 path mappings and skippings and the other for IDE path skipping. |
8a88dc2 to
2c237b8
Compare
|
@adamziel Using PHP.wasm CLI : It doesn't need to map paths since it calls Using Playground CLI, it becomes more technical. We have to check if PHP is 8.5 or higher. If it is higher, then we recreate the tempDirSymlink and set the Xdebug Config the same way as for PHP.wasm CLI but with mounts and cwd. If it is lower than PHP8.5 we need the Am I missing something ? |
|
This is great! I have an TODO in the multi-worker PR to find a way to avoid debug breaks during boot. We previously worked around it by booting with a dedicated worker, but in that PR, all workers are equal even though we do boot through one of them. This should at least let us avoid breaking on /internal PHP files. It's likely we'd still break on /wordpress files during boot, but maybe that is OK for now. I am reviewing this now but wanted to first share this happy sentiment along the way. :) |
brandonpayton
left a comment
There was a problem hiding this comment.
Thanks, @mho22! This looks good overall, but I left a few requests for changes.
| mounts?: Mount[]; | ||
| /** | ||
| * The IDE key to use for the debug configuration. Defaults to 'PLAYGROUNDCLI'. | ||
| * The IDE key to use for the debug configuration. Defaults to 'PHPWASMCLI'. |
There was a problem hiding this comment.
It is probably fine, but I want to note that Defaults to 'PHPWASMCLI' is the kind of comment that can easily become out of sync with reality since this is not where the default is assigned.
There was a problem hiding this comment.
The PHPWASMCLI default here needs to stay documented because it must match the one used at runtime in with-xdebug.ts on line 76 when writing the xdebug.ini file and the ideKey in xdebug-path-mappings.ts on line 489.
That said, I could extract it into a shared constant to remove the drift risk entirely. Would you prefer that?
There was a problem hiding this comment.
If the value needs to be the same between both, it sounds like it would be good to have a shared constant/declaration that expresses that. But whatever you think best works for me.
There was a problem hiding this comment.
Done. I created a DEFAULT_IDE_KEY constant.
packages/php-wasm/cli-util/src/test/xdebug-path-mappings.spec.ts
Outdated
Show resolved
Hide resolved
packages/php-wasm/node/src/lib/extensions/xdebug/with-xdebug.ts
Outdated
Show resolved
Hide resolved
051b84d to
ef502d6
Compare
ef502d6 to
46b2777
Compare
brandonpayton
left a comment
There was a problem hiding this comment.
Thanks, @mho22! I left additional comments, but please feel free to merge this when you think it is ready.
|
@brandonpayton I added the requested changes except for the CLI output. I'll create a new pull request for that. Don't hesitate to review the new changes and merge if ready. |
Thanks, @mho22! |
Motivation for the change, related issues
Related pull request : #2423
This pull request aims to provide a way to ignore paths from step debugging. This feature has been enabled internally in Xdebug 3.5 [ PHP 8.5 ] but for older PHP versions, only IDEs can somehow ignore paths.
This pull request focuses on Xdebug 3.5:
Implementation details
By adding a
.xdebugdirectory with apath.mapwith the list of path mappings :and a
skip.mapfile with the list of skipped paths :Which then are determined during runtime loading :
Testing Instructions
Partially in CI
And with this example :
/php/xdebug.php/php/foo.php/baz/qux.php/php/bar.phpscript.js/php/xdebug.phpon line 7node --no-warnings --loader=./packages/meta/src/node-es-module-loader/loader.mts script.jsin the terminalfoo.phpfile and go to thebar.phpone ]No current working directory exists in the virtual filesystem.