We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

A segmentation fault has occurred

I created an environment of Apache / 2.4.38 + PHP 7.3.4-2 + Phalcon3.4.4 with Docker. While proceeding according to the tutorial, if you proceed with step execution (I use PhpStorm2019.2), the process will return to the beginning of the file. The Apache log says Segmentation fault, but I don't know how to solve it or avoid the error.

I will show you what I need, so I would like to tell you a lot.

The following is the state when gdb is started. I have a core file, but I don't know how to attach it.

# gdb /usr/sbin/apache2 -c /tmp/core.8c1df7aa85a1.apache2.1565406013
GNU gdb (Debian 8.2.1-2) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <https://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/sbin/apache2...(no debugging symbols found)...done.
[New LWP 540]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/usr/sbin/apache2 -D FOREGROUND'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  zval_get_type (pz=0x0) at /usr/include/php/20180731/Zend/zend_types.h:411

warning: Source file is more recent than executable.
411             return pz->u1.v.type;
(gdb) quit
[email protected]:/# cp /tmp/core.8c1df7aa85a1.apache2.1565406013 /etc/php
php/          php.append.d/ php.extra.d/
[email protected]:/# cp /tmp/core.8c1df7aa85a1.apache2.1565406013 /etc/php.append
[email protected]:/# cp /tmp/core.8c1df7aa85a1.apache2.1565406013 /etc/php.extra.d/
[email protected]:/# gdb /usr/sbin/apache2 -c /tmp/core.8c1df7aa85a1.apache2.1565406013
GNU gdb (Debian 8.2.1-2) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <https://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/sbin/apache2...(no debugging symbols found)...done.
[New LWP 540]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/usr/sbin/apache2 -D FOREGROUND'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  zval_get_type (pz=0x0) at /usr/include/php/20180731/Zend/zend_types.h:411

warning: Source file is more recent than executable.
411             return pz->u1.v.type;
(gdb) where
#0  zval_get_type (pz=0x0) at /usr/include/php/20180731/Zend/zend_types.h:411
#1  xdebug_var_export_xml_node ([email protected]=0x55fec80426d0, [email protected]=0x55fec8042a20,
    [email protected]=0x55fec803a360, [email protected]=0x55fec803a2f0, [email protected]=1)
    at ./build-7.3/xdebug_var.c:2003
#2  0x00007f91bc703805 in xdebug_object_element_export_xml_node (class_name=0x55fec803f3f0 "Phalcon\\Config",
    options=0x55fec803a2f0, parent_name=0x55fec803e600, parent=0x55fec8042900, level=0, item_nptr=0x55fec80426b0)
    at ./build-7.3/xdebug_var.c:1881
#3  xdebug_var_export_xml_node (struc=<optimized out>, [email protected]=0x7ffe96feee58, [email protected]=0x55fec803e600,
    [email protected]=0x55fec8042900, [email protected]=0x55fec803a2f0, [email protected]=0)
    at ./build-7.3/xdebug_var.c:2133
#4  0x00007f91bc703c66 in xdebug_get_zval_value_xml_node_ex ([email protected]=0x55fec803e6f0, val=<optimized out>,
    [email protected]=0x7ffe96feeed0, [email protected]=0, [email protected]=0x55fec803a2f0)
    at ./build-7.3/xdebug_var.c:2204
#5  0x00007f91bc6eff5d in get_symbol ([email protected]=0x55fec803e6f0, [email protected]=0x55fec803a2f0)
    at ./build-7.3/xdebug_handler_dbgp.c:285
#6  0x00007f91bc6f0cd8 in attach_declared_var_with_contents (xml=0x55fec803e8b0, he=<optimized out>,
    options=0x55fec803a2f0) at ./build-7.3/xdebug_handler_dbgp.c:1634
#7  0x00007f91bc6f7270 in xdebug_hash_apply_with_argument ([email protected]=0x55fec8042d20, [email protected]=0x55fec803e8b0,
    [email protected]=0x7f91bc6f0cc0 <attach_declared_var_with_contents>, [email protected]=0x55fec803a2f0)
    at ./build-7.3/xdebug_hash.c:265
#8  0x00007f91bc6f4bc6 in attach_context_vars (func=0x7f91bc6f0cc0 <attach_declared_var_with_contents>,
    depth=<optimized out>, context_id=<optimized out>, options=0x55fec803a2f0, node=0x55fec803e8b0)
    at ./build-7.3/xdebug_handler_dbgp.c:1764
#9  xdebug_dbgp_handle_context_get (retval=0x7ffe96fef170, context=<optimized out>, args=<optimized out>)
    at ./build-7.3/xdebug_handler_dbgp.c:1865
#10 0x00007f91bc6f196b in xdebug_dbgp_parse_option (flags=0, retval=<optimized out>,
    line=0x55fec803e910 "context_get -i 24 -d 0 -c 0", context=0x7f91bc7193f0 <xdebug_globals+848>)
    at ./build-7.3/xdebug_handler_dbgp.c:2123
#11 xdebug_dbgp_cmdloop (context=0x7f91bc7193f0 <xdebug_globals+848>, bail=1) at ./build-7.3/xdebug_handler_dbgp.c:2167
#12 0x00007f91bc6f5d92 in xdebug_dbgp_breakpoint (context=0x7f91bc7193f0 <xdebug_globals+848>, stack=<optimized out>,
    file=<optimized out>, lineno=26, type=<optimized out>, exception=0x0, code=0x0, message=0x0)
    at ./build-7.3/xdebug_handler_dbgp.c:2442
#13 0x00007f91bc6e3536 in xdebug_statement_call (frame=<optimized out>) at ./build-7.3/xdebug.c:2567
#14 0x00007f91bccc84d2 in zend_llist_apply_with_argument () from /usr/lib/apache2/modules/libphp7.3.so
#15 0x00007f91bcb33c32 in ?? () from /usr/lib/apache2/modules/libphp7.3.so
#16 0x00007f91bcd54f37 in execute_ex () from /usr/lib/apache2/modules/libphp7.3.so
#17 0x00007f91bc6e3f93 in xdebug_execute_ex (execute_data=0x7f91bba1c030) at ./build-7.3/xdebug.c:1904
#18 0x00007f91bcd5b457 in zend_execute () from /usr/lib/apache2/modules/libphp7.3.so
#19 0x00007f91bccd4423 in zend_execute_scripts () from /usr/lib/apache2/modules/libphp7.3.so
#20 0x00007f91bcc74fd8 in php_execute_script () from /usr/lib/apache2/modules/libphp7.3.so
#21 0x00007f91bcd5d692 in ?? () from /usr/lib/apache2/modules/libphp7.3.so
#22 0x000055fec6b56a40 in ap_run_handler ()
#23 0x000055fec6b56fd6 in ap_invoke_handler ()
#24 0x000055fec6b6f5c3 in ap_process_async_request ()
#25 0x000055fec6b6f72e in ap_process_request ()
#26 0x000055fec6b6b82d in ?? ()
#27 0x000055fec6b608b0 in ap_run_process_connection ()
#28 0x00007f91bced93df in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#29 0x00007f91bced96d4 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#30 0x00007f91bceda3bf in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#31 0x000055fec6b3967e in ap_run_mpm ()
#32 0x000055fec6b31f57 in main ()
(gdb)
edited Aug '19

Could you please open an issue at GitHub with steps to reproduce?



4.2k

Thank you for your reply. What should I do for "reproduce"? I have never used github, so I don't understand it well. Since the amount of Dockerfile, run command arguments, PHP files, etc. is small, I think that it can be presented here.

Dockerfile

FROM debian:buster-slim

ENV TZ=Asia/Tokyo \
  PHP_INI_SCAN_DIR=:/etc/php.append.d:/etc/php.extra.d \
  APACHE_CONFDIR=/etc/apache2 \
  APACHE_ENVVARS=/etc/apache2/envvars

RUN set -eux; \
  mkdir -m 777 /etc/php.append.d; \
  mkdir -m 777 /etc/php.extra.d; \
  mkdir -m 777 /var/www; \
  chown www-data:www-data /var/www

RUN set -eux; \
  apt-get update; \
  apt-get upgrade -y; \
  apt-get install -y \
    apache2 \
    php7.3 \
    php7.3-dev \
    php7.3-mysql \
    php7.3-mbstring \
    php7.3-xml \
    php7.3-gd \
    php7.3-curl \
    php7.3-sqlite3 \
    php7.3-json \
    php7.3-zip \
    php-gettext \
    php-pear \
    php-xdebug \
    php7.3-mailparse; \
  curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | bash; \
  apt-get update; \
  apt-get install -y php7.3-phalcon; \
  apt-get clean; \
  rm -rf /var/lib/apt/lists/*

RUN set -eux; \
  a2enmod rewrite; \
  a2enmod info; \
  a2enmod headers; \
  sed -i "/conf-enabled/aIncludeOptional conf-additional/*.conf" /etc/apache2/apache2.conf; \
  mkdir /etc/apache2/conf-additional

EXPOSE 80

VOLUME \
  /etc/php.append.d \
  /etc/php.extra.d \
  /etc/apache2/conf-additional \
  /etc/apache2/sites-enabled \
  /var/www

CMD ["apachectl", "-D", "FOREGROUND"]

make image

docker build -t shin/sample . --no-cache --force-rm --pull

run command

docker run --ulimit core=-1 --privileged -p 80:80 -v D:\sample\apache.append:/etc/php.append.d -v D:\sample\php.extra.d:/etc/php.extra.d -v D:\sample\apache.append:/etc/apache2/conf-additiona -v D:\sample\apache.sites:/etc/apache2/sites-enabled -v D:\sample\sites:/var/www --name php73phalcon shin/sample:latest

file in host directory

D:\sample\apache.append

empty

D:\sample\apache.append

empty

D:\sample\php.extra.d

opcache.ini

opcache.enable=0

xdebug.ini

[xdebug]
zend_extension = xdebug.so
xdebug.idekey = "PHPSTORM"
xdebug.profiler_append = 0
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 0
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_connect_back = 0
xdebug.remote_host=host.docker.internal
;xdebug.remote_log="/tmp/xdebug_log"

D:\sample\apache.sites

000-default.conf

# Virtual Hosts
## default

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/default/public_html
    ServerName localhost
    ServerAlias www.localhost
    ErrorLog /var/www/default/logs/localhost.error.log
    CustomLog /var/www/default/logs/localhost.access.log combined

    AddDefaultCharset Off

    <Directory "/var/www/default/public_html">
      Options FollowSymLinks Indexes
      AllowOverride All
      Require all granted

      DirectoryIndex index.php index.html
    </Directory>

</VirtualHost>

100-foo.conf

# Virtual Hosts
## foo

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/foo/public_html
    ServerName foo.localhost
    ServerAlias www.foo.localhost
    ErrorLog /var/www/foo/logs/foo.localhost.error.log
    CustomLog /var/www/foo/logs/foo.localhost.access.log combined

    AddDefaultCharset Off

    <Directory "/var/www/foo/public_html">
      Options FollowSymLinks Indexes
      AllowOverride All
      Require all granted

      DirectoryIndex index.php index.html
    </Directory>

</VirtualHost>

D:\sample\sites\foo\public_html

index.php

<?php

define('APP_DIR', dirname(__DIR__) . '/app/');

$settings = [
    'database' => [
        'adapter'     => 'Mysql',
        'host'        => 'localhost',
        'username'    => 'root',
        'password'    => '',
        'dbname'      => 'test',
    ],
    'application' => [
        'controllersDir' => APP_DIR . 'controllers/',
        'modelsDir'      => APP_DIR . 'models/',
        'viewsDir'       => APP_DIR . 'views/',
        'pluginsDir'     => APP_DIR . 'plugins/',
        'libraryDir'     => APP_DIR . 'library/',
        'cacheDir'       => APP_DIR . 'cache/',
        'baseUri'        => '/tutorial/',
    ]
];
$config = new Phalcon\Config($settings);

// オートローダにディレクトリを登録する
$loader = new Phalcon\Loader();
$loader->registerDirs(
    [
        "../app/controllers/",
        "../app/models/",
    ]
);


4.2k

I'm sorry for taking so much time. I was not used to git, and I was unable to get core dump. The last work is lost and I can't get it.

The Xdebug version seems to be different from the previous one, but the segmentation fault does not change when executing the step.

You can get the environment from the following URL.

https://github.com/s-ohnishi/PhalconXdebug_segfault.git

Could you please open an issue at GitHub with steps to reproduce?



4.2k
Accepted
answer

Xdebug has been updated to 2.8.0 and no longer becomes a segmentation fault.