Skip to content

Commit 5c463d1

Browse files
author
Walter Erquinigo
committed
Revert "Retry of D84974"
This reverts commit 5b2b4f3. This caused a link error in http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/18794/steps/build/logs/stdio
1 parent 041da0d commit 5c463d1

File tree

11 files changed

+82
-363
lines changed

11 files changed

+82
-363
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def launch(self, program=None, args=None, cwd=None, env=None,
282282
trace=False, initCommands=None, preRunCommands=None,
283283
stopCommands=None, exitCommands=None, terminateCommands=None,
284284
sourcePath=None, debuggerRoot=None, launchCommands=None,
285-
sourceMap=None, disconnectAutomatically=True, runInTerminal=False):
285+
sourceMap=None, disconnectAutomatically=True):
286286
'''Sending launch request to vscode
287287
'''
288288

@@ -316,24 +316,18 @@ def cleanup():
316316
sourcePath=sourcePath,
317317
debuggerRoot=debuggerRoot,
318318
launchCommands=launchCommands,
319-
sourceMap=sourceMap,
320-
runInTerminal=runInTerminal)
319+
sourceMap=sourceMap)
321320
if not (response and response['success']):
322321
self.assertTrue(response['success'],
323322
'launch failed (%s)' % (response['message']))
324-
# We need to trigger a request_configurationDone after we've successfully
325-
# attached a runInTerminal process to finish initialization.
326-
if runInTerminal:
327-
self.vscode.request_configurationDone()
328-
329323

330324
def build_and_launch(self, program, args=None, cwd=None, env=None,
331325
stopOnEntry=False, disableASLR=True,
332326
disableSTDIO=False, shellExpandArguments=False,
333327
trace=False, initCommands=None, preRunCommands=None,
334328
stopCommands=None, exitCommands=None,
335329
terminateCommands=None, sourcePath=None,
336-
debuggerRoot=None, runInTerminal=False):
330+
debuggerRoot=None):
337331
'''Build the default Makefile target, create the VSCode debug adaptor,
338332
and launch the process.
339333
'''
@@ -343,4 +337,4 @@ def build_and_launch(self, program, args=None, cwd=None, env=None,
343337
self.launch(program, args, cwd, env, stopOnEntry, disableASLR,
344338
disableSTDIO, shellExpandArguments, trace,
345339
initCommands, preRunCommands, stopCommands, exitCommands,
346-
terminateCommands, sourcePath, debuggerRoot, runInTerminal=runInTerminal)
340+
terminateCommands, sourcePath, debuggerRoot)

lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py

+5-25
Original file line numberDiff line numberDiff line change
@@ -300,29 +300,12 @@ def send_recv(self, command):
300300
self.send_packet(command)
301301
done = False
302302
while not done:
303-
response_or_request = self.recv_packet(filter_type=['response', 'request'])
304-
if response_or_request is None:
303+
response = self.recv_packet(filter_type='response')
304+
if response is None:
305305
desc = 'no response for "%s"' % (command['command'])
306306
raise ValueError(desc)
307-
if response_or_request['type'] == 'response':
308-
self.validate_response(command, response_or_request)
309-
return response_or_request
310-
else:
311-
if response_or_request['command'] == 'runInTerminal':
312-
subprocess.Popen(response_or_request['arguments']['args'],
313-
env=response_or_request['arguments']['env'])
314-
self.send_packet({
315-
"type": "response",
316-
"seq": -1,
317-
"request_seq": response_or_request['seq'],
318-
"success": True,
319-
"command": "runInTerminal",
320-
"body": {}
321-
}, set_sequence=False)
322-
else:
323-
desc = 'unkonwn reverse request "%s"' % (response_or_request['command'])
324-
raise ValueError(desc)
325-
307+
self.validate_response(command, response)
308+
return response
326309
return None
327310

328311
def wait_for_event(self, filter=None, timeout=None):
@@ -616,8 +599,7 @@ def request_launch(self, program, args=None, cwd=None, env=None,
616599
trace=False, initCommands=None, preRunCommands=None,
617600
stopCommands=None, exitCommands=None,
618601
terminateCommands=None ,sourcePath=None,
619-
debuggerRoot=None, launchCommands=None, sourceMap=None,
620-
runInTerminal=False):
602+
debuggerRoot=None, launchCommands=None, sourceMap=None):
621603
args_dict = {
622604
'program': program
623605
}
@@ -656,8 +638,6 @@ def request_launch(self, program, args=None, cwd=None, env=None,
656638
args_dict['launchCommands'] = launchCommands
657639
if sourceMap:
658640
args_dict['sourceMap'] = sourceMap
659-
if runInTerminal:
660-
args_dict['runInTerminal'] = runInTerminal
661641
command_dict = {
662642
'command': 'launch',
663643
'type': 'request',

lldb/test/API/tools/lldb-vscode/runInTerminal/Makefile

-3
This file was deleted.

lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py

-48
This file was deleted.

lldb/test/API/tools/lldb-vscode/runInTerminal/main.c

-11
This file was deleted.

lldb/tools/lldb-vscode/JSONUtils.cpp

-40
Original file line numberDiff line numberDiff line change
@@ -998,44 +998,4 @@ llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit unit) {
998998
return llvm::json::Value(std::move(object));
999999
}
10001000

1001-
/// See
1002-
/// https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_RunInTerminal
1003-
llvm::json::Object
1004-
CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request) {
1005-
llvm::json::Object reverse_request;
1006-
reverse_request.try_emplace("type", "request");
1007-
reverse_request.try_emplace("command", "runInTerminal");
1008-
1009-
llvm::json::Object run_in_terminal_args;
1010-
// This indicates the IDE to open an embedded terminal, instead of opening the
1011-
// terminal in a new window.
1012-
run_in_terminal_args.try_emplace("kind", "integrated");
1013-
1014-
auto launch_request_arguments = launch_request.getObject("arguments");
1015-
std::vector<std::string> args = GetStrings(launch_request_arguments, "args");
1016-
// The program path must be the first entry in the "args" field
1017-
args.insert(args.begin(),
1018-
GetString(launch_request_arguments, "program").str());
1019-
run_in_terminal_args.try_emplace("args", args);
1020-
1021-
const auto cwd = GetString(launch_request_arguments, "cwd");
1022-
if (!cwd.empty())
1023-
run_in_terminal_args.try_emplace("cwd", cwd);
1024-
1025-
// We need to convert the input list of environments variables into a
1026-
// dictionary
1027-
std::vector<std::string> envs = GetStrings(launch_request_arguments, "env");
1028-
llvm::json::Object environment;
1029-
for (const std::string &env : envs) {
1030-
size_t index = env.find("=");
1031-
environment.try_emplace(env.substr(0, index), env.substr(index + 1));
1032-
}
1033-
run_in_terminal_args.try_emplace("env",
1034-
llvm::json::Value(std::move(environment)));
1035-
1036-
reverse_request.try_emplace(
1037-
"arguments", llvm::json::Value(std::move(run_in_terminal_args)));
1038-
return reverse_request;
1039-
}
1040-
10411001
} // namespace lldb_vscode

lldb/tools/lldb-vscode/JSONUtils.h

-12
Original file line numberDiff line numberDiff line change
@@ -443,18 +443,6 @@ llvm::json::Value CreateVariable(lldb::SBValue v, int64_t variablesReference,
443443

444444
llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit unit);
445445

446-
/// Create a runInTerminal reverse request object
447-
///
448-
/// \param[in] launch_request
449-
/// The original launch_request object whose fields are used to construct
450-
/// the reverse request object.
451-
///
452-
/// \return
453-
/// A "runInTerminal" JSON object that follows the specification outlined by
454-
/// Microsoft.
455-
llvm::json::Object
456-
CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request);
457-
458446
} // namespace lldb_vscode
459447

460448
#endif

lldb/tools/lldb-vscode/VSCode.cpp

+1-69
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ VSCode::VSCode()
3838
{"swift_catch", "Swift Catch", lldb::eLanguageTypeSwift},
3939
{"swift_throw", "Swift Throw", lldb::eLanguageTypeSwift}}),
4040
focus_tid(LLDB_INVALID_THREAD_ID), sent_terminated_event(false),
41-
stop_at_entry(false), is_attach(false),
42-
reverse_request_seq(0), waiting_for_run_in_terminal(false) {
41+
stop_at_entry(false), is_attach(false) {
4342
const char *log_file_path = getenv("LLDBVSCODE_LOG");
4443
#if defined(_WIN32)
4544
// Windows opens stdout and stdin in text mode which converts \n to 13,10
@@ -363,71 +362,4 @@ void VSCode::SetTarget(const lldb::SBTarget target) {
363362
}
364363
}
365364

366-
PacketStatus VSCode::GetObject(llvm::json::Object &object) {
367-
std::string json = ReadJSON();
368-
if (json.empty())
369-
return PacketStatus::EndOfFile;
370-
371-
llvm::StringRef json_sref(json);
372-
llvm::Expected<llvm::json::Value> json_value = llvm::json::parse(json_sref);
373-
if (!json_value) {
374-
auto error = json_value.takeError();
375-
if (log) {
376-
std::string error_str;
377-
llvm::raw_string_ostream strm(error_str);
378-
strm << error;
379-
strm.flush();
380-
*log << "error: failed to parse JSON: " << error_str << std::endl
381-
<< json << std::endl;
382-
}
383-
return PacketStatus::JSONMalformed;
384-
}
385-
object = *json_value->getAsObject();
386-
if (!json_value->getAsObject()) {
387-
if (log)
388-
*log << "error: json packet isn't a object" << std::endl;
389-
return PacketStatus::JSONNotObject;
390-
}
391-
return PacketStatus::Success;
392-
}
393-
394-
bool VSCode::HandleObject(const llvm::json::Object &object) {
395-
const auto packet_type = GetString(object, "type");
396-
if (packet_type == "request") {
397-
const auto command = GetString(object, "command");
398-
auto handler_pos = request_handlers.find(std::string(command));
399-
if (handler_pos != request_handlers.end()) {
400-
handler_pos->second(object);
401-
return true; // Success
402-
} else {
403-
if (log)
404-
*log << "error: unhandled command \"" << command.data() << std::endl;
405-
return false; // Fail
406-
}
407-
}
408-
return false;
409-
}
410-
411-
PacketStatus VSCode::SendReverseRequest(llvm::json::Object request,
412-
llvm::json::Object &response) {
413-
request.try_emplace("seq", ++reverse_request_seq);
414-
SendJSON(llvm::json::Value(std::move(request)));
415-
while (true) {
416-
PacketStatus status = GetObject(response);
417-
const auto packet_type = GetString(response, "type");
418-
if (packet_type == "response")
419-
return status;
420-
else {
421-
// Not our response, we got another packet
422-
HandleObject(response);
423-
}
424-
}
425-
return PacketStatus::EndOfFile;
426-
}
427-
428-
void VSCode::RegisterRequestCallback(std::string request,
429-
RequestCallback callback) {
430-
request_handlers[request] = callback;
431-
}
432-
433365
} // namespace lldb_vscode

lldb/tools/lldb-vscode/VSCode.h

-45
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLDB_TOOLS_LLDB_VSCODE_VSCODE_H
1010
#define LLDB_TOOLS_LLDB_VSCODE_VSCODE_H
1111

12-
#include <condition_variable>
1312
#include <iosfwd>
1413
#include <map>
1514
#include <set>
@@ -20,7 +19,6 @@
2019
#include "llvm/ADT/DenseSet.h"
2120
#include "llvm/ADT/StringMap.h"
2221
#include "llvm/ADT/StringRef.h"
23-
#include "llvm/Support/JSON.h"
2422
#include "llvm/Support/raw_ostream.h"
2523

2624
#include "lldb/API/SBAttachInfo.h"
@@ -67,15 +65,6 @@ enum class OutputType { Console, Stdout, Stderr, Telemetry };
6765

6866
enum VSCodeBroadcasterBits { eBroadcastBitStopEventThread = 1u << 0 };
6967

70-
typedef void (*RequestCallback)(const llvm::json::Object &command);
71-
72-
enum class PacketStatus {
73-
Success = 0,
74-
EndOfFile,
75-
JSONMalformed,
76-
JSONNotObject
77-
};
78-
7968
struct VSCode {
8069
InputStream input;
8170
OutputStream output;
@@ -102,10 +91,6 @@ struct VSCode {
10291
bool sent_terminated_event;
10392
bool stop_at_entry;
10493
bool is_attach;
105-
uint32_t reverse_request_seq;
106-
std::map<std::string, RequestCallback> request_handlers;
107-
std::condition_variable request_in_terminal_cv;
108-
bool waiting_for_run_in_terminal;
10994
// Keep track of the last stop thread index IDs as threads won't go away
11095
// unless we send a "thread" event to indicate the thread exited.
11196
llvm::DenseSet<lldb::tid_t> thread_ids;
@@ -167,36 +152,6 @@ struct VSCode {
167152
/// Set given target object as a current target for lldb-vscode and start
168153
/// listeing for its breakpoint events.
169154
void SetTarget(const lldb::SBTarget target);
170-
171-
const std::map<std::string, RequestCallback> &GetRequestHandlers();
172-
173-
PacketStatus GetObject(llvm::json::Object &object);
174-
bool HandleObject(const llvm::json::Object &object);
175-
176-
/// Send a Debug Adapter Protocol reverse request to the IDE
177-
///
178-
/// \param[in] request
179-
/// The payload of the request to send.
180-
///
181-
/// \param[out] response
182-
/// The response of the IDE. It might be undefined if there was an error.
183-
///
184-
/// \return
185-
/// A \a PacketStatus object indicating the sucess or failure of the
186-
/// request.
187-
PacketStatus SendReverseRequest(llvm::json::Object request,
188-
llvm::json::Object &response);
189-
190-
/// Registers a callback handler for a Debug Adapter Protocol request
191-
///
192-
/// \param[in] request
193-
/// The name of the request following the Debug Adapter Protocol
194-
/// specification.
195-
///
196-
/// \param[in] callback
197-
/// The callback to execute when the given request is triggered by the
198-
/// IDE.
199-
void RegisterRequestCallback(std::string request, RequestCallback callback);
200155
};
201156

202157
extern VSCode g_vsc;

0 commit comments

Comments
 (0)