forked from driftregion/iso14229
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_gdb.py
executable file
·56 lines (44 loc) · 1.4 KB
/
run_gdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
__doc__ = """
Automates bazel, gdb, and optionally qemu to accelerate debugging
the `bazel test` command explicitly prohibits interactive debugging,
so this script exists to automate the debugging process.
"""
import subprocess
import argparse
import os
GDB = "gdb-multiarch"
QEMU = "qemu-arm"
QEMU_LDFLAGS = "/usr/arm-linux-gnueabihf/"
GDB_PORT = 1234
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("test", help="The test to debug")
parser.add_argument("--config", help="bazel config", default="")
args = parser.parse_args()
gdb_args = [GDB, "-q", "-ex", f"file bazel-bin/test/{args.test}"]
print(f"building {args.test}...")
bazel_args = ["bazel", "build", "-c", "dbg", "--copt=-g", f"//test:{args.test}"]
if args.config:
bazel_args.append(f"--config={args.config}")
subprocess.check_call(bazel_args)
procs = []
if args.config:
qemu = subprocess.Popen(
[QEMU, "-g", str(GDB_PORT),
"-L", "/usr/arm-linux-gnueabihf/",
f"bazel-bin/test/{args.test}"],
env=os.environ.copy(),
)
if qemu.returncode is not None:
exit(qemu.returncode)
procs.append(qemu)
gdb_args += ["-ex", f"target remote localhost:{GDB_PORT}"]
try:
gdb = subprocess.Popen(gdb_args, env=os.environ.copy())
procs.append(gdb)
gdb.wait()
except KeyboardInterrupt:
pass
finally:
[p.kill() for p in procs]
exit(gdb.returncode)