156 changes: 77 additions & 79 deletions lldb/tools/lldb-vscode/VSCode.cpp → lldb/tools/lldb-dap/DAP.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- VSCode.cpp ----------------------------------------------*- C++ -*-===//
//===-- DAP.cpp -------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -12,8 +12,8 @@
#include <mutex>
#include <sstream>

#include "DAP.h"
#include "LLDBUtils.h"
#include "VSCode.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/FormatVariadic.h"

Expand All @@ -24,14 +24,14 @@
#include <windows.h>
#endif

using namespace lldb_vscode;
using namespace lldb_dap;

namespace lldb_vscode {
namespace lldb_dap {

VSCode g_vsc;
DAP g_dap;

VSCode::VSCode()
: broadcaster("lldb-vscode"),
DAP::DAP()
: broadcaster("lldb-dap"),
exception_breakpoints(
{{"cpp_catch", "C++ Catch", lldb::eLanguageTypeC_plus_plus},
{"cpp_throw", "C++ Throw", lldb::eLanguageTypeC_plus_plus},
Expand All @@ -49,7 +49,7 @@ VSCode::VSCode()
[&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }),
reverse_request_seq(0), repl_mode(ReplMode::Auto),
auto_repl_mode_collision_warning(false) {
const char *log_file_path = getenv("LLDBVSCODE_LOG");
const char *log_file_path = getenv("LLDBDAP_LOG");
#if defined(_WIN32)
// Windows opens stdout and stdin in text mode which converts \n to 13,10
// while the value is just 10 on Darwin/Linux. Setting the file mode to binary
Expand All @@ -64,18 +64,17 @@ VSCode::VSCode()
log.reset(new std::ofstream(log_file_path));
}

VSCode::~VSCode() = default;
DAP::~DAP() = default;

ExceptionBreakpoint *VSCode::GetExceptionBreakpoint(const std::string &filter) {
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
for (auto &bp : exception_breakpoints) {
if (bp.filter == filter)
return &bp;
}
return nullptr;
}

ExceptionBreakpoint *
VSCode::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
for (auto &bp : exception_breakpoints) {
if (bp.bp.GetID() == bp_id)
return &bp;
Expand All @@ -86,7 +85,7 @@ VSCode::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
// Send the JSON in "json_str" to the "out" stream. Correctly send the
// "Content-Length:" field followed by the length, followed by the raw
// JSON bytes.
void VSCode::SendJSON(const std::string &json_str) {
void DAP::SendJSON(const std::string &json_str) {
output.write_full("Content-Length: ");
output.write_full(llvm::utostr(json_str.size()));
output.write_full("\r\n\r\n");
Expand All @@ -95,7 +94,7 @@ void VSCode::SendJSON(const std::string &json_str) {

// Serialize the JSON value into a string and send the JSON packet to
// the "out" stream.
void VSCode::SendJSON(const llvm::json::Value &json) {
void DAP::SendJSON(const llvm::json::Value &json) {
std::string s;
llvm::raw_string_ostream strm(s);
strm << json;
Expand All @@ -112,7 +111,7 @@ void VSCode::SendJSON(const llvm::json::Value &json) {
}

// Read a JSON packet from the "in" stream.
std::string VSCode::ReadJSON() {
std::string DAP::ReadJSON() {
std::string length_str;
std::string json_str;
int length;
Expand Down Expand Up @@ -198,7 +197,7 @@ std::string VSCode::ReadJSON() {
// "required": [ "event", "body" ]
// }]
// }
void VSCode::SendOutput(OutputType o, const llvm::StringRef output) {
void DAP::SendOutput(OutputType o, const llvm::StringRef output) {
if (output.empty())
return;

Expand Down Expand Up @@ -318,13 +317,13 @@ void VSCode::SendOutput(OutputType o, const llvm::StringRef output) {
// };
// }

void VSCode::SendProgressEvent(uint64_t progress_id, const char *message,
uint64_t completed, uint64_t total) {
void DAP::SendProgressEvent(uint64_t progress_id, const char *message,
uint64_t completed, uint64_t total) {
progress_event_reporter.Push(progress_id, message, completed, total);
}

void __attribute__((format(printf, 3, 4)))
VSCode::SendFormattedOutput(OutputType o, const char *format, ...) {
DAP::SendFormattedOutput(OutputType o, const char *format, ...) {
char buffer[1024];
va_list args;
va_start(args, format);
Expand All @@ -334,8 +333,7 @@ VSCode::SendFormattedOutput(OutputType o, const char *format, ...) {
o, llvm::StringRef(buffer, std::min<int>(actual_length, sizeof(buffer))));
}

ExceptionBreakpoint *
VSCode::GetExceptionBPFromStopReason(lldb::SBThread &thread) {
ExceptionBreakpoint *DAP::GetExceptionBPFromStopReason(lldb::SBThread &thread) {
const auto num = thread.GetStopReasonDataCount();
// Check to see if have hit an exception breakpoint and change the
// reason to "exception", but only do so if all breakpoints that were
Expand All @@ -356,12 +354,12 @@ VSCode::GetExceptionBPFromStopReason(lldb::SBThread &thread) {
return exc_bp;
}

lldb::SBThread VSCode::GetLLDBThread(const llvm::json::Object &arguments) {
lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) {
auto tid = GetSigned(arguments, "threadId", LLDB_INVALID_THREAD_ID);
return target.GetProcess().GetThreadByID(tid);
}

lldb::SBFrame VSCode::GetLLDBFrame(const llvm::json::Object &arguments) {
lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) {
const uint64_t frame_id = GetUnsigned(arguments, "frameId", UINT64_MAX);
lldb::SBProcess process = target.GetProcess();
// Upper 32 bits is the thread index ID
Expand All @@ -371,19 +369,19 @@ lldb::SBFrame VSCode::GetLLDBFrame(const llvm::json::Object &arguments) {
return thread.GetFrameAtIndex(GetLLDBFrameID(frame_id));
}

llvm::json::Value VSCode::CreateTopLevelScopes() {
llvm::json::Value DAP::CreateTopLevelScopes() {
llvm::json::Array scopes;
scopes.emplace_back(CreateScope("Locals", VARREF_LOCALS,
g_vsc.variables.locals.GetSize(), false));
g_dap.variables.locals.GetSize(), false));
scopes.emplace_back(CreateScope("Globals", VARREF_GLOBALS,
g_vsc.variables.globals.GetSize(), false));
g_dap.variables.globals.GetSize(), false));
scopes.emplace_back(CreateScope("Registers", VARREF_REGS,
g_vsc.variables.registers.GetSize(), false));
g_dap.variables.registers.GetSize(), false));
return llvm::json::Value(std::move(scopes));
}

ExpressionContext VSCode::DetectExpressionContext(lldb::SBFrame &frame,
std::string &text) {
ExpressionContext DAP::DetectExpressionContext(lldb::SBFrame &frame,
std::string &text) {
// Include ` as an escape hatch.
if (!text.empty() && text[0] == '`') {
text = text.substr(1);
Expand Down Expand Up @@ -433,35 +431,35 @@ ExpressionContext VSCode::DetectExpressionContext(lldb::SBFrame &frame,
return ExpressionContext::Variable;
}

void VSCode::RunLLDBCommands(llvm::StringRef prefix,
const std::vector<std::string> &commands) {
void DAP::RunLLDBCommands(llvm::StringRef prefix,
const std::vector<std::string> &commands) {
SendOutput(OutputType::Console,
llvm::StringRef(::RunLLDBCommands(prefix, commands)));
}

void VSCode::RunInitCommands() {
void DAP::RunInitCommands() {
RunLLDBCommands("Running initCommands:", init_commands);
}

void VSCode::RunPreRunCommands() {
void DAP::RunPreRunCommands() {
RunLLDBCommands("Running preRunCommands:", pre_run_commands);
}

void VSCode::RunStopCommands() {
void DAP::RunStopCommands() {
RunLLDBCommands("Running stopCommands:", stop_commands);
}

void VSCode::RunExitCommands() {
void DAP::RunExitCommands() {
RunLLDBCommands("Running exitCommands:", exit_commands);
}

void VSCode::RunTerminateCommands() {
void DAP::RunTerminateCommands() {
RunLLDBCommands("Running terminateCommands:", terminate_commands);
}

lldb::SBTarget
VSCode::CreateTargetFromArguments(const llvm::json::Object &arguments,
lldb::SBError &error) {
DAP::CreateTargetFromArguments(const llvm::json::Object &arguments,
lldb::SBError &error) {
// Grab the name of the program we need to debug and create a target using
// the given program as an argument. Executable file can be a source of target
// architecture and platform, if they differ from the host. Setting exe path
Expand Down Expand Up @@ -490,7 +488,7 @@ VSCode::CreateTargetFromArguments(const llvm::json::Object &arguments,
return target;
}

void VSCode::SetTarget(const lldb::SBTarget target) {
void DAP::SetTarget(const lldb::SBTarget target) {
this->target = target;

if (target.IsValid()) {
Expand All @@ -504,7 +502,7 @@ void VSCode::SetTarget(const lldb::SBTarget target) {
}
}

PacketStatus VSCode::GetNextObject(llvm::json::Object &object) {
PacketStatus DAP::GetNextObject(llvm::json::Object &object) {
std::string json = ReadJSON();
if (json.empty())
return PacketStatus::EndOfFile;
Expand Down Expand Up @@ -538,7 +536,7 @@ PacketStatus VSCode::GetNextObject(llvm::json::Object &object) {
return PacketStatus::Success;
}

bool VSCode::HandleObject(const llvm::json::Object &object) {
bool DAP::HandleObject(const llvm::json::Object &object) {
const auto packet_type = GetString(object, "type");
if (packet_type == "request") {
const auto command = GetString(object, "command");
Expand Down Expand Up @@ -591,16 +589,16 @@ bool VSCode::HandleObject(const llvm::json::Object &object) {
return false;
}

llvm::Error VSCode::Loop() {
llvm::Error DAP::Loop() {
while (!sent_terminated_event) {
llvm::json::Object object;
lldb_vscode::PacketStatus status = GetNextObject(object);
lldb_dap::PacketStatus status = GetNextObject(object);

if (status == lldb_vscode::PacketStatus::EndOfFile) {
if (status == lldb_dap::PacketStatus::EndOfFile) {
break;
}

if (status != lldb_vscode::PacketStatus::Success) {
if (status != lldb_dap::PacketStatus::Success) {
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"failed to send packet");
}
Expand All @@ -614,9 +612,9 @@ llvm::Error VSCode::Loop() {
return llvm::Error::success();
}

void VSCode::SendReverseRequest(llvm::StringRef command,
llvm::json::Value arguments,
ResponseCallback callback) {
void DAP::SendReverseRequest(llvm::StringRef command,
llvm::json::Value arguments,
ResponseCallback callback) {
int64_t id;
{
std::lock_guard<std::mutex> locker(call_mutex);
Expand All @@ -632,12 +630,12 @@ void VSCode::SendReverseRequest(llvm::StringRef command,
});
}

void VSCode::RegisterRequestCallback(std::string request,
RequestCallback callback) {
void DAP::RegisterRequestCallback(std::string request,
RequestCallback callback) {
request_handlers[request] = callback;
}

lldb::SBError VSCode::WaitForProcessToStop(uint32_t seconds) {
lldb::SBError DAP::WaitForProcessToStop(uint32_t seconds) {
lldb::SBError error;
lldb::SBProcess process = target.GetProcess();
if (!process.IsValid()) {
Expand All @@ -649,26 +647,26 @@ lldb::SBError VSCode::WaitForProcessToStop(uint32_t seconds) {
while (std::chrono::steady_clock::now() < timeout_time) {
const auto state = process.GetState();
switch (state) {
case lldb::eStateAttaching:
case lldb::eStateConnected:
case lldb::eStateInvalid:
case lldb::eStateLaunching:
case lldb::eStateRunning:
case lldb::eStateStepping:
case lldb::eStateSuspended:
break;
case lldb::eStateDetached:
error.SetErrorString("process detached during launch or attach");
return error;
case lldb::eStateExited:
error.SetErrorString("process exited during launch or attach");
return error;
case lldb::eStateUnloaded:
error.SetErrorString("process unloaded during launch or attach");
return error;
case lldb::eStateCrashed:
case lldb::eStateStopped:
return lldb::SBError(); // Success!
case lldb::eStateAttaching:
case lldb::eStateConnected:
case lldb::eStateInvalid:
case lldb::eStateLaunching:
case lldb::eStateRunning:
case lldb::eStateStepping:
case lldb::eStateSuspended:
break;
case lldb::eStateDetached:
error.SetErrorString("process detached during launch or attach");
return error;
case lldb::eStateExited:
error.SetErrorString("process exited during launch or attach");
return error;
case lldb::eStateUnloaded:
error.SetErrorString("process unloaded during launch or attach");
return error;
case lldb::eStateCrashed:
case lldb::eStateStopped:
return lldb::SBError(); // Success!
}
std::this_thread::sleep_for(std::chrono::microseconds(250));
}
Expand Down Expand Up @@ -759,7 +757,7 @@ bool StartDebuggingRequestHandler::DoExecute(
return false;
}

g_vsc.SendReverseRequest(
g_dap.SendReverseRequest(
"startDebugging",
llvm::json::Object{{"request", request},
{"configuration", std::move(*configuration)}},
Expand All @@ -783,7 +781,7 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
// If a new mode is not specified report the current mode.
if (!command || llvm::StringRef(command[0]).empty()) {
std::string mode;
switch (g_vsc.repl_mode) {
switch (g_dap.repl_mode) {
case ReplMode::Variable:
mode = "variable";
break;
Expand All @@ -795,7 +793,7 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
break;
}

result.Printf("lldb-vscode repl-mode %s.\n", mode.c_str());
result.Printf("lldb-dap repl-mode %s.\n", mode.c_str());
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);

return true;
Expand All @@ -804,11 +802,11 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
llvm::StringRef new_mode{command[0]};

if (new_mode == "variable") {
g_vsc.repl_mode = ReplMode::Variable;
g_dap.repl_mode = ReplMode::Variable;
} else if (new_mode == "command") {
g_vsc.repl_mode = ReplMode::Command;
g_dap.repl_mode = ReplMode::Command;
} else if (new_mode == "auto") {
g_vsc.repl_mode = ReplMode::Auto;
g_dap.repl_mode = ReplMode::Auto;
} else {
lldb::SBStream error_message;
error_message.Printf("Invalid repl-mode '%s'. Expected one of 'variable', "
Expand All @@ -818,9 +816,9 @@ bool ReplModeRequestHandler::DoExecute(lldb::SBDebugger debugger,
return false;
}

result.Printf("lldb-vscode repl-mode %s set.\n", new_mode.data());
result.Printf("lldb-dap repl-mode %s set.\n", new_mode.data());
result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
return true;
}

} // namespace lldb_vscode
} // namespace lldb_dap
26 changes: 13 additions & 13 deletions lldb/tools/lldb-vscode/VSCode.h → lldb/tools/lldb-dap/DAP.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- VSCode.h ------------------------------------------------*- C++ -*-===//
//===-- DAP.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 LLDB_TOOLS_LLDB_VSCODE_VSCODE_H
#define LLDB_TOOLS_LLDB_VSCODE_VSCODE_H
#ifndef LLDB_TOOLS_LLDB_DAP_DAP_H
#define LLDB_TOOLS_LLDB_DAP_DAP_H

#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX

Expand Down Expand Up @@ -62,13 +62,13 @@
#define VARREF_FIRST_VAR_IDX (int64_t)4
#define NO_TYPENAME "<no-type>"

namespace lldb_vscode {
namespace lldb_dap {

typedef llvm::DenseMap<uint32_t, SourceBreakpoint> SourceBreakpointMap;
typedef llvm::StringMap<FunctionBreakpoint> FunctionBreakpointMap;
enum class OutputType { Console, Stdout, Stderr, Telemetry };

enum VSCodeBroadcasterBits {
enum DAPBroadcasterBits {
eBroadcastBitStopEventThread = 1u << 0,
eBroadcastBitStopProgressThread = 1u << 1
};
Expand Down Expand Up @@ -141,7 +141,7 @@ struct ReplModeRequestHandler : public lldb::SBCommandPluginInterface {
lldb::SBCommandReturnObject &result) override;
};

struct VSCode {
struct DAP {
std::string debug_adaptor_path;
InputStream input;
OutputStream output;
Expand Down Expand Up @@ -189,10 +189,10 @@ struct VSCode {
ReplMode repl_mode;
bool auto_repl_mode_collision_warning;

VSCode();
~VSCode();
VSCode(const VSCode &rhs) = delete;
void operator=(const VSCode &rhs) = delete;
DAP();
~DAP();
DAP(const DAP &rhs) = delete;
void operator=(const DAP &rhs) = delete;
ExceptionBreakpoint *GetExceptionBreakpoint(const std::string &filter);
ExceptionBreakpoint *GetExceptionBreakpoint(const lldb::break_id_t bp_id);

Expand Down Expand Up @@ -245,7 +245,7 @@ struct VSCode {
lldb::SBTarget CreateTargetFromArguments(const llvm::json::Object &arguments,
lldb::SBError &error);

/// Set given target object as a current target for lldb-vscode and start
/// Set given target object as a current target for lldb-dap and start
/// listeing for its breakpoint events.
void SetTarget(const lldb::SBTarget target);

Expand Down Expand Up @@ -311,8 +311,8 @@ struct VSCode {
void SendJSON(const std::string &json_str);
};

extern VSCode g_vsc;
extern DAP g_dap;

} // namespace lldb_vscode
} // namespace lldb_dap

#endif
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//===-- VSCodeForward.h -----------------------------------------*- C++ -*-===//
//===-- DAPForward.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 LLDB_TOOLS_LLDB_VSCODE_VSCODEFORWARD_H
#define LLDB_TOOLS_LLDB_VSCODE_VSCODEFORWARD_H
#ifndef LLDB_TOOLS_LLDB_DAP_DAPFORWARD_H
#define LLDB_TOOLS_LLDB_DAP_DAPFORWARD_H

namespace lldb_vscode {
namespace lldb_dap {
struct BreakpointBase;
struct ExceptionBreakpoint;
struct FunctionBreakpoint;
struct SourceBreakpoint;
} // namespace lldb_vscode
} // namespace lldb_dap

namespace lldb {
class SBAttachInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

#include "ExceptionBreakpoint.h"
#include "BreakpointBase.h"
#include "VSCode.h"
#include "DAP.h"

namespace lldb_vscode {
namespace lldb_dap {

void ExceptionBreakpoint::SetBreakpoint() {
if (bp.IsValid())
return;
bool catch_value = filter.find("_catch") != std::string::npos;
bool throw_value = filter.find("_throw") != std::string::npos;
bp = g_vsc.target.BreakpointCreateForException(language, catch_value,
bp = g_dap.target.BreakpointCreateForException(language, catch_value,
throw_value);
// See comments in BreakpointBase::GetBreakpointLabel() for details of why
// we add a label to our breakpoints.
Expand All @@ -27,8 +27,8 @@ void ExceptionBreakpoint::SetBreakpoint() {
void ExceptionBreakpoint::ClearBreakpoint() {
if (!bp.IsValid())
return;
g_vsc.target.BreakpointDelete(bp.GetID());
g_dap.target.BreakpointDelete(bp.GetID());
bp = lldb::SBBreakpoint();
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_EXCEPTIONBREAKPOINT_H
#define LLDB_TOOLS_LLDB_VSCODE_EXCEPTIONBREAKPOINT_H
#ifndef LLDB_TOOLS_LLDB_DAP_EXCEPTIONBREAKPOINT_H
#define LLDB_TOOLS_LLDB_DAP_EXCEPTIONBREAKPOINT_H

#include <string>

#include "lldb/API/SBBreakpoint.h"

namespace lldb_vscode {
namespace lldb_dap {

struct ExceptionBreakpoint {
std::string filter;
Expand All @@ -29,6 +29,6 @@ struct ExceptionBreakpoint {
void ClearBreakpoint();
};

} // namespace lldb_vscode
} // namespace lldb_dap

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

using namespace llvm;

namespace lldb_vscode {
namespace lldb_dap {

FifoFile::FifoFile(StringRef path) : m_path(path) {}

Expand Down Expand Up @@ -102,4 +102,4 @@ Error FifoFileIO::SendJSON(const json::Value &json,
return Error::success();
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_FIFOFILES_H
#define LLDB_TOOLS_LLDB_VSCODE_FIFOFILES_H
#ifndef LLDB_TOOLS_LLDB_DAP_FIFOFILES_H
#define LLDB_TOOLS_LLDB_DAP_FIFOFILES_H

#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
#include "llvm/Support/Error.h"
Expand All @@ -16,7 +16,7 @@

#include <chrono>

namespace lldb_vscode {
namespace lldb_dap {

/// Struct that controls the life of a fifo file in the filesystem.
///
Expand Down Expand Up @@ -82,6 +82,6 @@ class FifoFileIO {
std::string m_other_endpoint_name;
};

} // namespace lldb_vscode
} // namespace lldb_dap

#endif // LLDB_TOOLS_LLDB_VSCODE_FIFOFILES_H
#endif // LLDB_TOOLS_LLDB_DAP_FIFOFILES_H
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
//===----------------------------------------------------------------------===//

#include "FunctionBreakpoint.h"
#include "VSCode.h"
#include "DAP.h"

namespace lldb_vscode {
namespace lldb_dap {

FunctionBreakpoint::FunctionBreakpoint(const llvm::json::Object &obj)
: BreakpointBase(obj), functionName(std::string(GetString(obj, "name"))) {}

void FunctionBreakpoint::SetBreakpoint() {
if (functionName.empty())
return;
bp = g_vsc.target.BreakpointCreateByName(functionName.c_str());
bp = g_dap.target.BreakpointCreateByName(functionName.c_str());
// See comments in BreakpointBase::GetBreakpointLabel() for details of why
// we add a label to our breakpoints.
bp.AddName(GetBreakpointLabel());
Expand All @@ -29,4 +29,4 @@ void FunctionBreakpoint::SetBreakpoint() {
SetLogMessage();
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_FUNCTIONBREAKPOINT_H
#define LLDB_TOOLS_LLDB_VSCODE_FUNCTIONBREAKPOINT_H
#ifndef LLDB_TOOLS_LLDB_DAP_FUNCTIONBREAKPOINT_H
#define LLDB_TOOLS_LLDB_DAP_FUNCTIONBREAKPOINT_H

#include "BreakpointBase.h"

namespace lldb_vscode {
namespace lldb_dap {

struct FunctionBreakpoint : public BreakpointBase {
std::string functionName;
Expand All @@ -23,6 +23,6 @@ struct FunctionBreakpoint : public BreakpointBase {
void SetBreakpoint();
};

} // namespace lldb_vscode
} // namespace lldb_dap

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string>
#include <vector>

using namespace lldb_vscode;
using namespace lldb_dap;

StreamDescriptor::StreamDescriptor() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_IOSTREAM_H
#define LLDB_TOOLS_LLDB_VSCODE_IOSTREAM_H
#ifndef LLDB_TOOLS_LLDB_DAP_IOSTREAM_H
#define LLDB_TOOLS_LLDB_DAP_IOSTREAM_H

#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX

Expand All @@ -32,7 +32,7 @@ typedef int SOCKET;
// types of files, so we can't simply have one code path that just uses read
// and write everywhere. So we need an abstraction in order to allow us to
// treat them identically.
namespace lldb_vscode {
namespace lldb_dap {
struct StreamDescriptor {
StreamDescriptor();
~StreamDescriptor();
Expand Down Expand Up @@ -66,6 +66,6 @@ struct OutputStream {

bool write_full(llvm::StringRef str);
};
} // namespace lldb_vscode
} // namespace lldb_dap

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
#include "lldb/API/SBValue.h"
#include "lldb/Host/PosixApi.h"

#include "DAP.h"
#include "ExceptionBreakpoint.h"
#include "JSONUtils.h"
#include "LLDBUtils.h"
#include "VSCode.h"

namespace lldb_vscode {
namespace lldb_dap {

void EmplaceSafeString(llvm::json::Object &obj, llvm::StringRef key,
llvm::StringRef str) {
Expand Down Expand Up @@ -140,7 +140,7 @@ TryCreateAutoSummaryForContainer(lldb::SBValue &v) {
// We gate this feature because it performs GetNumChildren(), which can
// cause performance issues because LLDB needs to complete possibly huge
// types.
if (!g_vsc.enable_auto_variable_summaries)
if (!g_dap.enable_auto_variable_summaries)
return std::nullopt;

if (!v.MightHaveChildren())
Expand Down Expand Up @@ -197,7 +197,7 @@ TryCreateAutoSummaryForContainer(lldb::SBValue &v) {
/// Try to create a summary string for the given value that doesn't have a
/// summary of its own.
static std::optional<std::string> TryCreateAutoSummary(lldb::SBValue value) {
if (!g_vsc.enable_auto_variable_summaries)
if (!g_dap.enable_auto_variable_summaries)
return std::nullopt;

// We use the dereferenced value for generating the summary.
Expand Down Expand Up @@ -326,7 +326,7 @@ llvm::json::Value CreateScope(const llvm::StringRef name,
llvm::json::Object object;
EmplaceSafeString(object, "name", name.str());

// TODO: Support "arguments" scope. At the moment lldb-vscode includes the
// TODO: Support "arguments" scope. At the moment lldb-dap includes the
// arguments into the "locals" scope.
if (variablesReference == VARREF_LOCALS) {
object.try_emplace("presentationHint", "locals");
Expand Down Expand Up @@ -425,7 +425,7 @@ llvm::json::Value CreateBreakpoint(lldb::SBBreakpoint &bp,

if (bp_addr.IsValid()) {
std::string formatted_addr =
"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(g_vsc.target));
"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(g_dap.target));
object.try_emplace("instructionReference", formatted_addr);
auto line_entry = bp_addr.GetLineEntry();
const auto line = line_entry.GetLine();
Expand Down Expand Up @@ -513,7 +513,7 @@ llvm::json::Value CreateModule(lldb::SBModule &module) {
object.try_emplace("symbolStatus", "Symbols not found.");
}
std::string loaded_addr = std::to_string(
module.GetObjectFileHeaderAddress().GetLoadAddress(g_vsc.target));
module.GetObjectFileHeaderAddress().GetLoadAddress(g_dap.target));
object.try_emplace("addressRange", loaded_addr);
std::string version_str;
uint32_t version_nums[3];
Expand Down Expand Up @@ -775,7 +775,7 @@ std::optional<llvm::json::Value> CreateSource(lldb::SBFrame &frame) {
// }
llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
llvm::json::Object object;
int64_t frame_id = MakeVSCodeFrameID(frame);
int64_t frame_id = MakeDAPFrameID(frame);
object.try_emplace("id", frame_id);

// `function_name` can be a nullptr, which throws an error when assigned to an
Expand Down Expand Up @@ -932,7 +932,7 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread &thread,
body.try_emplace("reason", "step");
break;
case lldb::eStopReasonBreakpoint: {
ExceptionBreakpoint *exc_bp = g_vsc.GetExceptionBPFromStopReason(thread);
ExceptionBreakpoint *exc_bp = g_dap.GetExceptionBPFromStopReason(thread);
if (exc_bp) {
body.try_emplace("reason", "exception");
EmplaceSafeString(body, "description", exc_bp->label);
Expand Down Expand Up @@ -990,10 +990,10 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread &thread,
}
}
// "threadCausedFocus" is used in tests to validate breaking behavior.
if (tid == g_vsc.focus_tid) {
if (tid == g_dap.focus_tid) {
body.try_emplace("threadCausedFocus", true);
}
body.try_emplace("preserveFocusHint", tid != g_vsc.focus_tid);
body.try_emplace("preserveFocusHint", tid != g_dap.focus_tid);
body.try_emplace("allThreadsStopped", true);
event.try_emplace("body", std::move(body));
return llvm::json::Value(std::move(event));
Expand Down Expand Up @@ -1119,7 +1119,7 @@ llvm::json::Value CreateVariable(lldb::SBValue v, int64_t variablesReference,
// We create a "[raw]" fake child for each synthetic type, so we have to
// account for it when returning indexed variables. We don't need to do this
// for non-indexed ones.
bool has_raw_child = is_synthetic && g_vsc.enable_synthetic_child_debugging;
bool has_raw_child = is_synthetic && g_dap.enable_synthetic_child_debugging;
int actual_num_children = num_children + (has_raw_child ? 1 : 0);
if (is_array) {
object.try_emplace("indexedVariables", actual_num_children);
Expand Down Expand Up @@ -1170,8 +1170,8 @@ CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request,

auto launch_request_arguments = launch_request.getObject("arguments");
// The program path must be the first entry in the "args" field
std::vector<std::string> args = {
debug_adaptor_path.str(), "--comm-file", comm_file.str()};
std::vector<std::string> args = {debug_adaptor_path.str(), "--comm-file",
comm_file.str()};
if (debugger_pid != LLDB_INVALID_PROCESS_ID) {
args.push_back("--debugger-pid");
args.push_back(std::to_string(debugger_pid));
Expand Down Expand Up @@ -1248,7 +1248,7 @@ void FilterAndGetValueForKey(const lldb::SBStructuredData data, const char *key,
}

void addStatistic(llvm::json::Object &event) {
lldb::SBStructuredData statistics = g_vsc.target.GetStatistics();
lldb::SBStructuredData statistics = g_dap.target.GetStatistics();
bool is_dictionary =
statistics.GetType() == lldb::eStructuredDataTypeDictionary;
if (!is_dictionary)
Expand Down Expand Up @@ -1279,4 +1279,4 @@ std::string JSONToString(const llvm::json::Value &json) {
return data;
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_JSONUTILS_H
#define LLDB_TOOLS_LLDB_VSCODE_JSONUTILS_H
#ifndef LLDB_TOOLS_LLDB_DAP_JSONUTILS_H
#define LLDB_TOOLS_LLDB_DAP_JSONUTILS_H

#include "VSCodeForward.h"
#include "DAPForward.h"
#include "lldb/API/SBModule.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/JSON.h"
#include <cstdint>
#include <optional>

namespace lldb_vscode {
namespace lldb_dap {

/// Emplace a StringRef in a json::Object after enusring that the
/// string is valid UTF8. If not, first call llvm::json::fixUTF8
Expand Down Expand Up @@ -154,7 +154,7 @@ std::vector<std::string> GetStrings(const llvm::json::Object *obj,
/// and "success" set to true.
///
/// \param[in] request
/// The request object received from a call to VSCode::ReadJSON().
/// The request object received from a call to DAP::ReadJSON().
///
/// \param[in,out] response
/// An empty llvm::json::Object object that will be filled
Expand Down Expand Up @@ -214,7 +214,7 @@ void AppendBreakpoint(
std::optional<llvm::StringRef> request_path = std::nullopt,
std::optional<uint32_t> request_line = std::nullopt);

/// Converts breakpoint location to a Visual Studio Code "Breakpoint"
/// Converts breakpoint location to a debug adaptor protocol "Breakpoint".
///
/// \param[in] bp
/// A LLDB breakpoint object to convert into a JSON value
Expand All @@ -233,11 +233,10 @@ void AppendBreakpoint(
/// fallback.
///
/// \param[in] request_column
/// An optional column to use when creating the resulting "Breakpoint" object.
/// It is used if the breakpoint has no valid locations.
/// It is useful to ensure the same column
/// provided by the setBreakpoints request are returned to the IDE as a
/// fallback.
/// An optional column to use when creating the resulting "Breakpoint"
/// object. It is used if the breakpoint has no valid locations. It is
/// useful to ensure the same column provided by the setBreakpoints request
/// are returned to the IDE as a fallback.
///
/// \return
/// A "Breakpoint" JSON object with that follows the formal JSON
Expand Down Expand Up @@ -269,7 +268,7 @@ llvm::json::Value CreateModule(lldb::SBModule &module);
llvm::json::Object CreateEventObject(const llvm::StringRef event_name);

/// Create a "ExceptionBreakpointsFilter" JSON object as described in
/// the Visual Studio Code debug adaptor definition.
/// the debug adaptor definition.
///
/// \param[in] bp
/// The exception breakpoint object to use
Expand All @@ -280,8 +279,7 @@ llvm::json::Object CreateEventObject(const llvm::StringRef event_name);
llvm::json::Value
CreateExceptionBreakpointFilter(const ExceptionBreakpoint &bp);

/// Create a "Scope" JSON object as described in the Visual Studio Code
/// debug adaptor definition.
/// Create a "Scope" JSON object as described in the debug adaptor definition.
///
/// \param[in] name
/// The value to place into the "name" key
Expand All @@ -302,8 +300,7 @@ llvm::json::Value CreateScope(const llvm::StringRef name,
int64_t variablesReference,
int64_t namedVariables, bool expensive);

/// Create a "Source" JSON object as described in the Visual Studio Code
/// debug adaptor definition.
/// Create a "Source" JSON object as described in the debug adaptor definition.
///
/// \param[in] line_entry
/// The LLDB line table to use when populating out the "Source"
Expand All @@ -330,7 +327,7 @@ llvm::json::Value CreateSource(llvm::StringRef source_path);
/// object:
/// "id" - the stack frame ID as an integer
/// "name" - the function name as a string
/// "source" - source file information as a "Source" VSCode object
/// "source" - source file information as a "Source" DAP object
/// "line" - the source file line number as an integer
/// "column" - the source file column number as an integer
///
Expand Down Expand Up @@ -404,7 +401,7 @@ std::string CreateUniqueVariableNameForDisplay(lldb::SBValue v,
/// "value" - the value of the variable as a string
/// "type" - the typename of the variable as a string
/// "id" - a unique identifier for a value in case there are multiple
/// variables with the same name. Other parts of the VSCode
/// variables with the same name. Other parts of the DAP
/// protocol refer to values by name so this can help
/// disambiguate such cases if a IDE passes this "id" value
/// back down.
Expand Down Expand Up @@ -468,7 +465,7 @@ llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit unit);
/// The fifo file used to communicate the with the target launcher.
///
/// \param[in] debugger_pid
/// The PID of the lldb-vscode instance that will attach to the target. The
/// The PID of the lldb-dap instance that will attach to the target. The
/// launcher uses it on Linux tell the kernel that it should allow the
/// debugger process to attach.
///
Expand All @@ -490,6 +487,6 @@ llvm::json::Object CreateTerminatedEventObject();
/// Convert a given JSON object to a string.
std::string JSONToString(const llvm::json::Value &json);

} // namespace lldb_vscode
} // namespace lldb_dap

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
//===----------------------------------------------------------------------===//

#include "LLDBUtils.h"
#include "VSCode.h"
#include "DAP.h"

namespace lldb_vscode {
namespace lldb_dap {

void RunLLDBCommands(llvm::StringRef prefix,
const llvm::ArrayRef<std::string> &commands,
llvm::raw_ostream &strm) {
if (commands.empty())
return;
lldb::SBCommandInterpreter interp = g_vsc.debugger.GetCommandInterpreter();
lldb::SBCommandInterpreter interp = g_dap.debugger.GetCommandInterpreter();
if (!prefix.empty())
strm << prefix << "\n";
for (const auto &command : commands) {
Expand Down Expand Up @@ -78,9 +78,9 @@ uint32_t GetLLDBFrameID(uint64_t dap_frame_id) {
return dap_frame_id & ((1u << THREAD_INDEX_SHIFT) - 1);
}

int64_t MakeVSCodeFrameID(lldb::SBFrame &frame) {
int64_t MakeDAPFrameID(lldb::SBFrame &frame) {
return ((int64_t)frame.GetThread().GetIndexID() << THREAD_INDEX_SHIFT) |
frame.GetFrameID();
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_LLDBUTILS_H
#define LLDB_TOOLS_LLDB_VSCODE_LLDBUTILS_H
#ifndef LLDB_TOOLS_LLDB_DAP_LLDBUTILS_H
#define LLDB_TOOLS_LLDB_DAP_LLDBUTILS_H

#include "VSCodeForward.h"
#include "DAPForward.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
#include <vector>

namespace lldb_vscode {
namespace lldb_dap {

/// Run a list of LLDB commands in the LLDB command interpreter.
///
Expand Down Expand Up @@ -68,7 +68,7 @@ bool ThreadHasStopReason(lldb::SBThread &thread);
/// Given a LLDB frame, make a frame ID that is unique to a specific
/// thread and frame.
///
/// VSCode requires a Stackframe "id" to be unique, so we use the frame
/// DAP requires a Stackframe "id" to be unique, so we use the frame
/// index in the lower 32 bits and the thread index ID in the upper 32
/// bits.
///
Expand All @@ -78,34 +78,34 @@ bool ThreadHasStopReason(lldb::SBThread &thread);
/// \return
/// A unique integer that allows us to easily find the right
/// stack frame within a thread on subsequent VS code requests.
int64_t MakeVSCodeFrameID(lldb::SBFrame &frame);
int64_t MakeDAPFrameID(lldb::SBFrame &frame);

/// Given a VSCode frame ID, convert to a LLDB thread index id.
/// Given a DAP frame ID, convert to a LLDB thread index id.
///
/// VSCode requires a Stackframe "id" to be unique, so we use the frame
/// DAP requires a Stackframe "id" to be unique, so we use the frame
/// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in
/// the upper 32 - THREAD_INDEX_SHIFT bits.
///
/// \param[in] dap_frame_id
/// The VSCode frame ID to convert to a thread index ID.
/// The DAP frame ID to convert to a thread index ID.
///
/// \return
/// The LLDB thread index ID.
uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id);

/// Given a VSCode frame ID, convert to a LLDB frame ID.
/// Given a DAP frame ID, convert to a LLDB frame ID.
///
/// VSCode requires a Stackframe "id" to be unique, so we use the frame
/// DAP requires a Stackframe "id" to be unique, so we use the frame
/// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in
/// the upper 32 - THREAD_INDEX_SHIFT bits.
///
/// \param[in] dap_frame_id
/// The VSCode frame ID to convert to a frame ID.
/// The DAP frame ID to convert to a frame ID.
///
/// \return
/// The LLDB frame index ID.
uint32_t GetLLDBFrameID(uint64_t dap_frame_id);

} // namespace lldb_vscode
} // namespace lldb_dap

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class R<list<string> prefixes, string name>
: Option<prefixes, name, KIND_REMAINING_ARGS>;

def help: F<"help">,
HelpText<"Prints out the usage information for the LLDB VSCode tool.">;
HelpText<"Prints out the usage information for the lldb-dap tool.">;
def: Flag<["-"], "h">,
Alias<help>,
HelpText<"Alias for --help">;
Expand All @@ -19,7 +19,7 @@ def: Flag<["-"], "g">,

def port: S<"port">,
MetaVarName<"<port>">,
HelpText<"Communicate with the lldb-vscode tool over the defined port.">;
HelpText<"Communicate with the lldb-dap tool over the defined port.">;
def: Separate<["-"], "p">,
Alias<port>,
HelpText<"Alias for --port">;
Expand All @@ -37,7 +37,7 @@ def comm_file: S<"comm-file">,

def debugger_pid: S<"debugger-pid">,
MetaVarName<"<pid>">,
HelpText<"The PID of the lldb-vscode instance that sent the launchInTerminal "
HelpText<"The PID of the lldb-dap instance that sent the launchInTerminal "
"request when using --launch-target.">;

def repl_mode: S<"repl-mode">,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using namespace llvm;

namespace lldb_vscode {
namespace lldb_dap {

Error RedirectFd(int fd, std::function<void(llvm::StringRef)> callback) {
int new_fd[2];
Expand Down Expand Up @@ -59,4 +59,4 @@ Error RedirectFd(int fd, std::function<void(llvm::StringRef)> callback) {
return Error::success();
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===/

#ifndef LLDB_TOOLS_LLDB_VSCODE_OUTPUT_REDIRECTOR_H
#define LLDB_TOOLS_LLDB_VSCODE_OUTPUT_REDIRECTOR_H
#ifndef LLDB_TOOLS_LLDB_DAP_OUTPUT_REDIRECTOR_H
#define LLDB_TOOLS_LLDB_DAP_OUTPUT_REDIRECTOR_H

#include <thread>

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"

namespace lldb_vscode {
namespace lldb_dap {

/// Redirects the output of a given file descriptor to a callback.
///
Expand All @@ -23,6 +23,6 @@ namespace lldb_vscode {
/// otherwise.
llvm::Error RedirectFd(int fd, std::function<void(llvm::StringRef)> callback);

} // namespace lldb_vscode
} // namespace lldb_dap

#endif // LLDB_TOOLS_LLDB_VSCODE_OUTPUT_REDIRECTOR_H
#endif // LLDB_TOOLS_LLDB_DAP_OUTPUT_REDIRECTOR_H
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "llvm/Support/ErrorHandling.h"
#include <optional>

using namespace lldb_vscode;
using namespace lldb_dap;
using namespace llvm;

// The minimum duration of an event for it to be reported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
#include <queue>
#include <thread>

#include "VSCodeForward.h"
#include "DAPForward.h"

#include "llvm/Support/JSON.h"

namespace lldb_vscode {
namespace lldb_dap {

enum ProgressEventType {
progressStart,
progressUpdate,
progressEnd
};
enum ProgressEventType { progressStart, progressUpdate, progressEnd };

class ProgressEvent;
using ProgressEventReportCallback = std::function<void(ProgressEvent &)>;
Expand Down Expand Up @@ -157,4 +153,4 @@ class ProgressEventReporter {
std::mutex m_mutex;
};

} // namespace lldb_vscode
} // namespace lldb_dap
77 changes: 39 additions & 38 deletions lldb/tools/lldb-vscode/README.md → lldb/tools/lldb-dap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

# Introduction

The `lldb-vscode` tool creates a command line tool that implements the [Visual
Studio Code Debug API](https://code.visualstudio.com/docs/extensionAPI/api-debugging).
It can be installed as an extension for the Visual Studio Code and Nuclide IDE.
The `lldb-dap` tool (formerly `lldb-vscode`) creates a command line tool that
implements the [Debug Adapter
Protocol](https://microsoft.github.io/debug-adapter-protocol/). It can be
installed as an extension for Visual Studio Code and other IDEs supporting DAP.
The protocol is easy to run remotely and also can allow other tools and IDEs to
get a full featured debugger with a well defined protocol.

Expand All @@ -30,7 +31,7 @@ Installing the plug-in involves creating a directory in any location outside of
`~/.vscode/extensions`. For example, `~/vscode-lldb` is a valid one. You'll also
need a subfolder `bin`, e.g. `~/vscode-lldb/bin`. Then copy the `package.json`
file that is in the same directory as this documentation into it, and symlink
the `lldb-vscode` binary into the `bin` directory inside the plug-in directory.
the `lldb-dap` binary into the `bin` directory inside the plug-in directory.

Finally, on VS Code, execute the command
`Developer: Install Extension from Location` and pick the folder you just
Expand All @@ -40,59 +41,59 @@ If you want to make a stand alone plug-in that you can send to others on UNIX
systems:

```bash
mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
cp package.json ~/llvm-org.lldb-vscode-0.1.0
cd ~/llvm-org.lldb-vscode-0.1.0/bin
cp /path/to/a/built/lldb-vscode .
mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
cp package.json ~/llvm-org.lldb-dap-0.1.0
cd ~/llvm-org.lldb-dap-0.1.0/bin
cp /path/to/a/built/lldb-dap .
cp /path/to/a/built/liblldb.so .
```

If you want to make a stand alone plug-in that you can send to others on macOS
systems:

```bash
mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
cp package.json ~/llvm-org.lldb-vscode-0.1.0
cd ~/llvm-org.lldb-vscode-0.1.0/bin
cp /path/to/a/built/lldb-vscode .
mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
cp package.json ~/llvm-org.lldb-dap-0.1.0
cd ~/llvm-org.lldb-dap-0.1.0/bin
cp /path/to/a/built/lldb-dap .
rsync -av /path/to/a/built/LLDB.framework LLDB.framework
```

You might need to create additional directories for the `liblldb.so` or
`LLDB.framework` inside or next to the `bin` folder depending on how the
[rpath](https://en.wikipedia.org/wiki/Rpath) is set in your `lldb-vscode`
[rpath](https://en.wikipedia.org/wiki/Rpath) is set in your `lldb-dap`
binary. By default the `Debug` builds of LLDB usually includes
the current executable directory in the rpath, so these steps should work for
most people.

To create a plug-in that symlinks into your `lldb-vscode` in your build
To create a plug-in that symlinks into your `lldb-dap` in your build
directory:

```bash
mkdir -p ~/llvm-org.lldb-vscode-0.1.0/bin
cp package.json ~/llvm-org.lldb-vscode-0.1.0
cd ~/llvm-org.lldb-vscode-0.1.0/bin
ln -s /path/to/a/built/lldb-vscode
mkdir -p ~/llvm-org.lldb-dap-0.1.0/bin
cp package.json ~/llvm-org.lldb-dap-0.1.0
cd ~/llvm-org.lldb-dap-0.1.0/bin
ln -s /path/to/a/built/lldb-dap
```

This is handy if you want to debug and develope the `lldb-vscode` executable
This is handy if you want to debug and develop the `lldb-dap` executable
when adding features or fixing bugs.

# Configurations

Launching to attaching require you to create a [launch configuration](https://code.visualstudio.com/Docs/editor/debugging#_launch-configurations). This file
defines arguments that get passed to `lldb-vscode` and the configuration settings
defines arguments that get passed to `lldb-dap` and the configuration settings
control how the launch or attach happens.

## Launch Configuration Settings

When you launch a program with Visual Studio Code you will need to create a [launch.json](https://code.visualstudio.com/Docs/editor/debugging#_launch-configurations)
file that defines how your program will be run. The JSON configuration file can contain the following `lldb-vscode` specific launch key/value pairs:
file that defines how your program will be run. The JSON configuration file can contain the following `lldb-dap` specific launch key/value pairs:

|parameter |type|req | |
|-------------------|----|:--:|---------|
|**name** |string|Y| A configuration name that will be displayed in the IDE.
|**type** |string|Y| Must be "lldb-vscode".
|**type** |string|Y| Must be "lldb-dap".
|**request** |string|Y| Must be "launch".
|**program** |string|Y| Path to the executable to launch.
|**args** |[string]|| An array of command line argument strings to be passed to the program being launched.
Expand All @@ -106,7 +107,7 @@ file that defines how your program will be run. The JSON configuration file can
|**exitCommands** |[string]| | LLDB commands executed when the program exits. Commands and command output will be sent to the debugger console when they are executed.
|**terminateCommands** |[string]| | LLDB commands executed when the debugging session ends. Commands and command output will be sent to the debugger console when they are executed.
|**sourceMap** |[string[2]]| | Specify an array of path re-mappings. Each element in the array must be a two element array containing a source and destination pathname.
|**debuggerRoot** | string| |Specify a working directory to use when launching lldb-vscode. If the debug information in your executable contains relative paths, this option can be used so that `lldb-vscode` can find source files and object files that have relative paths.
|**debuggerRoot** | string| |Specify a working directory to use when launching lldb-dap. If the debug information in your executable contains relative paths, this option can be used so that `lldb-dap` can find source files and object files that have relative paths.

## Attaching Settings

Expand All @@ -116,12 +117,12 @@ When attaching to a process using LLDB you can attach in a few ways
2. Attach to an existing process by name
3. Attach by name by waiting for the next instance of a process to launch

The JSON configuration file can contain the following `lldb-vscode` specific launch key/value pairs:
The JSON configuration file can contain the following `lldb-dap` specific launch key/value pairs:

|parameter |type |req | |
|-------------------|--------|:--:|---------|
|**name** |string |Y| A configuration name that will be displayed in the IDE.
|**type** |string |Y| Must be "lldb-vscode".
|**type** |string |Y| Must be "lldb-dap".
|**request** |string |Y| Must be "attach".
|**program** |string | | Path to the executable to attach to. This value is optional but can help to resolve breakpoints prior the attaching to the program.
|**pid** |number | | The process id of the process you wish to attach to. If **pid** is omitted, the debugger will attempt to attach to the program by finding a process whose file name matches the file name from **porgram**. Setting this value to `${command:pickMyProcess}` will allow interactive process selection in the IDE.
Expand All @@ -143,7 +144,7 @@ adds `FOO=1` and `bar` to the environment:

```javascript
{
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "launch",
"name": "Debug",
"program": "/tmp/a.out",
Expand All @@ -158,7 +159,7 @@ This will attach to a process `a.out` whose process ID is 123:

```javascript
{
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "attach",
"name": "Attach to PID",
"program": "/tmp/a.out",
Expand All @@ -175,7 +176,7 @@ above configuration:
```javascript
{
"name": "Attach to Name",
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "attach",
"program": "/tmp/a.out",
}
Expand All @@ -187,7 +188,7 @@ to be launched you can add the "waitFor" key value pair:
```javascript
{
"name": "Attach to Name (wait)",
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "attach",
"program": "/tmp/a.out",
"waitFor": true
Expand All @@ -205,7 +206,7 @@ This loads the coredump file `/cores/123.core` associated with the program
```javascript
{
"name": "Load coredump",
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "attach",
"coreFile": "/cores/123.core",
"program": "/tmp/a.out"
Expand All @@ -221,7 +222,7 @@ locally on port `2345`.
```javascript
{
"name": "Local Debug Server",
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "attach",
"program": "/tmp/a.out",
"attachCommands": ["gdb-remote 2345"],
Expand All @@ -237,7 +238,7 @@ port `5678` of that other machine.
```javascript
{
"name": "Remote Debug Server",
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "attach",
"program": "/tmp/a.out",
"attachCommands": ["gdb-remote hostname:5678"],
Expand All @@ -246,12 +247,12 @@ port `5678` of that other machine.

# Custom debugger commands

The `lldb-vscode` tool includes additional custom commands to support the Debug
The `lldb-dap` tool includes additional custom commands to support the Debug
Adapter Protocol features.

## startDebugging

Using the command `lldb-vscode startDebugging` it is possible to trigger a
Using the command `lldb-dap startDebugging` it is possible to trigger a
reverse request to the client requesting a child debug session with the
specified configuration. For example, this can be used to attached to forked or
spawned processes. For more information see
Expand All @@ -260,7 +261,7 @@ spawned processes. For more information see
The custom command has the following format:

```
lldb-vscode startDebugging <launch|attach> <configuration>
lldb-dap startDebugging <launch|attach> <configuration>
```

This will launch a server and then request a child debug session for a client.
Expand All @@ -269,14 +270,14 @@ This will launch a server and then request a child debug session for a client.
{
"program": "server",
"postRunCommand": [
"lldb-vscode startDebugging launch '{\"program\":\"client\"}'"
"lldb-dap startDebugging launch '{\"program\":\"client\"}'"
]
}
```

## repl-mode

Inspect or adjust the behavior of lldb-vscode repl evaluation requests. The
Inspect or adjust the behavior of lldb-dap repl evaluation requests. The
supported modes are `variable`, `command` and `auto`.

- `variable` - Variable mode expressions are evaluated in the context of the
Expand All @@ -291,4 +292,4 @@ supported modes are `variable`, `command` and `auto`.

The initial repl-mode can be configured with the cli flag `--repl-mode=<mode>`
and may also be adjusted at runtime using the lldb command
`lldb-vscode repl-mode <mode>`.
`lldb-dap repl-mode <mode>`.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

using namespace llvm;

namespace lldb_vscode {
namespace lldb_dap {

const RunInTerminalMessagePid *RunInTerminalMessage::GetAsPidMessage() const {
return static_cast<const RunInTerminalMessagePid *>(this);
Expand Down Expand Up @@ -163,11 +163,11 @@ std::string RunInTerminalDebugAdapterCommChannel::GetLauncherError() {
Expected<std::shared_ptr<FifoFile>> CreateRunInTerminalCommFile() {
SmallString<256> comm_file;
if (std::error_code EC = sys::fs::getPotentiallyUniqueTempFileName(
"lldb-vscode-run-in-terminal-comm", "", comm_file))
"lldb-dap-run-in-terminal-comm", "", comm_file))
return createStringError(EC, "Error making unique file name for "
"runInTerminal communication files");

return CreateFifoFile(comm_file.str());
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_RUNINTERMINAL_H
#define LLDB_TOOLS_LLDB_VSCODE_RUNINTERMINAL_H
#ifndef LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H
#define LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H

#include "FifoFiles.h"

#include <future>
#include <thread>

namespace lldb_vscode {
namespace lldb_dap {

enum RunInTerminalMessageKind {
eRunInTerminalMessageKindPID = 0,
Expand Down Expand Up @@ -124,6 +124,6 @@ class RunInTerminalDebugAdapterCommChannel {
/// the runInTerminal launcher.
llvm::Expected<std::shared_ptr<FifoFile>> CreateRunInTerminalCommFile();

} // namespace lldb_vscode
} // namespace lldb_dap

#endif // LLDB_TOOLS_LLDB_VSCODE_RUNINTERMINAL_H
#endif // LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
//===----------------------------------------------------------------------===//

#include "SourceBreakpoint.h"
#include "VSCode.h"
#include "DAP.h"

namespace lldb_vscode {
namespace lldb_dap {

SourceBreakpoint::SourceBreakpoint(const llvm::json::Object &obj)
: BreakpointBase(obj), line(GetUnsigned(obj, "line", 0)),
column(GetUnsigned(obj, "column", 0)) {}

void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) {
lldb::SBFileSpecList module_list;
bp = g_vsc.target.BreakpointCreateByLocation(source_path.str().c_str(), line,
bp = g_dap.target.BreakpointCreateByLocation(source_path.str().c_str(), line,
column, 0, module_list);
// See comments in BreakpointBase::GetBreakpointLabel() for details of why
// we add a label to our breakpoints.
Expand All @@ -30,4 +30,4 @@ void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) {
SetLogMessage();
}

} // namespace lldb_vscode
} // namespace lldb_dap
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_TOOLS_LLDB_VSCODE_SOURCEBREAKPOINT_H
#define LLDB_TOOLS_LLDB_VSCODE_SOURCEBREAKPOINT_H
#ifndef LLDB_TOOLS_LLDB_DAP_SOURCEBREAKPOINT_H
#define LLDB_TOOLS_LLDB_DAP_SOURCEBREAKPOINT_H

#include "BreakpointBase.h"
#include "llvm/ADT/StringRef.h"

namespace lldb_vscode {
namespace lldb_dap {

struct SourceBreakpoint : public BreakpointBase {

Expand All @@ -33,6 +33,6 @@ inline bool operator<(const SourceBreakpoint &lhs,
return lhs.line < rhs.line;
}

} // namespace lldb_vscode
} // namespace lldb_dap

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.lldb-vscode</string>
<string>com.apple.lldb-dap</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>lldb-vscode</string>
<string>lldb-dap</string>
<key>CFBundleVersion</key>
<string>${LLDB_VERSION}</string>
<key>SecTaskAccess</key>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "lldb-vscode",
"name": "lldb-dap",
"displayName": "LLDB VSCode",
"version": "0.1.0",
"publisher": "llvm",
Expand Down Expand Up @@ -103,7 +103,7 @@
],
"debuggers": [
{
"type": "lldb-vscode",
"type": "lldb-dap",
"label": "Native LLDB Debugger",
"enableBreakpointsFor": {
"languageIds": [
Expand All @@ -124,9 +124,9 @@
"swift"
]
},
"program": "./bin/lldb-vscode",
"program": "./bin/lldb-dap",
"windows": {
"program": "./bin/lldb-vscode.exe"
"program": "./bin/lldb-dap.exe"
},
"configurationAttributes": {
"launch": {
Expand Down Expand Up @@ -219,7 +219,7 @@
},
"launchCommands": {
"type": "array",
"description": "Custom commands that are executed instead of launching a process. A target will be created with the launch arguments prior to executing these commands. The commands may optionally create a new target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail. Launch the process with \"process launch -s\" to make the process to at the entry point since lldb-vscode will auto resume if necessary.",
"description": "Custom commands that are executed instead of launching a process. A target will be created with the launch arguments prior to executing these commands. The commands may optionally create a new target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail. Launch the process with \"process launch -s\" to make the process to at the entry point since lldb-dap will auto resume if necessary.",
"default": []
},
"stopCommands": {
Expand Down Expand Up @@ -345,7 +345,7 @@
},
"initialConfigurations": [
{
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "launch",
"name": "Debug",
"program": "${workspaceRoot}/<your program>",
Expand All @@ -359,7 +359,7 @@
"label": "LLDB: Launch",
"description": "",
"body": {
"type": "lldb-vscode",
"type": "lldb-dap",
"request": "launch",
"name": "${2:Launch}",
"program": "^\"\\${workspaceRoot}/${1:<your program>}\"",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions lldb/tools/lldb-vscode
3 changes: 3 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ Changes to LLDB
for formatters to quickly find directly nested type when it's known
where to search for it, avoiding more expensive global search via
``SBTarget::FindFirstType``.
* ``lldb-vscode`` was renamed to ``lldb-dap`` and and its installation
instructions have been updated to reflect this. The underlying functionality
remains unchanged.

Changes to Sanitizers
---------------------
Expand Down