Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何读取gdb输出_Python_Python 3.x_Qt_Debugging_Gdb - Fatal编程技术网

Python 如何读取gdb输出

Python 如何读取gdb输出,python,python-3.x,qt,debugging,gdb,Python,Python 3.x,Qt,Debugging,Gdb,我正在用python3.5编写一个程序,并对所有GUI函数使用PyQt4。当我运行程序时,有时会出现分段错误。我在网上寻找解决方案,发现它使用了gdb 我试着用这种方式运行我的程序,但不知道如何读取输出。谁能给我一个提示吗 输出: gdb python3 GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL ver

我正在用
python3.5
编写一个程序,并对所有GUI函数使用
PyQt4
。当我运行程序时,有时会出现分段错误。我在网上寻找解决方案,发现它使用了
gdb

我试着用这种方式运行我的程序,但不知道如何读取输出。谁能给我一个提示吗

输出:

gdb python3
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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".
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 python3...(no debugging symbols found)...done.
(gdb) run GUI3.py 
Starting program: /usr/bin/python3 GUI3.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff3ad0700 (LWP 26031)]
[New Thread 0x7ffff12cf700 (LWP 26032)]
[New Thread 0x7fffeeace700 (LWP 26033)]
[New Thread 0x7fffd3da2700 (LWP 26034)]
[New Thread 0x7fffd2042700 (LWP 26035)]
[New Thread 0x7fffd1841700 (LWP 26036)]
[New Thread 0x7fffd1040700 (LWP 26037)]
[New Thread 0x7fffbb952700 (LWP 26038)]
Run function needs to be implemented

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
QWidgetBackingStore::sync (this=0x1ec5d30) at painting/qbackingstore.cpp:1239
1239    painting/qbackingstore.cpp: No such file or directory.
(gdb) backtrace 
#0  QWidgetBackingStore::sync (this=0x1ec5d30) at painting/qbackingstore.cpp:1239
#1  0x00007fffe0e11c50 in QWidgetPrivate::syncBackingStore (this=0x1907c20)
at kernel/qwidget.cpp:1894
#2  0x00007fffe0e249b8 in QWidget::event (this=this@entry=0x1b3b380, event=event@entry=0x20bab70)
at kernel/qwidget.cpp:8693
#3  0x00007fffe12089b3 in QMainWindow::event (this=0x1b3b380, event=0x20bab70)
at widgets/qmainwindow.cpp:1478
#4  0x00007fffe1cfc28b in ?? ()
   from /usr/lib/python3/dist-packages/PyQt4/QtGui.cpython-35m-x86_64-linux-gnu.so
#5  0x00007fffe0dcdfdc in QApplicationPrivate::notify_helper (this=this@entry=0x18f9d70, 
receiver=receiver@entry=0x1b3b380, e=e@entry=0x20bab70) at kernel/qapplication.cpp:4570
#6  0x00007fffe0dd4f16 in QApplication::notify (this=0x17de970, receiver=0x1b3b380, e=0x20bab70)
at kernel/qapplication.cpp:4356
#7  0x00007fffe1ebc0c6 in ?? ()
   from /usr/lib/python3/dist-packages/PyQt4/QtGui.cpython-35m-x86_64-linux-gnu.so
#8  0x00007fffe2eb390d in QCoreApplication::notifyInternal (this=0x17de970, 
receiver=receiver@entry=0x1b3b380, event=event@entry=0x20bab70)
at kernel/qcoreapplication.cpp:955
#9  0x00007fffe2eb73c6 in QCoreApplication::sendEvent (event=0x20bab70, receiver=0x1b3b380)
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:231
#10 QCoreApplicationPrivate::sendPostedEvents (receiver=receiver@entry=0x0, 
event_type=event_type@entry=0, data=0x18fc490) at kernel/qcoreapplication.cpp:1579
#11 0x00007fffe2eb76a3 in QCoreApplication::sendPostedEvents (receiver=receiver@entry=0x0, 
event_type=event_type@entry=0) at kernel/qcoreapplication.cpp:1472
#12 0x00007fffe2ee413e in QCoreApplication::sendPostedEvents ()
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:236
#13 postEventSourceDispatch (s=0x1900aa0) at kernel/qeventdispatcher_glib.cpp:300
#14 0x00007fffe2a62197 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#15 0x00007fffe2a623f0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#16 0x00007fffe2a6249c in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#17 0x00007fffe2ee42ae in QEventDispatcherGlib::processEvents (this=0x17be390, flags=...)
at kernel/qeventdispatcher_glib.cpp:450
#18 0x00007fffe0e7b616 in QGuiEventDispatcherGlib::processEvents (this=<optimised out>, flags=...)
at kernel/qguieventdispatcher_glib.cpp:204
#19 0x00007fffe2eb218f in QEventLoop::processEvents (this=this@entry=0x7fffffffd7d0, flags=...)
at kernel/qeventloop.cpp:149
#20 0x00007fffe2eb24f5 in QEventLoop::exec (this=this@entry=0x7fffffffd7d0, flags=...)
at kernel/qeventloop.cpp:204
#21 0x00007fffe2eb84b9 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:1227
#22 0x00007fffe1e6aa2b in ?? ()
    from /usr/lib/python3/dist-packages/PyQt4/QtGui.cpython-35m-x86_64-linux-gnu.so
#23 0x00000000004e9b7f in PyCFunction_Call ()
#24 0x00000000005372f4 in PyEval_EvalFrameEx ()
#25 0x0000000000540199 in ?? ()
#26 0x0000000000540e4f in PyEval_EvalCode ()
#27 0x000000000060c272 in ?? ()
#28 0x000000000060e71a in PyRun_FileExFlags ()
#29 0x000000000060ef0c in PyRun_SimpleFileExFlags ()
#30 0x000000000063fb26 in Py_Main ()
#31 0x00000000004cfeb1 in main ()
(gdb) 
gdb python3
GNU gdb(Ubuntu 7.11.1-0ubuntu1~16.5)7.11.1
版权所有(C)2016免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。键入“显示复制”
和“显示保修”了解详细信息。
此GDB配置为“x86_64-linux-gnu”。
键入“显示配置”以获取配置详细信息。
有关错误报告说明,请参阅:
.
在线查找GDB手册和其他文档资源,网址为:
.
要获得帮助,请键入“帮助”。
键入“apropos word”以搜索与“word”相关的命令。。。
正在从python3读取符号…(未找到调试符号)…已完成。
(gdb)运行GUI3.py
启动程序:/usr/bin/python3 GUI3.py
[已启用使用libthread_db的线程调试]
使用主机libthread_db library“/lib/x86_64-linux-gnu/libthread_db.so.1”。
[新螺纹0x7FF3AD0700(LWP 26031)]
[新螺纹0x7ffff12cf700(LWP 26032)]
[新螺纹0x7fffeeace700(LWP 26033)]
[新螺纹0x7fffd3da2700(LWP 26034)]
[新螺纹0x7fffd2042700(LWP 26035)]
[新螺纹0x7fffd1841700(LWP 26036)]
[新螺纹0x7fffd1040700(LWP 26037)]
[新螺纹0x7fffbb952700(LWP 26038)]
需要实现Run函数
线程1“python3”接收到信号SIGSEGV,分段错误。
QWidgetBackingStore::在painting/qbackingstore.cpp:1239处同步(此参数=0x1ec5d30)
1239绘画/qbackingstore.cpp:没有这样的文件或目录。
(gdb)回溯
#0 QWidgetBackingStore::在painting/qbackingstore.cpp:1239处同步(此值=0x1ec5d30)
#QWidgetPrivate::syncBackingStore中的1 0x00007fffe0e11c50(此=0x1907c20)
在kernel/qwidget.cpp:1894
#QWidget::事件中的2 0x00007fffe0e249b8(此=this@entry=0x1B380,事件=event@entry=0x20bab70)
在kernel/qwidget.cpp:8693
#QMainWindow::event中的3 0x00007fffe12089b3(此=0x1b3b380,事件=0x20bab70)
在widgets/qmainfown.cpp:1478
#4 0x00007fffe1cfc28b英寸??()
来自/usr/lib/python3/dist packages/PyQt4/QtGui.cpython-35m-x86_64-linux-gnu.so
#QApplicationPrivate::notify_helper中的5 0x00007fffe0dcdfdc(此=this@entry=0x18f9d70,
接受者=receiver@entry=0x1B380,e=e@entry=0x20bab70)在内核/qapplication.cpp:4570
#QApplication::notify中的6 0x00007fffe0dd4f16(此=0x17de970,接收器=0x1B380,e=0x20bab70)
在kernel/qapplication.cpp:4356
#7 0x00007fffe1ebc0c6英寸??()
来自/usr/lib/python3/dist packages/PyQt4/QtGui.cpython-35m-x86_64-linux-gnu.so
#8 QCoreApplication::notifyInternal中的0x00007fffe2eb390d(此=0x17de970,
接受者=receiver@entry=0x1B380,事件=event@entry=0x20bab70)
在kernel/qcoreapplication.cpp:955
#QCoreApplication::sendEvent中的9 0x00007fffe2eb73c6(事件=0x20bab70,接收器=0x1B380)
位于../../include/QtCore/../src/corelib/kernel/qcoreapplication.h:231
#10 QCoreApplicationPrivate::sendPostedEvents(接收器=receiver@entry=0x0,
事件类型=事件_type@entry=0,数据=0x18fc490),位于内核/qcoreapplication.cpp:1579
#QCoreApplication::sendPostedEvents(接收器)中的11 0x00007fffe2eb76a3=receiver@entry=0x0,
事件类型=事件_type@entry=0)在内核/qcoreapplication.cpp:1472
#QCoreApplication::sendPostedEvents()中的12 0x00007fffe2ee413e
位于../../include/QtCore/../src/corelib/kernel/qcoreapplication.h:236
#13内核/qeventdispatcher\u glib.cpp处的postEventSourceDispatch(s=0x1900aa0):300
#14 0x00007fffe2a62197位于/lib/x86\u 64-linux-gnu/libglib-2.0.so.0的g_主上下文中
#15 0x00007fffe2a623f0英寸??()来自/lib/x86_64-linux-gnu/libglib-2.0.so.0
#16 0x00007fffe2a6249c,位于/lib/x86\u 64-linux-gnu/libglib-2.0.so.0的g_main_上下文_迭代()中
#QEventDispatcherGlib::processEvents中的17 0x00007fffe2ee42ae(this=0x17be390,flags=…)
在kernel/qeventdispatcher_glib.cpp:450
#QGuiEventDispatcherGlib::processEvents中的18 0x00007fffe0e7b616(this=,flags=…)
在kernel/qguieventdispatcher_glib.cpp:204
#QEventLoop::processEvents中的19 0x00007fffe2eb218f(此=this@entry=0x7FFFFFD7D0,标志=…)
在kernel/qeventloop.cpp:149
#QEventLoop::exec中的20 0x00007fffe2eb24f5(此=this@entry=0x7FFFFFD7D0,标志=…)
在kernel/qeventloop.cpp:204处
#内核/QCoreApplication.cpp:1227处的QCoreApplication::exec()中的21 0x00007fffe2eb84b9
#22 0x00007fffe1e6aa2b英寸??()
来自/usr/lib/python3/dist packages/PyQt4/QtGui.cpython-35m-x86_64-linux-gnu.so
#PyCFunction_调用()中的23 0x00000000004e9b7f
#PyEval_EvalFrameEx()中的24 0x00000000005372f4
#25 0x0000000000540199英寸??()
#PyEval_EvalCode()中的26 0x0000000000540e4f
#27 0x000000000060c272英寸??()
#PyRun_FileExFlags()中的28 0x000000000060e71a
#PyRun_SimpleFileExFlags()中的29 0x000000000060ef0c
#30 0x000000000063fb26位于Py_干管()
#主管道中的31 0x00000000004cfeb1()
(gdb)

好吧,一个提示:您看到的是调用堆栈

作为一名程序员,您肯定知道,调用函数(或方法)涉及将调用的上下文(参数、局部变量、返回地址)添加到内存中称为堆栈的区域

因此,您看到了当分段错误发生时,您的代码(以及不是您的代码)所做的调用,这些调用尚未返回。当您的进程得到segfault时,它没有继续执行或“展开”堆栈-它只是转储了所有帧。(请注意,框架是从最深到最浅列出的。)

幸运的是,大多数堆栈帧都有正在运行的函数的名称,因此您可以更好地找出在有问题的段中访问内存的确切位置。不幸的是,堆栈跟踪似乎没有行号(这些都是
的对),因此无法重新执行