@@ -11,7 +11,6 @@ class TestGdbRemoteFork(gdbremote_testcase.GdbRemoteTestCaseBase):
1111 "{}:p([0-9a-f]+)[.]([0-9a-f]+).*" )
1212 fork_capture = {1 : "parent_pid" , 2 : "parent_tid" ,
1313 3 : "child_pid" , 4 : "child_tid" }
14- procinfo_regex = "[$]pid:([0-9a-f]+);.*"
1514
1615 @add_test_categories (["fork" ])
1716 def test_fork_multithreaded (self ):
@@ -68,7 +67,7 @@ def fork_and_detach_test(self, variant):
6867 "send packet: $OK#00" ,
6968 # verify that the current process is correct
7069 "read packet: $qC#00" ,
71- "send packet: $QC{} #00" .format (parent_tid ),
70+ "send packet: $QCp{}.{} #00" .format (parent_pid , parent_tid ),
7271 # verify that the correct processes are detached/available
7372 "read packet: $Hgp{}.{}#00" .format (child_pid , child_tid ),
7473 "send packet: $Eff#00" ,
@@ -167,12 +166,9 @@ def test_select_wrong_pid(self):
167166
168167 # get process pid
169168 self .test_sequence .add_log_lines ([
170- "read packet: $qProcessInfo#00" ,
171- {"direction" : "send" , "regex" : self .procinfo_regex ,
172- "capture" : {1 : "pid" }},
173169 "read packet: $qC#00" ,
174- {"direction" : "send" , "regex" : "[$]QC ([0-9a-f]+)#.*" ,
175- "capture" : {1 : "tid" }},
170+ {"direction" : "send" , "regex" : "[$]QCp([0-9a-f]+). ([0-9a-f]+)#.*" ,
171+ "capture" : {1 : "pid" , 2 : " tid" }},
176172 ], True )
177173 ret = self .expect_gdbremote_sequence ()
178174 pid , tid = (int (ret [x ], 16 ) for x in ("pid" , "tid" ))
@@ -208,8 +204,8 @@ def test_detach_current(self):
208204
209205 # get process pid
210206 self .test_sequence .add_log_lines ([
211- "read packet: $qProcessInfo #00" ,
212- {"direction" : "send" , "regex" : self . procinfo_regex ,
207+ "read packet: $qC #00" ,
208+ {"direction" : "send" , "regex" : "[$]QCp([0-9a-f]+).[0-9a-f]+#.*" ,
213209 "capture" : {1 : "pid" }},
214210 ], True )
215211 ret = self .expect_gdbremote_sequence ()
@@ -817,3 +813,56 @@ def test_register_read_write(self):
817813 data = ret .get ("data" )
818814 self .assertIsNotNone (data )
819815 self .assertEqual (data , old_val [1 ])
816+
817+ @add_test_categories (["fork" ])
818+ def test_qC (self ):
819+ self .build ()
820+ self .prep_debug_monitor_and_inferior (
821+ inferior_args = ["fork" ,
822+ "thread:new" ,
823+ "trap" ,
824+ ])
825+ self .add_qSupported_packets (["multiprocess+" ,
826+ "fork-events+" ])
827+ ret = self .expect_gdbremote_sequence ()
828+ self .assertIn ("fork-events+" , ret ["qSupported_response" ])
829+ self .reset_test_sequence ()
830+
831+ # continue and expect fork
832+ self .test_sequence .add_log_lines ([
833+ "read packet: $c#00" ,
834+ {"direction" : "send" , "regex" : self .fork_regex .format ("fork" ),
835+ "capture" : self .fork_capture },
836+ ], True )
837+ self .add_threadinfo_collection_packets ()
838+ ret = self .expect_gdbremote_sequence ()
839+ pidtids = [
840+ (ret ["parent_pid" ], ret ["parent_tid" ]),
841+ (ret ["child_pid" ], ret ["child_tid" ]),
842+ ]
843+ self .reset_test_sequence ()
844+
845+ for pidtid in pidtids :
846+ self .test_sequence .add_log_lines (
847+ ["read packet: $Hcp{}.{}#00" .format (* pidtid ),
848+ "send packet: $OK#00" ,
849+ "read packet: $c#00" ,
850+ {"direction" : "send" ,
851+ "regex" : "^[$]T05thread:p{}.{}.*" .format (* pidtid ),
852+ },
853+ ], True )
854+
855+ self .add_threadinfo_collection_packets ()
856+ ret = self .expect_gdbremote_sequence ()
857+ self .reset_test_sequence ()
858+
859+ pidtids = set (self .parse_threadinfo_packets (ret ))
860+ self .assertEqual (len (pidtids ), 4 )
861+ for pidtid in pidtids :
862+ self .test_sequence .add_log_lines (
863+ ["read packet: $Hgp{:x}.{:x}#00" .format (* pidtid ),
864+ "send packet: $OK#00" ,
865+ "read packet: $qC#00" ,
866+ "send packet: $QCp{:x}.{:x}#00" .format (* pidtid ),
867+ ], True )
868+ self .expect_gdbremote_sequence ()
0 commit comments