编写 PythonGDB 扩展时尝试子类化 gdb.Breakpoint 时出错

发布于 2024-11-04 13:18:09 字数 1289 浏览 0 评论 0原文

我正在尝试为 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) 

I'm trying to write a simple python extension for GDB that outputs to a file whenever a breakpoint is hit. According to the documentation, "The gdb.Breakpoint class can be sub-classed" (see http://sourceware.org/gdb/onlinedocs/gdb/Breakpoints-In-Python.html)

However when I try the following code I get the error "TypeError: Error when calling the metaclass bases. type 'gdb.Breakpoint' is not an acceptable base type"

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

I'm running Ubuntu 11.04 and gdb 7.2. Any help or links to better documentation would be appreciated. Thanks!

My exact steps:

$ 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) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相应的 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

The appropriate gdb 7.2 documentation is here:

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

I'm assuming EmployedRussian is using a relatively recent gdb 7.2 (7.2.90 or something equivalent which seems to contain these patches)

this is not really an official release of 7.2 and in many ways is more like a 7.3 pre-release, having been created just about 2 weeks before 7.3 branched
(the new feature cut off of gdb 7.3).

so that it worked on his is merely that gdb uses a 'branch 7.3 before release', rather than 'branch 7.3 after 7.2 release' model.

so to do this with 7.2 you might have to resort to

break foo
commands
python print "break"
end
凉城已无爱 2024-11-11 13:18:09

您的代码(已更正缩进)似乎可以与 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 应用了一些上游补丁。
不适用于“vanilla”7.2

Your code (corrected for indentation) appears to work fine with GDB-7.2 and recent GDB CVS snapshot:

$ 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

Do you see something different if you repeat steps above?
If not, what exactly are you doing to get the TypeError?

EDIT: this only works because my GDB-7.2 has some upstream patches applied.
It does not work with "vanilla" 7.2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文