From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3E9073855173 for ; Mon, 28 Nov 2022 12:05:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E9073855173 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669637126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Os6GA22xXd8L4+mDOKYSj+g+y+HiYPT5f608tgb28cQ=; b=a85NXmr/H6yRjUPX8VFD4nXpgp2ENhM+KvY6Dtwh19D6ngOWHPXy085vHBAcqKgeJHeMNh bIFPbwwhMa7ANeRXvTk9kAHOCedkY+rd1L26eUZVHEU/qzG7lHptYor6c2/Dievfi9NIQA khjGY11oA2xuHzYCqKhIlAvCJFT0OCc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-546-pXYSJreaOXumRh0zRo3SEQ-1; Mon, 28 Nov 2022 07:05:25 -0500 X-MC-Unique: pXYSJreaOXumRh0zRo3SEQ-1 Received: by mail-wr1-f70.google.com with SMTP id j30-20020adfa55e000000b00241b49be1a3so1829504wrb.4 for ; Mon, 28 Nov 2022 04:05:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Os6GA22xXd8L4+mDOKYSj+g+y+HiYPT5f608tgb28cQ=; b=dzidxnznHKSU69d8QvhGvj4yhSMBL3Ye6neFscJhUwNZpabBSVGxY1VVXeqt1oPKMJ q73sE7McFqSKB9WQAyorPvJcfqBLkPSNHpezgnwlmkka8p85IoKp+WZ1admlCvZT/Z0M RAdsjJtktDc6fjm/EbjQ5BUJEHMZq0hi1y3a6khlbADLyY9V6MJTwTzmWxIP0o9Jk0M0 18SmoaHb23IvIff553kj145TaQYf0w9npzOgLnBza6Hx3bgC1wNAmGBHZsv/GzEVWV16 ziCtl0rAefaNY/3tkNbD4+njSq+atBP5m30egMJiVEdxomHY7UPBOgidUF/x9gtuS9KP K/3w== X-Gm-Message-State: ANoB5plsVcmIC9RT1DIzNbDogNNtdUTEn54npM1mJimKTXZDeuLb5ViL 022seKgxf2+UwUKpomstWeamRmrxuBTQ9jz+WORx43n20eSKoSumglS8YyhCdQz65ZdcdUeo9L2 cUVKtRq4GRqlCLncDPzC4hQ== X-Received: by 2002:a05:600c:4f93:b0:3cf:a616:ccc0 with SMTP id n19-20020a05600c4f9300b003cfa616ccc0mr41705299wmq.73.1669637124373; Mon, 28 Nov 2022 04:05:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+a0GxHFrOME/0rwum0b/7B62W8fAwXKQKqq0LqeCBDdaNq9ZQy1li9kmtd8VGF2zm1J8rPg== X-Received: by 2002:a05:600c:4f93:b0:3cf:a616:ccc0 with SMTP id n19-20020a05600c4f9300b003cfa616ccc0mr41705263wmq.73.1669637123984; Mon, 28 Nov 2022 04:05:23 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id j23-20020a05600c1c1700b003cf57329221sm19952276wms.14.2022.11.28.04.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 04:05:23 -0800 (PST) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Cc: Simon Marchi Subject: Re: [PATCH v2 2/5] gdb/testsuite: refactor gdb.threads/detach-step-over.exp In-Reply-To: <20221121171213.1414366-3-simon.marchi@polymtl.ca> References: <20221121171213.1414366-1-simon.marchi@polymtl.ca> <20221121171213.1414366-3-simon.marchi@polymtl.ca> Date: Mon, 28 Nov 2022 12:05:22 +0000 Message-ID: <87iliz2sjh.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Simon Marchi writes: > From: Andrew Burgess > > Factor out some bits of gdb.threads/detach-step-over.exp to procs in > preparation to adding some new variations of the test. Rename the > existing "test" proc and make it use proc_with_prefix. > > Co-Authored-By: Simon Marchi > Change-Id: Ib4412545c81c8556029e0f7bfa9dd48d7a9f3189 LGTM. I guess if we're both happy then this is OK to go in without anyone other review. Thanks, Andrew > --- > .../gdb.threads/detach-step-over.exp | 238 ++++++++++-------- > 1 file changed, 138 insertions(+), 100 deletions(-) > > diff --git a/gdb/testsuite/gdb.threads/detach-step-over.exp b/gdb/testsuite/gdb.threads/detach-step-over.exp > index 917be2ef3782..ad9b08f549ea 100644 > --- a/gdb/testsuite/gdb.threads/detach-step-over.exp > +++ b/gdb/testsuite/gdb.threads/detach-step-over.exp > @@ -56,11 +56,11 @@ standard_testfile > > set bp_lineno [gdb_get_line_number "Set breakpoint here"] > > -# The test proper. See description above. > -proc test {condition_eval target_non_stop non_stop displaced} { > - # Number of threads started by the program. > - set n_threads 10 > +# Number of threads started by the program. > +set n_threads 10 > > +# Start GDB, configuring various settings according to the arguments. > +proc start_gdb_for_test {condition_eval target_non_stop non_stop displaced} { > save_vars { ::GDBFLAGS } { > append ::GDBFLAGS " -ex \"maint set target-non-stop $target_non_stop\"" > append ::GDBFLAGS " -ex \"set non-stop $non_stop\"" > @@ -69,10 +69,137 @@ proc test {condition_eval target_non_stop non_stop displaced} { > clean_restart $::binfile > } > > + gdb_test_no_output "set breakpoint condition-evaluation $condition_eval" > +} > + > +# Use the 'attach' command to attach to process with pid TESTPID. Return true > +# if we believe GDB has attached and we are back at the GDB prompt, otherwise, > +# return false. > +proc attach_to {testpid} { > + with_timeout_factor 2 { > + set attached 0 > + set saw_attaching 0 > + gdb_test_multiple "attach $testpid" "attach" { > + -re "Attaching to program.*process $testpid\r\n" { > + set saw_attaching 1 > + exp_continue > + } > + -re "new threads in iteration" { > + # Seen when "set debug libthread_db" is on. > + exp_continue > + } > + -re "Reading symbols from|Expanding full symbols from" { > + # Prevent -readnow timeout. > + exp_continue > + } > + -re "is a zombie - the process has already terminated.*$::gdb_prompt " { > + fail $gdb_test_name > + } > + -re "Unable to attach: .*$::gdb_prompt " { > + fail $gdb_test_name > + } > + -re "\r\n$::gdb_prompt " { > + if { $saw_attaching } { > + set attached 1 > + pass $gdb_test_name > + } else { > + fail $gdb_test_name > + } > + } > + } > + } > + > + return $attached > +} > + > +# After attaching to a multi-threaded inferior in non-stop mode, we expect to > +# see a stop message from each thread. This proc waits for all of these stop > +# messages. TID_RE is a regexp used to match the thread-id of the stopped > +# thread. > +# > +# Return true if we saw a stop from each of the expected threads (based on the > +# global N_THREADS value), otherwise, return false. > +proc check_stops_after_non_stop_attach {tid_re} { > + set any "\[^\r\n\]*" > + > + # In non-stop, we will see one stop per thread after the prompt. > + set stops 0 > + set test "seen all stops" > + for {set thread 1} { $thread <= $::n_threads } { incr thread } { > + if {[gdb_test_multiple "" $test { > + -re "Thread ${tid_re} ${any} stopped" { > + incr stops > + } > + }] != 0} { > + break > + } > + } > + > + # If we haven't seen all stops, then the > + # gdb_test_multiple in the loop above will have > + # already issued a FAIL. > + if {$stops != $::n_threads} { > + return false > + } > + pass $test > + return true > +} > + > +# Prepare for a single test iteration. TESTPID is the pid of the process GDB > +# will be attached too. NON_STOP indicates if GDB is configured in non-stop > +# mode or not. ATTEMPT is the current attempt number, and ATTEMPTS is the > +# maximum number of attempts we plan to run. TID_RE is a string used to match > +# against a thread-id in GDB's stop messages. > +# > +# Return true if everything is prepared correctly, otherwise return false. > +proc prepare_test_iter {testpid non_stop attempt attempts tid_re} { > + if {![attach_to $testpid]} { > + return false > + } > + > + if {$non_stop} { > + if {![check_stops_after_non_stop_attach $tid_re]} { > + return false > + } > + } > + > + gdb_test "break ${::srcfile}:${::bp_lineno} if 0" "Breakpoint.*" \ > + "break LOC if 0" > + > + if {$attempt < $attempts} { > + # Kick the time out timer for another round. > + gdb_test "print again = 1" " = 1" "reset timer in the inferior" > + # Show the time we had left in the logs, in case > + # something goes wrong. > + gdb_test "print seconds_left" " = .*" > + } > + > + if {$non_stop} { > + set cont_cmd "continue -a &" > + } else { > + set cont_cmd "continue &" > + } > + > + set cont_cmd_re [string_to_regexp $cont_cmd] > + gdb_test_multiple $cont_cmd "" { > + -re "^$cont_cmd_re\r\nContinuing\.\r\n$::gdb_prompt " { > + pass $gdb_test_name > + } > + } > + > + # Wait a bit, to give time for the threads to hit the > + # breakpoint. > + sleep 1 > + > + return true > +} > + > +# The test proper. See the description at the top of the file. > +proc_with_prefix test_detach_command {condition_eval target_non_stop non_stop displaced} { > set test_spawn_id [spawn_wait_for_attach $::binfile] > set testpid [spawn_id_get_pid $test_spawn_id] > > - set any "\[^\r\n\]*" > + start_gdb_for_test $condition_eval $target_non_stop $non_stop $displaced > > gdb_test "add-inferior" "Added inferior 2.*" > gdb_test "inferior 2" "Switching to .*" > @@ -84,8 +211,6 @@ proc test {condition_eval target_non_stop non_stop displaced} { > return > } > > - gdb_test_no_output "set breakpoint condition-evaluation $condition_eval" > - > # Get the PID of the test process. > set pid_inf2 "" > gdb_test_multiple "p mypid" "get pid of inferior 2" { > @@ -100,101 +225,12 @@ proc test {condition_eval target_non_stop non_stop displaced} { > with_test_prefix "iter $attempt" { > gdb_test "inferior 1" "Switching to .*" > > - with_timeout_factor 2 { > - set attached 0 > - set saw_attaching 0 > - set eperm 0 > - set test "attach" > - gdb_test_multiple "attach $testpid" $test { > - -re "Attaching to program.*process $testpid\r\n" { > - set saw_attaching 1 > - exp_continue > - } > - -re "new threads in iteration" { > - # Seen when "set debug libthread_db" is on. > - exp_continue > - } > - -re "Reading symbols from|Expanding full symbols from" { > - # Prevent -readnow timeout. > - exp_continue > - } > - -re "is a zombie - the process has already terminated.*$::gdb_prompt " { > - fail $gdb_test_name > - } > - -re "Unable to attach: .*$::gdb_prompt " { > - fail $gdb_test_name > - } > - -re "\r\n$::gdb_prompt " { > - if { $saw_attaching } { > - set attached 1 > - pass $test > - } else { > - fail $test > - } > - } > - } > - } > - > - if {!$attached} { > + if {![prepare_test_iter $testpid $non_stop \ > + $attempt $attempts "$::decimal\.$::decimal"]} { > kill_wait_spawned_process $test_spawn_id > return > } > > - if {$non_stop} { > - # In non-stop, we will see one stop per thread after > - # the prompt. > - set stops 0 > - set tid_re "$::decimal\.$::decimal" > - set test "seen all stops" > - for {set thread 1} { $thread <= $n_threads } { incr thread } { > - if {[gdb_test_multiple "" $test { > - -re "Thread ${tid_re} ${any} stopped" { > - incr stops > - } > - }] != 0} { > - break > - } > - } > - > - # If we haven't seen all stops, then the > - # gdb_test_multiple in the loop above will have > - # already issued a FAIL. > - if {$stops != $n_threads} { > - kill_wait_spawned_process $test_spawn_id > - return > - } > - pass $test > - } > - > - # Set threads stepping over a breakpoint continuously. > - gdb_test "break $::srcfile:$::bp_lineno if 0" "Breakpoint.*" \ > - "break LOC if 0" > - > - if {$attempt < $attempts} { > - # Kick the time out timer for another round. > - gdb_test "print again = 1" " = 1" "reset timer in the inferior" > - # Show the time we had left in the logs, in case > - # something goes wrong. > - gdb_test "print seconds_left" " = .*" > - } > - > - if {$non_stop} { > - set cont_cmd "continue -a &" > - } else { > - set cont_cmd "continue &" > - } > - > - set cont_cmd_re [string_to_regexp $cont_cmd] > - gdb_test_multiple $cont_cmd "" { > - -re "^$cont_cmd_re\r\nContinuing\.\r\n$::gdb_prompt " { > - pass $gdb_test_name > - } > - } > - > - # Wait a bit, to give time for the threads to hit the > - # breakpoint. > - sleep 1 > - > set running_count 0 > set interrupted 0 > gdb_test_multiple "info threads" "all threads running" { > @@ -219,7 +255,8 @@ proc test {condition_eval target_non_stop non_stop displaced} { > } > } > -re "$::gdb_prompt $" { > - gdb_assert {$running_count == ($n_threads + 1) * 2} $gdb_test_name > + gdb_assert {$running_count == ($::n_threads + 1) * 2} \ > + $gdb_test_name > } > } > > @@ -292,7 +329,8 @@ foreach_with_prefix breakpoint-condition-evaluation {"host" "target"} { > } > > foreach_with_prefix displaced {"off" "auto"} { > - test ${breakpoint-condition-evaluation} ${target-non-stop} ${non-stop} ${displaced} > + test_detach_command ${breakpoint-condition-evaluation} \ > + ${target-non-stop} ${non-stop} ${displaced} > } > } > } > -- > 2.38.1