mac上分析coredump文件

首先 开启 ulimit -c unlimited.
$dphpcbf -vvv src/Client/AthenaApiV3Client.php
Segmentation fault: 11 (core dumped)



$gdb -c /cores/core.63911
GNU gdb (GDB) 8.0
Copyright (C) 2017 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-apple-darwin15.0.0”.
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”.
“/cores/core.63911”: no core file handler recognizes format
(gdb) bt
No stack.
(gdb) where
No stack.
(gdb) quit

$lldb -c /cores/core.63911
(lldb) target create –core “/cores/core.63911”
warning: (x86_64) /cores/core.63911 load command 108 LC_SEGMENT_64 has a fileoff + filesize (0x28a0e000) that extends beyond the end of the file (0x28a0d000), the segment will be truncated to match
warning: (x86_64) /cores/core.63911 load command 109 LC_SEGMENT_64 has a fileoff (0x28a0e000) that extends beyond the end of the file (0x28a0d000), ignoring this section
Core file ‘/cores/core.63911’ (x86_64) was loaded.
(lldb) bt



  • thread #1: tid = 0x0000, 0x00007fff9a84fd32 libsystem_c.dylib`strlen + 18, stop reason = signal SIGSTOP

    • frame #0: 0x00007fff9a84fd32 libsystem_c.dylibstrlen + 18
      frame #1: 0x0000000105f0a95e myFile.so
      my_execute_ex(execute_data=0x00000001058186c0) + 830 at myFile.c:260
      frame #2: 0x0000000104ceb7e3 phpzend_call_function(fci=0x00007fff5b3e00c0, fci_cache=0x00007fff5b3e0030) + 2803 at zend_execute_API.c:837
      frame #3: 0x0000000104d37145 php
      zend_call_method(object=0x0000000000000000, obj_ce=0x0000000105807910, fn_proxy=0x000000010588e000, function_name=”composerautoloaderinit39791d212565a96d248c39975a86f0d4::loadclassloader”, function_name_len=71, retval_ptr=0x0000000000000000, param_count=1, arg1=0x00000001058186b0, arg2=0x0000000000000000) + 1221 at zend_interfaces.c:102
      frame #4: 0x0000000104b3dfc1 phpzif_spl_autoload_call(execute_data=0x0000000105818660, return_value=0x00007fff5b3e04d8) + 417 at php_spl.c:408
      frame #5: 0x0000000104ceb8b2 php
      zend_call_function(fci=0x00007fff5b3e0498, fci_cache=0x00007fff5b3e0470) + 3010 at zend_execute_API.c:850
      frame #6: 0x0000000104cec27e phpzend_lookup_class_ex(name=0x00000001058038a0, key=0x0000000105867810, use_autoload=1) + 1278 at zend_execute_API.c:1009
      frame #7: 0x0000000104ced39f php
      zend_fetch_class_by_name(class_name=0x00000001058038a0, key=0x0000000105867810, fetch_type=512) + 79 at zend_execute_API.c:1442
      frame #8: 0x0000000104d9ab2e phpZEND_NEW_SPEC_CONST_HANDLER(execute_data=0x0000000105818360) + 158 at zend_vm_execute.h:3156
      frame #9: 0x0000000104d6e964 php
      execute_ex(ex=0x0000000105818360) + 100 at zend_vm_execute.h:432
      frame #10: 0x0000000105f0a8ed myFile.somy_execute_ex(execute_data=0x0000000105818360) + 717 at myFile.c:255
      frame #11: 0x0000000104d98d00 php
      ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER(execute_data=0x00000001058182f0) + 672 at zend_vm_execute.h:1076
      frame #12: 0x0000000104d6e964 phpexecute_ex(ex=0x00000001058182f0) + 100 at zend_vm_execute.h:432
      frame #13: 0x0000000105f0a77a myFile.so
      my_execute_ex(execute_data=0x00000001058182f0) + 346 at myFile.c:236
      frame #14: 0x0000000104da086f phpZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER(execute_data=0x0000000105818030) + 703 at zend_vm_execute.h:35202
      frame #15: 0x0000000104d6e964 php
      execute_ex(ex=0x0000000105818030) + 100 at zend_vm_execute.h:432
      frame #16: 0x0000000105f0a8ed myFile.somy_execute_ex(execute_data=0x0000000105818030) + 717 at myFile.c:255
      frame #17: 0x0000000104d6eb6a php
      zend_execute(op_array=0x0000000105875400, return_value=0x0000000000000000) + 234 at zend_vm_execute.h:474
      frame #18: 0x0000000104d07f12 phpzend_execute_scripts(type=8, retval=0x0000000000000000, file_count=3) + 594 at zend.c:1447
      frame #19: 0x0000000104c5d721 php
      php_execute_script(primary_file=0x00007fff5b3e1848) + 1201 at main.c:2533
      frame #20: 0x0000000104e232b5 phpdo_cli(argc=4, argv=0x00007fff5b3e1f70) + 3941 at php_cli.c:990
      frame #21: 0x0000000104e2215a php
      main(argc=4, argv=0x00007fff5b3e1f70) + 1898 at php_cli.c:1378
      frame #22: 0x00007fff8ad7c5ad libdyld.dylib`start + 1
      (lldb) where
      error: ‘where’ is not a valid command.
      error: Unrecognized command ‘where’.
      (lldb)





问题原因



frame #1: 0x0000000105f0a95e myFile.so`my_execute_ex(execute_data=0x00000001058186c0) + 830 at myFile.c:260



frame #10: 0x0000000105f0a8ed myFile.so`my_execute_ex(execute_data=0x0000000105818360) + 717 at myFile.c:255



vi myFile.c



func_name[len+1]=’\0’;
efree(timeElipsed);
efree(func_name);
save_log(logMsg);
efree(logMsg);



这几个free 没有判断是否为空引起的



解决办法
$vi /usr/local/lib/php.ini
注释掉扩展
;extension=/usr/local/lib/php/extensions/debug-non-zts-20160303/myFile.so



问题解决



Category linux