Skip to content

Commit

Permalink
[arm] fix ptrsize caching
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Jan 9, 2022
1 parent d5a3bb6 commit 64e3115
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -2121,29 +2121,29 @@ def sp(self):
def fp(self):
return self.register("$fp")

__ptrsize = None
_ptrsize = None
@property
def ptrsize(self):
if not self.__ptrsize:
if not self._ptrsize:
res = cached_lookup_type("size_t")
if res is not None:
self.__ptrsize = res.sizeof
self._ptrsize = res.sizeof
else:
self.__ptrsize = gdb.parse_and_eval("$pc").type.sizeof
return self.__ptrsize
self._ptrsize = gdb.parse_and_eval("$pc").type.sizeof
return self._ptrsize

__endianness = None
_endianness = None
@property
def endianness(self) -> Endianness:
if not self.__endianness:
if not self._endianness:
output = gdb.execute("show endian", to_string=True).strip().lower()
if "little endian" in output:
self.__endianness = Endianness.LITTLE_ENDIAN
self._endianness = Endianness.LITTLE_ENDIAN
elif "big endian" in output:
self.__endianness = Endianness.BIG_ENDIAN
self._endianness = Endianness.BIG_ENDIAN
else:
raise OSError(f"No valid endianess found in '{output}'")
return self.__endianness
return self._endianness

def get_ith_parameter(self, i, in_func=True):
"""Retrieves the correct parameter used for the current function call."""
Expand Down Expand Up @@ -2330,9 +2330,7 @@ def instruction_length(self):

@property
def ptrsize(self):
if not self.__ptrsize:
self.__ptrsize = 2 if self.is_thumb() else 4
return self.__ptrsize
return 2 if self.is_thumb() else 4

def is_call(self, insn):
mnemo = insn.mnemonic
Expand Down

0 comments on commit 64e3115

Please sign in to comment.