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,3 @@
CXX_SOURCES := main.cpp

CFLAGS_EXTRAS := -O0
USE_LIBSTDCPP := 1

include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,16 @@
from lldbsuite.test import lldbutil


class LibcxxStringDataFormatterTestCase(TestBase):
class StdStringDataFormatterTestCase(TestBase):
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break at.
self.main_spec = lldb.SBFileSpec("main.cpp")
self.namespace = "std"

@add_test_categories(["libc++"])
@expectedFailureAll(
bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android"
)
# Inline namespace is randomly ignored as Clang due to broken lookup inside
# the std namespace.
@expectedFailureAll(debug_info="gmodules")
def test_with_run_command(self):
def do_test(self):
"""Test that that file and class static variables display correctly."""
self.build()

(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Set break point at this line.", self.main_spec
)
Expand All @@ -47,42 +38,13 @@ def cleanup():

ns = self.namespace

self.expect(
"frame variable",
substrs=[
'(%s::wstring) wempty = L""' % ns,
'(%s::wstring) s = L"hello world! מזל טוב!"' % ns,
'(%s::wstring) S = L"!!!!"' % ns,
"(const wchar_t *) mazeltov = 0x",
'L"מזל טוב"',
'(%s::string) empty = ""' % ns,
'(%s::string) q = "hello world"' % ns,
'(%s::string) Q = "quite a long std::strin with lots of info inside it"'
% ns,
'(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns,
'(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
% ns,
'(%s::u16string) u16_string = u"ß水氶"' % ns,
'(%s::u16string) u16_empty = u""' % ns,
'(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns,
'(%s::u32string) u32_empty = U""' % ns,
"(%s::string *) null_str = nullptr" % ns,
],
)
# Check 'S' pre-assignment.
self.expect("frame variable S", substrs=['(%s::wstring) S = L"!!!!"' % ns])

thread.StepOver()

TheVeryLongOne = frame.FindVariable("TheVeryLongOne")
summaryOptions = lldb.SBTypeSummaryOptions()
summaryOptions.SetCapping(lldb.eTypeSummaryUncapped)
uncappedSummaryStream = lldb.SBStream()
TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions)
uncappedSummary = uncappedSummaryStream.GetData()
self.assertGreater(
uncappedSummary.find("someText"),
0,
"uncappedSummary does not include the full string",
)
summaryOptions.SetCapping(lldb.eTypeSummaryCapped)
cappedSummaryStream = lldb.SBStream()
TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions)
Expand All @@ -108,31 +70,145 @@ def cleanup():
self.expect(
"frame variable",
substrs=[
'(%s::wstring) wempty = L""' % ns,
'(%s::wstring) s = L"hello world! מזל טוב!"' % ns,
'(%s::wstring) S = L"!!!!!"' % ns,
"(const wchar_t *) mazeltov = 0x",
'L"מזל טוב"',
'(%s::string) empty = ""' % ns,
'(%s::string) q = "hello world"' % ns,
'(%s::string) Q = "quite a long std::strin with lots of info inside it"'
% ns,
"(%s::string *) null_str = nullptr" % ns,
],
)

# Test references and pointers to std::string.
var_rq = frame.FindVariable("rq")
var_rQ = frame.FindVariable("rQ")
var_pq = frame.FindVariable("pq")
var_pQ = frame.FindVariable("pQ")

self.assertEqual(var_rq.GetSummary(), '"hello world"', "rq summary wrong")
self.assertEqual(
var_rQ.GetSummary(),
'"quite a long std::strin with lots of info inside it"',
"rQ summary wrong",
)
self.assertEqual(var_pq.GetSummary(), '"hello world"', "pq summary wrong")
self.assertEqual(
var_pQ.GetSummary(),
'"quite a long std::strin with lots of info inside it"',
"pQ summary wrong",
)

@expectedFailureAll(
bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android"
)
# Inline namespace is randomly ignored as Clang due to broken lookup inside
# the std namespace.
@expectedFailureAll(debug_info="gmodules")
@add_test_categories(["libc++"])
def test_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test()

@expectedFailureAll(
bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android"
)
# Inline namespace is randomly ignored as Clang due to broken lookup inside
# the std namespace.
@expectedFailureAll(debug_info="gmodules")
@add_test_categories(["libstdcxx"])
def test_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test()

def do_test_multibyte(self):
lldbutil.run_to_source_breakpoint(
self, "Set break point at this line.", self.main_spec
)

ns = self.namespace

self.expect(
"frame variable",
substrs=[
'(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns,
'(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
% ns,
'(%s::u16string) u16_string = u"ß水氶"' % ns,
'(%s::u16string) u16_empty = u""' % ns,
'(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns,
'(%s::u32string) u32_empty = U""' % ns,
"(%s::string *) null_str = nullptr" % ns,
],
)

# Finally, make sure that if the string is not readable, we give an error:
bkpt_2 = target.BreakpointCreateBySourceRegex(
"Break here to look at bad string", self.main_spec
@add_test_categories(["libc++"])
def test_multibyte_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test_multibyte()

@expectedFailureAll(
bugnumber="libstdc++ formatters don't support UTF-16/UTF-32 strings yet."
)
@add_test_categories(["libstdcxx"])
def test_multibyte_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test_multibyte()

def do_test_uncapped_summary(self):
(_, _, thread, _) = lldbutil.run_to_source_breakpoint(
self, "Set break point at this line.", self.main_spec
)

TheVeryLongOne = thread.frames[0].FindVariable("TheVeryLongOne")
summaryOptions = lldb.SBTypeSummaryOptions()
summaryOptions.SetCapping(lldb.eTypeSummaryUncapped)
uncappedSummaryStream = lldb.SBStream()
TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions)
uncappedSummary = uncappedSummaryStream.GetData()
self.assertGreater(
uncappedSummary.find("someText"),
0,
"uncappedSummary does not include the full string",
)
self.assertEqual(bkpt_2.GetNumLocations(), 1, "Got one location")
threads = lldbutil.continue_to_breakpoint(process, bkpt_2)
self.assertEqual(len(threads), 1, "Stopped at second breakpoint")
frame = threads[0].frames[0]
var = frame.FindVariable("in_str")
self.assertTrue(var.GetError().Success(), "Made variable")

@add_test_categories(["libc++"])
def test_uncapped_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test_uncapped_summary()

@expectedFailureAll(
bugnumber="libstdc++ std::string summary provider doesn't obey summary options."
)
@add_test_categories(["libstdcxx"])
def test_uncapped_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test_uncapped_summary()

def do_test_summary_unavailable(self):
"""
Make sure that if the string is not readable, we give an error.
"""
(_, _, thread, _) = lldbutil.run_to_source_breakpoint(
self, "Break here to look at bad string", self.main_spec
)

var = thread.frames[0].FindVariable("in_str")
self.assertTrue(var.GetError().Success(), "Found variable")
summary = var.GetSummary()
self.assertEqual(summary, "Summary Unavailable", "No summary for bad value")

@add_test_categories(["libc++"])
def test_unavailable_summary_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test_summary_unavailable()

@expectedFailureAll(
bugnumber="libstdc++ std::string summary provider doesn't output a user-friendly message for invalid strings."
)
@add_test_categories(["libstdcxx"])
def test_unavailable_summary_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test_summary_unavailable()
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include <stdint.h>
#include <string>

size_t touch_string(std::string &in_str) {
return in_str.size(); // Break here to look at bad string
}

int main() {
std::wstring wempty(L"");
std::wstring s(L"hello world! מזל טוב!");
std::wstring S(L"!!!!");
const wchar_t *mazeltov = L"מזל טוב";
std::string empty("");
std::string q("hello world");
std::string Q("quite a long std::strin with lots of info inside it");
std::string TheVeryLongOne(
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"9012345678901234567890123456789012345678901234567890someText123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012"
"345678901234567890123456789012345678901234567890123456789012345678901234"
"567890123456789012345678901234567890123456789012345678901234567890123456"
"789012345678901234567890123456789012345678901234567890123456789012345678"
"901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890");
std::string IHaveEmbeddedZeros("a\0b\0c\0d", 7);
std::wstring IHaveEmbeddedZerosToo(
L"hello world!\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監", 38);
std::u16string u16_string(u"ß水氶");
std::u16string u16_empty(u"");
std::u32string u32_string(U"🍄🍅🍆🍌");
std::u32string u32_empty(U"");
std::string *null_str = nullptr;
auto &rq = q;
auto &rQ = Q;
std::string *pq = &q;
std::string *pQ = &Q;

S.assign(L"!!!!!"); // Set break point at this line.
std::string *not_a_string = (std::string *)0x0;
touch_string(*not_a_string);
return 0;
}

This file was deleted.

Loading
Loading