Skip to content

Commit d50e254

Browse files
committed
- Added command "set breakpoint <on|off>"
1 parent 2be5a1e commit d50e254

File tree

5 files changed

+67
-38
lines changed

5 files changed

+67
-38
lines changed

phpdbg.c

Lines changed: 7 additions & 7 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

@@ -249,32 +249,32 @@ static PHP_FUNCTION(phpdbg_color)
249249
long element;
250250
char *color;
251251
zend_uint color_len;
252-
252+
253253
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &element, &color, &color_len) == FAILURE) {
254254
return;
255255
}
256-
256+
257257
switch (element) {
258258
case PHPDBG_COLOR_NOTICE:
259259
case PHPDBG_COLOR_ERROR:
260260
case PHPDBG_COLOR_PROMPT:
261261
phpdbg_set_color_ex(element, color, color_len TSRMLS_CC);
262262
break;
263-
263+
264264
default: zend_error(E_ERROR, "phpdbg detected an incorrect color constant");
265265
}
266266
} /* }}} */
267267

268268
/* {{{ proto void phpdbg_prompt(string prompt) */
269-
static PHP_FUNCTION(phpdbg_prompt)
269+
static PHP_FUNCTION(phpdbg_prompt)
270270
{
271271
char *prompt;
272272
zend_uint prompt_len;
273-
273+
274274
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &prompt, &prompt_len) == FAILURE) {
275275
return;
276276
}
277-
277+
278278
phpdbg_set_prompt(prompt TSRMLS_CC);
279279
} /* }}} */
280280

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_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(breakpoint) /* {{{ */
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(breakpoint);
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(breakpoint, "usage: set breakpoint <on|off>", 'b', set_breakpoint, NULL, 0),
3537
PHPDBG_END_COMMAND
3638
};
3739

0 commit comments

Comments
 (0)