Previously, I have described how to get information through the core file of PHP: How to debug the core of PHP to get the basic information , for the invocation of parameters this block, the introduction of the acquisition method is more complex.
So today I made an improvement for PHP 5.4 's. Gdbinit, and if you encounter the core of PHP 5.4, then you can simply get the information of the function call stack that contains the parameters when the core of PHP 5.4 occurs.
Suppose for the following script:
- <?php
- class Test {
- }
- function a($i) {
- b(new Test, 2.3432, "reader");
- }
- function b($i) {
- C(array(1,2,3));
- }
- function C($i) {
- D(TRUE);
- }
- function D($i) {
- $fp = fopen("/tmp/1.php", "R");
- e($fp);
- }
- function e($i) {
- Sleep(+);
- }
- a ();
After running in the background, PHP5.4 will sleep in the sleep of the E function, and if we use gdb attach up,
- GDB --pid= XXX //Use PS to get the PID of running script in background
Then, source PHP sources the following. Gdbinit:
- (gdb) Source Php54-src/.gdbini
Then, let's try calling the next zbacktrace to see what the results are:
- (GDB) Zbacktrace
- [0x2a95dac5e0] Sleep (/tmp/1.php:21)
- [0X2A95DAC4C0] e (Resource (#5))/tmp/1.php:17
- [0x2a95dac3f0] D (True)/tmp/1.php:13
- [0x2a95dac300] C (Array (3) [0x2a95de7db0])/tmp/1.php:10
- [0x2a95dac1c0] B (object[0x2a95de7840], 2.343200, "reader")/tmp/1.php:7
- [0x2a95dac0e8] A ()/tmp/1.php:2
Well, for the array and object, because we're not going to be messing around, so it's not unfolding, but if we want to see what this array is specifically about, you can do that, notice the above: Array (3) [0x2a95de7db0]:
- (GDB) print ((Zval *) 0x2a95de7db0)
- $4 = (struct _zval_struct *) 0x2a95de7db0
- (GDB) Printzv $4
- [0x2a95de7db0] (refcount=2) Array (3): {
- 0 = [0x2a95de79d0] (refcount=1) long:1
- 1 = [0x2a95de7b80] (refcount=1) long:2
- 2 = [0x2a95de7c98] (refcount=1) long:3
Similarly, for object, note the above: object[0x2a95de7840]
- (GDB) print ((Zval *) 0x2a95de7840)
- $ = (struct _zval_struct *) 0x2a95de7840
- (GDB) Printzv
- [0x2a95de7840] (refcount=2) object
- (Test) #1 "No properties found
One thing to note is that for object, if you are in the modal core file instead of attach to a running process, then the above attempt will get an error:
- (GDB) Printzv
- [0x2a95de7840] (refcount=2) objectyou can ' t do this without a process to debug
However, even so, we have a way, but it is more troublesome. Under NTS:
- (GDB) p ((Zval *) 0x2a95de7840)->value.obj.handle
- $6 = 1
- Note that the following value is used for this $6:1
- (GDB) p (zend_object*) Executor_globals->objects_store.object_buckets[1].bucket.obj.object
- $7 = (struct _zend_object *) 0x2a95de3ec0
- (GDB) P $9->ce->name
- $8 = 0x2a95e200b0 "Test
Oh, how, with this information, analysis of the reasons for the core, is it more simple? enjoy~
Finally, keep in mind that PHP 5.4 is still in development, and any new features may be adjusted or changed before final release. If you have any suggestions, also welcome feedback, help us make PHP better
Reproduce the call stack for PHP core