gdb 调试 php-cp扩展 redisProxy与pool_server的长连接

 

1.安装gdb 

sudo apt-get install gdb

2.进入php-cp扩展目录(已经编译过了),源码

https://github.com/swoole/php-cp

获取要调试函数的真实函数名 zim_redis_connect_pool_select

$ nm connect_pool.so

....
0000000000012170 t zim_redis_connect_pool___construct.localalias.9
0000000000012160 T zim_redis_connect_pool___destruct
0000000000012910 T zim_redis_connect_pool_done
00000000000120a0 T zim_redis_connect_pool_release
0000000000012350 T zim_redis_connect_pool_select #重点关注
00000000000120c0 T zim_redis_connect_pool_setAsync
0000000000016ca0 T zim_swSerialize___construct
0000000000019680 T zim_swSerialize___destruct
....

3.进入gdb调试

$ gdb php

...
(gdb) break zim_redis_connect_pool_select  #交互,设置断点
Function "zim_redis_connect_pool_select" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (zim_redis_connect_pool_select) pending.
(gdb) run /usr/local/openresty/nginx/html/test_connect_pool.php #运行脚本,脚本中使用了扩展中定义的的函数
Starting program: /usr/bin/php /usr/local/openresty/nginx/html/test_connect_pool.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, zim_redis_connect_pool_select (execute_data=0x7ffff321d160, 
    return_value=0x7fffffffa640)
    at /mnt/share/php-cp/connect_pool_client.c:1135
1135	{
(gdb) l                     //输入l
1130	    zend_update_property_string(redis_connect_pool_class_entry_ptr, object, ZEND_STRL("auth"), auth TSRMLS_CC);
1131	
1132	}
1133	
1134	PHP_METHOD(redis_connect_pool, select)
1135	{
1136	    zval *ip, *port, *z_args, *pass_data, *object, *auth;
1137	    char source_char[CP_SOURCE_MAX] = {0};
1138	    char *db;
1139	    zend_size_t db_len;
(gdb) 

通信过程:共享内存,pipe,reactor模式

你可能感兴趣的:(php)