@@ -78,34 +78,7 @@ Error AttachRequestHandler::Run(const AttachRequestArguments &args) const {
7878 // Perform the launch in synchronous mode so that we don't have to worry
7979 // about process state changes during the launch.
8080 ScopeSyncMode scope_sync_mode (dap.debugger );
81- if (args.attachCommands .empty ()) {
82- // No "attachCommands", just attach normally.
83- if (args.coreFile .empty ()) {
84- if (args.gdbRemotePort != LLDB_DAP_INVALID_PORT) {
85- // If port is specified and pid is not.
86- lldb::SBListener listener = dap.debugger .GetListener ();
87-
88- // If the user hasn't provided the hostname property, default
89- // localhost being used.
90- std::string connect_url =
91- llvm::formatv (" connect://{0}:" , args.gdbRemoteHostname );
92- connect_url += std::to_string (args.gdbRemotePort );
93- dap.target .ConnectRemote (listener, connect_url.c_str (), " gdb-remote" ,
94- error);
95- } else {
96- // Attach by pid or process name.
97- lldb::SBAttachInfo attach_info;
98- if (args.pid != LLDB_INVALID_PROCESS_ID)
99- attach_info.SetProcessID (args.pid );
100- else if (!dap.configuration .program .empty ())
101- attach_info.SetExecutable (dap.configuration .program .data ());
102- attach_info.SetWaitForLaunch (args.waitFor , false /* async*/ );
103- dap.target .Attach (attach_info, error);
104- }
105- } else {
106- dap.target .LoadCore (args.coreFile .data (), error);
107- }
108- } else {
81+ if (!args.attachCommands .empty ()) {
10982 // We have "attachCommands" that are a set of commands that are expected
11083 // to execute the commands after which a process should be created. If
11184 // there is no valid process after running these commands, we have failed.
@@ -115,6 +88,28 @@ Error AttachRequestHandler::Run(const AttachRequestArguments &args) const {
11588 // The custom commands might have created a new target so we should use
11689 // the selected target after these commands are run.
11790 dap.target = dap.debugger .GetSelectedTarget ();
91+ } else if (!args.coreFile .empty ()) {
92+ dap.target .LoadCore (args.coreFile .data (), error);
93+ } else if (args.gdbRemotePort != LLDB_DAP_INVALID_PORT) {
94+ // If port is specified and pid is not.
95+ lldb::SBListener listener = dap.debugger .GetListener ();
96+
97+ // If the user hasn't provided the hostname property, default
98+ // localhost being used.
99+ std::string connect_url =
100+ llvm::formatv (" connect://{0}:" , args.gdbRemoteHostname );
101+ connect_url += std::to_string (args.gdbRemotePort );
102+ dap.target .ConnectRemote (listener, connect_url.c_str (), " gdb-remote" ,
103+ error);
104+ } else {
105+ // Attach by pid or process name.
106+ lldb::SBAttachInfo attach_info;
107+ if (args.pid != LLDB_INVALID_PROCESS_ID)
108+ attach_info.SetProcessID (args.pid );
109+ else if (!dap.configuration .program .empty ())
110+ attach_info.SetExecutable (dap.configuration .program .data ());
111+ attach_info.SetWaitForLaunch (args.waitFor , false /* async*/ );
112+ dap.target .Attach (attach_info, error);
118113 }
119114 }
120115
0 commit comments