Skip to content

Handle minimum path in .xdebug directory discovery#1062

Closed
mho22 wants to merge 3 commits intoxdebug:masterfrom
mho22:handle-minimum-path-discovery
Closed

Handle minimum path in .xdebug directory discovery#1062
mho22 wants to merge 3 commits intoxdebug:masterfrom
mho22:handle-minimum-path-discovery

Conversation

@mho22
Copy link
Copy Markdown
Contributor

@mho22 mho22 commented Jan 28, 2026

This is some kind of unusual behavior but I stumbled upon this lately in one of my use cases. This is why I wanted to suggest this pull request. It is mainly focused on the .xdebug directory discovery for path mappings/skippings. Long story short : It couldn't find my .xdebug directory located at the root of my environment.

Here is a more precise use case :

Based on these lines in src/lib/maps/maps.c > line 183 :

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;
grand_dir = parts->c > 4 ? xdebug_join(slash, parts, 0, parts->c - 4) : NULL;

If my current debugged file is /foo/bar/baz/qux/file.php, then :

file_path = "/foo/bar/baz/qux/file.php"

current_dir = "/foo/bar/baz/qux"
parent_dir = "/foo/bar/baz"
grand_dir = "/foo/bar"

Nice. Now :

If my current debugging directory is /foo/bar/file.php, then :

file_path = "/foo/bar/file.php"

current_dir = "/foo/bar"
parent_dir = "/foo"
grand_dir = (NULL)

While grand_dir should probably return "/" instead (or almost "").

My suggestion would be to simply replace > with >=.

Currently it gives this :

file_path = "/foo/bar/file.php"

current_dir = "/foo/bar"
parent_dir = "/foo"
grand_dir = (NULL)
[42] [Path Mapping] INFO: Scanning for map files with pattern '/foo/.xdebug/*.map'
[42] [Path Mapping] DEBUG: No map files found with pattern '/foo/.xdebug/*.map'
[42] [Path Mapping] INFO: Scanning for map files with pattern '/foo/bar/.xdebug/*.map'
[42] [Path Mapping] DEBUG: No map files found with pattern '/foo/bar/.xdebug/*.map'
[42] [Path Mapping] DEBUG: Found 0 path mapping rules

While with my suggestion :

file_path = "/foo/bar/file.php"

current_dir = "/foo/bar"
parent_dir = "/foo"
grand_dir = ""
[42] [Path Mapping] INFO: Scanning for map files with pattern '/.xdebug/*.map'
[42] [Path Mapping] INFO: Reading mapping file '/.xdebug/paths.map'
[42] [Path Mapping] INFO: Scanning for map files with pattern '/foo/.xdebug/*.map'
[42] [Path Mapping] DEBUG: No map files found with pattern '/foo/.xdebug/*.map'
[42] [Path Mapping] INFO: Scanning for map files with pattern '/foo/bar/.xdebug/*.map'
[42] [Path Mapping] DEBUG: No map files found with pattern '/foo/bar/.xdebug/*.map'
[42] [Path Mapping] DEBUG: Found 3 path mapping rules

What do you think?

@derickr
Copy link
Copy Markdown
Contributor

derickr commented Feb 16, 2026

Hi,

sorry for the slow reply. I saw you just created an issue for it too.

I think this makes sense — would it be possible to create a test case for this perhaps?

cheers,
Derick

@mho22
Copy link
Copy Markdown
Contributor Author

mho22 commented Feb 16, 2026

No need to apologize at all, I'm sorry I didn't create an issue first.

I'll try to write a test case, but I'm not used to doing so in a project like Xdebug, so we may need a few back-and-forths.

I'll get back to you once it's done.

@derickr
Copy link
Copy Markdown
Contributor

derickr commented Feb 16, 2026

Your best bet might be looking at https://github.com/xdebug/xdebug/tree/master/tests/debugger/maps/skip-vendor-directory as an example. I suspect creating the right directory structure is the main problem (and I don't have a clever answer either at the moment).

@mho22
Copy link
Copy Markdown
Contributor Author

mho22 commented Feb 16, 2026

@derickr Thank you for the advice! I ended up adding the test as map-minimum-path and it ran successfully. Do you think I should do anything more?

--FILE--
<?php
require __DIR__ . '/../../dbgp/dbgpclient.php';
$filename = dirname(__FILE__) . '/foo/bar/file.inc';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test tests the thing you're fixing, as the dirname(__FILE__) is something that's already going to be several levels deep — where you want to test something that's only two or three path levels.

I think you might be able to get away with using sys_get_temp_dir() (like below in line 13 for the log file), create a directory in there (include getenv('UNIQ_RUN_ID') . getenv('TEST_PHP_WORKER') in the directory name to allow for parallelism), copy your test file file.inc and .xdebug directory there, and then set the breakpoints etc.

And then also remove them at the end of the test, with the --CLEAN-- section: https://php.github.io/php-src/miscellaneous/writing-tests.html#clean

Copy link
Copy Markdown
Contributor Author

@mho22 mho22 Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course... I'm not sure whether sys_get_temp_dir() guarantees that the .xdebug directory will be located at the root of the test, but if it does, then I think my latest commit should fix the issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derickr I'm not sure whether I should hit "re-request review," tag you here, or simply do nothing. I don't mean to rush you, I just want to make sure I haven't forgotten to do something on my end.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get to it, but I'm about to do two conferences and have a lot of things on my plate. I'm not forgetting about it, but I do want to test it with the right (ie, none) parent paths locally too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good luck with the conferences, and feel free to ping me if you need anything.

@derickr
Copy link
Copy Markdown
Contributor

derickr commented Mar 23, 2026

I'm closing this in favour of #1070 (keeping you as commit author), which is for the right branch and has the test case "fixed" too.

Thanks!

@derickr derickr closed this Mar 23, 2026
@mho22
Copy link
Copy Markdown
Contributor Author

mho22 commented Mar 24, 2026

@derickr Thank you! I am glad I contributed to Xdebug 🎉

@mho22 mho22 deleted the handle-minimum-path-discovery branch March 24, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants