Home  >  Article  >  Backend Development  >  Debugging nginx with GDB

Debugging nginx with GDB

WBOY
WBOYOriginal
2016-08-08 09:24:411498browse

<code>阅读源码的最好方式就是跟踪调试代码,这里介绍了如何利用GDB调试nginx的配置和步骤。
</code>

Modify the configuration file

<code>修改nginx.conf:
</code>
<code><span>#user  nobody;</span>
master_process <span>off</span>;
daemon <span>off</span>;</code>

daemon off; means turning off the daemon process mode, which eliminates the need to use GDB to track the forked child process. If the daemon is enabled by default, standard output is closed. Therefore, if you turn off the daemon mode, you can use printf to easily view the value of the variable.
master_process off; means using the master process itself to process requests.

Debug code

<code>调试nginx和调试简单的单文件程序基本相同,只是在设置断点时有点差别。
在函数func_name处设置断点:`break func_name`,函数可以用<tab>键补全。
在file_name.c文件的第line行设置断点:`break file_name.c:line`
然后把代码跑起来就OK了,最常用的命令是backtrace,简写成bt。够简单吧,之后nginx的运行就都在你的掌控之中。
</code>

The above introduces the use of GDB to debug nginx, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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