Skip to content

Commit 3d927e9

Browse files
committed
Fixed Windows mapping
1 parent cd268e6 commit 3d927e9

File tree

4 files changed

+29
-71
lines changed

4 files changed

+29
-71
lines changed

src/lib/maps/maps_private.c

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,20 @@ int remote_to_local(xdebug_path_maps *maps, const char *remote_path, size_t remo
7070
{
7171
xdebug_path_mapping *result;
7272
xdebug_hash *map = maps->remote_to_local_map;
73-
char *url_path = xdebug_normalize_path_char(remote_path);
7473

75-
if (!xdebug_hash_find(map, url_path, strlen(url_path), (void**) &result)) {
74+
if (!xdebug_hash_find(map, remote_path, strlen(remote_path), (void**) &result)) {
7675
/* We can't find an exact file match, so now try to see if we have a directory match, starting with the full
7776
* path and then removing the trailing directory path until there are none left */
7877
char *end_slash;
7978
char *directory;
8079

81-
end_slash = strrchr((char*) url_path, '/');
80+
end_slash = strrchr((char*) remote_path, DEFAULT_SLASH);
8281
if (!end_slash) {
83-
xdfree(url_path);
8482
return XDEBUG_PATH_MAP_TYPE_UNKNOWN;
8583
}
8684

87-
directory = xdstrndup(url_path, end_slash - url_path + 1);
88-
end_slash = strrchr((char*) directory, '/');
85+
directory = xdstrndup(remote_path, end_slash - remote_path + 1);
86+
end_slash = strrchr((char*) directory, DEFAULT_SLASH);
8987

9088
do {
9189
size_t n = end_slash - directory + 1;
@@ -100,19 +98,17 @@ int remote_to_local(xdebug_path_maps *maps, const char *remote_path, size_t remo
10098
*local_line = remote_line;
10199

102100
*local_path = xdebug_str_new();
103-
xdebug_str_add_fmt(*local_path, "%s%s", result->m.local_path->d, url_path + n);
101+
xdebug_str_add_fmt(*local_path, "%s%s", result->m.local_path->d, remote_path + n);
104102

105103
xdfree(directory);
106-
xdfree(url_path);
107104
return XDEBUG_PATH_MAP_TYPE_DIRECTORY;
108105
}
109106
}
110107

111-
end_slash = strrnchr(directory, '/', n - 1);
108+
end_slash = strrnchr(directory, DEFAULT_SLASH, n - 1);
112109
} while (end_slash);
113110

114111
xdfree(directory);
115-
xdfree(url_path);
116112
return XDEBUG_PATH_MAP_TYPE_UNKNOWN;
117113
}
118114

@@ -138,12 +134,10 @@ int remote_to_local(xdebug_path_maps *maps, const char *remote_path, size_t remo
138134
size_t result_line;
139135

140136
if (!result->m.line_ranges) {
141-
xdfree(url_path);
142137
return XDEBUG_PATH_MAP_TYPE_UNKNOWN;
143138
}
144139

145140
if (!find_local_line_number_from_ranges(remote_line, result->m.line_ranges, &result_path, &result_line)) {
146-
xdfree(url_path);
147141
return XDEBUG_PATH_MAP_TYPE_UNKNOWN;
148142
}
149143

@@ -154,7 +148,6 @@ int remote_to_local(xdebug_path_maps *maps, const char *remote_path, size_t remo
154148
*local_path = xdebug_str_copy(result_path);
155149
*local_line = result_line;
156150

157-
xdfree(url_path);
158151
return result->type;
159152
}
160153

@@ -167,7 +160,6 @@ int remote_to_local(xdebug_path_maps *maps, const char *remote_path, size_t remo
167160
*local_path = NULL;
168161
*local_line = -1;
169162

170-
xdfree(url_path);
171163
return XDEBUG_PATH_MAP_FLAGS_SKIP;
172164
}
173165

@@ -217,22 +209,20 @@ int local_to_remote(xdebug_path_maps *maps, const char *local_path, size_t local
217209
{
218210
xdebug_path_mapping *result;
219211
xdebug_hash *map = maps->local_to_remote_map;
220-
char *url_path = xdebug_normalize_path_char(local_path);
221212

222-
if (!xdebug_hash_find(map, url_path, strlen(url_path), (void**) &result)) {
213+
if (!xdebug_hash_find(map, local_path, strlen(local_path), (void**) &result)) {
223214
/* We can't find an exact file match, so now try to see if we have a directory match, starting with the full
224215
* path and then removing the trailing directory path until there are none left */
225216
char *end_slash;
226217
char *directory;
227218

228-
end_slash = strrchr((char*) url_path, '/');
219+
end_slash = strrchr((char*) local_path, DEFAULT_SLASH);
229220
if (!end_slash) {
230-
xdfree(url_path);
231221
return XDEBUG_PATH_MAP_TYPE_UNKNOWN;
232222
}
233223

234-
directory = xdstrndup(url_path, end_slash - url_path + 1);
235-
end_slash = strrchr((char*) directory, '/');
224+
directory = xdstrndup(local_path, end_slash - local_path + 1);
225+
end_slash = strrchr((char*) directory, DEFAULT_SLASH);
236226

237227
do {
238228
size_t n = end_slash - directory + 1;
@@ -242,19 +232,17 @@ int local_to_remote(xdebug_path_maps *maps, const char *local_path, size_t local
242232
*remote_line = local_line;
243233

244234
*remote_path = xdebug_str_new();
245-
xdebug_str_add_fmt(*remote_path, "%s%s", result->remote_path->d, url_path + n);
235+
xdebug_str_add_fmt(*remote_path, "%s%s", result->remote_path->d, local_path + n);
246236

247237
xdfree(directory);
248-
xdfree(url_path);
249238
return XDEBUG_PATH_MAP_TYPE_DIRECTORY;
250239
}
251240
}
252241

253-
end_slash = strrnchr(directory, '/', n - 1);
242+
end_slash = strrnchr(directory, DEFAULT_SLASH, n - 1);
254243
} while (end_slash);
255244

256245
xdfree(directory);
257-
xdfree(url_path);
258246
return XDEBUG_PATH_MAP_TYPE_UNKNOWN;
259247
}
260248

@@ -289,7 +277,6 @@ int local_to_remote(xdebug_path_maps *maps, const char *local_path, size_t local
289277
}
290278
}
291279

292-
xdfree(url_path);
293280
return result->type;
294281
}
295282

src/lib/maps/parser.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,21 @@ static bool extract_line_range(path_maps_parser_state *state, const char *elemen
386386
return false;
387387
}
388388

389+
#ifdef PHP_WIN32
390+
static void normalize_path_xdebug_str_in_place(xdebug_str *path)
391+
{
392+
int i;
393+
394+
for (i = 0; i < XDEBUG_STR_LEN(path); i++) {
395+
if (XDEBUG_STR_VAL(path)[i] == '/') {
396+
XDEBUG_STR_VAL(path)[i] = '\\';
397+
}
398+
}
399+
}
400+
#else
401+
# define normalize_path_xdebug_str_in_place(path)
402+
#endif
403+
389404
static xdebug_str* prepare_remote_element(path_maps_parser_state *state, const char *buffer, const char *equals, int *type, int *remote_begin, int *remote_end)
390405
{
391406
xdebug_str *remote_path;
@@ -440,8 +455,8 @@ static xdebug_str* prepare_remote_element(path_maps_parser_state *state, const c
440455
xdebug_str_addl(remote_path, trimmed, trimmed_length, false);
441456
}
442457

443-
/* Convert slashes to Unix style */
444-
xdebug_normalize_path_xdebug_str_in_place(remote_path);
458+
/* Convert Unix-style slashes (/) to Windows-style slashes (\\) from mapping file if needed */
459+
normalize_path_xdebug_str_in_place(remote_path);
445460

446461
/* clean up */
447462
xdfree(trimmed);
@@ -517,9 +532,6 @@ static xdebug_str* prepare_local_element(path_maps_parser_state *state, const ch
517532
xdebug_str_addl(local_path, trimmed, trimmed_length, false);
518533
}
519534

520-
/* Convert slashes to Unix style */
521-
xdebug_normalize_path_xdebug_str_in_place(local_path);
522-
523535
cleanup:
524536
/* clean up */
525537
xdfree(trimmed);

src/lib/usefulstuff.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -722,37 +722,3 @@ int xdebug_format_filename(char **formatted_name, const char *default_fmt, zend_
722722

723723
return fname.l;
724724
}
725-
726-
727-
#ifdef PHP_WIN32
728-
char *xdebug_normalize_path_char(const char *path)
729-
{
730-
char *new_path = xdstrdup(path);
731-
char *ptr = new_path;
732-
733-
do {
734-
if ((*ptr) == '\\') {
735-
*ptr = '/';
736-
}
737-
ptr++;
738-
} while (*ptr != '\0');
739-
740-
return new_path;
741-
}
742-
743-
void xdebug_normalize_path_xdebug_str_in_place(xdebug_str *path)
744-
{
745-
int i;
746-
747-
for (i = 0; i < XDEBUG_STR_LEN(path); i++) {
748-
if (XDEBUG_STR_VAL(path)[i] == '\\') {
749-
XDEBUG_STR_VAL(path)[i] = '/';
750-
}
751-
}
752-
}
753-
#else
754-
char *xdebug_normalize_path_char(const char *path)
755-
{
756-
return xdstrdup(path);
757-
}
758-
#endif

src/lib/usefulstuff.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ char *xdebug_zstr_path_to_url(zend_string *string);
3838
char *xdebug_xdebug_str_path_to_url(xdebug_str *string);
3939
char *xdebug_path_from_url(zend_string *fileurl);
4040

41-
char *xdebug_normalize_path_char(const char *path);
42-
#ifdef PHP_WIN32
43-
void xdebug_normalize_path_xdebug_str_in_place(xdebug_str *path);
44-
#else
45-
# define xdebug_normalize_path_xdebug_str_in_place(path)
46-
#endif
47-
4841
FILE *xdebug_fopen(char *fname, const char *mode, const char *extension, char **new_fname);
4942
int xdebug_format_output_filename(char **filename, char *format, char *script_name);
5043
int xdebug_format_file_link(char **filename, const char *error_filename, int error_lineno);

0 commit comments

Comments
 (0)