blob: d1c89c66f3c419ea81b2fac414c6c9d334623dc3 [file] [log] [blame]
Klement Sekera909a6a12017-08-08 04:33:53 +02001""" debug utilities """
2
3import os
4import pexpect
juraj.linkes40dd73b2018-09-21 13:55:16 +02005import sys
Klement Sekera909a6a12017-08-08 04:33:53 +02006
7gdb_path = '/usr/bin/gdb'
8
9
juraj.linkes40dd73b2018-09-21 13:55:16 +020010def spawn_gdb(binary_path, core_path):
Klement Sekera909a6a12017-08-08 04:33:53 +020011 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.linkes40dd73b2018-09-21 13:55:16 +020023 sys.stderr.write("Debugger '%s' does not exist or is not "
24 "an executable..\n" % gdb_path)