Skip to content

Commit 46551b5

Browse files
committed
Merged pull request xdebug#1071
* pr/1071: Fixed issue #2411: Native Path Mapping is not applied to the initial fileuri in the init packet
2 parents 862b96e + 3f3dc9a commit 46551b5

File tree

12 files changed

+133
-14
lines changed

12 files changed

+133
-14
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ src/*/*.dep
1515
src/*/*.lo
1616
src/*/*.loT
1717
src/*/.libs
18+
src/*/*/*.dep
19+
src/*/*/*.lo
20+
src/*/*/*.loT
21+
src/*/*/.libs
1822
/libs.mk
1923
/ac*.m4
2024
/build

src/debugger/handler_dbgp.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,16 @@ int xdebug_dbgp_init(xdebug_con *context, int mode)
25822582
if (zend_string_equals_literal(context->program_name, "-") || zend_string_equals_literal(context->program_name, "Command line code")) {
25832583
xdebug_xml_add_attribute_ex(response, "fileuri", xdstrdup("dbgp://stdin"), 0, 1);
25842584
} else {
2585-
xdebug_xml_add_attribute_ex(response, "fileuri", xdebug_zstr_path_to_url(context->program_name), 0, 1);
2585+
xdebug_str *local_path;
2586+
size_t local_line;
2587+
bool must_free_path = false;
2588+
2589+
xdebug_debugger_map_remote_to_local(context->program_name, 1, &local_path, &local_line, &must_free_path);
2590+
xdebug_xml_add_attribute_ex(response, "fileuri", xdebug_xdebug_str_path_to_url(local_path), 0, 1);
2591+
2592+
if (must_free_path) {
2593+
xdebug_str_free(local_path);
2594+
}
25862595
}
25872596
xdebug_xml_add_attribute_ex(response, "language", "PHP", 0, 0);
25882597
xdebug_xml_add_attribute_ex(response, "xdebug:language_version", XG_BASE(php_version_run_time), 0, 0);

tests/debugger/dbgp/dbgpclient.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ function fixFilePath( $m )
116116
return " {$m[1]}=\"file://{$fm[1]}\"";
117117
}
118118

119-
function doRead( $conn, ?string $transaction_id = null )
119+
private function shouldSanitizeFileUri( array $options ) : bool
120+
{
121+
if ( !array_key_exists( 'SanitizeFileUri', $options ) )
122+
{
123+
return true;
124+
}
125+
126+
return !! $options['SanitizeFileUri'];
127+
}
128+
129+
function doRead( $conn, ?string $transaction_id = null, ?array $options = [] )
120130
{
121131
stream_set_timeout( $conn, 3 );
122132
do {
@@ -157,7 +167,11 @@ function doRead( $conn, ?string $transaction_id = null )
157167
$read = preg_replace( '@\s(xdebug:language_version)="[^"]+?"@', ' \\1=""', $read );
158168
$read = preg_replace( '@(engine\sversion)="[^"]+?"@', '\\1=""', $read );
159169
$read = preg_replace( '@(2002-20[0-9]{2})@', '2002-2099', $read );
160-
$read = preg_replace_callback( '@\s(fileuri|filename)="file:///(.+?)"@', self::class . '::fixFilePath', $read );
170+
171+
if ( $this->shouldSanitizeFileUri( $options ) )
172+
{
173+
$read = preg_replace_callback( '@\s(fileuri|filename)="file:///(.+?)"@', self::class . '::fixFilePath', $read );
174+
}
161175

162176
echo $read, "\n\n";
163177

@@ -255,11 +269,11 @@ function runTest( $filename, array $commands, array $ini_options = [], array $op
255269
$this->pid = $procInfo['pid'];
256270

257271
// read header
258-
$this->doRead( $conn );
272+
$this->doRead( $conn, NULL, $options );
259273
foreach ( $commands as $command )
260274
{
261275
$this->sendCommand( $conn, $command, $i );
262-
$this->doRead( $conn, (string)$i );
276+
$this->doRead( $conn, (string)$i, $options );
263277

264278
$i++;
265279
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
./dbgp-breakpoint-line.inc = /var/www/projects/xdebug-test/fake-local-file.php
2+
./file-uri-file1.inc = /var/www/projects/xdebug-test/fake-local-file1.php
3+
./file-uri-file2.inc:1 = /var/www/projects/xdebug-test/fake-local-file2.php:1
4+
./file-uri-file2.inc:2-99999 = /var/www/projects/xdebug-test/fake-local-file2.php:3-100000

tests/debugger/maps/map-single-line/bug02374.phpt renamed to tests/debugger/maps/map-single-file/bug02374.phpt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,38 @@ dbgpRunFile(
2828
'xdebug.mode' => 'debug', 'xdebug.start_with_request' => 'yes',
2929
'xdebug.log' => $xdebugLogFileName, 'xdebug.log_level' => 10,
3030
'xdebug.path_mapping' => 'yes',
31-
]
31+
],
32+
[
33+
'SanitizeFileUri' => false,
34+
],
3235
);
3336

3437
echo file_get_contents( $xdebugLogFileName );
3538
@unlink( $xdebugLogFileName );
3639
?>
3740
--EXPECTF--
3841
<?xml version="1.0" encoding="iso-8859-1"?>
39-
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://dbgp-breakpoint-line.inc" language="PHP" xdebug:language_version="" protocol_version="1.0" appid=""><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2099 by Derick Rethans]]></copyright></init>
42+
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/projects/xdebug-test/fake-local-file.php" language="PHP" xdebug:language_version="" protocol_version="1.0" appid=""><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2099 by Derick Rethans]]></copyright></init>
4043

4144
-> feature_set -i 1 -n breakpoint_details -v 1
4245
<?xml version="1.0" encoding="iso-8859-1"?>
4346
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="breakpoint_details" success="1"></response>
4447

4548
-> step_into -i 2
4649
<?xml version="1.0" encoding="iso-8859-1"?>
47-
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file://" lineno="2"></xdebug:message></response>
50+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file:///var/www/projects/xdebug-test/fake-local-file.php" lineno="2"></xdebug:message></response>
4851

4952
-> breakpoint_set -i 3 -t line -f /var/www/projects/xdebug-test/fake-local-file.php -n 3
5053
<?xml version="1.0" encoding="iso-8859-1"?>
5154
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="{{PID}}0001"></response>
5255

5356
-> breakpoint_list -i 4
5457
<?xml version="1.0" encoding="iso-8859-1"?>
55-
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="4"><breakpoint type="line" filename="file://" lineno="3" state="enabled" hit_count="0" hit_value="0" id="{{PID}}0001"></breakpoint></response>
58+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="4"><breakpoint type="line" filename="file:///var/www/projects/xdebug-test/fake-local-file.php" lineno="3" state="enabled" hit_count="0" hit_value="0" id="{{PID}}0001"></breakpoint></response>
5659

5760
-> run -i 5
5861
<?xml version="1.0" encoding="iso-8859-1"?>
59-
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="5" status="break" reason="ok"><xdebug:message filename="file://" lineno="3"></xdebug:message><breakpoint type="line" filename="file://" lineno="3" state="enabled" hit_count="1" hit_value="0" id="{{PID}}0001"></breakpoint></response>
62+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="5" status="break" reason="ok"><xdebug:message filename="file:///var/www/projects/xdebug-test/fake-local-file.php" lineno="3"></xdebug:message><breakpoint type="line" filename="file:///var/www/projects/xdebug-test/fake-local-file.php" lineno="3" state="enabled" hit_count="1" hit_value="0" id="{{PID}}0001"></breakpoint></response>
6063

6164
-> detach -i 6
6265
<?xml version="1.0" encoding="iso-8859-1"?>

tests/debugger/maps/map-single-line/dbgp-breakpoint-line.inc renamed to tests/debugger/maps/map-single-file/dbgp-breakpoint-line.inc

File renamed without changes.

tests/debugger/maps/map-single-line/dbgp-breakpoint-line.phpt renamed to tests/debugger/maps/map-single-file/dbgp-breakpoint-line.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ echo file_get_contents( $xdebugLogFileName );
4040
[%d] [Path Mapping] DEBUG: No map files found with pattern '%sdebugger%e.xdebug%e*.map'
4141
[%d] [Path Mapping] INFO: Scanning for map files with pattern '%sdebugger%emaps%e.xdebug%e*.map'
4242
[%d] [Path Mapping] DEBUG: No map files found with pattern '%sdebugger%emaps%e.xdebug%e*.map'
43-
[%d] [Path Mapping] INFO: Scanning for map files with pattern '%sdebugger%emaps%emap-single-line%e.xdebug%e*.map'
44-
[%d] [Path Mapping] INFO: Reading mapping file '%sdebugger%emaps%emap-single-line%e.xdebug%esimple.map'
45-
[%d] [Path Mapping] DEBUG: Found 1 path mapping rules
43+
[%d] [Path Mapping] INFO: Scanning for map files with pattern '%sdebugger%emaps%emap-single-file%e.xdebug%e*.map'
44+
[%d] [Path Mapping] INFO: Reading mapping file '%sdebugger%emaps%emap-single-file%e.xdebug%esimple.map'
45+
[%d] [Path Mapping] DEBUG: Found 3 path mapping rules
4646
%A
4747
[%d] [Step Debug] <- breakpoint_set -i 3 -t line -f /var/www/projects/xdebug-test/fake-local-file.php -n 3
4848
[%d] [Path Mapping] INFO: Mapping (to replace) local location /var/www/projects/xdebug-test/fake-local-file.php:3
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
DBGP: fileuri with full file path map
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/../../../utils.inc';
6+
check_reqs('dbgp');
7+
?>
8+
--FILE--
9+
<?php
10+
require __DIR__ . '/../../dbgp/dbgpclient.php';
11+
$filename = dirname(__FILE__) . '/file-uri-file1.inc';
12+
13+
$xdebugLogFileName = sys_get_temp_dir() . '/' . getenv('UNIQ_RUN_ID') . getenv('TEST_PHP_WORKER') . 'start_ignore_yes_env.txt';
14+
@unlink( $xdebugLogFileName );
15+
16+
$commands = array(
17+
'feature_set -n breakpoint_details -v 1',
18+
'detach',
19+
);
20+
21+
dbgpRunFile(
22+
$filename, $commands,
23+
[
24+
'xdebug.mode' => 'debug', 'xdebug.start_with_request' => 'yes',
25+
'xdebug.log' => $xdebugLogFileName, 'xdebug.log_level' => 10,
26+
'xdebug.path_mapping' => 'yes',
27+
],
28+
[
29+
'SanitizeFileUri' => false,
30+
],
31+
);
32+
33+
echo file_get_contents( $xdebugLogFileName );
34+
@unlink( $xdebugLogFileName );
35+
?>
36+
--EXPECTF--
37+
<?xml version="1.0" encoding="iso-8859-1"?>
38+
<init %s fileuri="file:///var/www/projects/xdebug-test/fake-local-file1.php" %s></init>
39+
%A
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
DBGP: fileuri with multiple lines for file path map
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/../../../utils.inc';
6+
check_reqs('dbgp');
7+
?>
8+
--FILE--
9+
<?php
10+
require __DIR__ . '/../../dbgp/dbgpclient.php';
11+
$filename = dirname(__FILE__) . '/file-uri-file2.inc';
12+
13+
$xdebugLogFileName = sys_get_temp_dir() . '/' . getenv('UNIQ_RUN_ID') . getenv('TEST_PHP_WORKER') . 'start_ignore_yes_env.txt';
14+
@unlink( $xdebugLogFileName );
15+
16+
$commands = array(
17+
'feature_set -n breakpoint_details -v 1',
18+
'detach',
19+
);
20+
21+
dbgpRunFile(
22+
$filename, $commands,
23+
[
24+
'xdebug.mode' => 'debug', 'xdebug.start_with_request' => 'yes',
25+
'xdebug.log' => $xdebugLogFileName, 'xdebug.log_level' => 10,
26+
'xdebug.path_mapping' => 'yes',
27+
],
28+
[
29+
'SanitizeFileUri' => false,
30+
],
31+
);
32+
33+
echo file_get_contents( $xdebugLogFileName );
34+
@unlink( $xdebugLogFileName );
35+
?>
36+
--EXPECTF--
37+
<?xml version="1.0" encoding="iso-8859-1"?>
38+
<init %s fileuri="file:///var/www/projects/xdebug-test/fake-local-file2.php" %s></init>
39+
%A
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
define("YES", M_PI); $NO = 42;
3+
echo "hi\n";
4+
?>

0 commit comments

Comments
 (0)