[Lldb-commits] [lldb] r248555 - Fix evaluation of unicode character arrays (char16_t[] and char32_t[])
Dawn Perchik via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 24 19:16:53 PDT 2015
Author: dperchik
Date: Thu Sep 24 21:16:52 2015
New Revision: 248555
URL: http://llvm.org/viewvc/llvm-project?rev=248555&view=rev
Log:
Fix evaluation of unicode character arrays (char16_t[] and char32_t[])
Suppose we have the UTF-16 string:
char16_t[] s = u"hello";
Before this patch, evaluating the string in lldb would get:
(char16_t [6]) $0 = ([0] = U+0068 u'h', [1] = U+0065 u'e', [2] = U+006c u'l', [3] = U+006c u'l', [4] = U+006f u'o', [5] = U+0000 u'\0')
After applying the patch, we now get:
(char16_t [6]) $0 = u"hello"
Patch from evgeny.leviant at gmail.com
Reviewed by: granata.enrico
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D13053
Modified:
lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
lldb/trunk/test/lang/cpp/char1632_t/TestChar1632T.py
lldb/trunk/test/lang/cpp/char1632_t/main.cpp
Modified: lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h?rev=248555&r1=248554&r2=248555&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h Thu Sep 24 21:16:52 2015
@@ -106,6 +106,9 @@ namespace lldb_private {
size_t
ExtractIndexFromString (const char* item_name);
+ lldb::addr_t
+ GetArrayAddressOrPointerValue (ValueObject& valobj);
+
time_t
GetOSXEpoch ();
} // namespace formatters
Modified: lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormattersHelpers.cpp?rev=248555&r1=248554&r2=248555&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormattersHelpers.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormattersHelpers.cpp Thu Sep 24 21:16:52 2015
@@ -306,3 +306,16 @@ lldb_private::formatters::ExtractIndexFr
return UINT32_MAX;
return idx;
}
+
+lldb::addr_t
+lldb_private::formatters::GetArrayAddressOrPointerValue (ValueObject& valobj)
+{
+ lldb::addr_t data_addr = LLDB_INVALID_ADDRESS;
+
+ if (valobj.IsPointerType())
+ data_addr = valobj.GetValueAsUnsigned(0);
+ else if (valobj.IsArrayType())
+ data_addr = valobj.GetAddressOf();
+
+ return data_addr;
+}
Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp?rev=248555&r1=248554&r2=248555&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp (original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp Thu Sep 24 21:16:52 2015
@@ -628,8 +628,20 @@ LoadSystemFormatters(lldb::TypeCategoryI
#ifndef LLDB_DISABLE_PYTHON
// FIXME because of a bug in the FormattersContainer we need to add a summary for both X* and const X* (<rdar://problem/12717717>)
AddCXXSummary(cpp_category_sp, lldb_private::formatters::Char16StringSummaryProvider, "char16_t * summary provider", ConstString("char16_t *"), string_flags);
+ AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::Char16StringSummaryProvider,
+ "char16_t [] summary provider",
+ ConstString("char16_t \\[[0-9]+\\]"),
+ string_array_flags,
+ true);
AddCXXSummary(cpp_category_sp, lldb_private::formatters::Char32StringSummaryProvider, "char32_t * summary provider", ConstString("char32_t *"), string_flags);
+ AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::Char32StringSummaryProvider,
+ "char32_t [] summary provider",
+ ConstString("char32_t \\[[0-9]+\\]"),
+ string_array_flags,
+ true);
AddCXXSummary(cpp_category_sp, lldb_private::formatters::WCharStringSummaryProvider, "wchar_t * summary provider", ConstString("wchar_t *"), string_flags);
AddCXXSummary(cpp_category_sp, lldb_private::formatters::WCharStringSummaryProvider, "wchar_t * summary provider", ConstString("wchar_t \\[[0-9]+\\]"), string_array_flags, true);
Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp?rev=248555&r1=248554&r2=248555&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp (original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp Thu Sep 24 21:16:52 2015
@@ -24,6 +24,7 @@
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/ProcessStructReader.h"
+#include "lldb/DataFormatters/FormattersHelpers.h"
#include <algorithm>
@@ -44,9 +45,8 @@ lldb_private::formatters::Char16StringSu
if (!process_sp)
return false;
- lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
-
- if (!valobj_addr)
+ lldb::addr_t valobj_addr = GetArrayAddressOrPointerValue(valobj);
+ if (valobj_addr == 0 || valobj_addr == LLDB_INVALID_ADDRESS)
return false;
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
@@ -71,9 +71,8 @@ lldb_private::formatters::Char32StringSu
if (!process_sp)
return false;
- lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
-
- if (!valobj_addr)
+ lldb::addr_t valobj_addr = GetArrayAddressOrPointerValue(valobj);
+ if (valobj_addr == 0 || valobj_addr == LLDB_INVALID_ADDRESS)
return false;
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
@@ -98,14 +97,8 @@ lldb_private::formatters::WCharStringSum
if (!process_sp)
return false;
- lldb::addr_t data_addr = 0;
-
- if (valobj.IsPointerType())
- data_addr = valobj.GetValueAsUnsigned(0);
- else if (valobj.IsArrayType())
- data_addr = valobj.GetAddressOf();
-
- if (data_addr == 0 || data_addr == LLDB_INVALID_ADDRESS)
+ lldb::addr_t valobj_addr = GetArrayAddressOrPointerValue(valobj);
+ if (valobj_addr == 0 || valobj_addr == LLDB_INVALID_ADDRESS)
return false;
// Get a wchar_t basic type from the current type system
@@ -117,7 +110,7 @@ lldb_private::formatters::WCharStringSum
const uint32_t wchar_size = wchar_compiler_type.GetBitSize(nullptr); // Safe to pass NULL for exe_scope here
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
- options.SetLocation(data_addr);
+ options.SetLocation(valobj_addr);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
options.SetPrefixToken('L');
Modified: lldb/trunk/test/lang/cpp/char1632_t/TestChar1632T.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/char1632_t/TestChar1632T.py?rev=248555&r1=248554&r2=248555&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/char1632_t/TestChar1632T.py (original)
+++ lldb/trunk/test/lang/cpp/char1632_t/TestChar1632T.py Thu Sep 24 21:16:52 2015
@@ -64,6 +64,11 @@ class Char1632TestCase(TestBase):
self.expect("frame variable s16 s32",
substrs = ['(char16_t *) s16 = ','(char32_t *) s32 = ','u"ﺸﺵۻ"','U"ÐÐÐ ÐÐÐ"'])
+ # Check that we correctly report the array types
+ self.expect("frame variable as16 as32",
+ patterns = ['\(char16_t \[[0-9]+\]\) as16 = ', '\(char32_t \[[0-9]+\]\) as32 = '],
+ substrs = ['u"ﺸﺵۻ"','U"ÐÐÐ ÐÐÐ"'])
+
self.runCmd("next") # step to after the string is nullified
# check that we don't crash on NULL
@@ -77,6 +82,11 @@ class Char1632TestCase(TestBase):
self.expect("frame variable s16 s32",
substrs = ['(char16_t *) s16 = 0x','(char32_t *) s32 = ','"è²ãåããæ£ãªãã«ã²"','"à·´"'])
+ # check the same as above for arrays
+ self.expect("frame variable as16 as32",
+ patterns = ['\(char16_t \[[0-9]+\]\) as16 = ', '\(char32_t \[[0-9]+\]\) as32 = '],
+ substrs = ['"è²ãåããæ£ãªãã«ã²"','"à·´"'])
+
# check that zero values are properly handles
self.expect('frame variable cs16_zero', substrs=["U+0000 u'\\0'"])
self.expect('frame variable cs32_zero', substrs=["U+0x00000000 U'\\0'"])
Modified: lldb/trunk/test/lang/cpp/char1632_t/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/char1632_t/main.cpp?rev=248555&r1=248554&r2=248555&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/char1632_t/main.cpp (original)
+++ lldb/trunk/test/lang/cpp/char1632_t/main.cpp Thu Sep 24 21:16:52 2015
@@ -7,18 +7,38 @@
//
//===----------------------------------------------------------------------===//
+#include <assert.h>
+#include <string>
+
+#define UASZ 64
+
+template<class T, int N>
+void copy_char_seq (T (&arr)[N], const T* src)
+{
+ size_t src_len = std::char_traits<T>::length(src);
+ assert(src_len < N);
+
+ std::char_traits<T>::copy(arr, src, src_len);
+ arr[src_len] = 0;
+}
int main (int argc, char const *argv[])
{
- auto cs16_zero = (char16_t)0;
- auto cs32_zero = (char32_t)0;
+ char16_t as16[UASZ];
+ char32_t as32[UASZ];
+ auto cs16_zero = (char16_t)0;
+ auto cs32_zero = (char32_t)0;
auto cs16 = u"hello world à¾à¾à¾";
- auto cs32 = U"hello world à¾à¾à¾";
+ auto cs32 = U"hello world à¾à¾à¾";
char16_t *s16 = (char16_t *)u"ﺸﺵۻ";
char32_t *s32 = (char32_t *)U"ÐÐÐ ÐÐÐ";
+ copy_char_seq(as16, s16);
+ copy_char_seq(as32, s32);
s32 = nullptr; // breakpoint1
s32 = (char32_t *)U"à·´";
s16 = (char16_t *)u"è²ãåããæ£ãªãã«ã²";
+ copy_char_seq(as16, s16);
+ copy_char_seq(as32, s32);
s32 = nullptr; // breakpoint2
return 0;
}
More information about the lldb-commits
mailing list