@@ -2639,75 +2639,53 @@ bool GDBRemoteCommunicationClient::KillSpawnedProcess(lldb::pid_t pid) {
2639
2639
return false ;
2640
2640
}
2641
2641
2642
- bool GDBRemoteCommunicationClient::SetCurrentThread ( uint64_t tid) {
2643
- if (m_curr_tid == tid)
2644
- return true ;
2645
-
2646
- char packet[ 32 ] ;
2647
- int packet_len ;
2642
+ llvm::Optional< uint64_t >
2643
+ GDBRemoteCommunicationClient::SendSetCurrentThreadPacket ( uint64_t tid,
2644
+ char op) {
2645
+ lldb_private::StreamString packet;
2646
+ packet. PutChar ( ' H ' ) ;
2647
+ packet. PutChar (op) ;
2648
2648
if (tid == UINT64_MAX)
2649
- packet_len = :: snprintf ( packet, sizeof (packet), " Hg -1" );
2649
+ packet. PutCString ( " -1" );
2650
2650
else
2651
- packet_len = ::snprintf (packet, sizeof (packet), " Hg%" PRIx64, tid);
2652
- assert (packet_len + 1 < (int )sizeof (packet));
2653
- UNUSED_IF_ASSERT_DISABLED (packet_len);
2651
+ packet.PutHex64 (tid);
2654
2652
StringExtractorGDBRemote response;
2655
- if (SendPacketAndWaitForResponse (packet, response, false ) ==
2653
+ if (SendPacketAndWaitForResponse (packet. GetString () , response, false ) ==
2656
2654
PacketResult::Success) {
2657
- if (response.IsOKResponse ()) {
2658
- m_curr_tid = tid;
2659
- return true ;
2660
- }
2655
+ if (response.IsOKResponse ())
2656
+ return tid;
2661
2657
2662
2658
/*
2663
2659
* Connected bare-iron target (like YAMON gdb-stub) may not have support for
2664
2660
* Hg packet.
2665
2661
* The reply from '?' packet could be as simple as 'S05'. There is no packet
2666
2662
* which can
2667
2663
* give us pid and/or tid. Assume pid=tid=1 in such cases.
2668
- */
2669
- if (response.IsUnsupportedResponse () && IsConnected ()) {
2670
- m_curr_tid = 1 ;
2671
- return true ;
2672
- }
2664
+ */
2665
+ if (response.IsUnsupportedResponse () && IsConnected ())
2666
+ return 1 ;
2673
2667
}
2674
- return false ;
2668
+ return llvm::None ;
2675
2669
}
2676
2670
2677
- bool GDBRemoteCommunicationClient::SetCurrentThreadForRun (uint64_t tid) {
2678
- if (m_curr_tid_run == tid)
2671
+ bool GDBRemoteCommunicationClient::SetCurrentThread (uint64_t tid) {
2672
+ if (m_curr_tid == tid)
2679
2673
return true ;
2680
2674
2681
- char packet[32 ];
2682
- int packet_len;
2683
- if (tid == UINT64_MAX)
2684
- packet_len = ::snprintf (packet, sizeof (packet), " Hc-1" );
2685
- else
2686
- packet_len = ::snprintf (packet, sizeof (packet), " Hc%" PRIx64, tid);
2675
+ llvm::Optional<uint64_t > ret = SendSetCurrentThreadPacket (tid, ' g' );
2676
+ if (ret.hasValue ())
2677
+ m_curr_tid = ret.getValue ();
2678
+ return ret.hasValue ();
2679
+ }
2687
2680
2688
- assert (packet_len + 1 < (int )sizeof (packet));
2689
- UNUSED_IF_ASSERT_DISABLED (packet_len);
2690
- StringExtractorGDBRemote response;
2691
- if (SendPacketAndWaitForResponse (packet, response, false ) ==
2692
- PacketResult::Success) {
2693
- if (response.IsOKResponse ()) {
2694
- m_curr_tid_run = tid;
2695
- return true ;
2696
- }
2681
+ bool GDBRemoteCommunicationClient::SetCurrentThreadForRun (uint64_t tid) {
2682
+ if (m_curr_tid_run == tid)
2683
+ return true ;
2697
2684
2698
- /*
2699
- * Connected bare-iron target (like YAMON gdb-stub) may not have support for
2700
- * Hc packet.
2701
- * The reply from '?' packet could be as simple as 'S05'. There is no packet
2702
- * which can
2703
- * give us pid and/or tid. Assume pid=tid=1 in such cases.
2704
- */
2705
- if (response.IsUnsupportedResponse () && IsConnected ()) {
2706
- m_curr_tid_run = 1 ;
2707
- return true ;
2708
- }
2709
- }
2710
- return false ;
2685
+ llvm::Optional<uint64_t > ret = SendSetCurrentThreadPacket (tid, ' c' );
2686
+ if (ret.hasValue ())
2687
+ m_curr_tid_run = ret.getValue ();
2688
+ return ret.hasValue ();
2711
2689
}
2712
2690
2713
2691
bool GDBRemoteCommunicationClient::GetStopReply (
0 commit comments