Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,28 @@ static void RegisterStdStringSummaryProvider(
summary_sp);
}

static void RegisterStdStringViewSummaryProvider(
const lldb::TypeCategoryImplSP &category_sp, llvm::StringRef string_ty,
llvm::StringRef char_ty, lldb::TypeSummaryImplSP summary_sp) {
// std::string_view
category_sp->AddTypeSummary(
std::make_shared<lldb_private::TypeNameSpecifierImpl>(
string_ty, eFormatterMatchExact),
summary_sp);

// std::basic_string_view<char, std::char_traits<char>>
// NativePDB has spaces at different positions compared to PDB and DWARF, so
// use a regex and make them optional.
category_sp->AddTypeSummary(
std::make_shared<lldb_private::TypeNameSpecifierImpl>(
llvm::formatv(
"^std::basic_string_view<{0}, ?std::char_traits<{0}> ?>$",
char_ty)
.str(),
eFormatterMatchRegex),
summary_sp);
}

static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
if (!cpp_category_sp)
return;
Expand Down Expand Up @@ -1863,6 +1885,36 @@ static void LoadMsvcStlFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
MsvcStlStringSummaryProvider<StringElementType::UTF32>,
"MSVC STL std::u32string summary provider"));

RegisterStdStringViewSummaryProvider(
cpp_category_sp, "std::string_view", "char",
std::make_shared<CXXFunctionSummaryFormat>(
stl_summary_flags,
MsvcStlStringViewSummaryProvider<StringElementType::ASCII>,
"MSVC STL std::string_view summary provider"));
RegisterStdStringViewSummaryProvider(
cpp_category_sp, "std::u8string_view", "char8_t",
std::make_shared<CXXFunctionSummaryFormat>(
stl_summary_flags,
MsvcStlStringViewSummaryProvider<StringElementType::UTF8>,
"MSVC STL std::u8string_view summary provider"));
RegisterStdStringViewSummaryProvider(
cpp_category_sp, "std::u16string_view", "char16_t",
std::make_shared<CXXFunctionSummaryFormat>(
stl_summary_flags,
MsvcStlStringViewSummaryProvider<StringElementType::UTF16>,
"MSVC STL std::u16string_view summary provider"));
RegisterStdStringViewSummaryProvider(
cpp_category_sp, "std::u32string_view", "char32_t",
std::make_shared<CXXFunctionSummaryFormat>(
stl_summary_flags,
MsvcStlStringViewSummaryProvider<StringElementType::UTF32>,
"MSVC STL std::u32string_view summary provider"));
RegisterStdStringViewSummaryProvider(
cpp_category_sp, "std::wstring_view", "wchar_t",
std::make_shared<CXXFunctionSummaryFormat>(
stl_summary_flags, MsvcStlWStringViewSummaryProvider,
"MSVC STL std::wstring_view summary provider"));

stl_summary_flags.SetDontShowChildren(false);

AddCXXSynthetic(cpp_category_sp, MsvcStlAtomicSyntheticFrontEndCreator,
Expand Down
63 changes: 63 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/MsvcStl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,33 @@ static bool formatStringImpl(ValueObject &valobj, Stream &stream,
return true;
}

template <StringPrinter::StringElementType element_type>
static bool formatStringViewImpl(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options,
std::string prefix_token) {
auto data_sp = valobj.GetChildMemberWithName("_Mydata");
auto size_sp = valobj.GetChildMemberWithName("_Mysize");
if (!data_sp || !size_sp)
return false;

bool success = false;
uint64_t size = size_sp->GetValueAsUnsigned(0, &success);
if (!success) {
stream << "Summary Unavailable";
return true;
}

StreamString scratch_stream;
success = StringBufferSummaryProvider<element_type>(
scratch_stream, summary_options, data_sp, size, prefix_token);

if (success)
stream << scratch_stream.GetData();
else
stream << "Summary Unavailable";
return true;
}

bool lldb_private::formatters::IsMsvcStlStringType(ValueObject &valobj) {
std::vector<uint32_t> indexes;
return valobj.GetCompilerType().GetIndexOfChildMemberWithName("_Mypair", true,
Expand Down Expand Up @@ -153,3 +180,39 @@ bool lldb_private::formatters::MsvcStlStringSummaryProvider<
return MsvcStlStringSummaryProviderImpl<StringElementType::UTF32>(
valobj, stream, summary_options, "U");
}

bool lldb_private::formatters::MsvcStlWStringViewSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options) {
return formatStringViewImpl<StringElementType::UTF16>(valobj, stream,
summary_options, "L");
}

template <>
bool lldb_private::formatters::MsvcStlStringViewSummaryProvider<
StringElementType::ASCII>(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options) {
return formatStringViewImpl<StringElementType::ASCII>(valobj, stream,
summary_options, "");
}
template <>
bool lldb_private::formatters::MsvcStlStringViewSummaryProvider<
StringElementType::UTF8>(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options) {
return formatStringViewImpl<StringElementType::UTF8>(valobj, stream,
summary_options, "u8");
}
template <>
bool lldb_private::formatters::MsvcStlStringViewSummaryProvider<
StringElementType::UTF16>(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options) {
return formatStringViewImpl<StringElementType::UTF16>(valobj, stream,
summary_options, "u");
}
template <>
bool lldb_private::formatters::MsvcStlStringViewSummaryProvider<
StringElementType::UTF32>(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options) {
return formatStringViewImpl<StringElementType::UTF32>(valobj, stream,
summary_options, "U");
}
9 changes: 9 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/MsvcStl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ bool MsvcStlWStringSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // VC 2015+ std::wstring

template <StringPrinter::StringElementType element_type>
bool MsvcStlStringViewSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &summary_options); // std::{u8,u16,u32}?string_view

bool MsvcStlWStringViewSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // std::wstring_view

// MSVC STL std::shared_ptr<> and std::weak_ptr<>
bool IsMsvcStlSmartPointer(ValueObject &valobj);
bool MsvcStlSmartPointerSummaryProvider(ValueObject &valobj, Stream &stream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ def cleanup():
"u32_string", type="std::u32string_view", summary='U"🍄🍅🍆🍌"'
)
self.expect_var_path("u32_empty", type="std::u32string_view", summary='U""')
self.expect_var_path(
"oops", type="std::string_view", summary='"Hellooo World\\n"'
)

# GetSummary returns None so can't be checked by expect_var_path, so we
# use the str representation instead
Expand Down Expand Up @@ -163,3 +160,8 @@ def cleanup():
def test_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test()

@add_test_categories(["msvcstl"])
def test_msvcstl(self):
self.build()
self.do_test()
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ int main() {
std::string_view *null_str = nullptr;

std::string hello = "Hellooo ";
std::string_view oops = hello + "World\n";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tested implementation detail. For me, oops was "\0ellooo World\n", so I removed this.


q_source[0] = 'H'; // Set break point at this line.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -std=c++20

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# coding=utf8
"""
Test std::u8string_view summary.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class StdU8StringViewDataFormatterTestCase(TestBase):
def do_test(self):
lldbutil.run_to_source_breakpoint(
self, "Set break point at this line.", lldb.SBFileSpec("main.cpp")
)

self.expect(
"frame variable",
substrs=[
'(std::u8string_view) u8_string_small = u8"🍄"',
'(std::u8string_view) u8_string = u8"❤️👍📄📁😃🧑‍🌾"',
'(std::u8string_view) u8_empty = u8""',
'(std::u8string_view) u8_text = u8"ABCd"',
],
)

@expectedFailureAll(bugnumber="No libc++ formatters for std::u8string_view yet.")
@add_test_categories(["libc++"])
def test_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test()

@expectedFailureAll(bugnumber="No libstdc++ formatters for std::u8string_view yet.")
@add_test_categories(["libstdcxx"])
def test_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test()

@add_test_categories(["msvcstl"])
def test_msvc(self):
self.build()
self.do_test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cstdio>
#include <string_view>

int main() {
std::u8string_view u8_string_small(u8"🍄");
std::u8string_view u8_string(u8"❤️👍📄📁😃🧑‍🌾");
std::u8string_view u8_empty(u8"");
std::u8string_view u8_text(u8"ABC");
u8_text = u8"ABCd";

std::puts("// Set break point at this line.");
}
Loading