2011-04-30 80 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