ClangBuiltLinux / boot-utils

Collection of files for booting Linux kernels
26 stars 7 forks source link

boot-qemu.py: Check gdb_bin earlier #85

Closed nathanchance closed 1 year ago

nathanchance commented 1 year ago

Otherwise, the call to sys.exit() in die() does not work and we end up hanging.

Additionally, move it out of the while loop, as it does not make send to check for gdb_bin every single time we want to invoke it.

nathanchance commented 1 year ago

Though I'm still perplexed; why does sys.exit(1) not end the process? That still seems like a bug to me.

According to Python's documentation around sys.exit() and subprocess.Popen():

A call to sys.exit() is translated into an exception so that clean-up handlers (finally clauses of try statements) can be executed, and so that a debugger can execute a script without running the risk of losing control.

Popen objects are supported as context managers via the with statement: on exit, standard file descriptors are closed, and the process is waited for.

So what I suspect is happening here is that sys.exit() is called within the with statement, raising a SystemExit exception, and the interpreter waits for QEMU to exit before the script is allowed to exit. However, we spawned QEMU with -S, which freezes the CPU until it is started with GDB, so the interpreter hangs. I do not know if that is really a bug. We could potentially solve it by wrapping the whole with statement in a try statement. But this seems like a better fix in my opinion.