From patchwork Tue Jan 31 17:27:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64027 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 17A3E3858438 for ; Tue, 31 Jan 2023 17:49:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17A3E3858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187370; bh=GM+gpQWNaF082Wnc8jC/iYjI+Cs6aWV4B/kEe/bQtVM=; 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=sN9upf10swDwNU/writH4+ytIwLjAvuRO/2+S6L0HMR1Y1u4UERTiApVT/QBbYpzi FRd3iEds4aFiT/fuSPateVUtrBsflFZzPxjX9NW8qZB1iT+PobGQzyr3M9X2tMyT9c R7u7TlZzjeJ3/G0DWe+abKnIPHnW9xCRNUQx3m2E= 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 25C3D3858D33 for ; Tue, 31 Jan 2023 17:49:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25C3D3858D33 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-564-7y8f8GUUPZilAKDciU2_lQ-1; Tue, 31 Jan 2023 12:27:24 -0500 X-MC-Unique: 7y8f8GUUPZilAKDciU2_lQ-1 Received: by mail-qk1-f198.google.com with SMTP id q13-20020a37f70d000000b007283b33bfb3so405123qkj.4 for ; Tue, 31 Jan 2023 09:27:24 -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=GM+gpQWNaF082Wnc8jC/iYjI+Cs6aWV4B/kEe/bQtVM=; b=7O38cCPlQoYPy+DPxY+vb0DTIRBm6Zoiji8sX22LyXXA+zN8puvG/ojLX7HgORwcx1 tl46KDI0sY5BT+rBc7c9u+Rd6dDRxEurKCaXGLWNfvpcfJiMjXxE+MefqaESKRpXFuAE 5o2zgfS8vSzrdf+dYaGOxnm3UINuX8+ol3rhg9grdMJePqgeAvL6C2KPyQlLK+MD1uZC iL+2Qw4oQqNNiu1DYLvpYA/XR+4Agt3k8kvjwNw9MSFzTfOBCEdzXqUtVt2o4V2R4yPE 3GOmYc9/VMwHgu/cmihyv4JAjJms3PGirTCGRRuoXwSx1A+BQfrhOVAAWJzX/zFPs8Ts vxbw== X-Gm-Message-State: AO0yUKVMQYLrmTfzgBWIzTzJcAQpRiLh3qbqQxA2mfsFlsWOBF1pbOn/ AC/K7MjUWo+jTm/Ts3rTM+AQkOiTR7nxKdhE6fptliCkiZHgYSzs/BayISrA2QsWerbUcsEq96l vScLEEZL4ZHujuYUVsD9t5Tj1ZYTbvWTQ+KfXtmo3irY2bWMoQUXQK95J1m4D9UXHLssE4DVVJw == X-Received: by 2002:a05:622a:610:b0:3b8:5ad9:3fe8 with SMTP id z16-20020a05622a061000b003b85ad93fe8mr17721727qta.48.1675186043423; Tue, 31 Jan 2023 09:27:23 -0800 (PST) X-Google-Smtp-Source: AK7set/Qt2GGwcKjc52EbDSwZMiVFlxL8QVmrDDbn2gUcbGRuNeu7zyXMahaDCQN4FTDCjkmX2EhnQ== X-Received: by 2002:a05:622a:610:b0:3b8:5ad9:3fe8 with SMTP id z16-20020a05622a061000b003b85ad93fe8mr17721686qta.48.1675186043092; Tue, 31 Jan 2023 09:27:23 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id v3-20020ac87283000000b003b62e9c82ebsm10178671qto.48.2023.01.31.09.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:22 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 01/13] gdb/doc: extended documentation for inferior function calls Date: Tue, 31 Jan 2023 17:27:06 +0000 Message-Id: <69209dfdfad2e171fd8015c7ca4741e591416d44.1675185990.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.8 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, WEIRD_PORT 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" I noticed that the documentation for inferior function calls doesn't say much about what happens if/when an inferior function call is interrupted, i.e. it doesn't describe what the dummy frame looks like on the stack, or how GDB behaves when the inferior is continued and reaches the dummy frame. This commit aims to add some of this missing information. --- gdb/doc/gdb.texinfo | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 03033c7f9e3..682f85387e5 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20708,6 +20708,7 @@ in that case is controlled by the @code{set unwind-on-terminating-exception} command. +@anchor{stack unwind settings} @table @code @item set unwindonsignal @kindex set unwindonsignal @@ -20765,6 +20766,37 @@ @end table +When calling a function within a program, it is possible that the +program could enter a state from which the called function may never +return. If this happens then it is possible to interrupt the function +call by typing the interrupt character (often @kbd{Ctrl-c}). + +If a called function is interrupted for any reason, including hitting +a breakpoint, or triggering a watchpoint, and the stack is not unwound +due to @code{set unwind-on-terminating-exception on} or @code{set +unwindonsignal on} (@pxref{stack unwind settings}), +then the dummy-frame, created by @value{GDBN} to facilitate the call +to the program function, will be visible in the backtrace, for example +frame @code{#3} in the following backtrace: + +@smallexample +(@value{GDBP}) backtrace +#0 0x00007ffff7b3d1e7 in nanosleep () from /lib64/libc.so.6 +#1 0x00007ffff7b3d11e in sleep () from /lib64/libc.so.6 +#2 0x000000000040113f in deadlock () at test.cc:13 +#3 +#4 breakpt () at test.cc:20 +#5 0x0000000000401151 in main () at test.cc:25 +@end smallexample + +At this point it is possible to examine the state of the inferior just +like any other stop. + +Depending on why the function was interrupted then it may be possible +to resume the inferior (using commands like @code{continue}, +@code{step}, etc). In this case, when the inferior finally returns to +the dummy-frame, @value{GDBN} will once again halt the inferior. + @subsection Calling functions with no debug info @cindex no debug info functions From patchwork Tue Jan 31 17:27:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64029 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 4A1463858000 for ; Tue, 31 Jan 2023 17:50:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A1463858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187419; bh=YOqM371fnJuseZPG+vfR9ai3DSPN1m3S3lmdKNcrEsQ=; 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=CMarh6WD1Xpfe2mJcK7V/SUjZgVo0uNEtSwPQs/NboWuHhDCeGaGtyyrSucmScAKo UL5btFmjSjUCdeBP+ScSh3cOtdFtvGIBQjaLgpydg/mDU+L1FmTN/nyso0b144Jicn u7/f6F+Q9PH3IkPUZyA3zDx2+yvTSLD5vGt52c4M= 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 4008F3858404 for ; Tue, 31 Jan 2023 17:49:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4008F3858404 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-625-fgV4AsLUNd6mum8WZqZBSQ-1; Tue, 31 Jan 2023 12:27:25 -0500 X-MC-Unique: fgV4AsLUNd6mum8WZqZBSQ-1 Received: by mail-qk1-f197.google.com with SMTP id a3-20020a05620a438300b007069b068069so9460213qkp.2 for ; Tue, 31 Jan 2023 09:27:25 -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=YOqM371fnJuseZPG+vfR9ai3DSPN1m3S3lmdKNcrEsQ=; b=08jbd09CfU6YLqdsbXqxytJAbqf/xlgX5jole9U6Yhenby+sLi/6RvIdTPMckeOJEI Q2UCjYPhoS7btePd7kOjOL9pJfokdsEmICM+tTK+ZwikvLH+l8Ec53otWa1diyZ/G7SE ROkT0PvFSIpABwdsyTSI23tC2ZZ5nzlYXBgBRi+6FZMgbVrcsjYN/goEU0c/9ioirPmy ZS0EbUm0kJiZOERyzm9VF/N2HYrV6p3uj3CIIkt5K0NjSinO1TKBit74UWOqzqLvvkK9 0kBck5/UVA4uZr4rG27AI0YgkQ8NMymNOVIJxkj5Z3X2gWjNXtEPmP8uuZyEs3281k3C corg== X-Gm-Message-State: AO0yUKV6VyWifNpS86ilXIhDEuL+/Hr80XOYr/g8fZVJ2Hq5wu/T5t5T m5PVl1RtqS9UDwF5e2J0Kxvyv+1RXEv+lWbenSuld69Au88veOetIa/Bv2JzzO5sPerKWvo5+Uo tCXnfomGaFeK1KE7OMN7qTr0pTRulnHY+XjYgZsLe3Cyo16aWr3VdaYx56VllJJff1e8dGhdJWw == X-Received: by 2002:ac8:5956:0:b0:3b8:4144:fe72 with SMTP id 22-20020ac85956000000b003b84144fe72mr20946648qtz.9.1675186045306; Tue, 31 Jan 2023 09:27:25 -0800 (PST) X-Google-Smtp-Source: AK7set+YjOHcJ10eFWepkVTn3L1Mx9pP5+xUFq/9hytq7jzeMfa3fKehAf3JcKs0OOUxjm4Va7wlDg== X-Received: by 2002:ac8:5956:0:b0:3b8:4144:fe72 with SMTP id 22-20020ac85956000000b003b84144fe72mr20946618qtz.9.1675186045042; Tue, 31 Jan 2023 09:27:25 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id f10-20020ac8134a000000b003b9b4028d63sm921868qtj.80.2023.01.31.09.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:24 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 02/13] gdb/doc: extend the documentation for conditional breakpoints Date: Tue, 31 Jan 2023 17:27:07 +0000 Message-Id: <78764570698177ecf049fdab759908ca88fd7bd3.1675185990.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.8 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" This documentation update adds more text to describe what happens if a conditional breakpoint calls an inferior function, and the inferior function is interrupted for some reason. --- gdb/doc/gdb.texinfo | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 682f85387e5..dd8267f448f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -5713,6 +5713,17 @@ purpose of performing side effects when a breakpoint is reached (@pxref{Break Commands, ,Breakpoint Command Lists}). +If a breakpoint condition calls a function in your program, then it is +possible that your program could stop for some reason while in the +called function. For example, @value{GDBN} might hit a breakpoint in +the called function, or the called function may receive a signal +(e.g.@ a @code{SIGSEGV}) as a result of some undefined behavior. If +this happens then @value{GDBN} will stop. Depending on the settings +@code{unwindonsignal} and @code{unwind-on-terminating-exception} +(@pxref{Calling,,Calling Program Functions}) @value{GDBN} may unwind +the stack back to the breakpoint location, or may leave the program at +the frame where the stop occurred. + Breakpoint conditions can also be evaluated on the target's side if the target supports it. Instead of evaluating the conditions locally, @value{GDBN} encodes the expression into an agent expression From patchwork Tue Jan 31 17:27:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64037 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 DD748384F031 for ; Tue, 31 Jan 2023 17:52:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD748384F031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187528; bh=zDhofN96FnqddQl8entVMpPxNMWZWAIZXogfLo0xh0c=; 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=lRMlwVAB3OoloXULjYFRFGlrOoOhA4m7V6+dDiLCh9nlDqLH9JmtowMsi61AL+sOC wk24aplaikSYyWcKgIBraXpvjGop/FhVq0JSNuxFKSAa4nVqo5Svy3ZARTeFQY90V0 +Qkw18fNTJcVtIZ1QYv/BOCz6kTmfrh+KThZmCTg= 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 A60603858C33 for ; Tue, 31 Jan 2023 17:49:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A60603858C33 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-191-SFPoe1XLMg2BgkLbvJ2XpA-1; Tue, 31 Jan 2023 12:27:28 -0500 X-MC-Unique: SFPoe1XLMg2BgkLbvJ2XpA-1 Received: by mail-qv1-f70.google.com with SMTP id c10-20020a05621401ea00b004c72d0e92bcso8580195qvu.12 for ; Tue, 31 Jan 2023 09:27:28 -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=zDhofN96FnqddQl8entVMpPxNMWZWAIZXogfLo0xh0c=; b=INKR1zrFiGgQTgK3jOlF1MsOPrbrgZIDk18DIZqbVZt1vaty/aEAWgUY79mfkdNThv D5oLIiap25QcJKPULfu7tY3DvjgJAwkTs2hmRDmG/aboD0Dqe1162YXqr0dDAU66WUZX kcKR14gPyhKqVDQ5EuwTh6Xic/gdYji5vapGeyn4lse/cG7hZ746RbI7UBjYchSQEKId fcMSFNHJOruiL6zR2LJowVGywfhx+dWncMhA/1N/Re2FBzpWOBXiLKHW6JUVin64L58x kXkPQkKpkkPfemfBC6IjEZ4z4ouu1XCgEWksFO7H7WBrcqDn5cq7UDLgahXOj3XMsf/A AibQ== X-Gm-Message-State: AO0yUKVSldOMDQ60AvaFozD+LxqdOYdYCKnE0pQpgK8wbWQ4P12MplgX nS8aOoC98uohdYoC9Hm/GtnZujyJa3Hos74ZWLMQpi/+Gr2NCgL0hhztFnhB9T/5DCseANbirf0 F0R/GBlBY2leTH1swqH3CZW9d3eOEVaB+p0S/o6KkDkqbKm/5gAorLFcNovbFBo8VIUa+h7Qbcg == X-Received: by 2002:a05:6214:4505:b0:53b:d514:724 with SMTP id oo5-20020a056214450500b0053bd5140724mr14079773qvb.26.1675186047421; Tue, 31 Jan 2023 09:27:27 -0800 (PST) X-Google-Smtp-Source: AK7set/zdXs8CaDGnnZ1ZTLiD1I4/y5QOcvDEmVC85cJjZYx8v+OCtZ9kPyV2QaIhpYmmsSyDA30vQ== X-Received: by 2002:a05:6214:4505:b0:53b:d514:724 with SMTP id oo5-20020a056214450500b0053bd5140724mr14079723qvb.26.1675186046940; Tue, 31 Jan 2023 09:27:26 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id n63-20020a37bd42000000b007283b33bfbesm362759qkf.121.2023.01.31.09.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:26 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 03/13] gdb: include breakpoint number in testing condition error message Date: Tue, 31 Jan 2023 17:27:08 +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.8 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" When GDB fails to test the condition of a conditional breakpoint, for whatever reason, the error message looks like this: (gdb) break foo if (*(int *) 0) == 1 Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Error in testing breakpoint condition: Cannot access memory at address 0x0 Breakpoint 1, foo () at bpcond.c:11 11 int a = 32; (gdb) The line I'm interested in for this commit is this one: Error in testing breakpoint condition: In the case above we can figure out that the problematic breakpoint was #1 because in the final line of the message GDB reports the stop a breakpoint #1. However, in the next few patches I plan to change this. In some cases I don't think it makes sense for GDB to report the stop as being at breakpoint #1, consider this case: (gdb) list some_func 1 int 2 some_func () 3 { 4 int *p = 0; 5 return *p; 6 } 7 8 void 9 foo () 10 { (gdb) break foo if (some_func ()) Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Program received signal SIGSEGV, Segmentation fault. 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; Error in testing breakpoint condition: The program being debugged was signaled while in a function called from GDB. GDB remains in the frame where the signal was received. To change this behavior use "set unwindonsignal on". Evaluation of the expression containing the function (some_func) will be abandoned. When the function is done executing, GDB will silently stop. Program received signal SIGSEGV, Segmentation fault. Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; (gdb) Notice that, the final lines of output report the stop as being at breakpoint #1, even though we are actually located within some_func. I find this behaviour confusing, and propose that this should be changed. However, if I make that change then every reference to breakpoint #1 will be lost from the error message. So, in this commit, in preparation for the later commits, I propose to change the 'Error in testing breakpoint condition:' line to this: Error in testing condition for breakpoint NUMBER: where NUMBER will be filled in as appropriate. Here's the first example with the updated error: (gdb) break foo if (*(int *) 0) == 0 Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Error in testing condition for breakpoint 1: Cannot access memory at address 0x0 Breakpoint 1, foo () at bpcond.c:11 11 int a = 32; (gdb) The breakpoint number does now appear twice in the output, but I don't see that as a negative. This commit just changes the one line of the error, and updates the few tests that either included the old error in comments, or actually checked for the error in the expected output. As the only test that checked the line I modified is a Python test, I've added a new test that doesn't rely on Python that checks the error message in detail. While working on the new test, I spotted that it would fail when run with native-gdbserver and native-extended-gdbserver target boards. This turns out to be due to a gdbserver bug. To avoid cluttering this commit I've added a work around to the new test script so that the test passes for the remote boards, in the next few commits I will fix gdbserver, and update the test script to remove the work around. --- gdb/breakpoint.c | 3 +- gdb/testsuite/gdb.base/bp-cond-failure.c | 30 +++++ gdb/testsuite/gdb.base/bp-cond-failure.exp | 114 ++++++++++++++++++ .../gdb.base/catch-signal-siginfo-cond.exp | 2 +- gdb/testsuite/gdb.base/gnu-ifunc.exp | 2 +- .../gdb.python/py-finish-breakpoint.exp | 2 +- 6 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.base/bp-cond-failure.c create mode 100644 gdb/testsuite/gdb.base/bp-cond-failure.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 00cc2ab401c..eecaeefed3e 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5542,7 +5542,8 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) catch (const gdb_exception &ex) { exception_fprintf (gdb_stderr, ex, - "Error in testing breakpoint condition:\n"); + "Error in testing condition for breakpoint %d:\n", + b->number); } } else diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.c b/gdb/testsuite/gdb.base/bp-cond-failure.c new file mode 100644 index 00000000000..2a9974b47ce --- /dev/null +++ b/gdb/testsuite/gdb.base/bp-cond-failure.c @@ -0,0 +1,30 @@ +/* Copyright 2022-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 +foo () +{ + return 0; /* Breakpoint here. */ +} + +int +main () +{ + int res = foo (); + + return res; +} diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp new file mode 100644 index 00000000000..9388b8cf582 --- /dev/null +++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp @@ -0,0 +1,114 @@ +# Copyright 2022-2023 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 the format of the error message given when a breakpoint +# condition fails. +# +# In this case the breakpoint condition does not make use of inferior +# function calls, instead, the expression used for the breakpoint +# condition will throw an error when evaluated. +# +# We check that the correct breakpoint number appears in the error +# message, and that the error is reported at the correct source +# location. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \ + {debug}] == -1 } { + return +} + +# Run to main so that we connect to the target if using 'target +# remote'. This means that the is_address_zero_readable, and the +# 'show breakpoint condition-evaluation' checks below will be +# performed with the remote connection in place. +if { ![runto_main] } { + fail "run to main" + return -1 +} + +# This test relies on reading address zero triggering a SIGSEGV. +if { [is_address_zero_readable] } { + return +} + +# Where the breakpoint will be placed. +set bp_line [gdb_get_line_number "Breakpoint here"] + +proc run_test { cond_eval } { + clean_restart ${::binfile} + + if { ![runto_main] } { + fail "run to main" + return -1 + } + + if { $cond_eval ne "auto" } { + gdb_test_no_output "set breakpoint condition-evaluation ${cond_eval}" + } + + # Setup the conditional breakpoint and record its number. + gdb_breakpoint "${::srcfile}:${::bp_line} if (*(int *) 0) == 0" + set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*"] + + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "Error in testing condition for breakpoint ${bp_num}:" \ + "Cannot access memory at address 0x0" \ + "" \ + "Breakpoint ${bp_num}, foo \\(\\) at \[^\r\n\]+:${::bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+Breakpoint here\[^\r\n\]+"] +} + +# If we're using a remote target then conditions could be evaulated +# locally on the host, or on the remote target. Otherwise, conditions +# are always evaluated locally. +# +# Using "auto" will select the target if the target supports condition +# evaluation, otherwise, the local host will be used. +# +# So, we always include "auto", but then we look at the output of +# 'show breakpoint condition-evaluation', if this tells us that "auto" +# is using the target, then we specifically add "host" to the list of +# modes to check. + +set cond_eval_modes { "auto" } + +gdb_test_multiple "show breakpoint condition-evaluation" "" { + -re -wrap "Breakpoint condition evaluation mode is auto \\(currently target\\)\\." { + + ## NOTE: Instead of testing with "auto" and "host" in this + ## case we only test with "host". This is because a GDB bug + ## prevents the "auto" (a.k.a. target) mode from working. + ## + ## Don't worry, this will be fixed in a later commit, and this + ## comment will be removed at that time. + ## + ## lappend cond_eval_modes "host" + + set cond_eval_modes { "host" } + pass $gdb_test_name + } + + -re -wrap "Breakpoint condition evaluation mode is auto \\(currently host\\)\\." { + pass $gdb_test_name + } +} + +foreach_with_prefix cond_eval $cond_eval_modes { + run_test $cond_eval +} diff --git a/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp b/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp index 182b2f25faa..f400fc03b28 100644 --- a/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp +++ b/gdb/testsuite/gdb.base/catch-signal-siginfo-cond.exp @@ -18,7 +18,7 @@ # # (gdb) continue # Continuing. -# Error in testing breakpoint condition: +# Error in testing condition for breakpoint NUM: # Selected thread is running. # # Catchpoint 3 (signal SIGUSR1), 0x0000003615e35877 in __GI_raise (sig=10) at raise.c:56 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp index 0a435806409..22462bea233 100644 --- a/gdb/testsuite/gdb.base/gnu-ifunc.exp +++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp @@ -281,7 +281,7 @@ proc misc_tests {resolver_attr resolver_debug final_debug} { # Also test a former patch regression: # Continuing. - # Error in testing breakpoint condition: + # Error in testing condition for breakpoint NUM: # Attempt to take address of value not located in memory. # # Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp index b6bd7a63c8f..e5a46874afd 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp @@ -188,7 +188,7 @@ with_test_prefix "finish in normal frame" { gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition" gdb_test "continue" \ - "test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing breakpoint condition.*The program being debugged stopped while in a function called from GDB.*" \ + "test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing condition for breakpoint ${::decimal}.*The program being debugged stopped while in a function called from GDB.*" \ "stop in condition function" gdb_test "continue" "Continuing.*" "finish condition evaluation" From patchwork Tue Jan 31 17:27:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64028 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 320A93858C27 for ; Tue, 31 Jan 2023 17:49:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 320A93858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187370; bh=MlpcCbiH7uPAPCNQh01Jxe8GcmBHloptTG/lScdXxXs=; 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=O5PHK97pksNCpZbPHwmoQumRX8Cuw1N90Hwj4YGbcDO8Wr4HcrQ09YvhSGhjlCDn3 z7yifIw7s91Dnipj1FEKAzjMkY8sH9Kb/sF9FAlDTlGlZVQfOl0K5JkNrqLZN7Mh7A VA+XRMV6d2c6LcBViV4lZntgdE4vyei4I1rHPFgs= 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 22F5E3858D28 for ; Tue, 31 Jan 2023 17:49:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22F5E3858D28 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-464-UD-sSsI_Njm30OC4ACvQ9Q-1; Tue, 31 Jan 2023 12:27:30 -0500 X-MC-Unique: UD-sSsI_Njm30OC4ACvQ9Q-1 Received: by mail-qv1-f71.google.com with SMTP id ob12-20020a0562142f8c00b004c6c72bf1d0so8552127qvb.9 for ; Tue, 31 Jan 2023 09:27:29 -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=MlpcCbiH7uPAPCNQh01Jxe8GcmBHloptTG/lScdXxXs=; b=FIMwmyKwtFoBB9Fcih1rJMgOXl/LOUCKktgb3AbSkDFbyoaXRLRkfAFQB25TyrHu+C e221rJlm3bWeq/LbPKed5kGc2olTqkBjQjnBsvTqgn+507qHgPMu91fsZ4e+V+7XyLt4 SxomF2D87J81H9QkRefsHJyMirPDcx34PrcP79IGW2lLWXBlfP4DfyA3ydR6rTZtbZui tBias6RyS7GF6N1ijXThGAZEYaVWQLzSoFeN5N9IB8gjGfurL7pJB625lSrHJMfm3po7 ZSwMbLzRMutc+n8MG8SU4OZNc9W9MV4143txCDRZXwTfB5Z2z1UKywrr/8rwF6uMHv9X m/iQ== X-Gm-Message-State: AO0yUKU4fqMonaGMgCEYkdBxX9TaJOEQhBxKHUIzCIqUGA+qxtAki9Hy 00seJ/iOHrV3HaDjp3ShdNYTIa0rowfxhYj5mgr/YRYKrGFFWLALwuy3PwcATZXrxNNiWz9FeYo 9oDzm/+Qos9qDGeh7ZzAdwuPfT5WQQgPloPL6G1NT1fu0WwZ08bDNDfbLPhLA3fayHWOi27XCqw == X-Received: by 2002:a05:622a:1181:b0:3b8:293c:24eb with SMTP id m1-20020a05622a118100b003b8293c24ebmr20665757qtk.30.1675186049260; Tue, 31 Jan 2023 09:27:29 -0800 (PST) X-Google-Smtp-Source: AK7set+BvNCnvabOvTu1qSSug6viBuHNsWoPgBH8h/OFQtb4g3hVqmSHC2rRS4GZ2Ms5I7DUYO9cWQ== X-Received: by 2002:a05:622a:1181:b0:3b8:293c:24eb with SMTP id m1-20020a05622a118100b003b8293c24ebmr20665721qtk.30.1675186048917; Tue, 31 Jan 2023 09:27:28 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id x20-20020a05620a01f400b0071d2cd07560sm5614817qkn.124.2023.01.31.09.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:28 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 04/13] gdbserver: allows agent_mem_read to return an error code Date: Tue, 31 Jan 2023 17:27:09 +0000 Message-Id: <880c3b43698c198daa8dd9dc128421b4874454b2.1675185990.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.8 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" Currently the gdbserver function agent_mem_read ignores any errors from calling read_inferior_memory. This means that if there is an attempt to access invalid memory then this will appear to succeed. In this patch I update agent_mem_read so that if read_inferior_memory fails, agent_mem_read will return an error code. However, none of the callers of agent_mem_read actually check the return value, so this commit will have no effect on anything. In the next commit I will update the users of agent_mem_read to check for the error code. I've also updated the header comments on agent_mem_read to better reflect what the function does, and its possible return values. --- gdbserver/tracepoint.cc | 11 ++++------- gdbserver/tracepoint.h | 9 +++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc index 37a9a8c5b7c..60918fc0678 100644 --- a/gdbserver/tracepoint.cc +++ b/gdbserver/tracepoint.cc @@ -4914,8 +4914,7 @@ condition_true_at_tracepoint (struct tracepoint_hit_ctx *ctx, return (value ? 1 : 0); } -/* Do memory copies for bytecodes. */ -/* Do the recording of memory blocks for actions and bytecodes. */ +/* See tracepoint.h. */ int agent_mem_read (struct eval_agent_expr_context *ctx, @@ -4927,10 +4926,7 @@ agent_mem_read (struct eval_agent_expr_context *ctx, /* If a 'to' buffer is specified, use it. */ if (to != NULL) - { - read_inferior_memory (from, to, len); - return 0; - } + return read_inferior_memory (from, to, len); /* Otherwise, create a new memory block in the trace buffer. */ while (remaining > 0) @@ -4951,7 +4947,8 @@ agent_mem_read (struct eval_agent_expr_context *ctx, memcpy (mspace, &blocklen, sizeof (blocklen)); mspace += sizeof (blocklen); /* Record the memory block proper. */ - read_inferior_memory (from, mspace, blocklen); + if (read_inferior_memory (from, mspace, blocklen) != 0) + return 1; trace_debug ("%d bytes recorded", blocklen); remaining -= blocklen; from += blocklen; diff --git a/gdbserver/tracepoint.h b/gdbserver/tracepoint.h index a30f540d130..e424dc9dfb8 100644 --- a/gdbserver/tracepoint.h +++ b/gdbserver/tracepoint.h @@ -161,8 +161,13 @@ void gdb_agent_about_to_close (int pid); struct traceframe; struct eval_agent_expr_context; -/* Do memory copies for bytecodes. */ -/* Do the recording of memory blocks for actions and bytecodes. */ +/* When TO is not NULL, do memory copies for bytecodes, read LEN bytes + starting at address FROM, and place the result in the buffer TO. + Return 0 on success, otherwise a non-zero error code. + + When TO is NULL, do the recording of memory blocks for actions and + bytecodes into a new traceframe block. Return 0 on success, otherwise, + return 1 if there is an error. */ int agent_mem_read (struct eval_agent_expr_context *ctx, unsigned char *to, CORE_ADDR from, From patchwork Tue Jan 31 17:27:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64031 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 6446C3858C39 for ; Tue, 31 Jan 2023 17:50:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6446C3858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187435; bh=WpJb6Z6lSfjDWxWBRvLkeljxbLI1A+6tr1fbA9ZMIe4=; 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=TULUmdK7F5vhJf0dXnjqVnFtGy3Vatsx+vhB/Nk4vmmAFoLYIXE6y53mXuod1smHi 1/f7pGJWA5/YOQQJA/W8MuBbFT2ql0NJxxVeA8wMyHnd7L/1ReSP81b2NR5H/PPdLL uEGsPEjTFGEQtYmbC20mSpw73SOQ27KdHmg2Kl2Y= 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 E96C13858436 for ; Tue, 31 Jan 2023 17:49:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E96C13858436 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-361-2gkvaswaNMSEevrF2Jtxxw-1; Tue, 31 Jan 2023 12:27:31 -0500 X-MC-Unique: 2gkvaswaNMSEevrF2Jtxxw-1 Received: by mail-qt1-f197.google.com with SMTP id m7-20020ac807c7000000b003b80b35c136so6809769qth.5 for ; Tue, 31 Jan 2023 09:27:31 -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=WpJb6Z6lSfjDWxWBRvLkeljxbLI1A+6tr1fbA9ZMIe4=; b=62j4XJ55MLn9lHSkd037gopB5YylN91Ck/AfyIZCdtcZ0HIdqtm8xuGeq4K8ajDl9T aIZ8ic1H8XMsHpt/PWlnS/iySlLxynDhUFrU9OeaBWdl0uGu9JOOYZrCxXsSbXaSCCCl pdY2BiJnhCyMPSccc7dTKgAGj8T82aNJ1heB1HwcNGnBQ0RnXOItVo8umxHNZSDRlCBV 4I05tfJ8nzDV5BQOU0IgDnuo1UOfk9WcXbotwxpiQ3tLt56MGy44nyJCvkuBPSjZ5oex Hkb6Ee/4iBf4VjjrnOyDacOzFa+DZYQPC014MoDBsXiqv4N0vOHdiYWZLd8/oy7jwiKV yU1g== X-Gm-Message-State: AO0yUKXIJYWMb3Pbr4TnO9YQ5OoPLf+tsmIszg616rLx5rcKdPLqkVgr mLoVJW5zFj4NExLuCLIz/istwS9vdArejqc2qMeNEGuDViUXVmJ8nYpEistw4IYUHXB6LFz02vY QC8zPGudeJN7zGKiC5NC6YmWeHzgH9TGGJpDrLzBP4gha/MFLH7Qq7f61OcxhB11miplM6X4P5g == X-Received: by 2002:ac8:7dc2:0:b0:3b8:68df:fc75 with SMTP id c2-20020ac87dc2000000b003b868dffc75mr15016385qte.31.1675186051173; Tue, 31 Jan 2023 09:27:31 -0800 (PST) X-Google-Smtp-Source: AK7set+CgFs2kyKO1RIw/pM7DzP6e/mqZNpsQUdjKAMrzTtkCopGR4HNhxiGsGrdRJicPooj8UtUsw== X-Received: by 2002:ac8:7dc2:0:b0:3b8:68df:fc75 with SMTP id c2-20020ac87dc2000000b003b868dffc75mr15016348qte.31.1675186050881; Tue, 31 Jan 2023 09:27:30 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id ea16-20020a05620a489000b007059c5929b8sm10394752qkb.21.2023.01.31.09.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:30 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 05/13] gdbserver: allow agent expressions to fail with invalid memory access Date: Tue, 31 Jan 2023 17:27:10 +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.8 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" This commit extends gdbserver to take account of a failed memory access from agent_mem_read, and to return a new eval_result_type expr_eval_invalid_memory_access. I have only updated the agent_mem_read calls related directly to reading memory, I have not updated any of the calls related to tracepoint data collection. This is just because I'm not familiar with that area of gdb/gdbserver, and I don't want to break anything, so leaving the existing behaviour as it is seems like the safest approach. I've then updated gdb.base/bp-cond-failure.exp to test evaluating the breakpoints on the target, and have also extended the test so that it checks for different sizes of memory access. --- gdb/testsuite/gdb.base/bp-cond-failure.exp | 21 +++++++-------------- gdbserver/ax.cc | 12 ++++++++---- gdbserver/ax.h | 3 ++- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp index 9388b8cf582..d67c68c46a1 100644 --- a/gdb/testsuite/gdb.base/bp-cond-failure.exp +++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp @@ -48,7 +48,7 @@ if { [is_address_zero_readable] } { # Where the breakpoint will be placed. set bp_line [gdb_get_line_number "Breakpoint here"] -proc run_test { cond_eval } { +proc run_test { cond_eval access_type } { clean_restart ${::binfile} if { ![runto_main] } { @@ -61,7 +61,7 @@ proc run_test { cond_eval } { } # Setup the conditional breakpoint and record its number. - gdb_breakpoint "${::srcfile}:${::bp_line} if (*(int *) 0) == 0" + gdb_breakpoint "${::srcfile}:${::bp_line} if (*(${access_type} *) 0) == 0" set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*"] gdb_test "continue" \ @@ -90,16 +90,7 @@ set cond_eval_modes { "auto" } gdb_test_multiple "show breakpoint condition-evaluation" "" { -re -wrap "Breakpoint condition evaluation mode is auto \\(currently target\\)\\." { - - ## NOTE: Instead of testing with "auto" and "host" in this - ## case we only test with "host". This is because a GDB bug - ## prevents the "auto" (a.k.a. target) mode from working. - ## - ## Don't worry, this will be fixed in a later commit, and this - ## comment will be removed at that time. - ## - ## lappend cond_eval_modes "host" - + lappend cond_eval_modes "host" set cond_eval_modes { "host" } pass $gdb_test_name } @@ -109,6 +100,8 @@ gdb_test_multiple "show breakpoint condition-evaluation" "" { } } -foreach_with_prefix cond_eval $cond_eval_modes { - run_test $cond_eval +foreach_with_prefix access_type { "char" "short" "int" "long long" } { + foreach_with_prefix cond_eval $cond_eval_modes { + run_test $cond_eval $access_type + } } diff --git a/gdbserver/ax.cc b/gdbserver/ax.cc index 38ebfbbd750..fba5b4ad0fc 100644 --- a/gdbserver/ax.cc +++ b/gdbserver/ax.cc @@ -1112,22 +1112,26 @@ gdb_eval_agent_expr (struct eval_agent_expr_context *ctx, break; case gdb_agent_op_ref8: - agent_mem_read (ctx, cnv.u8.bytes, (CORE_ADDR) top, 1); + if (agent_mem_read (ctx, cnv.u8.bytes, (CORE_ADDR) top, 1) != 0) + return expr_eval_invalid_memory_access; top = cnv.u8.val; break; case gdb_agent_op_ref16: - agent_mem_read (ctx, cnv.u16.bytes, (CORE_ADDR) top, 2); + if (agent_mem_read (ctx, cnv.u16.bytes, (CORE_ADDR) top, 2) != 0) + return expr_eval_invalid_memory_access; top = cnv.u16.val; break; case gdb_agent_op_ref32: - agent_mem_read (ctx, cnv.u32.bytes, (CORE_ADDR) top, 4); + if (agent_mem_read (ctx, cnv.u32.bytes, (CORE_ADDR) top, 4) != 0) + return expr_eval_invalid_memory_access; top = cnv.u32.val; break; case gdb_agent_op_ref64: - agent_mem_read (ctx, cnv.u64.bytes, (CORE_ADDR) top, 8); + if (agent_mem_read (ctx, cnv.u64.bytes, (CORE_ADDR) top, 8) != 0) + return expr_eval_invalid_memory_access; top = cnv.u64.val; break; diff --git a/gdbserver/ax.h b/gdbserver/ax.h index 8e64a7a593e..c98e36a83c6 100644 --- a/gdbserver/ax.h +++ b/gdbserver/ax.h @@ -41,7 +41,8 @@ enum eval_result_type expr_eval_unhandled_opcode, expr_eval_unrecognized_opcode, expr_eval_divide_by_zero, - expr_eval_invalid_goto + expr_eval_invalid_goto, + expr_eval_invalid_memory_access }; struct agent_expr From patchwork Tue Jan 31 17:27:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64034 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 76A7A3857007 for ; Tue, 31 Jan 2023 17:51:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76A7A3857007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187489; bh=CphmbfKO3o9OUFxC7uQ7P2Z6sXBrJSCUmxSn1SFwEtw=; 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=jBJeGhSQHvMvylhNEAN7wkHyG8/ZWjImQL19e+v9k04EyzN8xprSszM/Lpa7gOBvA gVqGYYSTTbGTWg7lO6UMYxkrasiaxWt0BwYVu80jlgBN2k654UImYgA1EFGeVu+nnX LhLxxenqOYiOWWyyId5DXbK0Dq8zU6tc4pL+F1JE= 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 4328E3858017 for ; Tue, 31 Jan 2023 17:49:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4328E3858017 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-241-8SLuw6f0N9a9Yryhff_RuQ-1; Tue, 31 Jan 2023 12:27:34 -0500 X-MC-Unique: 8SLuw6f0N9a9Yryhff_RuQ-1 Received: by mail-qv1-f70.google.com with SMTP id ng1-20020a0562143bc100b004bb706b3a27so8748699qvb.20 for ; Tue, 31 Jan 2023 09:27:34 -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=CphmbfKO3o9OUFxC7uQ7P2Z6sXBrJSCUmxSn1SFwEtw=; b=niQB5uLcTFY4EIMYof4wTi8sz3MYzYdrbrNeLcewqsKdNgsBlokQNgq7jBk8Ew+ntV gVpFHmX1HX/ybhaR5l1oRcz0oD1Qo0vFceEhSEUQCrVaNLHlQlbo5pWzWlbckNzi/igS bJ6QIfL9lS1OzUYKDvwDHOrJfaRVEMtNDjDMXkA83T5dROuXydzM5OURJTeuWsaOKu2m 856HLNN0hg/SLdKOKrm89N16rvX0KGg1yubYY8sTVMCNq/BnpLTRag+1CBcJBFMaD/cH rcaLfv5TmfJT7CsdbdxmN5Te4x7sLYbJFX1Wr/Itat0zEFxzCL0m/5Jq16zxE2KEJUVz +rvQ== X-Gm-Message-State: AO0yUKWicNzCeRx38XvKNljiWf/+qYkk6fO06wf2fH9dQPmwzAfgev0u EHRak9/CZd/okeothkJNMxtXX3xnB0AoBMgTNeVsGWtj8YGeYPn6r6RILy3pj5E+NHxRS0HU2Ak Zo4RJUNCab1k98guTu061BehnEARkEsOHLgMrfRHIJZBS7jumA9KHfGovQM7xDA07IZ0EYJn4AQ == X-Received: by 2002:a05:622a:1802:b0:3b8:2838:97b9 with SMTP id t2-20020a05622a180200b003b8283897b9mr26251850qtc.15.1675186053525; Tue, 31 Jan 2023 09:27:33 -0800 (PST) X-Google-Smtp-Source: AK7set+dYr1Zyh8AuRvJffxP0xRWPlRNVCfs4w0SOoH8mLZGWRsG5IdEZg8h9o1n1JJRmWhlA4rpPQ== X-Received: by 2002:a05:622a:1802:b0:3b8:2838:97b9 with SMTP id t2-20020a05622a180200b003b8283897b9mr26251786qtc.15.1675186052954; Tue, 31 Jan 2023 09:27:32 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id o13-20020a05620a2a0d00b006ce580c2663sm10456187qkp.35.2023.01.31.09.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:32 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 06/13] gdb: avoid repeated signal reporting during failed conditional breakpoint Date: Tue, 31 Jan 2023 17:27:11 +0000 Message-Id: <2d68ac313695f9b0c7a97aa63deb7e78c8799044.1675185990.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.8 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" Consider the following case: (gdb) list some_func 1 int 2 some_func () 3 { 4 int *p = 0; 5 return *p; 6 } 7 8 void 9 foo () 10 { (gdb) break foo if (some_func ()) Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Program received signal SIGSEGV, Segmentation fault. 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; Error in testing breakpoint condition: The program being debugged was signaled while in a function called from GDB. GDB remains in the frame where the signal was received. To change this behavior use "set unwindonsignal on". Evaluation of the expression containing the function (some_func) will be abandoned. When the function is done executing, GDB will silently stop. Program received signal SIGSEGV, Segmentation fault. Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; (gdb) Notice that this line: Program received signal SIGSEGV, Segmentation fault. Appears twice in the output. The first time is followed by the current location. The second time is a little odd, why do we print that? Printing that line is controlled, in part, by a global variable, stopped_by_random_signal. This variable is reset to zero in handle_signal_stop, and is set if/when GDB figures out that the inferior stopped due to some random signal. The problem is, in our case, GDB first stops at the breakpoint for foo, and enters handle_signal_stop and the stopped_by_random_signal global is reset to 0. Later within handle_signal_stop GDB calls bpstat_stop_status, it is within this function (via bpstat_check_breakpoint_conditions) that the breakpoint condition is checked, and, we end up calling the inferior function (some_func in our example above). In our case above the thread performing the inferior function call segfaults in some_func. GDB catches the SIGSEGV and handles the stop, this causes us to reenter handle_signal_stop. The global variable stopped_by_random_signal is updated, this time it is set to true because the thread stopped due to SIGSEGV. As a result of this we print the first instance of the line (as seen above in the example). Finally we unwind GDB's call stack, the inferior function call is complete, and we return to the original handle_signal_stop. However, the stopped_by_random_signal global is still carrying the value as computed for the inferior function call's stop, which is why we now print a second instance of the line, as seen in the example. To prevent this, I propose adding a scoped_restore before we start an inferior function call. This will save and restore the global stopped_by_random_signal value. With this done, the output from our example is now this: (gdb) list some_func 1 int 2 some_func () 3 { 4 int *p = 0; 5 return *p; 6 } 7 8 void 9 foo () 10 { (gdb) break foo if (some_func ()) Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Program received signal SIGSEGV, Segmentation fault. 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; Error in testing condition for breakpoint 1: The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function (some_func) will be abandoned. When the function is done executing, GDB will silently stop. Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; (gdb) We now only see the 'Program received signal SIGSEGV, ...' line once, which I think makes more sense. Finally, I'm aware that the last few lines, that report the stop as being at 'Breakpoint 1', when this is not where the thread is actually located anymore, is not great. I'll address that in the next commit. --- gdb/infcall.c | 9 + gdb/testsuite/gdb.base/infcall-failure.c | 48 ++++++ gdb/testsuite/gdb.base/infcall-failure.exp | 185 +++++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 gdb/testsuite/gdb.base/infcall-failure.c create mode 100644 gdb/testsuite/gdb.base/infcall-failure.exp diff --git a/gdb/infcall.c b/gdb/infcall.c index 4c2a4e4f400..8ebc3453072 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -1293,6 +1293,15 @@ call_function_by_hand_dummy (struct value *function, /* Register a clean-up for unwind_on_terminating_exception_breakpoint. */ SCOPE_EXIT { delete_std_terminate_breakpoint (); }; + /* The stopped_by_random_signal variable is global. If we are here + as part of a breakpoint condition check then the global will have + already been setup as part of the original breakpoint stop. By + making the inferior call the global will be changed when GDB + handles the stop after the inferior call. Avoid confusion by + restoring the current value after the inferior call. */ + scoped_restore restore_stopped_by_random_signal + = make_scoped_restore (&stopped_by_random_signal, 0); + /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - If you're looking to implement asynchronous dummy-frames, then just below is the place to chop this function in two.. */ diff --git a/gdb/testsuite/gdb.base/infcall-failure.c b/gdb/testsuite/gdb.base/infcall-failure.c new file mode 100644 index 00000000000..fae012b2cda --- /dev/null +++ b/gdb/testsuite/gdb.base/infcall-failure.c @@ -0,0 +1,48 @@ +/* Copyright 2022-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +/* A function that segfaults (assuming that reads of address zero are + prohibited), this is used from within a breakpoint condition. */ +int +func_segfault () +{ + volatile int *p = 0; + return *p; /* Segfault here. */ +} + +/* A function in which we will place a breakpoint. This function is itself + then used from within a breakpoint condition. */ +int +func_bp () +{ + int res = 0; /* Second breakpoint. */ + return res; +} + +int +foo () +{ + return 0; /* First breakpoint. */ +} + +int +main () +{ + int res = foo (); + + return res; +} diff --git a/gdb/testsuite/gdb.base/infcall-failure.exp b/gdb/testsuite/gdb.base/infcall-failure.exp new file mode 100644 index 00000000000..214a64f8de3 --- /dev/null +++ b/gdb/testsuite/gdb.base/infcall-failure.exp @@ -0,0 +1,185 @@ +# Copyright 2022-2023 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 . + +# Some simple tests of inferior function calls from breakpoint +# conditions, in a single-threaded inferior. +# +# Test what happens when the inferior function (from a breakpoint +# condition) either hits a nested breakpoint, or segfaults. + +standard_testfile + +if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ + {debug}] == -1 } { + return +} + +set bp_1_line [gdb_get_line_number "First breakpoint"] +set bp_2_line [gdb_get_line_number "Second breakpoint"] +set segv_line [gdb_get_line_number "Segfault here"] + +# Start GDB based on TARGET_ASYNC and TARGET_NON_STOP, and then runto +# main. +proc start_gdb_and_runto_main { target_async target_non_stop } { + save_vars { ::GDBFLAGS } { + append ::GDBFLAGS \ + " -ex \"maint set target-non-stop $target_non_stop\"" + append ::GDBFLAGS \ + " -ex \"maintenance set target-async ${target_async}\"" + + clean_restart ${::binfile} + } + + if { ![runto_main] } { + return -1 + } + + return 0 +} + +# Start GDB according to ASYNC_P and NON_STOP_P, then setup a +# conditional breakpoint. The breakpoint condition includes an +# inferior function call that will itself hit a breakpoint. Check how +# GDB reports this to the user. +proc_with_prefix run_cond_hits_breakpoint_test { async_p non_stop_p } { + if { [start_gdb_and_runto_main $async_p $non_stop_p] == -1 } { + return + } + + # Setup the conditional breakpoint and record its number. + gdb_breakpoint "${::srcfile}:${::bp_1_line} if (func_bp ())" + set bp_1_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number of first breakpoint"] + + # Setup a breakpoint inside func_bp. + gdb_breakpoint "${::srcfile}:${::bp_2_line}" + set bp_2_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number of second breakpoint"] + + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Breakpoint ${bp_2_num}, func_bp \\(\\) at \[^\r\n\]+:${::bp_2_line}" \ + "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+" \ + "Error in testing condition for breakpoint ${bp_1_num}:" \ + "The program being debugged stopped while in a function called from GDB\\." \ + "Evaluation of the expression containing the function" \ + "\\(func_bp\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\." \ + "" \ + "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ + "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+"] +} + +# Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior +# function. The inferior function being called will itself have a +# breakpoint within it. Check how GDB reports this to the user. +proc_with_prefix run_call_hits_breakpoint_test { async_p non_stop_p } { + if { [start_gdb_and_runto_main $async_p $non_stop_p] == -1 } { + return + } + + # Setup a breakpoint inside func_bp. + gdb_breakpoint "${::srcfile}:${::bp_2_line}" + set bp_2_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number of second breakpoint"] + + + gdb_test "call func_bp ()" \ + [multi_line \ + "" \ + "Breakpoint ${bp_2_num}, func_bp \\(\\) at \[^\r\n\]+:${::bp_2_line}" \ + "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+" \ + "The program being debugged stopped while in a function called from GDB\\." \ + "Evaluation of the expression containing the function" \ + "\\(func_bp\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] +} + +# Start GDB according to ASYNC_P and NON_STOP_P, then setup a +# conditional breakpoint. The breakpoint condition includes an +# inferior function call that segfaults. Check how GDB reports this +# to the user. +proc_with_prefix run_cond_hits_segfault_test { async_p non_stop_p } { + if { [start_gdb_and_runto_main $async_p $non_stop_p] == -1 } { + return + } + + # This test relies on the inferior segfaulting when trying to + # access address zero. + if { [is_address_zero_readable] } { + unsupported "address zero is readable" + return + } + + # Setup the conditional breakpoint and record its number. + gdb_breakpoint "${::srcfile}:${::bp_1_line} if (func_segfault ())" + set bp_1_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number of first breakpoint"] + + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Program received signal SIGSEGV, Segmentation fault\\." \ + "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ + "Error in testing condition for breakpoint ${bp_1_num}:" \ + "The program being debugged stopped while in a function called from GDB\\." \ + "Evaluation of the expression containing the function" \ + "\\(func_segfault\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\." \ + "" \ + "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+"] +} + +# Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior +# function. The inferior function will segfault. Check how GDB +# reports this to the user. +proc_with_prefix run_call_hits_segfault_test { async_p non_stop_p } { + if { [start_gdb_and_runto_main $async_p $non_stop_p] == -1 } { + return + } + + # This test relies on the inferior segfaulting when trying to + # access address zero. + if { [is_address_zero_readable] } { + unsupported "address zero is readable" + return + } + + gdb_test "call func_segfault ()" \ + [multi_line \ + "" \ + "Program received signal SIGSEGV, Segmentation fault\\." \ + "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ + "The program being debugged stopped while in a function called from GDB\\." \ + "Evaluation of the expression containing the function" \ + "\\(func_segfault\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] +} + +foreach_with_prefix target_async { "on" "off" } { + foreach_with_prefix target_non_stop { "on" "off" } { + run_cond_hits_breakpoint_test $target_async $target_non_stop + run_call_hits_breakpoint_test $target_async $target_non_stop + + run_cond_hits_segfault_test $target_async $target_non_stop + run_call_hits_segfault_test $target_async $target_non_stop + } +} From patchwork Tue Jan 31 17:27:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64033 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 0A54A384F037 for ; Tue, 31 Jan 2023 17:50:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A54A384F037 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187457; bh=tUvZyh2yI8B2Rv+7QC1Ypn6Du0lP2qP2i7TbHhDYjkI=; 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=sM1SO9UkDuUpP6UZJAH8/yRQkxOMT9+IdJnmVH0wN9mXpB6Hs5EI/SJn/D6C2WOdy /KVvVrGG9pcE2ViiNKR1n8rEN/zjnWdVoSQwn/QYWYQcubNNX5PhSpP5QDeJ8u+TAS gxaQVilbCi8CJyJD9d4iVkfSrfuoffhBQZexfdA8= 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 B95603858C2F for ; Tue, 31 Jan 2023 17:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B95603858C2F Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-397-IigXy5dcMDiF6c5if-5RRQ-1; Tue, 31 Jan 2023 12:27:36 -0500 X-MC-Unique: IigXy5dcMDiF6c5if-5RRQ-1 Received: by mail-qk1-f198.google.com with SMTP id q21-20020a05620a0d9500b0070572ccdbf9so9551911qkl.10 for ; Tue, 31 Jan 2023 09:27:35 -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=tUvZyh2yI8B2Rv+7QC1Ypn6Du0lP2qP2i7TbHhDYjkI=; b=wmPyFY9AapKzvL3y6v4TTS0SvIeR8zYEgLu0THwx1wnjYFI88xvyRszGEravXHaSgv 82xHClFVvjC1qT5Ak5IA84kZzfwPoystSmtMV2Mzccnyrv9l19PrcIRCSsQz0Cp3ODxs ynLFpZZA1QkRKM3zQMG+Lnk//vvY7S+3CasKbLSG1l86i+OpGPgpanRwU+TH8vVypLad azBE+SR5lEODzK/GTORu0rArT2b4PqgYWGjEbPxnobsZYqLyYVSzDVAXKicM5Fu65xYu vCRvIbUBj6m1z6mvC2nzre6Zk0LkuKGdAKkgdhOeTrqWF4/Vtb+3REooo8l6fOPFWiFv MMjw== X-Gm-Message-State: AO0yUKWqRhgM0Dh+uLbCpAY4AV0WH5pX2spM9EQw2/3q3Dt5pxAo7C8/ firoLOIM0Ba18m/YeCQZmibOBlTX0NNDJZpIz5k0MNzp1MBcur4p9Az0uoFYP6Gb4mMRBPxzb1l 4oAzX8bEOEOREBC0V8qdLdG+R7Sh9CPfZcCDjOaNJQUzzx+AaYGbmGP4Br17fdteK1CSZ8P4TNA == X-Received: by 2002:ac8:5f91:0:b0:3b8:6c10:f52 with SMTP id j17-20020ac85f91000000b003b86c100f52mr12774269qta.46.1675186055352; Tue, 31 Jan 2023 09:27:35 -0800 (PST) X-Google-Smtp-Source: AK7set9KTEbnbVBaz8jXleaxxWtZAcgyLiB/YmekFGFoCoCoEzMjFbJOeqNafqCnsKIGwfZZYqBV2w== X-Received: by 2002:ac8:5f91:0:b0:3b8:6c10:f52 with SMTP id j17-20020ac85f91000000b003b86c100f52mr12774226qta.46.1675186054915; Tue, 31 Jan 2023 09:27:34 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id s1-20020ac85281000000b003b63238615fsm10105061qtn.46.2023.01.31.09.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:34 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 07/13] gdb: don't always print breakpoint location after failed condition check Date: Tue, 31 Jan 2023 17:27:12 +0000 Message-Id: <6a271d2d74565861813fcd7d3c0c8edb0b4e6375.1675185990.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.8 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" Consider the following session: (gdb) list some_func 1 int 2 some_func () 3 { 4 int *p = 0; 5 return *p; 6 } 7 8 void 9 foo () 10 { (gdb) break foo if (some_func ()) Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Program received signal SIGSEGV, Segmentation fault. 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; Error in testing condition for breakpoint 1: The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function (some_func) will be abandoned. When the function is done executing, GDB will silently stop. Breakpoint 1, 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; (gdb) What happens here is the breakpoint condition includes a call to an inferior function, and the inferior function segfaults. We can see that GDB reports the segfault, and then gives an error message that indicates that an inferior function call was interrupted. After this GDB appears to report that it is stopped at Breakpoint 1, inside some_func. I find this second stop report a little confusing. While it is true that GDB stopped as a result of hitting breakpoint 1, I think the message GDB currently prints might give the impression that GDB is actually stopped at a location of breakpoint 1, which is not the case. Also, I find the second stop message draws attention away from the "Program received signal SIGSEGV, Segmentation fault" stop message, and this second stop might be thought of as replacing in someway the earlier message. In short, I think things would be clearer if the second stop message were not reported at all, so the output should, I think, look like this: (gdb) list some_func 1 int 2 some_func () 3 { 4 int *p = 0; 5 return *p; 6 } 7 8 void 9 foo () 10 { (gdb) break foo if (some_func ()) Breakpoint 1 at 0x40111e: file bpcond.c, line 11. (gdb) r Starting program: /tmp/bpcond Program received signal SIGSEGV, Segmentation fault. 0x0000000000401116 in some_func () at bpcond.c:5 5 return *p; Error in testing condition for breakpoint 1: The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function (some_func) will be abandoned. When the function is done executing, GDB will silently stop. (gdb) The user can still find the number of the breakpoint that triggered the initial stop in this line: Error in testing condition for breakpoint 1: But there's now only one stop reason reported, the SIGSEGV, which I think is much clearer. To achieve this change I set the bpstat::print field when: (a) a breakpoint condition evaluation failed, and (b) the $pc of the thread changed during condition evaluation. I've updated the existing tests that checked the error message printed when a breakpoint condition evaluation failed. --- gdb/breakpoint.c | 12 ++++++++++++ gdb/testsuite/gdb.base/infcall-failure.exp | 18 ++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index eecaeefed3e..c4fec7e8e55 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5533,6 +5533,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) else within_current_scope = false; } + CORE_ADDR pc_before_check = get_frame_pc (get_selected_frame (nullptr)); if (within_current_scope) { try @@ -5544,6 +5545,17 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) exception_fprintf (gdb_stderr, ex, "Error in testing condition for breakpoint %d:\n", b->number); + + /* If the pc value changed as a result of evaluating the + condition then we probably stopped within an inferior + function call due to some unexpected stop, e.g. the thread + hit another breakpoint, or the thread received an + unexpected signal. In this case we don't want to also + print the information about this breakpoint. */ + CORE_ADDR pc_after_check + = get_frame_pc (get_selected_frame (nullptr)); + if (pc_before_check != pc_after_check) + bs->print = 0; } } else diff --git a/gdb/testsuite/gdb.base/infcall-failure.exp b/gdb/testsuite/gdb.base/infcall-failure.exp index 214a64f8de3..5ad179a089d 100644 --- a/gdb/testsuite/gdb.base/infcall-failure.exp +++ b/gdb/testsuite/gdb.base/infcall-failure.exp @@ -78,10 +78,7 @@ proc_with_prefix run_cond_hits_breakpoint_test { async_p non_stop_p } { "The program being debugged stopped while in a function called from GDB\\." \ "Evaluation of the expression containing the function" \ "\\(func_bp\\) will be abandoned\\." \ - "When the function is done executing, GDB will silently stop\\." \ - "" \ - "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ - "${::decimal}\\s+\[^\r\n\]+Second breakpoint\[^\r\n\]+"] + "When the function is done executing, GDB will silently stop\\."] } # Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior @@ -138,13 +135,12 @@ proc_with_prefix run_cond_hits_segfault_test { async_p non_stop_p } { "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ "Error in testing condition for breakpoint ${bp_1_num}:" \ - "The program being debugged stopped while in a function called from GDB\\." \ + "The program being debugged was signaled while in a function called from GDB\\." \ + "GDB remains in the frame where the signal was received\\." \ + "To change this behavior use \"set unwindonsignal on\"\\." \ "Evaluation of the expression containing the function" \ "\\(func_segfault\\) will be abandoned\\." \ - "When the function is done executing, GDB will silently stop\\." \ - "" \ - "Breakpoint ${bp_1_num}, \[^\r\n\]+" \ - "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+"] + "When the function is done executing, GDB will silently stop\\."] } # Start GDB according to ASYNC_P and NON_STOP_P, then call an inferior @@ -168,7 +164,9 @@ proc_with_prefix run_call_hits_segfault_test { async_p non_stop_p } { "Program received signal SIGSEGV, Segmentation fault\\." \ "${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \ "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ - "The program being debugged stopped while in a function called from GDB\\." \ + "The program being debugged was signaled while in a function called from GDB\\." \ + "GDB remains in the frame where the signal was received\\." \ + "To change this behavior use \"set unwindonsignal on\"\\." \ "Evaluation of the expression containing the function" \ "\\(func_segfault\\) will be abandoned\\." \ "When the function is done executing, GDB will silently stop\\."] From patchwork Tue Jan 31 17:27:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64030 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 7CE5A3858C39 for ; Tue, 31 Jan 2023 17:50:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CE5A3858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187425; bh=iM7811YNimi4dHql0gtvTnaJkZLrG1ns2bSGYUHGK9U=; 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=r24gc8IdVqx5b8Kt68CM2wrFOweU4U9zS1CfM3ZIIAkOxA2vAcCnUnjoABHQz0Mlf nWqE3HqpLnNW6MPqm1EhyVmh9PWfM1bs57BColQv83VPV2clYYZ3KsfHuyPaTUN2Dv jbT7SIu5kRPNHmYdL7o70uppQ1MEjnt/k78NDDAc= 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 4354E3858C5F for ; Tue, 31 Jan 2023 17:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4354E3858C5F Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-636-GjNfyKQtNCKjsaGG48vD2w-1; Tue, 31 Jan 2023 12:27:37 -0500 X-MC-Unique: GjNfyKQtNCKjsaGG48vD2w-1 Received: by mail-qt1-f200.google.com with SMTP id a24-20020ac84d98000000b003b9a4958f0cso2072911qtw.3 for ; Tue, 31 Jan 2023 09:27:37 -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=iM7811YNimi4dHql0gtvTnaJkZLrG1ns2bSGYUHGK9U=; b=baXPmGTOAYBfQthZJoZ68yyQKC+i0XGhw9Mk2GYm8vfDvTzV3yGOcczwGhLI9YwtBC 1eFjlL+BISzi4H4s+l1M7Rc1b2HnFHCFmtDtTdrEE77SQCbb1hDHDy/pfwaW+a/gbVNp gPuEAMRvkWuWlq3WK7OSlKRESYUcwIQ24WimIlrWC0pfulxDCeleXSD8N7Klo7IONY2W jrbNl3v/AphbWiYYx57PtUpB0R1mEpa7gtXVdw44tnFISTJ3ZwDjB5zZq6PdqbohcCd4 Pp/445meEQWbPcarYvxwLOO1v4q7set50tYCK+84j8TXD/FJjh5F2IdoUC78IesDgVxa 2NeQ== X-Gm-Message-State: AO0yUKUkBezIBlBHPrBeffGxZK+UKwFvhzHYoz5KV/DsE3cga6zoMcZN Ipz+JiyBsKc+B2VclJ/TIIKH35g2N2huDWxd3nVZSBIeER33c47OhzDbbNsmo5/U8A4fi4Nh7Ib Rnex9McUlU1yEFoNqcmzpnZWZcolkFnFpDpTSSNithUESIipiugFsNg/0AZSLJSnA4zT7Oom27Q == X-Received: by 2002:ac8:5a41:0:b0:3b8:6db0:7565 with SMTP id o1-20020ac85a41000000b003b86db07565mr10101100qta.11.1675186057121; Tue, 31 Jan 2023 09:27:37 -0800 (PST) X-Google-Smtp-Source: AK7set+kKMhKZq8jb0j4hDN+iF+kb44dpi00p4I9cLhLd0kkKLR7loBQmB+FddFoVryEiXY5LVzljQ== X-Received: by 2002:ac8:5a41:0:b0:3b8:6db0:7565 with SMTP id o1-20020ac85a41000000b003b86db07565mr10101070qta.11.1675186056824; Tue, 31 Jan 2023 09:27:36 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id a26-20020aed279a000000b003b8484fdfccsm6251747qtd.42.2023.01.31.09.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:36 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 08/13] Revert "gdb: remove unnecessary parameter wait_ptid from do_target_wait" Date: Tue, 31 Jan 2023 17:27:13 +0000 Message-Id: <4cc6209933e165e056ad97dfd9b946eaea1f38ea.1675185990.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.8 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" This reverts commit ac0d67ed1dcf470bad6a3bc4800c2ddc9bedecca. There was nothing wrong with the commit which I'm reverting here, but it removed some functionality that will be needed for a later commit; that is, the ability for GDB to ask for events from a specific ptid_t via the do_target_wait function. In a follow up commit, this functionality will be used to implement inferior function calls in multi-threaded inferiors. This is not a straight revert of the above commit. Reverting the above commit replaces a 'nullptr' with 'NULL', I've gone in and changed that, preserving the 'nullptr'. --- gdb/infrun.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index edfb5ab0a91..f97349f47d2 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3741,7 +3741,8 @@ do_target_wait_1 (inferior *inf, ptid_t ptid, more events. Polls for events from all inferiors/targets. */ static bool -do_target_wait (execution_control_state *ecs, target_wait_flags options) +do_target_wait (ptid_t wait_ptid, execution_control_state *ecs, + target_wait_flags options) { int num_inferiors = 0; int random_selector; @@ -3751,9 +3752,10 @@ do_target_wait (execution_control_state *ecs, target_wait_flags options) polling the rest of the inferior list starting from that one in a circular fashion until the whole list is polled once. */ - auto inferior_matches = [] (inferior *inf) + auto inferior_matches = [&wait_ptid] (inferior *inf) { - return inf->process_target () != nullptr; + return (inf->process_target () != nullptr + && ptid_t (inf->pid).matches (wait_ptid)); }; /* First see how many matching inferiors we have. */ @@ -3792,7 +3794,7 @@ do_target_wait (execution_control_state *ecs, target_wait_flags options) auto do_wait = [&] (inferior *inf) { - ecs->ptid = do_target_wait_1 (inf, minus_one_ptid, &ecs->ws, options); + ecs->ptid = do_target_wait_1 (inf, wait_ptid, &ecs->ws, options); ecs->target = inf->process_target (); return (ecs->ws.kind () != TARGET_WAITKIND_IGNORE); }; @@ -4169,7 +4171,7 @@ fetch_inferior_event () the event. */ scoped_disable_commit_resumed disable_commit_resumed ("handling event"); - if (!do_target_wait (&ecs, TARGET_WNOHANG)) + if (!do_target_wait (minus_one_ptid, &ecs, TARGET_WNOHANG)) { infrun_debug_printf ("do_target_wait returned no event"); disable_commit_resumed.reset_and_commit (); From patchwork Tue Jan 31 17:27:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64039 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 D95AF385B50F for ; Tue, 31 Jan 2023 17:52:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D95AF385B50F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187570; bh=IkZSqK5l2VcmcYb833OYUQKthdxKGT6JpWSkFvVN5zo=; 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=rXOV5Oazu4xG/hf77DVdt9VTafBxh+8F2+og6G3ItTzC7hhYlBg/GHDU36lGqiO4i ZR4LEuEsdpv/TdiVJknm2QfuR0hL9ucGO7HLZCS04iH6nZnAC3QPF5lYY37YRvjrBB 61yr3cb+bzzfxKVUzOJIFtLClszoUpgwShI6EyeI= 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 2B85B385841A for ; Tue, 31 Jan 2023 17:49:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B85B385841A Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-587-RoDjCRPAM0ycqyX4jFnKmg-1; Tue, 31 Jan 2023 12:27:41 -0500 X-MC-Unique: RoDjCRPAM0ycqyX4jFnKmg-1 Received: by mail-qk1-f198.google.com with SMTP id x7-20020a05620a098700b007242aa494ddso2791605qkx.19 for ; Tue, 31 Jan 2023 09:27:41 -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=IkZSqK5l2VcmcYb833OYUQKthdxKGT6JpWSkFvVN5zo=; b=Vwnqx2xWTJJlcUQhsUxrCWFotyLtYyymBzQc07LKn0tmgAcrbzYrZM3pP+4f/dg1xd jejVByDfJTth80EMCyU1aApifjByaSEaIpw+STusMsPo04cxD7Ddz8LsvTmJq/MmPboY iaTOlEqXGxYay7cZ3C4rR66hpCYCN+cK9qt5HiPqzu1YPSyF4tWH6Ake7kiPBBl3n69d ArUZ/LhiDM1x1Kz4rRUhFoSahxSvcP73o71jVgNtyondNzZ38T88yK6kby8azbZ+79oS LrHaF7/pVH632lzK7KRcZyA9lsS1c2qaTN5jSxjCiFK9K4ZqPimi0PLKaJahLaxxr6Ap 7C9A== X-Gm-Message-State: AO0yUKVuBcSukeaQBYvDbs/m/e71Pos2QonfDuoY6v6yUVm7c8DI/U1+ QaljzJK1xDSsjY1m2G8+R9gmqAEJADIeMsGzhUmgW/Yib9H2152IT2W8k2y9L66I0ha9JvDMk6t 6+JGpHJAjB8xYpNkqZJ6TGfAJ5PEe+x+ZJpCbrEI91XVte7S8XkyTxaCw64KlTu5m3dbZlvca+A == X-Received: by 2002:a05:622a:111:b0:3b8:ea9b:cbc6 with SMTP id u17-20020a05622a011100b003b8ea9bcbc6mr9934214qtw.56.1675186060317; Tue, 31 Jan 2023 09:27:40 -0800 (PST) X-Google-Smtp-Source: AK7set/v9QuzQ1pORyvETGcPO2J11tw3fy50k6Yu6n6HVUhnOIOw1dnFLsFxvOXr2cJ2POSv8KZpTw== X-Received: by 2002:a05:622a:111:b0:3b8:ea9b:cbc6 with SMTP id u17-20020a05622a011100b003b8ea9bcbc6mr9934071qtw.56.1675186058876; Tue, 31 Jan 2023 09:27:38 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id fu3-20020a05622a5d8300b003a7eb5baf3csm10076523qtb.69.2023.01.31.09.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:38 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Natalia Saiapova , Tankut Baris Aktemur Subject: [PATCHv3 09/13] gdb: fix b/p conditions with infcalls in multi-threaded inferiors Date: Tue, 31 Jan 2023 17:27:14 +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.8 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 fixes bug PR 28942, that is, creating a conditional breakpoint in a multi-threaded inferior, where the breakpoint condition includes an inferior function call. Currently, when a user tries to create such a breakpoint, then GDB will fail with: (gdb) break infcall-from-bp-cond-single.c:61 if (return_true ()) Breakpoint 2 at 0x4011fa: file /tmp/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.c, line 61. (gdb) continue Continuing. [New Thread 0x7ffff7c5d700 (LWP 2460150)] [New Thread 0x7ffff745c700 (LWP 2460151)] [New Thread 0x7ffff6c5b700 (LWP 2460152)] [New Thread 0x7ffff645a700 (LWP 2460153)] [New Thread 0x7ffff5c59700 (LWP 2460154)] Error in testing breakpoint condition: Couldn't get registers: No such process. An error occurred while in a function called from GDB. Evaluation of the expression containing the function (return_true) will be abandoned. When the function is done executing, GDB will silently stop. Selected thread is running. (gdb) Or, in some cases, like this: (gdb) break infcall-from-bp-cond-simple.c:56 if (is_matching_tid (arg, 1)) Breakpoint 2 at 0x401194: file /tmp/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.c, line 56. (gdb) continue Continuing. [New Thread 0x7ffff7c5d700 (LWP 2461106)] [New Thread 0x7ffff745c700 (LWP 2461107)] ../../src.release/gdb/nat/x86-linux-dregs.c:146: internal-error: x86_linux_update_debug_registers: Assertion `lwp_is_stopped (lwp)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. The precise error depends on the exact thread state; so there's race conditions depending on which threads have fully started, and which have not. But the underlying problem is always the same; when GDB tries to execute the inferior function call from within the breakpoint condition, GDB will, incorrectly, try to resume threads that are already running - GDB doesn't realise that some threads might already be running. The solution proposed in this patch requires an additional member variable thread_info::in_cond_eval. This flag is set to true (in breakpoint.c) when GDB is evaluating a breakpoint condition. In user_visible_resume_ptid (infrun.c), when the in_cond_eval flag is true, then GDB will only try to resume the current thread, that is, the thread for which the breakpoint condition is being evaluated. This solves the problem of GDB trying to resume threads that are already running. The next problem is that inferior function calls are assumed to be synchronous, that is, GDB doesn't expect to start an inferior function call in thread #1, then receive a stop from thread #2 for some other, unrelated reason. To prevent GDB responding to an event from another thread, we update fetch_inferior_event and do_target_wait in infrun.c, so that, when an inferior function call (on behalf of a breakpoint condition) is in progress, we only wait for events from the current thread (the one evaluating the condition). In do_target_wait I had to change the inferior_matches lambda function, which is used to select which inferior to wait on. Previously the logic was this: auto inferior_matches = [&wait_ptid] (inferior *inf) { return (inf->process_target () != nullptr && ptid_t (inf->pid).matches (wait_ptid)); }; This compares the pid of the inferior against the complete ptid we want to wait on. Before this commit wait_ptid was only ever minus_one_ptid (which is special, and means any process), and so every inferior would match. After this commit though wait_ptid might represent a specific thread in a specific inferior. If we compare the pid of the inferior to a specific ptid then these will not match. The fix is to compare against the pid extracted from the wait_ptid, not against the complete wait_ptid itself. In fetch_inferior_event, after receiving the event, we only want to stop all the other threads, and call inferior_event_handler with INF_EXEC_COMPLETE, if we are not evaluating a conditional breakpoint. If we are, then all the other threads should be left doing whatever they were before. The inferior_event_handler call will be performed once the breakpoint condition has finished being evaluated, and GDB decides to stop or not. The final problem that needs solving relates to GDB's commit-resume mechanism, which allows GDB to collect resume requests into a single packet in order to reduce traffic to a remote target. The problem is that the commit-resume mechanism will not send any resume requests for an inferior if there are already events pending on the GDB side. Imagine an inferior with two threads. Both threads hit a breakpoint, maybe the same conditional breakpoint. At this point there are two pending events, one for each thread. GDB selects one of the events and spots that this is a conditional breakpoint, GDB evaluates the condition. The condition includes an inferior function call, so GDB sets up for the call and resumes the one thread, the resume request is added to the commit-resume queue. When the commit-resume queue is committed GDB sees that there is a pending event from another thread, and so doesn't send any resume requests to the actual target, GDB is assuming that when we wait we will select the event from the other thread. However, as this is an inferior function call for a condition evaluation, we will not select the event from the other thread, we only care about events from the thread that is evaluating the condition - and the resume for this thread was never sent to the target. And so, GDB hangs, waiting for an event from a thread that was never fully resumed. To fix this issue I have added the concept of "forcing" the commit-resume queue. When enabling commit resume, if the force flag is true, then any resumes will be committed to the target, even if there are other threads with pending events. A note on authorship: this patch was based on some work done by Natalia Saiapova and Tankut Baris Aktemur from Intel[1]. I have made some changes to their work in this version. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28942 [1] https://sourceware.org/pipermail/gdb-patches/2020-October/172454.html Co-authored-by: Natalia Saiapova Co-authored-by: Tankut Baris Aktemur --- gdb/breakpoint.c | 2 + gdb/gdbthread.h | 3 + gdb/infcall.c | 6 + gdb/infrun.c | 64 +++-- gdb/infrun.h | 3 +- .../infcall-from-bp-cond-other-thread-event.c | 135 ++++++++++ ...nfcall-from-bp-cond-other-thread-event.exp | 175 +++++++++++++ .../gdb.threads/infcall-from-bp-cond-simple.c | 89 +++++++ .../infcall-from-bp-cond-simple.exp | 236 ++++++++++++++++++ .../gdb.threads/infcall-from-bp-cond-single.c | 139 +++++++++++ .../infcall-from-bp-cond-single.exp | 118 +++++++++ 11 files changed, 955 insertions(+), 15 deletions(-) create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.c create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.exp create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.c create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.c create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c4fec7e8e55..0cb4382ba5b 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5538,6 +5538,8 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) { try { + scoped_restore reset_in_cond_eval + = make_scoped_restore (&thread->control.in_cond_eval, true); condition_result = breakpoint_cond_eval (cond); } catch (const gdb_exception &ex) diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index c0f27a8a66e..736d5d50b5f 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -171,6 +171,9 @@ struct thread_control_state command. This is used to decide whether "set scheduler-locking step" behaves like "on" or "off". */ int stepping_command = 0; + + /* True if the thread is evaluating a BP condition. */ + bool in_cond_eval = false; }; /* Inferior thread specific part of `struct infcall_suspend_state'. */ diff --git a/gdb/infcall.c b/gdb/infcall.c index 8ebc3453072..34838dea1bd 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -641,6 +641,12 @@ run_inferior_call (std::unique_ptr sm, proceed (real_pc, GDB_SIGNAL_0); + /* Enable commit resume, but pass true for the force flag. This + ensures any thread we set running in proceed will actually be + committed to the target, even if some other thread in the current + target has a pending event. */ + scoped_enable_commit_resumed enable ("infcall", true); + infrun_debug_show_threads ("non-exited threads after proceed for inferior-call", all_non_exited_threads ()); diff --git a/gdb/infrun.c b/gdb/infrun.c index f97349f47d2..77a9a5bb7a8 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -2149,6 +2149,14 @@ user_visible_resume_ptid (int step) mode. */ resume_ptid = inferior_ptid; } + else if (inferior_ptid != null_ptid + && inferior_thread ()->control.in_cond_eval) + { + /* The inferior thread is evaluating a BP condition. Other threads + might be stopped or running and we do not want to change their + state, thus, resume only the current thread. */ + resume_ptid = inferior_ptid; + } else if (!sched_multi && target_supports_multi_process ()) { /* Resume all threads of the current process (and none of other @@ -2856,12 +2864,24 @@ schedlock_applies (struct thread_info *tp) execution_direction))); } -/* Set process_stratum_target::COMMIT_RESUMED_STATE in all target - stacks that have threads executing and don't have threads with - pending events. */ +/* When FORCE_P is false, set process_stratum_target::COMMIT_RESUMED_STATE + in all target stacks that have threads executing and don't have threads + with pending events. + + When FORCE_P is true, set process_stratum_target::COMMIT_RESUMED_STATE + in all target stacks that have threads executing regardless of whether + there are pending events or not. + + Passing FORCE_P as false makes sense when GDB is going to wait for + events from all threads and will therefore spot the pending events. + However, if GDB is only going to wait for events from select threads + (i.e. when performing an inferior call) then a pending event on some + other thread will not be spotted, and if we fail to commit the resume + state for the thread performing the inferior call, then the inferior + call will never complete (or even start). */ static void -maybe_set_commit_resumed_all_targets () +maybe_set_commit_resumed_all_targets (bool force_p) { scoped_restore_current_thread restore_thread; @@ -2890,7 +2910,7 @@ maybe_set_commit_resumed_all_targets () status to report, handle it before requiring the target to commit its resumed threads: handling the status might lead to resuming more threads. */ - if (proc_target->has_resumed_with_pending_wait_status ()) + if (!force_p && proc_target->has_resumed_with_pending_wait_status ()) { infrun_debug_printf ("not requesting commit-resumed for target %s, a" " thread has a pending waitstatus", @@ -2900,7 +2920,7 @@ maybe_set_commit_resumed_all_targets () switch_to_inferior_no_thread (inf); - if (target_has_pending_events ()) + if (!force_p && target_has_pending_events ()) { infrun_debug_printf ("not requesting commit-resumed for target %s, " "target has pending events", @@ -2993,7 +3013,7 @@ scoped_disable_commit_resumed::reset () { /* This is the outermost instance, re-enable COMMIT_RESUMED_STATE on the targets where it's possible. */ - maybe_set_commit_resumed_all_targets (); + maybe_set_commit_resumed_all_targets (false); } else { @@ -3026,7 +3046,7 @@ scoped_disable_commit_resumed::reset_and_commit () /* See infrun.h. */ scoped_enable_commit_resumed::scoped_enable_commit_resumed - (const char *reason) + (const char *reason, bool force_p) : m_reason (reason), m_prev_enable_commit_resumed (enable_commit_resumed) { @@ -3038,7 +3058,7 @@ scoped_enable_commit_resumed::scoped_enable_commit_resumed /* Re-enable COMMIT_RESUMED_STATE on the targets where it's possible. */ - maybe_set_commit_resumed_all_targets (); + maybe_set_commit_resumed_all_targets (force_p); maybe_call_commit_resumed_all_targets (); } @@ -3752,10 +3772,11 @@ do_target_wait (ptid_t wait_ptid, execution_control_state *ecs, polling the rest of the inferior list starting from that one in a circular fashion until the whole list is polled once. */ - auto inferior_matches = [&wait_ptid] (inferior *inf) + ptid_t wait_ptid_pid {wait_ptid.pid ()}; + auto inferior_matches = [&wait_ptid_pid] (inferior *inf) { return (inf->process_target () != nullptr - && ptid_t (inf->pid).matches (wait_ptid)); + && ptid_t (inf->pid).matches (wait_ptid_pid)); }; /* First see how many matching inferiors we have. */ @@ -4171,7 +4192,17 @@ fetch_inferior_event () the event. */ scoped_disable_commit_resumed disable_commit_resumed ("handling event"); - if (!do_target_wait (minus_one_ptid, &ecs, TARGET_WNOHANG)) + /* Is the current thread performing an inferior function call as part + of a breakpoint condition evaluation? */ + bool in_cond_eval = (inferior_ptid != null_ptid + && inferior_thread ()->control.in_cond_eval); + + /* If the thread is in the middle of the condition evaluation, wait for + an event from the current thread. Otherwise, wait for an event from + any thread. */ + ptid_t waiton_ptid = in_cond_eval ? inferior_ptid : minus_one_ptid; + + if (!do_target_wait (waiton_ptid, &ecs, TARGET_WNOHANG)) { infrun_debug_printf ("do_target_wait returned no event"); disable_commit_resumed.reset_and_commit (); @@ -4223,7 +4254,12 @@ fetch_inferior_event () bool should_notify_stop = true; bool proceeded = false; - stop_all_threads_if_all_stop_mode (); + /* If the thread that stopped just completed an inferior + function call as part of a condition evaluation, then we + don't want to stop all the other threads. */ + if (ecs.event_thread == nullptr + || !ecs.event_thread->control.in_cond_eval) + stop_all_threads_if_all_stop_mode (); clean_up_just_stopped_threads_fsms (&ecs); @@ -4238,7 +4274,7 @@ fetch_inferior_event () proceeded = normal_stop (); } - if (!proceeded) + if (!proceeded && !in_cond_eval) { inferior_event_handler (INF_EXEC_COMPLETE); cmd_done = 1; diff --git a/gdb/infrun.h b/gdb/infrun.h index 43fd1b44f5a..a78b5feb4a9 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -395,7 +395,8 @@ extern void maybe_call_commit_resumed_all_targets (); struct scoped_enable_commit_resumed { - explicit scoped_enable_commit_resumed (const char *reason); + explicit scoped_enable_commit_resumed (const char *reason, + bool force_p = false); ~scoped_enable_commit_resumed (); DISABLE_COPY_AND_ASSIGN (scoped_enable_commit_resumed); diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.c b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.c new file mode 100644 index 00000000000..e2a8ccb4ebe --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.c @@ -0,0 +1,135 @@ +/* Copyright 2022-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 +#include +#include + +#define NUM_THREADS 2 + +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +/* Some global variables to poke, just for something to do. */ +volatile int global_var_0 = 0; +volatile int global_var_1 = 0; + +/* This flag is updated from GDB. */ +volatile int raise_signal = 0; + +/* Implement the breakpoint condition function. Release the other thread + and try to give the other thread a chance to run. Then return ANSWER. */ +int +condition_core_func (int answer) +{ + /* This unlock should release the other thread. */ + if (pthread_mutex_unlock (&mutex) != 0) + abort (); + + /* And this yield and sleep should (hopefully) give the other thread a + chance to run. This isn't guaranteed of course, but once the other + thread does run it should hit a breakpoint, which GDB should + (temporarily) ignore, so there's no easy way for us to know the other + thread has done what it needs to, thus, yielding and sleeping is the + best we can do. */ + sched_yield (); + sleep (2); + + return answer; +} + +void +stop_marker () +{ + int a = 100; /* Final breakpoint here. */ +} + +/* A breakpoint condition function that always returns true. */ +int +condition_true_func () +{ + return condition_core_func (1); +} + +/* A breakpoint condition function that always returns false. */ +int +condition_false_func () +{ + return condition_core_func (0); +} + +void * +worker_func (void *arg) +{ + volatile int *ptr = 0; + int tid = *((int *) arg); + + switch (tid) + { + case 0: + global_var_0 = 11; /* First thread breakpoint. */ + break; + + case 1: + if (pthread_mutex_lock (&mutex) != 0) + abort (); + if (raise_signal) + global_var_1 = *ptr; /* Signal here. */ + else + global_var_1 = 99; /* Other thread breakpoint. */ + break; + + default: + abort (); + } + + return NULL; +} + +int +main () +{ + pthread_t threads[NUM_THREADS]; + int args[NUM_THREADS]; + + /* Set an alarm, just in case the test deadlocks. */ + alarm (300); + + /* We want the mutex to start locked. */ + if (pthread_mutex_lock (&mutex) != 0) + abort (); + + for (int i = 0; i < NUM_THREADS; i++) + { + args[i] = i; + pthread_create (&threads[i], NULL, worker_func, &args[i]); + } + + for (int i = 0; i < NUM_THREADS; i++) + { + void *retval; + pthread_join (threads[i], &retval); + } + + /* Unlock once we're done, just for cleanliness. */ + if (pthread_mutex_unlock (&mutex) != 0) + abort (); + + stop_marker (); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.exp new file mode 100644 index 00000000000..fe9aeea97f7 --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-other-thread-event.exp @@ -0,0 +1,175 @@ +# Copyright 2022-2023 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 for conditional breakpoints where the breakpoint condition includes +# an inferior function call. +# +# The tests in this script are testing what happens when an event arrives in +# another thread while GDB is waiting for the inferior function call (in the +# breakpoint condition) to finish. +# +# The expectation is that GDB will queue events for other threads and wait +# for the inferior function call to complete, if the condition is true, then +# the conditional breakpoint should be reported first. The other thread +# event should of course, not get lost, and should be reported as soon as +# the user tries to continue the inferior. +# +# If the conditional breakpoint ends up not being taken (the condition is +# false), then the other thread event should be reported immediately. +# +# This script tests what happens when the other thread event is (a) the +# other thread hitting a breakpoint, and (b) the other thread taking a +# signal (SIGSEGV in this case). + +standard_testfile + +if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ + {debug pthreads}] == -1 } { + return +} + +set cond_bp_line [gdb_get_line_number "First thread breakpoint"] +set other_bp_line [gdb_get_line_number "Other thread breakpoint"] +set final_bp_line [gdb_get_line_number "Final breakpoint here"] +set signal_line [gdb_get_line_number "Signal here"] + +# Start GDB based on TARGET_ASYNC and TARGET_NON_STOP, and then runto main. +proc start_gdb_and_runto_main { target_async target_non_stop } { + save_vars { ::GDBFLAGS } { + append ::GDBFLAGS \ + " -ex \"maint set target-non-stop $target_non_stop\"" + append ::GDBFLAGS \ + " -ex \"maintenance set target-async ${target_async}\"" + + clean_restart ${::binfile} + } + + if { ![runto_main] } { + fail "run to main" + return -1 + } + + return 0 +} + +# Run a test of GDB's conditional breakpoints, where the conditions include +# inferior function calls. While the inferior function call is executing +# another thread will hit a breakpoint (when OTHER_THREAD_SIGNAL is false), +# or receive a signal (when OTHER_THREAD_SIGNAL is true). GDB should report +# the conditional breakpoint first (if the condition is true), and then +# report the second thread event once the inferior is continued again. +# +# When STOP_AT_COND is true then the conditional breakpoint will have a +# condition that evaluates to true (and the GDB will stop at the +# breakpoint), otherwise, the condition will evaluate to false (and GDB will +# not stop at the breakpoint). +proc run_condition_test { stop_at_cond other_thread_signal \ + target_async target_non_stop } { + if { [start_gdb_and_runto_main $target_async \ + $target_non_stop] == -1 } { + return + } + + # Setup the conditional breakpoint. + if { $stop_at_cond } { + set cond_func "condition_true_func" + } else { + set cond_func "condition_false_func" + } + gdb_breakpoint \ + "${::srcfile}:${::cond_bp_line} if (${cond_func} ())" + set cond_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for conditional breakpoint"] + + if { $other_thread_signal } { + # Arrange for the other thread to raise a signal while GDB is + # evaluating the breakpoint condition. + gdb_test_no_output "set raise_signal = 1" + } else { + # And a breakpoint that will be hit by another thread only once the + # breakpoint condition starts to be evaluated. + gdb_breakpoint "${::srcfile}:${::other_bp_line}" + set other_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for other breakpoint"] + } + + # A final breakpoint once the test has completed. + gdb_breakpoint "${::srcfile}:${::final_bp_line}" + set final_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for final breakpoint"] + + if { $stop_at_cond } { + # Continue. The first breakpoint we hit should be the conditional + # breakpoint. The other thread will have hit its breakpoint, but + # that will have been deferred until the conditional breakpoint is + # reported. + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "" \ + "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${cond_bp_num}, worker_func \[^\r\n\]+:${::cond_bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+First thread breakpoint\[^\r\n\]+"] \ + "hit the conditional breakpoint" + } + + if { $other_thread_signal } { + # Now continue again, the other thread will now report that it + # received a signal. + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "Thread ${::decimal} \"\[^\"\r\n\]+\" received signal SIGSEGV, Segmentation fault\\." \ + "\\\[Switching to Thread \[^\r\n\]+\\\]" \ + "${::hex} in worker_func \[^\r\n\]+:${::signal_line}" \ + "${::decimal}\\s+\[^\r\n\]+Signal here\[^\r\n\]+"] \ + "received signal in other thread" + } else { + # Now continue again, the other thread will now report its + # breakpoint. + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "" \ + "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${other_bp_num}, worker_func \[^\r\n\]+:${::other_bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+Other thread breakpoint\[^\r\n\]+"] \ + "hit the breakpoint in other thread" + + # Run to the stop marker. + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "" \ + "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${final_bp_num}, stop_marker \[^\r\n\]+:${::final_bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+Final breakpoint here\[^\r\n\]+"] \ + "hit the final breakpoint" + } + + gdb_exit +} + +foreach_with_prefix target_async { "on" "off" } { + foreach_with_prefix target_non_stop { "on" "off" } { + foreach_with_prefix other_thread_signal { true false } { + foreach_with_prefix stop_at_cond { true false } { + run_condition_test $stop_at_cond $other_thread_signal \ + $target_async $target_non_stop + } + } + } +} diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.c b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.c new file mode 100644 index 00000000000..9d746d8be49 --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.c @@ -0,0 +1,89 @@ +/* Copyright 2022-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 + +#define NUM_THREADS 3 + +int +is_matching_tid (int *tid_ptr, int tid_value) +{ + return *tid_ptr == tid_value; +} + +int +return_true () +{ + return 1; +} + +int +return_false () +{ + return 0; +} + +int +function_that_segfaults () +{ + int *p = 0; + *p = 1; /* Segfault happens here. */ +} + +int +function_with_breakpoint () +{ + return 1; /* Nested breakpoint. */ +} + +void * +worker_func (void *arg) +{ + int a = 42; /* Breakpoint here. */ +} + +void +stop_marker () +{ + int b = 99; /* Stop marker. */ +} + +int +main () +{ + pthread_t threads[NUM_THREADS]; + int args[NUM_THREADS]; + + alarm (300); + + for (int i = 0; i < NUM_THREADS; i++) + { + args[i] = i; + pthread_create (&threads[i], NULL, worker_func, &args[i]); + } + + for (int i = 0; i < NUM_THREADS; i++) + { + void *retval; + pthread_join (threads[i], &retval); + } + + stop_marker (); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp new file mode 100644 index 00000000000..a101abbfe9b --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp @@ -0,0 +1,236 @@ +# Copyright 2022-2023 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 . + +# Some simple tests of inferior function calls from breakpoint +# conditions, in multi-threaded inferiors. +# +# This test sets up a multi-threaded inferior, and places a breakpoint +# at a location that many of the threads will reach. We repeat the +# test with different conditions, sometimes a single thread should +# stop at the breakpoint, sometimes multiple threads should stop, and +# sometime no threads should stop. + +standard_testfile + +if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ + {debug pthreads}] == -1 } { + return +} + +set cond_bp_line [gdb_get_line_number "Breakpoint here"] +set stop_bp_line [gdb_get_line_number "Stop marker"] +set nested_bp_line [gdb_get_line_number "Nested breakpoint"] +set segv_line [gdb_get_line_number "Segfault happens here"] + +# Start GDB based on TARGET_ASYNC and TARGET_NON_STOP, and then runto main. +proc start_gdb_and_runto_main { target_async target_non_stop } { + save_vars { ::GDBFLAGS } { + append ::GDBFLAGS \ + " -ex \"maint set target-non-stop $target_non_stop\"" + append ::GDBFLAGS \ + " -ex \"maintenance set target-async ${target_async}\"" + + clean_restart ${::binfile} + } + + if { ![runto_main] } { + fail "run to main" + return -1 + } + + return 0 +} + +# Run a test of GDB's conditional breakpoints, where the conditions include +# inferior function calls. +# +# CONDITION is the expression to be used as the breakpoint condition. +# +# N_EXPECTED_HITS is the number of threads that we expect to stop due to +# CONDITON. +# +# MESSAGE is used as a test name prefix. +proc run_condition_test { message n_expected_hits condition \ + target_async target_non_stop } { + with_test_prefix $message { + + if { [start_gdb_and_runto_main $target_async \ + $target_non_stop] == -1 } { + return + } + + # Use this convenience variable to track how often the + # breakpoint condition has been evaluated. This should be + # once per thread. + gdb_test "set \$n_cond_eval = 0" + + # Setup the conditional breakpoint. + gdb_breakpoint \ + "${::srcfile}:${::cond_bp_line} if ((++\$n_cond_eval) && (${condition}))" + + # And a breakpoint that we hit when the test is over, this one is + # not conditional. Only the main thread gets here once all the + # other threads have finished. + gdb_breakpoint "${::srcfile}:${::stop_bp_line}" + + # The number of times we stop at the conditional breakpoint. + set n_hit_condition 0 + + # Now keep 'continue'-ing GDB until all the threads have finished + # and we reach the stop_marker breakpoint. + gdb_test_multiple "continue" "spot all breakpoint hits" { + -re " worker_func \[^\r\n\]+${::srcfile}:${::cond_bp_line}\r\n${::decimal}\\s+\[^\r\n\]+Breakpoint here\[^\r\n\]+\r\n${::gdb_prompt} $" { + incr n_hit_condition + send_gdb "continue\n" + exp_continue + } + + -re " stop_marker \[^\r\n\]+${::srcfile}:${::stop_bp_line}\r\n${::decimal}\\s+\[^\r\n\]+Stop marker\[^\r\n\]+\r\n${::gdb_prompt} $" { + pass $gdb_test_name + } + } + + gdb_assert { $n_hit_condition == $n_expected_hits } \ + "stopped at breakpoint the expected number of times" + + # Ensure the breakpoint condition was evaluated once per thread. + gdb_test "print \$n_cond_eval" "= 3" \ + "condition was evaluated in each thread" + } +} + +# Check that after handling a conditional breakpoint (where the condition +# includes an inferior call), it is still possible to kill the running +# inferior, and then restart the inferior. +# +# At once point doing this would result in GDB giving an assertion error. +proc_with_prefix run_kill_and_restart_test { target_async target_non_stop } { + # This test relies on the 'start' command, which is not possible with + # the plain 'remote' target. + if { [target_info gdb_protocol] == "remote" } { + return + } + + if { [start_gdb_and_runto_main $target_async \ + $target_non_stop] == -1 } { + return + } + + # Setup the conditional breakpoint. + gdb_breakpoint \ + "${::srcfile}:${::cond_bp_line} if (is_matching_tid (arg, 1))" + gdb_continue_to_breakpoint "worker_func" + + # Now kill the program being debugged. + gdb_test "kill" "" "kill process" \ + "Kill the program being debugged.*y or n. $" "y" + + # Check we can restart the inferior. At one point this would trigger an + # assertion. + gdb_test "start" ".*" +} + +# Create a conditional breakpoint which includes a call to a function that +# segfaults. Run GDB and check what happens when the inferior segfaults +# during the inferior call. +proc_with_prefix run_bp_cond_segfaults { target_async target_non_stop } { + if { [start_gdb_and_runto_main $target_async \ + $target_non_stop] == -1 } { + return + } + + # This test relies on the inferior segfaulting when trying to + # access address zero. + if { [is_address_zero_readable] } { + return + } + + # Setup the conditional breakpoint, include a call to + # 'function_that_segfaults', which triggers the segfault. + gdb_breakpoint \ + "${::srcfile}:${::cond_bp_line} if (is_matching_tid (arg, 0) && function_that_segfaults ())" + set bp_1_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number of conditional breakpoint"] + + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "Thread ${::decimal} \"infcall-from-bp\" received signal SIGSEGV, Segmentation fault\\." \ + "${::hex} in function_that_segfaults \\(\\) at \[^\r\n\]+:${::segv_line}" \ + "${::decimal}\\s+\[^\r\n\]+Segfault happens here\[^\r\n\]+" \ + "Error in testing condition for breakpoint ${bp_1_num}:" \ + "The program being debugged was signaled while in a function called from GDB\\." \ + "GDB remains in the frame where the signal was received\\." \ + "To change this behavior use \"set unwindonsignal on\"\\." \ + "Evaluation of the expression containing the function" \ + "\\(function_that_segfaults\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] +} + +# Create a conditional breakpoint which includes a call to a function that +# itself has a breakpoint set within it. Run GDB and check what happens +# when GDB hits the nested breakpoint. +proc_with_prefix run_bp_cond_hits_breakpoint { target_async target_non_stop } { + if { [start_gdb_and_runto_main $target_async \ + $target_non_stop] == -1 } { + return + } + + # Setup the conditional breakpoint, include a call to + # 'function_with_breakpoint' in which we will shortly place a + # breakpoint. + gdb_breakpoint \ + "${::srcfile}:${::cond_bp_line} if (is_matching_tid (arg, 0) && function_with_breakpoint ())" + set bp_1_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number of conditional breakpoint"] + + gdb_breakpoint "${::srcfile}:${::nested_bp_line}" + set bp_2_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number of nested breakpoint"] + + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "Thread ${::decimal} \"infcall-from-bp\" hit Breakpoint ${bp_2_num}, function_with_breakpoint \\(\\) at \[^\r\n\]+:${::nested_bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+Nested breakpoint\[^\r\n\]+" \ + "Error in testing condition for breakpoint ${bp_1_num}:" \ + "The program being debugged stopped while in a function called from GDB\\." \ + "Evaluation of the expression containing the function" \ + "\\(function_with_breakpoint\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] +} + +foreach_with_prefix target_async { "on" "off" } { + foreach_with_prefix target_non_stop { "on" "off" } { + run_condition_test "exactly one thread is hit" \ + 1 "is_matching_tid (arg, 1)" \ + $target_async $target_non_stop + run_condition_test "exactly two threads are hit" \ + 2 "(is_matching_tid (arg, 0) || is_matching_tid (arg, 2))" \ + $target_async $target_non_stop + run_condition_test "all three threads are hit" \ + 3 "return_true ()" \ + $target_async $target_non_stop + run_condition_test "no thread is hit" \ + 0 "return_false ()" \ + $target_async $target_non_stop + + run_kill_and_restart_test $target_async $target_non_stop + run_bp_cond_segfaults $target_async $target_non_stop + run_bp_cond_hits_breakpoint $target_async $target_non_stop + } +} diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.c b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.c new file mode 100644 index 00000000000..835c72f03cf --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.c @@ -0,0 +1,139 @@ +/* Copyright 2022-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 +#include +#include + +#define NUM_THREADS 5 + +/* Semaphores, used to track when threads have started, and to control + when the threads finish. */ +sem_t startup_semaphore; +sem_t finish_semaphore; + +/* Mutex to control when the first worker thread hit a breakpoint + location. */ +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +/* Global variable to poke, just so threads have something to do. */ +volatile int global_var = 0; + +int +return_true () +{ + return 1; +} + +int +return_false () +{ + return 0; +} + +void * +worker_func (void *arg) +{ + int tid = *((int *) arg); + + switch (tid) + { + case 0: + /* Wait for MUTEX to become available, then pass through the + conditional breakpoint location. */ + if (pthread_mutex_lock (&mutex) != 0) + abort (); + global_var = 99; /* Conditional breakpoint here. */ + if (pthread_mutex_unlock (&mutex) != 0) + abort (); + break; + + default: + /* Notify the main thread that the thread has started, then wait for + the main thread to tell us to finish. */ + sem_post (&startup_semaphore); + if (sem_wait (&finish_semaphore) != 0) + abort (); + break; + } +} + +void +stop_marker () +{ + global_var = 99; /* Stop marker. */ +} + +int +main () +{ + pthread_t threads[NUM_THREADS]; + int args[NUM_THREADS]; + void *retval; + + /* An alarm, just in case the thread deadlocks. */ + alarm (300); + + /* Semaphore initialization. */ + if (sem_init (&startup_semaphore, 0, 0) != 0) + abort (); + if (sem_init (&finish_semaphore, 0, 0) != 0) + abort (); + + /* Lock MUTEX, this prevents the first worker thread from rushing ahead. */ + if (pthread_mutex_lock (&mutex) != 0) + abort (); + + /* Worker thread creation. */ + for (int i = 0; i < NUM_THREADS; i++) + { + args[i] = i; + pthread_create (&threads[i], NULL, worker_func, &args[i]); + } + + /* Wait for every thread (other than the first) to tell us it has started + up. */ + for (int i = 1; i < NUM_THREADS; i++) + { + if (sem_wait (&startup_semaphore) != 0) + abort (); + } + + /* Unlock the first thread so it can proceed. */ + if (pthread_mutex_unlock (&mutex) != 0) + abort (); + + /* Wait for the first thread only. */ + pthread_join (threads[0], &retval); + + /* Now post FINISH_SEMAPHORE to allow all the other threads to finish. */ + for (int i = 1; i < NUM_THREADS; i++) + sem_post (&finish_semaphore); + + /* Now wait for the remaining threads to complete. */ + for (int i = 1; i < NUM_THREADS; i++) + pthread_join (threads[i], &retval); + + /* Semaphore cleanup. */ + sem_destroy (&finish_semaphore); + sem_destroy (&startup_semaphore); + + stop_marker (); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.exp new file mode 100644 index 00000000000..9690f0ac3a3 --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-single.exp @@ -0,0 +1,118 @@ +# Copyright 2022-2023 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 . + +# This test reprocuces bug gdb/28942, performing an inferior function +# call from a breakpoint condition in a multi-threaded inferior. +# +# The important part of this test is that, when the conditional +# breakpoint is hit, and the condition (which includes an inferior +# function call) is evaluated, the other threads are running. + +standard_testfile + +if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ + {debug pthreads}] == -1 } { + return +} + +set cond_bp_line [gdb_get_line_number "Conditional breakpoint here"] +set final_bp_line [gdb_get_line_number "Stop marker"] + +# Start GDB based on TARGET_ASYNC and TARGET_NON_STOP, and then runto main. +proc start_gdb_and_runto_main { target_async target_non_stop } { + save_vars { ::GDBFLAGS } { + append ::GDBFLAGS \ + " -ex \"maint set target-non-stop $target_non_stop\"" + append ::GDBFLAGS \ + " -ex \"maintenance set target-async ${target_async}\"" + + clean_restart ${::binfile} + } + + if { ![runto_main] } { + fail "run to main" + return -1 + } + + return 0 +} + +# Run a test of GDB's conditional breakpoints, where the conditions include +# inferior function calls. +# +# TARGET_ASYNC and TARGET_NON_STOP are used when starting up GDB. +# +# When STOP_AT_COND is true the breakpoint condtion will evaluate to +# true, and GDB will stop at the breakpoint. Otherwise, the +# breakpoint condition will evaluate to false and GDB will not stop at +# the breakpoint. +proc run_condition_test { stop_at_cond \ + target_async target_non_stop } { + if { [start_gdb_and_runto_main $target_async \ + $target_non_stop] == -1 } { + return + } + + # Setup the conditional breakpoint. + if { $stop_at_cond } { + set cond_func "return_true" + } else { + set cond_func "return_false" + } + gdb_breakpoint \ + "${::srcfile}:${::cond_bp_line} if (${cond_func} ())" + set cond_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for conditional breakpoint"] + + # And a breakpoint that we hit when the test is over, this one is + # not conditional. + gdb_breakpoint "${::srcfile}:${::final_bp_line}" + set final_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for final breakpoint"] + + if { $stop_at_cond } { + # Continue. The first breakpoint we hit should be the conditional + # breakpoint. The other thread will have hit its breakpoint, but + # that will have been deferred until the conditional breakpoint is + # reported. + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "" \ + "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${cond_bp_num}, worker_func \[^\r\n\]+:${::cond_bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+Conditional breakpoint here\[^\r\n\]+"] \ + "hit the conditional breakpoint" + } + + # Run to the stop marker. + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "" \ + "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${final_bp_num}, stop_marker \[^\r\n\]+:${::final_bp_line}" \ + "${::decimal}\\s+\[^\r\n\]+Stop marker\[^\r\n\]+"] \ + "hit the final breakpoint" +} + +foreach_with_prefix target_async { "on" "off" } { + foreach_with_prefix target_non_stop { "on" "off" } { + foreach_with_prefix stop_at_cond { true false } { + run_condition_test $stop_at_cond \ + $target_async $target_non_stop + } + } +} From patchwork Tue Jan 31 17:27:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64035 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 9A172385B502 for ; Tue, 31 Jan 2023 17:51:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A172385B502 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187489; bh=re0jlQfrvzNkhW9gyA5a+knriaxkrwYsdg+E0L2ER0g=; 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=mW6jBeXxhW9t0C5m0tM+Wi/k1pomdxdIYbRy3C8d/neACr9NViytAonXiXHgz6Bme oNEgr9bJbAW9g8dvdD0E0X9q8Mssd1mSgO02QEsdxVlJ55bNcr7HYv5Mz0VemWrBSK MHJ+Isj1SfXk8z1Q6AbnrFQyWPl6pGufTd4nAGOo= 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 E1B6D3858C52 for ; Tue, 31 Jan 2023 17:49:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1B6D3858C52 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-635-Yga2lWiSNb2EQZJd-9CdmQ-1; Tue, 31 Jan 2023 12:27:43 -0500 X-MC-Unique: Yga2lWiSNb2EQZJd-9CdmQ-1 Received: by mail-qv1-f69.google.com with SMTP id p15-20020a0cf54f000000b0054fc21ff275so119622qvm.4 for ; Tue, 31 Jan 2023 09:27:43 -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=re0jlQfrvzNkhW9gyA5a+knriaxkrwYsdg+E0L2ER0g=; b=Ow8+oEsGgVvWmVi+GoS3Ls/ie8Hiwh/mVMP5Dx88zwtEyB2A7+rl4dqH28o5P6AXmW gaa+rwFZr0cFfdxMksJ91j/rMjeAegxdrUi/gJhZXJ+ZAIKNYlZ/6bRhzn3BEb3n6F/E mZ7d7hfFdxn68/BRBVYJy9aRuUcoZWHYhC15Xx2GMhsqBOUTLxbqAM/eabWd/M7Fh680 KA/S3mWxUC2G8F0K0+aRjcCk0YNYaWqeKd1z/0uVPzRfTeocPAjfIPFbnbHrDT+rXWLj /+qCyKTTQMZfoI/yddf1WnTNKCot4oQiJpVqm7NOq/e8Vi2ASM2St6X7oqlGrp/5gdPU qD1A== X-Gm-Message-State: AFqh2kpSbENsJnigjDB8FfGKae00CjMHxOR32YF40m886Yr7I4uZjSUw w49zD8QJXWsBgzXfTeiaQn9KB+K0p9jvbK78jzlWhmUrdtFN+6Hqxp8LDyhIiLHLR9DDZc0gbQJ dlzL55oQuRClBkVbGdD5AdzSiVQfonhsQY+ZJ7LNEvWm7pcHO8vPRxqZe/demN6BZKDafLeT5YQ == X-Received: by 2002:a05:622a:5da4:b0:3b5:bd73:12bc with SMTP id fu36-20020a05622a5da400b003b5bd7312bcmr68312096qtb.42.1675186062130; Tue, 31 Jan 2023 09:27:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXufQNFcM0ltUzyFXjZfCGh5SSehrn3y4NSzWVE5bibpstWY3SLjn4R4itvpuOfXum/tixRVeA== X-Received: by 2002:a05:622a:5da4:b0:3b5:bd73:12bc with SMTP id fu36-20020a05622a5da400b003b5bd7312bcmr68311989qtb.42.1675186060967; Tue, 31 Jan 2023 09:27:40 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id q20-20020ac84514000000b003b9a50c8fa1sm2079498qtn.87.2023.01.31.09.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:40 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 10/13] gdb: add timeouts for inferior function calls Date: Tue, 31 Jan 2023 17:27:15 +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.8 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" In the previous commits I have been working on improving inferior function call support. One thing that worries me about using inferior function calls from a conditional breakpoint is: what happens if the inferior function call fails? If the failure is obvious, e.g. the thread performing the call crashes, or hits a breakpoint, then this case is already well handled, and the error is reported to the user. But what if the thread performing the inferior call just deadlocks? If the user made the call from a 'print' or 'call' command, then the user might have some expectation of when the function call should complete, and, when this time limit is exceeded, the user will (hopefully) interrupt GDB and regain control of the debug session. But, when the inferior function call is from a breakpoint condition it is much harder to understand that GDB is deadlocked within an inferior call. Maybe the breakpoint hasn't been hit yet? Or maybe the condition was always false? Or maybe GDB is deadlocked in an inferior call? The only way to know for sure is to periodically interrupt GDB, check on all the threads, and then continue. Additionally, the focus of the previous commit was inferior function calls, from a conditional breakpoint, in a multi-threaded inferior. This opens up a whole new set of potential failure conditions. For example, what if the function called relies on interaction with some other thread, and the other thread crashes? Or hits a breakpoint? Given how inferior function calls work (in a synchronous manor), a stop event in some other thread is going to be ignored while the inferior function call is being executed as part of a breakpoint condition, and this means that GDB could get stuck waiting for the original condition thread, which will now never complete. In this commit I propose a solution to this problem. A timeout. For targets that support async-mode we can install an event-loop timer before starting the inferior function call. When the timer expires we will stop the thread performing the inferior function call. With this mechanism in place a user can be sure that any inferior call they make will either complete, or timeout eventually. Adding a timer like this is obviously a change in behaviour for the more common 'call' and 'print' uses of inferior function calls, so, in this patch, I propose having two different timers. One I call the 'direct-call-timeout', which is used for 'call' and 'print' commands. This timeout is by default set to unlimited, which, not surprisingly, means there is no timeout in place. A second timer, which I've called 'indirect-call-timeout', is used for inferior function calls from breakpoint conditions. This timeout has a default value of 30 seconds. This is a reasonably long time to wait, and hopefully should be enough in most cases to allow the inferior call to complete. An inferior call that takes more than 30 seconds, which is installed on a breakpoint condition is really going to slow down the debug session, so hopefully this is not a common use case. The user is, of course, free to reduce, or increase the timeout value, and can always use Ctrl-c to interrupt an inferior function call, but this timeout will ensure that GDB will stop at some point. The new commands added by this commit are: set direct-call-timeout SECONDS show direct-call-timeout set indirect-call-timeout SECONDS show indirect-call-timeout These new timeouts do depend on async-mode, so, if async-mode is disabled (maint set target-async off), or not supported (e.g. target sim), then the timeout is treated as unlimited (that is, no timeout is set). For targets that "fake" non-async mode, e.g. Linux native, where non-async mode is really just async mode, but then we park the target in a sissuspend, we could easily fix things so that the timeouts still work, however, for targets that really are not async aware, like the simulator, fixing things so that timeouts work correctly would be a much bigger task - that effort would be better spent just making the target async-aware. And so, I'm happy for now that this feature will only work on async targets. The two new show commands will display slightly different text if the current target is a non-async target, which should allow users to understand what's going on. There's a somewhat random test adjustment needed in gdb.base/help.exp, the test uses a regexp with the apropos command, and expects to find a single result. Turns out the new settings I added also matched the regexp, which broke the test. I've updated the regexp a little to exclude my new settings. In infcall.c you'll notice the thread_info::stop_requested flag being set when a timeout occurs. This flag setting is not required as part of this commit, but will be needed in a later commit. However, it seemed like setting this flag fitted better with this commit, which is why the change is added here. --- gdb/NEWS | 18 ++ gdb/doc/gdb.texinfo | 66 ++++++ gdb/infcall.c | 221 +++++++++++++++++- gdb/testsuite/gdb.base/help.exp | 2 +- gdb/testsuite/gdb.base/infcall-timeout.c | 36 +++ gdb/testsuite/gdb.base/infcall-timeout.exp | 82 +++++++ .../infcall-from-bp-cond-timeout.c | 169 ++++++++++++++ .../infcall-from-bp-cond-timeout.exp | 156 +++++++++++++ 8 files changed, 745 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/gdb.base/infcall-timeout.c create mode 100644 gdb/testsuite/gdb.base/infcall-timeout.exp create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.c create mode 100644 gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp diff --git a/gdb/NEWS b/gdb/NEWS index 445d28efed9..835bf7f8680 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -38,6 +38,24 @@ maintenance print record-instruction [ N ] prints how GDB would undo the N-th previous instruction, and if N is positive, it prints how GDB will redo the N-th following instruction. +set direct-call-timeout SECONDS +show direct-call-timeout +set indirect-call-timeout SECONDS +show indirect-call-timeout + These new settings can be used to limit how long GDB will wait for + an inferior function call to complete. The direct timeout is used + for inferior function calls from e.g. 'call' and 'print' commands, + while the indirect timeout is used for inferior function calls from + within a conditional breakpoint expression. + + The default for the direct timeout is unlimited, while the default + for the indirect timeout is 30 seconds. + + These timeouts will only have an effect for targets that are + operating in async mode. For non-async targets the timeouts are + ignored, GDB will wait indefinitely for an inferior function to + complete, unless interrupted by the user using Ctrl-C. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index dd8267f448f..f5d460eb9e5 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20808,6 +20808,72 @@ @code{step}, etc). In this case, when the inferior finally returns to the dummy-frame, @value{GDBN} will once again halt the inferior. +On targets that support asynchronous execution (@pxref{Background +Execution}) @value{GDBN} can place a timeout on any functions called +from @value{GDBN}. If the timeout expires and the function call is +still ongoing, then @value{GDBN} will interrupt the program. + +For targets that don't support asynchronous execution +(@pxref{Background Execution}) then timeouts for functions called from +@value{GDBN} are not supported, the timeout settings described below +will be treated as @code{unlimited}, meaning @value{GDBN} will wait +indefinitely for function call to complete, unless interrupted by the +user using @kbd{Ctrl-C}. + +@table @code +@item set direct-call-timeout @var{seconds} +@kindex set direct-call-timeout +@cindex timeout for called functions +Set the timeout used when calling functions in the program to +@var{seconds}, which should be an integer greater than zero, or the +special value @code{unlimited}, which indicates no timeout should be +used. The default for this setting is @code{unlimited}. + +This setting is used when the user calls a function directly from the +command prompt, for example with a @code{call} or @code{print} +command. + +This setting only works for targets that support asynchronous +execution (@pxref{Background Execution}), for any other target the +setting is treated as @code{unlimited}. + +@item show direct-call-timeout +@kindex show direct-call-timeout +@cindex timeout for called functions +Show the timeout used when calling functions in the program with a +@code{call} or @code{print} command. +@end table + +It is also possible to call functions within the program from the +condition of a conditional breakpoint (@pxref{Conditions, ,Break +Conditions}). A different setting controls the timeout used for +function calls made from a breakpoint condition. + +@table @code +@item set indirect-call-timeout @var{seconds} +@kindex set indirect-call-timeout +@cindex timeout for called functions +Set the timeout used when calling functions in the program from a +breakpoint or watchpoint condition to @var{seconds}, which should be +an integer greater than zero, or the special value @code{unlimited}, +which indicates no timeout should be used. The default for this +setting is @code{30} seconds. + +This setting only works for targets that support asynchronous +execution (@pxref{Background Execution}), for any other target the +setting is treated as @code{unlimited}. + +If a function called from a breakpoint or watchpoint condition times +out, then @value{GDBN} will stop at the point where the timeout +occurred. The breakpoint condition evaluation will be abandoned. + +@item show indirect-call-timeout +@kindex show indirect-call-timeout +@cindex timeout for called functions +Show the timeout used when calling functions in the program from a +breakpoint or watchpoint condition. +@end table + @subsection Calling functions with no debug info @cindex no debug info functions diff --git a/gdb/infcall.c b/gdb/infcall.c index 34838dea1bd..92f49a64e3e 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -95,6 +95,53 @@ show_may_call_functions_p (struct ui_file *file, int from_tty, value); } +/* A timeout (in seconds) for direct inferior calls. A direct inferior + call is one the user triggers from the prompt, e.g. with a 'call' or + 'print' command. Compare with the definition of indirect calls below. */ + +static unsigned int direct_call_timeout = UINT_MAX; + +/* Implement 'show direct-call-timeout'. */ + +static void +show_direct_call_timeout (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + if (target_has_execution () && !target_can_async_p ()) + gdb_printf (file, _("Current target does not support async mode, timeout " + "for direct inferior calls is \"unlimited\".\n")); + else if (direct_call_timeout == UINT_MAX) + gdb_printf (file, _("Timeout for direct inferior function calls " + "is \"unlimited\".\n")); + else + gdb_printf (file, _("Timeout for direct inferior function calls " + "is \"%s seconds\".\n"), value); +} + +/* A timeout (in seconds) for indirect inferior calls. An indirect inferior + call is one that originates from within GDB, for example, when + evaluating an expression for a conditional breakpoint. Compare with + the definition of direct calls above. */ + +static unsigned int indirect_call_timeout = 30; + +/* Implement 'show indirect-call-timeout'. */ + +static void +show_indirect_call_timeout (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + if (target_has_execution () && !target_can_async_p ()) + gdb_printf (file, _("Current target does not support async mode, timeout " + "for indirect inferior calls is \"unlimited\".\n")); + else if (indirect_call_timeout == UINT_MAX) + gdb_printf (file, _("Timeout for indirect inferior function calls " + "is \"unlimited\".\n")); + else + gdb_printf (file, _("Timeout for indirect inferior function calls " + "is \"%s seconds\".\n"), value); +} + /* How you should pass arguments to a function depends on whether it was defined in K&R style or prototype style. If you define a function using the K&R syntax that takes a `float' argument, then @@ -589,6 +636,86 @@ call_thread_fsm::should_notify_stop () return true; } +/* A class to control creation of a timer that will interrupt a thread + during an inferior call. */ +struct infcall_timer_controller +{ + /* Setup an event-loop timer that will interrupt PTID if the inferior + call takes too long. DIRECT_CALL_P is true when this inferior call is + a result of the user using a 'print' or 'call' command, and false when + this inferior call is a result of e.g. a conditional breakpoint + expression, this is used to select which timeout to use. */ + infcall_timer_controller (thread_info *thr, bool direct_call_p) + : m_thread (thr) + { + unsigned int timeout + = direct_call_p ? direct_call_timeout : indirect_call_timeout; + if (timeout < UINT_MAX && target_can_async_p ()) + { + int ms = timeout * 1000; + int id = create_timer (ms, infcall_timer_controller::timed_out, this); + m_timer_id.emplace (id); + infcall_debug_printf ("Setting up infcall timeout timer for " + "ptid %s: %d milliseconds", + m_thread->ptid.to_string ().c_str (), ms); + } + } + + /* Destructor. Ensure that the timer is removed from the event loop. */ + ~infcall_timer_controller () + { + /* If the timer has already triggered, then it will have already been + deleted from the event loop. If the timer has not triggered, then + delete it now. */ + if (m_timer_id.has_value () && !m_triggered) + delete_timer (*m_timer_id); + + /* Just for clarity, discard the timer id now. */ + m_timer_id.reset (); + } + + /* Return true if there was a timer in place, and the timer triggered, + otherwise, return false. */ + bool triggered_p () + { + gdb_assert (!m_triggered || m_timer_id.has_value ()); + return m_triggered; + } + +private: + /* The thread we should interrupt. */ + thread_info *m_thread; + + /* Set true when the timer is triggered. */ + bool m_triggered = false; + + /* Given a value when a timer is in place. */ + gdb::optional m_timer_id; + + /* Callback for the timer, forwards to ::trigger below. */ + static void + timed_out (gdb_client_data context) + { + infcall_timer_controller *ctrl + = static_cast (context); + ctrl->trigger (); + } + + /* Called when the timer goes off. Stop thread m_thread. */ + void + trigger () + { + m_triggered = true; + + scoped_disable_commit_resumed disable_commit_resumed ("infcall timeout"); + + infcall_debug_printf ("Stopping thread %s", + m_thread->ptid.to_string ().c_str ()); + target_stop (m_thread->ptid); + m_thread->stop_requested = true; + } +}; + /* Subroutine of call_function_by_hand to simplify it. Start up the inferior and wait for it to stop. Return the exception if there's an error, or an exception with @@ -599,13 +726,15 @@ call_thread_fsm::should_notify_stop () static struct gdb_exception run_inferior_call (std::unique_ptr sm, - struct thread_info *call_thread, CORE_ADDR real_pc) + struct thread_info *call_thread, CORE_ADDR real_pc, + bool *timed_out_p) { INFCALL_SCOPED_DEBUG_ENTER_EXIT; struct gdb_exception caught_error; ptid_t call_thread_ptid = call_thread->ptid; int was_running = call_thread->state == THREAD_RUNNING; + *timed_out_p = false; infcall_debug_printf ("call function at %s in thread %s, was_running = %d", core_addr_to_string (real_pc), @@ -617,6 +746,16 @@ run_inferior_call (std::unique_ptr sm, scoped_restore restore_in_infcall = make_scoped_restore (&call_thread->control.in_infcall, 1); + /* If the thread making the inferior call stops with a time out then the + stop_requested flag will be set. However, we don't want changes to + this flag to leak back to our caller, we might be here to handle an + inferior call from a breakpoint condition, so leaving this flag set + would appear that the breakpoint stop was actually a requested stop, + which is not true, and will cause GDB to print extra messages to the + output. */ + scoped_restore restore_stop_requested + = make_scoped_restore (&call_thread->stop_requested, false); + clear_proceed_status (0); /* Associate the FSM with the thread after clear_proceed_status @@ -650,11 +789,23 @@ run_inferior_call (std::unique_ptr sm, infrun_debug_show_threads ("non-exited threads after proceed for inferior-call", all_non_exited_threads ()); + /* Setup a timer (if possible, and if the settings allow) to prevent + the inferior call running forever. */ + bool direct_call_p = !call_thread->control.in_cond_eval; + infcall_timer_controller infcall_timer (call_thread, direct_call_p); + /* Inferior function calls are always synchronous, even if the target supports asynchronous execution. */ wait_sync_command_done (); - infcall_debug_printf ("inferior call completed successfully"); + /* If the timer triggered then the inferior call failed. */ + if (infcall_timer.triggered_p ()) + { + infcall_debug_printf ("inferior call timed out"); + *timed_out_p = true; + } + else + infcall_debug_printf ("inferior call completed successfully"); } catch (gdb_exception &e) { @@ -1308,6 +1459,10 @@ call_function_by_hand_dummy (struct value *function, scoped_restore restore_stopped_by_random_signal = make_scoped_restore (&stopped_by_random_signal, 0); + /* Set to true by the call to run_inferior_call below if the inferior + call is artificially interrupted by GDB due to taking too long. */ + bool timed_out_p = false; + /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - If you're looking to implement asynchronous dummy-frames, then just below is the place to chop this function in two.. */ @@ -1334,7 +1489,8 @@ call_function_by_hand_dummy (struct value *function, struct_addr); { std::unique_ptr sm_up (sm); - e = run_inferior_call (std::move (sm_up), call_thread.get (), real_pc); + e = run_inferior_call (std::move (sm_up), call_thread.get (), real_pc, + &timed_out_p); } if (e.reason < 0) @@ -1486,7 +1642,10 @@ When the function is done executing, GDB will silently stop."), std::string name = get_function_name (funaddr, name_buf, sizeof (name_buf)); - if (stopped_by_random_signal) + /* If the inferior call timed out then it will have been interrupted + by a signal, but we want to report this differently to the user, + which is done later in this function. */ + if (stopped_by_random_signal && !timed_out_p) { /* We stopped inside the FUNCTION because of a random signal. Further execution of the FUNCTION is not @@ -1530,6 +1689,36 @@ GDB remains in the frame where the signal was received.\n\ To change this behavior use \"set unwindonsignal on\".\n\ Evaluation of the expression containing the function\n\ (%s) will be abandoned.\n\ +When the function is done executing, GDB will silently stop."), + name.c_str ()); + } + } + + if (timed_out_p) + { + /* A timeout results in a signal being sent to the inferior. */ + gdb_assert (stopped_by_random_signal); + + /* Indentation is weird here. A later patch is going to move the + following block into an if/else, so I'm leaving the indentation + here to minimise the later patch. + + Also, the error message used below refers to 'set + unwind-on-timeout' which doesn't exist yet. This will be added + in a later commit, I'm leaving this in for now to minimise the + churn caused by the commit that adds unwind-on-timeout. */ + { + /* The user wants to stay in the frame where we stopped + (default). Discard inferior status, we're not at the same + point we started at. */ + discard_infcall_control_state (inf_status.release ()); + + error (_("\ +The program being debugged timed out while in a function called from GDB.\n\ +GDB remains in the frame where the timeout occurred.\n\ +To change this behavior use \"set unwind-on-timeout on\".\n\ +Evaluation of the expression containing the function\n\ +(%s) will be abandoned.\n\ When the function is done executing, GDB will silently stop."), name.c_str ()); } @@ -1643,6 +1832,30 @@ The default is to unwind the frame."), show_unwind_on_terminating_exception_p, &setlist, &showlist); + add_setshow_uinteger_cmd ("direct-call-timeout", no_class, + &direct_call_timeout, _("\ +Set the timeout, for direct calls to inferior function calls."), _("\ +Show the timeout, for direct calls to inferior function calls."), _("\ +If running on a target that supports, and is running in, async mode\n\ +then this timeout is used for any inferior function calls triggered\n\ +directly from the prompt, i.e. from a 'call' or 'print' command. The\n\ +timeout is specified in seconds."), + nullptr, + show_direct_call_timeout, + &setlist, &showlist); + + add_setshow_uinteger_cmd ("indirect-call-timeout", no_class, + &indirect_call_timeout, _("\ +Set the timeout, for indirect calls to inferior function calls."), _("\ +Show the timeout, for indirect calls to inferior function calls."), _("\ +If running on a target that supports, and is running in, async mode\n\ +then this timeout is used for any inferior function calls triggered\n\ +indirectly, i.e. being made as part of a breakpoint, or watchpoint,\n\ +condition expression. The timeout is specified in seconds."), + nullptr, + show_indirect_call_timeout, + &setlist, &showlist); + add_setshow_boolean_cmd ("infcall", class_maintenance, &debug_infcall, _("Set inferior call debugging."), diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp index 87919a819ab..504bf90cc15 100644 --- a/gdb/testsuite/gdb.base/help.exp +++ b/gdb/testsuite/gdb.base/help.exp @@ -121,7 +121,7 @@ gdb_test "help info bogus-gdb-command" "Undefined info command: \"bogus-gdb-comm gdb_test "help gotcha" "Undefined command: \"gotcha\"\. Try \"help\"\." # Test apropos regex. -gdb_test "apropos \\\(print\[\^\[ bsiedf\\\".-\]\\\)" "handle -- Specify how to handle signals\." +gdb_test "apropos \\\(print\[\^\[ bsiedf\\\"'.-\]\\\)" "handle -- Specify how to handle signals\." # Test apropos >1 word string. gdb_test "apropos handle signal" "handle -- Specify how to handle signals\." # Test apropos apropos. diff --git a/gdb/testsuite/gdb.base/infcall-timeout.c b/gdb/testsuite/gdb.base/infcall-timeout.c new file mode 100644 index 00000000000..895e8a36d59 --- /dev/null +++ b/gdb/testsuite/gdb.base/infcall-timeout.c @@ -0,0 +1,36 @@ +/* Copyright 2022 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 + +/* This function is called from GDB. */ +int +function_that_never_returns () +{ + while (1) + sleep (1); + + return 0; +} + +int +main () +{ + alarm (300); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/infcall-timeout.exp b/gdb/testsuite/gdb.base/infcall-timeout.exp new file mode 100644 index 00000000000..a5b0111ed04 --- /dev/null +++ b/gdb/testsuite/gdb.base/infcall-timeout.exp @@ -0,0 +1,82 @@ +# 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 GDB's direct-call-timeout setting, that is, ensure that if an +# inferior function call, invoked from e.g. a 'print' command, takes +# too long, then GDB can interrupt it, and return control to the user. + +standard_testfile + +if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ + {debug}] == -1 } { + return +} + +# Start GDB according to TARGET_ASYNC and TARGET_NON_STOP, then adjust +# the direct-call-timeout, and make an inferior function call that +# will never return. GDB should eventually timeout and stop the +# inferior. +proc_with_prefix run_test { target_async target_non_stop } { + save_vars { ::GDBFLAGS } { + append ::GDBFLAGS \ + " -ex \"maint set target-non-stop $target_non_stop\"" + append ::GDBFLAGS \ + " -ex \"maintenance set target-async ${target_async}\"" + + clean_restart ${::binfile} + } + + if {![runto_main]} { + fail "run to main" + return + } + + gdb_test_no_output "set direct-call-timeout 5" + + # When non-stop mode is off we get slightly different output from GDB. + if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } { + set stopped_line_pattern "Program received signal SIGINT, Interrupt\\." + } else { + set stopped_line_pattern "Program stopped\\." + } + + gdb_test "print function_that_never_returns ()" \ + [multi_line \ + $stopped_line_pattern \ + ".*" \ + "The program being debugged timed out while in a function called from GDB\\." \ + "GDB remains in the frame where the timeout occurred\\." \ + "To change this behavior use \"set unwind-on-timeout on\"\\." \ + "Evaluation of the expression containing the function" \ + "\\(function_that_never_returns\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] + + gdb_test "bt" ".* function_that_never_returns .*.*" +} + +foreach_with_prefix target_async { "on" "off" } { + + if { $target_async == "off" } { + # GDB can't timeout while waiting for a thread if the target + # runs with async-mode turned off; once the target is running + # GDB is effectively blocked until the target stops for some + # reason. + continue + } + + foreach_with_prefix target_non_stop { "on" "off" } { + run_test $target_async $target_non_stop + } +} diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.c b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.c new file mode 100644 index 00000000000..3bd91d7377d --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.c @@ -0,0 +1,169 @@ +/* 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 +#include +#include +#include +#include + +#define NUM_THREADS 5 + +/* Semaphores, used to track when threads have started, and to control + when the threads finish. */ +sem_t startup_semaphore; +sem_t finish_semaphore; +sem_t thread_1_semaphore; +sem_t thread_2_semaphore; + +/* Mutex to control when the first worker thread hit a breakpoint + location. */ +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +/* Global variable to poke, just so threads have something to do. */ +volatile int global_var = 0; + +int +condition_func () +{ + /* Let thread 2 run. */ + if (sem_post (&thread_2_semaphore) != 0) + abort (); + + /* Wait for thread 2 to complete its actions. */ + if (sem_wait (&thread_1_semaphore) != 0) + abort (); + + return 1; +} + +void +do_segfault () +{ + volatile int *p = 0; + *p = 0; /* Segfault here. */ +} + +void * +worker_func (void *arg) +{ + int tid = *((int *) arg); + + /* Let the main thread know that this worker has started. */ + if (sem_post (&startup_semaphore) != 0) + abort (); + + switch (tid) + { + case 0: + /* Wait for MUTEX to become available, then pass through the + conditional breakpoint location. */ + if (pthread_mutex_lock (&mutex) != 0) + abort (); + global_var = 99; /* Conditional breakpoint here. */ + if (pthread_mutex_unlock (&mutex) != 0) + abort (); + break; + + case 1: + if (sem_wait (&thread_2_semaphore) != 0) + abort (); + do_segfault (); + if (sem_post (&thread_1_semaphore) != 0) + abort (); + + /* Fall through. */ + default: + /* Wait until we are allowed to finish. */ + if (sem_wait (&finish_semaphore) != 0) + abort (); + break; + } +} + +void +stop_marker () +{ + global_var = 99; /* Stop marker. */ +} + +/* The main program entry point. */ + +int +main () +{ + pthread_t threads[NUM_THREADS]; + int args[NUM_THREADS]; + void *retval; + + /* An alarm, just in case the thread deadlocks. */ + alarm (300); + + /* Semaphore initialization. */ + if (sem_init (&startup_semaphore, 0, 0) != 0) + abort (); + if (sem_init (&finish_semaphore, 0, 0) != 0) + abort (); + if (sem_init (&thread_1_semaphore, 0, 0) != 0) + abort (); + if (sem_init (&thread_2_semaphore, 0, 0) != 0) + abort (); + + /* Lock MUTEX, this prevents the first worker thread from rushing ahead. */ + if (pthread_mutex_lock (&mutex) != 0) + abort (); + + /* Worker thread creation. */ + for (int i = 0; i < NUM_THREADS; i++) + { + args[i] = i; + pthread_create (&threads[i], NULL, worker_func, &args[i]); + } + + /* Wait for every thread to start. */ + for (int i = 0; i < NUM_THREADS; i++) + { + if (sem_wait (&startup_semaphore) != 0) + abort (); + } + + /* Unlock the first thread so it can proceed. */ + if (pthread_mutex_unlock (&mutex) != 0) + abort (); + + /* Wait for the first thread only. */ + pthread_join (threads[0], &retval); + + /* Now post FINISH_SEMAPHORE to allow all the other threads to finish. */ + for (int i = 1; i < NUM_THREADS; i++) + sem_post (&finish_semaphore); + + /* Now wait for the remaining threads to complete. */ + for (int i = 1; i < NUM_THREADS; i++) + pthread_join (threads[i], &retval); + + /* Semaphore cleanup. */ + sem_destroy (&finish_semaphore); + sem_destroy (&startup_semaphore); + sem_destroy (&thread_1_semaphore); + sem_destroy (&thread_2_semaphore); + + stop_marker (); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp new file mode 100644 index 00000000000..3341ff33f19 --- /dev/null +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp @@ -0,0 +1,156 @@ +# Copyright 2020 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 . + +# Tests inferior calls executed from a breakpoint condition in +# a multi-threaded program. +# +# This test has the inferior function call timeout, and checks how GDB +# handles this situation. + +standard_testfile + +if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ + {debug pthreads}] } { + return +} + +set cond_bp_line [gdb_get_line_number "Conditional breakpoint here"] +set final_bp_line [gdb_get_line_number "Stop marker"] +set segfault_line [gdb_get_line_number "Segfault here"] + +# Setup GDB based on TARGET_ASYNC and TARGET_NON_STOP. Setup some +# breakpoints in the inferior, one of which has an inferior call +# within its condition. +# +# Continue GDB, the breakpoint with inferior call will be hit, but the +# inferior call will never return. We expect GDB to timeout. +# +# The reason that the inferior call never completes is that a second +# thread, on which the inferior call relies, either hits a breakpoint +# (when OTHER_THREAD_BP is true), or crashes (when OTHER_THREAD_BP is +# false). +proc run_test { target_async target_non_stop other_thread_bp } { + save_vars { ::GDBFLAGS } { + append ::GDBFLAGS " -ex \"maint set target-non-stop $target_non_stop\"" + append ::GDBFLAGS " -ex \"maintenance set target-async ${target_async}\"" + + clean_restart ${::binfile} + } + + if {![runto_main]} { + fail "run to main" + return + } + + # The default timeout for indirect inferior calls (e.g. inferior + # calls for conditional breakpoint expressions) is pretty high. + # We don't want the test to take too long, so reduce this. + # + # However, the test relies on a second thread hitting some event + # (either a breakpoint or signal) before this timeout expires. + # + # There is a chance that on a really slow system this might not + # happen, in which case the test might fail. + # + # However, we still allocate 5 seconds, which feels like it should + # be enough time in most cases, but maybe we need to do something + # smarter here? Possibly we could have some initial run where the + # inferior doesn't timeout, but does do the same interaction + # between threads, we could time that, and use that as the basis + # for this timeout. For now though, we just hope 5 seconds is + # enough. + gdb_test_no_output "set indirect-call-timeout 5" + + gdb_breakpoint \ + "${::srcfile}:${::cond_bp_line} if (condition_func ())" + set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for conditional breakpoint"] + + gdb_breakpoint "${::srcfile}:${::final_bp_line}" + set final_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for final breakpoint"] + + # The thread performing an inferior call relies on a second + # thread. The second thread will segfault unless it hits a + # breakpoint first. In either case the initial thread will not + # complete its inferior call. + if { $other_thread_bp } { + gdb_breakpoint "${::srcfile}:${::segfault_line}" + set segfault_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get number for segfault breakpoint"] + } + + # When non-stop mode is off we get slightly different output from GDB. + if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } { + set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" received signal SIGINT, Interrupt\\." + } else { + set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." + } + + gdb_test "continue" \ + [multi_line \ + $stopped_line_pattern \ + ".*" \ + "Error in testing condition for breakpoint ${bp_num}:" \ + "The program being debugged timed out while in a function called from GDB\\." \ + "GDB remains in the frame where the timeout occurred\\." \ + "To change this behavior use \"set unwind-on-timeout on\"\\." \ + "Evaluation of the expression containing the function" \ + "\\(condition_func\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] \ + "expected timeout waiting for inferior call to complete" + + # Remember that other thread that either crashed (with a segfault) + # or hit a breakpoint? Now that the inferior call has timed out, + # if we try to resume then we should see the pending event from + # that other thread. + if { $other_thread_bp } { + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "" \ + "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${segfault_bp_num}, do_segfault \[^\r\n\]+:${::segfault_line}" \ + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+"] \ + "hit the segfault breakpoint" + } else { + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + ".*" \ + "Thread ${::decimal} \"infcall-from-bp\" received signal SIGSEGV, Segmentation fault\\." \ + "\\\[Switching to Thread \[^\r\n\]+\\\]" \ + "${::hex} in do_segfault \\(\\) at \[^\r\n\]+:${::segfault_line}" \ + "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+"] \ + "hit the segfault" + } +} + +foreach_with_prefix target_async {"on" "off" } { + + if { $target_async == "off" } { + # GDB can't timeout while waiting for a thread if the target + # runs with async-mode turned off; once the target is running + # GDB is effectively blocked until the target stops for some + # reason. + continue + } + + foreach_with_prefix target_non_stop {"off" "on"} { + foreach_with_prefix other_thread_bp { true false } { + run_test $target_async $target_non_stop $other_thread_bp + } + } +} From patchwork Tue Jan 31 17:27:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64038 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 58700384F033 for ; Tue, 31 Jan 2023 17:52:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58700384F033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187557; bh=0bZvBYG/LqW6MraOXUJL7beXwNy6n0wxQDb+gDvAHKM=; 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=IzYsyU1MvgOFoPGzIrTMT7tYE8XD69FVkqnUMXNNHju1HTr/rSpavaeYnNyjN5Fsc iC8V5OiQGDfOD+BOajdVpiIC5UmWY/7def6xog5SLRG5IBMqt7zyObafJrMhGZ9KoV yIj854DAOrmvE1U5AV+puBUv80P7YXrA7ppl3XuE= 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 ACF5338582A1 for ; Tue, 31 Jan 2023 17:50:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACF5338582A1 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-615-t9Qasmo5OaW-tbVJwBA82Q-1; Tue, 31 Jan 2023 12:27:44 -0500 X-MC-Unique: t9Qasmo5OaW-tbVJwBA82Q-1 Received: by mail-qt1-f200.google.com with SMTP id a13-20020ac8108d000000b003b7ea9814a2so6866033qtj.2 for ; Tue, 31 Jan 2023 09:27: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=0bZvBYG/LqW6MraOXUJL7beXwNy6n0wxQDb+gDvAHKM=; b=LcFw6BKnK0drzdrPL179683BtoprR2J5HBd0PfQri/IqKvYCiIXio+Bk/hIvsp9Kcz UXmFQJSR+VSr4DbC2aMMoysdG3/pjnRma9NJqzBI42vxBqiSwQGGwOd9S3ZOJ8iCXu3x N9EHS75FLXucK2LlS7zA+SHdo+Ibg5X7GpCFGVkANN2YYpOLJri5Flw39br21IUgpLlm zrN+FMUlZBFsotxc4kPSj1b3FJbFTMFN5rlCheny5MSYylByQlwudOB8rZXXSMll1i9V 5gJmD7uPkvpT+MaoudPlSf6QStcbher7xG42KJdBXPxhv/aF/OCSuXLuh+KgZyKpglCx fQPQ== X-Gm-Message-State: AO0yUKXizf/qDxrWG5saLKwvn5EOisQcKtPMgpUr8lGoYSvrM+ULrh3+ R1aWch7xXUtQ9Xm/LcqnAHMkF7p4aiQtZ99KNq7OLPcmxKlzwF0icqc0OkhFjHQsITDZwnZLZKa 6Fz+1dYNHWScVowTLA0jhkyza238V5XeqyFHO04e/Oozq/7HvMxJyrAyjjsUqwFUPoFDKfq2izg == X-Received: by 2002:a05:622a:1445:b0:3b9:a641:aa66 with SMTP id v5-20020a05622a144500b003b9a641aa66mr6990931qtx.15.1675186063368; Tue, 31 Jan 2023 09:27:43 -0800 (PST) X-Google-Smtp-Source: AK7set9X1JD6V/MnurBNhrpt+zHkewL1uwwOYJz+rqiD+6IoA2PY6O2VoEvxtHd/j3anYmitTnSTvw== X-Received: by 2002:a05:622a:1445:b0:3b9:a641:aa66 with SMTP id v5-20020a05622a144500b003b9a641aa66mr6990897qtx.15.1675186062954; Tue, 31 Jan 2023 09:27:42 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id a26-20020aed279a000000b003b8484fdfccsm6251904qtd.42.2023.01.31.09.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:42 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 11/13] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Tue, 31 Jan 2023 17:27:16 +0000 Message-Id: <97a59b0b300f2510c40237c129d26e302fe702da.1675185990.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.8 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" Currently, if the remote target is not running in non-stop mode, then, when GDB calls remote_target::stop, we end up sending an interrupt packet \x03 to the remote target. If the user interrupts the inferior from the GDB prompt (e.g. by typing Ctrl-c), then GDB calls remote_target::interrupt, which also ends up sending the interrupt packet. The problem here is that both of these mechanisms end up sending the interrupt packet, which means, when the target stops with a SIGINT, and this is reported back to GDB, we have no choice but to report this to the user as a SIGINT stop event. Now maybe this is the correct thing to do, after all the target has been stopped with SIGINT. However, this leads to an unfortunate change in behaviour when comparing non-stop vs all-stop mode. When running in non-stop mode, and remote_target::stop is called, the target will be stopped with a vCont packet, and this stop is then reported back to GDB as GDB_SIGNAL_0, this will cause GDB to print a message like: Program stopped. Or: Thread NN "binary name" stopped. In contrast, when non-stop mode is off, we get messages like: Program received SIGINT, Segmentation fault. Or: Thread NN "binary name" received SIGINT, Segmentation fault. In this commit I propose making use of thread_info::stop_requested within remote.c to know if the stop was triggered by GDB (and the SIGINT should be hidden) or if the stop was a user interrupt, and the SIGINT should be printed. In remote_target::process_stop_reply if the inferior stopped with SIGINT and the thread_info::stop_requested flag is set, then we change the stop signal to GDB_SIGNAL_0. Two of the tests added in the previous commit exposed this issue. In the previous commit the tests looked for either of the above patterns. In this commit I've updated these tests to only look for the "stopped" based messages. This commit is the reason why the previous commit took care to set the thread_info::stop_requested flag in infcall.c. --- gdb/remote.c | 10 ++++++++++ gdb/testsuite/gdb.base/infcall-timeout.exp | 9 +-------- .../gdb.threads/infcall-from-bp-cond-timeout.exp | 9 +-------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index ba7a7520cb4..604d75b9689 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8275,6 +8275,16 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, } else { + /* If this stop was actually requested by GDB then we can hide + the SIGINT from the user. */ + if (status->kind () == TARGET_WAITKIND_STOPPED + && status->sig () == GDB_SIGNAL_INT) + { + thread_info *thr = find_thread_ptid (this, ptid); + if (thr->stop_requested) + status->set_stopped (GDB_SIGNAL_0); + } + /* If the target works in all-stop mode, a stop-reply indicates that all the target's threads stopped. */ for (thread_info *tp : all_non_exited_threads (this)) diff --git a/gdb/testsuite/gdb.base/infcall-timeout.exp b/gdb/testsuite/gdb.base/infcall-timeout.exp index a5b0111ed04..bd6b2bfac3e 100644 --- a/gdb/testsuite/gdb.base/infcall-timeout.exp +++ b/gdb/testsuite/gdb.base/infcall-timeout.exp @@ -45,16 +45,9 @@ proc_with_prefix run_test { target_async target_non_stop } { gdb_test_no_output "set direct-call-timeout 5" - # When non-stop mode is off we get slightly different output from GDB. - if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } { - set stopped_line_pattern "Program received signal SIGINT, Interrupt\\." - } else { - set stopped_line_pattern "Program stopped\\." - } - gdb_test "print function_that_never_returns ()" \ [multi_line \ - $stopped_line_pattern \ + "Program stopped\\." \ ".*" \ "The program being debugged timed out while in a function called from GDB\\." \ "GDB remains in the frame where the timeout occurred\\." \ diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp index 3341ff33f19..9ba38e6896a 100644 --- a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp @@ -92,16 +92,9 @@ proc run_test { target_async target_non_stop other_thread_bp } { "get number for segfault breakpoint"] } - # When non-stop mode is off we get slightly different output from GDB. - if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } { - set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" received signal SIGINT, Interrupt\\." - } else { - set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." - } - gdb_test "continue" \ [multi_line \ - $stopped_line_pattern \ + "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." \ ".*" \ "Error in testing condition for breakpoint ${bp_num}:" \ "The program being debugged timed out while in a function called from GDB\\." \ From patchwork Tue Jan 31 17:27:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64032 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 E6FFA385DC3C for ; Tue, 31 Jan 2023 17:50:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6FFA385DC3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187449; bh=WrVht7u/jZ3F+xHZGx1T70Wp7guxepjM/2OWLUgrKBI=; 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=h6Pc41DypBxxHCc8IhlnnSKodwotBEIY8GeE90R1/yKlbT+sXtHezB9WgRnuDVHLc iGtTzi8HPHKXNb7YbOi1ap8XwM7jwIfulxX4aTbcN63WZqWeFl47IjCu69EtzM9RCw HoA4IqhvNOAmA04w0PhHUdtxDyTsOU1BUrWsxMtQ= 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 E3B973858C2D for ; Tue, 31 Jan 2023 17:49:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3B973858C2D Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-660-EGov9vcRNNKulvdoYg-93Q-1; Tue, 31 Jan 2023 12:27:46 -0500 X-MC-Unique: EGov9vcRNNKulvdoYg-93Q-1 Received: by mail-qt1-f200.google.com with SMTP id c16-20020ac85190000000b003b841d1118aso3993851qtn.17 for ; Tue, 31 Jan 2023 09:27:46 -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=WrVht7u/jZ3F+xHZGx1T70Wp7guxepjM/2OWLUgrKBI=; b=Q2OGLB6FkpqEH/6Pl6C26Bwzs+qxiyvQ1VsEC1v/o4ata15YJmzE37PF7zssoT+x49 PmmiEZZcWcfDFpUBwFGis4D5HntVwqXZPl2JQmn4spbOWadyG/QFjPmVfrbT+OaMKtG4 Np6lWN5dwID62BE9zvQqXzqB2pIakf+ZPeW0F8Wqh6lWjLtiL7d5dhzmC6nnASD5+zZD SvGh8LGKTpU7CXK/VPY/MZ9Vv71rQxi7IHV7jyOpn6DDsV1VJpr8ZAjbzeXiCp83NjxX 2vpAOe/7TiIfJa7HKQs6x5XaVevy6LKFd50Z88v3SDvdv5M1c6Rwjta1AzfI1Uc96AuL kbKg== X-Gm-Message-State: AO0yUKUK2ZNzihqINBGkXy1sglmpBVgT8j6+f7e24MTkfsrUWWy8UdS5 PfiNuPnj78I0IxS6sPZo2YBj8k4BPtHzLO+6jLcx60H6hinYScVEPuAOzqN5mvF1RQ5GQ4vO0lA tPuZ6MgExNJI3PkPlbMqDq4Fz7ginImeL1dgMIdChRHs68afIULx7AkfbN63a7Bd3a2sK9us6mQ == X-Received: by 2002:a05:6214:401a:b0:538:b19a:7ab5 with SMTP id kd26-20020a056214401a00b00538b19a7ab5mr18884545qvb.10.1675186065487; Tue, 31 Jan 2023 09:27:45 -0800 (PST) X-Google-Smtp-Source: AK7set9C01jWQlbRGc62ODsWhRNPvdvkQvciGPlfwT1tvPWbARb6JazExU59YnJTfOnIV7MUJ/qrsA== X-Received: by 2002:a05:6214:401a:b0:538:b19a:7ab5 with SMTP id kd26-20020a056214401a00b00538b19a7ab5mr18884484qvb.10.1675186064883; Tue, 31 Jan 2023 09:27:44 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id c66-20020a379a45000000b0071a291f0a4asm7869637qke.27.2023.01.31.09.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:44 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 12/13] gdb: introduce unwind-on-timeout setting Date: Tue, 31 Jan 2023 17:27:17 +0000 Message-Id: <4550bcb939249fa7618b80ed872dccdf51fa6f25.1675185990.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.8 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" Now that inferior function calls can timeout (see the recent introduction of direct-call-timeout and indirect-call-timeout), this commit adds a new setting unwind-on-timeout. This new setting is just like the existing unwindonsignal and unwind-on-terminating-exception, but the new setting will cause GDB to unwind the stack if an inferior function call times out. The existing inferior function call timeout tests have been updated to cover the new setting. --- gdb/NEWS | 9 +++ gdb/doc/gdb.texinfo | 33 +++++++--- gdb/infcall.c | 62 ++++++++++++++++--- gdb/testsuite/gdb.base/infcall-timeout.exp | 49 +++++++++++---- .../infcall-from-bp-cond-timeout.exp | 55 +++++++++++----- 5 files changed, 164 insertions(+), 44 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 835bf7f8680..9907f802e09 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -56,6 +56,15 @@ show indirect-call-timeout ignored, GDB will wait indefinitely for an inferior function to complete, unless interrupted by the user using Ctrl-C. +set unwind-on-timeout on|off +show unwind-on-timeout + These commands control whether GDB should unwind the stack when a + timeout occurs during an inferior function call. The default is + off, in which case the inferior will remain in the frame where the + timeout occurred. When on, GDB will unwind the stack removing the + dummy frame that was added for the inferior call, and restoring the + inferior state to how it was before the inferior call started. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f5d460eb9e5..9ddc01d833f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -5719,10 +5719,10 @@ the called function, or the called function may receive a signal (e.g.@ a @code{SIGSEGV}) as a result of some undefined behavior. If this happens then @value{GDBN} will stop. Depending on the settings -@code{unwindonsignal} and @code{unwind-on-terminating-exception} -(@pxref{Calling,,Calling Program Functions}) @value{GDBN} may unwind -the stack back to the breakpoint location, or may leave the program at -the frame where the stop occurred. +@code{unwindonsignal}, @code{unwind-on-terminating-exception}, and +@code{unwind-on-timeout} (@pxref{Calling,,Calling Program Functions}) +@value{GDBN} may unwind the stack back to the breakpoint location, or +may leave the program at the frame where the stop occurred. Breakpoint conditions can also be evaluated on the target's side if the target supports it. Instead of evaluating the conditions locally, @@ -20753,6 +20753,21 @@ Show the current setting of stack unwinding in the functions called by @value{GDBN}. +@item set unwind-on-timeout +@kindex set unwind-on-timeout +@cindex unwind stack in called functions when timing out +@cindex call dummy stack unwinding on timeout. +Set unwinding of the stack if a function called from @value{GDBN} +times out. If set to @code{off} (the default), @value{GDBN} stops in +the frame where the timeout occurred. If set to @code{on}, +@value{GDBN} unwinds the stack it created for the call and restores +the context to what it was before the call. + +@item show unwind-on-timeout +@kindex show unwind-on-timeout +Show whether @value{GDBN} will unwind the stack if a function called +from @value{GDBN} times out. + @item set may-call-functions @kindex set may-call-functions @cindex disabling calling functions in the program @@ -20784,11 +20799,11 @@ If a called function is interrupted for any reason, including hitting a breakpoint, or triggering a watchpoint, and the stack is not unwound -due to @code{set unwind-on-terminating-exception on} or @code{set -unwindonsignal on} (@pxref{stack unwind settings}), -then the dummy-frame, created by @value{GDBN} to facilitate the call -to the program function, will be visible in the backtrace, for example -frame @code{#3} in the following backtrace: +due to @code{set unwind-on-terminating-exception on}, @code{set +unwind-on-timeout on}, or @code{set unwindonsignal on} (@pxref{stack +unwind settings}), then the dummy-frame, created by @value{GDBN} to +facilitate the call to the program function, will be visible in the +backtrace, for example frame @code{#3} in the following backtrace: @smallexample (@value{GDBP}) backtrace diff --git a/gdb/infcall.c b/gdb/infcall.c index 92f49a64e3e..20d63ba4627 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -217,6 +217,27 @@ show_unwind_on_terminating_exception_p (struct ui_file *file, int from_tty, value); } +/* This boolean tells GDB what to do if an inferior function, called from + GDB, times out. If true GDB unwinds the stack and restores the context + to what it was before the call. When false GDB leaves the thread as it + is at the point of the timeout. + + The default is to stop in the frame where the time out occurred. */ + +static bool unwind_on_timeout_p = false; + +/* Implement 'show unwind-on-timeout'. */ + +static void +show_unwind_on_timeout_p (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, + _("Unwinding of stack if a timeout occurs " + "while in a call dummy is %s.\n"), + value); +} + /* Perform the standard coercions that are specified for arguments to be passed to C, Ada or Fortran functions. @@ -1699,14 +1720,27 @@ When the function is done executing, GDB will silently stop."), /* A timeout results in a signal being sent to the inferior. */ gdb_assert (stopped_by_random_signal); - /* Indentation is weird here. A later patch is going to move the - following block into an if/else, so I'm leaving the indentation - here to minimise the later patch. + if (unwind_on_timeout_p) + { + /* The user wants the context restored. */ + + /* We must get back to the frame we were before the + dummy call. */ + dummy_frame_pop (dummy_id, call_thread.get ()); - Also, the error message used below refers to 'set - unwind-on-timeout' which doesn't exist yet. This will be added - in a later commit, I'm leaving this in for now to minimise the - churn caused by the commit that adds unwind-on-timeout. */ + /* We also need to restore inferior status to that before the + dummy call. */ + restore_infcall_control_state (inf_status.release ()); + + error (_("\ +The program being debugged timed out while in a function called from GDB.\n\ +GDB has restored the context to what it was before the call.\n\ +To change this behavior use \"set unwind-on-timeout off\".\n\ +Evaluation of the expression containing the function\n\ +(%s) will be abandoned."), + name.c_str ()); + } + else { /* The user wants to stay in the frame where we stopped (default). Discard inferior status, we're not at the same @@ -1832,6 +1866,20 @@ The default is to unwind the frame."), show_unwind_on_terminating_exception_p, &setlist, &showlist); + add_setshow_boolean_cmd ("unwind-on-timeout", no_class, + &unwind_on_timeout_p, _("\ +Set unwinding of stack if a timeout occurs while in a call dummy."), _("\ +Show unwinding of stack if a timeout occurs while in a call dummy."), + _("\ +The unwind on timeout flag lets the user determine what gdb should do if\n\ +gdb times out while in a function called from gdb. If set, gdb unwinds\n\ +the stack and restores the context to what it was before the call. If\n\ +unset, gdb leaves the inferior in the frame where the timeout occurred.\n\ +The default is to stop in the frame where the timeout occurred."), + NULL, + show_unwind_on_timeout_p, + &setlist, &showlist); + add_setshow_uinteger_cmd ("direct-call-timeout", no_class, &direct_call_timeout, _("\ Set the timeout, for direct calls to inferior function calls."), _("\ diff --git a/gdb/testsuite/gdb.base/infcall-timeout.exp b/gdb/testsuite/gdb.base/infcall-timeout.exp index bd6b2bfac3e..a4d9fd6ee61 100644 --- a/gdb/testsuite/gdb.base/infcall-timeout.exp +++ b/gdb/testsuite/gdb.base/infcall-timeout.exp @@ -28,7 +28,11 @@ if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \ # the direct-call-timeout, and make an inferior function call that # will never return. GDB should eventually timeout and stop the # inferior. -proc_with_prefix run_test { target_async target_non_stop } { +# +# When UNWIND is "off" the inferior wil be left in the frame where the +# timeout occurs, otherwise, when UNWIND is "on", GDB should unwind +# back to the frame where the inferior call was made. +proc_with_prefix run_test { target_async target_non_stop unwind } { save_vars { ::GDBFLAGS } { append ::GDBFLAGS \ " -ex \"maint set target-non-stop $target_non_stop\"" @@ -44,19 +48,36 @@ proc_with_prefix run_test { target_async target_non_stop } { } gdb_test_no_output "set direct-call-timeout 5" + gdb_test_no_output "set unwind-on-timeout $unwind" + + if { $unwind } { + gdb_test "print function_that_never_returns ()" \ + [multi_line \ + "Program stopped\\." \ + ".*" \ + "The program being debugged timed out while in a function called from GDB\\." \ + "GDB has restored the context to what it was before the call\\." \ + "To change this behavior use \"set unwind-on-timeout off\"\\." \ + "Evaluation of the expression containing the function" \ + "\\(function_that_never_returns\\) will be abandoned\\."] - gdb_test "print function_that_never_returns ()" \ - [multi_line \ - "Program stopped\\." \ - ".*" \ - "The program being debugged timed out while in a function called from GDB\\." \ - "GDB remains in the frame where the timeout occurred\\." \ - "To change this behavior use \"set unwind-on-timeout on\"\\." \ - "Evaluation of the expression containing the function" \ - "\\(function_that_never_returns\\) will be abandoned\\." \ - "When the function is done executing, GDB will silently stop\\."] + gdb_test "bt" \ + "#0\\s+main \\(\\).*" + } else { + gdb_test "print function_that_never_returns ()" \ + [multi_line \ + "Program stopped\\." \ + ".*" \ + "The program being debugged timed out while in a function called from GDB\\." \ + "GDB remains in the frame where the timeout occurred\\." \ + "To change this behavior use \"set unwind-on-timeout on\"\\." \ + "Evaluation of the expression containing the function" \ + "\\(function_that_never_returns\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] - gdb_test "bt" ".* function_that_never_returns .*.*" + gdb_test "bt" \ + ".* function_that_never_returns .*.*" + } } foreach_with_prefix target_async { "on" "off" } { @@ -70,6 +91,8 @@ foreach_with_prefix target_async { "on" "off" } { } foreach_with_prefix target_non_stop { "on" "off" } { - run_test $target_async $target_non_stop + foreach_with_prefix unwind { "on" "off" } { + run_test $target_async $target_non_stop $unwind + } } } diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp index 9ba38e6896a..847a850673d 100644 --- a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp @@ -41,7 +41,12 @@ set segfault_line [gdb_get_line_number "Segfault here"] # thread, on which the inferior call relies, either hits a breakpoint # (when OTHER_THREAD_BP is true), or crashes (when OTHER_THREAD_BP is # false). -proc run_test { target_async target_non_stop other_thread_bp } { +# +# When UNWIND is "on" GDB will unwind the thread which performed the +# inferior function call back to the state where the inferior call was +# made (when the inferior call times out). Otherwise, when UNWIND is +# "off", the inferior is left in the frame where the timeout occurred. +proc run_test { target_async target_non_stop other_thread_bp unwind } { save_vars { ::GDBFLAGS } { append ::GDBFLAGS " -ex \"maint set target-non-stop $target_non_stop\"" append ::GDBFLAGS " -ex \"maintenance set target-async ${target_async}\"" @@ -72,6 +77,7 @@ proc run_test { target_async target_non_stop other_thread_bp } { # for this timeout. For now though, we just hope 5 seconds is # enough. gdb_test_no_output "set indirect-call-timeout 5" + gdb_test_no_output "set unwind-on-timeout $unwind" gdb_breakpoint \ "${::srcfile}:${::cond_bp_line} if (condition_func ())" @@ -92,18 +98,35 @@ proc run_test { target_async target_non_stop other_thread_bp } { "get number for segfault breakpoint"] } - gdb_test "continue" \ - [multi_line \ - "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." \ - ".*" \ - "Error in testing condition for breakpoint ${bp_num}:" \ - "The program being debugged timed out while in a function called from GDB\\." \ - "GDB remains in the frame where the timeout occurred\\." \ - "To change this behavior use \"set unwind-on-timeout on\"\\." \ - "Evaluation of the expression containing the function" \ - "\\(condition_func\\) will be abandoned\\." \ - "When the function is done executing, GDB will silently stop\\."] \ - "expected timeout waiting for inferior call to complete" + if { $unwind } { + gdb_test "continue" \ + [multi_line \ + "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." \ + ".*" \ + "Error in testing condition for breakpoint ${bp_num}:" \ + "The program being debugged timed out while in a function called from GDB\\." \ + "GDB has restored the context to what it was before the call\\." \ + "To change this behavior use \"set unwind-on-timeout off\"\\." \ + "Evaluation of the expression containing the function" \ + "\\(condition_func\\) will be abandoned\\." \ + "" \ + "Thread ${::decimal}\[^\r\n\]*hit Breakpoint ${bp_num}, \[^\r\n\]+" \ + "\[^\r\n\]+ Conditional breakpoint here\\. \[^\r\n\]+"] \ + "expected timeout waiting for inferior call to complete" + } else { + gdb_test "continue" \ + [multi_line \ + "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." \ + ".*" \ + "Error in testing condition for breakpoint ${bp_num}:" \ + "The program being debugged timed out while in a function called from GDB\\." \ + "GDB remains in the frame where the timeout occurred\\." \ + "To change this behavior use \"set unwind-on-timeout on\"\\." \ + "Evaluation of the expression containing the function" \ + "\\(condition_func\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] \ + "expected timeout waiting for inferior call to complete" + } # Remember that other thread that either crashed (with a segfault) # or hit a breakpoint? Now that the inferior call has timed out, @@ -142,8 +165,10 @@ foreach_with_prefix target_async {"on" "off" } { } foreach_with_prefix target_non_stop {"off" "on"} { - foreach_with_prefix other_thread_bp { true false } { - run_test $target_async $target_non_stop $other_thread_bp + foreach_with_prefix unwind {"off" "on"} { + foreach_with_prefix other_thread_bp { true false } { + run_test $target_async $target_non_stop $other_thread_bp $unwind + } } } } From patchwork Tue Jan 31 17:27:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64040 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 F1A0E385842C for ; Tue, 31 Jan 2023 17:53:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1A0E385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187621; bh=vlzWLyTkTm8j2i2h7Gwc4KNE1eNzpr+RzOKevNJAfVU=; 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=wzbRExwcZPaALmy4PtFBaIWZ67HhWj7M9Byg+NldFPK3TJgNPSF9a2onr0V5kC/Tp P7lMueS60SQ4Va/aTMfGMxz2pUIMYhZrEivIXfDU0hzQObdYPU+7LuSvmB1nfb73Eb 0bqPbCcXSGWUAp5H2K67bKaGT/U5b5uKX6yPs6V8= 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 3F7DF3857C48 for ; Tue, 31 Jan 2023 17:50:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F7DF3857C48 Received: from mail-vs1-f72.google.com (mail-vs1-f72.google.com [209.85.217.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-63--hjAHsIoOFmSpvmFT3shhQ-1; Tue, 31 Jan 2023 12:27:48 -0500 X-MC-Unique: -hjAHsIoOFmSpvmFT3shhQ-1 Received: by mail-vs1-f72.google.com with SMTP id 190-20020a6708c7000000b003d3efe13b28so3233946vsi.19 for ; Tue, 31 Jan 2023 09:27: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=vlzWLyTkTm8j2i2h7Gwc4KNE1eNzpr+RzOKevNJAfVU=; b=Crj3QEOHEbeuXaHxmRqeK36/UHN1SUHWIdTwjkIuMYGI08fYH+QK61RKgw80FnuTsP Re8SNJGPRxC/tlo08y9OqXIdFcEjI2eeI4dNTkPI7qEIeSNxDWEevNChqTF29aI6UAtv rwLjcv45oXBfM2oP5xZjp+BGNBn2gRRVtc8x3Oq2sakys9JAwMWbaU8g838cMJmFJ/Ue J6dJ4NECFTrTgYSEywrADMcqbJQ1FvCnL3+7oSe9+jl9Dse9X1+QTcogVkigUwW1iSSC gaFM4v0oZao8a1bqsfKanY/RxcmYGJPuoFZdCDogibPa98gXSixzOZAiD0Hl8xSPapad 5Bkg== X-Gm-Message-State: AFqh2kqvSKfhi12uFxhGY+TpS5v4IvdgGerVTJP6hFLSFjNRjthe22qb 9Reac5LmVlPL2I8Q2Lr5zUNscFU0rk6sSwJx/ihll1Sq9ivcqF9hACiZkVALFAxpJde0d8e4Yqn rEgKPECXq+Rc0o10D8E77C83wExjGp2JOQAXm7WLGFstNrl0rQM4pla6lkej4aRPdUyLW/DKYfw == X-Received: by 2002:a05:6102:e8b:b0:3ce:ea85:90f3 with SMTP id l11-20020a0561020e8b00b003ceea8590f3mr38806965vst.16.1675186067695; Tue, 31 Jan 2023 09:27:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXvmO9jhjABHEXGfWMPo0T2sNg9HgW/rnSDDQ8tdpcBdNimwJXBnc5cy0kZMOTzaeMN/GdhlcA== X-Received: by 2002:a05:6102:e8b:b0:3ce:ea85:90f3 with SMTP id l11-20020a0561020e8b00b003ceea8590f3mr38806945vst.16.1675186066864; Tue, 31 Jan 2023 09:27:46 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id x124-20020a379582000000b006cbc00db595sm10413028qkd.23.2023.01.31.09.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:46 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 13/13] gdb: rename unwindonsignal to unwind-on-signal Date: Tue, 31 Jan 2023 17:27:18 +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.8 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" We now have unwind-on-timeout and unwind-on-terminating-exception, and then the odd one out unwindonsignal. I'm not a great fan of these squashed together command names, so in this commit I propose renaming this to unwind-on-signal. Obviously I've added the hidden alias unwindonsignal so any existing GDB scripts will keep working. There's one test that I've extended to test the alias works, but in most of the other test scripts I've changed over to use the new name. The docs are updated to reference the new name. --- gdb/NEWS | 11 ++++++ gdb/doc/gdb.texinfo | 16 ++++++--- gdb/infcall.c | 21 ++++++----- gdb/testsuite/gdb.base/callfuncs.exp | 4 +-- gdb/testsuite/gdb.base/infcall-failure.exp | 4 +-- gdb/testsuite/gdb.base/unwindonsignal.exp | 36 +++++++++++++------ gdb/testsuite/gdb.compile/compile-cplus.exp | 2 +- gdb/testsuite/gdb.compile/compile.exp | 2 +- gdb/testsuite/gdb.cp/gdb2495.exp | 16 ++++----- gdb/testsuite/gdb.fortran/function-calls.exp | 2 +- gdb/testsuite/gdb.mi/mi-syn-frame.exp | 2 +- .../infcall-from-bp-cond-simple.exp | 2 +- .../gdb.threads/thread-unwindonsignal.exp | 8 ++--- 13 files changed, 83 insertions(+), 43 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 9907f802e09..cf178102822 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -65,6 +65,17 @@ show unwind-on-timeout dummy frame that was added for the inferior call, and restoring the inferior state to how it was before the inferior call started. +set unwind-on-signal on|off +show unwind-on-signal + These new commands replaces the existing set/show unwindonsignal. The + old command is maintained as an alias. + +* Changed commands + +set unwindonsignal on|off +show unwindonsignal + These commands are now aliases for the new set/show unwind-on-signal. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9ddc01d833f..9bfa20b1339 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20707,7 +20707,7 @@ It is possible for the function you call via the @code{print} or @code{call} command to generate a signal (e.g., if there's a bug in the function, or if you passed it incorrect arguments). What happens -in that case is controlled by the @code{set unwindonsignal} command. +in that case is controlled by the @code{set unwind-on-signal} command. Similarly, with a C@t{++} program it is possible for the function you call via the @code{print} or @code{call} command to generate an @@ -20721,7 +20721,8 @@ @anchor{stack unwind settings} @table @code -@item set unwindonsignal +@item set unwind-on-signal +@kindex set unwind-on-signal @kindex set unwindonsignal @cindex unwind stack in called functions @cindex call dummy stack unwinding @@ -20732,11 +20733,18 @@ default), @value{GDBN} stops in the frame where the signal was received. -@item show unwindonsignal +The command @code{set unwindonsignal} is an alias for this command, +and is maintained for backward compatibility. + +@item show unwind-on-signal +@kindex show unwind-on-signal @kindex show unwindonsignal Show the current setting of stack unwinding in the functions called by @value{GDBN}. +The command @code{show unwindonsignal} is an alias for this command, +and is maintained for backward compatibility. + @item set unwind-on-terminating-exception @kindex set unwind-on-terminating-exception @cindex unwind stack in called functions with unhandled exceptions @@ -20800,7 +20808,7 @@ If a called function is interrupted for any reason, including hitting a breakpoint, or triggering a watchpoint, and the stack is not unwound due to @code{set unwind-on-terminating-exception on}, @code{set -unwind-on-timeout on}, or @code{set unwindonsignal on} (@pxref{stack +unwind-on-timeout on}, or @code{set unwind-on-signal on} (@pxref{stack unwind settings}), then the dummy-frame, created by @value{GDBN} to facilitate the call to the program function, will be visible in the backtrace, for example frame @code{#3} in the following backtrace: diff --git a/gdb/infcall.c b/gdb/infcall.c index 20d63ba4627..71f93784c69 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -1689,7 +1689,7 @@ When the function is done executing, GDB will silently stop."), error (_("\ The program being debugged was signaled while in a function called from GDB.\n\ GDB has restored the context to what it was before the call.\n\ -To change this behavior use \"set unwindonsignal off\".\n\ +To change this behavior use \"set unwind-on-signal off\".\n\ Evaluation of the expression containing the function\n\ (%s) will be abandoned."), name.c_str ()); @@ -1707,7 +1707,7 @@ Evaluation of the expression containing the function\n\ error (_("\ The program being debugged was signaled while in a function called from GDB.\n\ GDB remains in the frame where the signal was received.\n\ -To change this behavior use \"set unwindonsignal on\".\n\ +To change this behavior use \"set unwind-on-signal on\".\n\ Evaluation of the expression containing the function\n\ (%s) will be abandoned.\n\ When the function is done executing, GDB will silently stop."), @@ -1839,17 +1839,22 @@ The default is to perform the conversion."), show_coerce_float_to_double_p, &setlist, &showlist); - add_setshow_boolean_cmd ("unwindonsignal", no_class, - &unwind_on_signal_p, _("\ + set_show_commands setshow_unwind_on_signal_cmds + = add_setshow_boolean_cmd ("unwind-on-signal", no_class, + &unwind_on_signal_p, _("\ Set unwinding of stack if a signal is received while in a call dummy."), _("\ Show unwinding of stack if a signal is received while in a call dummy."), _("\ -The unwindonsignal lets the user determine what gdb should do if a signal\n\ +The unwind-on-signal lets the user determine what gdb should do if a signal\n\ is received while in a function called from gdb (call dummy). If set, gdb\n\ unwinds the stack and restore the context to what as it was before the call.\n\ The default is to stop in the frame where the signal was received."), - NULL, - show_unwind_on_signal_p, - &setlist, &showlist); + NULL, + show_unwind_on_signal_p, + &setlist, &showlist); + add_alias_cmd ("unwindonsignal", setshow_unwind_on_signal_cmds.set, + no_class, 1, &setlist); + add_alias_cmd ("unwindonsignal", setshow_unwind_on_signal_cmds.show, + no_class, 1, &showlist); add_setshow_boolean_cmd ("unwind-on-terminating-exception", no_class, &unwind_on_terminating_exception_p, _("\ diff --git a/gdb/testsuite/gdb.base/callfuncs.exp b/gdb/testsuite/gdb.base/callfuncs.exp index 9bbf108ac0e..0a1a9bd9391 100644 --- a/gdb/testsuite/gdb.base/callfuncs.exp +++ b/gdb/testsuite/gdb.base/callfuncs.exp @@ -49,7 +49,7 @@ proc do_function_calls {prototypes} { # If any of these calls segv we don't want to affect subsequent tests. # E.g., we want to ensure register values are restored. - gdb_test_no_output "set unwindonsignal on" + gdb_test_no_output "set unwind-on-signal on" gdb_test "p t_char_values(0,0)" " = 0" gdb_test "p t_char_values('a','b')" " = 1" @@ -240,7 +240,7 @@ proc do_function_calls {prototypes} { "call inferior func with struct - returns char *" # Restore default value. - gdb_test_no_output "set unwindonsignal off" + gdb_test_no_output "set unwind-on-signal off" } # Procedure to get current content of all registers. diff --git a/gdb/testsuite/gdb.base/infcall-failure.exp b/gdb/testsuite/gdb.base/infcall-failure.exp index 5ad179a089d..e2e71649dac 100644 --- a/gdb/testsuite/gdb.base/infcall-failure.exp +++ b/gdb/testsuite/gdb.base/infcall-failure.exp @@ -137,7 +137,7 @@ proc_with_prefix run_cond_hits_segfault_test { async_p non_stop_p } { "Error in testing condition for breakpoint ${bp_1_num}:" \ "The program being debugged was signaled while in a function called from GDB\\." \ "GDB remains in the frame where the signal was received\\." \ - "To change this behavior use \"set unwindonsignal on\"\\." \ + "To change this behavior use \"set unwind-on-signal on\"\\." \ "Evaluation of the expression containing the function" \ "\\(func_segfault\\) will be abandoned\\." \ "When the function is done executing, GDB will silently stop\\."] @@ -166,7 +166,7 @@ proc_with_prefix run_call_hits_segfault_test { async_p non_stop_p } { "${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \ "The program being debugged was signaled while in a function called from GDB\\." \ "GDB remains in the frame where the signal was received\\." \ - "To change this behavior use \"set unwindonsignal on\"\\." \ + "To change this behavior use \"set unwind-on-signal on\"\\." \ "Evaluation of the expression containing the function" \ "\\(func_segfault\\) will be abandoned\\." \ "When the function is done executing, GDB will silently stop\\."] diff --git a/gdb/testsuite/gdb.base/unwindonsignal.exp b/gdb/testsuite/gdb.base/unwindonsignal.exp index d10d1fe244d..c17b5742ea8 100644 --- a/gdb/testsuite/gdb.base/unwindonsignal.exp +++ b/gdb/testsuite/gdb.base/unwindonsignal.exp @@ -40,34 +40,50 @@ gdb_test "break stop_here" "Breakpoint \[0-9\]* at .*" gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_here.*" \ "continue to breakpoint at stop_here" -# Turn on unwindonsignal. -gdb_test_no_output "set unwindonsignal on" \ - "setting unwindonsignal" +# Turn on unwind-on-signal. +gdb_test_no_output "set unwind-on-signal on" \ + "setting unwind-on-signal" -gdb_test "show unwindonsignal" \ +gdb_test "show unwind-on-signal" \ "Unwinding of stack .* is on." \ - "showing unwindonsignal" + "showing unwind-on-signal" + +# For backward compatibility we maintain a 'unwindonsignal' alias for +# 'unwind-on-signal', check it now. +gdb_test "show unwindonsignal" \ + "Unwinding of stack .* is on\\." \ + "showing unwindonsignal alias" + +gdb_test_no_output "set unwindonsignal off" \ + "setting unwindonsignal alias to off" + +gdb_test "show unwind-on-signal" \ + "Unwinding of stack .* is off\\." \ + "showing unwind-on-signal after setting via alias" + +gdb_test_no_output "set unwindonsignal on" \ + "setting unwindonsignal alias to on" # Call function (causing the program to get a signal), and see if gdb handles # it properly. if {[gdb_test "call gen_signal ()" \ "\[\r\n\]*The program being debugged was signaled.*" \ - "unwindonsignal, inferior function call signaled"] != 0} { + "inferior function call signaled"] != 0} { return 0 } # Verify the stack got unwound. gdb_test "bt" \ "#0 *\[x0-9a-f in\]*stop_here \\(.*\\) at .*#1 *\[x0-9a-f in\]*main \\(.*\\) at .*" \ - "unwindonsignal, stack unwound" + "stack unwound" # Verify the dummy frame got removed from dummy_frame_stack. gdb_test_multiple "maint print dummy-frames" \ - "unwindonsignal, dummy frame removed" { + "unwind-on-signal, dummy frame removed" { -re "\[\r\n\]*.*stack=.*code=.*\[\r\n\]+$gdb_prompt $" { - fail "unwindonsignal, dummy frame removed" + fail $gdb_test_name } -re "\[\r\n\]+$gdb_prompt $" { - pass "unwindonsignal, dummy frame removed" + pass $gdb_test_name } } diff --git a/gdb/testsuite/gdb.compile/compile-cplus.exp b/gdb/testsuite/gdb.compile/compile-cplus.exp index 489236a8b49..3bb4fa17284 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus.exp @@ -129,7 +129,7 @@ gdb_test "return" "\r\n#0 main .*" "return" \ "Make _gdb_expr\\(__gdb_regs\\*\\) return now\\? \\(y or n\\) " "y" gdb_test "info sym $infcall_pc" "\r\nNo symbol matches .*" "info sym not found" -gdb_test_no_output "set unwindonsignal on" +gdb_test_no_output "set unwind-on-signal on" gdb_test "compile code *(volatile int *) 0 = 0;" \ "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*" \ "compile code segfault second" diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp index f3d87cd2605..8822aab2e81 100644 --- a/gdb/testsuite/gdb.compile/compile.exp +++ b/gdb/testsuite/gdb.compile/compile.exp @@ -159,7 +159,7 @@ gdb_test "return" "\r\n#0 main .*" "return" \ "Make _gdb_expr return now\\? \\(y or n\\) " "y" gdb_test "info sym $infcall_pc" "\r\nNo symbol matches .*" "info sym not found" -gdb_test_no_output "set unwindonsignal on" +gdb_test_no_output "set unwind-on-signal on" gdb_test "compile code *(volatile int *) 0 = 0;" \ "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*" \ "compile code segfault second" diff --git a/gdb/testsuite/gdb.cp/gdb2495.exp b/gdb/testsuite/gdb.cp/gdb2495.exp index 0cb8bdd0ada..af94d959d83 100644 --- a/gdb/testsuite/gdb.cp/gdb2495.exp +++ b/gdb/testsuite/gdb.cp/gdb2495.exp @@ -104,29 +104,29 @@ if {![runto_main]} { # behaviour; it should not. Test both on and off states. # Turn on unwind on signal behaviour. -gdb_test_no_output "set unwindonsignal on" +gdb_test_no_output "set unwind-on-signal on" # Check that it is turned on. -gdb_test "show unwindonsignal" \ +gdb_test "show unwind-on-signal" \ "signal is received while in a call dummy is on.*" \ "turn on unwind on signal" # Check to see if new behaviour interferes with # normal signal handling in inferior function calls. gdb_test "p exceptions.raise_signal(1)" \ - "To change this behavior use \"set unwindonsignal off\".*" \ - "check for unwindonsignal off message" + "To change this behavior use \"set unwind-on-signal off\".*" \ + "check for unwind-on-signal off message" # And reverse - turn off again. -gdb_test_no_output "set unwindonsignal off" +gdb_test_no_output "set unwind-on-signal off" # Check that it is actually turned off. -gdb_test "show unwindonsignal" \ +gdb_test "show unwind-on-signal" \ "signal is received while in a call dummy is off.*" \ "turn off unwind on signal" # Check to see if new behaviour interferes with # normal signal handling in inferior function calls. gdb_test "p exceptions.raise_signal(1)" \ - "To change this behavior use \"set unwindonsignal on\".*" \ - "check for unwindonsignal on message" + "To change this behavior use \"set unwind-on-signal on\".*" \ + "check for unwind-on-signal on message" diff --git a/gdb/testsuite/gdb.fortran/function-calls.exp b/gdb/testsuite/gdb.fortran/function-calls.exp index f9a1efc241f..c4d1f232576 100644 --- a/gdb/testsuite/gdb.fortran/function-calls.exp +++ b/gdb/testsuite/gdb.fortran/function-calls.exp @@ -44,7 +44,7 @@ if {![runto [gdb_get_line_number "post_init"]]} { } # Use inspired by gdb.base/callfuncs.exp. -gdb_test_no_output "set unwindonsignal on" +gdb_test_no_output "set unwind-on-signal on" # Baseline: function and subroutine call with no arguments. gdb_test "p no_arg()" " = .TRUE." diff --git a/gdb/testsuite/gdb.mi/mi-syn-frame.exp b/gdb/testsuite/gdb.mi/mi-syn-frame.exp index 5b3e60f4f34..f026746931d 100644 --- a/gdb/testsuite/gdb.mi/mi-syn-frame.exp +++ b/gdb/testsuite/gdb.mi/mi-syn-frame.exp @@ -97,7 +97,7 @@ mi_gdb_test "409-stack-list-frames 0 0" \ # mi_gdb_test "410-data-evaluate-expression bar()" \ - ".*410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\".\\\\nEvaluation of the expression containing the function\\\\n\\(bar\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" \ + ".*410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwind-on-signal on\\\\\".\\\\nEvaluation of the expression containing the function\\\\n\\(bar\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" \ "call inferior function which raises exception" mi_gdb_test "411-stack-list-frames" "411\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"bar\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\",arch=\"$any\"},frame=\{level=\"1\",addr=\"$hex\",func=\"\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\",arch=\"$any\"}.*\\\]" "backtrace from inferior function at exception" diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp index a101abbfe9b..157d56f7009 100644 --- a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-simple.exp @@ -174,7 +174,7 @@ proc_with_prefix run_bp_cond_segfaults { target_async target_non_stop } { "Error in testing condition for breakpoint ${bp_1_num}:" \ "The program being debugged was signaled while in a function called from GDB\\." \ "GDB remains in the frame where the signal was received\\." \ - "To change this behavior use \"set unwindonsignal on\"\\." \ + "To change this behavior use \"set unwind-on-signal on\"\\." \ "Evaluation of the expression containing the function" \ "\\(function_that_segfaults\\) will be abandoned\\." \ "When the function is done executing, GDB will silently stop\\."] diff --git a/gdb/testsuite/gdb.threads/thread-unwindonsignal.exp b/gdb/testsuite/gdb.threads/thread-unwindonsignal.exp index b3e3288ba69..636e6539bda 100644 --- a/gdb/testsuite/gdb.threads/thread-unwindonsignal.exp +++ b/gdb/testsuite/gdb.threads/thread-unwindonsignal.exp @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Test use of unwindonsignal when a hand function call that gets interrupted +# Test use of unwind-on-signal when a hand function call that gets interrupted # by a signal in another thread. set NR_THREADS 4 @@ -52,12 +52,12 @@ gdb_test "continue" \ # We want the main thread (hand_call_with_signal) and # thread 1 (sigabrt_handler) to both run. -# Do turn on unwindonsignal. +# Do turn on unwind-on-signal. # We want to test gdb handling of the current thread changing when # unwindonsignal is in effect. -gdb_test_no_output "set unwindonsignal on" \ +gdb_test_no_output "set unwind-on-signal on" \ "setting unwindonsignal" -gdb_test "show unwindonsignal" \ +gdb_test "show unwind-on-signal" \ "Unwinding of stack .* is on." \ "showing unwindonsignal"