~/codeDir/phpCode/test # cgdb php GNU gdb (GDB) 8.2 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-alpine-linux-musl". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from php...(no debugging symbols found)...done. (gdb)
然后在创建锁以及上锁的地方打断点:
1 2 3 4 5
(gdb) b zim_swoole_lock___construct Breakpoint 1 at 0x7ffff74d3ea0: file /root/codeDir/cCode/swoole-src-4.3.4/swoole_lock.c, line 88. (gdb) b zim_swoole_lock_lock Breakpoint 2 at 0x7ffff74d3ac0: file /usr/local/include/php/Zend/zend_types.h, line 411. (gdb)
我们执行一下程序:
1 2 3 4 5 6 7 8 9
(gdb) r test.php The program being debugged has been started already. Start it from the beginning? (y or n) y The program being debugged has been started already. Starting program: /usr/local/bin/php test.php
Breakpoint 1, zim_swoole_lock___construct (execute_data=0x7ffff761d110, return_value=0x7fffffffb0b0) at /root/codeDir/cCode/swoole-src-4.3.4/swoole_lock.c:88 warning: Source file is more recent than executable. (gdb)
1 2 3 4 5 6 7 8 9 10 11
87│ staticPHP_METHOD(swoole_lock, __construct) 88├>{ 89│ long type = SW_MUTEX; 90│ char *filelock; 91│ size_t filelock_len = 0; 92│ int ret; 93│ 94│ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ls", &type, &filelock, &filelock_len) == FAILURE) 95│ { 96│ RETURN_FALSE; 97│ }
在创建Swoole\Lock的地方触发了断点。
我们继续运行:
1 2 3 4 5 6
(gdb) c Continuing.
Breakpoint 2, zim_swoole_lock_lock (execute_data=0x7ffff767d130, return_value=0x7ffff7040f30) at /usr/local/include/php/Zend/zend_types.h:411 (gdb) n (gdb)
(gdb) thread [Current thread is 1 (process 39810)] (gdb)
OK,此时协程1在线程1里面。我们在协程sleep的地方打一个断点:
1 2 3
(gdb) b swoole::Coroutine::sleep Breakpoint 3 at 0x7ffff74579d0 (2 locations) (gdb)
我们继续执行:
1 2 3 4 5 6 7 8 9 10 11
(gdb) c Continuing.
Breakpoint 3, 0x00007ffff74579d0 in swoole::Coroutine::sleep(double)@plt () from /usr/local/lib/php/extensions/no-debug-non-zts-20180731/swoole.so (gdb) n Single stepping until exit from function _ZN6swoole9Coroutine5sleepEd@plt, which has no line number information.
Breakpoint 3, swoole::Coroutine::sleep (sec=1) at /root/codeDir/cCode/swoole-src-4.3.4/include/coroutine.h:145 (gdb) n (gdb)
(gdb) thread [Current thread is 1 (process 39810)] (gdb)
此时协程1还是处于线程1里面。
我们继续执行:
1 2 3 4 5 6
(gdb) c Continuing.
Breakpoint 2, zim_swoole_lock_lock (execute_data=0x7ffff767f130, return_value=0x7ffff6e3ff30) at /usr/local/include/php/Zend/zend_types.h:411 (gdb) n (gdb)