gdb 调试php文件夹,GDB调试PHP代码入门

1、源码编译安装php,带–enable-debug参数

wget -O /opt/apps/phpbrew/distfiles/php-7.1.0.tar.bz2 “http://ftp.ntu.edu.tw/pub/php/distributions/php-7.1.0.tar.bz2”

phpbrew –debug install -j $(nproc) 7.1.0 +everything — \

–with-iconv=/usr/local \

–with-gd \

–with-openssl \

–enable-debug

2、编写简单php代码

➜ source cat zval.php

$a = 10;

echo $a;

$b = 20.1;

echo $b;

$c = $a;

echo $c;

3、gdb调试

gdb php

a、加断点

b ZEND_ECHO_SPEC_CV_HANDLER

b、执行代码

r zval.php

c、查询当前定义的变量

(gdb) info locals

z = 0x7fffecc13080

(gdb) ptype z

type = struct _zval_struct {

zend_value value;

union {

struct {…} v;

uint32_t type_info;

} u1;

union {

uint32_t next;

uint32_t cache_slot;

uint32_t lineno;

uint32_t num_args;

uint32_t fe_pos;

uint32_t fe_iter_idx;

uint32_t access_flags;

uint32_t property_guard;

} u2;

} *

d、打印变量

(gdb) p *(zval *)z

$3 = {

value = {

lval = 10,

dval = 4.9406564584124654e-323,

counted = 0xa,

str = 0xa,

arr = 0xa,

obj = 0xa,

res = 0xa,

ref = 0xa,

ast = 0xa,

zv = 0xa,

ptr = 0xa,

ce = 0xa,

func = 0xa,

ww = {

w1 = 10,

w2 = 0

}

},

u1 = {

v = {

type = 4 ‘\004’,

type_flags = 0 ‘\000’,

const_flags = 0 ‘\000’,

reserved = 0 ‘\000’

},

type_info = 4

},

u2 = {

next = 0,

cache_slot = 0,

lineno = 0,

num_args = 0,

fe_pos = 0,

fe_iter_idx = 0,

—Type to continue, or q to quit—

access_flags = 0,

property_guard = 0

}

}

(gdb) p *(zval *)&(zval *)z.value

$4 = {

value = {

lval = 10,

dval = 4.9406564584124654e-323,

counted = 0xa,

str = 0xa,

arr = 0xa,

obj = 0xa,

res = 0xa,

ref = 0xa,

ast = 0xa,

zv = 0xa,

ptr = 0xa,

ce = 0xa,

func = 0xa,

ww = {

w1 = 10,

w2 = 0

}

},

u1 = {

v = {

type = 4 ‘\004’,

type_flags = 0 ‘\000’,

const_flags = 0 ‘\000’,

reserved = 0 ‘\000’

},

type_info = 4

},

u2 = {

next = 0,

cache_slot = 0,

lineno = 0,

num_args = 0,

fe_pos = 0,

fe_iter_idx = 0,

—Type to continue, or q to quit—

access_flags = 0,

property_guard = 0

}

}

对照PHP源码:

Zend/zend_types.h-302-/* regular data types */

Zend/zend_types.h-303-#define IS_UNDEF 0

Zend/zend_types.h-304-#define IS_NULL 1

Zend/zend_types.h-305-#define IS_FALSE 2

Zend/zend_types.h-306-#define IS_TRUE 3

Zend/zend_types.h:307:#define IS_LONG 4

Zend/zend_types.h-308-#define IS_DOUBLE 5

Zend/zend_types.h-309-#define IS_STRING 6

Zend/zend_types.h-310-#define IS_ARRAY 7

Zend/zend_types.h-311-#define IS_OBJECT 8

Zend/zend_types.h-312-#define IS_RESOURCE 9

Zend/zend_types.h-313-#define IS_REFERENCE 10

u1.type 为 4时,变量值取 value.lval ( 10 )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值