Skip to content

Commit 914cca1

Browse files
committed
Merged pull request xdebug#1039
* pr/1039: Fixed Windows mapping Fixed issue #2374: Breakpoints in mapped paths don't trigger as they're mapped back before matching Distinguish between different types of mapping in log message Add debug information for final set of path mapping rules
2 parents bd9f063 + 3d927e9 commit 914cca1

File tree

12 files changed

+144
-90
lines changed

12 files changed

+144
-90
lines changed

src/debugger/debugger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int xdebug_debugger_map_remote_to_local(zend_string *remote_filename, int remote
314314
goto pass_through;
315315
}
316316

317-
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_INFO, "ENABLED", "Mapping location %s:%d", ZSTR_VAL(remote_filename), remote_lineno);
317+
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_INFO, "ENABLED", "Mapping remote location %s:%d", ZSTR_VAL(remote_filename), remote_lineno);
318318

319319
result = xdebug_path_maps_remote_to_local(
320320
ZSTR_VAL(remote_filename), remote_lineno,
@@ -451,7 +451,7 @@ void xdebug_debugger_statement_call(zend_string *filename, int lineno)
451451
for (le = XDEBUG_LLIST_HEAD(XG_DBG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) {
452452
extra_brk_info = XDEBUG_LLIST_VALP(le);
453453

454-
if (XG_DBG(context).handler->break_on_line(&(XG_DBG(context)), extra_brk_info, mapped_path, mapped_lineno)) {
454+
if (XG_DBG(context).handler->break_on_line(&(XG_DBG(context)), extra_brk_info, filename, lineno)) {
455455
break_ok = 1; /* Breaking is allowed by default */
456456

457457
/* Check if we have a condition set for it */

src/debugger/handler_dbgp.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static void map_local_to_remote_replace(xdebug_brk_info *brk_info)
322322
if (!xdebug_lib_path_mapping_enabled()) {
323323
return;
324324
}
325-
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_INFO, "ENABLED", "Mapping location %s:%d", ZSTR_VAL(brk_info->filename), brk_info->original_lineno);
325+
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_INFO, "ENABLED", "Mapping (to replace) local location %s:%d", ZSTR_VAL(brk_info->filename), brk_info->original_lineno);
326326

327327
if (xdebug_path_maps_local_to_remote(
328328
ZSTR_VAL(brk_info->filename), brk_info->original_lineno,
@@ -356,7 +356,7 @@ static void map_remote_brkinfo_to_local(xdebug_brk_info *brk_info, xdebug_str **
356356
goto pass_through;
357357
}
358358

359-
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_INFO, "ENABLED", "Mapping location %s:%d", ZSTR_VAL(brk_info->filename), brk_info->resolved_lineno);
359+
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_INFO, "ENABLED", "Mapping brkinfo local location %s:%d", ZSTR_VAL(brk_info->filename), brk_info->resolved_lineno);
360360

361361
if (xdebug_path_maps_remote_to_local(
362362
ZSTR_VAL(brk_info->filename), brk_info->resolved_lineno,
@@ -2767,7 +2767,7 @@ int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char
27672767
return 1;
27682768
}
27692769

2770-
int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, xdebug_str *orig_filename, int lineno)
2770+
int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, zend_string *orig_filename, int lineno)
27712771
{
27722772
zend_string *resolved_filename = NULL;
27732773

@@ -2778,12 +2778,12 @@ int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, xdebug_
27782778
return 0;
27792779
}
27802780

2781-
xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Current location: %s:%d.", XDEBUG_STR_VAL(orig_filename), lineno);
2781+
xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Current location: %s:%d.", ZSTR_VAL(orig_filename), lineno);
27822782

2783-
if (is_dbgp_url(ZSTR_VAL(brk->filename)) && xdebug_debugger_check_evaled_code_xdebug_str(orig_filename, &resolved_filename)) {
2784-
xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Found eval code for '%s': %s.", XDEBUG_STR_VAL(orig_filename), ZSTR_VAL(resolved_filename));
2783+
if (is_dbgp_url(ZSTR_VAL(brk->filename)) && xdebug_debugger_check_evaled_code_zstr(orig_filename, &resolved_filename)) {
2784+
xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Found eval code for '%s': %s.", ZSTR_VAL(orig_filename), ZSTR_VAL(resolved_filename));
27852785
} else {
2786-
resolved_filename = zend_string_init(XDEBUG_STR_VAL(orig_filename), XDEBUG_STR_LEN(orig_filename), false);
2786+
resolved_filename = zend_string_init(ZSTR_VAL(orig_filename), ZSTR_LEN(orig_filename), false);
27872787
}
27882788

27892789
xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Matching breakpoint '%s:%d' against location '%s:%d'.", ZSTR_VAL(brk->filename), brk->resolved_lineno, ZSTR_VAL(resolved_filename), lineno);

src/debugger/handler_dbgp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ typedef struct xdebug_dbgp_resolve_context {
8989
int xdebug_dbgp_init(xdebug_con *context, int mode);
9090
int xdebug_dbgp_deinit(xdebug_con *context);
9191
int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack);
92-
int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, xdebug_str *filename, int lineno);
92+
int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, zend_string *filename, int lineno);
9393
int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_vector *stack, xdebug_str *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info, zval *return_value);
9494
int xdebug_dbgp_resolve_breakpoints(xdebug_con *context, zend_string *filename);
9595
int xdebug_dbgp_stream_output(const char *string, unsigned int length);

src/debugger/handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct _xdebug_remote_handler {
146146
int (*remote_error)(xdebug_con *h, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack);
147147

148148
/* Breakpoints */
149-
int (*break_on_line)(xdebug_con *h, xdebug_brk_info *brk, xdebug_str *filename, int lineno);
149+
int (*break_on_line)(xdebug_con *h, xdebug_brk_info *brk, zend_string *filename, int lineno);
150150
int (*remote_breakpoint)(xdebug_con *h, xdebug_vector *stack, xdebug_str *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info, zval *return_value);
151151
int (*resolve_breakpoints)(xdebug_con *h, zend_string *opa);
152152

src/lib/maps/maps.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,37 @@ static void scan_directory(const char *dir)
118118
xdfree(scan_dir);
119119
}
120120

121+
static void dump_rule_info(void *ret, xdebug_hash_element *e)
122+
{
123+
xdebug_path_mapping *rule = (xdebug_path_mapping*) e->ptr;
124+
125+
if ((rule->type & XDEBUG_PATH_MAP_FLAGS_MASK) == XDEBUG_PATH_MAP_FLAGS_SKIP) {
126+
switch (rule->type & XDEBUG_PATH_MAP_TYPE_MASK) {
127+
case XDEBUG_PATH_MAP_TYPE_DIRECTORY:
128+
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_DEBUG, "RULE", "Skip directory '%s'", XDEBUG_STR_VAL(rule->remote_path));
129+
break;
130+
case XDEBUG_PATH_MAP_TYPE_FILE:
131+
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_DEBUG, "RULE", "Skip file '%s'", XDEBUG_STR_VAL(rule->remote_path));
132+
break;
133+
}
134+
} else {
135+
switch (rule->type & XDEBUG_PATH_MAP_TYPE_MASK) {
136+
case XDEBUG_PATH_MAP_TYPE_DIRECTORY:
137+
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_DEBUG, "RULE", "Map directory '%s' to '%s'", XDEBUG_STR_VAL(rule->remote_path), XDEBUG_STR_VAL(rule->m.local_path));
138+
break;
139+
case XDEBUG_PATH_MAP_TYPE_FILE:
140+
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_DEBUG, "RULE", "Map file '%s' to '%s'", XDEBUG_STR_VAL(rule->remote_path), XDEBUG_STR_VAL(rule->m.local_path));
141+
break;
142+
}
143+
}
144+
}
145+
146+
static void dump_mapping_rules(xdebug_path_maps *map_info)
147+
{
148+
xdebug_hash_apply(map_info->remote_to_local_map, NULL, dump_rule_info);
149+
xdebug_hash_apply(map_info->local_to_remote_map, NULL, dump_rule_info);
150+
}
151+
121152
void xdebug_path_maps_scan(const char *script_source)
122153
{
123154
xdebug_arg *parts;
@@ -164,6 +195,7 @@ void xdebug_path_maps_scan(const char *script_source)
164195
xdebug_arg_dtor(parts);
165196

166197
xdebug_log_ex(XLOG_CHAN_PATHMAP, XLOG_DEBUG, "RULES", "Found %zd path mapping rules", XG_LIB(path_mapping_information)->remote_to_local_map->size);
198+
dump_mapping_rules(XG_LIB(path_mapping_information));
167199
}
168200

169201
int xdebug_path_maps_local_to_remote(const char *local_path, size_t local_line, xdebug_str **remote_path, size_t *remote_line)

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)