Skip to content

Revert "[LLDB] Refactored CPlusPlusLanguage::MethodName to break lldb-server dependencies" #134995

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 1 commit into from
Apr 9, 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
2 changes: 0 additions & 2 deletions lldb/include/lldb/Core/Mangled.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ class Mangled {
/// for s, otherwise the enumerator for the mangling scheme detected.
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef const name);

static bool IsMangledName(llvm::StringRef name);

/// Decode a serialized version of this object from data.
///
/// \param data
Expand Down
16 changes: 14 additions & 2 deletions lldb/include/lldb/Core/RichManglingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "lldb/lldb-forward.h"
#include "lldb/lldb-private.h"

#include "lldb/Target/Language.h"
#include "lldb/Utility/ConstString.h"

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

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

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

/// Uniform handling of string buffers for ItaniumPartialDemangler.
llvm::StringRef processIPDStrResult(char *ipd_res, size_t res_len);

/// Cast the given parser to the given type. Ideally we would have a type
/// trait to deduce \a ParserT from a given InfoProvider, but unfortunately we
/// can't access CPlusPlusLanguage::MethodName from within the header.
template <class ParserT> static ParserT *get(llvm::Any parser) {
assert(parser.has_value());
assert(llvm::any_cast<ParserT *>(&parser));
return *llvm::any_cast<ParserT *>(&parser);
}
};

} // namespace lldb_private
Expand Down
98 changes: 0 additions & 98 deletions lldb/include/lldb/Target/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,104 +214,6 @@ class Language : public PluginInterface {
return std::vector<Language::MethodNameVariant>();
};

class MethodName {
public:
MethodName() {}

MethodName(ConstString full)
: m_full(full), m_basename(), m_context(), m_arguments(),
m_qualifiers(), m_return_type(), m_scope_qualified(), m_parsed(false),
m_parse_error(false) {}

virtual ~MethodName() {};

void Clear() {
m_full.Clear();
m_basename = llvm::StringRef();
m_context = llvm::StringRef();
m_arguments = llvm::StringRef();
m_qualifiers = llvm::StringRef();
m_return_type = llvm::StringRef();
m_scope_qualified.clear();
m_parsed = false;
m_parse_error = false;
}

bool IsValid() {
if (!m_parsed)
Parse();
if (m_parse_error)
return false;
return (bool)m_full;
}

ConstString GetFullName() const { return m_full; }

llvm::StringRef GetBasename() {
if (!m_parsed)
Parse();
return m_basename;
}

llvm::StringRef GetContext() {
if (!m_parsed)
Parse();
return m_context;
}

llvm::StringRef GetArguments() {
if (!m_parsed)
Parse();
return m_arguments;
}

llvm::StringRef GetQualifiers() {
if (!m_parsed)
Parse();
return m_qualifiers;
}

llvm::StringRef GetReturnType() {
if (!m_parsed)
Parse();
return m_return_type;
}

std::string GetScopeQualifiedName() {
if (!m_parsed)
Parse();
return m_scope_qualified;
}

protected:
virtual void Parse() {
m_parsed = true;
m_parse_error = true;
}

ConstString m_full; // Full name:
// "size_t lldb::SBTarget::GetBreakpointAtIndex(unsigned
// int) const"
llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
llvm::StringRef m_qualifiers; // Qualifiers: "const"
llvm::StringRef m_return_type; // Return type: "size_t"
std::string m_scope_qualified;
bool m_parsed = false;
bool m_parse_error = false;
};

virtual std::unique_ptr<Language::MethodName>
GetMethodName(ConstString name) const {
return std::make_unique<Language::MethodName>(name);
};

virtual std::pair<lldb::FunctionNameType, llvm::StringRef>
GetFunctionNameInfo(ConstString name) const {
return std::pair{lldb::eFunctionNameTypeNone, llvm::StringRef()};
};

/// Returns true iff the given symbol name is compatible with the mangling
/// scheme of this language.
///
Expand Down
5 changes: 4 additions & 1 deletion lldb/source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ if (LLDB_ENABLE_CURSES)
endif()
endif()

add_lldb_library(lldbCore NO_PLUGIN_DEPENDENCIES
# TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbCore
add_lldb_library(lldbCore
Address.cpp
AddressRange.cpp
AddressRangeListImpl.cpp
Expand Down Expand Up @@ -70,6 +71,8 @@ add_lldb_library(lldbCore NO_PLUGIN_DEPENDENCIES
lldbUtility
lldbValueObject
lldbVersion
lldbPluginCPlusPlusLanguage
lldbPluginObjCLanguage
${LLDB_CURSES_LIBS}

CLANG_LIBS
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Core/Mangled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
#include <cstring>
using namespace lldb_private;

#pragma mark Mangled

bool Mangled::IsMangledName(llvm::StringRef name) {
return Mangled::GetManglingScheme(name) != Mangled::eManglingSchemeNone;
static inline bool cstring_is_mangled(llvm::StringRef s) {
return Mangled::GetManglingScheme(s) != Mangled::eManglingSchemeNone;
}

#pragma mark Mangled

Mangled::ManglingScheme Mangled::GetManglingScheme(llvm::StringRef const name) {
if (name.empty())
return Mangled::eManglingSchemeNone;
Expand Down Expand Up @@ -121,7 +121,7 @@ int Mangled::Compare(const Mangled &a, const Mangled &b) {

void Mangled::SetValue(ConstString name) {
if (name) {
if (IsMangledName(name.GetStringRef())) {
if (cstring_is_mangled(name.GetStringRef())) {
m_demangled.Clear();
m_mangled = name;
} else {
Expand Down
Loading
Loading