如何调试Python/Kivy中的free(): invalid next size错误?
在Kivy中,我有时会遇到以下错误:
*** Error in `python': free(): invalid next size (fast): 0x0000000001d67800 ***
Aborted (core dumped)
这个错误并不是每次测试程序时都会出现,这让我很困惑。
我在搜索这个错误信息时,发现它似乎和C语言代码有关。我想我在Python中做的某些事情导致了Kivy的C代码出现了这个bug。
我想知道我该如何追踪这样一个bug。
版本信息:
Python版本:2.7.5-5ubuntu3
Cython版本:0.20.1+git90-g0e6e38e-1ubuntu2
Kivy版本:1.8.0-stable0+2014013011617^pkg23^ubuntu13.10。
1 个回答
7
首先,安装 gdb 和 Python 调试工具:sudo apt-get install gdb python2.7-dbg
然后在 gdb 中加载你的应用:gdb --args python <script.py>
你会看到一个 gdb 提示符 (gdb)
。输入 r
然后按回车。你的程序就会像正常一样开始运行(不过会慢一些)。
一旦你的应用崩溃,Kivy 窗口会保持打开,gdb 窗口会再次显示提示符。此时在这个提示符下输入 bt
,就可以查看回溯信息。
示例:
$ gdb --args python segtest.py
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 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/bin/python2.7...Reading symbols from /usr/lib/debug/usr/bin/python2.7...done.
done.
(gdb) r
Starting program: /usr/bin/python segtest.py
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[INFO ] [Logger ] Record log in /home/ryan/.kivy/logs/kivy_14-07-28_13.txt
[INFO ] [Factory ] 169 symbols loaded
[DEBUG ] [Cache ] register <kv.image> with limit=None, timeout=60s
[DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout=Nones
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600s
[DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=Nones
[INFO ] [Text ] Provider: pygame
[DEBUG ] [Cache ] register <textinput.label> with limit=None, timeout=60.0s
[DEBUG ] [Cache ] register <textinput.width> with limit=None, timeout=60.0s
[INFO ] Kivy v1.8.1-dev
[INFO ] [Python ] v2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2]
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG ] [Window ] Display driver x11
[DEBUG ] [Window ] Actual window size: 800x600
[DEBUG ] [Window ] Actual color bits r8 g8 b8 a8
[DEBUG ] [Window ] Actual depth bits: 24
[DEBUG ] [Window ] Actual stencil bits: 8
[DEBUG ] [Window ] Actual multisampling samples: 4
[INFO ] [GL ] OpenGL version <3.0 Mesa 10.1.3>
[INFO ] [GL ] OpenGL vendor <Intel Open Source Technology Center>
[INFO ] [GL ] OpenGL renderer <Mesa DRI Intel(R) Sandybridge Mobile >
[INFO ] [GL ] OpenGL parsed version: 3, 0
[INFO ] [GL ] Shading version <1.30>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[DEBUG ] [Shader ] Fragment compiled successfully
[DEBUG ] [Shader ] Vertex compiled successfully
[DEBUG ] [ImagePygame ] Load </home/ryan/git/aeris2/kivy/kivy/data/glsl/default.png>
[DEBUG ] [Modules ] Start <inspector> with config {}
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[DEBUG ] [App ] Loading kv <./test.kv>
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5971db6 in __pyx_f_4kivy_8graphics_12instructions_6Canvas_add (__pyx_v_self=0x7fffe2ec4a68,
__pyx_v_c=0x920190 <_Py_NoneStruct>, __pyx_skip_dispatch=<optimized out>) at kivy/graphics/instructions.c:8532
8532 ((struct __pyx_vtabstruct_4kivy_8graphics_12instructions_Instruction *)__pyx_v_c->__pyx_vtab)->radd(__pyx_v_c, ((struct __pyx_obj_4kivy_8graphics_12instructions_InstructionGroup *)__pyx_v_self));
(gdb) bt
#0 0x00007ffff5971db6 in __pyx_f_4kivy_8graphics_12instructions_6Canvas_add (__pyx_v_self=0x7fffe2ec4a68,
__pyx_v_c=0x920190 <_Py_NoneStruct>, __pyx_skip_dispatch=<optimized out>) at kivy/graphics/instructions.c:8532
#1 0x00007ffff597487e in __pyx_pf_4kivy_8graphics_12instructions_6Canvas_6add (
__pyx_v_c=0x920190 <_Py_NoneStruct>, __pyx_v_self=0x7fffe2ec4a68) at kivy/graphics/instructions.c:8611
#2 __pyx_pw_4kivy_8graphics_12instructions_6Canvas_7add (
__pyx_v_self=<kivy.graphics.instructions.Canvas at remote 0x7fffe2ec4a68>, __pyx_v_c=None)
at kivy/graphics/instructions.c:8591
#3 0x000000000052ccbc in call_function (oparg=<optimized out>, pp_stack=0x7fffffffd870) at ../Python/ceval.c:4008
#4 PyEval_EvalFrameEx (
f=f@entry=Frame 0x7fffdfa10050, for file /home/ryan/git/aeris2/kivy/kivy/core/window/__init__.py, line 647, in add_widget (self=<WindowPygame(_context=<Context(sandbox=None) at remote 0x7ffff659a740>, single_vkeyboard=True, _keyboards={'system': <Keyboard(widget=None, callback=None, window=<...>, target=None) at remote 0x7fffe2ebf0b8>}, _vkeyboard_cls=None, _system_keyboard=<...>, _pos=(0, 0), allow_vkeyboard=False, use_syskeyboard=True, flags=1073741843, trigger_keyboard_height=<ClockEvent(_last_dt=0, cid=207, clock=<ClockBase at remote 0x7ffff65c4a28>, weak_callback=<WeakMethod(_func=<function at remote 0x7fffe2e9fed8>, _obj=<weakref at remote 0x7fffe2ec2050>, _class=<type at remote 0x1029ac0>) at remote 0x7fffe2ebc9d0>, callback=None, timeout=<float at remote 0xf0ea98>, _is_triggered=False, _dt=<float at remote 0xa83608>, loop=False) at remote 0x7fffe2ebc990>, initialized=True, docked_vkeyboard=False, dpi=<float at remote 0xf0e930>, trigger_create_window=<ClockEvent(_last_dt=0, cid=207, clock=<...>, weak_callback=<W...(truncated), throwflag=throwflag@entry=0) at ../Python/ceval.c:2666
...
...
...