如何在Python / Kivy中调试free():无效的nex大小错误?

时间:2014-07-28 15:38:02

标签: python kivy

在Kivy,我偶尔会遇到以下错误:

*** Error in `python': free(): invalid next size (fast): 0x0000000001d67800 ***
Aborted (core dumped)

每次测试程序都不会发生这种情况,这真让我感到困惑。

搜索错误消息我被认为是与C代码有关。 我想我在python中做了一些事情,导致了kivy C代码中的这个错误。

我想知道如何跟踪这样的错误。

版本:

  • Python版本:2.7.5-5ubuntu3

  • Cython版本:0.20.1 + git90-g0e6e38e-1ubuntu2

  • Kivy版本:1.8.0-stable0 + 2014013011617 ^ pkg23 ^ ubuntu13.10。

1 个答案:

答案 0 :(得分:6)

首先,安装gdb和Python debug:sudo apt-get install gdb python2.7-dbg

然后在gdb中加载您的应用:gdb --args python <script.py>

您应该收到gdb提示(gdb)。输入r,然后按Enter键。你的程序将开始像平常一样运行(尽管速度较慢)。

一旦你的应用程序崩溃,Kivy窗口将保持打开状态,gdb shell将再次显示提示。在此提示符下键入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
...
...
...