aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
diff options
context:
space:
mode:
authorEbuka Ezike <yerimyah1@gmail.com>2025-05-27 20:52:51 +0100
committerGitHub <noreply@github.com>2025-05-27 20:52:51 +0100
commit04f9fac62238a4af2755e40b8020c64b3055c19a (patch)
tree73f36799173263f38566ac1896e606934960d0b1 /lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
parent782a9e9f64dfa21ca21f4b5c09569b35dd041bb0 (diff)
downloadllvm-04f9fac62238a4af2755e40b8020c64b3055c19a.zip
llvm-04f9fac62238a4af2755e40b8020c64b3055c19a.tar.gz
llvm-04f9fac62238a4af2755e40b8020c64b3055c19a.tar.bz2
[lldb] optionally match the `__debug` namespace for libstdc++ containers. (#140727)
If libstdc++ is compiled with `_GLIBCXX_DEBUG` flag it puts the containers in the namespace `std::__debug`. this causes the summary and synthetic formatters not to match the types. The formatters is updated to optionally match the `__debug::`. The formatters now clashed with the libc++ containers namespace regex which uses `std::__1` namespace The libc++ formatter is loaded first, then the libstdc++ since the priority of the formatters in lldb is the last one added. Fixes #60841
Diffstat (limited to 'lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp')
-rw-r--r--lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp68
1 files changed, 39 insertions, 29 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 542f13b..b178e06 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -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)...);
}
@@ -614,7 +614,7 @@ public:
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);
}
@@ -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")));
@@ -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")));
@@ -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(
@@ -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);
}
});