{"id":40,"date":"2011-05-26T10:42:08","date_gmt":"2011-05-26T02:42:08","guid":{"rendered":"http:\/\/www.sulabs.net\/?p=40"},"modified":"2017-01-09T10:34:36","modified_gmt":"2017-01-09T02:34:36","slug":"%e7%94%a8gdb-%e8%b0%83%e8%af%95-php-segmentation-fault-%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/www.sulabs.net\/?p=40","title":{"rendered":"\u7528GDB \u8c03\u8bd5 PHP Segmentation fault \u9519\u8bef"},"content":{"rendered":"<p>\u8f6c\u81ea <a href=\"http:\/\/hi.baidu.com\/thinkinginlamp\/blog\/item\/5e8062d9744f012511df9b93.html\">http:\/\/hi.baidu.com\/thinkinginlamp\/blog\/item\/5e8062d9744f012511df9b93.html<\/a><\/p>\n<p>Linux\u4e0b\uff0c<a href=\"http:\/\/en.wikipedia.org\/wiki\/Segmentation_fault\" target=\"_blank\">Segmentation fault<\/a>\u5f88\u5e38\u89c1\uff0c\u6b64\u65f6\uff0c\u4f7f\u7528GDB\u8c03\u8bd5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u786e\u5b9a\u51fa\u73b0\u9519\u8bef\u7684\u539f\u56e0\u3002<!--more--><\/p>\n<p>\u6211\u4eec\u5148\u60f3\u529e\u6cd5\u91cd\u73b0\u4e00\u4e0bSegmentation fault\u73b0\u8c61\uff0c\u4e0b\u9762\u6211\u4eec\u5148\u4f7f\u7528Shell\u7684\u65b9\u5f0f\u6765\u8bd5\u9a8c\uff0c\u7f16\u5199demo.sh\u811a\u672c\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\">#!\/bin\/bash<br \/>\nkill -s SEGV $$<\/span><\/p>\n<p>\u5176\u4e2d$$\u5c31\u662f\u811a\u672c\u7684\u8fdb\u7a0b\u53f7\uff0cSEGV\u4fe1\u53f7\u7684\u4f5c\u7528\u7b49\u540c\u4e8eSegmentation fault\uff0c\u6574\u53e5\u57fa\u672c\u610f\u601d\u5c31\u662f\u8ba9\u81ea\u5df1\u5d29\u6e83\u3002<\/p>\n<p>\u4fdd\u5b58\u597d\uff0c\u5e76\u4e14\u52a0\u4e0a\u6267\u884c\u6743\u9650\uff1achmod +x demo.sh<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\"># <strong>.\/demo.sh<\/strong><br \/>\nSegmentation fault<\/span><\/p>\n<p>\u5728\u51fa\u73b0Segmentation fault\u7684\u65f6\u5019\uff0cLinux\u6709\u80fd\u529b\u751f\u6210\u4e00\u4efdCore Dump\u6587\u4ef6\uff0c\u6211\u4eec\u6fc0\u6d3b\u8fd9\u79cd\u80fd\u529b\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\"># <strong>ulimit -c unlimited<\/strong><\/span><\/p>\n<p>\u751f\u6210\u7684Core Dump\u6587\u4ef6\u7684\u5177\u4f53\u4fe1\u606f\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u67e5\u770b\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\"># <strong>cat \/proc\/sys\/kernel\/core_pattern<\/strong><br \/>\ncore<\/span><\/p>\n<p>\u8fd9\u8868\u793a\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u751f\u6210core\u6587\u4ef6\uff0c\u63a5\u7740\u8fd0\u884c\u4e00\u6b21demo.sh\u6587\u4ef6\u5c31\u80fd\u751f\u6210core\u6587\u4ef6\u4e86\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\"># <strong>.\/demo.sh<\/strong><br \/>\nSegmentation fault (core dumped)<br \/>\n# <strong>ls<\/strong><br \/>\ncore.16069<\/span><\/p>\n<p>\u4e0b\u9762\u5230\u4e86\u4f7f\u7528gdb\u7684\u65f6\u5019\u4e86\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\"># <strong>gdb \/bin\/bash core.16069<\/strong><br \/>\n(gdb) <strong>bt<\/strong><br \/>\n#0 0x00c7c410 in __kernel_vsyscall ()<br \/>\n#1 0x00733146 in kill () from \/lib\/libc.so.6<br \/>\n#2 0x0807a561 in kill_pid ()<br \/>\n#3 0x080a2b9f in kill_builtin ()<br \/>\n#4 0x0806b81c in dispose_exec_redirects ()<br \/>\n#5 0x0806d010 in new_fd_bitmap ()<br \/>\n#6 0x0806dc17 in execute_command_internal ()<br \/>\n#7 0x0806f443 in execute_command ()<br \/>\n#8 0x0805ed21 in reader_loop ()<br \/>\n#9 0x0805e817 in main ()<\/span><\/p>\n<p>\u81f3\u4e8e\u8fd9\u4e9b\u5806\u6808\u4fe1\u606f\u600e\u4e48\u770b\u5c31\u9760\u4f60\u81ea\u5df1\u7684\u7ecf\u9a8c\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u518d\u770b\u4e00\u4e2aGDB\u8c03\u8bd5PHP\u811a\u672c\u7684\u4f8b\u5b50\uff1a\u4e00\u822c\u6765\u8bf4\uff0cPHP\u7a0b\u5e8f\u5458\u9047\u5230Segmentation fault\u7684\u60c5\u51b5\u5e76\u4e0d\u591a\uff0c\u4e0d\u8fc7\u6709\u65f6\u5019PHP\u5185\u90e8\u7684Bug\u8fd8\u662f\u53ef\u80fd\u89e6\u53d1\u8fd9\u7c7b\u9519\u8bef\uff0c\u800c\u4e14\u4e00\u65e6\u51fa\u73b0\uff0c\u6ca1\u6709\u660e\u786e\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u4e0d\u6613\u786e\u5b9a\u539f\u56e0\u3002\u6211\u8fd9\u91cc\u4e3e\u7684\u4f8b\u5b50\u662f\u5f53\u524dCURL\u6a21\u5757\u7684\u4e00\u4e2aBug\uff0c\u7248\u672c\u4fe1\u606f\u662fPHP 5.2.9\uff0cCURL 7.15.5\u3002<\/p>\n<p>\u7f16\u5199\u811a\u672cdemo.php\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\">&lt;?php<br \/>\n$url = \"http:\/\/localhost\/\";<\/span><\/p>\n<p>$ch = curl_init();<\/p>\n<p>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br \/>\ncurl_setopt($ch, CURLOPT_POST, 1);<br \/>\ncurl_setopt($ch, CURLOPT_POSTFIELDS, array('Hello' =&gt; 'World'));<br \/>\ncurl_setopt($ch, CURLOPT_URL, $url);<\/p>\n<p>$copy = curl_copy_handle($ch);<\/p>\n<p>curl_close($ch);<\/p>\n<p>curl_exec($copy);<\/p>\n<p>curl_close($copy);<br \/>\n?&gt;<\/p>\n<p>\u6267\u884c\u811a\u672c\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\"># <strong>php demo.php<\/strong><br \/>\nSegmentation fault (core dumped)<\/span><\/p>\n<p>\u4e0d\u51fa\u6240\u6599\u7684\u8bdd\u5c31\u4f1a\u51fa\u73b0Segmentation fault\u9519\u8bef\uff0c\u8fd8\u6709Core Dump\u6587\u4ef6\u3002\u8fd9\u6b21\u6211\u4eec\u6362\u4e00\u4e2aGDB\u8c03\u7528\u65b9\u5f0f\uff1a<\/p>\n<p><span style=\"font-family: \u5b8b\u4f53;\"># <strong>gdb php<\/strong><br \/>\nGNU gdb Red Hat Linux (6.5-37.el5rh)<br \/>\nCopyright (C) 2006 Free Software Foundation, Inc.<br \/>\nGDB is free software, covered by the GNU General Public License, and you are<br \/>\nwelcome to change it and\/or distribute copies of it under certain conditions.<br \/>\nType \"show copying\" to see the conditions.<br \/>\nThere is absolutely no warranty for GDB. Type \"show warranty\" for details.<br \/>\nThis GDB was configured as \"i386-redhat-linux-gnu\"...Using host libthread_db library \"\/lib\/libthread_db.so.1\".<\/span><\/p>\n<p>(gdb) <strong>run demo.php<\/strong><br \/>\nStarting program: \/usr\/local\/php\/bin\/php demo.php<br \/>\n[Thread debugging using libthread_db enabled]<br \/>\n[New Thread -1208236336 (LWP 11970)]<\/p>\n<p>Program received signal SIGSEGV, Segmentation fault.<br \/>\n[Switching to Thread -1208236336 (LWP 11970)]<br \/>\n0x010200a5 in memcpy () from \/lib\/libc.so.6<br \/>\n(gdb) <strong>bt<\/strong><br \/>\n#0 0x010200a5 in memcpy () from \/lib\/libc.so.6<br \/>\n#1 0x002423b3 in Curl_FormBoundary () from \/usr\/lib\/libcurl.so.3<br \/>\n#2 0x0024268f in Curl_getFormData () from \/usr\/lib\/libcurl.so.3<br \/>\n#3 0x00247a13 in Curl_http () from \/usr\/lib\/libcurl.so.3<br \/>\n#4 0x002529b0 in Curl_do () from \/usr\/lib\/libcurl.so.3<br \/>\n#5 0x0025ebe7 in Curl_perform () from \/usr\/lib\/libcurl.so.3<br \/>\n#6 0x0025f1d9 in curl_easy_perform () from \/usr\/lib\/libcurl.so.3<br \/>\n#7 0x080c5808 in zif_curl_exec ...<\/p>\n<p>\u5982\u679c\u811a\u672c\u4ee3\u7801\u5f88\u591a\uff0c\u4ec0\u4e48mysql, gd, curl\u4e00\u5927\u5806\u7684\u8bdd\uff0c\u901a\u8fc7\u4e0a\u9762\u7684\u8c03\u8bd5\u4fe1\u606f\uff0c\u5e94\u8be5\u7acb\u523b\u5c31\u80fd\u5224\u65ad\u51fa\u662fCURL\u6a21\u5757\u7684\u95ee\u9898\uff0c\u8fd9\u65e0\u7591\u4f1a\u5927\u5927\u8282\u7701\u6211\u4eec\u7684\u65f6\u95f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea http:\/\/hi.baidu.com\/thinkinginlamp\/bl &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/www.sulabs.net\/?p=40\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-other"],"_links":{"self":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":3,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":740,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions\/740"}],"wp:attachment":[{"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sulabs.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}