Skip to content

Commit c2365d8

Browse files
committed
compress globals
1 parent 8de21cb commit c2365d8

File tree

4 files changed

+70
-58
lines changed

4 files changed

+70
-58
lines changed

phpdbg.c

Lines changed: 12 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[] = {

phpdbg.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
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
@@ -58,20 +65,17 @@
5865
typedef struct _phpdbg_command_t phpdbg_command_t;
5966

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

7781
#endif /* PHPDBG_H */

phpdbg_bp.c

Lines changed: 18 additions & 18 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,11 +99,11 @@ 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),
106+
&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD],
107107
class_name, class_len,
108108
(void**)&class_breaks, sizeof(HashTable), (void**)&class_table);
109109
}
@@ -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,10 +267,10 @@ 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));
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]);
274274

275275
PHPDBG_G(flags) &= ~(PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP);
276276
PHPDBG_G(bp_count) = 0;

phpdbg_prompt.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ static PHPDBG_COMMAND(print) /* {{{ */
246246

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

@@ -268,9 +268,9 @@ static PHPDBG_COMMAND(print) /* {{{ */
268268

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

@@ -290,9 +290,9 @@ static PHPDBG_COMMAND(print) /* {{{ */
290290

291291
printf("--------------------------------------\n");
292292
printf("Opline Break Point Information:\n");
293-
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp_oplines), &position);
294-
zend_hash_get_current_data_ex(&PHPDBG_G(bp_oplines), (void**) &brake, &position) == SUCCESS;
295-
zend_hash_move_forward_ex(&PHPDBG_G(bp_oplines), &position)) {
293+
for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position);
294+
zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void**) &brake, &position) == SUCCESS;
295+
zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position)) {
296296
printf("#%d\t%s\n", brake->id, brake->name);
297297
}
298298
}
@@ -410,7 +410,15 @@ static PHPDBG_COMMAND(clean) /* {{{ */
410410
printf("[\tFunctions: %d]\n", zend_hash_num_elements(EG(function_table)));
411411
printf("[\tConstants: %d]\n", zend_hash_num_elements(EG(zend_constants)));
412412
printf("[\tIncluded: %d]\n", zend_hash_num_elements(&EG(included_files)));
413-
413+
414+
/* this is implicitly required */
415+
if (PHPDBG_G(ops)) {
416+
destroy_op_array(
417+
PHPDBG_G(ops) TSRMLS_CC);
418+
efree(PHPDBG_G(ops));
419+
PHPDBG_G(ops) = NULL;
420+
}
421+
414422
zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
415423
zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
416424
zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
@@ -433,10 +441,10 @@ static PHPDBG_COMMAND(clean) /* {{{ */
433441
static PHPDBG_COMMAND(clear) /* {{{ */
434442
{
435443
printf("[Clearing Breakpoints:]\n");
436-
printf("[\tFile\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_files)));
437-
printf("[\tSymbols\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_symbols)));
438-
printf("[\tOplines\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_oplines)));
439-
printf("[\tMethods\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp_methods)));
444+
printf("[\tFile\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]));
445+
printf("[\tSymbols\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]));
446+
printf("[\tOplines\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]));
447+
printf("[\tMethods\t%d]\n", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]));
440448

441449
phpdbg_clear_breakpoints(TSRMLS_C);
442450

0 commit comments

Comments
 (0)