0302 GDB调试走起【给PHP写插件】

编译安装

cd /home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29


#Zend:核心源码

# 查看配制选项,重要的是SAPI中的fpm,--debug,在make的时候gcc是o0,不会优化, 会显示细节,默认-o2
[parallels@eduline php-7.2.29]$ ./configure -h

./configure --prefix=/home/parallels/Sys/php71 --enable-fpm --enable-debug

make && make install

#可以看到过程
-I/usr/include -g -fvisibility=hidden **-O0** -Wall -DZEND_SIGNALS   -c /home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/Zend/zend_objects.c -o Zend/zend_objects.lo
/bin/sh /home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/libtool --silent --preserve-dup-deps --mode=compile cc 	-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -IZend/ -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/Zend/ -DPHP_ATOM_INC -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/include -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/main -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29 -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/ext/date/lib -I/usr/include/libxml2 -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/ext/sqlite3/libsqlite -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/TSRM -I/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/Zend
 
#安装完成
Installing shared extensions:     /home/parallels/Sys/php71/lib/php/extensions/debug-non-zts-20170718/
Installing PHP CLI binary:        /home/parallels/Sys/php71/bin/
Installing PHP CLI man page:      /home/parallels/Sys/php71/php/man/man1/
Installing PHP FPM binary:        /home/parallels/Sys/php71/sbin/
Installing PHP FPM defconfig:     /home/parallels/Sys/php71/etc/
Installing PHP FPM man page:      /home/parallels/Sys/php71/php/man/man8/
Installing PHP FPM status page:   /home/parallels/Sys/php71/php/php/fpm/
Installing phpdbg binary:         /home/parallels/Sys/php71/bin/
Installing phpdbg man page:       /home/parallels/Sys/php71/php/man/man1/
Installing PHP CGI binary:        /home/parallels/Sys/php71/bin/
Installing PHP CGI man page:      /home/parallels/Sys/php71/php/man/man1/
Installing build environment:     /home/parallels/Sys/php71/lib/php/build/
Installing header files:          /home/parallels/Sys/php71/include/php/
Installing helper programs:       /home/parallels/Sys/php71/bin/
  program: phpize
  program: php-config
Installing man pages:             /home/parallels/Sys/php71/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /home/parallels/Sys/php71/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.8
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.3
[PEAR] PEAR           - installed: 1.10.10
Warning! a PEAR user config file already exists from a previous PEAR installation at '/root/.pearrc'. You may probably want to remove it.
Wrote PEAR system config file at: /home/parallels/Sys/php71/etc/pear.conf
You may want to add: /home/parallels/Sys/php71/lib/php to your php.ini include_path
/home/parallels/Software/SysSoftware/php7internal/PHPtest/php-7.2.29/build/shtool install -c ext/phar/phar.phar /home/parallels/Sys/php71/bin
ln -s -f phar.phar /home/parallels/Sys/php71/bin/phar
Installing PDO headers:           /home/parallels/Sys/php71/include/php/ext/pdo/
# php 位置
/usr/local/Cellar/php@7.2

zval

// 位置:/usr/local/Cellar/php@7.2/7.2.27/include/php/Zend/zend_types.h
typedef union _zend_value {
	zend_long         lval;				/* long value */
	double            dval;				/* double value */
	zend_refcounted  *counted;
	zend_string      *str;
	zend_array       *arr;
	zend_object      *obj;
	zend_resource    *res;
	zend_reference   *ref;
	zend_ast_ref     *ast;
	zval             *zv;
	void             *ptr;
	zend_class_entry *ce;
	zend_function    *func;
	struct {
		uint32_t w1;
		uint32_t w2;
	} ww;
} zend_value;

struct _zval_struct {
	zend_value        value;			/* value */
	union {
		struct {
			ZEND_ENDIAN_LOHI_4(
				zend_uchar    type,			/* active type */
				zend_uchar    type_flags,
				zend_uchar    const_flags,
				zend_uchar    reserved)	    /* call info for EX(This) */
		} v;
		uint32_t type_info;
	} u1;
	union {
		uint32_t     next;                 /* hash collision chain */
		uint32_t     cache_slot;           /* literal cache slot */
		uint32_t     lineno;               /* line number (for ast nodes) */
		uint32_t     num_args;             /* arguments number for EX(This) */
		uint32_t     fe_pos;               /* foreach position */
		uint32_t     fe_iter_idx;          /* foreach iterator index */
		uint32_t     access_flags;         /* class constant access flags */
		uint32_t     property_guard;       /* single property guard */
		uint32_t     extra;                /* not further specified */
	} u2;
};

//搜索is_long
/* regular data types */
#define IS_UNDEF					0
#define IS_NULL						1
#define IS_FALSE					2
#define IS_TRUE						3
#define IS_LONG						4
#define IS_DOUBLE					5
#define IS_STRING					6
#define IS_ARRAY					7
#define IS_OBJECT					8
#define IS_RESOURCE					9
#define IS_REFERENCE				10

//搜索:
/* zval.u1.v.type_flags */
#define IS_TYPE_CONSTANT			(1<<0)
#define IS_TYPE_REFCOUNTED			(1<<2)
#define IS_TYPE_COPYABLE			(1<<4)


gdb 调试

UNIX及UNIX-like下的调试工具。或许,各位比较喜欢那种图形界面方式的,像VC、BCB等IDE的调试,但如果你是在 UNIX平台下做软件,你会发现GDB这个调试工具相比于VC、z的优点是具有修复网络断点以及恢复链接等功能,比BCB的图形化调试器有更强大的功能。

[root@eduline php-7.2.29]# yum install gdb
#进入调试模式
gdb /home/parallels/Sys/php71/bin/php
#打断点
b ZEND_ECHO_SPEC_CV_HANDLER
#运行
r /home/parallels/Software/SysSoftware/php7internal/chapter3/zval.php

#进入下一个断点continue
c

#单步执行next
n

# 查看指针
(gdb) p z
$1 = (zval *) 0x7ffff5e1e080
# 取值
(gdb) p *z
$2 = {value = {lval = 2, dval = 9.8813129168249309e-324,
    counted = 0x2, str = 0x2, arr = 0x2, obj = 0x2, res = 0x2,
    ref = 0x2, ast = 0x2, zv = 0x2, ptr = 0x2, ce = 0x2, func = 0x2,
    ww = {w1 = 2, 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, access_flags = 0, property_guard = 0, extra = 0}}
# 下一步
(gdb) n

# 问题:
Missing separate debuginfos, use: debuginfo-install glibc-2.17-292.el7.x86_64 libxml2-2.9.1-6.el7_2.3.x86_64 nss-softokn-freebl-3.44.0-8.el7_7.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-18.el7.x86_64

# 查找:debuginfo-install
yum whatprovides debuginfo-install

# 安装
yum install yum-utils

# 安装:
debuginfo-install glibc-2.17-292.el7.x86_64 libxml2-2.9.1-6.el7_2.3.x86_64 nss-softokn-freebl-3.44.0-8.el7_7.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-18.el7.x86_64

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值