blob: 4516b8c150be94338587d2f246ff684dd6873eec [file] [log] [blame]
Klement Sekera909a6a12017-08-08 04:33:53 +02001""" debug utilities """
2
3import os
4import pexpect
5
6gdb_path = '/usr/bin/gdb'
7
8
9def spawn_gdb(binary_path, core_path, logger):
10 if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
11 # automatically attach gdb
12 gdb_cmdline = "%s %s %s" % (gdb_path, binary_path, core_path)
13 gdb = pexpect.spawn(gdb_cmdline)
14 gdb.interact()
15 try:
16 gdb.terminate(True)
17 except:
18 pass
19 if gdb.isalive():
20 raise Exception("GDB refused to die...")
21 else:
22 logger.error("Debugger '%s' does not exist or is not an "
23 "executable.." % gdb_path)