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
32 changes: 0 additions & 32 deletions lldb/examples/synthetic/gnu_libstdcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,38 +882,6 @@ def update(self):
return False


def VariantSummaryProvider(valobj, dict):
raw_obj = valobj.GetNonSyntheticValue()
index_obj = raw_obj.GetChildMemberWithName("_M_index")
data_obj = raw_obj.GetChildMemberWithName("_M_u")
if not (index_obj and index_obj.IsValid() and data_obj and data_obj.IsValid()):
return "<Can't find _M_index or _M_u>"

def get_variant_npos_value(index_byte_size):
if index_byte_size == 1:
return 0xFF
elif index_byte_size == 2:
return 0xFFFF
else:
return 0xFFFFFFFF

npos_value = get_variant_npos_value(index_obj.GetByteSize())
index = index_obj.GetValueAsUnsigned(0)
if index == npos_value:
return " No Value"

# Strip references and typedefs.
variant_type = raw_obj.GetType().GetCanonicalType().GetDereferencedType()
template_arg_count = variant_type.GetNumberOfTemplateArguments()

# Invalid index can happen when the variant is not initialized yet.
if index >= template_arg_count:
return " <Invalid>"

active_type = variant_type.GetTemplateArgumentType(index)
return f" Active Type = {active_type.GetDisplayTypeName()} "


class VariantSynthProvider:
def __init__(self, valobj, dict):
self.raw_obj = valobj.GetNonSyntheticValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1513,11 +1513,9 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
TypeSummaryImplSP(new ScriptSummaryFormat(
stl_summary_flags,
"lldb.formatters.cpp.gnu_libstdcpp.ForwardListSummaryProvider")));
cpp_category_sp->AddTypeSummary(
"^std::variant<.+>$", eFormatterMatchRegex,
TypeSummaryImplSP(new ScriptSummaryFormat(
stl_summary_flags,
"lldb.formatters.cpp.gnu_libstdcpp.VariantSummaryProvider")));
AddCXXSummary(cpp_category_sp, LibStdcppVariantSummaryProvider,
"libstdc++ std::variant summary provider", "^std::variant<.+>$",
stl_summary_flags, true);

AddCXXSynthetic(
cpp_category_sp,
Expand Down
46 changes: 46 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,49 @@ bool lldb_private::formatters::LibStdcppSmartPointerSummaryProvider(

return true;
}

static uint64_t LibStdcppVariantNposValue(size_t index_byte_size) {
switch (index_byte_size) {
case 1:
return 0xff;
case 2:
return 0xffff;
default:
return 0xffff'ffff;
}
}

bool formatters::LibStdcppVariantSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
ValueObjectSP valobj_sp = valobj.GetNonSyntheticValue();
if (!valobj_sp)
return false;

ValueObjectSP index_obj = valobj_sp->GetChildMemberWithName("_M_index");
ValueObjectSP data_obj = valobj_sp->GetChildMemberWithName("_M_u");
if (!index_obj || !data_obj)
return false;

auto index_bytes = index_obj->GetByteSize();
if (!index_bytes)
return false;
auto npos_value = LibStdcppVariantNposValue(*index_bytes);
auto index = index_obj->GetValueAsUnsigned(0);
if (index == npos_value) {
stream.Printf(" No Value");
return true;
}

auto variant_type =
valobj_sp->GetCompilerType().GetCanonicalType().GetNonReferenceType();
if (!variant_type)
return false;
if (index >= variant_type.GetNumTemplateArguments(true)) {
stream.Printf(" <Invalid>");
return true;
}

auto active_type = variant_type.GetTypeTemplateArgument(index, true);
stream << " Active Type = " << active_type.GetDisplayTypeName() << " ";
return true;
}
4 changes: 4 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ bool LibStdcppUniquePointerSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libstdc++ std::unique_ptr<>

bool LibStdcppVariantSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libstdc++ std::variant<>

SyntheticChildrenFrontEnd *
LibstdcppMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
Expand Down
Loading