Skip to content

[rebranch] Fix various LLDB failures #3635

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 2 commits into from
Dec 8, 2021
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
26 changes: 11 additions & 15 deletions lldb/bindings/python/static-binding/LLDBWrapPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80631,16 +80631,10 @@ LLDBSwigPythonCreateScriptedProcess

PythonObject result = {};
if (arg_info.get().max_positional_args == 2) {
if (args_impl != nullptr) {
error_string.assign("args passed, but __init__ does not take an args dictionary");
Py_RETURN_NONE;
}
result = pfunc(target_arg, dict);
} else if (arg_info.get().max_positional_args >= 3) {
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBStructuredData(args_impl)));
result = pfunc(target_arg, args_arg, dict);
result = pfunc(target_arg, args_arg);
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)");
error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
Py_RETURN_NONE;
}

Expand All @@ -80654,7 +80648,8 @@ LLDBSwigPythonCreateScriptedThread
(
const char *python_class_name,
const char *session_dictionary_name,
const lldb::TargetSP& target_sp,
const lldb::ProcessSP& process_sp,
lldb_private::StructuredDataImpl *args_impl,
std::string &error_string
)
{
Expand All @@ -80672,12 +80667,12 @@ LLDBSwigPythonCreateScriptedThread
return nullptr;
}

// I do not want the SBTarget to be deallocated when going out of scope
// I do not want the SBProcess to be deallocated when going out of scope
// because python has ownership of it and will manage memory for this
// object by itself
PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBTarget(target_sp)));
PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBProcess(process_sp)));

if (!target_arg.IsAllocated())
if (!process_arg.IsAllocated())
Py_RETURN_NONE;

llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
Expand All @@ -80694,10 +80689,11 @@ LLDBSwigPythonCreateScriptedThread
}

PythonObject result = {};
if (arg_info.get().max_positional_args == 1) {
result = pfunc(target_arg);
if (arg_info.get().max_positional_args == 2) {
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBStructuredData(args_impl)));
result = pfunc(process_arg, args_arg);
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)");
error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
Py_RETURN_NONE;
}

Expand Down
18 changes: 13 additions & 5 deletions lldb/include/lldb/Symbol/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ class TypeSystem : public PluginInterface {
Module *module);

static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
Target *target,
const char *compiler_options);
Target *target);

// BEGIN APPLE
static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
Target *target);
Target *target,
const char *compiler_options);
// END APPLE

// Free up any resources associated with this TypeSystem. Done before
// removing all the TypeSystems from the TypeSystemMap.
Expand Down Expand Up @@ -556,16 +558,22 @@ class TypeSystemMap {
// callback to keep iterating, false to stop iterating.
void ForEach(std::function<bool(TypeSystem *)> const &callback);

void RemoveTypeSystemsForLanguage(lldb::LanguageType language);

llvm::Expected<TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language, Module *module,
bool can_create);

llvm::Expected<TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language, Target *target,
bool can_create);

// BEGIN SWIFT
llvm::Expected<TypeSystem &>
GetTypeSystemForLanguage(lldb::LanguageType language, Target *target,
bool can_create, const char *compiler_options);

void RemoveTypeSystemsForLanguage(lldb::LanguageType language);
// END SWIFT

protected:
typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> collection;
mutable std::mutex m_mutex; ///< A mutex to keep this object happy in
Expand Down
45 changes: 27 additions & 18 deletions lldb/source/Symbol/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ lldb::TypeSystemSP TypeSystem::CreateInstance(lldb::LanguageType language,
}

lldb::TypeSystemSP TypeSystem::CreateInstance(lldb::LanguageType language,
Target *target,
const char *compiler_options) {
return CreateInstanceHelper(language, nullptr, target, compiler_options);
Target *target) {
return CreateInstanceHelper(language, nullptr, target, nullptr);
}

lldb::TypeSystemSP TypeSystem::CreateInstance(lldb::LanguageType language,
Target *target) {
return CreateInstanceHelper(language, nullptr, target, nullptr);
Target *target,
const char *compiler_options) {
return CreateInstanceHelper(language, nullptr, target, compiler_options);
}

#ifndef NDEBUG
Expand Down Expand Up @@ -299,29 +299,38 @@ llvm::Expected<TypeSystem &> TypeSystemMap::GetTypeSystemForLanguage(

llvm::Expected<TypeSystem &>
TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
Target *target, bool can_create,
// BEGIN: SWIFT
const char *compiler_options) {
// END: SWIFT
Module *module, bool can_create) {
if (can_create) {
return GetTypeSystemForLanguage(
language, llvm::Optional<CreateCallback>([language, target,
// BEGIN SWIFT
compiler_options]() {
return TypeSystem::CreateInstance(language, target, compiler_options);
// END SWIFT
language, llvm::Optional<CreateCallback>([language, module]() {
return TypeSystem::CreateInstance(language, module);
}));
}
return GetTypeSystemForLanguage(language);
}

llvm::Expected<TypeSystem &>
TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
Module *module, bool can_create) {
Target *target, bool can_create) {
if (can_create) {
return GetTypeSystemForLanguage(
language, llvm::Optional<CreateCallback>([language, module]() {
return TypeSystem::CreateInstance(language, module);
language, llvm::Optional<CreateCallback>([language, target]() {
return TypeSystem::CreateInstance(language, target);
}));
}
return GetTypeSystemForLanguage(language);
}

// BEGIN SWIFT
llvm::Expected<TypeSystem &>
TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the compiler options ever get used in the swift code anymore, so we don't really need this version either. It won't hurt anything to leave it in for now, but we should remove it at some point.

Target *target, bool can_create,
const char *compiler_options) {
if (can_create) {
return GetTypeSystemForLanguage(
language, llvm::Optional<CreateCallback>([language, target,
compiler_options]() {
return TypeSystem::CreateInstance(language, target, compiler_options);
}));
}
return GetTypeSystemForLanguage(language);
Expand All @@ -337,4 +346,4 @@ void TypeSystemMap::RemoveTypeSystemsForLanguage(lldb::LanguageType language) {
m_map.erase(pos);
}
}

// END SWIFT