Skip to content

Commit

Permalink
Fallback to the first executable map if the given executable is invalid
Browse files Browse the repository at this point in the history
When a core file is created from a Python script that's executed
directly via shebang, the reported executable will be the shell script.
This is a problem because when we proceed to analyse the core file
pystack fails as this is not the correct binary that was used to
generate the core.

To avoid this problem, detect when this happens and fall back to the
executable reported in the first map that has a path in the core, which
is generally the real executable that we need.
  • Loading branch information
pablogsal committed May 24, 2024
1 parent 3edc7ef commit fa6cd96
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/pystack/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,20 @@ def process_core(parser: argparse.ArgumentParser, args: argparse.Namespace) -> N
print(format_failureinfo_information(corefile_analyzer.extract_failure_info()))

if not is_elf(executable):
raise errors.InvalidExecutable(
f"The provided executable ({executable}) doesn't have an executable format"
first_map = next(
(map for map in corefile_analyzer.extract_maps() if map.path is not None),
None,
)
if first_map is not None and is_elf(first_map.path):
executable = first_map.path
LOGGER.info(
"Setting executable automatically to the first map in the core: %s",
executable,
)
else:
raise errors.InvalidExecutable(
f"The provided executable ({executable}) doesn't have an executable format"
)

if args.native_mode != NativeReportingMode.OFF:
for module in corefile_analyzer.missing_modules():
Expand Down

0 comments on commit fa6cd96

Please sign in to comment.