[Lldb-commits] [lldb] [lldb-dap] Change the launch sequence (PR #138219)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri May 2 15:59:10 PDT 2025
================
@@ -137,55 +137,69 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
dap.SendOutput(OutputType::Console,
llvm::StringRef(attach_msg, attach_msg_len));
}
- if (attachCommands.empty()) {
- // No "attachCommands", just attach normally.
- // Disable async events so the attach will be successful when we return from
- // the launch call and the launch will happen synchronously
+ {
+ // Perform the launch in synchronous mode so that we don't have to worry
+ // about process state changes during the launch.
ScopeSyncMode scope_sync_mode(dap.debugger);
-
- if (core_file.empty()) {
- if ((pid != LLDB_INVALID_PROCESS_ID) &&
- (gdb_remote_port != invalid_port)) {
- // If both pid and port numbers are specified.
- error.SetErrorString("The user can't specify both pid and port");
- } else if (gdb_remote_port != invalid_port) {
- // If port is specified and pid is not.
- lldb::SBListener listener = dap.debugger.GetListener();
-
- // If the user hasn't provided the hostname property, default localhost
- // being used.
- std::string connect_url =
- llvm::formatv("connect://{0}:", gdb_remote_hostname);
- connect_url += std::to_string(gdb_remote_port);
- dap.target.ConnectRemote(listener, connect_url.c_str(), "gdb-remote",
- error);
+ if (attachCommands.empty()) {
+ // No "attachCommands", just attach normally.
+ if (core_file.empty()) {
+ if ((pid != LLDB_INVALID_PROCESS_ID) &&
+ (gdb_remote_port != invalid_port)) {
+ // If both pid and port numbers are specified.
+ error.SetErrorString("The user can't specify both pid and port");
+ } else if (gdb_remote_port != invalid_port) {
+ // If port is specified and pid is not.
+ lldb::SBListener listener = dap.debugger.GetListener();
+
+ // If the user hasn't provided the hostname property, default
+ // localhost being used.
+ std::string connect_url =
+ llvm::formatv("connect://{0}:", gdb_remote_hostname);
+ connect_url += std::to_string(gdb_remote_port);
+ dap.target.ConnectRemote(listener, connect_url.c_str(), "gdb-remote",
+ error);
+ } else {
+ // Attach by process name or id.
+ dap.target.Attach(attach_info, error);
+ }
} else {
- // Attach by process name or id.
- dap.target.Attach(attach_info, error);
+ dap.target.LoadCore(core_file.data(), error);
}
} else {
- dap.target.LoadCore(core_file.data(), error);
- }
- } else {
- // We have "attachCommands" that are a set of commands that are expected
- // to execute the commands after which a process should be created. If there
- // is no valid process after running these commands, we have failed.
- if (llvm::Error err = dap.RunAttachCommands(attachCommands)) {
- response["success"] = false;
- EmplaceSafeString(response, "message", llvm::toString(std::move(err)));
- dap.SendJSON(llvm::json::Value(std::move(response)));
- return;
+ // We have "attachCommands" that are a set of commands that are expected
+ // to execute the commands after which a process should be created. If
+ // there is no valid process after running these commands, we have failed.
+ if (llvm::Error err = dap.RunAttachCommands(attachCommands)) {
+ response["success"] = false;
+ EmplaceSafeString(response, "message", llvm::toString(std::move(err)));
+ dap.SendJSON(llvm::json::Value(std::move(response)));
+ return;
+ }
+ // The custom commands might have created a new target so we should use
+ // the selected target after these commands are run.
+ dap.target = dap.debugger.GetSelectedTarget();
}
- // The custom commands might have created a new target so we should use the
- // selected target after these commands are run.
- dap.target = dap.debugger.GetSelectedTarget();
-
- // Make sure the process is attached and stopped before proceeding as the
- // the launch commands are not run using the synchronous mode.
- error = dap.WaitForProcessToStop(std::chrono::seconds(timeout_seconds));
}
+ // Make sure the process is attached and stopped.
+ error = dap.WaitForProcessToStop(std::chrono::seconds(timeout_seconds));
+
+ // Clients can request a baseline of currently existing threads after
+ // we acknowledge the configurationDone request.
+ // Client requests the baseline of currently existing threads after
+ // a successful or attach by sending a 'threads' request
+ // right after receiving the configurationDone response.
+ // Obtain the list of threads before we resume the process
+ dap.initial_thread_list =
+ GetThreads(dap.target.GetProcess(), dap.thread_format);
----------------
JDevlieghere wrote:
The threads request gets delayed as well. As long as it comes in after the launch/attach request, it will get handled after. Here's the log between VS Code and the implementation in this PR:
```
--> {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lldb-dap","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true,"supportsMemoryEvent":true,"supportsStartDebuggingRequest":true,"supportsANSIStyling":true},"type":"request","seq":1}
<-- {"body":{"$__lldb_version":"lldb version 21.0.0git (git at github.com:JDevlieghere/llvm-project.git revision e7333489e50b1efe16203e8fd7b6dc7f2dcd4439)\n clang revision e7333489e50b1efe16203e8fd7b6dc7f2dcd4439\n llvm revision e7333489e50b1efe16203e8fd7b6dc7f2dcd4439","completionTriggerCharacters":["."," ","\t"],"exceptionBreakpointFilters":[{"default":false,"filter":"cpp_catch","label":"C++ Catch"},{"default":false,"filter":"cpp_throw","label":"C++ Throw"},{"default":false,"filter":"objc_catch","label":"Objective-C Catch"},{"default":false,"filter":"objc_throw","label":"Objective-C Throw"}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionInfoRequest":true,"supportsExceptionOptions":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsRestartRequest":true,"supportsSetVariable":true,"supportsStepInTargetsRequest":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"}
<-- {"event":"initialized","seq":0,"type":"event"}
--> {"command":"launch","arguments":{"type":"lldb-dap","request":"launch","name":"Launch LLDB","program":"/Users/jonas/llvm/build-ra/bin/lldb","args":[],"env":[],"cwd":"/Users/jonas/llvm/llvm-project","__configurationTarget":6,"__sessionId":"8dc997cc-ed4f-4ce1-a7e8-f2d59ea84796"},"type":"request","seq":2}
--> {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":3}
<-- {"body":{"breakpoints":[]},"command":"setFunctionBreakpoints","request_seq":3,"seq":0,"success":true,"type":"response"}
--> {"command":"setInstructionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4}
--> {"command":"setExceptionBreakpoints","arguments":{"filters":[]},"type":"request","seq":5}
<-- {"body":{"breakpoints":[]},"command":"setInstructionBreakpoints","request_seq":4,"seq":0,"success":true,"type":"response"}
--> {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6}
<-- {"command":"setExceptionBreakpoints","request_seq":5,"seq":0,"success":true,"type":"response"}
<-- {"body":{"breakpoints":[]},"command":"setDataBreakpoints","request_seq":6,"seq":0,"success":true,"type":"response"}
--> {"command":"configurationDone","type":"request","seq":7}
<-- {"command":"configurationDone","request_seq":7,"seq":0,"success":true,"type":"response"}
--> {"command":"threads","type":"request","seq":8}
<-- {"body":{"module":{"addressRange":"4294967296","debugInfoSize":"","id":"CFAF6A92-9494-3549-9408-121B5F8E5A32","name":"lldb","path":"/Users/jonas/llvm/build-ra/bin/lldb","symbolFilePath":"/Users/jonas/llvm/build-ra/bin/lldb","symbolStatus":"Symbols loaded."},"reason":"removed"},"event":"module","seq":0,"type":"event"}
<-- {"command":"launch","request_seq":2,"seq":0,"success":true,"type":"response"}
<-- {"body":{"isLocalProcess":true,"name":"/Users/jonas/llvm/build-ra/bin/lldb","startMethod":"launch","systemProcessId":24119},"event":"process","seq":0,"type":"event"}
<-- {"body":{"threads":[{"id":3321319,"name":"Thread 1"}]},"command":"threads","request_seq":8,"seq":0,"success":true,"type":"response"}
```
https://github.com/llvm/llvm-project/pull/138219
More information about the lldb-commits
mailing list