2012-10-26 31 views
25

Tôi đang chạy công việc PHP dòng lệnh dẫn đến Lỗi phân đoạn. Công việc này đã làm việc trong một thời gian dài, nhưng nó xử lý một cái gì đó được gửi qua email. Rõ ràng có cái gì đó trong email này phá vỡ nó, nhưng tôi không có ý tưởng gì. Nếu tôi đặt tệp lõi vào gdb, nó thực sự không có sự trợ giúp:Làm cách nào để chẩn đoán lỗi phân đoạn PHP này?

$ gdb /usr/local/bin/php core.20381 
GNU gdb (GDB) 7.1-ubuntu 
Copyright (C) 2010 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://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". 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>... 
Reading symbols from /usr/local/bin/php...done. 
[New Thread 20381] 

warning: Can't read pathname for load map: Input/output error. 
Reading symbols from /lib/libcrypt.so.1...(no debugging symbols found)...done. 
Loaded symbols for /lib/libcrypt.so.1 
Reading symbols from /lib/librt.so.1...(no debugging symbols found)...done. 
Loaded symbols for /lib/librt.so.1 
Reading symbols from /usr/lib/libmysqlclient_r.so.15...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libmysqlclient_r.so.15 
Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done. 
Loaded symbols for /lib/libpthread.so.0 
Reading symbols from /lib/libz.so.1...(no debugging symbols found)...done. 
Loaded symbols for /lib/libz.so.1 
Reading symbols from /usr/lib/libmcrypt.so.4...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libmcrypt.so.4 
Reading symbols from /usr/lib/libltdl.so.7...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libltdl.so.7 
Reading symbols from /lib/libpng12.so.0...(no debugging symbols found)...done. 
Loaded symbols for /lib/libpng12.so.0 
Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done. 
Loaded symbols for /lib/libm.so.6 
Reading symbols from /lib/libdl.so.2...(no debugging symbols found)...done. 
Loaded symbols for /lib/libdl.so.2 
Reading symbols from /lib/libnsl.so.1...(no debugging symbols found)...done. 
Loaded symbols for /lib/libnsl.so.1 
Reading symbols from /usr/lib/libcurl-gnutls.so.4...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libcurl-gnutls.so.4 
Reading symbols from /usr/lib/libxml2.so.2...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libxml2.so.2 
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done. 
Loaded symbols for /lib/libc.so.6 
Reading symbols from /lib/libresolv.so.2...(no debugging symbols found)...done. 
Loaded symbols for /lib/libresolv.so.2 
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done. 
Loaded symbols for /lib64/ld-linux-x86-64.so.2 
Reading symbols from /usr/lib/libidn.so.11...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libidn.so.11 
Reading symbols from /usr/lib/liblber-2.4.so.2...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/liblber-2.4.so.2 
Reading symbols from /usr/lib/libldap_r-2.4.so.2...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libldap_r-2.4.so.2 
Reading symbols from /usr/lib/libgssapi_krb5.so.2...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libgssapi_krb5.so.2 
Reading symbols from /usr/lib/libgnutls.so.26...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libgnutls.so.26 
Reading symbols from /lib/libgcrypt.so.11...(no debugging symbols found)...done. 
Loaded symbols for /lib/libgcrypt.so.11 
Reading symbols from /usr/lib/libsasl2.so.2...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libsasl2.so.2 
Reading symbols from /usr/lib/libkrb5.so.3...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libkrb5.so.3 
Reading symbols from /usr/lib/libk5crypto.so.3...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libk5crypto.so.3 
Reading symbols from /lib/libcom_err.so.2...(no debugging symbols found)...done. 
Loaded symbols for /lib/libcom_err.so.2 
Reading symbols from /usr/lib/libkrb5support.so.0...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libkrb5support.so.0 
Reading symbols from /lib/libkeyutils.so.1...(no debugging symbols found)...done. 
Loaded symbols for /lib/libkeyutils.so.1 
Reading symbols from /usr/lib/libtasn1.so.3...(no debugging symbols found)...done. 
Loaded symbols for /usr/lib/libtasn1.so.3 
Reading symbols from /lib/libgpg-error.so.0...(no debugging symbols found)...done. 
Loaded symbols for /lib/libgpg-error.so.0 
Reading symbols from /lib/libgcc_s.so.1...(no debugging symbols found)...done. 
Loaded symbols for /lib/libgcc_s.so.1 
Reading symbols from /lib/libnss_files.so.2...(no debugging symbols found)...done. 
Loaded symbols for /lib/libnss_files.so.2 
Can't read symbols from system-supplied DSO at 0x7fffb4bfc000: File truncated 
Core was generated by `/usr/local/bin/php /src/prod/current/utils/cron.php --run=/utils/proces'. 
Program terminated with signal 11, Segmentation fault. 
#0 match (
    eptr=0x1370a887 "/td>\n\t\t\t\t\t\t\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t\t\n\t\t<tr>\n\t\t\t<td style=\"border-top:3px solid #efefef; padding:20px 10px;\">\n\t\t\t\t<table style=\"width:100%;\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t\n", '\t' <repeats 12 times>, "\n\t\t\t\t"..., ecode=0x133dc3aa "N", 
    mstart=0x13708600 "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">\n\n</head>\n\n<body style=\"padding"..., markptr=0x0, offset_top=4, md=0x7fffb4b1b620, ims=0, eptrb=0x0, flags=0, rdepth=17680) at /home/farmer/srcs/php-5.3.4/ext/pcre/pcrelib/pcre_exec.c:470 
470 { 

Nếu tôi làm 'bt', tôi chỉ nhận được câu lệnh "khớp" này lặp đi lặp lại. Dưới đây là những điều đầu tiên:

#1 0x000000000046ef1e in match (
    eptr=0x1370a887 "/td>\n\t\t\t\t\t\t\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t\t\n\t\t<tr>\n\t\t\t<td style=\"border-top:3px solid #efefef; padding:20px 10px;\">\n\t\t\t\t<table style=\"width:100%;\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t\n", '\t' <repeats 12 times>, "\n\t\t\t\t"..., ecode=0x133dc3a5 "_", mstart=<value optimized out>, markptr=<value optimized out>, 
    offset_top=<value optimized out>, md=0x7fffb4b1b620, ims=0, eptrb=0x0, flags=0, rdepth=17679) at /home/farmer/srcs/php-5.3.4/ext/pcre/pcrelib/pcre_exec.c:803 
#2 0x0000000000479789 in match (
    eptr=0x1370a887 "/td>\n\t\t\t\t\t\t\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t\t\n\t\t<tr>\n\t\t\t<td style=\"border-top:3px solid #efefef; padding:20px 10px;\">\n\t\t\t\t<table style=\"width:100%;\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t\n", '\t' <repeats 12 times>, "\n\t\t\t\t"..., ecode=0x133dc5ca "V\002%\033U\002.", mstart=<value optimized out>, 
    markptr=<value optimized out>, offset_top=<value optimized out>, md=0x7fffb4b1b620, ims=0, eptrb=0x0, flags=0, rdepth=<value optimized out>) 
    at /home/farmer/srcs/php-5.3.4/ext/pcre/pcrelib/pcre_exec.c:1623 
#3 0x000000000046ef1e in match (
    eptr=0x1370a886 "</td>\n\t\t\t\t\t\t\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t\t\n\t\t<tr>\n\t\t\t<td style=\"border-top:3px solid #efefef; padding:20px 10px;\">\n\t\t\t\t<table style=\"width:100%;\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t\n", '\t' <repeats 12 times>, "\n\t\t\t"..., ecode=0x133dc3a5 "_", mstart=<value optimized out>, markptr=<value optimized out>, 
    offset_top=<value optimized out>, md=0x7fffb4b1b620, ims=0, eptrb=0x0, flags=0, rdepth=17677) at /home/farmer/srcs/php-5.3.4/ext/pcre/pcrelib/pcre_exec.c:803 
#4 0x0000000000479789 in match (
    eptr=0x1370a886 "</td>\n\t\t\t\t\t\t\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t\t\n\t\t<tr>\n\t\t\t<td style=\"border-top:3px solid #efefef; padding:20px 10px;\">\n\t\t\t\t<table style=\"width:100%;\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t\n", '\t' <repeats 12 times>, "\n\t\t\t"..., ecode=0x133dc5ca "V\002%\033U\002.", mstart=<value optimized out>, 
    markptr=<value optimized out>, offset_top=<value optimized out>, md=0x7fffb4b1b620, ims=0, eptrb=0x0, flags=0, rdepth=<value optimized out>) 
    at /home/farmer/srcs/php-5.3.4/ext/pcre/pcrelib/pcre_exec.c:1623 
#5 0x000000000046ef1e in match (
    eptr=0x1370a885 "\t</td>\n\t\t\t\t\t\t\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t\t\n\t\t<tr>\n\t\t\t<td style=\"border-top:3px solid #efefef; padding:20px 10px;\">\n\t\t\t\t<table style=\"width:100%;\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t\n", '\t' <repeats 12 times>, "\n\t\t"..., ecode=0x133dc3a5 "_", mstart=<value optimized out>, markptr=<value optimized out>, 
    offset_top=<value optimized out>, md=0x7fffb4b1b620, ims=0, eptrb=0x0, flags=0, rdepth=17675) at /home/farmer/srcs/php-5.3.4/ext/pcre/pcrelib/pcre_exec.c:803 

Tôi thực sự đang thua lỗ ở đây. Tôi đã thử chạy lệnh trong strace, và nó có vẻ là seg-faulting trong thư viện PEAR Mail_Queue. Dưới đây là phần cuối của đường (một số thông tin nhận diện đã bị xóa):

lstat("/src/prod/releases/20121025202143/www/application/pear/MDB2/Driver/mysql.php", {st_mode=S_IFREG|0770, st_size=55723, ...}) = 0 
lstat("/src/prod/releases/20121025202143/www/application/pear/MDB2/Driver", {st_mode=S_IFDIR|0770, st_size=4096, ...}) = 0 
lstat("/src/prod/releases/20121025202143/www/application/pear/MDB2", {st_mode=S_IFDIR|0770, st_size=4096, ...}) = 0 
lstat("/src/prod/releases/20121025202143/www/application/pear", {st_mode=S_IFDIR|0770, st_size=4096, ...}) = 0 
open("/src/prod/releases/20121025202143/www/application/pear/MDB2/Driver/mysql.php", O_RDONLY) = 6 
fstat(6, {st_mode=S_IFREG|0770, st_size=55723, ...}) = 0 
fstat(6, {st_mode=S_IFREG|0770, st_size=55723, ...}) = 0 
fstat(6, {st_mode=S_IFREG|0770, st_size=55723, ...}) = 0 
mmap(NULL, 55723, PROT_READ, MAP_SHARED, 6, 0) = 0x2b49f7bb4000 
brk(0x987b000)       = 0x987b000 
brk(0x98bb000)       = 0x98bb000 
munmap(0x2b49f7bb4000, 55723)   = 0 
close(6)        = 0 
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 6 
fcntl(6, F_SETFL, O_RDONLY)    = 0 
fcntl(6, F_GETFL)      = 0x2 (flags O_RDWR) 
fcntl(6, F_GETFL)      = 0x2 (flags O_RDWR) 
fcntl(6, F_SETFL, O_RDWR|O_NONBLOCK) = 0 
connect(6, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr("IP ADDRESS TO DB SERVER REMOVED")}, 16) = -1 EINPROGRESS (Operation now in progress) 
fcntl(6, F_SETFL, O_RDWR)    = 0 
poll([{fd=6, events=POLLIN|POLLPRI}], 1, 60000) = 1 ([{fd=6, revents=POLLIN}]) 
setsockopt(6, SOL_SOCKET, SO_RCVTIMEO, "\2003\341\1\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0 
setsockopt(6, SOL_SOCKET, SO_SNDTIMEO, "\2003\341\1\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0 
setsockopt(6, SOL_IP, IP_TOS, [8], 4) = 0 
setsockopt(6, SOL_TCP, TCP_NODELAY, [1], 4) = 0 
setsockopt(6, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0 
poll([{fd=6, events=POLLIN}], 1, 60000) = 1 ([{fd=6, revents=POLLIN}]) 
read(6, "C\0\0\0\n5.1.37-1ubuntu5.5-log\0Q\257\3\0009"..., 16384) = 71 
write(6, "=\0\0\1\205\242\2\0\0\0\[email protected]\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 65) = 65 
read(6, "\7\0\0\2\0\0\0\2\0\0\0", 16384) = 11 
poll([{fd=6, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout) 
write(6, "\10\0\0\0\2xxxxx", 12)  = 12 
read(6, "\7\0\0\1\0\0\0\2\0\0\0", 16384) = 11 
lstat("/src/prod/current/www/application/pear/Mail/mime.php", {st_mode=S_IFREG|0770, st_size=50252, ...}) = 0 
lstat("/src/prod/current/www/application/pear/Mail", {st_mode=S_IFDIR|0770, st_size=4096, ...}) = 0 
lstat("/src/prod/current/www/application/pear", {st_mode=S_IFDIR|0770, st_size=4096, ...}) = 0 
lstat("/src/prod/current/www/application", {st_mode=S_IFDIR|0776, st_size=4096, ...}) = 0 
--- SIGSEGV (Segmentation fault) @ 0 (0) --- 
+++ killed by SIGSEGV +++ 
Segmentation fault 

Nếu có ý tưởng hoặc gợi ý cho các dòng điều tra, tôi thực sự đánh giá cao điều đó. Tôi thực sự bối rối về điều này.

+4

Trông giống như luồng stackover trong 'preg_match', có thể do đầu vào bệnh lý thực sự gây ra. Bạn có thể thử tìm ra dòng lệnh nào của bạn gây ra vấn đề, sau đó xác định đầu vào của hàm là gì, sau đó gửi báo cáo lỗi PHP :) – nneonneo

+0

Bạn đã giải quyết được vấn đề này chưa? Có vẻ như bạn đang chạy PHP 5.3.4, được phát hành vào tháng 12 năm 2010, bạn có thử cập nhật lên phiên bản mới hơn không? –

Trả lời

32

Tôi thường sử dụng xdebug nếu tôi gặp phải một segfault. Tôi thích sử dụng các dòng sau:

php -d xdebug.auto_trace=ON -d xdebug.trace_output_dir=mytracedir/ myscript.php 

Với dấu vết đầu ra dưới mytracedir /, bạn có thể dễ dàng tìm ra dòng php gần đúng, làm gián đoạn tập lệnh. Sau đó viết lại dòng trong một câu lệnh trên mỗi dòng và sử dụng error_log() để gỡ lỗi các vars. Nếu bạn sử dụng __destruct() hoặc __toString(), nó có thể phức tạp hơn một chút ở đó.

Xem http://xdebug.org/docs/execution_trace để biết thêm thông tin.

(Nếu tiện ích không được nạp, nhưng cài đặt, cố gắng thêm php -dzend_extension=xdebug.so [...])

+0

Điều đó cũng sẽ bị lỗi.Mặc dù đó là một công cụ tuyệt vời;) – hakre

+1

Có, nhưng bạn có thể thấy quá trình php diễn ra bao lâu trước khi gặp sự cố. Nếu bạn có nhiều dòng có thể bị sập (PCRE-đệ quy), bạn có cơ hội tốt hơn để tìm một dòng phù hợp. Ít nhất, tôi sẽ làm theo cách đó ;-) – Trendfischer

+1

Đúng, điểm tốt. Ngoài ra bạn có thể làm điều đó với xdebug và gỡ lỗi từ xa. Có thể bắt đầu phiên trong GDB. +1. – hakre

10

Các debugger đã cho bạn biết những gì sẽ xảy ra:

... rdepth=17680) at /home/farmer/srcs/php-5.3.4/ext/pcre/pcrelib/pcre_exec.c:470 

Xem pcre.recursion_limit setting:

PCRE .recursion_limit - Giới hạn đệ quy của PCRE. Xin lưu ý rằng nếu bạn đặt giá trị này thành số cao, bạn có thể tiêu thụ tất cả các ngăn xếp quy trình có sẵn và cuối cùng gặp sự cố PHP (do đạt đến giới hạn kích thước ngăn xếp áp đặt bởi Hệ điều hành).

Giảm giá trị của nó để không bị sập nữa để khắc phục nhanh chóng. Sau đó, bạn sẽ thấy HTML của mình không được xử lý hoàn toàn bằng cụm từ thông dụng.

Cải thiện biểu thức để không dựa vào đệ quy nhiều như vậy. Có thể bạn chỉ muốn sử dụng trình phân tích cú pháp HTML.

1

Thử xóa memcache.so và tắt opcache khỏi dòng lệnh php.ini bao gồm nhận xét phần opcache. Bài viết chạy kịch bản với tham số -c path/php.cli.ini và '-d memory_limit -1'

Các vấn đề liên quan