How to debug a segmentation fault?

php.internals

Benjamin Morel

6 years ago
Hi internals, I'm encountering a SIGSEGV in PHP-FPM on PHP 7.4.2 in a Symfony app. The bug seems to happen during the rendering of a Twig template; this makes it hard for me to pinpoint the code that triggers the segfault. Could you please tell me what the procedure to collect information is, so that I can file a useful bug report? Thank you, — Benjamin

tyson andre

6 years ago

Nikita Popov

6 years ago
On Tue, Jan 28, 2020 at 5:29 PM Benjamin Morel <benjamin.morel@gmail.com> wrote:
> Hi internals, > > I'm encountering a SIGSEGV in PHP-FPM on PHP 7.4.2 in a Symfony app. The > bug seems to happen during the rendering of a Twig template; this makes it > hard for me to pinpoint the code that triggers the segfault. > > Could you please tell me what the procedure to collect information is, so > that I can file a useful bug report? >
As the first step, I would always suggest to reproduce this issue with the CLI binary (this includes the builtin server under -S localhost:8000 -t public). That way you don't have to deal with multi-process FPM. Once that is done, the easiest way to get some useful debugging information is to run PHP under valgrind, this is done using "USE_ZEND_ALLOC=0 valgrind php ...". Nikita

Bishop Bettini

6 years ago
On Tue, Jan 28, 2020 at 11:28 AM Benjamin Morel <benjamin.morel@gmail.com> wrote:
> I'm encountering a SIGSEGV in PHP-FPM on PHP 7.4.2 in a Symfony app. The > bug seems to happen during the rendering of a Twig template; this makes it > hard for me to pinpoint the code that triggers the segfault. > > Could you please tell me what the procedure to collect information is, so > that I can file a useful bug report? >
Great advice so far. I would add, since you're using PHP-FPM, that the pool configuration needs to have: process.dumpable = 1 to get core dumps out of workers. Without this you might not get core dumps, even when you have other core dump settings configured (ulimit -c unlimited, chmod +r phpfpm, etc.).

Benjamin Morel

6 years ago
> > I would add, since you're using PHP-FPM, that the pool configuration needs > to have: > process.dumpable = 1
Thank you! I could not generate a core dump before adding this configuration option! The generating a gdb backtrace <https://bugs.php.net/bugs-generating-backtrace.php> page looks a big outdated, it would be nice if someone could update it will all the helpful info received in this thread. I'm not sure if I could gather helpful enough info about the issue, but anyway I filed a bug here: https://bugs.php.net/bug.php?id=79194 Thank you, Benjamin On Wed, 29 Jan 2020 at 18:19, Bishop Bettini <bishop@php.net> wrote:

tyson andre

6 years ago

tyson andre

6 years ago
Sorry, I didn't notice that https://bugs.php.net/bug.php?id=79194 was already closed with a similar answer.

tyson andre

6 years ago

Benjamin Morel

6 years ago
> > Infinite recursion leading to a segfault is **a known bug with no plans to > be fixed that I know of,** which I've encountered many times.
That's unfortunate; as I said in the bug report, it's so easy to trigger and so easy to miss when reviewing the code! And the process crashing instead of reporting an error is really a pity. An explicit error message would be nice, but as I understand this would require setting a hard limit on the call stack depth, which may bring other issues. Thank you, — Benjamin On Thu, 30 Jan 2020 at 03:59, tyson andre <tysonandre775@hotmail.com> wrote: