On 10/19/26 21:26, Alex Bennée wrote:
Passing a plain string to subprocess involves making sure the escaping
is correct so the underlying shell doesn't get confused. This can be
tricky to track across multiple processes. To simplify this build the
command as an array and execute gdb directly without involving the
shell.
We add a mini-helper to make the log output a bit more copy and paste
friendly.
Suggested-by: Ilya Leoshkevich <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
---
tests/guest-debug/run-test.py | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/tests/guest-debug/run-test.py b/tests/guest-debug/run-test.py
index 838c1c26971..e8b69f85cd1 100755
--- a/tests/guest-debug/run-test.py
+++ b/tests/guest-debug/run-test.py
@@ -51,6 +51,10 @@ def log(output, msg):
print(msg)
+def format_cmd(cmd):
+ return " ".join(f'"{arg}"' if ' ' in arg else arg for arg in cmd)
I would use shlex.quote() here.
It doesn't do anything to strings that don't require quoting:
>>> print(shlex.quote('aaa'))
aaa
>>> print(shlex.quote('"aaa'))
'"aaa'
With that:
Reviewed-by: Ilya Leoshkevich <[email protected]>
[...]