From 0ad4bafa040464a2c95624b4c1c40de7b9b2d585 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 6 Jan 2025 09:46:53 +0200 Subject: [PATCH] Debugger: Fix support for big-endian targets Amends 67072d3f5bb1b425a2b9d3bf30d57542e9f88902. Change-Id: I7c3c08d970e837f77f7194aa80ad403da1ddd4e9 Reviewed-by: Christian Stenger Reviewed-by: hjk --- share/qtcreator/debugger-with-python2/dumper.py | 7 ++++--- share/qtcreator/debugger-with-python2/gdbbridge.py | 1 + share/qtcreator/debugger/dumper.py | 13 +++++++------ share/qtcreator/debugger/gdbbridge.py | 1 + share/qtcreator/debugger/lldbbridge.py | 5 ++++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/share/qtcreator/debugger-with-python2/dumper.py b/share/qtcreator/debugger-with-python2/dumper.py index 1fd42848d4e..7fd12eb5f09 100644 --- a/share/qtcreator/debugger-with-python2/dumper.py +++ b/share/qtcreator/debugger-with-python2/dumper.py @@ -188,6 +188,7 @@ class DumperBase(): self.typeData = {} self.isBigEndian = False self.packCode = '<' + self.byteorder = 'little' self.resetCaches() self.resetStats() @@ -1560,17 +1561,17 @@ class DumperBase(): primaryOpcode = data[0] if primaryOpcode == relativeJumpCode: # relative jump on 32 and 64 bit with a 32bit offset - offset = int.from_bytes(data[1:5], byteorder='little') + offset = int.from_bytes(data[1:5], byteorder=self.byteorder) return address + 5 + offset if primaryOpcode == jumpCode: if data[1] != 0x25: # check for known extended opcode return 0 # 0xff25 is a relative jump on 64bit and an absolute jump on 32 bit if self.ptrSize() == 8: - offset = int.from_bytes(data[2:6], byteorder='little') + offset = int.from_bytes(data[2:6], byteorder=self.byteorder) return address + 6 + offset else: - return int.from_bytes(data[2:6], byteorder='little') + return int.from_bytes(data[2:6], byteorder=self.byteorder) return 0 # Do not try to extract a function pointer if there are no values to compare with diff --git a/share/qtcreator/debugger-with-python2/gdbbridge.py b/share/qtcreator/debugger-with-python2/gdbbridge.py index 9699e518fe3..822e995f0ff 100644 --- a/share/qtcreator/debugger-with-python2/gdbbridge.py +++ b/share/qtcreator/debugger-with-python2/gdbbridge.py @@ -666,6 +666,7 @@ class Dumper(DumperBase): self.isBigEndian = gdb.execute('show endian', to_string=True).find('big endian') > 0 self.packCode = '>' if self.isBigEndian else '<' + self.byteorder = 'big' if self.isBigEndian else 'little' (ok, res) = self.tryFetchInterpreterVariables(args) if ok: diff --git a/share/qtcreator/debugger/dumper.py b/share/qtcreator/debugger/dumper.py index e7e25a482fe..677943ca34a 100644 --- a/share/qtcreator/debugger/dumper.py +++ b/share/qtcreator/debugger/dumper.py @@ -178,6 +178,7 @@ class DumperBase(): self.isBigEndian = False self.packCode = '<' + self.byteorder = 'little' self.resetCaches() self.resetStats() @@ -1767,17 +1768,17 @@ class DumperBase(): primaryOpcode = data[0] if primaryOpcode == relativeJumpCode: # relative jump on 32 and 64 bit with a 32bit offset - offset = int.from_bytes(data[1:5], byteorder='little') + offset = int.from_bytes(data[1:5], byteorder=self.byteorder) return address + 5 + offset if primaryOpcode == jumpCode: if data[1] != 0x25: # check for known extended opcode return 0 # 0xff25 is a relative jump on 64bit and an absolute jump on 32 bit if self.ptrSize() == 8: - offset = int.from_bytes(data[2:6], byteorder='little') + offset = int.from_bytes(data[2:6], byteorder=self.byteorder) return address + 6 + offset else: - return int.from_bytes(data[2:6], byteorder='little') + return int.from_bytes(data[2:6], byteorder=self.byteorder) return 0 # Do not try to extract a function pointer if there are no values to compare with @@ -2532,7 +2533,7 @@ typename)) def extract_pointer_at_address(self, address): blob = self.value_data_from_address(address, self.ptrSize()) - return int.from_bytes(blob, byteorder='little') + return int.from_bytes(blob, byteorder=self.byteorder) def value_extract_integer(self, value, size, signed): if isinstance(value.lvalue, int): @@ -2542,7 +2543,7 @@ typename)) #with self.dumper.timer('extractInt'): value.check() blob = self.value_data(value, size) - return int.from_bytes(blob, byteorder='little', signed=signed) + return int.from_bytes(blob, byteorder=self.byteorder, signed=signed) def value_extract_something(self, valuish, size, signed=False): if isinstance(valuish, int): @@ -2551,7 +2552,7 @@ typename)) blob = self.value_data(valuish, size) else: raise RuntimeError('CANT EXTRACT FROM %s' % type(valuish)) - res = int.from_bytes(blob, byteorder='little', signed=signed) + res = int.from_bytes(blob, byteorder=self.byteorder, signed=signed) #self.warn("EXTRACTED %s SIZE %s FROM %s" % (res, size, blob)) return res diff --git a/share/qtcreator/debugger/gdbbridge.py b/share/qtcreator/debugger/gdbbridge.py index fec4ee84b3d..cbda6aa7ce6 100644 --- a/share/qtcreator/debugger/gdbbridge.py +++ b/share/qtcreator/debugger/gdbbridge.py @@ -679,6 +679,7 @@ class Dumper(DumperBase): self.isBigEndian = gdb.execute('show endian', to_string=True).find('big endian') > 0 self.packCode = '>' if self.isBigEndian else '<' + self.byteorder = 'big' if self.isBigEndian else 'little' #(ok, res) = self.tryFetchInterpreterVariables(args) #if ok: diff --git a/share/qtcreator/debugger/lldbbridge.py b/share/qtcreator/debugger/lldbbridge.py index 4863a0b3f58..52288f07869 100644 --- a/share/qtcreator/debugger/lldbbridge.py +++ b/share/qtcreator/debugger/lldbbridge.py @@ -145,7 +145,7 @@ class Dumper(DumperBase): target_typeid = self.from_native_type(nativeTargetType) target_address = nativeValue.GetValueAsUnsigned() val = self.Value(self) - val.ldata = target_address.to_bytes(self.ptrSize(), 'little') + val.ldata = target_address.to_bytes(self.ptrSize(), self.byteorder) if self.useDynamicType: target_typeid = self.dynamic_typeid_at_address(target_typeid, target_address) val.typeid = self.create_reference_typeid(target_typeid) @@ -1354,6 +1354,9 @@ class Dumper(DumperBase): return self.isArmMac = frame.module.triple.startswith('arm64-apple') + self.isBigEndian = frame.module.byte_order == lldb.eByteOrderBig + self.packCode = '>' if self.isBigEndian else '<' + self.byteorder = 'big' if self.isBigEndian else 'little' self.output = [] isPartial = len(self.partialVariable) > 0