From e7d90c23b6275a56cb63ec40792faaa615003f67 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 24 Jun 2022 14:46:39 +0200 Subject: [PATCH] Dumper: Fix dump of std::string on macOS Try to handle the alternate layout of strings correctly. Depending on the defines and the endianness the string structure may vary quite a bit. Old approach just took care of the default layout and the endianness. In case of an alternate layout of strings we failed so far. Fixes: QTCREATORBUG-26175 Done-with: Viktor Govako Change-Id: I788eb5619408bca281eb887c3f6a269808c27d24 Reviewed-by: hjk --- share/qtcreator/debugger/stdtypes.py | 58 ++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/share/qtcreator/debugger/stdtypes.py b/share/qtcreator/debugger/stdtypes.py index 1f4386607d7..41d96b15f32 100644 --- a/share/qtcreator/debugger/stdtypes.py +++ b/share/qtcreator/debugger/stdtypes.py @@ -776,28 +776,54 @@ def qdumpHelper__std__string__MSVC(d, value, charType, format): d.putCharArrayHelper(data, size, charType, format) +def qdump__std____1__string__alternateLayoutHelper(d, value): + try: + _d = value['__s']['__data_'].address() + alternateLayout = (_d - value.address()) == 0 + if alternateLayout: + lastByte = value.split('b')[-1] + if int(lastByte & 0x80) == 0: + # Short/internal + size = value['__s']['__size_'].integer() + data = value.address() + else: + # Long/external + (data, size, _) = value.split('ppp') + return size, data + else: + return None, None + except: + return None, None + + def qdump__std____1__string(d, value): - firstByte = value.split('b')[0] - if int(firstByte & 1) == 0: - # Short/internal. - size = int(firstByte / 2) - data = value.address() + 1 - else: - # Long/external. - (dummy, size, data) = value.split('ppp') + (size, data) = qdump__std____1__string__alternateLayoutHelper(d, value) + if size is None or data is None: + firstByte = value.split('b')[0] + if int(firstByte & 1) == 0: + # Short/internal. + size = int(firstByte / 2) + data = value.address() + 1 + else: + # Long/external. + (_, size, data) = value.split('ppp') + d.putCharArrayHelper(data, size, d.charType(), d.currentItemFormat()) d.putType("std::string") def qdump__std____1__wstring(d, value): - firstByte = value.split('b')[0] - if int(firstByte & 1) == 0: - # Short/internal. - size = int(firstByte / 2) - data = value.address() + 4 - else: - # Long/external. - (dummy, size, data) = value.split('ppp') + (size, data) = qdump__std____1__string__alternateLayoutHelper(d, value) + if size is None or data is None: + firstByte = value.split('b')[0] + if int(firstByte & 1) == 0: + # Short/internal. + size = int(firstByte / 2) + data = value.address() + 4 + else: + # Long/external. + (_, size, data) = value.split('ppp') + d.putCharArrayHelper(data, size, d.createType('wchar_t')) d.putType("std::wstring")