Skip to content

Commit fbc6241

Browse files
authored
[LLDB] Refactored CPlusPlusLanguage::MethodName to break lldb-server dependencies (#132274)
This patch addresses the issue #129543. After this patch the size of lldb-server is reduced by 9MB. Co-authored-by: @bulbazord Alex Langford
1 parent 5c27511 commit fbc6241

17 files changed

+286
-267
lines changed

lldb/include/lldb/Core/Mangled.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class Mangled {
246246
/// for s, otherwise the enumerator for the mangling scheme detected.
247247
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef const name);
248248

249+
static bool IsMangledName(llvm::StringRef name);
250+
249251
/// Decode a serialized version of this object from data.
250252
///
251253
/// \param data

lldb/include/lldb/Core/RichManglingContext.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lldb/lldb-forward.h"
1313
#include "lldb/lldb-private.h"
1414

15+
#include "lldb/Target/Language.h"
1516
#include "lldb/Utility/ConstString.h"
1617

1718
#include "llvm/ADT/Any.h"
@@ -67,11 +68,7 @@ class RichManglingContext {
6768
char *m_ipd_buf;
6869
size_t m_ipd_buf_size = 2048;
6970

70-
/// Members for PluginCxxLanguage
71-
/// Cannot forward declare inner class CPlusPlusLanguage::MethodName. The
72-
/// respective header is in Plugins and including it from here causes cyclic
73-
/// dependency. Instead keep a llvm::Any and cast it on-access in the cpp.
74-
llvm::Any m_cxx_method_parser;
71+
std::unique_ptr<Language::MethodName> m_cxx_method_parser;
7572

7673
/// Clean up memory when using PluginCxxLanguage
7774
void ResetCxxMethodParser();
@@ -81,15 +78,6 @@ class RichManglingContext {
8178

8279
/// Uniform handling of string buffers for ItaniumPartialDemangler.
8380
llvm::StringRef processIPDStrResult(char *ipd_res, size_t res_len);
84-
85-
/// Cast the given parser to the given type. Ideally we would have a type
86-
/// trait to deduce \a ParserT from a given InfoProvider, but unfortunately we
87-
/// can't access CPlusPlusLanguage::MethodName from within the header.
88-
template <class ParserT> static ParserT *get(llvm::Any parser) {
89-
assert(parser.has_value());
90-
assert(llvm::any_cast<ParserT *>(&parser));
91-
return *llvm::any_cast<ParserT *>(&parser);
92-
}
9381
};
9482

9583
} // namespace lldb_private

lldb/include/lldb/Target/Language.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,104 @@ class Language : public PluginInterface {
214214
return std::vector<Language::MethodNameVariant>();
215215
};
216216

217+
class MethodName {
218+
public:
219+
MethodName() {}
220+
221+
MethodName(ConstString full)
222+
: m_full(full), m_basename(), m_context(), m_arguments(),
223+
m_qualifiers(), m_return_type(), m_scope_qualified(), m_parsed(false),
224+
m_parse_error(false) {}
225+
226+
virtual ~MethodName() {};
227+
228+
void Clear() {
229+
m_full.Clear();
230+
m_basename = llvm::StringRef();
231+
m_context = llvm::StringRef();
232+
m_arguments = llvm::StringRef();
233+
m_qualifiers = llvm::StringRef();
234+
m_return_type = llvm::StringRef();
235+
m_scope_qualified.clear();
236+
m_parsed = false;
237+
m_parse_error = false;
238+
}
239+
240+
bool IsValid() {
241+
if (!m_parsed)
242+
Parse();
243+
if (m_parse_error)
244+
return false;
245+
return (bool)m_full;
246+
}
247+
248+
ConstString GetFullName() const { return m_full; }
249+
250+
llvm::StringRef GetBasename() {
251+
if (!m_parsed)
252+
Parse();
253+
return m_basename;
254+
}
255+
256+
llvm::StringRef GetContext() {
257+
if (!m_parsed)
258+
Parse();
259+
return m_context;
260+
}
261+
262+
llvm::StringRef GetArguments() {
263+
if (!m_parsed)
264+
Parse();
265+
return m_arguments;
266+
}
267+
268+
llvm::StringRef GetQualifiers() {
269+
if (!m_parsed)
270+
Parse();
271+
return m_qualifiers;
272+
}
273+
274+
llvm::StringRef GetReturnType() {
275+
if (!m_parsed)
276+
Parse();
277+
return m_return_type;
278+
}
279+
280+
std::string GetScopeQualifiedName() {
281+
if (!m_parsed)
282+
Parse();
283+
return m_scope_qualified;
284+
}
285+
286+
protected:
287+
virtual void Parse() {
288+
m_parsed = true;
289+
m_parse_error = true;
290+
}
291+
292+
ConstString m_full; // Full name:
293+
// "size_t lldb::SBTarget::GetBreakpointAtIndex(unsigned
294+
// int) const"
295+
llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
296+
llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
297+
llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
298+
llvm::StringRef m_qualifiers; // Qualifiers: "const"
299+
llvm::StringRef m_return_type; // Return type: "size_t"
300+
std::string m_scope_qualified;
301+
bool m_parsed = false;
302+
bool m_parse_error = false;
303+
};
304+
305+
virtual std::unique_ptr<Language::MethodName>
306+
GetMethodName(ConstString name) const {
307+
return std::make_unique<Language::MethodName>(name);
308+
};
309+
310+
virtual std::pair<lldb::FunctionNameType, llvm::StringRef>
311+
GetFunctionNameInfo(ConstString name) const {
312+
return std::pair{lldb::eFunctionNameTypeNone, llvm::StringRef()};
313+
};
314+
217315
/// Returns true iff the given symbol name is compatible with the mangling
218316
/// scheme of this language.
219317
///

lldb/source/Core/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ if (LLDB_ENABLE_CURSES)
1616
endif()
1717
endif()
1818

19-
# TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbCore
20-
add_lldb_library(lldbCore
19+
add_lldb_library(lldbCore NO_PLUGIN_DEPENDENCIES
2120
Address.cpp
2221
AddressRange.cpp
2322
AddressRangeListImpl.cpp
@@ -71,8 +70,6 @@ add_lldb_library(lldbCore
7170
lldbUtility
7271
lldbValueObject
7372
lldbVersion
74-
lldbPluginCPlusPlusLanguage
75-
lldbPluginObjCLanguage
7673
${LLDB_CURSES_LIBS}
7774

7875
CLANG_LIBS

lldb/source/Core/Mangled.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
#include <cstring>
3434
using namespace lldb_private;
3535

36-
static inline bool cstring_is_mangled(llvm::StringRef s) {
37-
return Mangled::GetManglingScheme(s) != Mangled::eManglingSchemeNone;
38-
}
39-
4036
#pragma mark Mangled
4137

38+
bool Mangled::IsMangledName(llvm::StringRef name) {
39+
return Mangled::GetManglingScheme(name) != Mangled::eManglingSchemeNone;
40+
}
41+
4242
Mangled::ManglingScheme Mangled::GetManglingScheme(llvm::StringRef const name) {
4343
if (name.empty())
4444
return Mangled::eManglingSchemeNone;
@@ -121,7 +121,7 @@ int Mangled::Compare(const Mangled &a, const Mangled &b) {
121121

122122
void Mangled::SetValue(ConstString name) {
123123
if (name) {
124-
if (cstring_is_mangled(name.GetStringRef())) {
124+
if (IsMangledName(name.GetStringRef())) {
125125
m_demangled.Clear();
126126
m_mangled = name;
127127
} else {

0 commit comments

Comments
 (0)