Skip to content

[lldb][test] Consolidate libstdc++ and libc++ vector formatter tests into generic test #146885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2025
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

CXXFLAGS := -O0
USE_LIBSTDCPP := 1

include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
Test lldb data formatter subsystem.
"""


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


class LibcxxVectorDataFormatterTestCase(TestBase):
class StdVectorDataFormatterTestCase(TestBase):
def check_numbers(self, var_name, show_ptr=False):
patterns = []
substrs = [
Expand Down Expand Up @@ -52,10 +51,8 @@ def check_numbers(self, var_name, show_ptr=False):
self.expect("frame variable " + var_name + "[2]", substrs=["123"])
self.expect("frame variable " + var_name + "[3]", substrs=["1234"])

@add_test_categories(["libc++"])
def test_with_run_command(self):
def do_test(self):
"""Test that that file and class static variables display correctly."""
self.build()
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.cpp", False)
)
Expand Down Expand Up @@ -170,10 +167,25 @@ def cleanup():

self.expect("frame variable strings", substrs=["vector has 0 items"])

@add_test_categories(["libstdcxx"])
def test_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test()

@add_test_categories(["libstdcxx"])
def test_libstdcxx_debug(self):
self.build(
dictionary={"USE_LIBSTDCPP": 1, "CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"}
)
self.do_test()

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

def do_test_ref_and_ptr(self):
"""Test that that file and class static variables display correctly."""
self.build()
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Stop here to check by ref", lldb.SBFileSpec("main.cpp", False)
)
Expand All @@ -186,3 +198,20 @@ def test_ref_and_ptr(self):
self.expect("frame variable ptr", substrs=["ptr =", " size=7"])

self.expect("expression ptr", substrs=["$", "size=7"])

@add_test_categories(["libstdcxx"])
def test_ref_and_ptr_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test_ref_and_ptr()

@add_test_categories(["libstdcxx"])
def test_ref_and_ptr_libstdcxx_debug(self):
self.build(
dictionary={"USE_LIBSTDCPP": 1, "CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"}
)
self.do_test_ref_and_ptr()

@add_test_categories(["libc++"])
def test_ref_and_ptr_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test_ref_and_ptr()
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <string>
#include <vector>
typedef std::vector<int> int_vect;
typedef std::vector<std::string> string_vect;

template <class T>
void by_ref_and_ptr(std::vector<T> &ref, std::vector<T> *ptr) {
// Stop here to check by ref
return;
}

int main() {
int_vect numbers;
numbers.push_back(1); // break here
numbers.push_back(12); // break here
numbers.push_back(123);
numbers.push_back(1234);
numbers.push_back(12345); // break here
numbers.push_back(123456);
numbers.push_back(1234567);
by_ref_and_ptr(numbers, &numbers);

printf("break here");
numbers.clear();

numbers.push_back(7); // break here

string_vect strings;
strings.push_back(std::string("goofy"));
strings.push_back(std::string("is"));
strings.push_back(std::string("smart"));
printf("break here");
strings.push_back(std::string("!!!"));

printf("break here");
strings.clear();

return 0; // break here
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading