Files
mango/tools/kernel-debug/debug_session.py

63 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import sys
import os
import subprocess
import time
import signal
qemu_args = []
gdb_args = []
cur_program = ''
def run_process(args):
p = subprocess.Popen(args,
bufsize=1,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
while True:
retcode = p.poll()
line = p.stdout.read(1)
yield line
if retcode is not None:
break
for arg in sys.argv[1:]:
if arg == '--qemu':
cur_program = 'qemu'
continue
elif arg == '--gdb':
cur_program = 'gdb'
continue
if cur_program == 'qemu':
qemu_args += [arg]
elif cur_program == 'gdb':
gdb_args += [arg]
else:
print('No program specified')
exit(-1)
env = os.environ.copy()
signal.signal(signal.SIGINT, signal.SIG_IGN)
qemu = subprocess.Popen(qemu_args,
env=env,
start_new_session=True,
restore_signals=False)
time.sleep(1)
if qemu.poll() is not None:
print('Failed to start QEMU')
exit(-1)
subprocess.run(gdb_args,
env=env,
stdout=sys.stdout,
stdin=sys.stdin,
stderr=sys.stderr)
qemu.kill()