Skip to content

Commit

Permalink
report: add _get_gdb_path helper function
Browse files Browse the repository at this point in the history
Introduce the `_get_gdb_path` helper function to reduce the size of
`Report.gdb_command`.
  • Loading branch information
bdrung committed Jul 11, 2024
1 parent 2f18763 commit fa3e89c
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions apport/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa3e89c

Please sign in to comment.