MCPcopy Create free account
hub / github.com/bloomberg/pystack / process_core

Function process_core

src/pystack/__main__.py:340–425  ·  view source on GitHub ↗
(parser: argparse.ArgumentParser, args: argparse.Namespace)

Source from the content-addressed store, hash-verified

338
339
340def process_core(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None:
341 corefile = pathlib.Path(args.core)
342 if not corefile.exists():
343 parser.error(f"Core {corefile} does not exist")
344
345 if is_gzip(corefile):
346 corefile = decompress_gzip(corefile)
347
348 if args.executable is None:
349 corefile_analyzer = CoreFileAnalyzer(corefile)
350 executable = pathlib.Path(corefile_analyzer.extract_executable())
351 if not is_elf(executable):
352 first_map = next(
353 (
354 map
355 for map in corefile_analyzer.extract_maps()
356 if map.path is not None
357 ),
358 None,
359 )
360 if (
361 first_map is not None
362 and first_map.path is not None
363 and is_elf(first_map.path)
364 ):
365 executable = first_map.path
366 LOGGER.info(
367 "Setting executable automatically to the first map in the core: %s",
368 executable,
369 )
370 if not executable.exists():
371 raise errors.DetectedExecutableNotFound(
372 f"Detected executable doesn't exist: {executable}"
373 )
374 print(f"Using executable found in the core file: {executable}")
375 else:
376 executable = pathlib.Path(args.executable)
377
378 if not executable.exists():
379 parser.error(f"Executable {executable} does not exist")
380
381 lib_search_path = ""
382 if args.lib_search_path:
383 lib_search_path = args.lib_search_path
384 if args.lib_search_root:
385 library_dirs: Set[str] = set()
386 for pattern in {"**/*.so", "**/*.so.*"}:
387 library_dirs.update(
388 str(file.parent)
389 for file in pathlib.Path(args.lib_search_root).glob(pattern)
390 )
391 lib_search_path = ":".join(sorted(library_dirs))
392 LOGGER.info("Using library search path: %s", lib_search_path)
393
394 corefile_analyzer = CoreFileAnalyzer(corefile, executable, lib_search_path)
395 with suppress(Exception):
396 print(format_psinfo_information(corefile_analyzer.extract_ps_info()))
397 print(format_failureinfo_information(corefile_analyzer.extract_failure_info()))

Callers

nothing calls this directly

Calls 8

is_gzipFunction · 0.90
decompress_gzipFunction · 0.90
is_elfFunction · 0.90
CoreFileAnalyzerClass · 0.85
print_threadFunction · 0.85
existsMethod · 0.80

Tested by

no test coverage detected