Skip to content

Commit 629b962

Browse files
committed
- Fix conflict
2 parents e32d511 + d7e09f9 commit 629b962

File tree

4 files changed

+83
-62
lines changed

4 files changed

+83
-62
lines changed

phpdbg.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ static void php_phpdbg_destroy_bp_methods(void *brake) /* {{{ */
7070

7171
static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
7272
{
73-
zend_hash_init(&PHPDBG_G(bp_files), 8, NULL, php_phpdbg_destroy_bp_file, 0);
74-
zend_hash_init(&PHPDBG_G(bp_symbols), 8, NULL, php_phpdbg_destroy_bp_symbol, 0);
75-
zend_hash_init(&PHPDBG_G(bp_oplines), 8, NULL, php_phpdbg_destroy_bp_opline, 0);
76-
zend_hash_init(&PHPDBG_G(bp_methods), 8, NULL, php_phpdbg_destroy_bp_methods, 0);
73+
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], 8, NULL, php_phpdbg_destroy_bp_file, 0);
74+
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], 8, NULL, php_phpdbg_destroy_bp_symbol, 0);
75+
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], 8, NULL, php_phpdbg_destroy_bp_opline, 0);
76+
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
7777

7878
return SUCCESS;
7979
} /* }}} */
8080

8181
static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
8282
{
83-
zend_hash_destroy(&PHPDBG_G(bp_files));
84-
zend_hash_destroy(&PHPDBG_G(bp_symbols));
85-
zend_hash_destroy(&PHPDBG_G(bp_oplines));
86-
zend_hash_destroy(&PHPDBG_G(bp_methods));
83+
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
84+
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
85+
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
86+
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]);
8787

8888
if (PHPDBG_G(exec)) {
8989
efree(PHPDBG_G(exec));
@@ -112,10 +112,10 @@ static PHP_FUNCTION(phpdbg_break)
112112
instructs phpdbg to clear breakpoints */
113113
static PHP_FUNCTION(phpdbg_clear)
114114
{
115-
zend_hash_clean(&PHPDBG_G(bp_files));
116-
zend_hash_clean(&PHPDBG_G(bp_symbols));
117-
zend_hash_clean(&PHPDBG_G(bp_oplines));
118-
zend_hash_clean(&PHPDBG_G(bp_methods));
115+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
116+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
117+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
118+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]);
119119
} /* }}} */
120120

121121
zend_function_entry phpdbg_user_functions[] = {
@@ -379,6 +379,10 @@ int main(int argc, char *argv[]) /* {{{ */
379379
ini_entries_len += sizeof(phpdbg_ini_hardcoded) - 2;
380380

381381
phpdbg->ini_entries = ini_entries;
382+
383+
printf("[Welcome to phpdbg, the interactive PHP debugger, v%s]\n", PHPDBG_VERSION);
384+
printf("To get help using phpdbg type \"help\" and press enter\n");
385+
printf("[Please report bugs to <%s>]\n", PHPDBG_ISSUES);
382386

383387
if (phpdbg->startup(phpdbg) == SUCCESS) {
384388
zend_activate(TSRMLS_C);

phpdbg.h

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,42 @@
4545

4646
#define PHPDBG_NEXT 2
4747

48+
/* {{{ tables */
49+
#define PHPDBG_BREAK_FILE 0
50+
#define PHPDBG_BREAK_SYM 1
51+
#define PHPDBG_BREAK_OPLINE 2
52+
#define PHPDBG_BREAK_METHOD 3
53+
#define PHPDBG_BREAK_TABLES 4 /* }}} */
54+
4855
/* {{{ flags */
4956
#define PHPDBG_HAS_FILE_BP 0x00000001
5057
#define PHPDBG_HAS_SYM_BP 0x00000010
5158
#define PHPDBG_HAS_OPLINE_BP 0x00000100
5259
#define PHPDBG_HAS_METHOD_BP 0x00001000
53-
#define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP)
60+
#define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP)
5461

5562
#define PHPDBG_IS_STEPPING 0x00010000
5663
#define PHPDBG_IS_QUIET 0x00100000
5764
#define PHPDBG_IS_QUITTING 0x01000000 /* }}} */
5865

66+
/* {{{ strings */
67+
#define PHPDBG_ISSUES "http://github.com/krakjoe/phpdbg/issues"
68+
#define PHPDBG_VERSION "0.0.0" /* }}} */
69+
5970
typedef struct _phpdbg_command_t phpdbg_command_t;
6071

6172
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
62-
HashTable bp_files; /* file breakpoints */
63-
HashTable bp_symbols; /* symbol breakpoints */
64-
HashTable bp_oplines; /* opline breakpoints */
65-
HashTable bp_methods; /* method breakpoints */
66-
char *exec; /* file to execute */
67-
size_t exec_len; /* size of exec */
68-
zend_op_array *ops; /* op_array */
69-
zval *retval; /* return value */
70-
int bp_count; /* breakpoint count */
71-
int vmret; /* return from last opcode handler execution */
72-
phpdbg_command_t *last; /* last command */
73-
const char *last_params; /* last expression */
74-
size_t last_params_len; /* last expression length */
75-
zend_ulong flags; /* phpdbg flags */
73+
HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */
74+
char *exec; /* file to execute */
75+
size_t exec_len; /* size of exec */
76+
zend_op_array *ops; /* op_array */
77+
zval *retval; /* return value */
78+
int bp_count; /* breakpoint count */
79+
int vmret; /* return from last opcode handler execution */
80+
phpdbg_command_t *last; /* last command */
81+
const char *last_params; /* last expression */
82+
size_t last_params_len; /* last expression length */
83+
zend_ulong flags; /* phpdbg flags */
7684
ZEND_END_MODULE_GLOBALS(phpdbg)
7785

7886
#endif /* PHPDBG_H */

phpdbg_bp.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{
5252

5353
PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
5454

55-
if (zend_hash_find(&PHPDBG_G(bp_files),
55+
if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
5656
new_break.filename, path_len, (void**)&break_files_ptr) == FAILURE) {
5757
zend_llist break_files;
5858

5959
zend_llist_init(&break_files, sizeof(phpdbg_breakfile_t),
6060
phpdbg_llist_breakfile_dtor, 0);
6161

62-
zend_hash_update(&PHPDBG_G(bp_files),
62+
zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
6363
new_break.filename, path_len, &break_files, sizeof(zend_llist),
6464
(void**)&break_files_ptr);
6565
}
@@ -75,15 +75,15 @@ void phpdbg_set_breakpoint_symbol(const char *name TSRMLS_DC) /* {{{ */
7575
{
7676
size_t name_len = strlen(name);
7777

78-
if (!zend_hash_exists(&PHPDBG_G(bp_symbols), name, name_len)) {
78+
if (!zend_hash_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], name, name_len)) {
7979
phpdbg_breaksymbol_t new_break;
8080

8181
PHPDBG_G(flags) |= PHPDBG_HAS_SYM_BP;
8282

8383
new_break.symbol = estrndup(name, name_len + 1);
8484
new_break.id = PHPDBG_G(bp_count)++;
8585

86-
zend_hash_update(&PHPDBG_G(bp_symbols), new_break.symbol,
86+
zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], new_break.symbol,
8787
name_len, &new_break, sizeof(phpdbg_breaksymbol_t), NULL);
8888

8989
printf("[Breakpoint #%d added at %s]\n", new_break.id, new_break.symbol);
@@ -99,12 +99,12 @@ void phpdbg_set_breakpoint_method(const char* class_name,
9999
{
100100
HashTable class_breaks, *class_table;
101101

102-
if (zend_hash_find(&PHPDBG_G(bp_methods), class_name, class_len, (void**)&class_table) != SUCCESS) {
102+
if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name, class_len, (void**)&class_table) != SUCCESS) {
103103
zend_hash_init(
104104
&class_breaks, 8, NULL, phpdbg_class_breaks_dtor, 0);
105105
zend_hash_update(
106-
&PHPDBG_G(bp_methods),
107-
class_name, class_len,
106+
&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD],
107+
class_name, class_len,
108108
(void**)&class_breaks, sizeof(HashTable), (void**)&class_table);
109109
}
110110

@@ -132,7 +132,7 @@ void phpdbg_set_breakpoint_opline(const char *name TSRMLS_DC) /* {{{ */
132132
{
133133
zend_ulong opline = strtoul(name, 0, 16);
134134

135-
if (!zend_hash_index_exists(&PHPDBG_G(bp_oplines), opline)) {
135+
if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline)) {
136136
phpdbg_breakline_t new_break;
137137

138138
PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
@@ -141,7 +141,7 @@ void phpdbg_set_breakpoint_opline(const char *name TSRMLS_DC) /* {{{ */
141141
new_break.opline = opline;
142142
new_break.id = PHPDBG_G(bp_count)++;
143143

144-
zend_hash_index_update(&PHPDBG_G(bp_oplines), opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
144+
zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
145145

146146
printf("[Breakpoint #%d added at %s]\n", new_break.id, new_break.name);
147147
} else {
@@ -151,7 +151,7 @@ void phpdbg_set_breakpoint_opline(const char *name TSRMLS_DC) /* {{{ */
151151

152152
void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
153153
{
154-
if (!zend_hash_index_exists(&PHPDBG_G(bp_oplines), (zend_ulong) opline)) {
154+
if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline)) {
155155
phpdbg_breakline_t new_break;
156156

157157
PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
@@ -162,7 +162,7 @@ void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{
162162
new_break.opline = (zend_ulong) opline;
163163
new_break.id = PHPDBG_G(bp_count)++;
164164

165-
zend_hash_index_update(&PHPDBG_G(bp_oplines), (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
165+
zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
166166

167167
printf("[Breakpoint #%d added at %p]\n", new_break.id, (zend_op*) new_break.opline);
168168
}
@@ -174,7 +174,7 @@ int phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
174174
zend_llist *break_list;
175175
zend_llist_element *le;
176176

177-
if (zend_hash_find(&PHPDBG_G(bp_files), op_array->filename, name_len,
177+
if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], op_array->filename, name_len,
178178
(void**)&break_list) == FAILURE) {
179179
return FAILURE;
180180
}
@@ -215,7 +215,7 @@ int phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */
215215
fname = "main";
216216
}
217217

218-
if (zend_hash_find(&PHPDBG_G(bp_symbols), fname, strlen(fname),
218+
if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname, strlen(fname),
219219
(void**)&bp) == SUCCESS) {
220220
printf("[Breakpoint #%d in %s() at %s:%u]\n", bp->id, bp->symbol,
221221
zend_get_executed_filename(TSRMLS_C),
@@ -231,7 +231,7 @@ int phpdbg_find_breakpoint_method(zend_op_array *ops TSRMLS_DC) /* {{{ */
231231
HashTable *class_table;
232232
phpdbg_breakmethod_t *bp;
233233

234-
if (zend_hash_find(&PHPDBG_G(bp_methods), ops->scope->name, ops->scope->name_length,
234+
if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], ops->scope->name, ops->scope->name_length,
235235
(void**)&class_table) == SUCCESS) {
236236
if (zend_hash_find(
237237
class_table,
@@ -253,7 +253,7 @@ int phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ *
253253
{
254254
phpdbg_breakline_t *bp;
255255

256-
if (zend_hash_index_find(&PHPDBG_G(bp_oplines), (zend_ulong) opline,
256+
if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline,
257257
(void**)&bp) == SUCCESS) {
258258
printf("[Breakpoint #%d in %s at %s:%u]\n", bp->id, bp->name,
259259
zend_get_executed_filename(TSRMLS_C),
@@ -267,12 +267,13 @@ int phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ *
267267

268268
void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */
269269
{
270-
zend_hash_clean(&PHPDBG_G(bp_files));
271-
zend_hash_clean(&PHPDBG_G(bp_symbols));
272-
zend_hash_clean(&PHPDBG_G(bp_oplines));
273-
zend_hash_clean(&PHPDBG_G(bp_methods));
274-
270+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
271+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
272+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
273+
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]);
274+
275275
PHPDBG_G(flags) &= ~PHPDBG_BP_MASK;
276+
276277
PHPDBG_G(bp_count) = 0;
277278
} /* }}} */
278279

phpdbg_prompt.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ static PHPDBG_COMMAND(print) /* {{{ */
247247

248248
printf("--------------------------------------\n");
249249
printf("File Break Point Information:\n");
250-
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp_files), &position);
251-
zend_hash_get_current_data_ex(&PHPDBG_G(bp_files), (void**) &points, &position) == SUCCESS;
252-
zend_hash_move_forward_ex(&PHPDBG_G(bp_files), &position)) {
250+
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position);
251+
zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], (void**) &points, &position) == SUCCESS;
252+
zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position)) {
253253
zend_llist_position lposition;
254254
phpdbg_breakfile_t *brake;
255255

@@ -269,9 +269,9 @@ static PHPDBG_COMMAND(print) /* {{{ */
269269

270270
printf("--------------------------------------\n");
271271
printf("Symbol Break Point Information:\n");
272-
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp_symbols), &position);
273-
zend_hash_get_current_data_ex(&PHPDBG_G(bp_symbols), (void**) &points, &position) == SUCCESS;
274-
zend_hash_move_forward_ex(&PHPDBG_G(bp_symbols), &position)) {
272+
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position);
273+
zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], (void**) &points, &position) == SUCCESS;
274+
zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position)) {
275275
zend_llist_position lposition;
276276
phpdbg_breaksymbol_t *brake;
277277

@@ -291,9 +291,9 @@ static PHPDBG_COMMAND(print) /* {{{ */
291291

292292
printf("--------------------------------------\n");
293293
printf("Opline Break Point Information:\n");
294-
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp_oplines), &position);
295-
zend_hash_get_current_data_ex(&PHPDBG_G(bp_oplines), (void**) &brake, &position) == SUCCESS;
296-
zend_hash_move_forward_ex(&PHPDBG_G(bp_oplines), &position)) {
294+
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position);
295+
zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void**) &brake, &position) == SUCCESS;
296+
zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position)) {
297297
printf("#%d\t%s\n", brake->id, brake->name);
298298
}
299299
}
@@ -412,6 +412,14 @@ static PHPDBG_COMMAND(clean) /* {{{ */
412412
printf("[\tConstants: %d]\n", zend_hash_num_elements(EG(zend_constants)));
413413
printf("[\tIncluded: %d]\n", zend_hash_num_elements(&EG(included_files)));
414414

415+
/* this is implicitly required */
416+
if (PHPDBG_G(ops)) {
417+
destroy_op_array(
418+
PHPDBG_G(ops) TSRMLS_CC);
419+
efree(PHPDBG_G(ops));
420+
PHPDBG_G(ops) = NULL;
421+
}
422+
415423
zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
416424
zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
417425
zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
@@ -434,10 +442,10 @@ static PHPDBG_COMMAND(clean) /* {{{ */
434442
static PHPDBG_COMMAND(clear) /* {{{ */
435443
{
436444
printf("[Clearing Breakpoints:]\n");
437-
printf("[\tFile\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_files)));
438-
printf("[\tSymbols\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_symbols)));
439-
printf("[\tOplines\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_oplines)));
440-
printf("[\tMethods\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_methods)));
445+
printf("[\tFile\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]));
446+
printf("[\tSymbols\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]));
447+
printf("[\tOplines\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]));
448+
printf("[\tMethods\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]));
441449

442450
phpdbg_clear_breakpoints(TSRMLS_C);
443451

@@ -446,7 +454,7 @@ static PHPDBG_COMMAND(clear) /* {{{ */
446454

447455
static PHPDBG_COMMAND(help) /* {{{ */
448456
{
449-
printf("[Welcome to phpdbg, the interactive PHP debugger.]\n");
457+
printf("[Welcome to phpdbg, the interactive PHP debugger, v%s]\n", PHPDBG_VERSION);
450458

451459
if (!expr_len) {
452460
const phpdbg_command_t *prompt_command = phpdbg_prompt_commands;
@@ -470,7 +478,7 @@ static PHPDBG_COMMAND(help) /* {{{ */
470478
printf("failed to find help command: %s\n", expr);
471479
}
472480
}
473-
printf("[Please report bugs to <https://github.com/krakjoe/phpdbg/issues>]\n");
481+
printf("[Please report bugs to <%s>]\n", PHPDBG_ISSUES);
474482

475483
return SUCCESS;
476484
} /* }}} */

0 commit comments

Comments
 (0)