<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>https://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>https://jackxiang.com/post//</link>
<title><![CDATA[[实践OK]php的coredump怎么看?段错误等造成死机问题的分析， apache的coredump文件及其它像swoole这样的出现崩溃查找问题在哪行的原理。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Fri, 14 Nov 2014 08:58:52 +0000</pubDate> 
<guid>https://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	设置一下吐核，按Swoole官方的Wiki教程，设置一下吐核，From: https://wiki.swoole.com/wiki/page/10.html ：<br/>一、开启CoreDump：<br/>ulimit -c&nbsp;&nbsp; #查看<br/>#ulimit -c unlimited<br/>使用gdb来查看core dump信息。core文件一般在当前目录，如果操作系统做了处理，将core dump文件放置到其他目录，请替换为相应的路径<br/><br/><br/>二、设置内核参数将吐的核放到指定目录下指定格式存放：<br/>kernel.core_pattern = /data/core_files/core-%e-%p-%t<br/>通过ulimit -c命令查看当前coredump文件的限制<br/>ulimit -c<br/>打开core dump<br/>ulimit -c unlimited<br/><br/>三、调试：<br/>#gdb /usr/bin/httpd core.123<br/>gdb /usr/local/nginx/sbin/nginx core.456<br/><br/>四、在GDB里使用bt命令调试等：<br/>在gdb下输入bt查看调用栈信息<br/><br/>(gdb)bt<br/>Program terminated with signal 11, Segmentation fault.<br/>#0&nbsp;&nbsp;0x00007f1cdbe205e0 in swServer_onTimer (reactor=&lt;value optimized out&gt;, event=...)&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;at /usr/local/php/swoole-swoole-1.5.9b/src/network/Server.c:92<br/>92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serv-&gt;onTimer(serv, timer_node-&gt;interval);<br/>Missing separate debuginfos, use: debuginfo-install php-cli-5.3.3-22.el6.x86_64<br/>在gdb中使用f指令查看代码段<br/><br/>(gdb)f 1<br/>(gdb)f 0<br/><br/>五、像这种退出不是段错误，没有Coredump的：<br/>==&gt; /data/logs/nginx/error.log &lt;==<br/><br/>2017/08/16 11:56:52 [notice] 41234#0: signal 17 (SIGCHLD) received<br/>2017/08/16 11:56:52 [notice] 41234#0: worker process 41237 exited with code 2<br/>2017/08/16 11:56:52 [alert] 41234#0: worker process 41237 exited with fatal code 2 and cannot be respawned<br/>2017/08/16 11:56:52 [notice] 41234#0: signal 29 (SIGIO) received<br/>2017/08/16 11:56:52 [emerg] 41236#0: load ip map file error: /usr/local/nginx/conf/ip.map<br/><br/>2017/08/16 11:56:52 [notice] 41234#0: signal 17 (SIGCHLD) received<br/>2017/08/16 11:56:52 [notice] 41234#0: worker process 41236 exited with code 2<br/>2017/08/16 11:56:52 [alert] 41234#0: worker process 41236 exited with fatal code 2 and cannot be respawned<br/>原因是：一个文件不存在，故意移动了下：<br/>mv /usr/local/nginx/conf/ip.map /usr/local/nginx/conf/ip.map.bak<br/>===================================================================================<br/>使用gdb来查看core dump信息。core文件一般在当前目录，如果操作系统做了处理，将core dump文件放置到其他目录，请替换为相应的路径<br/>gdb php core <br/>gdb php /tmp/core.4596<br/>在gdb下输入bt查看调用栈信息<br/>(gdb)bt<br/>Program terminated with signal 11, Segmentation fault.<br/>#0&nbsp;&nbsp;0x00007f1cdbe205e0 in swServer_onTimer (reactor=&lt;value optimized out&gt;, event=...)&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;at /usr/local/php/swoole-swoole-1.5.9b/src/network/Server.c:92<br/>92&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serv-&gt;onTimer(serv, timer_node-&gt;interval);<br/>Missing separate debuginfos, use: debuginfo-install php-cli-5.3.3-22.el6.x86_64<br/>在gdb中使用f指令查看代码段<br/>(gdb)f 1<br/>(gdb)f 0<br/><br/><br/>对gdb下f命令的实践，能显示哪一行出了问题：<br/>(gdb) bt<br/>#0&nbsp;&nbsp;0x00007ffff7b01980 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:81<br/>#1&nbsp;&nbsp;0x00007ffff7a924a0 in _IO_new_file_underflow (fp=0x7ffff7dd5640 &lt;_IO_2_1_stdin_&gt;) at fileops.c:612<br/>#2&nbsp;&nbsp;0x00007ffff7a9342e in __GI__IO_default_uflow (fp=0x7ffff7dd5640 &lt;_IO_2_1_stdin_&gt;) at genops.c:436<br/>#3&nbsp;&nbsp;0x00007ffff7a753b3 in _IO_vfscanf_internal (s=&lt;optimized out&gt;, format=&lt;optimized out&gt;, argptr=argptr@entry=0x7fffffffe368, errp=errp@entry=0x0) at vfscanf.c:600<br/>#4&nbsp;&nbsp;0x00007ffff7a83a19 in __isoc99_scanf (format=&lt;optimized out&gt;) at isoc99_scanf.c:37<br/>#5&nbsp;&nbsp;0x00000000004006d4 in creat () at nodedemo.c:24<br/>#6&nbsp;&nbsp;0x000000000040075b in main () at nodedemo.c:46<br/>(gdb) f 5<br/>#5&nbsp;&nbsp;0x00000000004006d4 in creat () at nodedemo.c:24<br/>24&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>(gdb) f 2<br/>#2&nbsp;&nbsp;0x00007ffff7a9342e in __GI__IO_default_uflow (fp=0x7ffff7dd5640 &lt;_IO_2_1_stdin_&gt;) at genops.c:436<br/>436&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ch = _IO_UNDERFLOW (fp);<br/><br/><br/>如果为0，需要修改/etc/security/limits.conf，进行limit设置。<br/>开启core-dump后，一旦程序发生异常，会将进程导出到文件。对于调查程序问题有很大的帮助<br/>来自：http://wiki.swoole.com/wiki/page/10.html http://wiki.swoole.com/wiki/page/11.html<br/>—————————————————————————————————————————————<br/><br/>记录一下。<br/>1. ulimit -S -c unlimited<br/>2. 在apache主配置文件中增加一行：CoreDumpDirectory /var/apache_coredump #目录随意<br/>3. chown修改/var/apache_coredump的权限为apache子进程可写<br/><br/>注意：不要开启太久，core文件太多。占用太多磁盘空间<br/>调试<br/>gdb /usr/bin/httpd core.123<br/> apache的coredump <br/><br/>来自：http://5iwww.blog.51cto.com/856039/761077<br/><br/> 在实际工作当中，通过会出现某个应用造成死机问题。如何解决该问题。<br/>方法一：最简单办法，看打印，通过反复调试，看是哪条语句造成造成了死机。这种方法效率低，而且有时不准确，比如一个系统中有多个进程，但A进程跑的B断点是，出现段错误，系统发出11号信号，造成B，C等进程接到11号信号反初始化而推出。实际当中可能不一定是A进程原因，因为此时B，C等进程也在并发执行，甚至A，B，c 三个进程都在访问某一共享资源（如共享内存等）。<br/><br/>方法二：让内核通过OOPS打出堆栈信息，PC指针和链接指针，进行pc指针分析或者堆栈回溯<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;内核默认是不支持OOPS打印，需要内核配置开关打开。通常内为了了优化性能，调试开关都不会打开，需要我们根据实际需要打开某些调试开关。<br/>OOPS打出来可以看到：pc指针，LR链接库指针，CPU各个寄存器信息，堆栈信息。<br/><br/>简单情况：<br/>从OOPS知道PC指针，如果该进程是没有调用库，可以直接将该进程反汇编 objdump -D -S&nbsp;&nbsp;xxx进程名&gt;124.txt<br/>再从123.txt找到该PC指针位置对于的C代码行，即可定位。<br/>对于情况还可以使用addr2line&nbsp;&nbsp;PC指针&nbsp;&nbsp;-e&nbsp;&nbsp;xxxx进程名 -f定位到某个C代码行<br/>复杂情况：<br/>如果一个进程包含很多库，甚至要调用底层驱动，定位起来就更加麻烦。<br/>首先看pc指针地址确认是在死在内核态和用户态。还是KO模块，不同处理器架构不一样，可以看内核地址映射表&nbsp;&nbsp;system.map<br/>比如在MIPS系统中<br/>用户程序地址空间：&nbsp;&nbsp;&nbsp;&nbsp;0x00000000~0x7FFFFFFF；<br/>内核地址空间：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.map文件中的_stext ~_etext，大概是0x80000000~0x80300000；<br/>可加载模块地址空间：0xC0000000~0xC0800000<br/>如果在用户空间：<br/>首先通过cat /proc./pid/maps<br/>查看 pc=xxxx 指针所在库，比如pc指针所在库为xxx.so ,而xx.so的地址访问为aaa~bbb<br/>那么pc指针再 xxx.so库中偏移地址为xxx-aaa=ccc<br/>对xxx.so&nbsp;&nbsp;进行反汇编，objdump -D -S &gt;345.txt<br/>查找到ccc行就能找到对应行。<br/>注意该进程以及改进程所在的库编译是必需加-g ,也不能strip，否则反汇编出来没有C代码的映射行<br/>如果是在内核空间，可以通过堆栈回溯法进程回溯。该方法需要熟悉汇编，其次需要耐心，这里不详述。<br/>堆栈回溯法出来OOPS<br/>&nbsp;&nbsp;通过反汇编，然后堆栈回溯，找到出问题的函数，该方法需要熟悉汇编，其次需要耐心，这里不详述。<br/><br/>方法三：coredump分析法<br/>对于死机问题，某些情况下OOPS打印出来的信息不足以分析。coreDump给了个详细的方法。<br/>首先在内核当中打开coredup&nbsp;&nbsp;开关，死机后就会产生一个core问题，事后可以通过 gdb调试方法来分析定位死机的位置。<br/><br/>摘自：http://blog.csdn.net/fengliang191/article/details/36894103
]]>
</description>
</item><item>
<link>https://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]php的coredump怎么看?段错误等造成死机问题的分析， apache的coredump文件及其它像swoole这样的出现崩溃查找问题在哪行的原理。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>