Skip to content

Commit 02ae3f8

Browse files
committed
Merge branch 'master' of https://github.com/krakjoe/phpdbg
1 parent 4e6a8ee commit 02ae3f8

File tree

6 files changed

+80
-49
lines changed

6 files changed

+80
-49
lines changed

phpdbg.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
7878
REGISTER_LONG_CONSTANT("PHPDBG_COLOR_PROMPT", PHPDBG_COLOR_PROMPT, CONST_CS|CONST_PERSISTENT);
7979
REGISTER_LONG_CONSTANT("PHPDBG_COLOR_NOTICE", PHPDBG_COLOR_NOTICE, CONST_CS|CONST_PERSISTENT);
8080
REGISTER_LONG_CONSTANT("PHPDBG_COLOR_ERROR", PHPDBG_COLOR_ERROR, CONST_CS|CONST_PERSISTENT);
81-
81+
8282
return SUCCESS;
8383
} /* }}} */
8484

@@ -162,6 +162,7 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
162162
if (PHPDBG_G(prompt)[0]) {
163163
free(PHPDBG_G(prompt)[0]);
164164
}
165+
165166
if (PHPDBG_G(prompt)[1]) {
166167
free(PHPDBG_G(prompt)[1]);
167168
}
@@ -249,32 +250,32 @@ static PHP_FUNCTION(phpdbg_color)
249250
long element;
250251
char *color;
251252
zend_uint color_len;
252-
253+
253254
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &element, &color, &color_len) == FAILURE) {
254255
return;
255256
}
256-
257+
257258
switch (element) {
258259
case PHPDBG_COLOR_NOTICE:
259260
case PHPDBG_COLOR_ERROR:
260261
case PHPDBG_COLOR_PROMPT:
261262
phpdbg_set_color_ex(element, color, color_len TSRMLS_CC);
262263
break;
263-
264+
264265
default: zend_error(E_ERROR, "phpdbg detected an incorrect color constant");
265266
}
266267
} /* }}} */
267268

268269
/* {{{ proto void phpdbg_prompt(string prompt) */
269-
static PHP_FUNCTION(phpdbg_prompt)
270+
static PHP_FUNCTION(phpdbg_prompt)
270271
{
271272
char *prompt;
272273
zend_uint prompt_len;
273-
274+
274275
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &prompt, &prompt_len) == FAILURE) {
275276
return;
276277
}
277-
278+
278279
phpdbg_set_prompt(prompt TSRMLS_CC);
279280
} /* }}} */
280281

@@ -565,19 +566,21 @@ int main(int argc, char **argv) /* {{{ */
565566
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
566567
#endif
567568

569+
phpdbg_main:
568570
#ifdef ZTS
569571
tsrm_startup(1, 1, 0, NULL);
570572

571573
tsrm_ls = ts_resource(0);
572574
#endif
573575

574-
bp_tmp_file = malloc(L_tmpnam);
575-
tmpnam(bp_tmp_file);
576-
if (bp_tmp_file == NULL) {
577-
phpdbg_error("Unable to create temporary file");
576+
if (!cleaning) {
577+
bp_tmp_file = malloc(L_tmpnam);
578+
tmpnam(bp_tmp_file);
579+
if (bp_tmp_file == NULL) {
580+
phpdbg_error("Unable to create temporary file");
581+
}
578582
}
579583

580-
phpdbg_main:
581584
ini_entries = NULL;
582585
ini_entries_len = 0;
583586
ini_ignore = 0;
@@ -858,16 +861,15 @@ int main(int argc, char **argv) /* {{{ */
858861
sapi_shutdown();
859862
}
860863

864+
#ifdef ZTS
865+
tsrm_shutdown();
866+
#endif
867+
861868
if (cleaning) {
862869
goto phpdbg_main;
863870
}
864871

865872
free(bp_tmp_file);
866873

867-
#ifdef ZTS
868-
/* bugggy */
869-
/* tsrm_shutdown(); */
870-
#endif
871-
872874
return 0;
873875
} /* }}} */

phpdbg.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@
112112
#define PHPDBG_IS_INITIALIZING (1<<19)
113113
#define PHPDBG_IS_SIGNALED (1<<20)
114114
#define PHPDBG_IS_INTERACTIVE (1<<21)
115+
#define PHPDBG_IS_BP_ENABLED (1<<22)
115116

116117
#ifndef _WIN32
117-
# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED)
118+
# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED|PHPDBG_IS_BP_ENABLED)
118119
#else
119-
# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET)
120+
# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_BP_ENABLED)
120121
#endif /* }}} */
121122

122123
/* {{{ strings */
@@ -137,7 +138,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
137138
HashTable registered; /* registered */
138139
HashTable seek; /* seek oplines */
139140
phpdbg_frame_t frame; /* frame */
140-
141+
141142
char *exec; /* file to execute */
142143
size_t exec_len; /* size of exec */
143144
zend_op_array *ops; /* op_array */
@@ -151,10 +152,10 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
151152

152153
char *prompt[2]; /* prompt */
153154
const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */
154-
155+
155156
phpdbg_command_t *lcmd; /* last command */
156157
phpdbg_param_t lparam; /* last param */
157-
158+
158159
zend_ulong flags; /* phpdbg flags */
159160
ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */
160161

phpdbg_bp.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
4848
{
4949
HashPosition position;
5050
HashTable *table = NULL;
51-
51+
5252
if (PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP) {
5353
zend_llist *brakes;
5454

5555
table = &PHPDBG_G(bp)[PHPDBG_BREAK_FILE];
56-
56+
5757
for (zend_hash_internal_pointer_reset_ex(table, &position);
5858
zend_hash_get_current_data_ex(table, (void*) &brakes, &position) == SUCCESS;
5959
zend_hash_move_forward_ex(table, &position)) {
60-
60+
6161
zend_llist_position lposition;
6262
phpdbg_breakfile_t *brake;
6363
zend_ulong count = zend_llist_count(brakes);
64-
64+
6565
if ((brake = zend_llist_get_first_ex(brakes, &lposition))) {
6666
phpdbg_notice(
6767
"Exporting file breakpoints in %s (%d)", brake->filename, count);
@@ -72,14 +72,14 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
7272
}
7373
}
7474
}
75-
75+
7676
if (PHPDBG_G(flags) & PHPDBG_HAS_SYM_BP) {
7777
phpdbg_breaksymbol_t *brake;
78-
78+
7979
table = &PHPDBG_G(bp)[PHPDBG_BREAK_SYM];
80-
80+
8181
phpdbg_notice("Exporting symbol breakpoints (%d)", zend_hash_num_elements(table));
82-
82+
8383
for (zend_hash_internal_pointer_reset_ex(table, &position);
8484
zend_hash_get_current_data_ex(table, (void*) &brake, &position) == SUCCESS;
8585
zend_hash_move_forward_ex(table, &position)) {
@@ -106,36 +106,36 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
106106
zend_hash_move_forward_ex(class, &mposition)) {
107107
if (!noted) {
108108
phpdbg_notice(
109-
"Exporting method breakpoints in %s (%d)",
109+
"Exporting method breakpoints in %s (%d)",
110110
brake->class_name, zend_hash_num_elements(class));
111111
noted = 1;
112112
}
113-
113+
114114
fprintf(
115115
handle, "break %s::%s\n", brake->class_name, brake->func_name);
116116
}
117117
}
118118
}
119-
119+
120120
if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) {
121121
phpdbg_breakop_t *brake;
122-
122+
123123
table = &PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE];
124-
124+
125125
phpdbg_notice(
126126
"Exporting opcode breakpoints (%d)", zend_hash_num_elements(table));
127-
127+
128128
for (zend_hash_internal_pointer_reset_ex(table, &position);
129129
zend_hash_get_current_data_ex(table, (void**) &brake, &position) == SUCCESS;
130130
zend_hash_move_forward_ex(table, &position)) {
131-
131+
132132
fprintf(
133-
handle, "break op %s\n", brake->name);
133+
handle, "break op %s\n", brake->name);
134134
}
135135
}
136-
136+
137137
/* export other types here after resolving errors from source command */
138-
138+
139139
} /* }}} */
140140

141141
PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */
@@ -545,6 +545,10 @@ int phpdbg_find_conditional_breakpoint(TSRMLS_D) /* {{{ */
545545

546546
int phpdbg_find_breakpoint(zend_execute_data* execute_data TSRMLS_DC) /* {{{ */
547547
{
548+
if (!(PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED)) {
549+
return FAILURE;
550+
}
551+
548552
/* conditions cannot be executed by eval()'d code */
549553
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)
550554
&& (PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)

phpdbg_help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ PHPDBG_HELP(break) /* {{{ */
234234
phpdbg_writeln(EMPTY);
235235
phpdbg_writeln("\t%sbreak [address] 0x7ff68f570e08", phpdbg_get_prompt(TSRMLS_C));
236236
phpdbg_writeln("\t%sb [a] 0x7ff68f570e08", phpdbg_get_prompt(TSRMLS_C));
237-
phpdbg_writeln("\tWill break at the opline with the address provided (addresses are shown during execution)");
237+
phpdbg_writeln("\tWill break at the opline with the address provided");
238238
phpdbg_writeln(EMPTY);
239239
phpdbg_writeln("\t%sbreak [lineno] 200", phpdbg_get_prompt(TSRMLS_C));
240240
phpdbg_writeln("\t%sb [l] 200", phpdbg_get_prompt(TSRMLS_C));

phpdbg_set.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,55 @@ PHPDBG_SET(prompt) /* {{{ */
4141
return SUCCESS;
4242
} /* }}} */
4343

44+
PHPDBG_SET(break) /* {{{ */
45+
{
46+
switch (param->type) {
47+
case EMPTY_PARAM:
48+
phpdbg_writeln("%s",
49+
PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED ? "on" : "off");
50+
break;
51+
52+
case STR_PARAM:
53+
if (strncasecmp(param->str, PHPDBG_STRL("on")) == 0) {
54+
PHPDBG_G(flags) |= PHPDBG_IS_BP_ENABLED;
55+
} else if (strncasecmp(param->str, PHPDBG_STRL("off")) == 0) {
56+
PHPDBG_G(flags) ^= PHPDBG_IS_BP_ENABLED;
57+
}
58+
break;
59+
60+
phpdbg_default_switch_case();
61+
}
62+
63+
return SUCCESS;
64+
} /* }}} */
65+
4466
PHPDBG_SET(color) /* {{{ */
4567
{
4668
if ((param->type == STR_PARAM) && (input->argc == 3)) {
4769
const phpdbg_color_t *color = phpdbg_get_color(
4870
input->argv[2]->string, input->argv[2]->length TSRMLS_CC);
4971
int element = PHPDBG_COLOR_INVALID;
50-
72+
5173
if (color) {
52-
if (phpdbg_argv_is(1, "prompt")) {
53-
phpdbg_notice(
74+
if (phpdbg_argv_is(1, "prompt")) {
75+
phpdbg_notice(
5476
"setting prompt color to %s (%s)", color->name, color->code);
5577
element = PHPDBG_COLOR_PROMPT;
5678
if (PHPDBG_G(prompt)[1]) {
5779
free(PHPDBG_G(prompt)[1]);
5880
PHPDBG_G(prompt)[1]=NULL;
5981
}
6082
} else if (phpdbg_argv_is(1, "error")) {
61-
phpdbg_notice(
83+
phpdbg_notice(
6284
"setting error color to %s (%s)", color->name, color->code);
6385
element = PHPDBG_COLOR_ERROR;
64-
86+
6587
} else if (phpdbg_argv_is(1, "notice")) {
66-
phpdbg_notice(
88+
phpdbg_notice(
6789
"setting notice color to %s (%s)", color->name, color->code);
6890
element = PHPDBG_COLOR_NOTICE;
69-
70-
} else goto usage;
91+
92+
} else goto usage;
7193

7294
/* set color for element */
7395
phpdbg_set_color(element, color TSRMLS_CC);

phpdbg_set.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
PHPDBG_SET(prompt);
2828
PHPDBG_SET(color);
2929
PHPDBG_SET(oplog);
30+
PHPDBG_SET(break);
3031

3132
static const phpdbg_command_t phpdbg_set_commands[] = {
3233
PHPDBG_COMMAND_D_EX(prompt, "usage: set prompt <string>", 'p', set_prompt, NULL, 0),
3334
PHPDBG_COMMAND_D_EX(color, "usage: set color <element> <color>", 'c', set_color, NULL, 1),
3435
PHPDBG_COMMAND_D_EX(oplog, "usage: set oplog <output>", 'O', set_oplog, NULL, 0),
36+
PHPDBG_COMMAND_D_EX(break, "usage: set break <on|off>", 'b', set_break, NULL, 0),
3537
PHPDBG_END_COMMAND
3638
};
3739

0 commit comments

Comments
 (0)