|
| 1 | +import re |
| 2 | + |
| 3 | +# |
| 4 | +# Python MI command to manage gdb's "checkpoint" command.. |
| 5 | +# |
| 6 | +# https://sourceware.org/gdb/current/onlinedocs/gdb.html/Checkpoint_002fRestart.html#Checkpoint_002fRestart |
| 7 | +# |
| 8 | + |
| 9 | +class MICheckpoint(gdb.MICommand): |
| 10 | + """ |
| 11 | + Run the 'checkpoint' command. |
| 12 | +
|
| 13 | + -checkpoint-list List all checkpoints, including the id for each checkpoint. |
| 14 | + -checkpoint-create Create a checkpoint at the current debugging position. |
| 15 | + -checkpoint-select Select a checkpoint to make active as described by ID. |
| 16 | + -checkpoint-delete Delete a checkpoint described by ID. |
| 17 | +
|
| 18 | + See: https://sourceware.org/gdb/current/onlinedocs/gdb.html/Checkpoint_002fRestart.html#Checkpoint_002fRestart |
| 19 | + """ |
| 20 | + |
| 21 | + def __init__(self, name, mode): |
| 22 | + self._mode = mode |
| 23 | + super(MICheckpoint, self).__init__(name) |
| 24 | + |
| 25 | + def invoke(self, argv): |
| 26 | + if self._mode == "list": |
| 27 | + |
| 28 | + checkpointentries = [] |
| 29 | + |
| 30 | + result = gdb.execute ("info checkpoints " + " ".join(argv), to_string=True) |
| 31 | + print(result) |
| 32 | + |
| 33 | + lines = result.split("\n") |
| 34 | + for line in lines: |
| 35 | + if (line == ""): |
| 36 | + continue |
| 37 | + |
| 38 | + columns = re.search(r"^([ *])\ (\d+)\ (.*?)\,\ (.*?)\,\ (.*?)$", line) |
| 39 | + if columns: |
| 40 | + checkpointmeta = {} |
| 41 | + checkpointmeta["id"] = columns.group(2) |
| 42 | + checkpointmeta["state"] = columns.group(1) |
| 43 | + checkpointmeta["process"] = columns.group(3) |
| 44 | + checkpointmeta["file"] = columns.group(4) |
| 45 | + checkpointmeta["line"] = columns.group(5) |
| 46 | + |
| 47 | + checkpointentries.append(checkpointmeta) |
| 48 | + |
| 49 | + else: |
| 50 | + columns = re.search(r"^([ *])\ (\d+)\ (.*)$", line) |
| 51 | + if columns: |
| 52 | + checkpointmeta = {} |
| 53 | + checkpointmeta["id"] = columns.group(2) |
| 54 | + checkpointmeta["state"] = columns.group(1) |
| 55 | + checkpointmeta["process"] = columns.group(3) |
| 56 | + checkpointmeta["file"] = "" |
| 57 | + checkpointmeta["line"] = "" |
| 58 | + |
| 59 | + checkpointentries.append(checkpointmeta) |
| 60 | + |
| 61 | + return { "checkpoints": checkpointentries} |
| 62 | + |
| 63 | + elif self._mode == "create": |
| 64 | + gdb.execute ("checkpoint " + " ".join(argv), to_string=True) |
| 65 | + return None |
| 66 | + elif self._mode == "select": |
| 67 | + gdb.execute ("select " + " ".join(argv), to_string=True) |
| 68 | + return None |
| 69 | + elif self._mode == "delete": |
| 70 | + gdb.execute ("delete checkpoint " + " ".join(argv), to_string=True) |
| 71 | + return None |
| 72 | + else: |
| 73 | + raise gdb.GdbError("checkpoints: Invalid parameter: %s" % self._mode) |
| 74 | + |
| 75 | +MICheckpoint("-checkpoint-list", "list") |
| 76 | +MICheckpoint("-checkpoint-create", "create") |
| 77 | +MICheckpoint("-checkpoint-select", "select") |
| 78 | +MICheckpoint("-checkpoint-delete", "delete") |
| 79 | + |
0 commit comments