From patchwork Mon Nov 28 11:25:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61146 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF27C38532D8 for ; Mon, 28 Nov 2022 11:26:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF27C38532D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669634771; bh=hyKpFXOcE3toZObp9LxpSeToVua9OmUE2gMNb6lPSBw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=PBtZVXUDkDvOqt+/SCQQs938lkbOOlDu0eHJ8X1mzV8iedCVWvahCgHWDmpLUBwB1 OKsX6pngb7ZGFx2q+jAycs5lUsuX0XcuTg3Qe9B9KnEv1DGKIMgDKx1pDA5J3xS2H0 QTJ+cHxu8hG2lzLIG9zNhnkd6lFLZtM7gxb1h3RI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id EA7463858CDB for ; Mon, 28 Nov 2022 11:25:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EA7463858CDB Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-427-WY7HEQ9FMQeRYXwB_6bJ9g-1; Mon, 28 Nov 2022 06:25:44 -0500 X-MC-Unique: WY7HEQ9FMQeRYXwB_6bJ9g-1 Received: by mail-wr1-f69.google.com with SMTP id k1-20020adfb341000000b0024215e0f486so549969wrd.21 for ; Mon, 28 Nov 2022 03:25:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hyKpFXOcE3toZObp9LxpSeToVua9OmUE2gMNb6lPSBw=; b=ISgeSTQ6rYkZxh6nU8YnH1BiyXSDwq9AWifYFaOmtE3JyfxWz+z2OjlFSsY6AQ2DCh cjBdYmBnMT8jHWm6JmvUiXqJPkTv1gKHXDI4QoShqmLYx9tfpf5O3zzZoSW+/3pmzbYZ 3V7ga5UMmpMqWcMMzK9nA0ZfVHTHjBtUmu0gZJH+adke9KlFAGSMLtg+BX6u09+VpcNT OJFFLjnV+n7b4bmZGTKshlC4typ2U9ZJEVLRasnJID6ETJSgageIyWD1Y9x6bdkdiZPV 6LWTTEfyG+u1xpzj2WDS+TT3eO+qEPsWRCNx1LE8EA9p1rMcoZ31SU8N356MCv76gaGU gDJw== X-Gm-Message-State: ANoB5pk8DB1mzau4U4iDLupbWstRzKfTdiGldADMMYXjDhc0g5XIiuus jH9I3jkyfSGzxhB7rhjq+jnvm7/V2BkXUsF7vibMpec8RuNkPsUnQG0c6GcLlTlii5AYYfRJTHE u2yDki0hLct0upfkAUAbCygjxAicaXLWTxXpnnCfD7nGYlKzWzrLyCXpVerd4g30kZMHqqGmHqA == X-Received: by 2002:a05:600c:5408:b0:3d0:1c3f:e3ae with SMTP id he8-20020a05600c540800b003d01c3fe3aemr27943408wmb.27.1669634743105; Mon, 28 Nov 2022 03:25:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4AA1Q2vS47397sBJJccwIFS1SpIsCnvEMagpTeh1m3j1ihTzOpGmX9Amb7oq+aE5mTeWM5Rw== X-Received: by 2002:a05:600c:5408:b0:3d0:1c3f:e3ae with SMTP id he8-20020a05600c540800b003d01c3fe3aemr27943386wmb.27.1669634742838; Mon, 28 Nov 2022 03:25:42 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id p7-20020adfe607000000b00241fea203b6sm10660525wrm.87.2022.11.28.03.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:42 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/6] gdb/remote: announce thread exit events for remote targets Date: Mon, 28 Nov 2022 11:25:33 +0000 Message-Id: <0215c520c680334efac7f0544d834ec1fb7aff8e.1669634536.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" For some reason the "[Thread XXXX exited]" messages are not printed inside thread.c from functions like delete_thread, etc as might be expected. Instead, each target seems to print the message before calling delete_thread. This doesn't seem ideal, and I can't help but feel that the printing should be moved into thread.c, however, I have not tried to do that in this commit, as I suspect there will be lots of fallout that needs fixing up. Instead, in this commit, I have added the printing code into remote.c, so that the remote target will now correctly tell the user when a thread has exited. This fixes some test failures in gdb.threads/thread-specific-bp.exp when run with the native-gdbserver and native-extended-gdbserver board. When using the native-extended-gdbserver board I still see 1 test failure, but I think this is not related to the issue fixed in this commit, so I'm ignoring that for now. --- gdb/remote.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index 5118ecd0a31..1737caa579c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -3978,6 +3978,10 @@ remote_target::update_thread_list () if (has_single_non_exited_thread (tp->inf)) continue; + if (print_thread_events) + gdb_printf (_("[%s exited]\n"), + target_pid_to_str (tp->ptid).c_str ()); + /* Not found. */ delete_thread (tp); } From patchwork Mon Nov 28 11:25:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61147 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D78038532DA for ; Mon, 28 Nov 2022 11:26:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D78038532DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669634777; bh=AGs35qvSAOThl7MF43+Ta3cyytpoWLxv4inxsHj7Ls4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=kFm85p9+Gm6gFiaH+fPwETVkC24YfruEaHfo/IqEvsrJILuhvTMp65zxpU49x76Ax oW4kBZ8rY5/lpFAy8KRjFQsrxYtu2gEWhoqbSsWGsF9140PmFsZFKs/G56sePJxm0J i+3p/YNsCfB9t7UCcihY98A/Rx89JnWHqe13PHSc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 7CAE23858C62 for ; Mon, 28 Nov 2022 11:25:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7CAE23858C62 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-278-IVgZJ45_Nm6KErH-0kQ33Q-1; Mon, 28 Nov 2022 06:25:46 -0500 X-MC-Unique: IVgZJ45_Nm6KErH-0kQ33Q-1 Received: by mail-wr1-f69.google.com with SMTP id l8-20020adfc788000000b00241ef50e89eso1792096wrg.0 for ; Mon, 28 Nov 2022 03:25:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AGs35qvSAOThl7MF43+Ta3cyytpoWLxv4inxsHj7Ls4=; b=7FTCA/QiMSsZddGiZfTW8mx/rGJ1T5FmoI6TOp299rA+abfgH6q0oA5KfnCr4R5Txr PrIctozwfm4by/KkWLtkt52gJHGVwZPK3WDS28HTt4PDR2ucANJDVY5MqxdicSNauCk2 b1Y6jLzu9cS6HNQcG5g8bO8URjsI7Zq5Vn6lGnCqsv/9dyCOjJhfEH4SL/K0XukJFg/u 316sfVbOiGihHS1/tLetw+cGOX34hW7jAqCBpkvdYGYOoIVjJDijcOntaomfvsFApmej 11CUWxZAxaVObQItZNYEdvRfJIVZa00uFlODMt2IoHKhy2IyvTDdXmAeWFGsVUYSir0m ULeg== X-Gm-Message-State: ANoB5pkBGsTVmN9FwHQuDhTEPwtagZrj1ebQ0Tb0mI8qjeMfjjp5oDAy jC4Ncq4xT8XgVBCU29KR2+yjwk8N8XuOx55ClgRPCkApxIDSv2Mg8T1y8LbMhzMCCNNNLpjpoZS zb6+iArJsFnabEShz/B8pNsluIuPNEgj+OcwOyEKzuvLHXxbtoTo/TfbekHNcNSALEPpaSmZ4+Q == X-Received: by 2002:a5d:414b:0:b0:242:b59:c3c6 with SMTP id c11-20020a5d414b000000b002420b59c3c6mr6929877wrq.91.1669634744473; Mon, 28 Nov 2022 03:25:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf40y/BBKOtcjxs3g+ua0DefT/o4LP7q+lUeB/O7/rMCzApJGL7vKchP9FaX/GAk9/OiBXQrqw== X-Received: by 2002:a5d:414b:0:b0:242:b59:c3c6 with SMTP id c11-20020a5d414b000000b002420b59c3c6mr6929856wrq.91.1669634744162; Mon, 28 Nov 2022 03:25:44 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id c12-20020adfed8c000000b00236b2804d79sm10613260wro.2.2022.11.28.03.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:43 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/6] gdb/testsuite: don't try to set non-stop mode on a running target Date: Mon, 28 Nov 2022 11:25:34 +0000 Message-Id: <4483776f267f338e1ddf759fbe47a7917f3e898f.1669634536.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The test gdb.threads/thread-specific-bp.exp tries to set non-stop mode on a running target, something which the manual makes clear is not allowed. The consequence of this is that the gdb.threads/thread-specific-bp.exp test has one failure when run with the native-extended-gdbserver board. This commit restructures the test a little, we now set the non-stop mode as part of the GDBFLAGS, so the mode will be set before GDB connects to the target. As a consequence I'm able to move the with_test_prefix out of the check_thread_specific_breakpoint proc. The check_thread_specific_breakpoint proc is now called within a loop. After this commit the gdb.threads/thread-specific-bp.exp test has zero failures for me with native-extended-gdbserver, native-gdbserver, and the unix board. --- .../gdb.threads/thread-specific-bp.exp | 138 +++++++++--------- 1 file changed, 67 insertions(+), 71 deletions(-) diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp index 863c139d6b2..dc822f37b7b 100644 --- a/gdb/testsuite/gdb.threads/thread-specific-bp.exp +++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp @@ -24,8 +24,6 @@ if {[gdb_compile_pthreads \ return -1 } -clean_restart ${binfile} - # Extract and return the thread ID of the thread stopped at function # FUNC. @@ -45,86 +43,84 @@ proc get_thread_id {func} { return $thre } -proc check_thread_specific_breakpoint {mode} { - with_test_prefix "$mode" { - global gdb_prompt +proc check_thread_specific_breakpoint {non_stop} { + global gdb_prompt - if ![runto_main] { - return -1 - } + if ![runto_main] { + return -1 + } - set main_thre [get_thread_id "main"] - if { $main_thre < 0 } { - return -1 - } + set main_thre [get_thread_id "main"] + if { $main_thre < 0 } { + return -1 + } - gdb_breakpoint "start" - gdb_continue_to_breakpoint "start" + gdb_breakpoint "start" + gdb_continue_to_breakpoint "start" - set start_thre [get_thread_id "start"] - if { $start_thre < 0 } { - return -1 - } + set start_thre [get_thread_id "start"] + if { $start_thre < 0 } { + return -1 + } - # Set a thread-specific breakpoint at "main". This can't ever - # be hit, but that's OK. - gdb_breakpoint "main thread $start_thre" - gdb_test "info break" ".*breakpoint.*thread $start_thre" "breakpoint set" - - # Set breakpoint at a place only reacheable after the "start" - # thread exits. - gdb_breakpoint "end" - - # Switch back to the main thread, and resume all threads. The - # "start" thread exits, and the main thread reaches "end". - gdb_test "thread $main_thre" \ - "Switching to thread $main_thre.*" \ - "thread $main_thre selected" - - if { $mode == "non-stop" } { - set cmd "continue -a" - } else { - set cmd "continue" - } - set test "continue to end" - set thread_exited 0 - set prompt 0 - gdb_test_multiple "$cmd" $test -lbl { - -re "(^|\r\n)\\\[Thread \[^\r\n\]* exited](?=\r\n)" { - if { $prompt } { - pass $gdb_test_name - } else { - set thread_exited 1 - exp_continue - } + # Set a thread-specific breakpoint at "main". This can't ever + # be hit, but that's OK. + gdb_breakpoint "main thread $start_thre" + gdb_test "info break" ".*breakpoint.*thread $start_thre" "breakpoint set" + + # Set breakpoint at a place only reacheable after the "start" + # thread exits. + gdb_breakpoint "end" + + # Switch back to the main thread, and resume all threads. The + # "start" thread exits, and the main thread reaches "end". + gdb_test "thread $main_thre" \ + "Switching to thread $main_thre.*" \ + "thread $main_thre selected" + + if { $non_stop } { + set cmd "continue -a" + } else { + set cmd "continue" + } + set test "continue to end" + set thread_exited 0 + set prompt 0 + gdb_test_multiple "$cmd" $test -lbl { + -re "(^|\r\n)\\\[Thread \[^\r\n\]* exited](?=\r\n)" { + if { $prompt } { + pass $gdb_test_name + } else { + set thread_exited 1 + exp_continue } - -re "\r\n$gdb_prompt " { - if { $thread_exited } { - pass $gdb_test_name - } else { - set prompt 1 - exp_continue - } + } + -re "\r\n$gdb_prompt " { + if { $thread_exited } { + pass $gdb_test_name + } else { + set prompt 1 + exp_continue } } + } - set test "thread-specific breakpoint was deleted" - gdb_test_multiple "info breakpoint" $test { - -re "thread $start_thre\n$gdb_prompt $" { - fail $test - } - -re "$gdb_prompt $" { - pass $test - } + set test "thread-specific breakpoint was deleted" + gdb_test_multiple "info breakpoint" $test { + -re "thread $start_thre\n$gdb_prompt $" { + fail $test + } + -re "$gdb_prompt $" { + pass $test } } } -# Test all-stop mode. -check_thread_specific_breakpoint "all-stop" - -clean_restart ${binfile} +foreach_with_prefix non_stop {on off} { + save_vars { GDBFLAGS } { + append GDBFLAGS " -ex \"set non-stop $non_stop\"" + clean_restart $binfile + } -# Test non-stop mode. -gdb_test_no_output "set non-stop on" "set non-stop mode" -check_thread_specific_breakpoint "non-stop" + check_thread_specific_breakpoint $non_stop +} From patchwork Mon Nov 28 11:25:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61148 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B72623857365 for ; Mon, 28 Nov 2022 11:26:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B72623857365 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669634801; bh=VWfsnpYMxgevKRVUj10nnQ6mpzJDV9Vo5VLTylsO0W0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=yoX9SJSetf8SzgYDeGwUR6PwCqSq6rs9nioBSfFlKhhnMNdLKWVJM6Des2jiJ9rXN vOLoTiq6pAchygiPJOJt9CGTnHslvRfuMkLQWzdOMf0JBEODgEKhLhvPRXKvfNdV+i fG9yRPvxtfHzWAP+tmD3m0OAEJSc1P/8/4Gbzc4g= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C8E9A3857C4F for ; Mon, 28 Nov 2022 11:25:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8E9A3857C4F 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-55-y09zF2knOIu50jr3NHQonQ-1; Mon, 28 Nov 2022 06:25:47 -0500 X-MC-Unique: y09zF2knOIu50jr3NHQonQ-1 Received: by mail-wr1-f70.google.com with SMTP id v2-20020adfa1c2000000b002420d780a32so760646wrv.14 for ; Mon, 28 Nov 2022 03:25:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VWfsnpYMxgevKRVUj10nnQ6mpzJDV9Vo5VLTylsO0W0=; b=tNKzMMld3TBepOpmQdh2l8I9uKShm5eX6r1W+tC+h8Yo4Ml9+E+wgoL5mhdqyVims7 b6T8WjfcwDNF7o0gFYluOQLg6rSEfiasq6mNnlLCrSq+VX5Df/WXWHvIjn6KyLQeCyYC TRXs17gTtaD8H98PQHELKbTOc8adAZ8T/NjyYhzCCizHqN1YnQaeIvhogE6uVnSwoI7m /bMTSROZ1TAIuYIDhGPENET9EAzBcHIdHgA6yClGiGlCqF0cPBhfYYD21pTxLxk9CQM5 xKt8ER3FVQEhiXfyZ3bR1xh92pugRAUC2xrHd+BPf3+38das1X/ZaHH1aol3BA5HUvk+ N/qQ== X-Gm-Message-State: ANoB5plHseEJBkUbqAwtRp1UldNTeI+poyektr79lsK+jXkBofAp44HK s1B2RFd1cY6PBza/elSUm5IAW9W7A+DRa4rQR2tIggbRftj842GyEV63OijfKo/lCe/4r4Oh5gG 44kB6sgzVonPsqTynzVCgW6oqDDANUqqonOlTC619WgP3blnT4kxlmxuRZqbwiUpdwXRSAh8euQ == X-Received: by 2002:a05:600c:35c4:b0:3cf:9668:e8f8 with SMTP id r4-20020a05600c35c400b003cf9668e8f8mr28133172wmq.195.1669634745914; Mon, 28 Nov 2022 03:25:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5zMIQUMgIaXKc/ej98LM6Rk7qhSSIbjSczeq3wftzmmRjPClkVh3D01T4Je8oEir64vX3uWA== X-Received: by 2002:a05:600c:35c4:b0:3cf:9668:e8f8 with SMTP id r4-20020a05600c35c400b003cf9668e8f8mr28133143wmq.195.1669634745580; Mon, 28 Nov 2022 03:25:45 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id b6-20020a05600010c600b0024217e7aaa7sm2462065wrx.50.2022.11.28.03.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:45 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/6] gdb: fix display of thread condition for multi-location breakpoints Date: Mon, 28 Nov 2022 11:25:35 +0000 Message-Id: <685ac9c3cc26e43c47b1a5fd3a59f7e97c5eca2b.1669634536.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" If a breakpoint with multiple locations has a thread condition, then the 'info breakpoints' output is a little messed up, here's an example of the current output: (gdb) break foo thread 1 Breakpoint 2 at 0x401114: foo. (3 locations) (gdb) break bar thread 1 Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y thread 1 stop only in thread 1 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 stop only in thread 1 Notice that, at the end of the location for breakpoint 3, the 'thread 1' condition is printed. In contrast, for breakpoint 2, the 'thread 1' appears randomly, in the "What" column, though slightly offset. I believe this is a bug in GDB, in the function print_one_breakpoint_location, due to checking the local variable part_of_multiple, instead of header_of_multiple. If I fix this oversight, then the output is now: (gdb) break foo thread 1 Breakpoint 2 at 0x401114: foo. (3 locations) (gdb) break bar thread 1 Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y stop only in thread 1 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 stop only in thread 1 The 'thread 1' condition is now displayed at the end of each location, which makes the output the same for single location breakpoints and multi-location breakpoints. --- gdb/breakpoint.c | 2 +- gdb/testsuite/gdb.base/thread-bp-multi-loc.c | 44 ++++++++++ .../gdb.base/thread-bp-multi-loc.exp | 88 +++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/thread-bp-multi-loc.c create mode 100644 gdb/testsuite/gdb.base/thread-bp-multi-loc.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index f0276a963c0..2ec8ca364b6 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6467,7 +6467,7 @@ print_one_breakpoint_location (struct breakpoint *b, output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); } - if (!part_of_multiple) + if (!header_of_multiple) { if (b->thread != -1) { diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.c b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c new file mode 100644 index 00000000000..cab009c39ec --- /dev/null +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +volatile int global_var = 0; + +__attribute__((__always_inline__)) static inline void +foo (void) +{ + int i; + + for (i = 0; i < 10; ++i) + global_var = i; +} + +static void +bar (void) +{ + global_var = 0; + foo (); +} + +int +main (void) +{ + global_var = 0; + foo (); + bar (); + foo (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp new file mode 100644 index 00000000000..9abff5866d9 --- /dev/null +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp @@ -0,0 +1,88 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Create a multi-location breakpoint with a thread condition, then check the +# output of 'info breakpoints' to ensure that the thread condition is +# displayed correctly. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return +} + +if ![runto_main] then { + return +} + +gdb_test_no_output "with confirm off -- delete breakpoints" + +set bp_number "" +gdb_test_multiple "break foo thread 1" "" { + -re "^break foo thread 1\r\n" { + exp_continue + } + -re "^Breakpoint ($decimal) at $hex: foo\[^\r\n\]+3 locations\[^\r\n\]+\r\n" { + set bp_number $expect_out(1,string) + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { ![string eq $bp_number ""] } + } +} + +if { $bp_number == "" } { + unresolved "breakpoint not placed correctly" + return +} + +set saw_header false +set saw_cond false +set loc_count 0 +gdb_test_multiple "info breakpoints" "" { + -re "^info breakpoints\r\n" { + exp_continue + } + + -re "^Num\\s+\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^$bp_number\\s+breakpoint\\s+keep\\s+y\\s+\\s*\r\n" { + set saw_header true + exp_continue + } + + -re "^\\s+stop only in thread 1\r\n" { + set saw_cond true + exp_continue + } + + -re "^$bp_number\\.\[123\]\\s+\[^\r\n\]+ thread 1\r\n" { + incr loc_count + exp_continue + } + + -re "^$gdb_prompt $" { + with_test_prefix $gdb_test_name { + gdb_assert { $saw_header } \ + "saw header line" + gdb_assert { $saw_cond } \ + "saw b/p condition line" + gdb_assert { $loc_count == 3 } \ + "saw all three locations" + } + } +} From patchwork Mon Nov 28 11:25:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61149 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57C6D3858004 for ; Mon, 28 Nov 2022 11:27:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57C6D3858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669634830; bh=xSFKnJxly2El5OxWzNp/KbJ5b+cn6y8Nke/cx3aq1og=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=jAZx1jBSFLHJ0YGLQlWOCxmRnTHLO3T0T9HZXR/+QxL/x+duALoLp/Sc6Fff+aAcR lxpnhFPmzirdKXkSfWX/WpgMxGLTMM7d/wn4EsLI/PdsNEcN2z2MjM+GQw9q0LDVhK vEjFpiHYoir0VJ6eM6LIk7HJXstzJNHigkB7g8Do= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4C6ED385782B for ; Mon, 28 Nov 2022 11:25:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C6ED385782B 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-59-zZT27EohM_ybZoH1gqN3uQ-1; Mon, 28 Nov 2022 06:25:48 -0500 X-MC-Unique: zZT27EohM_ybZoH1gqN3uQ-1 Received: by mail-wr1-f70.google.com with SMTP id m24-20020adfa3d8000000b00242168ce9d1so525308wrb.15 for ; Mon, 28 Nov 2022 03:25:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xSFKnJxly2El5OxWzNp/KbJ5b+cn6y8Nke/cx3aq1og=; b=xxx5urVZv2dv6fr8epOoT+JfR1/zp4cp1sSRA7LjxN/tUJOxJv5jjTCjhHeuhPC4I/ wElWCXi5wyPJxkqgwsoBZHhZBGrXrio0FZ2/esl08gFGC69veuUJKx9RvshUmuSbgDwG bH5MJoH7APrjKDEhYg9hZENhrfgJEBm2ocJuBjeb/cflpyzBTPMGMqmaSQyUK/7cvMme WwDaGr+4BRb7nefrru861KEOAii1KPuU2gTtOG7a6fM3zrNd01JpuCINhKmRRuwNdiZz jStrcAJ1sYrVyJFiCagerOwIx8h8PIwKcKFDneJNitudPy7gCZucpW6PHHpx92vxqxJd Zo6Q== X-Gm-Message-State: ANoB5pkzwB3/+AthbNirFr6GUZfjj6PnIOD52VTJxll+ZPdRfIwkAYt6 SJqOZo0cTL94O70dyt186LaGYcdq28PcANq6sCICJqbBlP9qyUlXE/Ju7JIga5HLBExT5PPfgo1 O4TfdbfjCPnrxbgjc32esZB5a6eZrHabQ7B4Mrg/6zxomqACBUnB9M2BxYxR67aiwFcPMhdzvrQ == X-Received: by 2002:a5d:526b:0:b0:242:380:c10e with SMTP id l11-20020a5d526b000000b002420380c10emr10522876wrc.132.1669634747327; Mon, 28 Nov 2022 03:25:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf7es/rb1URRWjPOVmyoQnliVySHSazg+PKrtF8QbMUxv+0745EwRJklVjHVbpTNAiEHfYCkKw== X-Received: by 2002:a5d:526b:0:b0:242:380:c10e with SMTP id l11-20020a5d526b000000b002420380c10emr10522859wrc.132.1669634747056; Mon, 28 Nov 2022 03:25:47 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id p1-20020a1c5441000000b003b4cba4ef71sm18507788wmi.41.2022.11.28.03.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:46 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 4/6] gdb: error if 'thread' or 'task' keywords are overused Date: Mon, 28 Nov 2022 11:25:36 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When creating a breakpoint or watchpoint, the 'thread' and 'task' keywords can be used to create a thread or task specific breakpoint or watchpoint. Currently, a thread or task specific breakpoint can only apply for a single thread or task, if multiple threads or tasks are specified when creating the breakpoint (or watchpoint), then the last specified id will be used. The exception to the above is that when the 'thread' keyword is used during the creation of a watchpoint, GDB will give an error if 'thread' is given more than once. In this commit I propose making this behaviour consistent, if the 'thread' or 'task' keywords are used more than once when creating either a breakpoint or watchpoint, then GDB will give an error. I haven't updated the manual, we don't explicitly say that these keywords can be repeated, and (to me), given the keyword takes a single id, I don't think it makes much sense to repeat the keyword. As such, I see this more as adding a missing error to GDB, rather than making some big change. However, I have added an entry to the NEWS file as I guess it is possible that some people might hit this new error with an existing (I claim, badly written) GDB script. I've added some new tests to check for the new error. Just one test needed updating, gdb.linespec/keywords.exp, this test did use the 'thread' keyword twice, and expected the breakpoint to be created. Looking at what this test was for though, it was checking the use of '-force-condition', and I don't think that being able to repeat 'thread' was actually a critical part of this test. As such, I've updated this test to expect the error when 'thread' is repeated. --- gdb/NEWS | 9 +++++++++ gdb/breakpoint.c | 9 +++++++++ gdb/testsuite/gdb.ada/tasks.exp | 4 ++++ gdb/testsuite/gdb.linespec/keywords.exp | 10 ++++++++-- gdb/testsuite/gdb.threads/thread-specific-bp.exp | 4 ++++ gdb/testsuite/gdb.threads/watchthreads2.exp | 3 +++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index dddef6525de..1f2233082ae 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -101,6 +101,15 @@ (gdb) disable $_hit_bpnum are both disabling the breakpoint. +* For the break command, multiple uses of the 'thread' or 'task' + keywords will now given an error instead of just using the thread or + task id from the last instance of the keyword. + +* For the watch command, multiple uses of the 'task' keyword will now + given an error instead of just using the task id from the last + instance of the keyword. The 'thread' keyword already gave an error + when used multiple times with the watch command. + * New commands maintenance set ignore-prologue-end-flag on|off diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 2ec8ca364b6..bf99297a250 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8793,6 +8793,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, const char *tmptok; struct thread_info *thr; + if (*thread != -1) + error(_("You can specify only one thread.")); + tok = end_tok + 1; thr = parse_thread_id (tok, &tmptok); if (tok == tmptok) @@ -8804,6 +8807,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, { char *tmptok; + if (*task != 0) + error(_("You can specify only one task.")); + tok = end_tok + 1; *task = strtol (tok, &tmptok, 0); if (tok == tmptok) @@ -10086,6 +10092,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, { char *tmp; + if (task != 0) + error(_("You can specify only one task.")); + task = strtol (value_start, &tmp, 0); if (tmp == value_start) error (_("Junk after task keyword.")); diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp index 2ca03396d7c..c2ab6c6724d 100644 --- a/gdb/testsuite/gdb.ada/tasks.exp +++ b/gdb/testsuite/gdb.ada/tasks.exp @@ -39,6 +39,10 @@ gdb_test "info tasks" \ "\r\n"] \ "info tasks before inserting breakpoint" +# Check that multiple uses of the 'task' keyword will give an error. +gdb_test "break break_me task 1 task 3" "You can specify only one task\\." +gdb_test "watch j task 1 task 3" "You can specify only one task\\." + # Insert a breakpoint that should stop only if task 1 stops. Since # task 1 never calls break_me, this shouldn't actually ever trigger. # The fact that this breakpoint is created _before_ the next one diff --git a/gdb/testsuite/gdb.linespec/keywords.exp b/gdb/testsuite/gdb.linespec/keywords.exp index 94536df4670..dca854d3f59 100644 --- a/gdb/testsuite/gdb.linespec/keywords.exp +++ b/gdb/testsuite/gdb.linespec/keywords.exp @@ -80,8 +80,14 @@ foreach prefix {"" "thread 1 "} { foreach suffix {"" " " " thread 1"} { foreach cond {"" " if 1"} { with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" { - gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ - "message" + + if { [regexp thread $prefix] && [regexp thread $suffix] } { + gdb_test "break main ${prefix}-force-condition${suffix}${cond}" \ + "You can specify only one thread\\." + } else { + gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ + "message" + } } } } diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp index dc822f37b7b..a300f3ef7ab 100644 --- a/gdb/testsuite/gdb.threads/thread-specific-bp.exp +++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp @@ -63,6 +63,10 @@ proc check_thread_specific_breakpoint {non_stop} { return -1 } + # Check that multiple uses of 'thread' keyword give an error. + gdb_test "break main thread $start_thre thread $main_thre" \ + "You can specify only one thread\\." + # Set a thread-specific breakpoint at "main". This can't ever # be hit, but that's OK. gdb_breakpoint "main thread $start_thre" diff --git a/gdb/testsuite/gdb.threads/watchthreads2.exp b/gdb/testsuite/gdb.threads/watchthreads2.exp index 2c18b20257c..ef502507f9f 100644 --- a/gdb/testsuite/gdb.threads/watchthreads2.exp +++ b/gdb/testsuite/gdb.threads/watchthreads2.exp @@ -73,6 +73,9 @@ if { $nr_started == $NR_THREADS } { return -1 } +# Check that multiple uses of the 'thread' keyword will give an error. +gdb_test "watch x thread 1 thread 2" "You can specify only one thread\\." + # Watch X, it will be modified by all threads. # We want this watchpoint to be set *after* all threads are running. gdb_test "watch x" "Hardware watchpoint 3: x" From patchwork Mon Nov 28 11:25:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61151 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 013D2385B190 for ; Mon, 28 Nov 2022 11:28:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 013D2385B190 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669634887; bh=KBJdQyLcK3+SwCqClGbqodlt1uONMHyBFrYdyBRvcpc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fb6exnqf+PSKoE3Ojb50yanYrH1An5DofAqDIUnFEb2TyJMJnjFKq9UyCylF/U/b4 9sXSZ8bifzaHireFFheUOjDUt5rP3pgZpqRlm/mSsXkJsonc4ZCAoq4oCBhKGsDzzI 7gCbC/Hf/Hdf0YZR1/tMvLWjvVDB3jd49scZcA8M= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 E0ABB385B535 for ; Mon, 28 Nov 2022 11:25:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0ABB385B535 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-244-yf8s_O33Nwa68-g6qO_MWA-1; Mon, 28 Nov 2022 06:25:52 -0500 X-MC-Unique: yf8s_O33Nwa68-g6qO_MWA-1 Received: by mail-wm1-f71.google.com with SMTP id c1-20020a7bc001000000b003cfe40fca79so3606717wmb.6 for ; Mon, 28 Nov 2022 03:25:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KBJdQyLcK3+SwCqClGbqodlt1uONMHyBFrYdyBRvcpc=; b=K0SOIsqPrfu3mhYohpgFGAoNg3JWSKPD/wEOTZgzy0tHTLdgTxwY5AZ1S60Ub3MmfZ mEqiAJiSasCsm0xhqK9T0RMITtara4mq837AdC5zGqnzOSabHAnps6KjtNsyn2L11jay 7IKh6Sii1Gej9WAjRbMkbMmRsbcLUuJBEYJDuMwLb98ylZJ0WfKJNRbhbhacIhyeRLJR cNfoVuOglHUCm3He1rN196fhgCKDCB6gS4B1piH3zLDx37ogAHMGSaoIe5UNmKtNx3m/ Tw632TH/AIeQ7ee+YxNYdGhNAlImb6Gk2ci7CRoES63lNk7STfEFJSQdKGuobam0jab7 qcHw== X-Gm-Message-State: ANoB5pk7NYqwlVshdWbYMkySHlqeyZKHYBKEbqxMeLAlxWaAzuRCE6EY 2ZzdtVOzwZU3gqPh0RK2LAfxCAI9oOeA72Db4uUNwzwR5Ta9TfsFHlB7+Q/yTvRkpnx3yAxpKMT rneGkKkdbaeGpqwAYca1ZUUSliua5rU+qD/nm/pdgusXYlheerm5rvLMM7h2ICF3J6SSWyLoX4Q == X-Received: by 2002:a05:600c:21c8:b0:3c6:d9f0:9534 with SMTP id x8-20020a05600c21c800b003c6d9f09534mr22516329wmj.101.1669634750034; Mon, 28 Nov 2022 03:25:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf46BfwbOaUPNApvU7cUcEVqiZ8/lADsi8rC51pFLUJD1GQdGFGZ442eaHExQglnw7DoFGd1Sg== X-Received: by 2002:a05:600c:21c8:b0:3c6:d9f0:9534 with SMTP id x8-20020a05600c21c800b003c6d9f09534mr22516247wmj.101.1669634748524; Mon, 28 Nov 2022 03:25:48 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id t13-20020a5d690d000000b002366e8eee11sm10503422wru.101.2022.11.28.03.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:48 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 5/6] gdb: add inferior-specific breakpoints and watchpoints Date: Mon, 28 Nov 2022 11:25:37 +0000 Message-Id: <0d3144a162d93c2b7d409234bd199e3c9fbbfce8.1669634536.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit extends the breakpoint mechanism to allow for inferior specific breakpoints (and watchpoints). As GDB gains better support for multiple connections, and so for running multiple (possibly unrelated) inferiors, then it is not hard to imagine that a user might wish to create breakpoints that apply to any thread in a single inferior. To achieve this currently, the user would need to create a condition possibly making use of the $_inferior convenience variable, which, though functional, isn't the most user friendly. This commit adds a new 'inferior' keyword that allows for the creation of inferior specific breakpoints. Like thread specific breakpoints, the inferior specific breakpoints are automatically deleted once the inferior in question exits. --- gdb/NEWS | 7 + gdb/breakpoint.c | 177 ++++++++++++++--- gdb/breakpoint.h | 10 +- gdb/doc/gdb.texinfo | 74 ++++++- gdb/doc/python.texi | 27 ++- gdb/dummy-frame.c | 1 + gdb/elfread.c | 5 +- gdb/guile/scm-breakpoint.c | 5 + gdb/inferior.h | 10 + gdb/infrun.c | 2 + gdb/linespec.c | 4 +- gdb/python/py-breakpoint.c | 77 ++++++++ gdb/testsuite/gdb.linespec/cpcompletion.exp | 4 +- gdb/testsuite/gdb.linespec/explicit.exp | 1 + .../gdb.multi/inferior-specific-bp-1.c | 52 +++++ .../gdb.multi/inferior-specific-bp-2.c | 52 +++++ .../gdb.multi/inferior-specific-bp.exp | 183 ++++++++++++++++++ gdb/testsuite/gdb.python/py-breakpoint.exp | 43 ++++ gdb/testsuite/lib/completion-support.exp | 2 +- 19 files changed, 688 insertions(+), 48 deletions(-) create mode 100644 gdb/testsuite/gdb.multi/inferior-specific-bp-1.c create mode 100644 gdb/testsuite/gdb.multi/inferior-specific-bp-2.c create mode 100644 gdb/testsuite/gdb.multi/inferior-specific-bp.exp diff --git a/gdb/NEWS b/gdb/NEWS index 1f2233082ae..f3cb0f96f67 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -110,6 +110,13 @@ instance of the keyword. The 'thread' keyword already gave an error when used multiple times with the watch command. +* Breakpoints can now be inferior-specific. This is similar to the + existing thread-specific breakpoint support. Breakpoint conditions + can include the 'inferior' keyword followed by an inferior id (as + displayed in the 'info inferiors' output). It is invalid to use + both the 'inferior' and 'thread' keywords when creating a + breakpoint. + * New commands maintenance set ignore-prologue-end-flag on|off diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index bf99297a250..307f4e7720f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -96,7 +96,7 @@ static void create_breakpoints_sal (struct gdbarch *, gdb::unique_xmalloc_ptr, gdb::unique_xmalloc_ptr, enum bptype, - enum bpdisp, int, int, + enum bpdisp, int, int, int, int, int, int, int, unsigned); @@ -1462,11 +1462,28 @@ breakpoint_set_thread (struct breakpoint *b, int thread) { int old_thread = b->thread; + gdb_assert (thread == -1 || b->inferior == -1); + b->thread = thread; if (old_thread != thread) gdb::observers::breakpoint_modified.notify (b); } +/* Set the inferior for breakpoint B to INFERIOR. If INFERIOR is -1, make + the breakpoint work for any inferior. */ + +void +breakpoint_set_inferior (struct breakpoint *b, int inferior) +{ + int old_inferior = b->inferior; + + gdb_assert (inferior == -1 || b->thread == -1); + + b->inferior = inferior; + if (old_inferior != inferior) + gdb::observers::breakpoint_modified.notify (b); +} + /* Set the task for this breakpoint. If TASK is 0, make the breakpoint work for any task. */ @@ -3151,6 +3168,12 @@ insert_breakpoint_locations (void) && !valid_global_thread_id (bl->owner->thread)) continue; + /* Or inferior specific breakpoints if the inferior no longer + exists. */ + if (bl->owner->inferior != -1 + && !valid_global_inferior_id (bl->owner->inferior)) + continue; + switch_to_program_space_and_thread (bl->pspace); /* For targets that support global breakpoints, there's no need @@ -3255,6 +3278,32 @@ Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\ } } +/* Called when inferior INF has exited. Remove per-inferior breakpoints. */ + +static void +remove_inferior_breakpoints (struct inferior *inf) +{ + for (breakpoint *b : all_breakpoints_safe ()) + { + if (b->inferior == inf->num && user_breakpoint_p (b)) + { + /* Tell the user the breakpoint has been deleted. But only for + breakpoints that would not normally have been deleted at the + next stop anyway. */ + if (b->disposition != disp_del + && b->disposition != disp_del_at_next_stop) + gdb_printf (_("\ +Inferior-specific breakpoint %d deleted - inferior %d has exited.\n"), + b->number, inf->num); + + + /* Hide it from the user and mark it for deletion. */ + b->number = 0; + b->disposition = disp_del_at_next_stop; + } + } +} + /* See breakpoint.h. */ void @@ -5464,6 +5513,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) evaluating the condition if this isn't the specified thread/task. */ if ((b->thread != -1 && b->thread != thread->global_num) + || (b->inferior != -1 && b->inferior != thread->inf->num) || (b->task != 0 && b->task != ada_get_task_number (thread))) { infrun_debug_printf ("incorrect thread or task, not stopping"); @@ -6481,6 +6531,11 @@ print_one_breakpoint_location (struct breakpoint *b, uiout->text (" task "); uiout->field_signed ("task", b->task); } + else if (b->inferior != -1) + { + uiout->text (" inferior "); + uiout->field_signed ("inferior", b->inferior); + } } uiout->text ("\n"); @@ -6535,7 +6590,14 @@ print_one_breakpoint_location (struct breakpoint *b, } uiout->text ("\n"); } - + + if (!part_of_multiple && b->inferior != -1) + { + uiout->text ("\tstop only in inferior "); + uiout->field_signed ("inferior", b->inferior); + uiout->text ("\n"); + } + if (!part_of_multiple) { if (b->hit_count) @@ -7508,7 +7570,10 @@ delete_longjmp_breakpoint (int thread) if (b->type == bp_longjmp || b->type == bp_exception) { if (b->thread == thread) - delete_breakpoint (b); + { + gdb_assert (b->inferior == -1); + delete_breakpoint (b); + } } } @@ -7519,7 +7584,10 @@ delete_longjmp_breakpoint_at_next_stop (int thread) if (b->type == bp_longjmp || b->type == bp_exception) { if (b->thread == thread) - b->disposition = disp_del_at_next_stop; + { + gdb_assert (b->inferior == -1); + b->disposition = disp_del_at_next_stop; + } } } @@ -7572,6 +7640,7 @@ check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) ALL_BREAKPOINTS_SAFE (b, b_tmp) if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) { + gdb_assert (b->inferior == -1); struct breakpoint *dummy_b = b->related_breakpoint; /* Find the bp_call_dummy breakpoint in the list of breakpoints @@ -8404,7 +8473,8 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_, gdb::unique_xmalloc_ptr cond_string_, gdb::unique_xmalloc_ptr extra_string_, enum bpdisp disposition_, - int thread_, int task_, int ignore_count_, + int thread_, int task_, int inferior_, + int ignore_count_, int from_tty, int enabled_, unsigned flags, int display_canonical_) @@ -8430,6 +8500,11 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_, thread = thread_; task = task_; + inferior = inferior_; + + /* A breakpoint can be thread specific, or inferior specific, but not + both. This should be checked when the breakpoint condition is parsed. */ + gdb_assert (!(thread != -1 && inferior != -1)); cond_string = std::move (cond_string_); extra_string = std::move (extra_string_); @@ -8531,7 +8606,7 @@ create_breakpoint_sal (struct gdbarch *gdbarch, gdb::unique_xmalloc_ptr cond_string, gdb::unique_xmalloc_ptr extra_string, enum bptype type, enum bpdisp disposition, - int thread, int task, int ignore_count, + int thread, int task, int inferior, int ignore_count, int from_tty, int enabled, int internal, unsigned flags, int display_canonical) @@ -8545,7 +8620,7 @@ create_breakpoint_sal (struct gdbarch *gdbarch, std::move (cond_string), std::move (extra_string), disposition, - thread, task, ignore_count, + thread, task, inferior, ignore_count, from_tty, enabled, flags, display_canonical); @@ -8574,7 +8649,8 @@ create_breakpoints_sal (struct gdbarch *gdbarch, gdb::unique_xmalloc_ptr cond_string, gdb::unique_xmalloc_ptr extra_string, enum bptype type, enum bpdisp disposition, - int thread, int task, int ignore_count, + int thread, int task, int inferior, + int ignore_count, int from_tty, int enabled, int internal, unsigned flags) { @@ -8598,7 +8674,7 @@ create_breakpoints_sal (struct gdbarch *gdbarch, std::move (cond_string), std::move (extra_string), type, disposition, - thread, task, ignore_count, + thread, task, inferior, ignore_count, from_tty, enabled, internal, flags, canonical->special_display); } @@ -8728,21 +8804,26 @@ check_fast_tracepoint_sals (struct gdbarch *gdbarch, } } -/* Given TOK, a string specification of condition and thread, as - accepted by the 'break' command, extract the condition - string and thread number and set *COND_STRING and *THREAD. - PC identifies the context at which the condition should be parsed. - If no condition is found, *COND_STRING is set to NULL. - If no thread is found, *THREAD is set to -1. */ +/* Given TOK, a string specification of condition and thread, as accepted + by the 'break' command, extract the condition string into *COND_STRING. + If no condition string is found then *COND_STRING is set to nullptr. + + If the breakpoint specification has an associated thread, task, or + inferior, these are extracted into *THREAD, *TASK, and *INFERIOR + respectively, otherwise these arguments are set to -1 (for THREAD and + INFERIOR) or 0 (for TASK). + + PC identifies the context at which the condition should be parsed. */ static void find_condition_and_thread (const char *tok, CORE_ADDR pc, gdb::unique_xmalloc_ptr *cond_string, - int *thread, int *task, + int *thread, int *inferior, int *task, gdb::unique_xmalloc_ptr *rest) { cond_string->reset (); *thread = -1; + *inferior = -1; *task = 0; rest->reset (); bool force = false; @@ -8759,7 +8840,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, if ((*tok == '"' || *tok == ',') && rest) { rest->reset (savestring (tok, strlen (tok))); - return; + break; } end_tok = skip_to_space (tok); @@ -8803,6 +8884,18 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, *thread = thr->global_num; tok = tmptok; } + else if (toklen >= 1 && strncmp (tok, "inferior", toklen) == 0) + { + char *tmptok; + + tok = end_tok + 1; + *inferior = strtol (tok, &tmptok, 0); + if (tok == tmptok) + error (_("Junk after inferior keyword.")); + if (!valid_global_inferior_id (*inferior)) + error (_("Unknown inferior number %d."), *inferior); + tok = tmptok; + } else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) { char *tmptok; @@ -8821,11 +8914,15 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, else if (rest) { rest->reset (savestring (tok, strlen (tok))); - return; + break; } else error (_("Junk at end of arguments.")); } + + if (*thread != -1 && *inferior != -1) + error (_("Invalid use of both 'thread' and 'inferior' in " + "breakpoint condition")); } /* Call 'find_condition_and_thread' for each sal in SALS until a parse @@ -8837,7 +8934,7 @@ static void find_condition_and_thread_for_sals (const std::vector &sals, const char *input, gdb::unique_xmalloc_ptr *cond_string, - int *thread, int *task, + int *thread, int *inferior, int *task, gdb::unique_xmalloc_ptr *rest) { int num_failures = 0; @@ -8845,6 +8942,7 @@ find_condition_and_thread_for_sals (const std::vector &sals, { gdb::unique_xmalloc_ptr cond; int thread_id = 0; + int inferior_id = 0; int task_id = 0; gdb::unique_xmalloc_ptr remaining; @@ -8857,9 +8955,10 @@ find_condition_and_thread_for_sals (const std::vector &sals, try { find_condition_and_thread (input, sal.pc, &cond, &thread_id, - &task_id, &remaining); + &inferior_id, &task_id, &remaining); *cond_string = std::move (cond); *thread = thread_id; + *inferior = inferior_id; *task = task_id; *rest = std::move (remaining); break; @@ -8961,6 +9060,7 @@ create_breakpoint (struct gdbarch *gdbarch, struct linespec_result canonical; bool pending = false; int task = 0; + int inferior = -1; int prev_bkpt_count = breakpoint_count; gdb_assert (ops != NULL); @@ -9038,7 +9138,8 @@ create_breakpoint (struct gdbarch *gdbarch, const linespec_sals &lsal = canonical.lsals[0]; find_condition_and_thread_for_sals (lsal.sals, extra_string, - &cond, &thread, &task, &rest); + &cond, &thread, &inferior, + &task, &rest); cond_string_copy = std::move (cond); extra_string_copy = std::move (rest); } @@ -9088,7 +9189,7 @@ create_breakpoint (struct gdbarch *gdbarch, std::move (extra_string_copy), type_wanted, tempflag ? disp_del : disp_donttouch, - thread, task, ignore_count, + thread, task, inferior, ignore_count, from_tty, enabled, internal, flags); } else @@ -10028,6 +10129,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, const char *cond_end = NULL; enum bptype bp_type; int thread = -1; + int inferior = -1; /* Flag to indicate whether we are going to use masks for the hardware watchpoint. */ bool use_mask = false; @@ -10068,6 +10170,10 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, tok++; toklen = end_tok - tok + 1; + if (thread != -1 && inferior != -1) + error (_("Invalid use of both 'thread' and 'inferior' in " + "watchpoint condition")); + if (toklen == 6 && startswith (tok, "thread")) { struct thread_info *thr; @@ -10081,10 +10187,8 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, /* Extract the thread ID from the next token. */ thr = parse_thread_id (value_start, &endp); - - /* Check if the user provided a valid thread ID. */ - if (*endp != ' ' && *endp != '\t' && *endp != '\0') - invalid_thread_id_error (value_start); + if (value_start == endp) + error (_("Junk after thread keyword.")); thread = thr->global_num; } @@ -10101,6 +10205,16 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, if (!valid_task_id (task)) error (_("Unknown task %d."), task); } + else if (toklen == 8 && startswith (tok, "inferior")) + { + char *tmp; + + inferior = strtol (value_start, &tmp, 0); + if (tmp == value_start) + error (_("Junk after inferior keyword.")); + if (!valid_global_inferior_id (inferior)) + error (_("Unknown inferior number %d."), inferior); + } else if (toklen == 4 && startswith (tok, "mask")) { /* We've found a "mask" token, which means the user wants to @@ -10271,6 +10385,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, w.reset (new watchpoint (nullptr, bp_type)); w->thread = thread; + w->inferior = inferior; w->task = task; w->disposition = disp_donttouch; w->pspace = current_program_space; @@ -12182,7 +12297,8 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, enum bptype type_wanted, enum bpdisp disposition, int thread, - int task, int ignore_count, + int task, int inferior, + int ignore_count, int from_tty, int enabled, int internal, unsigned flags) { @@ -12208,7 +12324,7 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, std::move (cond_string), std::move (extra_string), disposition, - thread, task, ignore_count, + thread, task, inferior, ignore_count, from_tty, enabled, flags, canonical->special_display)); @@ -12841,10 +12957,11 @@ code_breakpoint::location_spec_to_sals (location_spec *locspec, if (condition_not_parsed && extra_string != NULL) { gdb::unique_xmalloc_ptr local_cond, local_extra; - int local_thread, local_task; + int local_thread, local_task, local_inferior; find_condition_and_thread_for_sals (sals, extra_string.get (), &local_cond, &local_thread, + &local_inferior, &local_task, &local_extra); gdb_assert (cond_string == nullptr); if (local_cond != nullptr) @@ -14930,4 +15047,6 @@ This is useful for formatted output in user-defined commands.")); "breakpoint"); gdb::observers::thread_exit.attach (remove_threaded_breakpoints, "breakpoint"); + gdb::observers::inferior_exit.attach (remove_inferior_breakpoints, + "breakpoint"); } diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index f7633d29cbf..7ee914ef1bd 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -584,7 +584,7 @@ struct breakpoint_ops struct linespec_result *, gdb::unique_xmalloc_ptr, gdb::unique_xmalloc_ptr, - enum bptype, enum bpdisp, int, int, + enum bptype, enum bpdisp, int, int, int, int, int, int, int, unsigned); }; @@ -801,6 +801,10 @@ struct breakpoint care. */ int thread = -1; + /* Inferior number for inferior-specific breakpoint, or -1 if this + breakpoint is for all inferiors. */ + int inferior = -1; + /* Ada task number for task-specific breakpoint, or 0 if don't care. */ int task = 0; @@ -856,7 +860,7 @@ struct code_breakpoint : public breakpoint gdb::unique_xmalloc_ptr cond_string, gdb::unique_xmalloc_ptr extra_string, enum bpdisp disposition, - int thread, int task, int ignore_count, + int thread, int task, int inferior, int ignore_count, int from_tty, int enabled, unsigned flags, int display_canonical); @@ -1668,6 +1672,8 @@ extern void breakpoint_set_silent (struct breakpoint *b, int silent); extern void breakpoint_set_thread (struct breakpoint *b, int thread); +extern void breakpoint_set_inferior (struct breakpoint *b, int inferior); + extern void breakpoint_set_task (struct breakpoint *b, int task); /* Clear the "inserted" flag in all breakpoints. */ diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index bababf3c7ff..5cf6c43393f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -3500,6 +3500,58 @@ space as a result of inferior 1 having executed a @code{vfork} call. @end table +@menu +* Inferior-Specific Breakpoints:: Controlling breakpoints +@end menu + +@node Inferior-Specific Breakpoints +@subsection Inferior-Specific Breakpoints + +When debugging multiple inferiors, you can choose whether to set +breakpoints for all inferiors, or for a particular inferior. + +@table @code +@cindex breakpoints and inferiors +@cindex inferior breakpoints +@kindex break @dots{} inferior @var{inferior-id} +@item break @var{locspec} inferior @var{inferior-id} +@itemx break @var{locspec} inferior @var{inferior-id} if @dots{} +@var{locspec} specifies a code location or locations in your program. +@xref{Location Specifications}, for details. + +Use the qualifier @samp{inferior @var{inferior-id}} with a breakpoint +command to specify that you only want @value{GDBN} to stop when a +particular inferior reaches this breakpoint. The @var{inferior-id} +specifier is one of the inferior identifiers assigned by @value{GDBN}, +shown in the first column of the @samp{info inferiors} output. + +If you do not specify @samp{inferior @var{inferior-id}} when you set a +breakpoint, the breakpoint applies to @emph{all} inferiors of your +program. + +You can use the @code{inferior} qualifier on conditional breakpoints as +well; in this case, place @samp{inferior @var{inferior-id}} before or +after the breakpoint condition, like this: + +@smallexample +(@value{GDBP}) break frik.c:13 inferior 2 if bartab > lim +@end smallexample +@end table + +Inferior-specific breakpoints are automatically deleted when +@value{GDBN} detects the corresponding inferior has exited. For +example: + +@smallexample +(@value{GDBP}) c +Inferior-specific breakpoint 3 deleted - inferior 2 has exited. +@end smallexample + +A breakpoint can't be both inferior-specific and thread-specific +(@pxref{Thread-Specific Breakpoints}) using both the @code{inferior} +and @code{thread} keywords when creating a breakpoint will give an +error. + @node Threads @section Debugging Programs with Multiple Threads @@ -4462,8 +4514,9 @@ situation. It is also possible to insert a breakpoint that will stop the program -only if a specific thread (@pxref{Thread-Specific Breakpoints}) -or a specific task (@pxref{Ada Tasks}) hits that breakpoint. +only if a specific thread (@pxref{Thread-Specific Breakpoints}), +specific inferior (@pxref{Inferior-Specific Breakpoints}), or a +specific task (@pxref{Ada Tasks}) hits that breakpoint. @item break When called without any arguments, @code{break} sets a breakpoint at @@ -4979,7 +5032,7 @@ @table @code @kindex watch -@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]} @r{[}task @var{task-id}@r{]} +@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}inferior @var{inferior-id}@r{]} @r{[}mask @var{maskvalue}@r{]} @r{[}task @var{task-id}@r{]} Set a watchpoint for an expression. @value{GDBN} will break when the expression @var{expr} is written into by the program and its value changes. The simplest (and the most popular) use of this command is @@ -4996,8 +5049,10 @@ that watchpoints restricted to a single thread in this way only work with Hardware Watchpoints. -Similarly, if the @code{task} argument is given, then the watchpoint -will be specific to the indicated Ada task (@pxref{Ada Tasks}). +Similarly, if the @code{inferior} argument is given, then the +watchpoint will trigger only for the specific inferior, or if the +@code{task} argument is given, then the watchpoint will be specific to +the indicated Ada task (@pxref{Ada Tasks}). Ordinarily a watchpoint respects the scope of variables in @var{expr} (see below). The @code{-location} argument tells @value{GDBN} to @@ -5026,12 +5081,12 @@ @end smallexample @kindex rwatch -@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]} +@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}inferior @var{inferior-id}@r{]} @r{[}mask @var{maskvalue}@r{]} Set a watchpoint that will break when the value of @var{expr} is read by the program. @kindex awatch -@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]} +@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}inferior @var{inferior-id}@r{]} @r{[}mask @var{maskvalue}@r{]} Set a watchpoint that will break when @var{expr} is either read from or written into by the program. @@ -7313,6 +7368,11 @@ explictly asks for the thread list with the @code{info threads} command. +A breakpoint can't be both thread-specific and inferior-specific +(@pxref{Inferior-Specific Breakpoints}) using both the @code{thread} +and @code{inferior} keywords when creating a breakpoint will give an +error. + @node Interrupted System Calls @subsection Interrupted System Calls diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 9cbb2f9f57d..396d0f7f7af 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3281,7 +3281,9 @@ A @code{gdb.Inferior} object has the following attributes: @defvar Inferior.num -ID of inferior, as assigned by GDB. +ID of inferior, as assigned by GDB. You can use this to +make Python breakpoints inferior-specific, for example +(@pxref{python_breakpoint_inferior,,The Breakpoint.inferior attribute}). @end defvar @anchor{gdbpy_inferior_connection} @@ -6077,9 +6079,26 @@ @anchor{python_breakpoint_thread} @defvar Breakpoint.thread -If the breakpoint is thread-specific, this attribute holds the -thread's global id. If the breakpoint is not thread-specific, this -attribute is @code{None}. This attribute is writable. +If the breakpoint is thread-specific (@pxref{Thread-Specific +Breakpoints}), this attribute holds the thread's global id. If the +breakpoint is not thread-specific, this attribute is @code{None}. +This attribute is writable. + +Only one of @code{Breakpoint.thread} or @code{Breakpoint.inferior} can +be set to a valid id at any time, that is, a breakpoint can be thread +specific, or inferior specific, but not both. +@end defvar + +@anchor{python_breakpoint_inferior} +@defvar Breakpoint.inferior +If the breakpoint is inferior-specific (@pxref{Inferior-Specific +Breakpoints}), this attribute holds the inferior's id. If the +breakpoint is not inferior-specific, this attribute is @code{None}. +This attribute is writable. + +Only one of @code{Breakpoint.thread} or @code{Breakpoint.inferior} can +be set to a valid id at any time, that is, a breakpoint can be thread +specific, or inferior specific, but not both. @end defvar @defvar Breakpoint.task diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c index 42c4bf23431..75ebf940a0c 100644 --- a/gdb/dummy-frame.c +++ b/gdb/dummy-frame.c @@ -132,6 +132,7 @@ pop_dummy_frame_bpt (struct breakpoint *b, struct dummy_frame *dummy) if (b->thread == dummy->id.thread->global_num && b->disposition == disp_del && b->frame_id == dummy->id.id) { + gdb_assert (b->inferior == -1); while (b->related_breakpoint != b) delete_breakpoint (b->related_breakpoint); diff --git a/gdb/elfread.c b/gdb/elfread.c index 64aeb239670..ed3cad0cd02 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -968,7 +968,10 @@ elf_gnu_ifunc_resolver_stop (code_breakpoint *b) if (b_return->thread == thread_id && b_return->loc->requested_address == prev_pc && b_return->frame_id == prev_frame_id) - break; + { + gdb_assert (b_return->inferior == -1); + break; + } } if (b_return == b) diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index a7799416c50..90b66a7af86 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -779,6 +779,11 @@ gdbscm_set_breakpoint_thread_x (SCM self, SCM newvalue) else SCM_ASSERT_TYPE (0, newvalue, SCM_ARG2, FUNC_NAME, _("integer or #f")); + if (bp_smob->bp->inferior != -1) + scm_misc_error (FUNC_NAME, + _("Cannot have both thread and inferior conditions " + "on a breakpoint"), SCM_EOL); + breakpoint_set_thread (bp_smob->bp, id); return SCM_UNSPECIFIED; diff --git a/gdb/inferior.h b/gdb/inferior.h index 69525a2e053..3b25403d83c 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -746,4 +746,14 @@ extern void print_selected_inferior (struct ui_out *uiout); extern void switch_to_inferior_and_push_target (inferior *new_inf, bool no_connection, inferior *org_inf); +/* Return true if ID is a valid global inferior number. */ + +inline bool valid_global_inferior_id (int id) +{ + for (inferior *inf : all_inferiors ()) + if (inf->num == id) + return true; + return false; +} + #endif /* !defined (INFERIOR_H) */ diff --git a/gdb/infrun.c b/gdb/infrun.c index 96346e1f25b..0650b3c1528 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8039,6 +8039,7 @@ insert_exception_resume_breakpoint (struct thread_info *tp, frame = nullptr; bp->thread = tp->global_num; + bp->inferior = -1; inferior_thread ()->control.exception_resume_breakpoint = bp; } } @@ -8072,6 +8073,7 @@ insert_exception_resume_from_probe (struct thread_info *tp, bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), handler, bp_exception_resume).release (); bp->thread = tp->global_num; + bp->inferior = -1; inferior_thread ()->control.exception_resume_breakpoint = bp; } diff --git a/gdb/linespec.c b/gdb/linespec.c index 3db35998f7e..b01423107f9 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -254,9 +254,9 @@ enum linespec_token_type /* List of keywords. This is NULL-terminated so that it can be used as enum completer. */ -const char * const linespec_keywords[] = { "if", "thread", "task", "-force-condition", NULL }; +const char * const linespec_keywords[] = { "if", "thread", "task", "inferior", "-force-condition", NULL }; #define IF_KEYWORD_INDEX 0 -#define FORCE_KEYWORD_INDEX 3 +#define FORCE_KEYWORD_INDEX 4 /* A token of the linespec lexer */ diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 7a757432948..31d447a468f 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -280,11 +280,69 @@ bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure) return -1; } + if (self_bp->bp->inferior != -1 && id != -1) + { + PyErr_SetString (PyExc_RuntimeError, + _("Cannot have both thread and inferior conditions " + "on a breakpoint")); + return -1; + } + breakpoint_set_thread (self_bp->bp, id); return 0; } +/* Python function to set the inferior of a breakpoint. */ + +static int +bppy_set_inferior (PyObject *self, PyObject *newvalue, void *closure) +{ + gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self; + long id; + + BPPY_SET_REQUIRE_VALID (self_bp); + + if (newvalue == NULL) + { + PyErr_SetString (PyExc_TypeError, + _("Cannot delete `inferior' attribute.")); + return -1; + } + else if (PyLong_Check (newvalue)) + { + if (!gdb_py_int_as_long (newvalue, &id)) + return -1; + + if (!valid_global_inferior_id (id)) + { + PyErr_SetString (PyExc_RuntimeError, + _("Invalid inferior ID.")); + return -1; + } + } + else if (newvalue == Py_None) + id = -1; + else + { + PyErr_SetString (PyExc_TypeError, + _("The value of `inferior' must be an integer or None.")); + return -1; + } + + if (self_bp->bp->thread != -1 && id != -1) + { + PyErr_SetString (PyExc_RuntimeError, + _("Cannot have both thread and inferior conditions " + "on a breakpoint")); + return -1; + } + + breakpoint_set_inferior (self_bp->bp, id); + + return 0; +} + /* Python function to set the (Ada) task of a breakpoint. */ static int bppy_set_task (PyObject *self, PyObject *newvalue, void *closure) @@ -689,6 +747,20 @@ bppy_get_thread (PyObject *self, void *closure) return gdb_py_object_from_longest (self_bp->bp->thread).release (); } +/* Python function to get the breakpoint's inferior ID. */ +static PyObject * +bppy_get_inferior (PyObject *self, void *closure) +{ + gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self; + + BPPY_REQUIRE_VALID (self_bp); + + if (self_bp->bp->inferior == -1) + Py_RETURN_NONE; + + return gdb_py_object_from_longest (self_bp->bp->inferior).release (); +} + /* Python function to get the breakpoint's task ID (in Ada). */ static PyObject * bppy_get_task (PyObject *self, void *closure) @@ -1335,6 +1407,11 @@ static gdb_PyGetSetDef breakpoint_object_getset[] = { If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\ If the value is None, then this breakpoint is not thread-specific.\n\ No other type of value can be used.", NULL }, + { "inferior", bppy_get_inferior, bppy_set_inferior, + "Inferior ID for the breakpoint.\n\ +If the value is an inferior ID (integer), then this is an inferior-specific\n\ +breakpoint. If the value is None, then this breakpoint is not\n\ +inferior-specific. No other type of value can be used.", NULL }, { "task", bppy_get_task, bppy_set_task, "Thread ID for the breakpoint.\n\ If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\ diff --git a/gdb/testsuite/gdb.linespec/cpcompletion.exp b/gdb/testsuite/gdb.linespec/cpcompletion.exp index 0383469828c..650d0e75ea3 100644 --- a/gdb/testsuite/gdb.linespec/cpcompletion.exp +++ b/gdb/testsuite/gdb.linespec/cpcompletion.exp @@ -1259,8 +1259,8 @@ proc_with_prefix function-labels {} { } # Test that completion after a function name offers keyword -# (if/task/thread/-force-condition) matches in linespec mode, and also -# the explicit location options in explicit locations mode. +# (if/inferior/task/thread/-force-condition) matches in linespec mode, +# and also the explicit location options in explicit locations mode. proc_with_prefix keywords-after-function {} { set explicit_list \ diff --git a/gdb/testsuite/gdb.linespec/explicit.exp b/gdb/testsuite/gdb.linespec/explicit.exp index 9064c137e13..2e4c42f3aba 100644 --- a/gdb/testsuite/gdb.linespec/explicit.exp +++ b/gdb/testsuite/gdb.linespec/explicit.exp @@ -412,6 +412,7 @@ namespace eval $testfile { "-qualified" "-source" "if" + "inferior" "task" "thread" } diff --git a/gdb/testsuite/gdb.multi/inferior-specific-bp-1.c b/gdb/testsuite/gdb.multi/inferior-specific-bp-1.c new file mode 100644 index 00000000000..26cb01911d2 --- /dev/null +++ b/gdb/testsuite/gdb.multi/inferior-specific-bp-1.c @@ -0,0 +1,52 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +volatile int global_var = 0; + +static void +stop_breakpt (void) +{ + /* Nothing. */ +} + +static inline void __attribute__((__always_inline__)) +foo (void) +{ + int i; + + for (i = 0; i < 10; ++i) + global_var = 0; +} + +static void +bar (void) +{ + global_var = 0; + + foo (); +} + + +int +main (void) +{ + global_var = 0; + foo (); + bar (); + stop_breakpt (); + return 0; +} diff --git a/gdb/testsuite/gdb.multi/inferior-specific-bp-2.c b/gdb/testsuite/gdb.multi/inferior-specific-bp-2.c new file mode 100644 index 00000000000..3ddb1a17446 --- /dev/null +++ b/gdb/testsuite/gdb.multi/inferior-specific-bp-2.c @@ -0,0 +1,52 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +static int bar (void); +static int baz (void); +static int foo (void); + +static void +stop_breakpt (void) +{ + /* Nothing. */ +} + +int +main (void) +{ + int ret = baz (); + stop_breakpt (); + return ret; +} + +static int +bar (void) +{ + return baz (); +} + +static int +foo (void) +{ + return 0; +} + +static int +baz (void) +{ + return foo (); +} diff --git a/gdb/testsuite/gdb.multi/inferior-specific-bp.exp b/gdb/testsuite/gdb.multi/inferior-specific-bp.exp new file mode 100644 index 00000000000..5d65f19b88c --- /dev/null +++ b/gdb/testsuite/gdb.multi/inferior-specific-bp.exp @@ -0,0 +1,183 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test inferior-specific breakpoints. + +standard_testfile -1.c -2.c + +if { [use_gdb_stub] } { + return +} + +set srcfile1 ${srcfile} +set binfile1 ${binfile}-1 +set binfile2 ${binfile}-2 + +if { [build_executable ${testfile}.exp ${binfile1} "${srcfile1}"] != 0 } { + return -1 +} + +if { [build_executable ${testfile}.exp ${binfile2} "${srcfile2}"] != 0 } { + return -1 +} + +# Start the first inferior. +clean_restart ${binfile1} +if {![runto_main]} { + return +} + +# Add a second inferior, and start this one too. +gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2" +gdb_test "inferior 2" "Switching to inferior 2.*" "switch to inferior 2" +gdb_load $binfile2 +if {![runto_main]} { + return +} + +# Try to create a breakpoint using both the 'inferior' and 'thread' keywords, +# this should fail. Try with the keywords in both orders just in case the +# parser has a bug. +gdb_test "break foo thread 1.1 inferior 1" \ + "Invalid use of both 'thread' and 'inferior' in breakpoint condition" +gdb_test "break foo inferior 1 thread 1.1" \ + "Invalid use of both 'thread' and 'inferior' in breakpoint condition" + +# While w're here, check that we can't create a watchpoint with both thread +# and inferior keywords. As above, test with keywords in both orders. +foreach type {watch rwatch awatch} { + gdb_test "$type global_var thread 1.1 inferior 1" \ + "Invalid use of both 'thread' and 'inferior' in watchpoint condition" + gdb_test "$type global_var inferior 1 thread 1.1" \ + "Invalid use of both 'thread' and 'inferior' in watchpoint condition" +} + +# Clear out any other breakpoints. +gdb_test "with confirm off -- delete breakpoints" + +# Create an inferior specific breakpoint. +gdb_test "break foo inferior 1" \ + "Breakpoint $decimal at $hex: foo\\. \\(3 locations\\)" + +set saw_header false +set location_count 0 +set saw_inf_cond false +gdb_test_multiple "info breakpoints" "" { + -re "^info breakpoints\r\n" { + exp_continue + } + + -re "^Num\\s+\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^$decimal\\s+breakpoint\\s+keep\\s+y\\s+\\s*\r\n" { + set saw_header true + exp_continue + } + + -re "^\\s+stop only in inferior 1\r\n" { + set saw_inf_cond true + exp_continue + } + + -re "^$decimal\\.\[123\]\\s+y\\s+ $hex in foo at \[^\r\n\]+ inf \[12\] inferior 1\r\n" { + incr location_count + exp_continue + } + + -re "^$gdb_prompt $" { + with_test_prefix $gdb_test_name { + gdb_assert { $saw_header } + gdb_assert { $location_count == 3 } + gdb_assert { $saw_inf_cond } + } + } +} + +# Create a multi-inferior breakpoint to stop at. +gdb_test "break stop_breakpt" + +# Now resume inferior 2, this should reach 'stop_breakpt'. +gdb_test "continue" "hit Breakpoint $decimal\.$decimal, stop_breakpt \\(\\) .*" \ + "continue in inferior 2" + +# Switch to inferior 1, and try there. +gdb_test "inferior 1" ".*" \ + "select inferior 1 to check the inferior-specific b/p works" +gdb_test "continue " "hit Breakpoint $decimal\.$decimal, foo \\(\\) .*" \ + "first continue in inferior 1" + +# Now back to inferior 2, let the inferior exit, the inferior-specific +# breakpoint should not be deleted. +gdb_test "inferior 2" ".*" \ + "switch back to allow inferior 2 to exit" +gdb_test "continue" "Inferior 2 \[^\r\n\]+ exited normally.*" \ + "allow inferior 2 to exit" + +gdb_test "inferior 1" ".*" \ + "select inferior 1 to check inferior-specific b/p still works" +gdb_test "continue " "hit Breakpoint $decimal\.$decimal, foo \\(\\) .*" \ + "second continue in inferior 1" +gdb_test "continue " "hit Breakpoint $decimal\.$decimal, stop_breakpt \\(\\) .*" \ + "third continue in inferior 1" + +# Now allow inferior 1 to exit, the inferior specific breakpoint should be +# deleted. +gdb_test "continue" \ + [multi_line \ + "\\\[Inferior 1 \[^\r\n\]+ exited normally\\\]" \ + "Inferior-specific breakpoint $decimal deleted - inferior 1 has exited\\."] + +set saw_header false +set location_count 0 +set saw_inf_cond false +gdb_test_multiple "info breakpoints" "info breakpoint after inferior 1 exited" { + -re "^info breakpoints\r\n" { + exp_continue + } + + -re "^Num\\s+\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^$decimal\\s+breakpoint\\s+keep\\s+y\\s+\\s*\r\n" { + set saw_header true + exp_continue + } + + -re "^\\s+stop only in inferior 1\r\n" { + # This should not happen, this breakpoint should have been deleted. + set saw_inf_cond true + exp_continue + } + + -re "^\\s+breakpoint already hit 2 times\r\n" { + exp_continue + } + + -re "^$decimal\\.\[12\]\\s+y\\s+ $hex in stop_breakpt at \[^\r\n\]+ inf \[12\]\r\n" { + incr location_count + exp_continue + } + + -re "^$gdb_prompt $" { + with_test_prefix $gdb_test_name { + gdb_assert { $saw_header } + gdb_assert { $location_count == 2 } + gdb_assert { !$saw_inf_cond } + } + } +} diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index c3215b13d5c..8906dea6655 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -112,6 +112,8 @@ proc_with_prefix test_bkpt_basic { } { "Get Breakpoint List" 0 gdb_test "python print (blist\[1\].thread)" \ "None" "Check breakpoint thread" + gdb_test "python print (blist\[1\].inferior)" \ + "None" "Check breakpoint inferior" gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" \ "True" "Check breakpoint type" gdb_test "python print (blist\[0\].number)" \ @@ -214,6 +216,46 @@ proc_with_prefix test_bkpt_cond_and_cmds { } { "check number of lines in commands" } +# Test breakpoint thread and inferior attributes. +proc_with_prefix test_bkpt_thread_and_inferior { } { + global srcfile testfile hex decimal + + # Start with a fresh gdb. + clean_restart ${testfile} + + if ![runto_main] then { + return 0 + } + + with_test_prefix "thread" { + delete_breakpoints + gdb_test "break multiply thread 1" + gdb_test "python bp = gdb.breakpoints ()\[0\]" + gdb_test "python print(bp.thread)" "1" + gdb_test "python print(bp.inferior)" "None" + gdb_test "python bp.inferior = 1" \ + "RuntimeError: Cannot have both thread and inferior conditions on a breakpoint.*" + gdb_test_no_output "python bp.thread = None" + gdb_test_no_output "python bp.inferior = 1" \ + "set the inferior now the thread has been cleared" + gdb_test "info breakpoints" "stop only in inferior 1\r\n.*" + } + + with_test_prefix "inferior" { + delete_breakpoints + gdb_test "break multiply inferior 1" + gdb_test "python bp = gdb.breakpoints ()\[0\]" + gdb_test "python print(bp.thread)" "None" + gdb_test "python print(bp.inferior)" "1" + gdb_test "python bp.thread = 1" \ + "RuntimeError: Cannot have both thread and inferior conditions on a breakpoint.*" + gdb_test_no_output "python bp.inferior = None" + gdb_test_no_output "python bp.thread = 1" \ + "set the thread now the inferior has been cleared" + gdb_test "info breakpoints" "stop only in thread 1\r\n.*" + } +} + proc_with_prefix test_bkpt_invisible { } { global srcfile testfile hex decimal @@ -849,6 +891,7 @@ proc_with_prefix test_bkpt_auto_disable { } { test_bkpt_basic test_bkpt_deletion test_bkpt_cond_and_cmds +test_bkpt_thread_and_inferior test_bkpt_invisible test_hardware_breakpoints test_catchpoints diff --git a/gdb/testsuite/lib/completion-support.exp b/gdb/testsuite/lib/completion-support.exp index 0c03d0f035e..135649ed4d9 100644 --- a/gdb/testsuite/lib/completion-support.exp +++ b/gdb/testsuite/lib/completion-support.exp @@ -27,7 +27,7 @@ namespace eval completion { # List of all quote chars, including no-quote at all. variable maybe_quoted_list {"" "'" "\""} - variable keyword_list {"-force-condition" "if" "task" "thread"} + variable keyword_list {"-force-condition" "if" "inferior" "task" "thread"} variable explicit_opts_list \ {"-function" "-label" "-line" "-qualified" "-source"} From patchwork Mon Nov 28 11:25:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61150 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24E31385800A for ; Mon, 28 Nov 2022 11:27:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24E31385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669634858; bh=2mLlCmIwN0nI5N2cgaUxorulTNc17c1qW0VyW6w0DRE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=lv39f9g2yMVdNkJlIsL3/ovpije9VvJP5BD+QQra/gglENqw5ZCFIVOMAZbXl263p pCpDc2HAab/QD4Pg7rOQEpHLTmmaVvAVtUQLmaRqDBb8NklTu1uj0DYCcrc/RsX+an zTqmQeKx22XWLwF9oQaJjfU33emAPtKidmJlCu2Y= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4DF21385B18B for ; Mon, 28 Nov 2022 11:25:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4DF21385B18B Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-391--OQ_hvHoMS-mTqCGzSWLXQ-1; Mon, 28 Nov 2022 06:25:51 -0500 X-MC-Unique: -OQ_hvHoMS-mTqCGzSWLXQ-1 Received: by mail-wr1-f69.google.com with SMTP id o8-20020adfba08000000b00241e80f08e0so1795399wrg.12 for ; Mon, 28 Nov 2022 03:25:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2mLlCmIwN0nI5N2cgaUxorulTNc17c1qW0VyW6w0DRE=; b=YlSTJEdhkMTMYKtiCeAnWYIQzWlHvAniWWzmhTKviPrC/GxiL3GzNIB+IJcKrCNg/S MoSK/YwL/BgYG0j5xBI+YdJUbA5B3hNWdQV4tngUBlYHoruiV7E0Qd/Zp6n5eik4BTTn lvmGa12GolmzU/GaclYnS9AHwFnEtlNigZWTBREuKKJQRe4ZYXAwC8rAgtVBZn6zaytG dPZlYdWDgYiQvYbLWAMPt919Upjf4K9mCWYdXh44xZz8bylu4NKubH7xwAl5eX5tXjdP 3iSgMBdKOG6ncDMFM9jaVkGjWtUOg2GZu77ZqAfPvTSS7gjIs8wJ9b0wbWUAXJC8JIlM OrSw== X-Gm-Message-State: ANoB5plOGshbJmTgY9OBy3qCNjcr6em9z3ydlfpd5crPuPT7pRpeVnOI XLj7HKQp5Oy+/FI5lCMIZ3RCx+CEpTSQaaPna7Qpc8opzg/u0xfZxkGOGTYGTU4dx1qTnNg0ygu r7OqS9M1+Jzx6KqXmsFrxEl4VnGpFKvBQTgNs260Q3yAEbh31vXUrWsH44zxee3sKLtDMgh89iQ == X-Received: by 2002:a5d:5254:0:b0:242:14dc:a06e with SMTP id k20-20020a5d5254000000b0024214dca06emr3589516wrc.675.1669634750224; Mon, 28 Nov 2022 03:25:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf74dm2bnvZoZm7db0tLCPsiETC4gKyKjBUOUlEaO2S6jZbkLH1RLGkPLymwgbYZl9VffTxmlQ== X-Received: by 2002:a5d:5254:0:b0:242:14dc:a06e with SMTP id k20-20020a5d5254000000b0024214dca06emr3589480wrc.675.1669634749811; Mon, 28 Nov 2022 03:25:49 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id c12-20020adfed8c000000b00236b2804d79sm10613571wro.2.2022.11.28.03.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:49 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 6/6] gdb: convert the 'start' breakpoint to use inferior keyword Date: Mon, 28 Nov 2022 11:25:38 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Now that we have support for inferior specific breakpoints, the breakpoint created for the 'start' command can make use of this keyword. In most cases the observed functionality should be unchanged from a user's point of view, though the code in GDB is a little cleaner now, we no longer need to change the expression used based on the language. I do wonder if the current mechanism could run into problems if we had different inferiors of different languages. For example, if we had an Ada inferior and a C inferior and followed a process a little like this: 1. Start C inferior, the inferior stops before main for some reason, 2. Start the Ada inferior, this runs to main, 3. I think when we hit main, the condition for both breakpoints will be evaluated, this will include evaluating the expression for the C 'start' breakpoint, which uses '==' and is, I guess, not valid for Ada. I haven't tried to create a testcase for this situation, but it's a possibly interesting edge case. One place where the observed behaviour is different, is that inferior breakpoints, like thread breakpoints, will be auto-deleted when the contained inferior exits. As a result, if an inferior exits before hitting the start breakpoint, then the 'start' breakpoint will be auto-deleted. I have got a test that covers this situation. --- gdb/infcmd.c | 10 +--- .../gdb.base/start-inferior-specific-1.c | 32 +++++++++++ .../gdb.base/start-inferior-specific-2.c | 22 ++++++++ .../gdb.base/start-inferior-specific.exp | 55 +++++++++++++++++++ 4 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 gdb/testsuite/gdb.base/start-inferior-specific-1.c create mode 100644 gdb/testsuite/gdb.base/start-inferior-specific-2.c create mode 100644 gdb/testsuite/gdb.base/start-inferior-specific.exp diff --git a/gdb/infcmd.c b/gdb/infcmd.c index f7bce0d0399..7aa9a959bdb 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -429,13 +429,9 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how) have proper inferior-specific breakpoint support, in the breakpoint machinery. We could then avoid inserting a breakpoint in the program spaces unrelated to this inferior. */ - const char *op - = ((current_language->la_language == language_ada - || current_language->la_language == language_pascal - || current_language->la_language == language_m2) ? "=" : "=="); - std::string arg = string_printf - ("-qualified %s if $_inferior %s %d", main_name (), op, - current_inferior ()->num); + std::string arg = string_printf ("-qualified %s inferior %d", + main_name (), + current_inferior ()->num); tbreak_command (arg.c_str (), 0); } diff --git a/gdb/testsuite/gdb.base/start-inferior-specific-1.c b/gdb/testsuite/gdb.base/start-inferior-specific-1.c new file mode 100644 index 00000000000..1717a82b75d --- /dev/null +++ b/gdb/testsuite/gdb.base/start-inferior-specific-1.c @@ -0,0 +1,32 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include + +__attribute__((constructor)) +static void +ctor (void) +{ + exit (1); +} + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/start-inferior-specific-2.c b/gdb/testsuite/gdb.base/start-inferior-specific-2.c new file mode 100644 index 00000000000..b69e218962a --- /dev/null +++ b/gdb/testsuite/gdb.base/start-inferior-specific-2.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/start-inferior-specific.exp b/gdb/testsuite/gdb.base/start-inferior-specific.exp new file mode 100644 index 00000000000..50e4e109116 --- /dev/null +++ b/gdb/testsuite/gdb.base/start-inferior-specific.exp @@ -0,0 +1,55 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that a breakpoint created for the 'start' command, will be +# silently deleted if the inferior being started exits before reaching +# main. + +standard_testfile -1.c -2.c + +if {[use_gdb_stub]} { + return +} + +set srcfile1 ${srcfile} + +set binfile1 ${binfile}-1 +set binfile2 ${binfile}-2 + +if {[build_executable ${testfile}.exp ${binfile1} "${srcfile1}"] != 0} { + return -1 +} + +if {[build_executable ${testfile}.exp ${binfile2} "${srcfile2}"] != 0} { + return -1 +} + +clean_restart ${binfile1} + +# Start the first inferior, this will exit before hitting the 'start' +# breakpoint in main. +gdb_test "start" \ + [multi_line \ + "Temporary breakpoint $decimal at \[^\r\n\]+" \ + "Starting program: \[^\r\n\]+" \ + "\\\[Inferior $decimal \[^\r\n\]+ exited with code 01\\\]"] + +# Now load a different binary and run it. This inferior should run +# all the way to completion without hitting a breakpoint in main. +gdb_load ${binfile2} +gdb_test "run" \ + [multi_line \ + "Starting program: \[^\r\n\]+" \ + "\\\[Inferior $decimal \[^\r\n\]+ exited normally\\\]"]