Skip to content
Open
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
17 changes: 16 additions & 1 deletion lldb/cmake/modules/LLDBFramework.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,28 @@ set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_DOCUMENTATION_COMMENTS "YES")

# On iOS, there is no versioned framework layout. Skip this symlink step.
if(NOT APPLE_EMBEDDED)
# Apart from this one, CMake creates all required symlinks in the framework bundle.
add_custom_command(TARGET liblldb POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Versions/A/Modules/
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${LLDB_SOURCE_DIR}/include/lldb/lldb-framework.modulemap
${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Versions/A/Modules/module.modulemap
COMMENT "LLDB.framework: copy framework modulemap"
)

# Apart from these ones, CMake creates all required symlinks in the framework bundle.
add_custom_command(TARGET liblldb POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
Versions/Current/Headers
${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Headers
COMMENT "LLDB.framework: create Headers symlink"
)
add_custom_command(TARGET liblldb POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
Versions/Current/Modules
${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Modules
COMMENT "LLDB.framework: create Modules symlink"
)
endif()

# At configuration time, collect headers for the framework bundle and copy them
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/LLDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLDB_API_LLDB_H
#define LLDB_API_LLDB_H

#include "lldb/lldb-public.h"

#include "lldb/API/SBAddress.h"
#include "lldb/API/SBAttachInfo.h"
#include "lldb/API/SBBlock.h"
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ enum ScriptLanguage {
eScriptLanguageNone = 0,
eScriptLanguagePython,
eScriptLanguageLua,
eScriptLanguageSwift,
eScriptLanguageUnknown,
eScriptLanguageDefault = eScriptLanguagePython
};
Expand Down
10 changes: 10 additions & 0 deletions lldb/include/lldb/lldb-framework.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
framework module LLDB {
requires cplusplus
umbrella header "LLDB.h"

export *
module * {
export *
}
}

1 change: 1 addition & 0 deletions lldb/source/Commands/CommandObjectBreakpointCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ are no syntax errors may indicate that a function was declared but never called.
switch (m_script_language) {
case eScriptLanguagePython:
case eScriptLanguageLua:
case eScriptLanguageSwift:
m_use_script_language = true;
break;
case eScriptLanguageNone:
Expand Down
5 changes: 5 additions & 0 deletions lldb/source/Commands/CommandObjectScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ static constexpr OptionEnumValueElement g_script_option_enumeration[] = {
"lua",
"Lua",
},
{
eScriptLanguageSwift,
"swift",
"Swift",
},
{
eScriptLanguageNone,
"default",
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Commands/CommandObjectWatchpointCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ are no syntax errors may indicate that a function was declared but never called.
switch (m_script_language) {
case eScriptLanguagePython:
case eScriptLanguageLua:
case eScriptLanguageSwift:
m_use_script_language = true;
break;
case eScriptLanguageNone:
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Interpreter/OptionArgParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ lldb::ScriptLanguage OptionArgParser::ToScriptLanguage(
return eScriptLanguagePython;
if (s.equals_insensitive("lua"))
return eScriptLanguageLua;
if (s.equals_insensitive("swift"))
return eScriptLanguageSwift;
if (s.equals_insensitive("default"))
return eScriptLanguageDefault;
if (s.equals_insensitive("none"))
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Interpreter/ScriptInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
return "Python";
case eScriptLanguageLua:
return "Lua";
case eScriptLanguageSwift:
return "Swift";
case eScriptLanguageUnknown:
return "Unknown";
}
Expand Down Expand Up @@ -91,6 +93,8 @@ ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
return eScriptLanguagePython;
if (language.equals_insensitive(LanguageToString(eScriptLanguageLua)))
return eScriptLanguageLua;
if (language.equals_insensitive(LanguageToString(eScriptLanguageSwift)))
return eScriptLanguageSwift;
return eScriptLanguageUnknown;
}

Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Plugins/ScriptInterpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ endif()
if (LLDB_ENABLE_LUA)
add_subdirectory(Lua)
endif()

add_subdirectory(Swift)
9 changes: 9 additions & 0 deletions lldb/source/Plugins/ScriptInterpreter/Swift/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_lldb_library(lldbPluginScriptInterpreterSwift PLUGIN
ScriptInterpreterSwift.cpp
SwiftInterpreter.cpp

LINK_LIBS
lldbCore
lldbInterpreter
LLVMOrcJIT
)
140 changes: 140 additions & 0 deletions lldb/source/Plugins/ScriptInterpreter/Swift/ScriptInterpreterSwift.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//===-- ScriptInterpreterSwift.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "ScriptInterpreterSwift.h"
#include "SwiftInterpreter.h"

#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Interpreter/CommandReturnObject.h"

#include "llvm/Support/FormatAdapters.h"

#include <memory>
#include <vector>

using namespace lldb;
using namespace lldb_private;

LLDB_PLUGIN_DEFINE(ScriptInterpreterSwift)

ScriptInterpreterSwift::ScriptInterpreterSwift(Debugger &Debugger)
: ScriptInterpreter(Debugger, eScriptLanguageSwift) {}

ScriptInterpreterSwift::~ScriptInterpreterSwift() {}

bool ScriptInterpreterSwift::ExecuteOneLine(
llvm::StringRef Command, CommandReturnObject *Result,
const ExecuteScriptOptions &Options) {
if (Command.empty()) {
if (Result)
Result->AppendError("empty command passed to swift\n");
return false;
}

llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
IORedirectOrError = ScriptInterpreterIORedirect::Create(
Options.GetEnableIO(), m_debugger, Result);
if (!IORedirectOrError) {
if (Result)
Result->AppendErrorWithFormatv(
"failed to redirect I/O: {0}\n",
llvm::fmt_consume(IORedirectOrError.takeError()));
else
llvm::consumeError(IORedirectOrError.takeError());
return false;
}

ScriptInterpreterIORedirect &IORedirect = **IORedirectOrError;

if (auto Error = m_swift->executeOneLine(Command, m_debugger)) {
Result->AppendErrorWithFormatv(
"Swift failed attempting to evaluate '{0}': {1}\n", Command,
llvm::toString(std::move(Error)));
return false;
}

IORedirect.Flush();
return true;
}

void ScriptInterpreterSwift::ExecuteInterpreterLoop() {
// At the moment, the only time the debugger does not have an input file
// handle is when this is called directly from lua, in which case it is
// both dangerous and unnecessary (not to mention confusing) to try to embed
// a running interpreter loop inside the already running lua interpreter
// loop, so we won't do it.
if (!m_debugger.GetInputFile().IsValid())
return;

// FIXME: unimplemented
}

bool ScriptInterpreterSwift::LoadScriptingModule(
const char *Filename, const LoadScriptOptions &options,
lldb_private::Status &Error, StructuredData::ObjectSP *Module_sp,
FileSpec ExtraSearchDir) {

FileSystem::Instance().Collect(Filename);
if (llvm::Error E = m_swift->loadScriptFile(Filename)) {
Error.SetErrorStringWithFormatv("swift failed to import '{0}': {1}\n",
Filename, llvm::toString(std::move(E)));
return false;
}
return true;
}

void ScriptInterpreterSwift::Initialize() {
static llvm::once_flag g_onceFlag;

llvm::call_once(g_onceFlag, []() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(),
lldb::eScriptLanguageSwift, CreateInstance);
});
}

void ScriptInterpreterSwift::Terminate() {}

llvm::Error ScriptInterpreterSwift::EnterSession(user_id_t DebuggerId) {
if (m_sessionIsActive)
return llvm::Error::success();

m_sessionIsActive = true;

return llvm::Error::success();
}

llvm::Error ScriptInterpreterSwift::LeaveSession() {
if (!m_sessionIsActive)
return llvm::Error::success();

m_sessionIsActive = false;

return llvm::Error::success();
}

lldb::ScriptInterpreterSP
ScriptInterpreterSwift::CreateInstance(Debugger &Debugger) {
return std::make_shared<ScriptInterpreterSwift>(Debugger);
}

lldb_private::ConstString ScriptInterpreterSwift::GetPluginNameStatic() {
static ConstString g_name("script-swift");
return g_name;
}

const char *ScriptInterpreterSwift::GetPluginDescriptionStatic() {
return "Swift script interpreter";
}

lldb_private::ConstString ScriptInterpreterSwift::GetPluginName() {
return GetPluginNameStatic();
}

uint32_t ScriptInterpreterSwift::GetPluginVersion() { return 1; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//===-- ScriptInterpreterSwift.h --------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_ScriptInterpreterSwift_h_
#define liblldb_ScriptInterpreterSwift_h_

#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"

namespace lldb_private {

class SwiftInterpreter;

class ScriptInterpreterSwift : public ScriptInterpreter {
public:
class CommandDataSwift : public BreakpointOptions::CommandData {
public:
CommandDataSwift() : BreakpointOptions::CommandData() {
interpreter = lldb::eScriptLanguageSwift;
}
};

ScriptInterpreterSwift(Debugger &debugger);

~ScriptInterpreterSwift() override;

bool ExecuteOneLine(
llvm::StringRef command, CommandReturnObject *result,
const ExecuteScriptOptions &options = ExecuteScriptOptions()) override;

void ExecuteInterpreterLoop() override;

bool LoadScriptingModule(const char *filename,
const LoadScriptOptions &options,
lldb_private::Status &error,
StructuredData::ObjectSP *module_sp = nullptr,
FileSpec extra_search_dir = {}) override;

// Static Functions
static void Initialize();

static void Terminate();

static lldb::ScriptInterpreterSP CreateInstance(Debugger &debugger);

static lldb_private::ConstString GetPluginNameStatic();

static const char *GetPluginDescriptionStatic();

static bool BreakpointCallbackFunction(void *baton,
StoppointCallbackContext *context,
lldb::user_id_t break_id,
lldb::user_id_t break_loc_id);

// PluginInterface protocol
lldb_private::ConstString GetPluginName() override;

uint32_t GetPluginVersion() override;

llvm::Error EnterSession(lldb::user_id_t debugger_id);
llvm::Error LeaveSession();

private:
bool m_sessionIsActive = false;
std::unique_ptr<SwiftInterpreter> m_swift =
std::make_unique<SwiftInterpreter>();
};

} // namespace lldb_private

#endif // liblldb_ScriptInterpreterSwift_h_
Loading