//
//===----------------------------------------------------------------------===//
-#include <stdarg.h>
#include <fstream>
#include <mutex>
+#include <stdarg.h>
#include "LLDBUtils.h"
#include "VSCode.h"
#if defined(_WIN32)
#define NOMINMAX
-#include <windows.h>
#include <fcntl.h>
#include <io.h>
+#include <windows.h>
#endif
using namespace lldb_vscode;
stop_at_entry(false), is_attach(false) {
const char *log_file_path = getenv("LLDBVSCODE_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
-// fixes this.
+ // 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
+ // fixes this.
int result = _setmode(fileno(stdout), _O_BINARY);
assert(result);
result = _setmode(fileno(stdin), _O_BINARY);
log.reset(new std::ofstream(log_file_path));
}
-VSCode::~VSCode() {
-}
+VSCode::~VSCode() {}
int64_t VSCode::GetLineForPC(int64_t sourceReference, lldb::addr_t pc) const {
auto pos = source_map.find(sourceReference);
va_start(args, format);
int actual_length = vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
- SendOutput(o, llvm::StringRef(buffer,
- std::min<int>(actual_length, sizeof(buffer))));
+ SendOutput(
+ o, llvm::StringRef(buffer, std::min<int>(actual_length, sizeof(buffer))));
}
int64_t VSCode::GetNextSourceReference() {
RunLLDBCommands("Running terminateCommands:", terminate_commands);
}
-lldb::SBTarget VSCode::CreateTargetFromArguments(
- const llvm::json::Object &arguments,
- lldb::SBError &error) {
+lldb::SBTarget
+VSCode::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
llvm::StringRef platform_name = GetString(arguments, "platformName");
llvm::StringRef program = GetString(arguments, "program");
auto target = this->debugger.CreateTarget(
- program.data(),
- target_triple.data(),
- platform_name.data(),
- true, // Add dependent modules.
- error
- );
+ program.data(), target_triple.data(), platform_name.data(),
+ true, // Add dependent modules.
+ error);
if (error.Fail()) {
// Update message if there was an error.
error.SetErrorStringWithFormat(
- "Could not create a target for a program '%s': %s.",
- program.data(), error.GetCString());
+ "Could not create a target for a program '%s': %s.", program.data(),
+ error.GetCString());
}
return target;
listener.StartListeningForEvents(this->broadcaster,
eBroadcastBitStopEventThread);
listener.StartListeningForEvents(
- this->target.GetBroadcaster(),
- lldb::SBTarget::eBroadcastBitModulesLoaded |
- lldb::SBTarget::eBroadcastBitModulesUnloaded |
- lldb::SBTarget::eBroadcastBitSymbolsLoaded);
+ this->target.GetBroadcaster(),
+ lldb::SBTarget::eBroadcastBitModulesLoaded |
+ lldb::SBTarget::eBroadcastBitModulesUnloaded |
+ lldb::SBTarget::eBroadcastBitSymbolsLoaded);
}
}
char buffer[1024];
size_t count;
while ((count = process.GetSTDOUT(buffer, sizeof(buffer))) > 0)
- g_vsc.SendOutput(OutputType::Stdout, llvm::StringRef(buffer, count));
+ g_vsc.SendOutput(OutputType::Stdout, llvm::StringRef(buffer, count));
while ((count = process.GetSTDERR(buffer, sizeof(buffer))) > 0)
g_vsc.SendOutput(OutputType::Stderr, llvm::StringRef(buffer, count));
}
if (event_mask & lldb::SBTarget::eBroadcastBitModulesLoaded) {
body.try_emplace("reason", "new");
} else if (event_mask &
- lldb::SBTarget::eBroadcastBitModulesUnloaded) {
+ lldb::SBTarget::eBroadcastBitModulesUnloaded) {
body.try_emplace("reason", "removed");
} else if (event_mask &
- lldb::SBTarget::eBroadcastBitSymbolsLoaded) {
+ lldb::SBTarget::eBroadcastBitSymbolsLoaded) {
body.try_emplace("reason", "changed");
}
body.try_emplace("module", module_value);
// "CompletionsRequest": {
// "allOf": [ { "$ref": "#/definitions/Request" }, {
// "type": "object",
-// "description": "Returns a list of possible completions for a given caret position and text.\nThe CompletionsRequest may only be called if the 'supportsCompletionsRequest' capability exists and is true.",
+// "description": "Returns a list of possible completions for a given caret
+// position and text.\nThe CompletionsRequest may only be called if the
+// 'supportsCompletionsRequest' capability exists and is true.",
// "properties": {
// "command": {
// "type": "string",
// "properties": {
// "frameId": {
// "type": "integer",
-// "description": "Returns completions in the scope of this stack frame. If not specified, the completions are returned for the global scope."
+// "description": "Returns completions in the scope of this stack frame.
+// If not specified, the completions are returned for the global scope."
// },
// "text": {
// "type": "string",
-// "description": "One or more source lines. Typically this is the text a user has typed into the debug console before he asked for completion."
+// "description": "One or more source lines. Typically this is the text a
+// user has typed into the debug console before he asked for completion."
// },
// "column": {
// "type": "integer",
-// "description": "The character position for which to determine the completion proposals."
+// "description": "The character position for which to determine the
+// completion proposals."
// },
// "line": {
// "type": "integer",
-// "description": "An optional line for which to determine the completion proposals. If missing the first line of the text is assumed."
+// "description": "An optional line for which to determine the completion
+// proposals. If missing the first line of the text is assumed."
// }
// },
// "required": [ "text", "column" ]
// },
// "CompletionItem": {
// "type": "object",
-// "description": "CompletionItems are the suggestions returned from the CompletionsRequest.",
-// "properties": {
+// "description": "CompletionItems are the suggestions returned from the
+// CompletionsRequest.", "properties": {
// "label": {
// "type": "string",
-// "description": "The label of this completion item. By default this is also the text that is inserted when selecting this completion."
+// "description": "The label of this completion item. By default this is
+// also the text that is inserted when selecting this completion."
// },
// "text": {
// "type": "string",
-// "description": "If text is not falsy then it is inserted instead of the label."
+// "description": "If text is not falsy then it is inserted instead of the
+// label."
// },
// "sortText": {
// "type": "string",
-// "description": "A string that should be used when comparing this item with other items. When `falsy` the label is used."
+// "description": "A string that should be used when comparing this item
+// with other items. When `falsy` the label is used."
// },
// "type": {
// "$ref": "#/definitions/CompletionItemType",
-// "description": "The item's type. Typically the client uses this information to render the item in the UI with an icon."
+// "description": "The item's type. Typically the client uses this
+// information to render the item in the UI with an icon."
// },
// "start": {
// "type": "integer",
-// "description": "This value determines the location (in the CompletionsRequest's 'text' attribute) where the completion text is added.\nIf missing the text is added at the location specified by the CompletionsRequest's 'column' attribute."
+// "description": "This value determines the location (in the
+// CompletionsRequest's 'text' attribute) where the completion text is
+// added.\nIf missing the text is added at the location specified by the
+// CompletionsRequest's 'column' attribute."
// },
// "length": {
// "type": "integer",
-// "description": "This value determines how many characters are overwritten by the completion text.\nIf missing the value 0 is assumed which results in the completion text being inserted."
+// "description": "This value determines how many characters are
+// overwritten by the completion text.\nIf missing the value 0 is assumed
+// which results in the completion text being inserted."
// }
// },
// "required": [ "label" ]
// },
// "CompletionItemType": {
// "type": "string",
-// "description": "Some predefined types for the CompletionItem. Please note that not all clients have specific icons for all of them.",
-// "enum": [ "method", "function", "constructor", "field", "variable", "class", "interface", "module", "property", "unit", "value", "enum", "keyword", "snippet", "text", "color", "file", "reference", "customcolor" ]
+// "description": "Some predefined types for the CompletionItem. Please note
+// that not all clients have specific icons for all of them.", "enum": [
+// "method", "function", "constructor", "field", "variable", "class",
+// "interface", "module", "property", "unit", "value", "enum", "keyword",
+// "snippet", "text", "color", "file", "reference", "customcolor" ]
// }
void request_completions(const llvm::json::Object &request) {
llvm::json::Object response;
lldb::SBStringList matches;
lldb::SBStringList descriptions;
g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
- text.c_str(),
- actual_column,
- 0, -1, matches, descriptions);
+ text.c_str(), actual_column, 0, -1, matches, descriptions);
size_t count = std::min((uint32_t)100, matches.GetSize());
targets.reserve(count);
for (size_t i = 0; i < count; i++) {
llvm::json::Object item;
llvm::StringRef match_ref = match;
- for(llvm::StringRef commit_point: {".", "->"}) {
- if (match_ref.contains(commit_point)){
+ for (llvm::StringRef commit_point : {".", "->"}) {
+ if (match_ref.contains(commit_point)) {
match_ref = match_ref.rsplit(commit_point).second;
}
}
} else {
SetValueForKey(value, body, "result");
auto value_typename = value.GetType().GetDisplayTypeName();
- EmplaceSafeString(body, "type", value_typename ? value_typename : NO_TYPENAME);
+ EmplaceSafeString(body, "type",
+ value_typename ? value_typename : NO_TYPENAME);
if (value.MightHaveChildren()) {
auto variablesReference = VARIDX_TO_VARREF(g_vsc.variables.GetSize());
g_vsc.variables.Append(value);
if (module_id == curr_module.GetUUIDString()) {
int num_units = curr_module.GetNumCompileUnits();
for (int j = 0; j < num_units; j++) {
- auto curr_unit = curr_module.GetCompileUnitAtIndex(j);\
- units.emplace_back(CreateCompileUnit(curr_unit));\
+ auto curr_unit = curr_module.GetCompileUnitAtIndex(j);
+ units.emplace_back(CreateCompileUnit(curr_unit));
}
body.try_emplace("compileUnits", std::move(units));
break;
// Disable any function breakpoints that aren't in the request_bps.
// There is no call to remove function breakpoints other than calling this
// function with a smaller or empty "breakpoints" list.
- for (auto &pair: g_vsc.function_breakpoints) {
+ for (auto &pair : g_vsc.function_breakpoints) {
auto request_pos = request_bps.find(pair.first());
if (request_pos == request_bps.end()) {
// This function breakpoint no longer exists delete it from LLDB
}
}
// Remove any breakpoints that are no longer in our list
- for (const auto &name: remove_names)
+ for (const auto &name : remove_names)
g_vsc.function_breakpoints.erase(name);
// Any breakpoints that are left in "request_bps" are breakpoints that
handler_pos->second(*object);
} else {
if (g_vsc.log)
- *g_vsc.log << "error: unhandled command \"" << command.data() << std::endl;
+ *g_vsc.log << "error: unhandled command \"" << command.data()
+ << std::endl;
return 1;
}
}