Home > PHP Framework > Swoole > What to use to debug swoole program

What to use to debug swoole program

angryTom
Release: 2020-02-12 14:01:08
Original
3418 people have browsed it

What to use to debug swoole program

What to use to debug the swoole program

You can use GDB to debug the swoole program. gdb is the abbreviation of GNU debugger, which is a programming debugging tool.

Function of gdb:

1. Start the program and run the program as you like according to user-defined requirements.

2. The debugged program can be stopped at the debugging breakpoint specified by the user (the breakpoint can be a conditional expression).

3. When the program stops, you can check what happened in the program at this time. For example, you can print the value of a variable.

4. Dynamically change the execution environment of the variable program.

Recommended learning: swoole tutorial

How to use gdb to debug swoole:

Enter gdb

gdb php test.php
Copy after login

gdbinit

(gdb) source /path/to/swoole-src/gdbinit
Copy after login

Set breakpoints

For example, co::sleep function

(gdb) b zim_swoole_coroutine_util_sleep
Copy after login

Print all coroutines and status of the current progress

(gdb) co_list 
coroutine 1 SW_CORO_YIELD
coroutine 2 SW_CORO_RUNNING
Copy after login

Print the current run The call stack of the current coroutine

(gdb) co_bt 
coroutine cid:[2]
[0x7ffff148a100] Swoole\Coroutine->sleep(0.500000) [internal function]
[0x7ffff148a0a0] {closure}() /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:7 
[0x7ffff141e0c0] go(object[0x7ffff141e110]) [internal function]
[0x7ffff141e030] (main) /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:10
Copy after login

Print the call stack of the specified coroutine ID

(gdb) co_bt 1
[0x7ffff1487100] Swoole\Coroutine->sleep(0.500000) [internal function]
[0x7ffff14870a0] {closure}() /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:3 
[0x7ffff141e0c0] go(object[0x7ffff141e110]) [internal function]
[0x7ffff141e030] (main) /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:10
Copy after login

Print the status of the serial coroutine

(gdb) co_status 
     stack_size: 2097152
     call_stack_size: 1
     active: 1
     coro_num: 2
     max_coro_num: 3000
     peak_coro_num: 2
Copy after login

The above is the detailed content of What to use to debug swoole program. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template