leyou
leyou

Reputation: 817

Segmentation fault (core dumped) in PHP

Ok, I'm running a PHP app on command line on Ubuntu, and it ends with "Segmentation fault (core dumped)".

How do I go from here to debug it? I'm pretty sure there is no memory leak as I checked it already with get_memory_usage().

Edit: Alright, as explained by Brendan and Ulricht, I tried gdb. That's not my environment at all so sorry for the oncoming newbie questions.

I ran my code under gdb and got the segfault. Here are the first 22 lines.

(gdb) bt
#0  0x00000000006f5d36 in ?? ()
#1  0x00000000006f7625 in ?? ()
#2  0x00000000006f7b68 in zend_parse_parameters ()
#3  0x0000000000610584 in zif_array_rand ()
#4  0x00000000006dd9bb in dtrace_execute_internal ()
#5  0x000000000079da15 in ?? ()
#6  0x0000000000717748 in execute_ex ()
#7  0x00000000006dd8b9 in dtrace_execute_ex ()
#8  0x000000000079e060 in ?? ()
#9  0x0000000000717748 in execute_ex ()
#10 0x00000000006dd8b9 in dtrace_execute_ex ()
#11 0x000000000079e060 in ?? ()
#12 0x0000000000717748 in execute_ex ()
#13 0x00000000006dd8b9 in dtrace_execute_ex ()
#14 0x000000000079e060 in ?? ()
#15 0x0000000000717748 in execute_ex ()
#16 0x00000000006dd8b9 in dtrace_execute_ex ()
#17 0x000000000079e060 in ?? ()
#18 0x0000000000717748 in execute_ex ()
#19 0x00000000006dd8b9 in dtrace_execute_ex ()
#20 0x000000000079e060 in ?? ()
#21 0x0000000000717748 in execute_ex ()
#22 0x00000000006dd8b9 in dtrace_execute_ex ()

According to https://bugs.php.net/bugs-generating-backtrace.php, I should get "execute" calls, instead I have "execute_ex". Same thing?

The following command anyway does not return the function name (after having done frame 6):

print (char *)(executor_globals.function_state_ptr->function)->common.function_name
Attempt to extract a component of a value that is not a structure.

Edit2: I'd appreciate knowing why the downvote. I think it's a valid question and I haven't found a similar one for PHP. If there is then you're free to comment.

Upvotes: 8

Views: 7695

Answers (1)

Ulrich Eckhardt
Ulrich Eckhardt

Reputation: 17444

There are several things to pinpoint the error, but the first is to run the executable in gdb:

> gdb /usr/bin/php
....
(gdb) run path/to/script

Note that you can also load the dumped core into gdb. Other tools for finding out what could cause the issue are strace and valgrind.

Upvotes: 4

Related Questions