Beispiel #1
0
def gdb_parse_and_eval(exp):
    """Evaluate an expression and return the gdb.Value or None which
    correspond to the result of the evaluation."""

    # Work around non-existing gdb.parse_and_eval as in released 7.0
    overwrite = gdb.parameter("logging overwrite")
    redirect = gdb.parameter("logging redirect")
    file = gdb.parameter("logging file")
    # Unfortunately there is no mean to check if the logging is enabled or
    # not.  TODO: So we look for the modification date of the logging file
    # to check if it is enabled.
    logging = False

    def restore():
        gdb.execute("set logging off")
        gdb.execute("set logging redirect off")
        gdb.execute("set logging overwrite off")
        gdb.execute("set logging file " + file)
        gdb.execute("set logging redirect " + ("on" if redirect else "off"))
        gdb.execute("set logging logging " + ("on" if logging else "off"))
        # re-enable it after the start of the logging.
        gdb.execute("set logging overwrite " + ("on" if overwrite else "off"))

    gdb.execute("set logging off")
    gdb.execute("set logging file .gdb.python.tmp")
    gdb.execute("set logging overwrite on")
    gdb.execute("set logging redirect on")
    gdb.execute("set logging on")
    try:
        gdb.execute("print %s" % exp)
    except:
        restore()
        return None
    restore()
    return gdb.history(0)
    def invoke(self, arg, from_tty):
        args = arg.split(" ")
        if len(args) is not 2:
            raise gdb.GdbError(
                "Expects 2 arguments. See \"help forward-geometry\"")
        command = "call hpp::model::forwardGeometry({0},{1})".format(
            args[0], args[1])
        print "Calling ", command
        gdb.execute(command, from_tty, True)
        val = gdb.history(0)

        start = val['_M_impl']['_M_start']
        finish = val['_M_impl']['_M_finish']
        end = val['_M_impl']['_M_end_of_storage']
        length = int(finish - start)

        print "%s links" % length

        cl = Client()

        item = start
        while item != finish:
            current = item.dereference()
            name = str(current["name"]["_M_dataplus"]["_M_p"].string())
            pos = [0, 0, 0, 0, 0, 0, 0]
            for i in range(3):
                pos[i] = float(current["p"][i])
            for i in range(4):
                pos[i + 3] = float(current["q"][i])
            cl.gui.applyConfiguration(name, pos)
            item = item + 1
        cl.gui.refresh()
        print "done"
Beispiel #3
0
def gdb_parse_and_eval(exp):
    """Evaluate an expression and return the gdb.Value or None which
    correspond to the result of the evaluation."""

    # Work around non-existing gdb.parse_and_eval as in released 7.0
    overwrite = gdb.parameter("logging overwrite")
    redirect = gdb.parameter("logging redirect")
    file = gdb.parameter("logging file")
    # Unfortunately there is no mean to check if the logging is enabled or
    # not.  TODO: So we look for the modification date of the logging file
    # to check if it is enabled.
    logging = False
    def restore():
        gdb.execute("set logging off")
        gdb.execute("set logging redirect off")
        gdb.execute("set logging overwrite off")
        gdb.execute("set logging file " + file)
        gdb.execute("set logging redirect " + ("on" if redirect else "off"))
        gdb.execute("set logging logging " + ("on" if logging else "off"))
        # re-enable it after the start of the logging.
        gdb.execute("set logging overwrite " + ("on" if overwrite else "off"))
    gdb.execute("set logging off")
    gdb.execute("set logging file .gdb.python.tmp")
    gdb.execute("set logging overwrite on")
    gdb.execute("set logging redirect on")
    gdb.execute("set logging on")
    try:
        gdb.execute("print %s" % exp)
    except:
        restore()
        return None
    restore()
    return gdb.history(0)
    def invoke (self, arg, from_tty):
        args = arg.split (" ")
        if len(args) is not 2:
            raise gdb.GdbError ("Expects 2 arguments. See \"help forward-geometry\"")
        command = "call hpp::model::forwardGeometry({0},{1})".format (args[0], args[1])
        print "Calling ", command
        gdb.execute (command, from_tty, True)
        val = gdb.history (0)

        start = val['_M_impl']['_M_start']
        finish = val['_M_impl']['_M_finish']
        end = val['_M_impl']['_M_end_of_storage']
        length = int (finish - start)

        print "%s links" % length

        cl = Client ()

        item = start
        while item != finish:
            current = item.dereference ()
            name = str(current["name"]["_M_dataplus"]["_M_p"].string())
            pos = [0,0,0,0,0,0,0]
            for i in range(3):
                pos[i] = float(current["p"][i])
            for i in range(4):
                pos[i+3] = float(current["q"][i])
            cl.gui.applyConfiguration (name, pos)
            item = item + 1
        cl.gui.refresh ()
        print "done"
Beispiel #5
0
 def getArg(number):
     "returns string for argument number"
     string= str(gdb.history(number))
     # TODO: does not work for userCommand with ''
     m = re.match('^[\'\"](.*)[\'\"]$', string)
     assert m is not None, 'Expected command line argument for gdb'
     return m.group(1)
 def parse_and_eval(exp):
     if gdb.VERSION.startswith("6.8.50.2009"):
         return gdb.parse_and_eval(exp)
     # Work around non-existing gdb.parse_and_eval as in released 7.0
     gdb.execute("set logging redirect on")
     gdb.execute("set logging on")
     gdb.execute("print %s" % exp)
     gdb.execute("set logging off")
     return gdb.history(0)
Beispiel #7
0
 def parse_and_eval(exp):
     if gdb.VERSION.startswith("6.8.50.2009"):
         return gdb.parse_and_eval(exp)
     # Work around non-existing gdb.parse_and_eval as in released 7.0
     gdb.execute("set logging redirect on")
     gdb.execute("set logging on")
     gdb.execute("print %s" % exp)
     gdb.execute("set logging off")
     return gdb.history(0)
Beispiel #8
0
 def parseAndEvaluate(exp):
     if isGoodGdb():
         return gdb.parse_and_eval(exp)
     # Work around non-existing gdb.parse_and_eval as in released 7.0
     gdb.execute("set logging redirect on")
     gdb.execute("set logging on")
     try:
         gdb.execute("print %s" % exp)
     except:
         gdb.execute("set logging off")
         gdb.execute("set logging redirect off")
         return None
     gdb.execute("set logging off")
     gdb.execute("set logging redirect off")
     return gdb.history(0)
Beispiel #9
0
 def parseAndEvaluate(exp):
     if isGoodGdb():
         return gdb.parse_and_eval(exp)
     # Work around non-existing gdb.parse_and_eval as in released 7.0
     gdb.execute("set logging redirect on")
     gdb.execute("set logging on")
     try:
         gdb.execute("print %s" % exp)
     except:
         gdb.execute("set logging off")
         gdb.execute("set logging redirect off")
         return None
     gdb.execute("set logging off")
     gdb.execute("set logging redirect off")
     return gdb.history(0)
Beispiel #10
0
 def read_variable(self, name):
     gdb.execute("p " + name, to_string=True)
     return gdb.history(0)
Beispiel #11
0
 def read_variable(self, name):
     gdb.execute("p " + name, to_string=True)
     return gdb.history(0)
Beispiel #12
0
    dump_core('outfile.core')


def exit_gdb():
    gdb.execute('set confirm off')
    gdb.execute('quit')


def main():
    parser = ArgumentParser(description='Play around with the GDB library')

    parser.add_argument('binary', help='Command to run')
    parser.add_argument('args', help='Arguments to pass to command', nargs='*')

    args = parser.parse_args()
    print('Run {} with args={}'.format(args.binary, args.args))
    run_with_gdb(args.binary, args.args)
    print('Ran example, now quitting')
    exit_gdb()


if __name__ == '__main__':
    gdb.execute('print $args')
    args = gdb.history(0).string().split(' ')

    import sys
    sys.argv += args
    main()
else:
    print(__name__)