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
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
CXX_SOURCES := main.cpp

USE_LIBCPP := 1

CXXFLAGS_EXTRAS := -std=c++17

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Test lldb data formatter for LibStdC++ std::variant.
Test lldb data formatter subsystem.
"""

import lldb
Expand All @@ -8,18 +8,23 @@
from lldbsuite.test import lldbutil


class LibStdcxxVariantDataFormatterTestCase(TestBase):
@add_test_categories(["libstdcxx"])
def test_with_run_command(self):
"""Test LibStdC++ std::variant data formatter works correctly."""
self.build()
class StdVariantDataFormatterTestCase(TestBase):
def do_test(self):
"""Test that that file and class static variables display correctly."""

def cleanup():
self.runCmd("type format clear", check=False)
self.runCmd("type summary clear", check=False)
self.runCmd("type filter clear", check=False)
self.runCmd("type synth clear", check=False)

# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)

(self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp", False)
)

lldbutil.continue_to_breakpoint(self.process, bkpt)

for name in ["v1", "v1_typedef"]:
self.expect(
"frame variable " + name,
Expand Down Expand Up @@ -65,32 +70,16 @@ def test_with_run_command(self):
self.expect("frame variable v_valueless", substrs=["v_valueless = No Value"])

self.expect(
"frame variable v_many_types_valueless",
substrs=["v_many_types_valueless = No Value"],
)

@add_test_categories(["libstdcxx"])
def test_invalid_variant_index(self):
"""Test LibStdC++ data formatter for std::variant with invalid index."""
self.build()

(self.target, self.process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp", False)
)

lldbutil.continue_to_breakpoint(self.process, bkpt)

self.expect(
"frame variable v1",
substrs=["v1 = Active Type = int {", "Value = 12", "}"],
"frame variable v_300_types_valueless",
substrs=["v_300_types_valueless = No Value"],
)

var_v1 = thread.frames[0].FindVariable("v1")
var_v1_raw_obj = var_v1.GetNonSyntheticValue()
index_obj = var_v1_raw_obj.GetChildMemberWithName("_M_index")
self.assertTrue(index_obj and index_obj.IsValid())
@add_test_categories(["libc++"])
def test_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test()

INVALID_INDEX = "100"
index_obj.SetValueFromCString(INVALID_INDEX)

self.expect("frame variable v1", substrs=["v1 = <Invalid>"])
@add_test_categories(["libstdcxx"])
def test_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test()
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ struct S {
};

int main() {
bool has_variant = true;

printf("%d\n", has_variant); // break here

std::variant<int, double, char> v1;
std::variant<int, double, char> &v1_ref = v1;

using V1_typedef = std::variant<int, double, char>;
V1_typedef v1_typedef;
V1_typedef &v1_typedef_ref = v1_typedef;
Expand All @@ -24,7 +21,7 @@ int main() {
std::variant<int, double, char> v3;
std::variant<std::variant<int, double, char>> v_v1;
std::variant<int, char, S> v_valueless = 5;
// The next variant has many types, meaning the type index does not fit in
// The next variant has 300 types, meaning the type index does not fit in
// a byte and must be `unsigned short` instead of `unsigned char` when
// using the unstable libc++ ABI. With stable libc++ ABI, the type index
// is always just `unsigned int`.
Expand All @@ -45,11 +42,15 @@ int main() {
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, S>
v_many_types_valueless;
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
S>
v_300_types_valueless;

v_valueless = 5;
v_many_types_valueless.emplace<0>(10);
v_300_types_valueless.emplace<0>(10);

v1 = 12; // v contains int
v1_typedef = v1;
Expand Down Expand Up @@ -83,11 +84,11 @@ int main() {
try {
// Exception in move-assignment is guaranteed to put std::variant into a
// valueless state.
v_many_types_valueless = S();
v_300_types_valueless = S();
} catch (...) {
}

printf("%d\n", v_many_types_valueless.valueless_by_exception());
printf("%d\n", v_300_types_valueless.valueless_by_exception());

return 0; // break here
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CXX_SOURCES := main.cpp

USE_LIBSTDCPP := 1
CXXFLAGS_EXTRAS := -std=c++17
USE_LIBSTDCPP := 1

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class InvalidStdVariantDataFormatterTestCase(TestBase):
@add_test_categories(["libstdcxx"])
def test(self):
"""Test STL data formatters for std::variant with invalid index."""
self.build()

(_, _, thread, _) = lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp", False)
)

self.expect(
"frame variable v1",
substrs=["v1 = Active Type = char {", "Value = 'x'", "}"],
)

var_v1 = thread.frames[0].FindVariable("v1")
var_v1_raw_obj = var_v1.GetNonSyntheticValue()
index_obj = var_v1_raw_obj.GetChildMemberWithName("_M_index")
self.assertTrue(index_obj and index_obj.IsValid())

INVALID_INDEX = "100"
index_obj.SetValueFromCString(INVALID_INDEX)

self.expect("frame variable v1", substrs=["v1 = <Invalid>"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <cstdio>
#include <variant>

int main() {
std::variant<int, double, char> v1;
v1 = 'x';

std::puts("// break here");

return 0;
}
Loading