Skip to content

Commit 728502f

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
2 parents ed0602f + 3b2b080 commit 728502f

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

sapi/phpdbg/phpdbg.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ static void php_phpdbg_destroy_file_source(zval *data) /* {{{ */
128128
if (source->buf) {
129129
efree(source->buf);
130130
}
131-
efree(source->filename);
132131
efree(source);
133132
} /* }}} */
134133

sapi/phpdbg/phpdbg_list.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
251251
memcpy(data.buf, bufptr, data.len);
252252
}
253253
memset(data.buf + data.len, 0, ZEND_MMAP_AHEAD + 1);
254-
data.filename = filename;
255254
data.line[0] = 0;
256255

257256
memset(&fake, 0, sizeof(fake));
@@ -284,10 +283,9 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
284283
return NULL;
285284
}
286285

287-
dataptr->filename = estrdup(dataptr->filename);
288286
dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line);
289-
zend_hash_str_add_ptr(&PHPDBG_G(file_sources), filename, strlen(filename), dataptr);
290-
phpdbg_resolve_pending_file_break(filename);
287+
zend_hash_add_ptr(&PHPDBG_G(file_sources), ret->filename, dataptr);
288+
phpdbg_resolve_pending_file_break(ZSTR_VAL(ret->filename));
291289

292290
fake.opened_path = NULL;
293291
zend_file_handle_dtor(&fake);
@@ -322,9 +320,7 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) {
322320
return NULL;
323321
}
324322

325-
filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename);
326-
327-
dataptr = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), filename, strlen(filename));
323+
dataptr = zend_hash_find_ptr(&PHPDBG_G(file_sources), op_array->filename);
328324
ZEND_ASSERT(dataptr != NULL);
329325

330326
dataptr->op_array = *op_array;
@@ -371,7 +367,6 @@ zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) {
371367
dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line);
372368
zend_hash_add_ptr(&PHPDBG_G(file_sources), fake_name, dataptr);
373369

374-
dataptr->filename = estrndup(ZSTR_VAL(fake_name), ZSTR_LEN(fake_name));
375370
zend_string_release(fake_name);
376371

377372
dataptr->op_array = *op_array;

sapi/phpdbg/phpdbg_list.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ void phpdbg_init_list(void);
4242
void phpdbg_list_update(void);
4343

4444
typedef struct {
45-
char *filename;
4645
char *buf;
4746
size_t len;
4847
#if HAVE_MMAP

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ int phpdbg_compile_stdin(zend_string *code) {
543543
PHPDBG_G(exec_len) = 1;
544544
{ /* remove leading ?> from source */
545545
int i;
546+
/* remove trailing data after zero byte, used for avoiding conflicts in eval()'ed code snippets */
546547
zend_string *source_path = strpprintf(0, "-%c%p", 0, PHPDBG_G(ops)->opcodes);
547548
phpdbg_file_source *data = zend_hash_find_ptr(&PHPDBG_G(file_sources), source_path);
548549
dtor_func_t dtor = PHPDBG_G(file_sources).pDestructor;
@@ -552,9 +553,6 @@ int phpdbg_compile_stdin(zend_string *code) {
552553
zend_hash_str_update_ptr(&PHPDBG_G(file_sources), "-", 1, data);
553554
zend_string_release(source_path);
554555

555-
efree(data->filename);
556-
data->filename = estrdup("-");
557-
558556
for (i = 1; i <= data->lines; i++) {
559557
data->line[i] -= 2;
560558
}
@@ -571,7 +569,10 @@ int phpdbg_compile(void) /* {{{ */
571569
{
572570
zend_file_handle fh;
573571
char *buf;
572+
char *start_line = NULL;
574573
size_t len;
574+
size_t start_line_len;
575+
int i;
575576

576577
if (!PHPDBG_G(exec)) {
577578
phpdbg_error("inactive", "type=\"nocontext\"", "No execution context");
@@ -590,14 +591,40 @@ int phpdbg_compile(void) /* {{{ */
590591
}
591592
case '\n':
592593
CG(start_lineno) = 2;
593-
fh.handle.stream.mmap.len -= fh.handle.stream.mmap.buf - buf;
594+
start_line_len = fh.handle.stream.mmap.buf - buf;
595+
start_line = emalloc(start_line_len);
596+
memcpy(start_line, buf, start_line_len);
597+
fh.handle.stream.mmap.len -= start_line_len;
594598
end = fh.handle.stream.mmap.buf;
595599
}
596600
} while (fh.handle.stream.mmap.buf + 1 < end);
597601
}
598602

599603
PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE);
600604

605+
/* prepend shebang line to file_source */
606+
if (start_line) {
607+
phpdbg_file_source *data = zend_hash_find_ptr(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename);
608+
609+
dtor_func_t dtor = PHPDBG_G(file_sources).pDestructor;
610+
PHPDBG_G(file_sources).pDestructor = NULL;
611+
zend_hash_del(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename);
612+
PHPDBG_G(file_sources).pDestructor = dtor;
613+
614+
data = erealloc(data, sizeof(phpdbg_file_source) + sizeof(uint) * ++data->lines);
615+
memmove(data->line + 1, data->line, sizeof(uint) * data->lines);
616+
data->line[0] = 0;
617+
data->buf = erealloc(data->buf, data->len + start_line_len);
618+
memmove(data->buf + start_line_len, data->buf, data->len * sizeof(uint));
619+
memcpy(data->buf, start_line, start_line_len);
620+
efree(start_line);
621+
data->len += start_line_len;
622+
for (i = 1; i <= data->lines; i++) {
623+
data->line[i] += start_line_len;
624+
}
625+
zend_hash_update_ptr(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename, data);
626+
}
627+
601628
fh.handle.stream.mmap.buf = buf;
602629
fh.handle.stream.mmap.len = len;
603630
zend_destroy_file_handle(&fh);

sapi/phpdbg/tests/bug73704.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #73704 (phpdbg shows the wrong line in files with shebang)
3+
--PHPDBG--
4+
list 6
5+
b 4
6+
r
7+
c
8+
q
9+
--EXPECTF--
10+
[Successful compilation of %s]
11+
prompt> 00001: #!/usr/bin/env php
12+
00002: <?php
13+
00003:
14+
00004: echo 1;
15+
00005:
16+
prompt> [Breakpoint #0 added at %s:4]
17+
prompt> [Breakpoint #0 at %s:4, hits: 1]
18+
>00004: echo 1;
19+
00005:
20+
prompt> 1
21+
[Script ended normally]
22+
prompt>
23+
--FILE--
24+
#!/usr/bin/env php
25+
<?php
26+
27+
echo 1;

0 commit comments

Comments
 (0)