@@ -553,3 +553,90 @@ def test_vCont_all_processes_implicit(self):
553
553
"send packet: $E03#00" ,
554
554
], True )
555
555
self .expect_gdbremote_sequence ()
556
+
557
+ @add_test_categories (["fork" ])
558
+ def test_memory_read_write (self ):
559
+ self .build ()
560
+ INITIAL_DATA = "Initial message"
561
+ self .prep_debug_monitor_and_inferior (
562
+ inferior_args = ["set-message:{}" .format (INITIAL_DATA ),
563
+ "get-data-address-hex:g_message" ,
564
+ "fork" ,
565
+ "print-message:" ,
566
+ "trap" ,
567
+ ])
568
+ self .add_qSupported_packets (["multiprocess+" ,
569
+ "fork-events+" ])
570
+ ret = self .expect_gdbremote_sequence ()
571
+ self .assertIn ("fork-events+" , ret ["qSupported_response" ])
572
+ self .reset_test_sequence ()
573
+
574
+ # continue and expect fork
575
+ self .test_sequence .add_log_lines ([
576
+ "read packet: $c#00" ,
577
+ {"type" : "output_match" ,
578
+ "regex" : self .maybe_strict_output_regex (r"data address: 0x([0-9a-fA-F]+)\r\n" ),
579
+ "capture" : {1 : "addr" }},
580
+ {"direction" : "send" , "regex" : self .fork_regex .format ("fork" ),
581
+ "capture" : self .fork_capture },
582
+ ], True )
583
+ ret = self .expect_gdbremote_sequence ()
584
+ pidtids = {
585
+ "parent" : (ret ["parent_pid" ], ret ["parent_tid" ]),
586
+ "child" : (ret ["child_pid" ], ret ["child_tid" ]),
587
+ }
588
+ addr = ret ["addr" ]
589
+ self .reset_test_sequence ()
590
+
591
+ for name , pidtid in pidtids .items ():
592
+ self .test_sequence .add_log_lines (
593
+ ["read packet: $Hgp{}.{}#00" .format (* pidtid ),
594
+ "send packet: $OK#00" ,
595
+ # read the current memory contents
596
+ "read packet: $m{},{:x}#00" .format (addr ,
597
+ len (INITIAL_DATA ) + 1 ),
598
+ {"direction" : "send" ,
599
+ "regex" : r"^[$](.+)#.*$" ,
600
+ "capture" : {1 : "data" }},
601
+ # write a new value
602
+ "read packet: $M{},{:x}:{}#00" .format (addr ,
603
+ len (name ) + 1 ,
604
+ seven .hexlify (
605
+ name + "\0 " )),
606
+ "send packet: $OK#00" ,
607
+ # resume the process and wait for the trap
608
+ "read packet: $Hcp{}.{}#00" .format (* pidtid ),
609
+ "send packet: $OK#00" ,
610
+ "read packet: $c#00" ,
611
+ {"type" : "output_match" ,
612
+ "regex" : self .maybe_strict_output_regex (r"message: (.*)\r\n" ),
613
+ "capture" : {1 : "printed_message" }},
614
+ {"direction" : "send" ,
615
+ "regex" : "^[$]T05thread:p{}.{}.*" .format (* pidtid ),
616
+ },
617
+ ], True )
618
+ ret = self .expect_gdbremote_sequence ()
619
+ data = seven .unhexlify (ret ["data" ])
620
+ self .assertEqual (data , INITIAL_DATA + "\0 " )
621
+ self .assertEqual (ret ["printed_message" ], name );
622
+ self .reset_test_sequence ()
623
+
624
+ # we do the second round separately to make sure that initial data
625
+ # is correctly preserved while writing into the first process
626
+
627
+ for name , pidtid in pidtids .items ():
628
+ self .test_sequence .add_log_lines (
629
+ ["read packet: $Hgp{}.{}#00" .format (* pidtid ),
630
+ "send packet: $OK#00" ,
631
+ # read the current memory contents
632
+ "read packet: $m{},{:x}#00" .format (addr ,
633
+ len (name ) + 1 ),
634
+ {"direction" : "send" ,
635
+ "regex" : r"^[$](.+)#.*$" ,
636
+ "capture" : {1 : "data" }},
637
+ ], True )
638
+ ret = self .expect_gdbremote_sequence ()
639
+ self .assertIsNotNone (ret .get ("data" ))
640
+ data = seven .unhexlify (ret .get ("data" ))
641
+ self .assertEqual (data , name + "\0 " )
642
+ self .reset_test_sequence ()
0 commit comments