Klement Sekera | 909a6a1 | 2017-08-08 04:33:53 +0200 | [diff] [blame] | 1 | """ debug utilities """ |
| 2 | |
| 3 | import os |
| 4 | import pexpect |
juraj.linkes | 40dd73b | 2018-09-21 13:55:16 +0200 | [diff] [blame] | 5 | import sys |
Klement Sekera | 909a6a1 | 2017-08-08 04:33:53 +0200 | [diff] [blame] | 6 | |
| 7 | gdb_path = '/usr/bin/gdb' |
| 8 | |
| 9 | |
juraj.linkes | 40dd73b | 2018-09-21 13:55:16 +0200 | [diff] [blame] | 10 | def spawn_gdb(binary_path, core_path): |
Klement Sekera | 909a6a1 | 2017-08-08 04:33:53 +0200 | [diff] [blame] | 11 | if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK): |
| 12 | # automatically attach gdb |
| 13 | gdb_cmdline = "%s %s %s" % (gdb_path, binary_path, core_path) |
| 14 | gdb = pexpect.spawn(gdb_cmdline) |
| 15 | gdb.interact() |
| 16 | try: |
| 17 | gdb.terminate(True) |
| 18 | except: |
| 19 | pass |
| 20 | if gdb.isalive(): |
| 21 | raise Exception("GDB refused to die...") |
| 22 | else: |
juraj.linkes | 40dd73b | 2018-09-21 13:55:16 +0200 | [diff] [blame] | 23 | sys.stderr.write("Debugger '%s' does not exist or is not " |
| 24 | "an executable..\n" % gdb_path) |