From fa3e89c05fce78b6ed7cb53381f365b0673f8b1d Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 11 Jul 2024 12:17:44 +0200 Subject: [PATCH] report: add _get_gdb_path helper function Introduce the `_get_gdb_path` helper function to reduce the size of `Report.gdb_command`. --- apport/report.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/apport/report.py b/apport/report.py index e5bc2f132..10bbfcc49 100644 --- a/apport/report.py +++ b/apport/report.py @@ -259,6 +259,29 @@ def _dom_remove_space(node): _dom_remove_space(c) +def _get_gdb_path(gdb_sandbox: str | None, same_arch: bool) -> str: + """Determine path to GDB.""" + gdb_sandbox_bin = os.path.join(gdb_sandbox, "usr", "bin") if gdb_sandbox else None + gdb_path = _which_extrapath("gdb", gdb_sandbox_bin) + if not gdb_path: + raise FileNotFoundError( + errno.ENOENT, os.strerror(errno.ENOENT), "gdb not found in retracing env" + ) + + if not same_arch: + # check if we have gdb-multiarch + ma = _which_extrapath("gdb-multiarch", gdb_sandbox_bin) + if ma: + gdb_path = ma + else: + sys.stderr.write( + "WARNING: Please install gdb-multiarch for processing " + 'reports from foreign architectures. Results with "gdb" ' + "will be very poor.\n" + ) + return gdb_path + + def _run_hook(report, ui, hook): if not os.path.exists(hook): return False @@ -1862,32 +1885,9 @@ def gdb_command( ): same_arch = True - gdb_sandbox_bin = ( - os.path.join(gdb_sandbox, "usr", "bin") if gdb_sandbox else None - ) - gdb_path = _which_extrapath("gdb", gdb_sandbox_bin) - if not gdb_path: - raise FileNotFoundError( - errno.ENOENT, - os.strerror(errno.ENOENT), - "gdb not found in retracing env", - ) - - command = [gdb_path] + command = [_get_gdb_path(gdb_sandbox, same_arch)] environ: dict[str, str] = {} - if not same_arch: - # check if we have gdb-multiarch - ma = _which_extrapath("gdb-multiarch", gdb_sandbox_bin) - if ma: - command = [ma] - else: - sys.stderr.write( - "WARNING: Please install gdb-multiarch for processing " - 'reports from foreign architectures. Results with "gdb" ' - "will be very poor.\n" - ) - if sandbox: native_multiarch = "x86_64-linux-gnu" # N.B. set solib-absolute-prefix is an alias for set sysroot