import gdb

class FunCatchpoint (gdb.Breakpoint):

    #__init__ spec [type] [wp_class] [internal]
    def __init__(self, arg):
        super (FunCatchpoint, self).__init__("__cxa_throw")
        self.active = arg

    def stop (self):
#        print "stop called for: " + self.active
        frame = gdb.newest_frame()
        while frame:
#            print frame.name()
            if frame.name() == self.active:
                return True
            frame = frame.older()
        return False

class FunCatch(gdb.Command):
    """catch exceptions (but only when inside the given function)

       example:  fcatch SfxBaseModel::getTitle"""

    def __init__ (self):
        super (FunCatch, self).__init__ (
            "fcatch", gdb.COMMAND_BREAKPOINTS)
        #not a good idea: need names, not symbols, gdb.COMPLETE_SYMBOL)

    def invoke (self, arg, from_tty):
        FunCatchpoint(arg)

FunCatch()
