(gdb) l 4444 Delay for a given number of seconds */ 4445 PHP_FUNCTION(sleep) 4446 { 4447 long num; 4448 4449 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num) == FAILURE) { 4450 RETURN_FALSE; 4451 } 4452 if (num < 0) { 4453 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of seconds must be greater than or equal to 0"); (gdb) l 4450 4445 PHP_FUNCTION(sleep) 4446 { 4447 long num; 4448 4449 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num) == FAILURE) { 4450 RETURN_FALSE; 4451 } 4452 if (num < 0) { 4453 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of seconds must be greater than or equal to 0"); 4454 RETURN_FALSE; (gdb) l zif_usleep 4463 /* }}} */ 4464 4465 /* {{{ proto void usleep(int micro_seconds) 4466 Delay for a given number of micro seconds */ 4467 PHP_FUNCTION(usleep) 4468 { 4469 #if HAVE_USLEEP 4470 long num; 4471 4472 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num) == FAILURE) {
继续执行
(gdb) n 4452 if (num < 0) { (gdb) p num $6 = 3 (gdb) n 4457 RETURN_LONG(php_sleep(num)); (gdb) n 4462 } (gdb) n execute_internal (execute_data_ptr=0xb7fa1144, fci=0x0, return_value_used=0) at /usr/local/src/php-5.5.23/Zend/zend_execute.c:1488 1488 }
到了execute_internal ,可以查看一下当前函数的一个状态
(gdb) p execute_data_ptr $7 = (zend_execute_data *) 0xb7fa1144 (gdb) p *execute_data_ptr $8 = {opline = 0xb7fbcacc, function_state = {function = 0x8bcf3e8, arguments = 0xb7fa119c}, op_array = 0xb7fbc7b4, object = 0x0, symbol_table = 0x8b99cdc, prev_execute_data = 0x0, old_error_reporting = 0x0, nested = 0 '\000', original_return_value = 0x38b4ac9, current_scope = 0x49, current_called_scope = 0x45, current_this = 0x0, fast_ret = 0x0, call_slots = 0xb7fa1188, call = 0xb7fa1188} (gdb) p *execute_data_ptr->function_state.function->common->function_name $9 = 115 's' (gdb) p execute_data_ptr->function_state.function->common->function_name $10 = 0x8af03c9 "sleep" (gdb) p execute_data_ptr->op_array->filename $11 = 0xb7fbc8e8 "/code/kk.php"
查看当前hashtable
(gdb) p *execute_data_ptr->symbol_table $ = {nTableSize = , nTableMask = , nNumOfElements = , nNextFreeElement = , pInternalPointer = xbfbc, pListHead = xbfbc, pListTail = xbfbd, arBuckets = xbfb, pDestructor = xbff <_zval_ptr_dtor_wrapper>, persistent = '\', nApplyCount = '\', bApplyProtection = '\', inconsistent = }
继续执行输出c之后,回车即可,同样可以看到in_array的执行信息
(gdb) p *execute_data_ptr->function_state.function $24 = {type = 1 '\001', common = {type = 1 '\001', function_name = 0x8af1841 "in_array", scope = 0x0, fn_flags = 256, prototype = 0x0, num_args = 3, required_num_args = 2, arg_info = 0x8ae7554}, op_array = {type = 1 '\001', function_name = 0x8af1841 "in_array", scope = 0x0, fn_flags = 256, prototype = 0x0, num_args = 3, required_num_args = 2, arg_info = 0x8ae7554, refcount = 0x842691d, opcodes = 0x8bcf120, last = 0, vars = 0x0, last_var = 0, T = 1, nested_calls = 3086618796, used_stack = 0, brk_cont_array = 0x0, last_brk_cont = 1, try_catch_array = 0xb7fa10dd, last_try_catch = 96, has_finally_block = 160 '\240', static_variables = 0x0, this_var = 11482064, filename = 0xaf1ff4 "|\035\257", line_start = 11482016, line_end = 146381272, doc_comment = 0xbffff238 "x\362\377\277\244\aY\b\021", doc_comment_len = 10305959, early_binding = 11085989, literals = 0x8b7a0a0, last_literal = 140062666, run_time_cache = 0xb7fa10d4, last_cache_slot = 90, reserved = {0x9, 0x8b5f7ac, 0x796, 0x0}}, internal_function = {type = 1 '\001', function_name = 0x8af1841 "in_array", scope = 0x0, fn_flags = 256, prototype = 0x0, num_args = 3, required_num_args = 2, arg_info = 0x8ae7554, handler = 0x842691d <zif_in_array>, module = 0x8bcf120}} (gdb) p execute_data_ptr->function_state.function->common->function_name $26 = 0x8af1841 "in_array" (gdb) p execute_data_ptr->op_array->filename $27 = 0xb7fbc8e8 "/code/kk.php"
还可以加一下监控watch、设置一些调试变量set 等等
其他的调试工具还有 strace 查看系统调用、ltrace 查看类库的调用、vld查看opcode。
以上内容是小编给大家分享的关于如何使用GDB调试PHP程序的全部内容,希望大家喜欢。
您可能感兴趣的文章: