在Qt中设置断点后,gdb说:"访问内存地址时出错"

Nei*_*eil 5 debugging qt gdb breakpoints qt4

我在这里写了一个非常简单的Qt程序:

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    QTableView table(&frame);
    table.resize(100, 100);
    table.show();

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

当我尝试设置一个点击表的断点时,我从gdb得到这个错误:

(gdb) symbol-file /usr/lib/libQtGui.so.4.4.3.debug 
Load new symbol table from "/usr/lib/libQtGui.so.4.4.3.debug"? (y or n) y
Reading symbols from /usr/lib/libQtGui.so.4.4.3.debug...done.
(gdb) br 'QAbstractItemView::clicked(QModelIndex const&)'
Breakpoint 1 at 0x5fc660: file .moc/release-shared/moc_qabstractitemview.cpp, line 313.
(gdb) run
Starting program: ./qt-test
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x5fc660: Input/output error.
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么不能插入断点?

Nei*_*eil 11

不要使用gdb命令symbol-file加载外部符号.断点地址是错误的,因为它们没有重新定位.

相反,放入断点main,运行程序,然后设置断点:

gdb ./program
GNU gdb 6.8-debian blah blah blah
(gdb) br main
Breakpoint 1 at 0x80489c1
(gdb) run
Starting program: ./program
Breakpoint 1, 0x080489c1 in main ()
(gdb) br 'QAbstractItemView::clicked(QModelIndex const&)'
Breakpoint 2 at 0xb7d24664
(gdb) continue
Continuing.
Run Code Online (Sandbox Code Playgroud)

然后让你的断点发生.

确保在要设置断点的函数中指定参数列表,而不指定这些参数的名称,只列出它们的类型.

  • 感谢irc.freenode.net中#gdb中的pholklore获取此答案. (4认同)

And*_*ndy 2

如果你想在 main 中自动中断而不设置断点,也可以使用该start命令。
如果您需要向程序提供任何参数,您可以使用:
start argument1 argument2