Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segmentation fault (core dumped) in PHP

Tags:

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.

like image 261
leyou Avatar asked Oct 11 '14 15:10

leyou


People also ask

Is core dumped a segmentation fault?

Core Dump (Segmentation fault) in C/C++ Core Dump/Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.” When a piece of code tries to do read and write operation in a read only location in memory or freed block of memory, it is known as core dump.

What causes PHP segmentation fault?

Because of the Memory Access Violation, a segmentation fault occurs. The error happens when a software tries to access a memory block that it is not permitted to access. To put it another way, you're approaching a memory location that isn't yours.

What is causing segfault?

A segmentation fault (aka segfault) is a common condition that causes programs to crash; they are often associated with a file named core . Segfaults are caused by a program trying to read or write an illegal memory location.


1 Answers

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.

like image 56
Ulrich Eckhardt Avatar answered Sep 21 '22 06:09

Ulrich Eckhardt