如何调试Django细分错误?

时间:2018-08-27 21:15:15

标签: python django segmentation-fault gdb python-3.7

我认为经过一段时间的更新后,我的Django应用已经一次segfault开始运行了。以下是我尝试使用gdb进行调试的尝试,但是我看不到根本原因:

# gdb -ex=r --args ../pyenv/bin/python3 -X faulthandler manage.py runserver 127.0.0.1:8000
GNU gdb (GDB) 8.1.1
Copyright (C) 2018 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-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ../pyenv/bin/python3...(no debugging symbols found)...done.
Starting program: /home/narunas/website/www/pyenv/bin/python3 -X faulthandler manage.py runserver 127.0.0.1:8000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Performing system checks...

System check identified no issues (0 silenced).
August 27, 2018 - 15:59:58
Django version 2.0, using settings 'website.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7de107b in kill () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7de107b in kill () from /usr/lib/libc.so.6
#1  0x00007ffff7a450b7 in ?? () from /usr/lib/libpython3.7m.so.1.0
#2  0x00007ffff7984ff3 in _PyMethodDef_RawFastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#3  0x00007ffff7985201 in _PyCFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#4  0x00007ffff79faf5d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#5  0x00007ffff79847db in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#6  0x00007ffff79f63cd in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#7  0x00007ffff793d069 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#8  0x00007ffff7984982 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#9  0x00007ffff79fa933 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#10 0x00007ffff793d069 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#11 0x00007ffff793e476 in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#12 0x00007ffff794d4f8 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#13 0x00007ffff793e7cb in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#14 0x00007ffff79f7a76 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#15 0x00007ffff793d069 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#16 0x00007ffff793e476 in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#17 0x00007ffff794d4f8 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#18 0x00007ffff793e7cb in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#19 0x00007ffff79f7a76 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#20 0x00007ffff793d069 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#21 0x00007ffff793e476 in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#22 0x00007ffff794d4f8 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#23 0x00007ffff793e7cb in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#24 0x00007ffff79f7a76 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#25 0x00007ffff793d069 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#26 0x00007ffff793e476 in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#27 0x00007ffff794d4f8 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#28 0x00007ffff793e7cb in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#29 0x00007ffff79f7a76 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#30 0x00007ffff79847db in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#31 0x00007ffff79f6225 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#32 0x00007ffff79847db in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#33 0x00007ffff79f6225 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#34 0x00007ffff793d069 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#35 0x00007ffff7984982 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#36 0x00007ffff79f63cd in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#37 0x00007ffff793d069 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#38 0x00007ffff793df34 in PyEval_EvalCodeEx () from /usr/lib/libpython3.7m.so.1.0
#39 0x00007ffff793df5c in PyEval_EvalCode () from /usr/lib/libpython3.7m.so.1.0
#40 0x00007ffff7a6c770 in ?? () from /usr/lib/libpython3.7m.so.1.0
#41 0x00007ffff7a6e54a in PyRun_FileExFlags () from /usr/lib/libpython3.7m.so.1.0
#42 0x00007ffff7a6fac5 in PyRun_SimpleFileExFlags () from /usr/lib/libpython3.7m.so.1.0
#43 0x00007ffff7a71a8f in ?? () from /usr/lib/libpython3.7m.so.1.0
#44 0x00007ffff7a72420 in _Py_UnixMain () from /usr/lib/libpython3.7m.so.1.0
#45 0x00007ffff7dcd223 in __libc_start_main () from /usr/lib/libc.so.6
#46 0x000055555555477a in _start ()

由于-X faulthandler标志,我还观察到以下内容:

Fatal Python error: Segmentation fault

Current thread 0x00007efe5b61c600 (most recent call first):
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/utils/autoreload.py", line 303 in python_reloader
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/utils/autoreload.py", line 330 in main
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 105 in run
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 98 in handle
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/core/management/base.py", line 335 in execute
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 61 in execute
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/core/management/base.py", line 288 in run_from_argv
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 365 in execute
  File "/home/narunas/website/www/pyenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 371 in execute_from_command_line
  File "./manage.py", line 12 in <module>

以下是我项目中使用的一些模块:

Django<2.1
wagtail==2.2.1
wagtailmenus>=2.7.1
wagtail-condensedinlinepanel>=0.4.2
psycopg2-binary
django-debug-toolbar
django-extensions
ipython
libsass
django-compressor
django-sass-processor
django-ipware
requests
waitress

接下来要采取哪些步骤来发现这些segfaults的根本原因?

目前,我正在使用 Python 3.7 Arch Linux操作系统上进行调试。

Edit-1

我使用Python3.7编译了debugging symbols,因此现在观察以下backtrace

(gdb) bt
#0  0x00007ffff7de007b in kill () from /usr/lib/libc.so.6
#1  0x00007ffff7c53fe7 in os_kill () from /usr/lib/libpython3.7m.so.1.0
#2  0x00007ffff7bc150a in _PyMethodDef_RawFastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#3  0x00007ffff7bc1851 in _PyCFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#4  0x00007ffff7c1284a in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#5  0x00007ffff7bccf7b in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#6  0x00007ffff7c0e040 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#7  0x00007ffff7bcbced in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#8  0x00007ffff7bcd1f2 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#9  0x00007ffff7c121f6 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#10 0x00007ffff7bcbced in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#11 0x00007ffff7bcda0d in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#12 0x00007ffff7b95a63 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#13 0x00007ffff7b8b428 in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#14 0x00007ffff7c0f43d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#15 0x00007ffff7bcbced in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#16 0x00007ffff7bcda0d in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#17 0x00007ffff7b95a63 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#18 0x00007ffff7b8b428 in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#19 0x00007ffff7c0f43d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#20 0x00007ffff7bcbced in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#21 0x00007ffff7bcda0d in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#22 0x00007ffff7b95a63 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#23 0x00007ffff7b8b428 in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#24 0x00007ffff7c0f43d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#25 0x00007ffff7bcbced in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#26 0x00007ffff7bcda0d in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#27 0x00007ffff7b95a63 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#28 0x00007ffff7b8b428 in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#29 0x00007ffff7c0f43d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#30 0x00007ffff7bccf7b in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#31 0x00007ffff7c0dea3 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#32 0x00007ffff7bccf7b in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#33 0x00007ffff7c0dea3 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#34 0x00007ffff7bcbced in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#35 0x00007ffff7bcd1f2 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#36 0x00007ffff7c0e040 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#37 0x00007ffff7bcbced in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#38 0x00007ffff7bcce34 in PyEval_EvalCodeEx () from /usr/lib/libpython3.7m.so.1.0
#39 0x00007ffff7bcce5c in PyEval_EvalCode () from /usr/lib/libpython3.7m.so.1.0
#40 0x00007ffff7c6f240 in run_mod () from /usr/lib/libpython3.7m.so.1.0
#41 0x00007ffff7c6f5de in PyRun_FileExFlags () from /usr/lib/libpython3.7m.so.1.0
#42 0x00007ffff7c71065 in PyRun_SimpleFileExFlags () from /usr/lib/libpython3.7m.so.1.0
#43 0x00007ffff7c72923 in pymain_main.constprop () from /usr/lib/libpython3.7m.so.1.0
#44 0x00007ffff7c72b50 in _Py_UnixMain () from /usr/lib/libpython3.7m.so.1.0
#45 0x00007ffff7dcc223 in __libc_start_main () from /usr/lib/libc.so.6
#46 0x000055555555477a in _start ()
(gdb) disassemble 
Dump of assembler code for function kill:
   0x00007ffff7de0070 <+0>: endbr64 
   0x00007ffff7de0074 <+4>: mov    $0x3e,%eax
   0x00007ffff7de0079 <+9>: syscall 
=> 0x00007ffff7de007b <+11>:    cmp    $0xfffffffffffff001,%rax
   0x00007ffff7de0081 <+17>:    jae    0x7ffff7de0084 <kill+20>
   0x00007ffff7de0083 <+19>:    retq   
   0x00007ffff7de0084 <+20>:    mov    0x185db5(%rip),%rcx        # 0x7ffff7f65e40
   0x00007ffff7de008b <+27>:    neg    %eax
   0x00007ffff7de008d <+29>:    mov    %eax,%fs:(%rcx)
   0x00007ffff7de0090 <+32>:    or     $0xffffffffffffffff,%rax
   0x00007ffff7de0094 <+36>:    retq   
End of assembler dump.
(gdb) info registers 
rax            0x0  0
rbx            0x80 128
rcx            0x7ffff7de007b   140737351909499
rdx            0x6e 110
rsi            0xb  11
rdi            0x6e93   28307
rbp            0x7ffff7d86bc0   0x7ffff7d86bc0 <_PyRuntime>
rsp            0x7fffffffc738   0x7fffffffc738
r8             0x0  0
r9             0x2c 44
r10            0x3a 58
r11            0x202    514
r12            0x7ffff7d59360   140737351357280
r13            0x7ffff7d40e88   140737351257736
r14            0x2  2
r15            0x7ffff72d14f8   140737340314872
rip            0x7ffff7de007b   0x7ffff7de007b <kill+11>
eflags         0x202    [ IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
gs             0x0  0

要确认现在存在debugging symbols

$ file /usr/lib/libpython3.7m.so.1.0 
/usr/lib/libpython3.7m.so.1.0: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=4a17d5aceb3c01ddb4cf598bca66c5954a08f65e, with debug_info, not stripped
$
$
$ objdump --syms /usr/lib/libpython3.7m.so.1.0 | head

/usr/lib/libpython3.7m.so.1.0:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000238 l    d  .note.gnu.build-id 0000000000000000              .note.gnu.build-id
0000000000000260 l    d  .gnu.hash  0000000000000000              .gnu.hash
0000000000003760 l    d  .dynsym    0000000000000000              .dynsym
0000000000010690 l    d  .dynstr    0000000000000000              .dynstr
000000000001a23e l    d  .gnu.version   0000000000000000              .gnu.version
000000000001b388 l    d  .gnu.version_r 0000000000000000              .gnu.version_r

0 个答案:

没有答案