scripts: cros_gdb - add option to pass gdb binary

It can be helpful to pass the gdb binary (especially in cros chrome_sdk)
especially when you want to have the option to parse python scripts in
gdb so that complex types can be displayed. Default is to use the old
behaviour only if cross_gdb is passed the binary from there will be
used.

BUG=b:278247253
TEST=cros_gdb --board $SDK_BOARD --remote dut_vm --attach browser
TEST=cros_gdb --board $SDK_BOARD --remote dut_vm --attach browser --cross_gdb /usr/bin/gdb

Change-Id: Ib4ced710efce70ad64cf899920d061ba502a164b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4428031
Reviewed-by: Tim Bain <tbain@google.com>
Tested-by: Marc Grimme <marcgrimme@google.com>
Commit-Queue: Marc Grimme <marcgrimme@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_gdb.py b/scripts/cros_gdb.py
index a7a647f..d33280c 100644
--- a/scripts/cros_gdb.py
+++ b/scripts/cros_gdb.py
@@ -107,6 +107,7 @@
         cgdb_flag,
         ping,
         binary,
+        gdb_binary,
     ):
         self.board = board
         self.sysroot = None
@@ -129,7 +130,7 @@
         self.framework = "auto"
         self.qemu = None
         self.device = None
-        self.cross_gdb = None
+        self.cross_gdb = gdb_binary
         self.ping = ping
         self.binary = binary
         self.in_chroot = None
@@ -210,7 +211,8 @@
         if self.in_chroot:
             self.sysroot = build_target_lib.get_default_sysroot_path(self.board)
             self.inf_cmd = self.RemoveSysrootPrefix(self.inf_cmd)
-            self.cross_gdb = self.GetCrossGdb()
+            if not self.cross_gdb:
+                self.cross_gdb = self.GetCrossGdb()
         else:
             self.chrome_path = os.path.realpath(
                 os.path.join(
@@ -219,7 +221,8 @@
             )
             self.sdk_path = path_util.FindCacheDir()
             self.sysroot = self.SimpleChromeSysroot()
-            self.cross_gdb = self.SimpleChromeGdb()
+            if not self.cross_gdb:
+                self.cross_gdb = self.SimpleChromeGdb()
 
         if self.remote:
             # If given remote process name, find pid & inf_cmd on remote device.
@@ -641,6 +644,11 @@
 
     parser.add_argument("--board", default=None, help="board to debug for")
     parser.add_argument(
+        "--gdb",
+        type="file_exists",
+        help="Path to gdb binary. Default is that gdb binary is auto detected.",
+    )
+    parser.add_argument(
         "-g",
         "--gdb_args",
         action="append",
@@ -777,6 +785,7 @@
         options.cgdb,
         options.ping,
         options.binary,
+        options.gdb,
     )
 
     try: