diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2023-03-30 16:33:24 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-03 19:03:43 +0000 |
commit | fef3763f1534f2e01423e4b44a13cc2efefc48cf (patch) | |
tree | 727f8b58e23fd1edf0e049937c287f15652be070 | |
parent | 0828964c98e1f0c0ed6f70136d4ad4e9ed9ffc5e (diff) | |
download | chrome-ec-fef3763f1534f2e01423e4b44a13cc2efefc48cf.tar.gz |
ec_openocd: add an option for using an external gdbserver
Add an option to skip the openocd start altogether and just run GDB and
connect to an already running target. This is useful for using a
different gdbserver (such as JLinkGDBServer), but still have most of the
gdb initialization sequence done by the script.
BRANCH=none
BUG=b:276311425
TEST=./util/ec_openocd.py --board rex flash
TEST=./util/ec_openocd.py --board rex flash -x
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: I8e9ce853484160441ba79e378db3d513b3f6af3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4386297
Reviewed-by: Robert Zieba <robertzieba@google.com>
-rwxr-xr-x | util/ec_openocd.py | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/util/ec_openocd.py b/util/ec_openocd.py index b15b002789..76348c6329 100755 --- a/util/ec_openocd.py +++ b/util/ec_openocd.py @@ -55,7 +55,7 @@ def create_openocd_args(interface, board): return args -def create_gdb_args(board, port, executable): +def create_gdb_args(board, port, executable, attach): if not board in boards: raise RuntimeError(f"Unsupported board {board}") @@ -85,6 +85,9 @@ def create_gdb_args(board, port, executable): f"target extended-remote localhost:{port}", ] + if not attach: + args.extend(["-ex", "load"]) + return args @@ -98,7 +101,7 @@ def flash(interface, board, image, verify): subprocess.run(args, stdout=sys.stdout, stderr=subprocess.STDOUT) -def debug(interface, board, port, executable): +def debug(interface, board, port, executable, attach): # Start OpenOCD in the background openocd_args = create_openocd_args(interface, board) openocd_args += ["-c", f"gdb_port {port}"] @@ -127,7 +130,7 @@ def debug(interface, board, port, executable): sock.close() - gdb_args = create_gdb_args(board, port, executable) + gdb_args = create_gdb_args(board, port, executable, attach) # Start GDB gdb = subprocess.Popen( gdb_args, stdout=sys.stdout, stderr=subprocess.STDOUT, stdin=sys.stdin @@ -154,6 +157,18 @@ def debug(interface, board, port, executable): print(openocd_out) +def debug_external(board, port, executable, attach): + """Run GDB against an external gdbserver.""" + gdb_args = create_gdb_args(board, port, executable, attach) + subprocess.run( + gdb_args, + stdout=sys.stdout, + stderr=subprocess.STDOUT, + stdin=sys.stdin, + check=True, + ) + + def get_flash_file(board): return ( EC_BASE / "build" / "zephyr" / board / "output" / "ec.bin" @@ -217,6 +232,18 @@ def main(): type=int, default=3333, ) + debug_parser.add_argument( + "--external-gdbserver", + "-x", + help="Do not run openocd, use an already running external gdb server", + action="store_true", + ) + debug_parser.add_argument( + "--attach", + "-a", + help="Do not load the binary after starting gdb, attach to the running instance instead", + action="store_true", + ) args = parser.parse_args() # Get the image path if we were given one @@ -235,7 +262,21 @@ def main(): if target_file == None else target_file ) - debug(args.interface, args.board, args.port, executable_file) + if args.external_gdbserver: + debug_external( + args.board, + args.port, + executable_file, + args.attach, + ) + else: + debug( + args.interface, + args.board, + args.port, + executable_file, + args.attach, + ) else: parser.print_usage() |