2011-04-30 82 views
4

我正在尝试为GDB编写一个简单的python扩展,只要命中断点就输出到文件。根据该文件,“该gdb.Breakpoint类可以子类化”(见http://sourceware.org/gdb/onlinedocs/gdb/Breakpoints-In-Python.html尝试在编写PythonGDB扩展时创建gdb.Breakpoint的子类时出错

然而,当我尝试下面的代码我得到的错误“类型错误:调用元类基地时,错误类型“GDB。断点'不是可接受的基类型“

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) 

回答

5

适当的GDB 7.2的文档是在这里:

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

我假设EmployedRussian使用相对较新的GDB 7.2(90年7月2日或似乎包含这些补丁的东西相当)

这不是真正的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 
+0

是的,我没有意识到我的GDB-7.2已经合并了这些补丁,但它确实如此。当我建立“香草”7.2时,我得到了和OP一样的错误。 – 2011-05-01 02:48:07

+0

是的,我设法建立了7.2.90,它工作。谢谢! – 2011-05-01 18:41:39

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

+0

很抱歉的格式错误。我已经编辑我的帖子,我正在采取的步骤来产生错误。为了保持一致性,我将脚本重命名为t.py。我注意到CVS快照是我的几个版本,所以我会接下来尝试一下。 – 2011-04-30 16:21:01

+0

我一直无法从源代码构建gdb,得到错误“/libdecnumber/decContext.h:54:61:致命错误:gstdint.h:没有这样的文件或目录”。这很可能与原始问题无关,并且因为你在7.2下工作,所以无论如何建立7.3分支都会有所帮助。任何其他想法?谢谢您的帮助! – 2011-04-30 18:31:53