Skip to content

[lldb] optionally match the __debug namespace for libstdc++ containers. #140727

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 8 commits into from
May 27, 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
68 changes: 39 additions & 29 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class NodeAllocator {
public:
void reset() { Alloc.Reset(); }

template <typename T, typename... Args> T *makeNode(Args &&... args) {
template <typename T, typename... Args> T *makeNode(Args &&...args) {
return new (Alloc.Allocate(sizeof(T), alignof(T)))
T(std::forward<Args>(args)...);
}
Expand All @@ -614,7 +614,7 @@ class ManglingSubstitutor
ManglingSubstitutor() : Base(nullptr, nullptr) {}

template <typename... Ts>
ConstString substitute(llvm::StringRef Mangled, Ts &&... Vals) {
ConstString substitute(llvm::StringRef Mangled, Ts &&...Vals) {
this->getDerived().reset(Mangled, std::forward<Ts>(Vals)...);
return substituteImpl(Mangled);
}
Expand Down Expand Up @@ -1449,47 +1449,50 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
stl_deref_flags.SetFrontEndWantsDereference();

cpp_category_sp->AddTypeSynthetic(
"^std::vector<.+>(( )?&)?$", eFormatterMatchRegex,
"^std::(__debug::)?vector<.+>(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdVectorSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::map<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::(__debug::)?map<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::deque<.+>(( )?&)?$", eFormatterMatchRegex,
"^std::(__debug)?deque<.+>(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdDequeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::set<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::(__debug::)?set<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::multimap<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::(__debug::)?multimap<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::multiset<.+> >(( )?&)?$", eFormatterMatchRegex,
"^std::(__debug::)?multiset<.+> >(( )?&)?$", eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::unordered_(multi)?(map|set)<.+> >$", eFormatterMatchRegex,
"^std::(__debug::)?unordered_(multi)?(map|set)<.+> >$",
eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdUnorderedMapSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::(__cxx11::)?list<.+>(( )?&)?$", eFormatterMatchRegex,
"^std::((__debug::)?|(__cxx11::)?)list<.+>(( )?&)?$",
eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_deref_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider")));
cpp_category_sp->AddTypeSynthetic(
"^std::(__cxx11::)?forward_list<.+>(( )?&)?$", eFormatterMatchRegex,
"^std::((__debug::)?|(__cxx11::)?)forward_list<.+>(( )?&)?$",
eFormatterMatchRegex,
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdForwardListSynthProvider")));
Expand All @@ -1501,44 +1504,47 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {

stl_summary_flags.SetDontShowChildren(false);
stl_summary_flags.SetSkipPointers(false);
cpp_category_sp->AddTypeSummary("^std::bitset<.+>(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::vector<.+>(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::map<.+> >(( )?&)?$",
cpp_category_sp->AddTypeSummary("^std::(__debug::)?bitset<.+>(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::set<.+> >(( )?&)?$",
cpp_category_sp->AddTypeSummary("^std::(__debug::)?vector<.+>(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::deque<.+>(( )?&)?$",
cpp_category_sp->AddTypeSummary("^std::(__debug::)?map<.+> >(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::multimap<.+> >(( )?&)?$",
cpp_category_sp->AddTypeSummary("^std::(__debug::)?set<.+> >(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::multiset<.+> >(( )?&)?$",
cpp_category_sp->AddTypeSummary("^std::(__debug::)?deque<.+>(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::unordered_(multi)?(map|set)<.+> >$",
cpp_category_sp->AddTypeSummary("^std::(__debug::)?multimap<.+> >(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary("^std::(__cxx11::)?list<.+>(( )?&)?$",
cpp_category_sp->AddTypeSummary("^std::(__debug::)?multiset<.+> >(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary(
"^std::(__cxx11::)?forward_list<.+>(( )?&)?$", eFormatterMatchRegex,
"^std::(__debug::)?unordered_(multi)?(map|set)<.+> >$",
eFormatterMatchRegex,
TypeSummaryImplSP(
new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary(
"^std::((__debug::)?|(__cxx11::)?)list<.+>(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(
new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->AddTypeSummary(
"^std::((__debug::)?|(__cxx11::)?)forward_list<.+>(( )?&)?$",
eFormatterMatchRegex,
TypeSummaryImplSP(new ScriptSummaryFormat(
stl_summary_flags,
"lldb.formatters.cpp.gnu_libstdcpp.ForwardListSummaryProvider")));
Expand Down Expand Up @@ -1592,7 +1598,7 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
AddCXXSynthetic(
cpp_category_sp,
lldb_private::formatters::LibStdcppBitsetSyntheticFrontEndCreator,
"std::bitset synthetic child", "^std::bitset<.+>(( )?&)?$",
"std::bitset synthetic child", "^std::(__debug::)?bitset<.+>(( )?&)?$",
stl_deref_flags, true);

AddCXXSynthetic(
Expand Down Expand Up @@ -1731,8 +1737,12 @@ lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() {
DataVisualization::Categories::GetCategory(ConstString(GetPluginName()),
g_category);
if (g_category) {
LoadLibStdcppFormatters(g_category);
// NOTE: the libstdcpp formatters are loaded after libcxx formatters
// because we don't want to the libcxx formatters to match the potential
// `__debug` inline namespace that libstdcpp may use.
// LLDB prioritizes the last loaded matching formatter.
LoadLibCxxFormatters(g_category);
LoadLibStdcppFormatters(g_category);
LoadSystemFormatters(g_category);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,7 @@ def cleanup():

# and also validate that one can print formatters for a language
self.expect(
"type summary list -l c++", substrs=["vector", "map", "list", "string"]
"type summary list -l c++",
substrs=["vector", "map", "list", "string"],
ordered=False,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test lldb data formatter subsystem.
"""


from typing import Optional
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand All @@ -19,8 +19,17 @@ def setUp(self):
@add_test_categories(["libstdcxx"])
@expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc")
def test_with_run_command(self):
self.with_run_command()

@add_test_categories(["libstdcxx"])
@expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc")
def test_with_run_command_debug(self):
build_args = {"CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"}
self.with_run_command("__debug::", build_args)

def with_run_command(self, namespace: str = "", dictionary: Optional[dict] = None):
"""Test that that file and class static variables display correctly."""
self.build()
self.build(dictionary=dictionary)
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

lldbutil.run_break_set_by_source_regexp(self, "Set break point at this line.")
Expand Down Expand Up @@ -48,7 +57,7 @@ def cleanup():
self.runCmd("frame variable ii --show-types")

self.runCmd(
'type summary add -x "std::map<" --summary-string "map has ${svar%#} items" -e'
f'type summary add -x "std::{namespace}map<" --summary-string "map has ${{svar%#}} items" -e'
)

self.expect("frame variable ii", substrs=["map has 0 items", "{}"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""


from typing import Optional
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand All @@ -16,10 +17,19 @@ def setUp(self):
# Find the line number to break at.
self.line = line_number("main.cpp", "// Set break point at this line.")

@skip
@add_test_categories(["libstdcxx"])
def test_with_run_command(self):
self.with_run_command()

@add_test_categories(["libstdcxx"])
def test_with_run_command_debug(self):
build_args = {"CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"}
self.with_run_command(build_args)

def with_run_command(self, dictionary: Optional[dict] = None):
"""Test that that file and class static variables display correctly."""
self.build()
self.build(dictionary=dictionary)
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

lldbutil.run_break_set_by_file_and_line(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""


from typing import Optional
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand All @@ -19,8 +20,17 @@ def setUp(self):
@add_test_categories(["libstdcxx"])
@expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc")
def test_with_run_command(self):
self.with_run_command()

@add_test_categories(["libstdcxx"])
@expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc")
def test_with_run_command_debug(self):
build_args = {"CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"}
self.with_run_command(build_args)

def with_run_command(self, dictionary: Optional[dict] = None):
"""Test that that file and class static variables display correctly."""
self.build()
self.build(dictionary=dictionary)
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

lldbutil.run_break_set_by_source_regexp(self, "Set break point at this line.")
Expand Down
Loading