Skip to content

Commit

Permalink
Reorder reset_arch: param forced, elf header, gdb conf
Browse files Browse the repository at this point in the history
Signed-off-by: José Luis Di Biase <[email protected]>
  • Loading branch information
josx committed Sep 2, 2023
1 parent 6a6e2a0 commit c49ea4f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -3677,21 +3677,22 @@ def reset_architecture(arch: Optional[str] = None) -> None:
raise OSError(f"Specified arch {arch.upper()} is not supported")
return

# check for elf header architecture
if gef.binary.e_machine:
try:
gef.arch = arches[gef.binary.e_machine]()
except KeyError:
raise OSError(f"CPU type is currently not supported: {gef.binary.e_machine}")
return

# last resort, use gdb default architecture
gdb_arch = get_arch()

preciser_arch = next((a for a in arches.values() if a.supports_gdb_arch(gdb_arch)), None)
if preciser_arch:
gef.arch = preciser_arch()
return

# last resort, use the info from elf header to find it from the known architectures
try:
arch_name = gef.binary.e_machine if gef.binary else gdb_arch
gef.arch = arches[arch_name]()
except KeyError:
raise OSError(f"CPU type is currently not supported: {get_arch()}")
return


@lru_cache()
def cached_lookup_type(_type: str) -> Optional[gdb.Type]:
Expand Down

0 comments on commit c49ea4f

Please sign in to comment.