[Lldb-commits] [lldb] r369582 - Add char8_t support (C++20)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 21 14:30:55 PDT 2019
Author: jdevlieghere
Date: Wed Aug 21 14:30:55 2019
New Revision: 369582
URL: http://llvm.org/viewvc/llvm-project?rev=369582&view=rev
Log:
Add char8_t support (C++20)
This patch adds support for the char8_t type introduced in C++20
char8_t. The original patch was submitted by James Blachly on the LLDB
mailing list [1]. I modified the patch a bit and added a test.
[1] http://lists.llvm.org/pipermail/lldb-dev/2019-August/015393.html
Differential revision: https://reviews.llvm.org/D66447
Added:
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/Makefile
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/TestCxxChar8_t.py
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/main.cpp
Modified:
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/source/Commands/CommandObjectMemory.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.h
lldb/trunk/source/Symbol/ClangASTContext.cpp
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=369582&r1=369581&r2=369582&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Wed Aug 21 14:30:55 2019
@@ -193,6 +193,7 @@ enum Format {
eFormatHexFloat, // ISO C99 hex float string
eFormatInstruction, // Disassemble an opcode
eFormatVoid, // Do not print this
+ eFormatUnicode8,
kNumFormats
};
@@ -592,7 +593,7 @@ enum CommandArgumentType {
};
// Symbol types
-// Symbol holds the SymbolType in a 6-bit field (m_type), so if you get over 63
+// Symbol holds the SymbolType in a 6-bit field (m_type), so if you get over 63
// entries you will have to resize that field.
enum SymbolType {
eSymbolTypeAny = 0,
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/Makefile?rev=369582&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/Makefile Wed Aug 21 14:30:55 2019
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+CFLAGS_EXTRAS := -std=c++2a -fchar8_t
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/TestCxxChar8_t.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/TestCxxChar8_t.py?rev=369582&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/TestCxxChar8_t.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/TestCxxChar8_t.py Wed Aug 21 14:30:55 2019
@@ -0,0 +1,40 @@
+# coding=utf8
+"""
+Test that C++ supports char8_t correctly.
+"""
+
+from __future__ import print_function
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class CxxChar8_tTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipIf(compiler="clang", compiler_version=['<', '7.0'])
+ def test(self):
+ """Test that C++ supports char8_t correctly."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # FIXME: We should be able to test this with target variable, but the
+ # data formatter output is broken.
+ lldbutil.run_break_set_by_symbol(self, 'main')
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.expect(
+ "frame variable a", substrs=["(char8_t) ::a = 0x61 u8'a'"])
+
+ self.expect(
+ "frame variable ab", substrs=['(const char8_t *) ::ab', 'u8"ä½ å¥½"'])
+
+ self.expect(
+ "frame variable abc", substrs=['(char8_t [9]) ::abc = u8"ä½ å¥½"'])
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/main.cpp?rev=369582&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/main.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/char8_t/main.cpp Wed Aug 21 14:30:55 2019
@@ -0,0 +1,7 @@
+#include <cstring>
+
+char8_t a = u8'a';
+const char8_t* ab = u8"ä½ å¥½";
+char8_t abc[9] = u8"ä½ å¥½";
+
+int main (int argc, char const *argv[]) { return 0; }
Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=369582&r1=369581&r2=369582&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Wed Aug 21 14:30:55 2019
@@ -163,6 +163,7 @@ public:
case eFormatOctal:
case eFormatDecimal:
case eFormatEnum:
+ case eFormatUnicode8:
case eFormatUnicode16:
case eFormatUnicode32:
case eFormatUnsigned:
@@ -1411,6 +1412,7 @@ protected:
case eFormatBytesWithASCII:
case eFormatComplex:
case eFormatEnum:
+ case eFormatUnicode8:
case eFormatUnicode16:
case eFormatUnicode32:
case eFormatVectorOfChar:
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=369582&r1=369581&r2=369582&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp (original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp Wed Aug 21 14:30:55 2019
@@ -854,6 +854,14 @@ static void LoadSystemFormatters(lldb::T
// 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::Char8StringSummaryProvider,
+ "char8_t * summary provider", ConstString("char8_t *"), string_flags);
+ AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::Char8StringSummaryProvider,
+ "char8_t [] summary provider",
+ ConstString("char8_t \\[[0-9]+\\]"), string_array_flags, true);
+
+ AddCXXSummary(
cpp_category_sp, lldb_private::formatters::Char16StringSummaryProvider,
"char16_t * summary provider", ConstString("char16_t *"), string_flags);
AddCXXSummary(cpp_category_sp,
@@ -890,6 +898,9 @@ static void LoadSystemFormatters(lldb::T
.SetHideItemNames(true)
.SetShowMembersOneLiner(false);
+ AddCXXSummary(cpp_category_sp, lldb_private::formatters::Char8SummaryProvider,
+ "char8_t summary provider", ConstString("char8_t"),
+ widechar_flags);
AddCXXSummary(
cpp_category_sp, lldb_private::formatters::Char16SummaryProvider,
"char16_t summary provider", ConstString("char16_t"), widechar_flags);
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=369582&r1=369581&r2=369582&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp (original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp Wed Aug 21 14:30:55 2019
@@ -32,6 +32,31 @@ using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
+bool lldb_private::formatters::Char8StringSummaryProvider(
+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
+ ProcessSP process_sp = valobj.GetProcessSP();
+ if (!process_sp)
+ return false;
+
+ lldb::addr_t valobj_addr = GetArrayAddressOrPointerValue(valobj);
+ if (valobj_addr == 0 || valobj_addr == LLDB_INVALID_ADDRESS)
+ return false;
+
+ StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
+ options.SetLocation(valobj_addr);
+ options.SetProcessSP(process_sp);
+ options.SetStream(&stream);
+ options.SetPrefixToken("u8");
+
+ if (!StringPrinter::ReadStringAndDumpToStream<
+ StringPrinter::StringElementType::UTF8>(options)) {
+ stream.Printf("Summary Unavailable");
+ return true;
+ }
+
+ return true;
+}
+
bool lldb_private::formatters::Char16StringSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
ProcessSP process_sp = valobj.GetProcessSP();
@@ -128,6 +153,32 @@ bool lldb_private::formatters::WCharStri
return true;
}
+bool lldb_private::formatters::Char8SummaryProvider(
+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
+ DataExtractor data;
+ Status error;
+ valobj.GetData(data, error);
+
+ if (error.Fail())
+ return false;
+
+ std::string value;
+ valobj.GetValueAsCString(lldb::eFormatUnicode8, value);
+ if (!value.empty())
+ stream.Printf("%s ", value.c_str());
+
+ StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
+ options.SetData(data);
+ options.SetStream(&stream);
+ options.SetPrefixToken("u8");
+ options.SetQuote('\'');
+ options.SetSourceSize(1);
+ options.SetBinaryZeroIsTerminator(false);
+
+ return StringPrinter::ReadBufferAndDumpToStream<
+ StringPrinter::StringElementType::UTF8>(options);
+}
+
bool lldb_private::formatters::Char16SummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
DataExtractor data;
Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.h?rev=369582&r1=369581&r2=369582&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.h (original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CxxStringTypes.h Wed Aug 21 14:30:55 2019
@@ -16,6 +16,9 @@
namespace lldb_private {
namespace formatters {
+bool Char8StringSummaryProvider(ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options); // char8_t*
+
bool Char16StringSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // char16_t* and unichar*
@@ -27,6 +30,9 @@ bool Char32StringSummaryProvider(
bool WCharStringSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // wchar_t*
+bool Char8SummaryProvider(ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options); // char8_t
+
bool Char16SummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // char16_t and unichar
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=369582&r1=369581&r2=369582&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Wed Aug 21 14:30:55 2019
@@ -1384,11 +1384,12 @@ CompilerType ClangASTContext::GetBuiltin
case DW_ATE_UTF:
if (type_name) {
- if (streq(type_name, "char16_t")) {
+ if (streq(type_name, "char16_t"))
return CompilerType(this, ast->Char16Ty.getAsOpaquePtr());
- } else if (streq(type_name, "char32_t")) {
+ else if (streq(type_name, "char32_t"))
return CompilerType(this, ast->Char32Ty.getAsOpaquePtr());
- }
+ else if (streq(type_name, "char8_t"))
+ return CompilerType(this, ast->Char8Ty.getAsOpaquePtr());
}
break;
}
More information about the lldb-commits
mailing list