GDB event handler for new object file cases.
(evt: Optional["gdb.NewObjFileEvent"])
| 3508 | |
| 3509 | |
| 3510 | def new_objfile_handler(evt: Optional["gdb.NewObjFileEvent"]) -> None: |
| 3511 | """GDB event handler for new object file cases.""" |
| 3512 | reset_all_caches() |
| 3513 | path = evt.new_objfile.filename if evt else gdb.current_progspace().filename |
| 3514 | try: |
| 3515 | if gef.session.root and path.startswith("target:"): |
| 3516 | # If the process is in a container, replace the "target:" prefix |
| 3517 | # with the actual root directory of the process. |
| 3518 | path = path.replace("target:", str(gef.session.root), 1) |
| 3519 | target = pathlib.Path(path) |
| 3520 | FileFormatClasses = list(filter(lambda fmtcls: fmtcls.is_valid(target), __registered_file_formats__)) |
| 3521 | GuessedFileFormatClass : Type[FileFormat] = FileFormatClasses.pop() if len(FileFormatClasses) else Elf |
| 3522 | binary = GuessedFileFormatClass(target) |
| 3523 | if not gef.binary: |
| 3524 | gef.binary = binary |
| 3525 | reset_architecture() |
| 3526 | else: |
| 3527 | gef.session.modules.append(binary) |
| 3528 | except FileNotFoundError as fne: |
| 3529 | # Linux automatically maps the vDSO into our process, and GDB |
| 3530 | # will give us the string 'system-supplied DSO' as a path. |
| 3531 | # This is normal, so we shouldn't warn the user about it |
| 3532 | if "system-supplied DSO" not in path: |
| 3533 | warn(f"Failed to find objfile or not a valid file format: {str(fne)}") |
| 3534 | except RuntimeError as re: |
| 3535 | warn(f"Not a valid file format: {str(re)}") |
| 3536 | return |
| 3537 | |
| 3538 | |
| 3539 | def exit_handler(_: "gdb.ExitedEvent") -> None: |
no test coverage detected