4

我正在尝试为 GDB 编写一个简单的 python 扩展,只要遇到断点就会输出到文件中。根据文档,“可以对 gdb.Breakpoint 类进行子分类”(参见http://sourceware.org/gdb/onlinedocs/gdb/Breakpoints-In-Python.html

但是,当我尝试以下代码时,我收到错误“TypeError:调用元类基时出错。类型'gdb.Breakpoint'不是可接受的基类型”

class MyBreakpoint(gdb.Breakpoint):
  def stop (self):
    print "break"
    return False

我正在运行 Ubuntu 11.04 和 gdb 7.2。任何帮助或更好的文档链接将不胜感激。谢谢!

我的具体步骤:

$ gdb
GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2
Copyright (C) 2010 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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) source t.py 
Traceback (most recent call last):
  File "t.py", line 3, in <module>
    class MyBreakpoint(gdb.Breakpoint):
TypeError: Error when calling the metaclass bases
    type 'gdb.Breakpoint' is not an acceptable base type
(gdb) 
4

2 回答 2

5

适当的 gdb 7.2 文档在这里:

http://sourceware.org/gdb/download/onlinedocs/gdb/Breakpoints-In-Python.html#Breakpoints-In-Python

我假设 EmployedRussian 使用的是相对较新的 gdb 7.2(7.2.90 或类似的似乎包含这些补丁的东西)

这并不是 7.2 的真正正式版本,在许多方面更像是 7.3 的预发布版本,它是在 7.3 分支前大约 2 周创建的(gdb 7.3 的新功能中断)。

所以它对他的工作仅仅是gdb使用“发布前的7.3分支”,而不是“7.2发布后的7.3分支”模型。

所以要使用 7.2 执行此操作,您可能不得不求助于

break foo
commands
python print "break"
end
于 2011-05-01T00:39:56.260 回答
3

您的代码(更正了缩进)似乎与 GDB-7.2 和最近的 GDB CVS 快照一起工作正常:

$ cat t.py
class MyBreakpoint(gdb.Breakpoint):
  def stop (self):
    print "break"
    return False

$ gdb-cvs 
GNU gdb (GDB) 7.3.50.20110411-cvs
Copyright (C) 2011 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-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) source t.py
(gdb) quit

如果您重复上述步骤,您会看到不同的东西吗?如果没有,你到底在做什么来获得TypeError

编辑:这只是因为我的 GDB-7.2 应用了一些上游补丁。它不适用于“香草”7.2

于 2011-04-30T16:05:57.493 回答