4

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) 
stefan_g
  • 57
  • 8

2 Answers2

5

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
matt
  • 5,364
  • 1
  • 25
  • 25
  • Yes, I didn't realize my GDB-7.2 has these patches merged in, but it does. When I built "vanilla" 7.2, I got the same error as the OP. – Employed Russian May 01 '11 at 02:48
3

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

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Sorry about the formatting error. I've edited my post with the exact steps I'm taking to produce the error. I've renamed my script to t.py just for consistency. I notice that the CVS snapshot is a few versions ahead of mine, so I'll give that a try next. – stefan_g Apr 30 '11 at 16:21
  • I've been unable to build gdb from source, getting the error "/libdecnumber/decContext.h:54:61: fatal error: gstdint.h: No such file or directory". This is likely not related to the original problem, and since you got it working on 7.2 I doubt building the 7.3 branch would help anyway. Any other ideas? Thanks for the help! – stefan_g Apr 30 '11 at 18:31