[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 7 14:01:25 PDT 2024


================
@@ -749,9 +755,27 @@ void request_attach(const llvm::json::Object &request) {
     // Disable async events so the attach will be successful when we return from
     // the launch call and the launch will happen synchronously
     g_dap.debugger.SetAsync(false);
-    if (core_file.empty())
-      g_dap.target.Attach(attach_info, error);
-    else
+    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 = g_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.data());
+        connect_url += std::to_string(gdb_remote_port);
----------------
clayborg wrote:

Probably best to format this all in one go and think the llvm::formatv supports std:strings already, so you might be able to remove the `.data()` and then format the port in the same call:
```
 std::string connect_url =
            llvm::formatv("connect://{0}:{1}", gdb_remote_hostname, gdb_remote_port);
```

https://github.com/llvm/llvm-project/pull/91570


More information about the lldb-commits mailing list