Skip to content

Commit 5ce9a86

Browse files
authored
[lldb] Make variant formatter work with libstdc++-14 (#97568)
In this version the internal data member has grown an additional template parameter (bool), which was throwing the summary provider off. This patch uses the type of the entire variant object. This is part of the API/ABI, so it should be more stable, but it means we have to explicitly strip typedefs and references to get to the interesting bits, which is why I've extended the test case with examples of those.
1 parent f50f7a7 commit 5ce9a86

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

lldb/examples/synthetic/gnu_libstdcpp.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,15 @@ def get_variant_npos_value(index_byte_size):
914914
if index == npos_value:
915915
return " No Value"
916916

917+
# Strip references and typedefs.
918+
variant_type = raw_obj.GetType().GetCanonicalType().GetDereferencedType()
919+
template_arg_count = variant_type.GetNumberOfTemplateArguments()
920+
917921
# Invalid index can happen when the variant is not initialized yet.
918-
template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
919922
if index >= template_arg_count:
920923
return " <Invalid>"
921924

922-
active_type = data_obj.GetType().GetTemplateArgumentType(index)
925+
active_type = variant_type.GetTemplateArgumentType(index)
923926
return f" Active Type = {active_type.GetDisplayTypeName()} "
924927

925928

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ def test_with_run_command(self):
2121

2222
lldbutil.continue_to_breakpoint(self.process, bkpt)
2323

24-
self.expect(
25-
"frame variable v1",
26-
substrs=["v1 = Active Type = int {", "Value = 12", "}"],
27-
)
28-
29-
self.expect(
30-
"frame variable v1_ref",
31-
substrs=["v1_ref = Active Type = int : {", "Value = 12", "}"],
32-
)
24+
for name in ["v1", "v1_typedef"]:
25+
self.expect(
26+
"frame variable " + name,
27+
substrs=[name + " = Active Type = int {", "Value = 12", "}"],
28+
)
29+
30+
for name in ["v1_ref", "v1_typedef_ref"]:
31+
self.expect(
32+
"frame variable " + name,
33+
substrs=[name + " = Active Type = int : {", "Value = 12", "}"],
34+
)
3335

3436
self.expect(
3537
"frame variable v_v1",

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ int main() {
1414

1515
std::variant<int, double, char> v1;
1616
std::variant<int, double, char> &v1_ref = v1;
17+
using V1_typedef = std::variant<int, double, char>;
18+
V1_typedef v1_typedef;
19+
V1_typedef &v1_typedef_ref = v1_typedef;
20+
1721
std::variant<int, double, char> v2;
1822
std::variant<int, double, char> v3;
1923
std::variant<std::variant<int, double, char>> v_v1;
@@ -43,6 +47,7 @@ int main() {
4347
v_many_types_no_value;
4448

4549
v1 = 12; // v contains int
50+
v1_typedef = v1;
4651
v_v1 = v1;
4752
int i = std::get<int>(v1);
4853
printf("%d\n", i); // break here

0 commit comments

Comments
 (0)