Skip to content

Commit 993220a

Browse files
committed
[lldb] Remove CPlusPlusLanguage from Mangled
The only remaining plugin dependency in Mangled is CPlusPlusLanguage which it uses to extract information from C++ mangled names. The static function GetDemangledNameWithoutArguments is written specifically for C++, so it would make sense for this specific functionality to live in a C++-related plugin. In order to keep this functionality in Mangled without maintaining this dependency, I added `Language::GetDemangledFunctionNameWithoutArguments`. Differential Revision: https://reviews.llvm.org/D105215
1 parent c54d5c9 commit 993220a

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

lldb/include/lldb/Target/Language.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ class Language : public PluginInterface {
243243
FunctionNameRepresentation representation,
244244
Stream &s);
245245

246+
virtual ConstString
247+
GetDemangledFunctionNameWithoutArguments(Mangled mangled) const {
248+
if (ConstString demangled = mangled.GetDemangledName())
249+
return demangled;
250+
251+
return mangled.GetMangledName();
252+
}
253+
246254
virtual void GetExceptionResolverDescription(bool catch_on, bool throw_on,
247255
Stream &s);
248256

lldb/source/Core/Mangled.cpp

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
#include "lldb/Core/Mangled.h"
1010

1111
#include "lldb/Core/RichManglingContext.h"
12+
#include "lldb/Target/Language.h"
1213
#include "lldb/Utility/ConstString.h"
1314
#include "lldb/Utility/Log.h"
1415
#include "lldb/Utility/Logging.h"
1516
#include "lldb/Utility/RegularExpression.h"
1617
#include "lldb/Utility/Stream.h"
1718
#include "lldb/lldb-enumerations.h"
1819

19-
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
20-
2120
#include "llvm/ADT/StringRef.h"
2221
#include "llvm/Demangle/Demangle.h"
2322
#include "llvm/Support/Compiler.h"
@@ -34,35 +33,6 @@ static inline bool cstring_is_mangled(llvm::StringRef s) {
3433
return Mangled::GetManglingScheme(s) != Mangled::eManglingSchemeNone;
3534
}
3635

37-
static ConstString GetDemangledNameWithoutArguments(ConstString mangled,
38-
ConstString demangled) {
39-
const char *mangled_name_cstr = mangled.GetCString();
40-
41-
if (demangled && mangled_name_cstr && mangled_name_cstr[0]) {
42-
if (mangled_name_cstr[0] == '_' && mangled_name_cstr[1] == 'Z' &&
43-
(mangled_name_cstr[2] != 'T' && // avoid virtual table, VTT structure,
44-
// typeinfo structure, and typeinfo
45-
// mangled_name
46-
mangled_name_cstr[2] != 'G' && // avoid guard variables
47-
mangled_name_cstr[2] != 'Z')) // named local entities (if we eventually
48-
// handle eSymbolTypeData, we will want
49-
// this back)
50-
{
51-
CPlusPlusLanguage::MethodName cxx_method(demangled);
52-
if (!cxx_method.GetBasename().empty()) {
53-
std::string shortname;
54-
if (!cxx_method.GetContext().empty())
55-
shortname = cxx_method.GetContext().str() + "::";
56-
shortname += cxx_method.GetBasename().str();
57-
return ConstString(shortname);
58-
}
59-
}
60-
}
61-
if (demangled)
62-
return demangled;
63-
return mangled;
64-
}
65-
6636
#pragma mark Mangled
6737

6838
Mangled::ManglingScheme Mangled::GetManglingScheme(llvm::StringRef const name) {
@@ -344,14 +314,16 @@ ConstString Mangled::GetName(Mangled::NamePreference preference) const {
344314
if (preference == ePreferMangled && m_mangled)
345315
return m_mangled;
346316

317+
// Call the accessor to make sure we get a demangled name in case it hasn't
318+
// been demangled yet...
347319
ConstString demangled = GetDemangledName();
348320

349321
if (preference == ePreferDemangledWithoutArguments) {
350-
return GetDemangledNameWithoutArguments(m_mangled, demangled);
322+
if (Language *lang = Language::FindPlugin(GuessLanguage())) {
323+
return lang->GetDemangledFunctionNameWithoutArguments(*this);
324+
}
351325
}
352326
if (preference == ePreferDemangled) {
353-
// Call the accessor to make sure we get a demangled name in case it hasn't
354-
// been demangled yet...
355327
if (demangled)
356328
return demangled;
357329
return m_mangled;

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ bool CPlusPlusLanguage::SymbolNameFitsToLanguage(Mangled mangled) const {
6464
return mangled_name && CPlusPlusLanguage::IsCPPMangledName(mangled_name);
6565
}
6666

67+
ConstString CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(
68+
Mangled mangled) const {
69+
const char *mangled_name_cstr = mangled.GetMangledName().GetCString();
70+
ConstString demangled_name = mangled.GetDemangledName();
71+
if (demangled_name && mangled_name_cstr && mangled_name_cstr[0]) {
72+
if (mangled_name_cstr[0] == '_' && mangled_name_cstr[1] == 'Z' &&
73+
(mangled_name_cstr[2] != 'T' && // avoid virtual table, VTT structure,
74+
// typeinfo structure, and typeinfo
75+
// mangled_name
76+
mangled_name_cstr[2] != 'G' && // avoid guard variables
77+
mangled_name_cstr[2] != 'Z')) // named local entities (if we
78+
// eventually handle eSymbolTypeData,
79+
// we will want this back)
80+
{
81+
CPlusPlusLanguage::MethodName cxx_method(demangled_name);
82+
if (!cxx_method.GetBasename().empty()) {
83+
std::string shortname;
84+
if (!cxx_method.GetContext().empty())
85+
shortname = cxx_method.GetContext().str() + "::";
86+
shortname += cxx_method.GetBasename().str();
87+
return ConstString(shortname);
88+
}
89+
}
90+
}
91+
if (demangled_name)
92+
return demangled_name;
93+
return mangled.GetMangledName();
94+
}
95+
6796
// PluginInterface protocol
6897

6998
lldb_private::ConstString CPlusPlusLanguage::GetPluginName() {

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class CPlusPlusLanguage : public Language {
106106

107107
bool SymbolNameFitsToLanguage(Mangled mangled) const override;
108108

109+
ConstString
110+
GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override;
111+
109112
static bool IsCPPMangledName(llvm::StringRef name);
110113

111114
// Extract C++ context and identifier from a string using heuristic matching

0 commit comments

Comments
 (0)