GDB Introduction:
GDB is a powerful UNIX program debugging tool released by the GNU Open Source Organization. If you are working on the UNIX platform, you will find that GDB is a debugging tool that has more powerful functions than the graphical debuggers of VC and BCB.
issue
Environment: Linux/PHP v5.5.7
When the mobile phone accesses the background of this site, click on some pages, and the 502 error will appear, and you want to find out what is the specific reason for the 502 error.
php-fpm error log is as follows:
WARNING: [pool www] child 11274 exited on signal 11 (SIGSEGV) after 0.089068 seconds from start
Core file
The core file is actually an image of memory, which stores the corresponding information of the memory when the program crashes, and is mainly used to debug the program. When the program crashes, a core file will be generated, in fact, it should be said to be a core dump file, the default generation location is in the same directory as the executable program, the file name is core.***, where *** is a certain number.
Command:
core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 7271 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 65535 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 7271 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited If the core file size is 0, the core file cannot be generated, and we need to set it.
ulimit -c unlimited, it means that the size of the core file is unlimited
Setup complete, rememberRestart the php-fpm service, the command is as follows:
Check the error log again, as follows:
[23-May-2020 14:39:14] WARNING: [pool www] child 2220 exited on signal 11 (SIGSEGV - core dumped) after 7.255225 seconds from start [23-May-2020 14:39:14] NOTICE: [pool www] child 2231 started If the log contains the words "SIGSEGV – core dumped", it means that the rore file has been successfully generated.
The core file will be generated under the website directory, if you don't know, you can also find the core file with the following command:
The address generated by the core of my server is: /alidata/www/itsvse_web/core.2220
Install gdb
The command is as follows:
gdb debug php-fpm
Prepare the .gdbinit file
The .gdbinit file is under the PHP source code, and it must be consistent with the php version you are running!
My file address: /root/sh-1.5.5/php-5.5.7/.gdbinit
Download address of the latest php version of .gdbinit file:
The hyperlink login is visible.
gdb to open the core file
In the core file directory, run the following command:
[root@o itsvse_web]# gdb php-fpm -c core.2220 GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <The hyperlink login is visible. 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-redhat-linux-gnu". For bug reporting instructions, please see: <The hyperlink login is visible. Reading symbols from /alidata/server/php-5.5.7/sbin/php-fpm... done. [New LWP 2220] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Core was generated by `php-fpm: pool www '. Program terminated with signal 11, Segmentation fault. #0 tsrm_realpath_r ( path=path@entry=0x7ffdd9ebf100 "/alidata/www/itsvse_web/./source/language/mobile/lang_template.php", start=start@entry=1, len=66, ll=ll@entry=0x7ffdd9ebf0f4, t=t@entry=0x7ffdd9ebf0f8, use_realpath=use_realpath@entry=2, is_dir=is_dir@entry=0, link_is_dir=link_is_dir@entry=0x0) at /root/sh-1.5.5/php-5.5.7/TSRM/tsrm_virtual_cwd.c:751 751 { Missing separate debuginfos, use: debuginfo-install cyrus-sasl-lib-2.1.26-23.el7.x86_64 glibc-2.17-307.el7.1.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-46.el7.x86_64 libcom_err-1.42.9-17.el7.x86_64 libcurl-7.29.0-57.el7.x86_64 libgcc-4.8.5-39.el7.x86_64 libidn-1.28-4.el7.x86_64 libselinux-2.5-15.el7.x86_ 64 libssh2-1.8.0-3.el7.x86_64 libstdc++-4.8.5-39.el7.x86_64 libxml2-2.9.1-6.el7.4.x86_64 nspr-4.21.0-1.el7.x86_64 nss-3.44.0-7.el7_7.x86_64 nss-softokn-freebl-3.44.0-8.el7_ 7.x86_64 nss-util-3.44.0-4.el7_7.x86_64 openldap-2.4.44-21.el7_6.x86_64 openssl-libs-1.0.2k-19.el7.x86_64 pcre-8.32-17.el7.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-18.el7.x86_64 You can see something like the following words:
Core was generated by `php-fpm: pool www '. Program terminated with signal 11, Segmentation fault. bt(backtrace): Lists the call stack
(gdb) bt #0 tsrm_realpath_r ( path=path@entry=0x7ffdd9ebf100 "/alidata/www/itsvse_web/./source/language/mobile/lang_template.php", start=start@entry=1, len=66, ll=ll@entry=0x7ffdd9ebf0f4, t=t@entry=0x7ffdd9ebf0f8, use_realpath=use_realpath@entry=2, is_dir=is_dir@entry=0, link_is_dir=link_is_dir@entry=0x0) at /root/sh-1.5.5/php-5.5.7/TSRM/tsrm_virtual_cwd.c:751 #1 0x000000000075209a in virtual_file_ex (state=state@entry=0x7ffdd9ec0140, path=path@entry=0xed3a4d8 "/alidata/www/itsvse_web/./source/language/mobile/lang_template.php", verify_path=verify_path@entry=0x0, use_realpath=use_realpath@entry=2) at /root/sh-1.5.5/php-5.5.7/TSRM/tsrm_virtual_cwd.c:1292 #2 0x000000000075308c in tsrm_realpath ( path=path@entry=0xed3a4d8 "/alidata/www/itsvse_web/./source/language/mobile/lang_template.php", real_path=real_path@entry=0x7ffdd9ec1250 "vse_web/./source/plugin/dsu_amupper/pper.class.p\300\023\354\331\375\177") at /root/sh-1.5.5/php-5.5.7/TSRM/tsrm_virtual_cwd.c :1954
Review the exit thread
Introducing .gdbinit (gdb command scripting) provided in the PHP source code
Look at the zbacktrace and variable values
(gdb) zbacktrace [0xed9f8f0] lang() /alidata/www/itsvse_web/source/function/function_core.php:444 [0xed9e2e8] lang("core", "title_board_message") /alidata/www/itsvse_web/source/function/function_message.php:43 [0xed9a988] dshowmessage("mobile_template_no_found", "", array(1)[0xec46a28], array(0)[0xec46bc0], 0) /alidata/www/itsvse_web/source/function/function_core.php:1426 [0xed9a6d8] showmessage("mobile_template_no_found", "", array(1)[0xec46a28]) /alidata/www/itsvse_web/source/function/function_core.php:618 [0xed97638] template("dsu_amupper:pper_foot") /alidata/www/itsvse_web/source/plugin/dsu_amupper/pper.class.php:82 [0x7ffdd9ec3e50] plugin_dsu_amupper->global_footer(array(0)[0xec40028]) [0xed97080] call_user_func(array(2)[0xed6b8b0], array(0)[0xec40028]) /alidata/www/itsvse_web/source/function/function_core.php:1177 [0xed954b8] hookscript("global", "global") /alidata/www/itsvse_web/source/function/function_core.php:1214 [0xed95218] hookscriptoutput("showmessage") /alidata/www/itsvse_web/data/template/8_8_touch_common_showmessage.tpl.php:1 [0xed949e8] ??? /alidata/www/itsvse_web/source/function/function_message.php:237 [0xed91088] dshowmessage("mobile_template_no_found", "", array(1)[0xec40c10], array(0)[0xec76d40], 0) /alidata/www/itsvse_web/source/function/function_core.php:1426 [0xed90dd8] showmessage("mobile_template_no_found", "", array(1)[0xec40c10]) /alidata/www/itsvse_web/source/function/function_core.php:618 [0xed8dd38] template("dsu_amupper:pper_foot") /alidata/www/itsvse_web/source/plugin/dsu_amupper/pper.class.php:82 [0x7ffdd9ec49a0] plugin_dsu_amupper->global_footer(array(0)[0xec39ab0]) [0xed8d780] call_user_func(array(2)[0xeb833e8], array(0)[0xec39ab0]) /alidata/www/itsvse_web/source/function/function_core.php:1177 [0xed8bbb8] hookscript("global", "global") /alidata/www/itsvse_web/source/function/function_core.php:1214 [0xed8b918] hookscriptoutput("showmessage") /alidata/www/itsvse_web/data/template/8_8_touch_common_showmessage.tpl.php:1 [0xed8b0e8] ??? /alidata/www/itsvse_web/source/function/function_message.php:237 [0xed651b0] dshowmessage("mobile_template_no_found", "", array(1)[0xecc0fe0], array(0)[0xec76718], 0) /alidata/www/itsvse_web/source/function/function_core.php:1426 [0xed64f00] showmessage("mobile_template_no_found", "", array(1)[0xecc0fe0]) /alidata/www/itsvse_web/source/function/function_core.php:618 [0xed61e60] template("dsu_amupper:pper_foot") /alidata/www/itsvse_web/source/plugin/dsu_amupper/pper.class.php:82 [0x7ffdd9ec54f0] plugin_dsu_amupper->global_footer(array(0)[0xeb834f8])
(gdb) print ((zval *)0xec46a28) $1 = (zval *) 0xec46a28 (gdb) printzv $1 [0xec46a28] (refcount=5) array(1): { "url\0" => [0xecb2fb0] (refcount=2) string(33): "/admin.php?action=index&mobile=no" } (gdb) Solution
I didn't actually see any errors, but it was obvious from the logs that there was a problem with the mobile access, and after testing, it was indeed a 502 error only in the case of mobile access.
Because there is no mobile version in the background, I directly modified the admin.php source code and added the following code on the first line:
In this way, the program will always get an access request from the PC browser, and it will not go through the logical code of the mobile phone version, solved!
|