Home编程语言PHPGDB调试PHP源码理解变量引用

GDB调试PHP源码理解变量引用

<?php
$a = 'hello';

/*
(gdb) p z
$1 = (zval *) 0x101421080
(gdb) p *z
$2 = {value = {lval = 4315948736, dval = 2.1323619996695517e-314, counted = 0x1014026c0,
    str = 0x1014026c0, arr = 0x1014026c0, obj = 0x1014026c0, res = 0x1014026c0, ref = 0x1014026c0,
    ast = 0x1014026c0, zv = 0x1014026c0, ptr = 0x1014026c0, ce = 0x1014026c0, func = 0x1014026c0, ww = {
      w1 = 20981440, w2 = 1}}, u1 = {v = {type = 6 '\006', type_flags = 0 '\000', u = {call_info = 0,
        extra = 0}}, type_info = 6}, u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0,
    num_args = 0, fe_pos = 0, fe_iter_idx = 0, access_flags = 0, property_guard = 0,
    constant_flags = 0, extra = 0}}
(gdb) p $2.value.str
$3 = (zend_string *) 0x1014026c0
(gdb) p *$2.value.str
$4 = {gc = {refcount = 1, u = {type_info = 70}}, h = 9223372247569412249, len = 5, val = "h"}
(gdb) p *$2.value.str.val@5
$5 = "hello"
 */
echo $a;



$b = &$a;

/*
(gdb) p z
$6 = (zval *) 0x101421080
(gdb) p *z
$7 = {value = {lval = 4315943304, dval = 2.1323593159049635e-314, counted = 0x101401188,
    str = 0x101401188, arr = 0x101401188, obj = 0x101401188, res = 0x101401188, ref = 0x101401188,
    ast = 0x101401188, zv = 0x101401188, ptr = 0x101401188, ce = 0x101401188, func = 0x101401188, ww = {
      w1 = 20976008, w2 = 1}}, u1 = {v = {type = 10 '\n', type_flags = 1 '\001', u = {call_info = 0,
        extra = 0}}, type_info = 266}, u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0,
    num_args = 0, fe_pos = 0, fe_iter_idx = 0, access_flags = 0, property_guard = 0,
    constant_flags = 0, extra = 0}}
(gdb) p $7.value.ref
$8 = (zend_reference *) 0x101401188
(gdb) p *$7.value.ref
$9 = {gc = {refcount = 2, u = {type_info = 10}}, val = {value = {lval = 4315948736,
      dval = 2.1323619996695517e-314, counted = 0x1014026c0, str = 0x1014026c0, arr = 0x1014026c0,
      obj = 0x1014026c0, res = 0x1014026c0, ref = 0x1014026c0, ast = 0x1014026c0, zv = 0x1014026c0,
      ptr = 0x1014026c0, ce = 0x1014026c0, func = 0x1014026c0, ww = {w1 = 20981440, w2 = 1}}, u1 = {
      v = {type = 6 '\006', type_flags = 0 '\000', u = {call_info = 0, extra = 0}}, type_info = 6},
    u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0, num_args = 0, fe_pos = 0,
      fe_iter_idx = 0, access_flags = 0, property_guard = 0, constant_flags = 0, extra = 0}}}
(gdb) p $9.val.value.str
$10 = (zend_string *) 0x1014026c0
(gdb) p *$9.val.value.str
$11 = {gc = {refcount = 1, u = {type_info = 70}}, h = 9223372247569412249, len = 5, val = "h"}
(gdb) p *$9.val.value.str.val@5
$12 = "hello"
 */
echo $a;

/*
(gdb) p z
$14 = (zval *) 0x101421090
(gdb) p *z
$15 = {value = {lval = 4315943304, dval = 2.1323593159049635e-314, counted = 0x101401188,
    str = 0x101401188, arr = 0x101401188, obj = 0x101401188, res = 0x101401188, ref = 0x101401188,
    ast = 0x101401188, zv = 0x101401188, ptr = 0x101401188, ce = 0x101401188, func = 0x101401188, ww = {
      w1 = 20976008, w2 = 1}}, u1 = {v = {type = 10 '\n', type_flags = 1 '\001', u = {call_info = 0,
        extra = 0}}, type_info = 266}, u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0,
    num_args = 0, fe_pos = 0, fe_iter_idx = 0, access_flags = 0, property_guard = 0,
    constant_flags = 0, extra = 0}}
(gdb) p $15.value.ref
$16 = (zend_reference *) 0x101401188
(gdb) p *$15.value.ref
$17 = {gc = {refcount = 2, u = {type_info = 10}}, val = {value = {lval = 4315948736,
      dval = 2.1323619996695517e-314, counted = 0x1014026c0, str = 0x1014026c0, arr = 0x1014026c0,
      obj = 0x1014026c0, res = 0x1014026c0, ref = 0x1014026c0, ast = 0x1014026c0, zv = 0x1014026c0,
      ptr = 0x1014026c0, ce = 0x1014026c0, func = 0x1014026c0, ww = {w1 = 20981440, w2 = 1}}, u1 = {
      v = {type = 6 '\006', type_flags = 0 '\000', u = {call_info = 0, extra = 0}}, type_info = 6},
    u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0, num_args = 0, fe_pos = 0,
      fe_iter_idx = 0, access_flags = 0, property_guard = 0, constant_flags = 0, extra = 0}}}
(gdb) p $17.val.value.str
$18 = (zend_string *) 0x1014026c0
(gdb) p *$17.val.value.str
$19 = {gc = {refcount = 1, u = {type_info = 70}}, h = 9223372247569412249, len = 5, val = "h"}
(gdb) p *$17.val.value.str.val@5
$20 = "hello"
 */
echo $b;

$b = 'world';

/*
(gdb) p z
$21 = (zval *) 0x101421080
(gdb) p *z
$22 = {value = {lval = 4315943304, dval = 2.1323593159049635e-314, counted = 0x101401188,
    str = 0x101401188, arr = 0x101401188, obj = 0x101401188, res = 0x101401188, ref = 0x101401188,
    ast = 0x101401188, zv = 0x101401188, ptr = 0x101401188, ce = 0x101401188, func = 0x101401188, ww = {
      w1 = 20976008, w2 = 1}}, u1 = {v = {type = 10 '\n', type_flags = 1 '\001', u = {call_info = 0,
        extra = 0}}, type_info = 266}, u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0,
    num_args = 0, fe_pos = 0, fe_iter_idx = 0, access_flags = 0, property_guard = 0,
    constant_flags = 0, extra = 0}}
(gdb) p $22.value.ref
$23 = (zend_reference *) 0x101401188
(gdb) p *$22.value.ref
$24 = {gc = {refcount = 2, u = {type_info = 10}}, val = {value = {lval = 4315948800,
      dval = 2.132362031289753e-314, counted = 0x101402700, str = 0x101402700, arr = 0x101402700,
      obj = 0x101402700, res = 0x101402700, ref = 0x101402700, ast = 0x101402700, zv = 0x101402700,
      ptr = 0x101402700, ce = 0x101402700, func = 0x101402700, ww = {w1 = 20981504, w2 = 1}}, u1 = {
      v = {type = 6 '\006', type_flags = 0 '\000', u = {call_info = 0, extra = 0}}, type_info = 6},
    u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0, num_args = 0, fe_pos = 0,
      fe_iter_idx = 0, access_flags = 0, property_guard = 0, constant_flags = 0, extra = 0}}}
(gdb) p $24.val.value.str
$25 = (zend_string *) 0x101402700
(gdb) p *$24.val.value.str
$26 = {gc = {refcount = 1, u = {type_info = 70}}, h = 9223372247587566957, len = 5, val = "w"}
(gdb) p *$24.val.value.str.val@5
$27 = "world"
 */
echo $a;

/*
(gdb) p z
$28 = (zval *) 0x101421090
(gdb) p *z
$29 = {value = {lval = 4315943304, dval = 2.1323593159049635e-314, counted = 0x101401188,
    str = 0x101401188, arr = 0x101401188, obj = 0x101401188, res = 0x101401188, ref = 0x101401188,
    ast = 0x101401188, zv = 0x101401188, ptr = 0x101401188, ce = 0x101401188, func = 0x101401188, ww = {
      w1 = 20976008, w2 = 1}}, u1 = {v = {type = 10 '\n', type_flags = 1 '\001', u = {call_info = 0,
        extra = 0}}, type_info = 266}, u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0,
    num_args = 0, fe_pos = 0, fe_iter_idx = 0, access_flags = 0, property_guard = 0,
    constant_flags = 0, extra = 0}}
(gdb) p $29.value.ref
$30 = (zend_reference *) 0x101401188
(gdb) p *$29.value.ref
$31 = {gc = {refcount = 2, u = {type_info = 10}}, val = {value = {lval = 4315948800,
      dval = 2.132362031289753e-314, counted = 0x101402700, str = 0x101402700, arr = 0x101402700,
      obj = 0x101402700, res = 0x101402700, ref = 0x101402700, ast = 0x101402700, zv = 0x101402700,
      ptr = 0x101402700, ce = 0x101402700, func = 0x101402700, ww = {w1 = 20981504, w2 = 1}}, u1 = {
      v = {type = 6 '\006', type_flags = 0 '\000', u = {call_info = 0, extra = 0}}, type_info = 6},
    u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0, num_args = 0, fe_pos = 0,
      fe_iter_idx = 0, access_flags = 0, property_guard = 0, constant_flags = 0, extra = 0}}}
(gdb) p $31.val.value.str
$32 = (zend_string *) 0x101402700
(gdb) p *$31.val.value.str
$33 = {gc = {refcount = 1, u = {type_info = 70}}, h = 9223372247587566957, len = 5, val = "w"}
(gdb) p *$31.val.value.str.val@5
$34 = "world"
*/
echo $b;

unset($b);

/*
(gdb) p z
$35 = (zval *) 0x101421080
(gdb) p *z
$36 = {value = {lval = 4315943304, dval = 2.1323593159049635e-314, counted = 0x101401188,
    str = 0x101401188, arr = 0x101401188, obj = 0x101401188, res = 0x101401188, ref = 0x101401188,
    ast = 0x101401188, zv = 0x101401188, ptr = 0x101401188, ce = 0x101401188, func = 0x101401188, ww = {
      w1 = 20976008, w2 = 1}}, u1 = {v = {type = 10 '\n', type_flags = 1 '\001', u = {call_info = 0,
        extra = 0}}, type_info = 266}, u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0,
    num_args = 0, fe_pos = 0, fe_iter_idx = 0, access_flags = 0, property_guard = 0,
    constant_flags = 0, extra = 0}}
(gdb) p $36.value.ref
$37 = (zend_reference *) 0x101401188
(gdb) p *$36.value.ref
$38 = {gc = {refcount = 1, u = {type_info = 10}}, val = {value = {lval = 4315948800,
      dval = 2.132362031289753e-314, counted = 0x101402700, str = 0x101402700, arr = 0x101402700,
      obj = 0x101402700, res = 0x101402700, ref = 0x101402700, ast = 0x101402700, zv = 0x101402700,
      ptr = 0x101402700, ce = 0x101402700, func = 0x101402700, ww = {w1 = 20981504, w2 = 1}}, u1 = {
      v = {type = 6 '\006', type_flags = 0 '\000', u = {call_info = 0, extra = 0}}, type_info = 6},
    u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0, num_args = 0, fe_pos = 0,
      fe_iter_idx = 0, access_flags = 0, property_guard = 0, constant_flags = 0, extra = 0}}}
(gdb) p $38.val.value.str
$39 = (zend_string *) 0x101402700
(gdb) p *$38.val.value.str
$40 = {gc = {refcount = 1, u = {type_info = 70}}, h = 9223372247587566957, len = 5, val = "w"}
(gdb) p *$38.val.value.str.val@5
$41 = "world"
 */
echo $a;

/*
(gdb) p z
$42 = (zval *) 0x101421090
(gdb) p *z
$43 = {value = {lval = 4315943304, dval = 2.1323593159049635e-314, counted = 0x101401188,
    str = 0x101401188, arr = 0x101401188, obj = 0x101401188, res = 0x101401188, ref = 0x101401188,
    ast = 0x101401188, zv = 0x101401188, ptr = 0x101401188, ce = 0x101401188, func = 0x101401188, ww = {
      w1 = 20976008, w2 = 1}}, u1 = {v = {type = 0 '\000', type_flags = 0 '\000', u = {call_info = 0,
        extra = 0}}, type_info = 0}, u2 = {next = 0, cache_slot = 0, opline_num = 0, lineno = 0,
    num_args = 0, fe_pos = 0, fe_iter_idx = 0, access_flags = 0, property_guard = 0,
    constant_flags = 0, extra = 0}}
 */
echo $b;

打赏
Posted in PHP
发表评论

电子邮件地址不会被公开。