@@ -162,6 +162,12 @@ void GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers() {
162
162
RegisterMemberFunctionHandler (
163
163
StringExtractorGDBRemote::eServerPacketType_vAttachWait,
164
164
&GDBRemoteCommunicationServerLLGS::Handle_vAttachWait);
165
+ RegisterMemberFunctionHandler (
166
+ StringExtractorGDBRemote::eServerPacketType_qVAttachOrWaitSupported,
167
+ &GDBRemoteCommunicationServerLLGS::Handle_qVAttachOrWaitSupported);
168
+ RegisterMemberFunctionHandler (
169
+ StringExtractorGDBRemote::eServerPacketType_vAttachOrWait,
170
+ &GDBRemoteCommunicationServerLLGS::Handle_vAttachOrWait);
165
171
RegisterMemberFunctionHandler (
166
172
StringExtractorGDBRemote::eServerPacketType_vCont,
167
173
&GDBRemoteCommunicationServerLLGS::Handle_vCont);
@@ -338,7 +344,7 @@ Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
338
344
}
339
345
340
346
Status GDBRemoteCommunicationServerLLGS::AttachWaitProcess (
341
- llvm::StringRef process_name) {
347
+ llvm::StringRef process_name, bool include_existing ) {
342
348
Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS));
343
349
344
350
std::chrono::milliseconds polling_interval = std::chrono::milliseconds (1 );
@@ -347,13 +353,17 @@ Status GDBRemoteCommunicationServerLLGS::AttachWaitProcess(
347
353
ProcessInstanceInfoList exclusion_list;
348
354
ProcessInstanceInfoMatch match_info;
349
355
match_info.GetProcessInfo ().GetExecutableFile ().SetFile (
350
- process_name, llvm::sys::path::Style::posix );
351
- match_info.SetNameMatchType (NameMatch::EndsWith );
356
+ process_name, llvm::sys::path::Style::native );
357
+ match_info.SetNameMatchType (NameMatch::Equals );
352
358
353
- // Create the excluded process list before polling begins.
354
- Host::FindProcesses (match_info, exclusion_list);
355
- LLDB_LOG (log, " placed '{0}' processes in the exclusion list." ,
356
- exclusion_list.size ());
359
+ if (include_existing) {
360
+ LLDB_LOG (log, " including existing processes in search" );
361
+ } else {
362
+ // Create the excluded process list before polling begins.
363
+ Host::FindProcesses (match_info, exclusion_list);
364
+ LLDB_LOG (log, " placed '{0}' processes in the exclusion list." ,
365
+ exclusion_list.size ());
366
+ }
357
367
358
368
LLDB_LOG (log, " waiting for '{0}' to appear" , process_name);
359
369
@@ -3275,7 +3285,43 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttachWait(
3275
3285
3276
3286
LLDB_LOG (log, " attempting to attach to process named '{0}'" , process_name);
3277
3287
3278
- Status error = AttachWaitProcess (process_name);
3288
+ Status error = AttachWaitProcess (process_name, false );
3289
+ if (error.Fail ()) {
3290
+ LLDB_LOG (log, " failed to attach to process named '{0}': {1}" , process_name,
3291
+ error);
3292
+ return SendErrorResponse (error);
3293
+ }
3294
+
3295
+ // Notify we attached by sending a stop packet.
3296
+ return SendStopReasonForState (m_debugged_process_up->GetState ());
3297
+ }
3298
+
3299
+ GDBRemoteCommunication::PacketResult
3300
+ GDBRemoteCommunicationServerLLGS::Handle_qVAttachOrWaitSupported (
3301
+ StringExtractorGDBRemote &packet) {
3302
+ return SendOKResponse ();
3303
+ }
3304
+
3305
+ GDBRemoteCommunication::PacketResult
3306
+ GDBRemoteCommunicationServerLLGS::Handle_vAttachOrWait (
3307
+ StringExtractorGDBRemote &packet) {
3308
+ Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS));
3309
+
3310
+ // Consume the ';' after the identifier.
3311
+ packet.SetFilePos (strlen (" vAttachOrWait" ));
3312
+
3313
+ if (!packet.GetBytesLeft () || packet.GetChar () != ' ;' )
3314
+ return SendIllFormedResponse (packet, " vAttachOrWait missing expected ';'" );
3315
+
3316
+ // Allocate the buffer for the process name from vAttachWait.
3317
+ std::string process_name;
3318
+ if (!packet.GetHexByteString (process_name))
3319
+ return SendIllFormedResponse (packet,
3320
+ " vAttachOrWait failed to parse process name" );
3321
+
3322
+ LLDB_LOG (log, " attempting to attach to process named '{0}'" , process_name);
3323
+
3324
+ Status error = AttachWaitProcess (process_name, true );
3279
3325
if (error.Fail ()) {
3280
3326
LLDB_LOG (log, " failed to attach to process named '{0}': {1}" , process_name,
3281
3327
error);
0 commit comments