How to ignore errors in user defined commands?

Tom Tromey tromey@redhat.com
Tue Jun 22 16:12:00 GMT 2010


>>>>> "Steffen" == Steffen Dettmer <steffen.dettmer@googlemail.com> writes:

Steffen> when an error occures, the execution of a user define command
Steffen> stops. How can I avoid this?

Steffen> I use arm-elf-gdb-6.8 to debug my remote target.

With 6.8, I think there is no way.

A long time ago there was a patch to add exception handling to the gdb
command language.  This is still in bugzilla somewhere.  I don't know
why it was never applied.

With a Python-enabled gdb you can write a command like the appended.
Then you can "ignore-errors do something".

Tom

class IgnoreErrorsCommand (gdb.Command):
    """Execute a single command, ignoring all errors.
Only one-line commands are supported.
This is primarily useful in scripts."""

    def __init__ (self):
        super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
                                                    gdb.COMMAND_OBSCURE,
                                                    # FIXME...
                                                    gdb.COMPLETE_COMMAND)

    def invoke (self, arg, from_tty):
        try:
            gdb.execute (arg, from_tty)
        except:
            pass

IgnoreErrorsCommand ()



More information about the Gdb mailing list