From 2f60b923acb68d45b101313954b70779c13a19b8 Mon Sep 17 00:00:00 2001 From: vadim-xd Date: Fri, 12 Apr 2024 11:40:12 +0300 Subject: [PATCH] Fix std::string::data() xmethod dcca6898563b485eb7f46fdd5dd82cb011409735 --- ynd/gdb/14/pretty_printers/libcxx_xmethods.py | 2 +- ynd/gdb/14/pretty_printers/test/gdbtest/main.cpp | 1 + ynd/gdb/14/pretty_printers/test/test.py | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ynd/gdb/14/pretty_printers/libcxx_xmethods.py b/ynd/gdb/14/pretty_printers/libcxx_xmethods.py index 665aa7b..844b1b6 100644 --- a/ynd/gdb/14/pretty_printers/libcxx_xmethods.py +++ b/ynd/gdb/14/pretty_printers/libcxx_xmethods.py @@ -169,7 +169,7 @@ def __call__(self, obj): is_long = ss['__is_long_'] if is_long: sl = destructure_compressed_pair(obj['__r_'])[0]['__l'] - return sl['__data_'].address.cast(self.result_type) + return sl['__data_'].cast(self.result_type) else: return ss['__data_'].address.cast(self.result_type) diff --git a/ynd/gdb/14/pretty_printers/test/gdbtest/main.cpp b/ynd/gdb/14/pretty_printers/test/gdbtest/main.cpp index c8ba40e..555881c 100644 --- a/ynd/gdb/14/pretty_printers/test/gdbtest/main.cpp +++ b/ynd/gdb/14/pretty_printers/test/gdbtest/main.cpp @@ -45,6 +45,7 @@ std::pair test_pair = {1, 2}; std::array test_array = {{1, 2, 3, 4}}; std::string test_string = "Это тест."; +std::string test_long_string = "A very long string that will not use small string optimization..."; std::string test_nullbyte_string{"\x00тест"sv}; std::string test_binary_string{"\xff\x00\xff\x00"sv}; std::string_view test_string_view(test_string); diff --git a/ynd/gdb/14/pretty_printers/test/test.py b/ynd/gdb/14/pretty_printers/test/test.py index 45cb98f..9e2a657 100644 --- a/ynd/gdb/14/pretty_printers/test/test.py +++ b/ynd/gdb/14/pretty_printers/test/test.py @@ -66,6 +66,7 @@ def data(field): test_pair='pair = {first = 1, second = 2}', test_array='{__elems_ = {1, 2, 3, 4}}', test_string='"Это тест."', + test_long_string='"A very long string that will not use small string optimization..."', test_nullbyte_string='"\\000тест"', test_binary_string='"\\377\\000\\377\\000"', test_string_view='"Это тест."', @@ -134,9 +135,13 @@ def test_pretty_printers(test_name, test_output): test_array_elem=('test_array[2]', re.compile(r'= \(int &\) @0x[0-9a-f]+: 3')), test_array_data=('test_array.data()', re.compile(r'= \(int \*\) 0x[0-9a-f]+ ')), test_string_length=('test_string.length()', '= 16'), - test_string_elem=('test_string[15]', re.compile(r'= \(char &\) @0x[0-9a-f]+: 46 \'.\'')), + test_string_elem=('test_string[15]', re.compile(r'= \(char &\) @0x[0-9a-f]+: 46 \'\.\'')), test_string_data=('test_string.data()', re.compile(r'= 0x[0-9a-f]+ "Это тест\."')), test_string_c_str=('test_string.c_str()', re.compile(r'= 0x[0-9a-f]+ "Это тест\."')), + test_long_string_length=('test_long_string.length()', '= 65'), + test_long_string_elem=('test_long_string[33]', re.compile(r'= \(char &\) @0x[0-9a-f]+: 117 \'u\'')), + test_long_string_data=('test_long_string.data()', re.compile(r'= 0x[0-9a-f]+ "A very long string that will not use small string optimization\.\.\."')), + # c_str() shares implementation with data(), no need to re-test it for long strings. test_tstring_length=('test_tstring.length()', '= 16'), test_tstring_elem=('test_tstring[15]', re.compile(r'= \(char &\) @0x[0-9a-f]+: 46 \'.\'')), test_tstring_data=('test_tstring.data()', re.compile(r'= 0x[0-9a-f]+ "Это тест\."')),