Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise "gdb not found" as soon as detected (LP: #2031919) #220

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions apport/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,6 @@ def add_gdb_info(self, rootdir=None, gdb_sandbox=None):
}
gdb_cmd, environ = self.gdb_command(rootdir, gdb_sandbox)
environ["HOME"] = "/nonexistent"
if not gdb_cmd:
raise FileNotFoundError(
errno.ENOENT,
os.strerror(errno.ENOENT),
"gdb not found in retracing env",
)

gdb_cmd += [
"--batch",
# limit maximum backtrace depth (to avoid looped stacks)
Expand Down Expand Up @@ -1811,7 +1804,9 @@ def anonymize(self):
else:
self[k] = pattern.sub(repl, self[k])

def gdb_command(self, sandbox, gdb_sandbox=None):
def gdb_command(
self, sandbox: Optional[str], gdb_sandbox: Optional[str] = None
) -> tuple[list[str], dict[str, str]]:
# TODO: Split into smaller functions/methods
# pylint: disable=too-many-branches,too-many-locals
"""Build gdb command for this report.
Expand Down Expand Up @@ -1841,9 +1836,14 @@ def gdb_command(self, sandbox, gdb_sandbox=None):
)
gdb_path = _which_extrapath("gdb", gdb_sandbox_bin)
if not gdb_path:
return "", ""
raise FileNotFoundError(
errno.ENOENT,
os.strerror(errno.ENOENT),
"gdb not found in retracing env",
)

command = [gdb_path]
environ = {}
environ: dict[str, str] = {}

if not same_arch:
# check if we have gdb-multiarch
Expand Down Expand Up @@ -1884,7 +1884,7 @@ def gdb_command(self, sandbox, gdb_sandbox=None):
environ |= {
"LD_LIBRARY_PATH": ld_lib_path,
"PYTHONHOME": pyhome,
"GCONV_PATH": (f"{gdb_sandbox}/usr/lib/{native_multiarch}/gconv"),
"GCONV_PATH": f"{gdb_sandbox}/usr/lib/{native_multiarch}/gconv",
}
command.insert(
0, f"{gdb_sandbox}" f"/lib/{native_multiarch}/ld-linux-x86-64.so.2"
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@ def test_gen_stacktrace_top(self):
),
)

@unittest.mock.patch("shutil.which", unittest.mock.MagicMock(return_value=None))
def test_gdb_add_info_no_gdb(self):
r = apport.report.Report()
r["Signal"] = "6"
r["ExecutablePath"] = "/bin/bash"
r["CoreDump"] = "/var/lib/apport/coredump/core.bash"
r["AssertionMessage"] = "foo.c:42 main: i > 0"
with self.assertRaises(FileNotFoundError):
r.add_gdb_info()

def test_crash_signature(self):
"""crash_signature()."""
r = apport.report.Report()
Expand Down