From patchwork Tue May 30 20:46:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70338 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 1D23D3854148 for ; Tue, 30 May 2023 20:47:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D23D3854148 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479675; bh=oFv8uJ7ag5VlzsKVFl9NhboDc4Rhda55mhuQd5ZZwh8=; 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=JnarusCas3Lue/EVrldS1FSJ5JTG1oXeXUlypnEr1D2NxSbkoibBkOq61lXn1LDJ0 Zfgyfnsd8jjE0PzNgD/cauDHoITdLFCmRL9woMf5BaDDWNFM7NV9JG153tv6NvFJZx B2PcDtBQMS8K3hnWKZ4WlFWY9W+j9XNq6dCAUnJk= 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 B2392385696E for ; Tue, 30 May 2023 20:47:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2392385696E Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-m2YnXX24PgOoJ2Jq_8eINQ-1; Tue, 30 May 2023 16:47:01 -0400 X-MC-Unique: m2YnXX24PgOoJ2Jq_8eINQ-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f612a1b0fdso28702145e9.2 for ; Tue, 30 May 2023 13:47:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479619; x=1688071619; 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=oFv8uJ7ag5VlzsKVFl9NhboDc4Rhda55mhuQd5ZZwh8=; b=dcdquXWNn1GclOxfjxHYDofjMEGbAH2B1gQsHbGX0b0kvquupKxxLD4B1txLAcuh1y C4sWX1FCAHpp7AugEwdcf9fvzqISGlPU6ZKEvq0WOBptRI4mmGPf/rLhMppQxMVP+yz4 g19c7BA62QCdpilKQ4viQevXWgSjF1k8mlJFjS0lNgEE9l5RDyoe0H8cbPTfZi3bpkbc UhgG1yjVK8BkOb9qxZXBBU6YQNcRErrInqDRt38IKPai/A86KWXhc+NfGrOuWtznHDL7 KX5pPnslNZ3qI6m6E02nd1BZoJHWjbsb8e8OS56fbiksQ7zB7a11a3nFEukEx4sjbhkx duVw== X-Gm-Message-State: AC+VfDxHfGhVsAkfNe0wThTA3GemM8aL1x5hsq4SumA08zNaKNHsYfSc NRggOvGCY1cjXd7g2eY4Eo8EKdZQ2cWvEr+U2am4cu4Mm0y2TrIMWtF0mtpZKO2Xw/diWX2lchw +zwIsCoOJf/vuLTA6iePqZRFMvV8iVIbet0WE/SEWQsEV1TJAA46N3o3ruK+UUy2T/r1D1XBhw2 WWJY1Llw== X-Received: by 2002:a05:600c:ad7:b0:3f5:ce4:6c3f with SMTP id c23-20020a05600c0ad700b003f50ce46c3fmr3666310wmr.7.1685479619685; Tue, 30 May 2023 13:46:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7zfIb2vDptqCrkUNQpGMuPK7KyZdK4cLEIjnbXGTx+t3qAKlDm1nBnckJU+/pqhxh3+OX0zQ== X-Received: by 2002:a05:600c:ad7:b0:3f5:ce4:6c3f with SMTP id c23-20020a05600c0ad700b003f50ce46c3fmr3666294wmr.7.1685479619303; Tue, 30 May 2023 13:46:59 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id u5-20020a05600c00c500b003f0ad8d1c69sm21888446wmm.25.2023.05.30.13.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:46:59 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 1/9] gdb: create_breakpoint: assert for a valid thread-id Date: Tue, 30 May 2023 21:46:45 +0100 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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" Add an assert into create_breakpoint (breakpoint.c) that the thread argument is a valid thread-id; either a value greater than zero, or -1 to indicate any thread. The thread is ignored if parse_extra is true though, so take that into account too. There should be no user visible changes after this commit. --- gdb/breakpoint.c | 4 ++++ gdb/breakpoint.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index a94277f0c6c..fe92893863d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9000,6 +9000,10 @@ create_breakpoint (struct gdbarch *gdbarch, gdb_assert (ops != NULL); + /* If PARSE_EXTRA is true then the thread-id will be parsed from + EXTRA_STRING, otherwise, ensure THREAD is valid. */ + gdb_assert (parse_extra || thread == -1 || thread > 0); + /* If extra_string isn't useful, set it to NULL. */ if (extra_string != NULL && *extra_string == '\0') extra_string = NULL; diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 709d27fa4db..331c908ecbc 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1589,6 +1589,12 @@ enum breakpoint_create_flags the FORCE_CONDITION parameter is ignored and the corresponding argument is parsed from EXTRA_STRING. + The THREAD should be a global thread number, the created breakpoint will + only apply for that thread. If the breakpoint should apply for all + threads then pass -1. However, if PARSE_EXTRA is non-zero then the + THREAD parameter is ignored and an optional thread number will be parsed + from EXTRA_STRING. + If INTERNAL is non-zero, the breakpoint number will be allocated from the internal breakpoint count. From patchwork Tue May 30 20:46:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70336 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 B9D5538560B9 for ; Tue, 30 May 2023 20:47:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9D5538560B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479653; bh=bYHV737hqhOm4T3sY9Q6vH3xEatxQzgfszxUynHXNtE=; 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=fnVDzSxYww4KlZ3c3BfPfxTXcK7NkLZGN4hSPZkTEp47g2gczDKWF20dKtfHEvYHw sUblC+uoL6P9FEPu27SYJEFTotxv9LNkkjC0LWEL6flkYt5UtsfNRrPbY7YCakVG5g 4THS5e5rxx7Q3a1D7H7uImXSeM/F5WalLZCHeOf8= 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 EBC113857707 for ; Tue, 30 May 2023 20:47:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBC113857707 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-gVXqT19GPDmYauH0x6Zmwg-1; Tue, 30 May 2023 16:47:05 -0400 X-MC-Unique: gVXqT19GPDmYauH0x6Zmwg-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f6f2f18ecbso17577485e9.0 for ; Tue, 30 May 2023 13:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479621; x=1688071621; 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=bYHV737hqhOm4T3sY9Q6vH3xEatxQzgfszxUynHXNtE=; b=XdqZ6BCr2p6pnN84K7Ao8uE+revRT1bR3BDUXLiB/sA3imJPiqE8fpreojNDq8afiQ 6obkUnq2/gl2/uXf1Q6t7go+jJj2x2GcD92bsoawB69+YL1uucJM9snizMgQcRPEAYXj LTvZVQZxR8nZjivgNKsg3Qq3ISR5TxxfZt2x2729BV6BtLrcqs0lgAgcvzUSEhVM9Tc5 hXAGHD/bc6dpqat0H+5uoZar4zS0UbL4Qgze/48hj19EiEd3jukXargV126AiwYVEpaB UYbvoZAtSklETGVhyBp9DvrvqftfREZeE7bW2K2eKLngRj2/fhtM6t9fUAy+9YNzF5wc R7sg== X-Gm-Message-State: AC+VfDyHTPJkwkXMxBsLxB0+dWHjbrqtFiGAdQuV4aCzD5hBgyaH/OBk 7AA2/CR4NnHCtKN3NCjZ3FWQEihRurE+KZbzICujfvmXPOmk/UgJODX717xdEVHBQ0D6vJD7jfZ aRyMuqLOREgYNJLo6D0VlEHJAPyeBU+69gVSJAjXUH00IQI2hko8ySSxmIjrZMFcP2/jnMsxwHj furLQmjA== X-Received: by 2002:a05:600c:2294:b0:3f1:8c5f:dfc5 with SMTP id 20-20020a05600c229400b003f18c5fdfc5mr2509519wmf.39.1685479621148; Tue, 30 May 2023 13:47:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6HJMTpaYG6K8VuhMXiGXm60LTtTlVef0hyNE9hlT+r1jBiLCTl05I4CX+CMpZ/94bHSvYBVA== X-Received: by 2002:a05:600c:2294:b0:3f1:8c5f:dfc5 with SMTP id 20-20020a05600c229400b003f18c5fdfc5mr2509508wmf.39.1685479620803; Tue, 30 May 2023 13:47:00 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id 10-20020a05600c228a00b003f42461ac75sm21868947wmf.12.2023.05.30.13.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:00 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 2/9] gdb: create_breakpoint: asserts relating to extra_string/parse_extra Date: Tue, 30 May 2023 21:46:46 +0100 Message-Id: <889e80fd01c97a437c29f55c5185ee36fa30c844.1685479504.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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The goal of this commit is to better define the API for create_breakpoint especially around the use of extra_string and parse_extra. This will be useful in the next commit when I plan to make some changes to create_breakpoint. This commit makes one possibly breaking change: until this commit it was possible to create thread-specific dprintf breakpoint like this: (gdb) dprintf call_me, thread 1 "%s", "hello" Dprintf 2 at 0x401152: file /tmp/hello.c, line 8. (gdb) info breakpoints Num Type Disp Enb Address What 2 dprintf keep y 0x0000000000401152 in call_me at /tmp/hello.c:8 thread 1 stop only in thread 1 printf "%s", "hello" (gdb) this feature of dprintf was not documented, was not tested, and is slightly different in syntax to how we create thread specific breakpoints and/or watchpoints -- the thread condition appears after the first ','. I believe that this worked at all was simply by luck. We happen to pass the parse_extra flag as true from dprintf_command to create_breakpoint. So in this commit I made the choice change this. We now pass parse_extra as false from dprintf_command to create_breakpoint. With this done it is assumed that the only thing in the extra_string is the dprintf format and arguments. Beyond this change I've updated the comment on create_breakpoint in breakpoint.h, and I've then added some asserts into create_breakpoint as well as moving around some of the error handling. - We now assert on the incoming argument values, - I've moved an error check to sit after the call to find_condition_and_thread_for_sals, this ensures the extra_string was parsed correctly, In dprintf_command: - We now throw an error if there is no format string after the dprintf location. This error was already being thrown, but was being caught later in the process. With this change we catch the missing string earlier, - And, as mentioned earlier, we pass parse_extra as false when calling create_breakpoint, In create_tracepoint_from_upload: - We now throw an error if the parsed location doesn't completely consume the addr_str variable. This error has now effectively moved out of create_breakpoint. --- gdb/breakpoint.c | 42 +++++++++++++++++++++++++++++------------- gdb/breakpoint.h | 38 ++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index fe92893863d..fcd2f472bf7 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9008,6 +9008,17 @@ create_breakpoint (struct gdbarch *gdbarch, if (extra_string != NULL && *extra_string == '\0') extra_string = NULL; + /* A bp_dprintf must always have an accompanying EXTRA_STRING containing + the dprintf format and arguments -- PARSE_EXTRA should always be false + in this case. + + For all other breakpoint types, EXTRA_STRING should be nullptr unless + PARSE_EXTRA is true. */ + gdb_assert ((type_wanted == bp_dprintf + && extra_string != nullptr && !parse_extra) + || (type_wanted != bp_dprintf + && (extra_string == nullptr || parse_extra))); + try { ops->create_sals_from_location_spec (locspec, &canonical); @@ -9071,6 +9082,8 @@ create_breakpoint (struct gdbarch *gdbarch, if (parse_extra) { + gdb_assert (type_wanted != bp_dprintf); + gdb::unique_xmalloc_ptr rest; gdb::unique_xmalloc_ptr cond; @@ -9078,15 +9091,15 @@ create_breakpoint (struct gdbarch *gdbarch, find_condition_and_thread_for_sals (lsal.sals, extra_string, &cond, &thread, &task, &rest); + + if (rest.get () != nullptr && *(rest.get ()) != '\0') + error (_("Garbage '%s' at end of command"), rest.get ()); + cond_string_copy = std::move (cond); extra_string_copy = std::move (rest); } else { - if (type_wanted != bp_dprintf - && extra_string != NULL && *extra_string != '\0') - error (_("Garbage '%s' at end of location"), extra_string); - /* Check the validity of the condition. We should error out if the condition is invalid at all of the locations and if it is not forced. In the PARSE_EXTRA case above, this @@ -9295,20 +9308,17 @@ dprintf_command (const char *arg, int from_tty) /* If non-NULL, ARG should have been advanced past the location; the next character must be ','. */ - if (arg != NULL) + if (arg == nullptr || arg[0] != ',' || arg[1] == '\0') + error (_("Format string required")); + else { - if (arg[0] != ',' || arg[1] == '\0') - error (_("Format string required")); - else - { - /* Skip the comma. */ - ++arg; - } + /* Skip the comma. */ + ++arg; } create_breakpoint (get_current_arch (), locspec.get (), - NULL, 0, arg, false, 1 /* parse arg */, + NULL, -1, arg, false, 0 /* parse arg */, 0, bp_dprintf, 0 /* Ignore count */, pending_break_support, @@ -13874,6 +13884,12 @@ create_tracepoint_from_upload (struct uploaded_tp *utp) location_spec_up locspec = string_to_location_spec (&addr_str, current_language); + + + gdb_assert (addr_str != nullptr); + if (*addr_str != '\0') + error (_("Garbage '%s' at end of location"), addr_str); + if (!create_breakpoint (get_current_arch (), locspec.get (), utp->cond_string.get (), -1, addr_str, diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 331c908ecbc..8abb46b54ad 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1574,26 +1574,36 @@ enum breakpoint_create_flags functions for setting a breakpoint at LOCSPEC. This function has two major modes of operations, selected by the - PARSE_EXTRA parameter. + PARSE_EXTRA and WANTED_TYPE parameters. - If PARSE_EXTRA is zero, LOCSPEC is just the breakpoint's location - spec, with condition, thread, and extra string specified by the - COND_STRING, THREAD, and EXTRA_STRING parameters. + When WANTED_TYPE is not bp_dprintf the following rules apply: - If PARSE_EXTRA is non-zero, this function will attempt to extract - the condition, thread, and extra string from EXTRA_STRING, ignoring - the similarly named parameters. + If PARSE_EXTRA is zero, LOCSPEC is just the breakpoint's location + spec, with condition, thread, and extra string specified by the + COND_STRING, THREAD, and EXTRA_STRING parameters. - If FORCE_CONDITION is true, the condition is accepted even when it is - invalid at all of the locations. However, if PARSE_EXTRA is non-zero, - the FORCE_CONDITION parameter is ignored and the corresponding argument - is parsed from EXTRA_STRING. + If PARSE_EXTRA is non-zero, this function will attempt to extract the + condition, thread, and extra string from EXTRA_STRING, ignoring the + similarly named parameters. + + When WANTED_TYPE is bp_dprintf the following rules apply: + + PARSE_EXTRA must always be zero, LOCSPEC is just the breakpoint's + location spec, with condition, thread, and extra string (which + contains the dprintf format and arguments) specified by the + COND_STRING, THREAD, and EXTRA_STRING parameters. + + If FORCE_CONDITION is true, the condition (in COND_STRING) is accepted + even when it is invalid at all of the locations. However, if + PARSE_EXTRA is non-zero and WANTED_TYPE is not bp_dprintf, the + FORCE_CONDITION parameter is ignored and the corresponding argument is + parsed from EXTRA_STRING. The THREAD should be a global thread number, the created breakpoint will only apply for that thread. If the breakpoint should apply for all - threads then pass -1. However, if PARSE_EXTRA is non-zero then the - THREAD parameter is ignored and an optional thread number will be parsed - from EXTRA_STRING. + threads then pass -1. However, if PARSE_EXTRA is non-zero and + WANTED_TYPE is not bp_dprintf, then the THREAD parameter is ignored and + an optional thread number will be parsed from EXTRA_STRING. If INTERNAL is non-zero, the breakpoint number will be allocated from the internal breakpoint count. From patchwork Tue May 30 20:46:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70339 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 703D1385559B for ; Tue, 30 May 2023 20:47:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 703D1385559B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479679; bh=4slbOZ6mfwYI7cdKwWKvNzlRHVIfCRzDnMa2zPFuQrI=; 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=idfyP5IxdQEzCmwTnSVq1qxwCRh+FblCXR4E1milj3htqO9vfdqhj0HxaUVAegwfD XiPI/T6iAPs05Biq6pFWThZZDMfVZ5NZwObBUMA/PaWcyE6SlI2Uzv80dTZFK6n8d6 Jns/2GKdqkCGSgNeY3FtsmR78LmuhPjpHSOL3wDw= 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 F319C3858410 for ; Tue, 30 May 2023 20:47:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F319C3858410 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-lZaQFA5ZOdqUPqyemztjPg-1; Tue, 30 May 2023 16:47:04 -0400 X-MC-Unique: lZaQFA5ZOdqUPqyemztjPg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f5df65f9f4so19146135e9.2 for ; Tue, 30 May 2023 13:47:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479622; x=1688071622; 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=4slbOZ6mfwYI7cdKwWKvNzlRHVIfCRzDnMa2zPFuQrI=; b=VEAXHmKSGiIGsHBS9baJnzij4NSnoYZ7J+OKMBqRZ8Xk297FB59RJiMRq/RSiqG0ic gyp7C+86ictxb3+4/E3Qbt3otdc46Ojrf4ep7Ma+rDcYTSx/An4MRDDOmJw4J6s7L5G3 KL3jDZTMVIMTiEq1SwPprMva9+tlFbmkDj/fA+7kcL9mUszCUHvp1NRenb/ygkSInXJu 1HLav0jj4RfJmTfkTyWBhX6AXrQ2zJXOVl9h2Tf1/+Z8unvBVpzWELdyF8OxvcPzy3l+ HGrGS0QZWtdPQAeYuYVt8JotNX08ox1Mu/Ex8eiWQCu8o3A7B1lv3apB55AlSbGrAJYh EK8w== X-Gm-Message-State: AC+VfDwe71/wlfbixJ8gGHULVqLmIa3Br3NVjZUApyw1YKdX0N1m4WK9 6io9iWQClTdJWNq6YDu+nCaltGDlyjA7jMHsnGUgCtMhIvwk3Iyh77OuS2Rdx9s0W5bKudWpY/n PtxQJYr4wkzgfUA77Mz1y1JNQt2aaXFOTAx4eqcq0ihA8POGUx+6JFd0D5/UCXyt0bJL7NfOOjG sted1eqg== X-Received: by 2002:a5d:4a12:0:b0:30a:de1b:93e5 with SMTP id m18-20020a5d4a12000000b0030ade1b93e5mr2612084wrq.52.1685479622777; Tue, 30 May 2023 13:47:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6fdUA8ydT6uBtZutLSG3k/NB1tfDeiYvbFB8cdnIQHoNBkSsYiwtf1rCCKPlSIyrhvWLQzPg== X-Received: by 2002:a5d:4a12:0:b0:30a:de1b:93e5 with SMTP id m18-20020a5d4a12000000b0030ade1b93e5mr2612073wrq.52.1685479622428; Tue, 30 May 2023 13:47:02 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id a27-20020a5d457b000000b002f103ca90cdsm4318085wrc.101.2023.05.30.13.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:02 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 3/9] gdb: change 'if' to gdb_assert in update_dprintf_command_list Date: Tue, 30 May 2023 21:46:47 +0100 Message-Id: <09152d06a4099a28ec03bf4e3167bdf6287da1ef.1685479504.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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 in update_dprintf_command_list that we handle the case where the bp_dprintf style breakpoint doesn't have a format and args string. However, I don't believe such a situation is possible. The obvious approach certainly already catches this case: (gdb) dprintf main Format string required If it is possible to create a dprintf breakpoint without a format and args string then I think we should be catching this case and handling it at creation time, rather than having GDB just ignore the situation later on. And so, I propose that we change the 'if' that ignores the case where the format/args string is empty, and instead assert that we do always have a format/args string. The original code, that handled an empty format/args string has existed since commit e7e0cddfb0d4, which is when dprintf support was added to GDB. If I'm correct and this situation can't ever happen then there should be no user visible changes after this commit. --- gdb/breakpoint.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index fcd2f472bf7..2cadc8c0295 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8356,8 +8356,9 @@ update_dprintf_command_list (struct breakpoint *b) const char *dprintf_args = b->extra_string.get (); gdb::unique_xmalloc_ptr printf_line = nullptr; - if (!dprintf_args) - return; + /* Trying to create a dprintf breakpoint without a format and args + string should be detected at creation time. */ + gdb_assert (dprintf_args != nullptr); dprintf_args = skip_spaces (dprintf_args); From patchwork Tue May 30 20:46:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70340 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 303C5384FDE2 for ; Tue, 30 May 2023 20:48:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 303C5384FDE2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479685; bh=+bs40666ydHhaT0Mz1M2KwV8r3QzFN4GYbUN4/QbHOw=; 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=ZG8DApU2nmRvbm3UuE9ldvVxBXVNW3FKSNaJe0BSlQfsqykvO2n8ukUE8MpY7otch fKSjWIrO76bDsLpnbYxX9M1C5s8ikihZKdvGcPuZTT2G5W68bn+l/v1qO98HBkRUfR k27Vvxrez4MEmwwM1yPxsh6FgL8An421nDr1TGw0= 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 716CB385840C for ; Tue, 30 May 2023 20:47:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 716CB385840C Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-5Fv3OVNkPAWStVMNPiynPQ-1; Tue, 30 May 2023 16:47:05 -0400 X-MC-Unique: 5Fv3OVNkPAWStVMNPiynPQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f5ec8aac77so31070625e9.3 for ; Tue, 30 May 2023 13:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479624; x=1688071624; 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=+bs40666ydHhaT0Mz1M2KwV8r3QzFN4GYbUN4/QbHOw=; b=DkMCQiu7ww5rUd73rQA1yqKdi7yCzKNX3g0oyaKfdy0XNwagmucv7sXxHS6fPvnuOe NLOvz7gelMiDhP/zv5v0pOnwNHhKJGtTu7rUYdzQvnFEecs1IiPvKnYra9DYMUi9ZIzI uCilPx3obN4Q5W2xRSiW+etlJan0eDGxzRP20XDLa907MV5nkHa8kAV35jh5f9U+X7Hm WZczj++vuTTf+EuYZ5BlyZTjXhHRpZxzNssQMd67V+YRLoKsSHudEQc0yn+PqTucg78B o1E/iBb+h4Qp1mz2BSXU76JzzS6NSHbbaAOvzut8NP6tCceAIm0+fhAolsRNf8y0SWXl rB7w== X-Gm-Message-State: AC+VfDx+dtrdWPY4/TOq/ks3vmUd1pSreZBTYEDhoiV1yT7TDbl8Mje9 lA+S+LRPvps3iQhzNTd1HiNHCIkAw31oVhYNMNNUeIa5JK1y3GxXyZJu7m3BDguckoNKioOGVDS gDAVgggiIQtx0hCB3QeJPjeXUtWVMa8pgfyiOmz8ReLCrMu8YJ62ddZWTsqY9DjBWREqL47VZJ4 KocVfOuA== X-Received: by 2002:a7b:cd15:0:b0:3f4:e7c2:607d with SMTP id f21-20020a7bcd15000000b003f4e7c2607dmr2515829wmj.13.1685479624270; Tue, 30 May 2023 13:47:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5e2JYWnvqw81O34Rcxpt2vVZBQTp9HU0ulMllwoQ0OYEpFtv0PqbuUizvhXDRvu8mtJCMqWQ== X-Received: by 2002:a7b:cd15:0:b0:3f4:e7c2:607d with SMTP id f21-20020a7bcd15000000b003f4e7c2607dmr2515822wmj.13.1685479623991; Tue, 30 May 2023 13:47:03 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id a10-20020a05600c224a00b003f4247fbb5fsm21860297wmm.10.2023.05.30.13.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:03 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 4/9] gdb: build dprintf commands just once in code_breakpoint constructor Date: Tue, 30 May 2023 21:46:48 +0100 Message-Id: <093c41c52d00f086f5adc9b87826d1d89bdca2a1.1685479504.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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 in code_breakpoint::code_breakpoint that we are calling update_dprintf_command_list once for each breakpoint location, when we really only need to call this once per breakpoint -- the data updated by this function, the breakpoint command list -- is per breakpoint, not per breakpoint location. Calling update_dprintf_command_list multiple times is just wasted effort, there's no per location error checking, we don't even pass the current location to the function. This commit moves the update_dprintf_command_list call outside of the per-location loop. I have also changes the 'if' that handles the case where the extra_string (which holds the format/args) is empty. I don't believe that this situation can ever arise -- and if it does we should be catching it earlier and throwing an error at that point. There should be no user visible changes after this commit. --- gdb/breakpoint.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 2cadc8c0295..4eb40c01274 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8517,19 +8517,17 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_, /* Do not set breakpoint locations conditions yet. As locations are inserted, they get sorted based on their addresses. Let the list stabilize to have reliable location numbers. */ + } - /* Dynamic printf requires and uses additional arguments on the - command line, otherwise it's an error. */ - if (type == bp_dprintf) - { - if (extra_string != nullptr) - update_dprintf_command_list (this); - else - error (_("Format string required")); - } - else if (extra_string != nullptr) - error (_("Garbage '%s' at end of command"), extra_string.get ()); + /* Dynamic printf requires and uses additional arguments on the + command line, otherwise it's an error. */ + if (type == bp_dprintf) + { + gdb_assert (extra_string != nullptr); + update_dprintf_command_list (this); } + else if (extra_string != nullptr) + error (_("Garbage '%s' at end of command"), extra_string.get ()); /* The order of the locations is now stable. Set the location condition using the location's number. */ From patchwork Tue May 30 20:46:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70343 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 4648338532D4 for ; Tue, 30 May 2023 20:48:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4648338532D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479722; bh=qOXwyOpx9EQLaWDH4Im6Yn1ddt1i2AxXMYnGQ0f4PsA=; 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=tywwkvt4oIwms8F0ej/QV0cfisVC9SwyjvG963VM1oJkDblVH7YfgngZtlW4PxYvg /uq5U23kg9JbDGe91zjD5jIWvwLq46rK+UO5HvYWv62fulLI7X7IDGLuibvrbyrKR7 H7oGvoNpf2xnw/aPJNOTQ+moyyv/Eo/0kNn2Q7xw= 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 C1505385770F for ; Tue, 30 May 2023 20:47:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1505385770F Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-509-SfJ2yHSXPqqVkww_A0-C7w-1; Tue, 30 May 2023 16:47:07 -0400 X-MC-Unique: SfJ2yHSXPqqVkww_A0-C7w-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f60536450eso28762145e9.1 for ; Tue, 30 May 2023 13:47:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479626; x=1688071626; 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=qOXwyOpx9EQLaWDH4Im6Yn1ddt1i2AxXMYnGQ0f4PsA=; b=ji7lStn8mv+gb1rXAsXtph34rOV6Jl30VsRBKAKZMu0MUyeCgvQLmjz4k88ISLji2F q3s+tYxy4I11xfhy11cajhvxB0dQtnJrMy3mSlYjdlVaiMZwJrCs3NHVnlIsZAXCCIxn Ii0cNPQhQfXwNqyXyHSJ3c3NS5Ygnc+xb7uI/DboWHIVJDsQPo3o0i0dFBRr61u1BRiQ Hg/OQ6iB0rl8JmY507eb4sWy7HSESMuXjFGPtBoJGUHZhrdaFQ7JRf75nFCQDWiCjTfw DGWoEjRYMed/Bu70iVJuVOPyoVU+rc/McdxJKSBt1ArU5cGnGwvA/l5A+dXD2V/LSaLT 3Nog== X-Gm-Message-State: AC+VfDwowj13eSaSeDiMGUEDm5TU+SE6ARUjyOHyl4kWGqV2e60PB+op fwv+WOKZV5HHMbk+fcA9Lw8fIOU16yHtDzUVEv3m3V692Jma+/DGggNN6I+nfj9546LQk9XHSTP cwZ7w4CBfNrcR2z3K/aOAu2GuwTUzceyqDO3EJkZM+lP9FWcxEID98OTi7eFpdHhOXkK33Dw+vU kPyZVoYw== X-Received: by 2002:a7b:cc11:0:b0:3f6:128:36a5 with SMTP id f17-20020a7bcc11000000b003f6012836a5mr3352441wmh.10.1685479625688; Tue, 30 May 2023 13:47:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tTJD5jcB6JeG1Dfb8bcCvqsPHlnb+lu5EWUUcfVC0oCSbGPawnuq+2reGqDTcOvZo4YmZoA== X-Received: by 2002:a7b:cc11:0:b0:3f6:128:36a5 with SMTP id f17-20020a7bcc11000000b003f6012836a5mr3352431wmh.10.1685479625371; Tue, 30 May 2023 13:47:05 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id u15-20020a05600c210f00b003f42d8dd7d1sm22136198wml.7.2023.05.30.13.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:05 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 5/9] gdb: don't display inferior list for pending breakpoints Date: Tue, 30 May 2023 21:46:49 +0100 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 in the 'info breakpoints' output, GDB sometimes prints the inferior list for pending breakpoints, this doesn't seem right to me. A pending breakpoint has no locations (at least, as far as we display things in the 'info breakpoints' output), so including an inferior list seems odd. Here's what I see right now: (gdb) info breakpoint 5 Num Type Disp Enb Address What 5 breakpoint keep y foo inf 1 (gdb) It's the 'inf 1' at the end of the line that I'm objecting too. To trigger this behaviour we need to be in a multi-inferior debug session. The breakpoint must have been non-pending at some point in the past, and so have a location assigned to it. The breakpoint becomes pending again as a result of a shared library being unloaded. When this happens the location itself is marked pending (via bp_location::shlib_disabled). In print_one_breakpoint_location, in order to print the inferior list we check that the breakpoint has a location, and that we have multiple inferiors, but we don't check if the location itself is pending. This commit adds that check, which means the output is now: (gdb) info breakpoint 5 Num Type Disp Enb Address What 5 breakpoint keep y foo (gdb) Which I think makes more sense. --- gdb/breakpoint.c | 2 +- gdb/testsuite/gdb.multi/pending-bp-lib.c | 22 +++++ gdb/testsuite/gdb.multi/pending-bp.c | 66 +++++++++++++ gdb/testsuite/gdb.multi/pending-bp.exp | 115 +++++++++++++++++++++++ 4 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.multi/pending-bp-lib.c create mode 100644 gdb/testsuite/gdb.multi/pending-bp.c create mode 100644 gdb/testsuite/gdb.multi/pending-bp.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 4eb40c01274..6a76bfbefe8 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6452,7 +6452,7 @@ print_one_breakpoint_location (struct breakpoint *b, } } - if (loc != NULL && !header_of_multiple) + if (loc != NULL && !header_of_multiple && !loc->shlib_disabled) { std::vector inf_nums; int mi_only = 1; diff --git a/gdb/testsuite/gdb.multi/pending-bp-lib.c b/gdb/testsuite/gdb.multi/pending-bp-lib.c new file mode 100644 index 00000000000..15d1b9833dd --- /dev/null +++ b/gdb/testsuite/gdb.multi/pending-bp-lib.c @@ -0,0 +1,22 @@ +/* Copyright 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 . */ + +int global_var = 0; + +void +foo (int arg) +{ + global_var = arg; +} diff --git a/gdb/testsuite/gdb.multi/pending-bp.c b/gdb/testsuite/gdb.multi/pending-bp.c new file mode 100644 index 00000000000..ca8a3c20b72 --- /dev/null +++ b/gdb/testsuite/gdb.multi/pending-bp.c @@ -0,0 +1,66 @@ +/* Copyright 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 . */ + +#include +#include + +void +breakpt () +{ + /* Nothing. */ +} + +volatile int global_counter = 0; + +volatile int call_count = 1; + +int +main (void) +{ + void *handle; + void (*func)(int); + + /* Some filler work so that we don't initially stop on the breakpt call + below. */ + ++global_counter; + + breakpt (); /* Break before open. */ + + /* Now load the shared library. */ + handle = dlopen (SHLIB_NAME, RTLD_LAZY); + if (handle == NULL) + abort (); + + breakpt (); /* Break after open. */ + + /* Find the function symbol. */ + func = (void (*)(int)) dlsym (handle, "foo"); + + for (; call_count > 0; --call_count) + { + /* Call the library function. */ + func (1); + } + + breakpt (); /* Break before close. */ + + /* Unload the shared library. */ + if (dlclose (handle) != 0) + abort (); + + breakpt (); /* Break after close. */ + + return 0; +} diff --git a/gdb/testsuite/gdb.multi/pending-bp.exp b/gdb/testsuite/gdb.multi/pending-bp.exp new file mode 100644 index 00000000000..4a65f79cfc4 --- /dev/null +++ b/gdb/testsuite/gdb.multi/pending-bp.exp @@ -0,0 +1,115 @@ +# Copyright 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 . + +# Tests related to pending breakpoints in a multi-inferior environment. + +require allow_shlib_tests !use_gdb_stub + +standard_testfile + +set libname $testfile-lib +set srcfile_lib $srcdir/$subdir/$libname.c +set binfile_lib [standard_output_file $libname.so] + +if { [gdb_compile_shlib $srcfile_lib $binfile_lib {}] != "" } { + untested "failed to compile shared library 1" + return -1 +} + +set binfile_lib_target [gdb_download_shlib $binfile_lib] + +if { [build_executable "failed to prepare" $testfile $srcfile \ + [list debug \ + additional_flags=-DSHLIB_NAME=\"$binfile_lib_target\" \ + shlib_load pthreads]] } { + return -1 +} + +# Used to override delete_breakpoints when we don't want breakpoints +# deleted. +proc do_nothing {} {} + +# Start two inferiors, both running the same test binary. The arguments +# INF_1_STOP and INF_2_STOP are source code patterns that are passed to +# gdb_get_line_number to figure out where each inferior should be stopped. +# +# This proc does a clean_restart and leaves inferior 2 selected. Also the +# 'breakpoint pending' flag is enabled, so pending breakpoints can be created +# without GDB prompting the user. +proc do_test_setup { inf_1_stop inf_2_stop } { + clean_restart ${::binfile} + + gdb_locate_shlib $::binfile_lib + + if ![runto_main] { + return false + } + + gdb_breakpoint [gdb_get_line_number ${inf_1_stop}] temporary + gdb_continue_to_breakpoint "move inferior 1 into position" + + gdb_test "add-inferior -exec ${::binfile}" \ + "Added inferior 2.*" "add inferior 2" + gdb_test "inferior 2" "Switching to inferior 2 .*" "switch to inferior 2" + + with_override delete_breakpoints do_nothing { + if {![runto_main]} { + return false + } + } + + gdb_breakpoint [gdb_get_line_number ${inf_2_stop}] temporary + gdb_continue_to_breakpoint "move inferior 2 into position" + + gdb_test_no_output "set breakpoint pending on" + + return true +} + +# Check that when a breakpoint is in the pending state, but that breakpoint +# does have some locations (those locations themselves are pending), GDB +# doesn't display the inferior list in the 'info breakpoints' output. +proc_with_prefix test_no_inf_display {} { + do_test_setup "Break before close" "Break before open" + + # Create a breakpoint on 'foo'. This will find a location in inferior 1, + # but will not find a location in inferior 2 -- the shared library is not + # yet loaded in that inferior. + gdb_breakpoint "foo" + set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \ + "get foo breakpoint number"] + + # Check the 'info breakpoints' output. Notice we display the inferior + # list at the end of the breakpoint line. + gdb_test "info breakpoint $bpnum" \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex\\s+\]*>\\s+inf 1" \ + "check info breakpoints while breakpoint is inserted" + + # Ensure we are in inferior 1, move the inferior forward until the shared + # library has been unloaded. The breakpoint on 'foo' will return to the + # pending state. + gdb_test "inferior 1" "Switching to inferior 1 .*" + gdb_breakpoint [gdb_get_line_number "Break after close"] temporary + gdb_continue_to_breakpoint "after close library" + + # Check the 'info breakpoints' output, check there is no 'inf 1' at the + # end of the breakpoint line. + gdb_test "info breakpoint $bpnum" \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "check info breakpoints while breakpoint is pending" +} + +# Run all the tests. +test_no_inf_display From patchwork Tue May 30 20:46:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70345 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 9D75F3856976 for ; Tue, 30 May 2023 20:49:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D75F3856976 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479781; bh=Ady9o2l35YAad2gzkclIBf9IDPAuUsOVxA3IhKPQ4oo=; 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=JJKXtKf2OCCp3jKkbE+Tjn8TKaOkD+uONySWsmnH5dGorzwVAa01dbSrC8ohAQ/kp aWOEM4rQXykXVN2Yhb3WQT3KkESKNpdxHtfNTKP1U2YSyi8qGV6JdUkceAr/yHUSqK AlrFj5zR7NsECF4GdY+1cu/aEeYF0K95QUofo3YU= 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 40E23385660E for ; Tue, 30 May 2023 20:47:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40E23385660E Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-BAgC-DVgNoyppy8xWXjMTA-1; Tue, 30 May 2023 16:47:12 -0400 X-MC-Unique: BAgC-DVgNoyppy8xWXjMTA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f6ffc456e7so12428375e9.2 for ; Tue, 30 May 2023 13:47:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479628; x=1688071628; 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=Ady9o2l35YAad2gzkclIBf9IDPAuUsOVxA3IhKPQ4oo=; b=lxXhHDsDReVH+EvAjLOF6/6C+IhndQwV4thnJ6eVQgBx2uFnvKmQkbmBY+Vp+opAaR ZRID69kTcq6MDdsV9PEbcxGFVez0A6/hBIiQILdmDmKRgzM0lqS3o+1UNtIr9fxNWw2D SfN902YO+DKrtXm24mJ5cgrxQJ1RSZiq6tE6v2roIbe+EjbbPqGpt/y+yEkMtYoLGixp LC+u5VwiF8tXBtIHFfnxqfLrkc2eD9BgnQo+iTaejL/8jEcyZeC3Mh847EZBxgtgjU4N rq/RQeNQyOAU1rr5+406vmQM/B9FEh48+IRE4cKcVPUbZddSUVpziffXopvtrRmNswv2 cRgQ== X-Gm-Message-State: AC+VfDwGYbq2DHuLQcyc1s+HVzz8dJYyGDIlu35yllpYGuZy9QTipHmd +Ry1HZ4z0VzcAnxCnZLA+lNlyLJ7yK6vJP6voxjA23tAuyOq3XySyNrq1RAGN/BVBreHz5OPTfo 5PQVq6uS/lFhBPa0e0ojNOMuRfdN8eNvsGz0VH9rDP5DuQ9r3LC3WknXTVcl1mJJ4+7S7tHVqUF 07MbzU9Q== X-Received: by 2002:a7b:c38f:0:b0:3f6:ad84:e603 with SMTP id s15-20020a7bc38f000000b003f6ad84e603mr2434309wmj.28.1685479627917; Tue, 30 May 2023 13:47:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55BrpIQNbwDLHEYdYidDtHW4QwTACt51hHVyjDFw8nQ8g27BZxZQYVA3hS2SCX9Y46iCyoVw== X-Received: by 2002:a7b:c38f:0:b0:3f6:ad84:e603 with SMTP id s15-20020a7bc38f000000b003f6ad84e603mr2434278wmj.28.1685479626961; Tue, 30 May 2023 13:47:06 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id p23-20020a05600c205700b003f42314832fsm18353988wmg.18.2023.05.30.13.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:06 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii Subject: [PATCHv3 6/9] gdb: parse pending breakpoint thread/task immediately Date: Tue, 30 May 2023 21:46:50 +0100 Message-Id: <18356f2ab1d11c9e4399c3b612fd8e696e00bc74.1685479504.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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The initial motivation for this commit was to allow thread or (in the future) inferior specific breakpoints to only be inserted within the appropriate inferior's program-space. The benefit of this is that inferiors for which the breakpoint does not apply will no longer need to stop, and then resume, for such breakpoints. This commit does not make this change, but is a refactor to allow this change in a later commit. The problem we currently have is that when a thread-specific breakpoint is created, the thread number is only parsed by calling find_condition_and_thread_for_sals. This function is only called for non-pending breakpoints, and requires that we know the locations at which the breakpoint will be placed (for expression checking in case the breakpoint is also conditional). A consequence of this is that by the time we figure out the breakpoint is thread-specific we have already looked up locations in all program spaces. This feels wasteful -- if we knew the thread-id earlier then we could reduce the work GDB does by only looking up locations within the program space for which the breakpoint applies. Another consequence of how find_condition_and_thread_for_sals is called is that pending breakpoints don't currently know they are thread-specific, nor even that they are conditional! Additionally, by delaying parsing the thread-id, pending breakpoints can be created for non-existent threads, this is different to how non-pending breakpoints are handled. In this commit the create_breakpoint function is updated so that the extra_string, which contains the thread/task/condition information, is parsed immediately, even for pending breakpoints. Obviously, the condition still can't be validated until the breakpoint becomes non-pending, but the thread/task information can be pulled from the extra-string, and can be validated early on, even for pending breakpoints. There are a couple of benefits to doing this: 1. Printing of breakpoints is more consistent now. Consider creating a conditional breakpoint before this commit: (gdb) set breakpoint pending on (gdb) break pendingfunc if (0) Function "pendingfunc" not defined. Breakpoint 1 (pendingfunc if (0)) pending. (gdb) break main if (0) Breakpoint 2 at 0x401198: file /tmp/hello.c, line 18. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y pendingfunc if (0) 2 breakpoint keep y 0x0000000000401198 in main at /tmp/hello.c:18 stop only if (0) (gdb) And after this commit: (gdb) set breakpoint pending on (gdb) break pendingfunc if (0) Function "pendingfunc" not defined. Breakpoint 1 (pendingfunc) pending. (gdb) break main if (0) Breakpoint 2 at 0x401198: file /home/andrew/tmp/hello.c, line 18. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y pendingfunc stop only if (0) 2 breakpoint keep y 0x0000000000401198 in main at /home/andrew/tmp/hello.c:18 stop only if (0) (gdb) Notice that the display of the condition is now the same for the pending and non-pending breakpoints. The same is true for the thread information in thread-specific breakpoints, this information is displayed on its own line now rather than being part of the 'What' field. 2. We can check that the thread exists as soon as the pending breakpoint exits. Currently there is a weird different between pending and non-pending breakpoints when creating a thread-specific breakpoint. A pending thread-specific breakpoint only checks its thread when it becomes non-pending, at which point the thread the breakpoint was intended for might have exited. Here's the behaviour before this commit: (gdb) set breakpoint pending on (gdb) break foo thread 2 Function "foo" not defined. Breakpoint 2 (foo thread 2) pending. (gdb) c Continuing. [Thread 0x7ffff7c56700 (LWP 2948835) exited] Error in re-setting breakpoint 2: Unknown thread 2. [Inferior 1 (process 2948832) exited normally] (gdb) Notice the 'Error in re-setting breakpoint 2: Unknown thread 2.' line, this was triggered when the thread tried to become non-pending, and GDB discovers that the thread no longer exists. Compare that to the behaviour after this commit: (gdb) set breakpoint pending on (gdb) break foo thread 2 Function "foo" not defined. Breakpoint 2 (foo) pending. (gdb) c Continuing. [Thread 0x7ffff7c56700 (LWP 2949243) exited] Thread-specific breakpoint 2 deleted - thread 2 no longer in the thread list. [Inferior 1 (process 2949240) exited normally] (gdb) Now the behaviour for pending breakpoints is identical to non-pending breakpoints, the thread specific breakpoint is removed as soon as the thread the breakpoint is associated with exits. As a result of this commit the breakpoints 'extra_string' field is now only used by bp_dprintf type breakpoints to hold the printf format and arguments. This string should always be empty for other breakpoint types. This allows me to clean up some code in print_breakpoint_location. In code_breakpoint::code_breakpoint I'm able to change an error case into an assert. This is because this error is now handled earlier in create_breakpoint. As a result we know that by this point, the extra_string will always be nullptr for anything other than a bp_dprintf style breakpoint. The find_condition_and_thread_for_sals function is now no longer needed, this was previously doing the delayed splitting of the extra string into thread, task, and condition, but this is now all done in create_breakpoint, so find_condition_and_thread_for_sals can be deleted, and the code that calls this in code_breakpoint::location_spec_to_sals can be removed. With this update this code would only ever be reached for bp_dprintf style breakpoints, and in these cases the extra_string should not contain anything other than format and args. The most interesting changes are all in create_breakpoint and in the new file break-cond-parse.c. We have a new block of code early on in create_breakpoint that is responsible for splitting the extra_string into its component parts by calling create_breakpoint_parse_arg_string a function in the new break-cond-parse.c file. This means that some of the later code can be simplified a little. The new break-cond-parse.c file implements the splitting up the extra_string and finding all the parts, as well as some self-tests for the new function. Finally, now we know all the details, these can be stored within the breakpoint object if we end up creating a deferred breakpoint. Additionally, if we are creating a deferred bp_dprintf we can parse the extra_string to build the printf command. Reviewed-By: Eli Zaretskii --- gdb/Makefile.in | 2 + gdb/NEWS | 4 + gdb/break-cond-parse.c | 403 ++++++++++++++++++ gdb/break-cond-parse.h | 47 ++ gdb/breakpoint.c | 330 ++++---------- gdb/testsuite/gdb.base/condbreak.exp | 20 +- gdb/testsuite/gdb.base/pending.exp | 23 +- gdb/testsuite/gdb.linespec/explicit.exp | 4 +- gdb/testsuite/gdb.mi/mi-dprintf-pending.exp | 3 +- .../gdb.threads/del-pending-thread-bp-lib.c | 22 + .../gdb.threads/del-pending-thread-bp.c | 85 ++++ .../gdb.threads/del-pending-thread-bp.exp | 108 +++++ 12 files changed, 793 insertions(+), 258 deletions(-) create mode 100644 gdb/break-cond-parse.c create mode 100644 gdb/break-cond-parse.h create mode 100644 gdb/testsuite/gdb.threads/del-pending-thread-bp-lib.c create mode 100644 gdb/testsuite/gdb.threads/del-pending-thread-bp.c create mode 100644 gdb/testsuite/gdb.threads/del-pending-thread-bp.exp diff --git a/gdb/Makefile.in b/gdb/Makefile.in index d909786792c..afa43b8e4de 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1025,6 +1025,7 @@ COMMON_SFILES = \ break-catch-sig.c \ break-catch-syscall.c \ break-catch-throw.c \ + break-cond-parse.c \ breakpoint.c \ bt-utils.c \ btrace.c \ @@ -1292,6 +1293,7 @@ HFILES_NO_SRCDIR = \ bfd-target.h \ bfin-tdep.h \ block.h \ + break-cond-parse.h \ breakpoint.h \ bsd-kvm.h \ bsd-uthread.h \ diff --git a/gdb/NEWS b/gdb/NEWS index d97e3c15a87..d50b01ffa4f 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -67,6 +67,10 @@ break foo thread 1 task 1 watch var thread 2 task 3 +* For breakpoints that are created in the 'pending' state, any + 'thread' or 'task' keywords are parsed at the time the breakpoint is + created, rather than at the time the breakpoint becomes non-pending. + * New commands maintenance print record-instruction [ N ] diff --git a/gdb/break-cond-parse.c b/gdb/break-cond-parse.c new file mode 100644 index 00000000000..e8da24d2643 --- /dev/null +++ b/gdb/break-cond-parse.c @@ -0,0 +1,403 @@ +/* Copyright (C) 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 "defs.h" +#include "gdbsupport/gdb_assert.h" +#include "gdbsupport/selftest.h" +#include "test-target.h" +#include "scoped-mock-context.h" +#include "break-cond-parse.h" +#include "tid-parse.h" +#include "ada-lang.h" + +/* When parsing tokens from a string, which direction are we parsing? + + Given the following string and pointer 'ptr': + + ABC DEF GHI JKL + ^ + ptr + + Parsing 'forward' will return the token 'GHI' and update 'ptr' to point + between GHI and JKL. Parsing 'backward' will return the token 'DEF' and + update 'ptr' to point between ABC and DEF. +*/ + +enum class parse_direction +{ + /* Parse the next token forwards. */ + forward, + + /* Parse the previous token backwards. */ + backward +}; + +struct token +{ + /* Create a new token. START points to the first character of the new + token, while END points at the last character of the new token. + + Neither START or END can be nullptr, and both START and END must point + into the same C style string (i.e. there should be no null character + between START and END). END must be equal to, or greater than START, + that is, it is not possible to create a zero length token. */ + + token (const char *start, const char *end) + : m_start (start), + m_end (end) + { + gdb_assert (m_end >= m_start); + gdb_assert (m_start + strlen (m_start) > m_end); + } + + /* Return a pointer to the first character of this token. */ + const char *start () const + { + return m_start; + } + + /* Return a pointer to the last character of this token. */ + const char *end () const + { + return m_end; + } + + /* Return the length of the token. */ + size_t length () const + { + return m_end - m_start + 1; + } + + /* Return true if this token matches STR. If this token is shorter than + STR then only a partial match is performed and true will be returned + if the token length sub-string matches. Otherwise, return false. */ + bool matches (const char *str) const + { + return strncmp (m_start, str, length ()) == 0; + } + +private: + /* The first character of this token. */ + const char *m_start; + + /* The last character of this token. */ + const char *m_end; +}; + +/* Find the next token in DIRECTION from *CURR. */ + +static token +find_next_token (const char **curr, parse_direction direction) +{ + const char *tok_start, *tok_end; + + if (direction == parse_direction::forward) + { + *curr = skip_spaces (*curr); + tok_start = *curr; + *curr = skip_to_space (*curr); + tok_end = *curr - 1; + } + else + { + gdb_assert (direction == parse_direction::backward); + + while (isspace (**curr)) + --(*curr); + + tok_end = *curr; + + while (!isspace (**curr)) + --(*curr); + + tok_start = (*curr) + 1; + } + + return token (tok_start, tok_end); +} + +/* See break-cond-parse.h. */ + +void +create_breakpoint_parse_arg_string + (const char *tok, gdb::unique_xmalloc_ptr *cond_string, + int *thread, int *task, gdb::unique_xmalloc_ptr *rest, bool *force) +{ + /* Set up the defaults. */ + cond_string->reset (); + rest->reset (); + *thread = -1; + *task = -1; + *force = false; + + if (tok == nullptr) + return; + + const char *cond_start = nullptr; + const char *cond_end = nullptr; + parse_direction direction = parse_direction::forward; + while (*tok != '\0') + { + /* Find the next token. If moving backward and this token starts at + the same location as the condition then we must have found the + other end of the condition string -- we're done. */ + token t = find_next_token (&tok, direction); + if (direction == parse_direction::backward && t.start () <= cond_start) + { + cond_end = t.end () + 1; + break; + } + + /* We only have a single flag option to check for. All the other + options take a value so require an additional token to be found. */ + if (t.length () > 0 && t.matches ("-force-condition")) + { + *force = true; + continue; + } + + /* Maybe the first token was the last token in the string. If this + is the case then we definitely can't try to extract a value + token. This also means that the token T is meaningless. Reset + TOK to point at the start of the unknown content and break out of + the loop. We'll record the unknown part of the string outside of + the scanning loop (below). */ + if (direction == parse_direction::forward && *tok == '\0') + { + tok = t.start (); + break; + } + + /* As before, find the next token and, if we are scanning backwards, + check that we have not reached the start of the condition string. */ + token v = find_next_token (&tok, direction); + if (direction == parse_direction::backward && v.start () <= cond_start) + { + /* Use token T here as that must also be part of the condition + string. */ + cond_end = t.end () + 1; + break; + } + + /* When moving backward we will first parse the value token then the + keyword token, so swap them now. */ + if (direction == parse_direction::backward) + std::swap (t, v); + + /* Check for valid option in token T. If we find a valid option then + parse the value from the token V. Except for 'if', that's handled + differently. + + For the 'if' token we need to capture the entire condition + string, so record the start of the condition string and then + start scanning backwards looking for the end of the condition + string. */ + if (direction == parse_direction::forward && t.length () > 0 + && t.matches ("if")) + { + cond_start = v.start (); + tok = tok + strlen (tok); + gdb_assert (*tok == '\0'); + --tok; + direction = parse_direction::backward; + continue; + } + else if (t.length () > 0 && t.matches ("thread")) + { + const char *tmptok; + struct thread_info *thr; + + if (*thread != -1) + error(_("You can specify only one thread.")); + + if (*task != -1) + error (_("You can specify only one of thread or task.")); + + thr = parse_thread_id (v.start (), &tmptok); + const char *expected_end = skip_spaces (v.end () + 1); + if (tmptok != expected_end) + error (_("Junk after thread keyword.")); + *thread = thr->global_num; + } + else if (t.length () > 0 && t.matches ("task")) + { + char *tmptok; + + if (*task != -1) + error(_("You can specify only one task.")); + + if (*thread != -1) + error (_("You can specify only one of thread or task.")); + + *task = strtol (v.start (), &tmptok, 0); + const char *expected_end = v.end () + 1; + if (tmptok != expected_end) + error (_("Junk after task keyword.")); + if (!valid_task_id (*task)) + error (_("Unknown task %d."), *task); + } + else + { + /* An unknown token. If we are scanning forward then reset TOK + to point at the start of the unknown content, we record this + outside of the scanning loop (below). + + If we are scanning backward then unknown content is assumed to + be the other end of the condition string, obviously, this is + just a heuristic, we could be looking at a mistyped command + line, but this will be spotted when the condition is + eventually evaluated. + + Either way, no more scanning is required after this. */ + if (direction == parse_direction::forward) + tok = t.start (); + else + { + gdb_assert (direction == parse_direction::backward); + cond_end = v.end () + 1; + } + break; + } + } + + if (cond_start != nullptr) + { + /* If we found the start of a condition string then we should have + switched to backward scan mode, and found the end of the condition + string. Capture the whole condition string into COND_STRING now. */ + gdb_assert (direction == parse_direction::backward); + gdb_assert (cond_end != nullptr); + cond_string->reset (savestring (cond_start, cond_end - cond_start)); + } + else if (*tok != '\0') + { + /* If we didn't have a condition start pointer then we should still + be in forward scanning mode. If we didn't reach the end of the + input string (TOK is not at the null character) then the rest of + the input string is garbage that we didn't understand. + + Record the unknown content into REST. The caller of this function + will report this as an error later on. We could report the error + here, but we prefer to allow the caller to run other checks, and + prioritise other errors before reporting this problem. */ + gdb_assert (direction == parse_direction::forward); + rest->reset (savestring (tok, strlen (tok))); + } +} + +#if GDB_SELF_TEST + +namespace selftests { + +/* Run a single test of the create_breakpoint_parse_arg_string function. + INPUT is passed to create_breakpoint_parse_arg_string while all other + arguments are the expected output from + create_breakpoint_parse_arg_string. */ + +static void +test (const char *input, const char *condition, int thread = -1, + int task = -1, bool force = false, const char *rest = nullptr) +{ + gdb::unique_xmalloc_ptr extracted_condition; + gdb::unique_xmalloc_ptr extracted_rest; + int extracted_thread, extracted_task; + bool extracted_force_condition; + std::string exception_msg; + + try + { + create_breakpoint_parse_arg_string (input, &extracted_condition, + &extracted_thread, + &extracted_task, &extracted_rest, + &extracted_force_condition); + } + catch (const gdb_exception_error &ex) + { + string_file buf; + + exception_print (&buf, ex); + exception_msg = buf.release (); + } + + if ((condition == nullptr) != (extracted_condition.get () == nullptr) + || (condition != nullptr + && strcmp (condition, extracted_condition.get ()) != 0) + || (rest == nullptr) != (extracted_rest.get () == nullptr) + || (rest != nullptr && strcmp (rest, extracted_rest.get ()) != 0) + || thread != extracted_thread + || task != extracted_task + || force != extracted_force_condition + || !exception_msg.empty ()) + { + if (run_verbose ()) + { + debug_printf ("input: '%s'\n", input); + debug_printf ("condition: '%s'\n", extracted_condition.get ()); + debug_printf ("rest: '%s'\n", extracted_rest.get ()); + debug_printf ("thread: %d\n", extracted_thread); + debug_printf ("task: %d\n", extracted_task); + debug_printf ("forced: %s\n", + extracted_force_condition ? "true" : "false"); + debug_printf ("exception: '%s'\n", exception_msg.c_str ()); + } + + /* Report the failure. */ + SELF_CHECK (false); + } +} + +/* Test the create_breakpoint_parse_arg_string function. Just wraps + multiple calls to the test function above. */ + +static void +create_breakpoint_parse_arg_string_tests (void) +{ + gdbarch *arch = current_inferior ()->gdbarch; + scoped_restore_current_pspace_and_thread restore; + scoped_mock_context mock_target (arch); + + int global_thread_num = mock_target.mock_thread.global_num; + + test (" if blah ", "blah"); + test (" if blah thread 1", "blah", global_thread_num); + test (" if blah thread 1 ", "blah", global_thread_num); + test ("thread 1 woof", nullptr, global_thread_num, -1, false, "woof"); + test ("thread 1 X", nullptr, global_thread_num, -1, false, "X"); + test (" if blah thread 1 -force-condition", "blah", global_thread_num, + -1, true); + test (" -force-condition if blah thread 1", "blah", global_thread_num, + -1, true); + test (" -force-condition if blah thread 1 ", "blah", global_thread_num, + -1, true); + test ("thread 1 -force-condition if blah", "blah", global_thread_num, + -1, true); + test ("if (A::outer::func ())", "(A::outer::func ())"); +} + +} // namespace selftests +#endif /* GDB_SELF_TEST */ + +void _initialize_break_cond_parse (); +void +_initialize_break_cond_parse () +{ +#if GDB_SELF_TEST + selftests::register_test + ("create_breakpoint_parse_arg_string", + selftests::create_breakpoint_parse_arg_string_tests); +#endif +} diff --git a/gdb/break-cond-parse.h b/gdb/break-cond-parse.h new file mode 100644 index 00000000000..ec62b88ea92 --- /dev/null +++ b/gdb/break-cond-parse.h @@ -0,0 +1,47 @@ +/* Copyright (C) 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 . */ + +#if !defined (BREAK_COND_PARSE_H) +#define BREAK_COND_PARSE_H 1 + +/* Given TOK, a string possibly containing a condition, thread, task and + force-condition flag, as accepted by the 'break' command, extract the + condition string, thread and task numbers, and the force_condition flag, + then set *COND_STRING, *THREAD, *TASK, and *FORCE. + + As TOK is parsed, if an unknown keyword is encountered before the 'if' + keyword then everything starting from the unknown keyword is placed into + *REST. + + Both *COND and *REST are initialized to nullptr. If no 'if' keyword is + found then *COND will be returned as nullptr. If no unknown content is + found then *REST is returned as nullptr. + + If no thread is found, *THREAD is set to -1. If no task is found, *TASK + is set to -1. If the -force-condition flag is not found then *FORCE is + set to false. + + Due to the free-form nature that the string TOK might take (a 'thread' + keyword can appear before or after an 'if' condition) then we end up + having to check for keywords from both the start of TOK and the end of + TOK. */ + +extern void create_breakpoint_parse_arg_string + (const char *tok, gdb::unique_xmalloc_ptr *cond_string, + int *thread, int *task, gdb::unique_xmalloc_ptr *rest, bool *force); + +#endif diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 6a76bfbefe8..ed3d61605bf 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -70,6 +70,7 @@ #include "cli/cli-style.h" #include "cli/cli-decode.h" #include +#include "break-cond-parse.h" /* readline include files */ #include "readline/tilde.h" @@ -6190,20 +6191,7 @@ print_breakpoint_location (const breakpoint *b, const bp_location *loc) uiout->field_stream ("at", stb); } else - { - uiout->field_string ("pending", b->locspec->to_string ()); - /* If extra_string is available, it could be holding a condition - or dprintf arguments. In either case, make sure it is printed, - too, but only for non-MI streams. */ - if (!uiout->is_mi_like_p () && b->extra_string != NULL) - { - if (b->type == bp_dprintf) - uiout->text (","); - else - uiout->text (" "); - uiout->text (b->extra_string.get ()); - } - } + uiout->field_string ("pending", b->locspec->to_string ()); if (loc && is_breakpoint (b) && breakpoint_condition_evaluation_mode () == condition_evaluation_target @@ -8526,8 +8514,8 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_, gdb_assert (extra_string != nullptr); update_dprintf_command_list (this); } - else if (extra_string != nullptr) - error (_("Garbage '%s' at end of command"), extra_string.get ()); + else + gdb_assert (extra_string == nullptr); /* The order of the locations is now stable. Set the location condition using the location's number. */ @@ -8754,160 +8742,6 @@ check_fast_tracepoint_sals (struct gdbarch *gdbarch, } } -/* Given TOK, a string specification of condition and thread, as - accepted by the 'break' command, extract the condition - string and thread number and set *COND_STRING and *THREAD. - PC identifies the context at which the condition should be parsed. - If no condition is found, *COND_STRING is set to NULL. - If no thread is found, *THREAD is set to -1. */ - -static void -find_condition_and_thread (const char *tok, CORE_ADDR pc, - gdb::unique_xmalloc_ptr *cond_string, - int *thread, int *task, - gdb::unique_xmalloc_ptr *rest) -{ - cond_string->reset (); - *thread = -1; - *task = -1; - rest->reset (); - bool force = false; - - while (tok && *tok) - { - const char *end_tok; - int toklen; - const char *cond_start = NULL; - const char *cond_end = NULL; - - tok = skip_spaces (tok); - - if ((*tok == '"' || *tok == ',') && rest) - { - rest->reset (savestring (tok, strlen (tok))); - return; - } - - end_tok = skip_to_space (tok); - - toklen = end_tok - tok; - - if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) - { - tok = cond_start = end_tok + 1; - try - { - parse_exp_1 (&tok, pc, block_for_pc (pc), 0); - } - catch (const gdb_exception_error &) - { - if (!force) - throw; - else - tok = tok + strlen (tok); - } - cond_end = tok; - cond_string->reset (savestring (cond_start, cond_end - cond_start)); - } - else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0) - { - tok = tok + toklen; - force = true; - } - else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) - { - const char *tmptok; - struct thread_info *thr; - - if (*thread != -1) - error(_("You can specify only one thread.")); - - if (*task != -1) - error (_("You can specify only one of thread or task.")); - - tok = end_tok + 1; - thr = parse_thread_id (tok, &tmptok); - if (tok == tmptok) - error (_("Junk after thread keyword.")); - *thread = thr->global_num; - tok = tmptok; - } - else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) - { - char *tmptok; - - if (*task != -1) - error(_("You can specify only one task.")); - - if (*thread != -1) - error (_("You can specify only one of thread or task.")); - - tok = end_tok + 1; - *task = strtol (tok, &tmptok, 0); - if (tok == tmptok) - error (_("Junk after task keyword.")); - if (!valid_task_id (*task)) - error (_("Unknown task %d."), *task); - tok = tmptok; - } - else if (rest) - { - rest->reset (savestring (tok, strlen (tok))); - return; - } - else - error (_("Junk at end of arguments.")); - } -} - -/* Call 'find_condition_and_thread' for each sal in SALS until a parse - succeeds. The parsed values are written to COND_STRING, THREAD, - TASK, and REST. See the comment of 'find_condition_and_thread' - for the description of these parameters and INPUT. */ - -static void -find_condition_and_thread_for_sals (const std::vector &sals, - const char *input, - gdb::unique_xmalloc_ptr *cond_string, - int *thread, int *task, - gdb::unique_xmalloc_ptr *rest) -{ - int num_failures = 0; - for (auto &sal : sals) - { - gdb::unique_xmalloc_ptr cond; - int thread_id = -1; - int task_id = -1; - gdb::unique_xmalloc_ptr remaining; - - /* Here we want to parse 'arg' to separate condition from thread - number. But because parsing happens in a context and the - contexts of sals might be different, try each until there is - success. Finding one successful parse is sufficient for our - goal. When setting the breakpoint we'll re-parse the - condition in the context of each sal. */ - try - { - find_condition_and_thread (input, sal.pc, &cond, &thread_id, - &task_id, &remaining); - *cond_string = std::move (cond); - /* At most one of thread or task can be set. */ - gdb_assert (thread_id == -1 || task_id == -1); - *thread = thread_id; - *task = task_id; - *rest = std::move (remaining); - break; - } - catch (const gdb_exception_error &e) - { - num_failures++; - /* If no sal remains, do not continue. */ - if (num_failures == sals.size ()) - throw; - } - } -} - /* Decode a static tracepoint marker spec. */ static std::vector @@ -9018,6 +8852,44 @@ create_breakpoint (struct gdbarch *gdbarch, || (type_wanted != bp_dprintf && (extra_string == nullptr || parse_extra))); + /* Will hold either copies of the similarly named function argument, or + will hold a modified version of the function argument, depending on + the value of PARSE_EXTRA. */ + gdb::unique_xmalloc_ptr cond_string_copy; + gdb::unique_xmalloc_ptr extra_string_copy; + + if (parse_extra) + { + /* Parse EXTRA_STRING splitting the parts out. */ + create_breakpoint_parse_arg_string (extra_string, &cond_string_copy, + &thread, &task, &extra_string_copy, + &force_condition); + + /* We could check that EXTRA_STRING_COPY is empty at this point -- it + should be, as we only get here for things that are not bp_dprintf, + however, we prefer to give the location spec parser a chance to + run first, this means the user will get errors about invalid + location spec instead of an error about garbage at the end of the + command line. + + We still do the EXTRA_STRING_COPY is empty check, just later in + this function. */ + + gdb_assert (thread == -1 || thread > 0); + gdb_assert (task == -1 || task > 0); + } + else + { + if (cond_string != nullptr) + cond_string_copy.reset (xstrdup (cond_string)); + if (extra_string != nullptr) + extra_string_copy.reset (xstrdup (extra_string)); + } + + /* Clear these. Updated values are now held in the *_copy locals. */ + cond_string = nullptr; + extra_string = nullptr; + try { ops->create_sals_from_location_spec (locspec, &canonical); @@ -9053,6 +8925,13 @@ create_breakpoint (struct gdbarch *gdbarch, throw; } + /* The only bp_dprintf should have anything in EXTRA_STRING_COPY by this + point. For all other breakpoints this indicates an error. We could + place this check earlier in the function, but we prefer to see errors + from the location spec parser before we see this error message. */ + if (type_wanted != bp_dprintf && extra_string_copy.get () != nullptr) + error (_("Garbage '%s' at end of command"), extra_string_copy.get ()); + if (!pending && canonical.lsals.empty ()) return 0; @@ -9076,62 +8955,31 @@ create_breakpoint (struct gdbarch *gdbarch, breakpoint. */ if (!pending) { - gdb::unique_xmalloc_ptr cond_string_copy; - gdb::unique_xmalloc_ptr extra_string_copy; - - if (parse_extra) + /* Check the validity of the condition. We should error out if the + condition is invalid at all of the locations and if it is not + forced. In the PARSE_EXTRA case above, this check is done when + parsing the EXTRA_STRING. */ + if (cond_string_copy.get () != nullptr && !force_condition) { - gdb_assert (type_wanted != bp_dprintf); - - gdb::unique_xmalloc_ptr rest; - gdb::unique_xmalloc_ptr cond; - + int num_failures = 0; const linespec_sals &lsal = canonical.lsals[0]; - - find_condition_and_thread_for_sals (lsal.sals, extra_string, - &cond, &thread, &task, &rest); - - if (rest.get () != nullptr && *(rest.get ()) != '\0') - error (_("Garbage '%s' at end of command"), rest.get ()); - - cond_string_copy = std::move (cond); - extra_string_copy = std::move (rest); - } - else - { - /* Check the validity of the condition. We should error out - if the condition is invalid at all of the locations and - if it is not forced. In the PARSE_EXTRA case above, this - check is done when parsing the EXTRA_STRING. */ - if (cond_string != nullptr && !force_condition) + for (const auto &sal : lsal.sals) { - int num_failures = 0; - const linespec_sals &lsal = canonical.lsals[0]; - for (const auto &sal : lsal.sals) + const char *cond = cond_string_copy.get (); + try { - const char *cond = cond_string; - try - { - parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0); - /* One success is sufficient to keep going. */ - break; - } - catch (const gdb_exception_error &) - { - num_failures++; - /* If this is the last sal, error out. */ - if (num_failures == lsal.sals.size ()) - throw; - } + parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0); + /* One success is sufficient to keep going. */ + break; + } + catch (const gdb_exception_error &) + { + num_failures++; + /* If this is the last sal, error out. */ + if (num_failures == lsal.sals.size ()) + throw; } } - - /* Create a private copy of condition string. */ - if (cond_string) - cond_string_copy.reset (xstrdup (cond_string)); - /* Create a private copy of any extra string. */ - if (extra_string) - extra_string_copy.reset (xstrdup (extra_string)); } ops->create_breakpoints_sal (gdbarch, &canonical, @@ -9148,21 +8996,15 @@ create_breakpoint (struct gdbarch *gdbarch, type_wanted); b->locspec = locspec->clone (); - if (parse_extra) - b->cond_string = NULL; - else - { - /* Create a private copy of condition string. */ - b->cond_string.reset (cond_string != NULL - ? xstrdup (cond_string) - : NULL); - b->thread = thread; - } + /* Create a private copy of condition string. */ + b->cond_string = std::move (cond_string_copy); + + b->thread = thread; + b->task = task; /* Create a private copy of any extra string. */ - b->extra_string.reset (extra_string != NULL - ? xstrdup (extra_string) - : NULL); + b->extra_string = std::move (extra_string_copy); + b->ignore_count = ignore_count; b->disposition = tempflag ? disp_del : disp_donttouch; b->condition_not_parsed = 1; @@ -9171,9 +9013,12 @@ create_breakpoint (struct gdbarch *gdbarch, && type_wanted != bp_hardware_breakpoint) || thread != -1) b->pspace = current_program_space; + if (type_wanted == bp_dprintf) + update_dprintf_command_list (b.get ()); + install_breakpoint (internal, std::move (b), 0); } - + if (canonical.lsals.size () > 1) { warning (_("Multiple breakpoints were set.\nUse the " @@ -12880,23 +12725,6 @@ code_breakpoint::location_spec_to_sals (location_spec *locspec, { for (auto &sal : sals) resolve_sal_pc (&sal); - if (condition_not_parsed && extra_string != NULL) - { - gdb::unique_xmalloc_ptr local_cond, local_extra; - int local_thread, local_task; - - find_condition_and_thread_for_sals (sals, extra_string.get (), - &local_cond, &local_thread, - &local_task, &local_extra); - gdb_assert (cond_string == nullptr); - if (local_cond != nullptr) - cond_string = std::move (local_cond); - thread = local_thread; - task = local_task; - if (local_extra != nullptr) - extra_string = std::move (local_extra); - condition_not_parsed = 0; - } if (type == bp_static_tracepoint) sals[0] = update_static_tracepoint (this, sals[0]); diff --git a/gdb/testsuite/gdb.base/condbreak.exp b/gdb/testsuite/gdb.base/condbreak.exp index a5b2a28701b..50ae82c3f32 100644 --- a/gdb/testsuite/gdb.base/condbreak.exp +++ b/gdb/testsuite/gdb.base/condbreak.exp @@ -179,6 +179,10 @@ gdb_test "break -q main if (1==1) thread 999" \ "Unknown thread 999\\." gdb_test "break -q main thread 999 if (1==1)" \ "Unknown thread 999\\." +gdb_test "break -q main if (1==1) thread 999 -force-condition" \ + "Unknown thread 999\\." +gdb_test "break -q main thread 999 if (1==1) -force-condition" \ + "Unknown thread 999\\." # Verify that both if and thread can be distinguished from a breakpoint # address expression. @@ -186,20 +190,34 @@ gdb_test "break *main if (1==1) thread 999" \ "Unknown thread 999\\." gdb_test "break *main thread 999 if (1==1)" \ "Unknown thread 999\\." +gdb_test "break *main if (1==1) thread 999 -force-condition" \ + "Unknown thread 999\\." +gdb_test "break *main thread 999 if (1==1) -force-condition" \ + "Unknown thread 999\\." # Similarly for task. gdb_test "break *main if (1==1) task 999" \ "Unknown task 999\\." gdb_test "break *main task 999 if (1==1)" \ "Unknown task 999\\." +gdb_test "break *main if (1==1) task 999 -force-condition" \ + "Unknown task 999\\." +gdb_test "break *main task 999 if (1==1) -force-condition" \ + "Unknown task 999\\." -# GDB accepts abbreviations for "thread" and "task". +# GDB accepts abbreviations for "thread" and "task" and "-force-condition" gdb_test "break *main if (1==1) t 999" \ "Unknown thread 999\\." gdb_test "break *main if (1==1) th 999" \ "Unknown thread 999\\." gdb_test "break *main if (1==1) ta 999" \ "Unknown task 999\\." +gdb_test "break *main if (1==1) t 999 -force" \ + "Unknown thread 999\\." +gdb_test "break *main if (1==1) th 999 -force" \ + "Unknown thread 999\\." +gdb_test "break *main if (1==1) ta 999 -force" \ + "Unknown task 999\\." set test "run until breakpoint at marker3" gdb_test_multiple "continue" $test { diff --git a/gdb/testsuite/gdb.base/pending.exp b/gdb/testsuite/gdb.base/pending.exp index d7d3735000a..645f63bdb16 100644 --- a/gdb/testsuite/gdb.base/pending.exp +++ b/gdb/testsuite/gdb.base/pending.exp @@ -170,7 +170,8 @@ gdb_test "info break" \ \[\t \]+stop only if k == 1.* \[\t \]+print k.* \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.* -\[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.*" \ +\[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc.* +\\s+stop only if x > 3.*" \ "multiple pending breakpoints" @@ -195,8 +196,10 @@ gdb_test "info break" \ \[\t \]+stop only if k == 1.* \[\t \]+print k.* \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.* -\[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc if x > 3.* -\[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp3_loc.*ignore next 2 hits.*" \ +\[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp2_loc.* +\\s+stop only if x > 3.* +\[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*pendshr.c:$bp3_loc.* +\\s+ignore next 2 hits.*" \ "multiple pending breakpoints 2" # @@ -267,3 +270,17 @@ gdb_test "info break" \ \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$mainline.* \[0-9\]+\[\t \]+breakpoint keep y.*PENDING.*imaginary.*" \ "verify pending breakpoint after restart" + +# Test GDB's parsing of pending breakpoint thread and condition. + +gdb_test_no_output "set breakpoint pending on" +gdb_test "break foo if (unknown_var && another_unknown_var) thread 1" \ + "Breakpoint $decimal \\(foo\\) pending\\." +set bpnum [get_integer_valueof "\$bpnum" "*INVALID" \ + "get number for foo breakpoint"] +gdb_test "info breakpoints $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "\\s+stop only if \\(unknown_var && another_unknown_var\\)" \ + "\\s+stop only in thread 1"] \ + "check pending breakpoint on foo" diff --git a/gdb/testsuite/gdb.linespec/explicit.exp b/gdb/testsuite/gdb.linespec/explicit.exp index b08d65953d2..7c8b2475881 100644 --- a/gdb/testsuite/gdb.linespec/explicit.exp +++ b/gdb/testsuite/gdb.linespec/explicit.exp @@ -574,7 +574,7 @@ namespace eval $testfile { allow-pending]} { fail "set $tst" } else { - gdb_test "info break" ".*PENDING.*myfunction if foofoofoo == 1.*" $tst + gdb_test "info break" ".*PENDING.*myfunction\r\n\\s+stop only if foofoofoo == 1.*" $tst } gdb_exit @@ -585,7 +585,7 @@ namespace eval $testfile { allow-pending]} { fail "set $tst" } else { - gdb_test "info break" ".*PENDING.*myfunction if arg == 0" $tst + gdb_test "info break" ".*PENDING.*myfunction\r\n\\s+stop only if arg == 0" $tst gdb_load [standard_output_file $exefile] gdb_test "info break" \ diff --git a/gdb/testsuite/gdb.mi/mi-dprintf-pending.exp b/gdb/testsuite/gdb.mi/mi-dprintf-pending.exp index 28f52938aeb..bb9987a5572 100644 --- a/gdb/testsuite/gdb.mi/mi-dprintf-pending.exp +++ b/gdb/testsuite/gdb.mi/mi-dprintf-pending.exp @@ -50,7 +50,8 @@ set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] # Set pending dprintf via MI. set bp [mi_make_breakpoint_pending -number "1" -type "dprintf" \ -disp "keep" -enabled "y" -pending "pendfunc1" \ - -original-location "pendfunc1"] + -original-location "pendfunc1" \ + -script {\["printf \\\"hello\\\""\]}] mi_gdb_test "-dprintf-insert -f pendfunc1 \"hello\"" \ ".*\\^done,$bp" "mi set dprintf" diff --git a/gdb/testsuite/gdb.threads/del-pending-thread-bp-lib.c b/gdb/testsuite/gdb.threads/del-pending-thread-bp-lib.c new file mode 100644 index 00000000000..15d1b9833dd --- /dev/null +++ b/gdb/testsuite/gdb.threads/del-pending-thread-bp-lib.c @@ -0,0 +1,22 @@ +/* Copyright 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 . */ + +int global_var = 0; + +void +foo (int arg) +{ + global_var = arg; +} diff --git a/gdb/testsuite/gdb.threads/del-pending-thread-bp.c b/gdb/testsuite/gdb.threads/del-pending-thread-bp.c new file mode 100644 index 00000000000..938e05bc4d7 --- /dev/null +++ b/gdb/testsuite/gdb.threads/del-pending-thread-bp.c @@ -0,0 +1,85 @@ +/* Copyright 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 . */ + +#include +#include +#include + +pthread_barrier_t barrier; + +static void +barrier_wait (pthread_barrier_t *b) +{ + int res = pthread_barrier_wait (b); + if (res != 0 && res != PTHREAD_BARRIER_SERIAL_THREAD) + abort (); +} + +static void * +thread_worker (void *arg) +{ + barrier_wait (&barrier); + return NULL; +} + +void +breakpt () +{ + /* Nothing. */ +} + +int +main (void) +{ + void *handle; + void (*func)(int); + pthread_t thread; + + if (pthread_barrier_init (&barrier, NULL, 2) != 0) + abort (); + + if (pthread_create (&thread, NULL, thread_worker, NULL) != 0) + abort (); + + breakpt (); + + /* Allow the worker thread to complete. */ + barrier_wait (&barrier); + + if (pthread_join (thread, NULL) != 0) + abort (); + + breakpt (); + + /* Now load the shared library. */ + handle = dlopen (SHLIB_NAME, RTLD_LAZY); + if (handle == NULL) + abort (); + + /* Find the function symbol. */ + func = (void (*)(int)) dlsym (handle, "foo"); + + /* Call the library function. */ + func (1); + + /* Unload the shared library. */ + if (dlclose (handle) != 0) + abort (); + + breakpt (); + + return 0; +} + diff --git a/gdb/testsuite/gdb.threads/del-pending-thread-bp.exp b/gdb/testsuite/gdb.threads/del-pending-thread-bp.exp new file mode 100644 index 00000000000..4ed05eaa42d --- /dev/null +++ b/gdb/testsuite/gdb.threads/del-pending-thread-bp.exp @@ -0,0 +1,108 @@ +# Copyright 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 checks that pending thread-specific breakpoints are +# correctly deleted when the thread the breakpoint is for goes out of +# scope. +# +# We also check that we can't create a pending thread-specific +# breakpoint for a non-existent thread. + +require allow_shlib_tests + +standard_testfile + +set libname $testfile-lib +set srcfile_lib $srcdir/$subdir/$libname.c +set binfile_lib [standard_output_file $libname.so] + +if { [gdb_compile_shlib $srcfile_lib $binfile_lib {}] != "" } { + untested "failed to compile shared library 1" + return -1 +} + +set binfile_lib_target [gdb_download_shlib $binfile_lib] + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ + [list debug \ + additional_flags=-DSHLIB_NAME=\"$binfile_lib_target\" \ + shlib_load pthreads]] } { + return -1 +} + +gdb_locate_shlib $binfile_lib + +if ![runto_main] { + return 0 +} + +# Run until we have two threads. +gdb_breakpoint "breakpt" +gdb_continue_to_breakpoint "first breakpt call" + +# Confirm that we have a thread '2'. +gdb_test "info threads" "\r\n\\s+2\\s+\[^\r\n\]+" + +# Create a pending, thread-specific, breakpoint on 'foo'. +gdb_breakpoint "foo thread 2" allow-pending +set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \ + "get breakpoint number"] + +# Check we can't create a pending thread-specific breakpoint for a +# non-existent thread. +gdb_test "with breakpoint pending on -- break foo thread 99" \ + "Unknown thread 99\\." + +# Continue to 'breakpt' again. Don't use gdb_continue_to_breakpoint +# as we are looking for the thread exited and breakpoint deleted +# messages. +set output [list "Continuing\\."] + +if {!([target_info exists gdb_protocol] + && ([target_info gdb_protocol] == "remote" + || [target_info gdb_protocol] == "extended-remote"))} { + # Due to bug PR gdb/30129 we don't see the thread exited messages + # for remote targets. When this bit of this test can be cleaned + # up. + lappend output "\\\[Thread \[^\r\n\]+ exited\\\]" +} + +lappend output "Thread-specific breakpoint $bpnum deleted - thread 2 no longer in the thread list\\." \ + "" \ + "Thread 1 \[^\r\n\]+, breakpt \\(\\) at \[^\r\n\]+" \ + "$decimal\\s+\[^\r\n\]+" + +gdb_test "continue" \ + [multi_line {*}$output] \ + "second breakpt call" + +# Confirm breakpoint has been deleted. +gdb_test "info breakpoints $bpnum" \ + "No breakpoint or watchpoint matching '$bpnum'\\." + +# Continue again. This will pass through 'foo'. We should not stop +# in 'foo', the breakpoint has been deleted. We should next stop in +# breakpt again. +gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Thread 1 \[^\r\n\]+ hit Breakpoint $decimal, breakpt \\(\\) at \[^\r\n\]+" \ + "$decimal\\s+\[^\r\n\]+"] \ + "third breakpt call" +gdb_test "bt 1" \ + [multi_line \ + "#0\\s+breakpt \\(\\) at \[^\r\n\]+" \ + "\\(More stack frames follow\\.\\.\\.\\)"] From patchwork Tue May 30 20:46:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70342 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 A0302384F1C0 for ; Tue, 30 May 2023 20:48:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0302384F1C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479715; bh=6JwvSvi00T3QFo2Q7Z7grT2aXMFg+ffEGmTEpl48PX4=; 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=MT0tsSeMgcGTjhthRxvfNHcrBJLYoVYRp0im6i1uE0+h9+wahnDAXzM3f3a9982Us W3rhm3m0mOZBqk9+sDi3YNwpHEHKWuDbeV2fN/fbhFymtiiwm7LsAnk5FmYYARgmY8 61nUnlIMCxZRw2tmeFhVHLTfV+Z32gMKuV6BtAwQ= 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 AE0473858D28 for ; Tue, 30 May 2023 20:47:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE0473858D28 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-gMWVICxLPISw0Ty-D2LXbQ-1; Tue, 30 May 2023 16:47:10 -0400 X-MC-Unique: gMWVICxLPISw0Ty-D2LXbQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-30af81cf4dbso398359f8f.2 for ; Tue, 30 May 2023 13:47:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479629; x=1688071629; 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=6JwvSvi00T3QFo2Q7Z7grT2aXMFg+ffEGmTEpl48PX4=; b=hU7DOCdKT2HC2YDCHneSefneGGw0CoSxE+oyAx+WhabflbEJ1FpRz5pXleeKGDosUu +6j21LIogXLPuS9OgLJWieWXlqwMW5c/P0jtuQh41VwyihvEmB7cGoi3P20SiObI5Eut 1JoUKbnBEfLDnRqzRLUugPWwum//v2X/qe+En9OGnwbgGdxaqfUC5yDSnUGPNzvmpSy8 n4Je3O9HiRm+IP0rs3nN6cc8wHuGGkkmhs2TIzFb6KGSGPuSEBwCVfE51Di2cMDFRqxF LaDQRnnT3/dg1kAYdSfbCVwP3quVbZrXWKnWrQrFsO4+Kf+Es8k5Ml7wKYJwGpPlffZl Oojg== X-Gm-Message-State: AC+VfDztam8Vm4TXRnNoUAz+RCJrqL3WxcU1XzRKB+uqKyo6B7JoCT69 aAmYwyodT6ZHJB/TEBvAGw0pLvWmhTgrTml1MuGZ5YQDPueIARKHZQcLORKoTiaf4Uw+stV3h6t Oos9tDTeP5inaL1lHvuxdt8PqwhxMoLBhJ81mRSqyqc77arFV3Bt8L2/Xl7UuLzFNrbnLOTJhCc wGUk/SGw== X-Received: by 2002:a5d:550f:0:b0:301:2452:e4d with SMTP id b15-20020a5d550f000000b0030124520e4dmr3190418wrv.46.1685479628845; Tue, 30 May 2023 13:47:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7W1ARCQATD3jnFlSOhQ50SVN800InfK9bIRGgOEoCKY7rNwORkj1F9XdDoMm/iTSL7WMy8gQ== X-Received: by 2002:a5d:550f:0:b0:301:2452:e4d with SMTP id b15-20020a5d550f000000b0030124520e4dmr3190411wrv.46.1685479628542; Tue, 30 May 2023 13:47:08 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id m4-20020a5d4a04000000b003079c402762sm4406143wrq.19.2023.05.30.13.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:08 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 7/9] gdb: remove breakpoint_re_set_one Date: Tue, 30 May 2023 21:46:51 +0100 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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" During a later patch I wanted to reset a single breakpoint, so I called breakpoint_re_set_one. However, this is not the right thing to do. If we look at breakpoint_re_set then we see that there's a whole bunch of state that needs to be preserved prior to calling breakpoint_re_set_one, and after calling breakpoint_re_set_one we still need to call update_global_location_list. I could just update the comment on breakpoint_re_set_one to make it clearer how the function should be used -- or more likely to warn that the function should only be used as a helper from breakpoint_re_set. However, breakpoint_re_set_one is only 3 lines long. So I figure it might actually be easier to just fold breakpoint_re_set_one into breakpoint_re_set, then there's no risk of accidentally calling breakpoint_re_set_one when we shouldn't. There should be no user visible changes after this commit. --- gdb/breakpoint.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index ed3d61605bf..79a55d66f08 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -12776,17 +12776,6 @@ create_sals_from_location_spec_default (location_spec *locspec, parse_breakpoint_sals (locspec, canonical); } -/* Reset a breakpoint. */ - -static void -breakpoint_re_set_one (breakpoint *b) -{ - input_radix = b->input_radix; - set_language (b->language); - - b->re_set (); -} - /* Re-set breakpoint locations for the current program space. Locations bound to other program spaces are left untouched. */ @@ -12798,12 +12787,11 @@ breakpoint_re_set (void) scoped_restore save_input_radix = make_scoped_restore (&input_radix); scoped_restore_current_pspace_and_thread restore_pspace_thread; - /* breakpoint_re_set_one sets the current_language to the language - of the breakpoint it is resetting (see prepare_re_set_context) - before re-evaluating the breakpoint's location. This change can - unfortunately get undone by accident if the language_mode is set - to auto, and we either switch frames, or more likely in this context, - we select the current frame. + /* To ::re_set each breakpoint we set the current_language to the + language of the breakpoint before re-evaluating the breakpoint's + location. This change can unfortunately get undone by accident if + the language_mode is set to auto, and we either switch frames, or + more likely in this context, we select the current frame. We prevent this by temporarily turning the language_mode to language_mode_manual. We restore it once all breakpoints @@ -12820,7 +12808,9 @@ breakpoint_re_set (void) { try { - breakpoint_re_set_one (&b); + input_radix = b.input_radix; + set_language (b.language); + b.re_set (); } catch (const gdb_exception &ex) { From patchwork Tue May 30 20:46:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70341 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 E253A3854E56 for ; Tue, 30 May 2023 20:48:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E253A3854E56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479705; bh=KfggFHAybcT4U3+5aRvVJSfCS/jqQSOMQksgngIXpRk=; 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=MZ7nXEoLFISKeNWOPFCpiUkDHgU0t62XV/R7jFBDwiC1L2gkNerrZJjy3/q4qEyoO GQTKc+QgorMgVxHNKbYogpsJn59qOLFmOCeHnovkrZztrEQupbqD2gtJucc4xTVirn MpOcBibAmNs2h6LikOSW6qUYkXd3vhEYhtQI7hvg= 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 120E03856967 for ; Tue, 30 May 2023 20:47:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 120E03856967 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-BMRSMrXzOia0i00hmrcKEQ-1; Tue, 30 May 2023 16:47:11 -0400 X-MC-Unique: BMRSMrXzOia0i00hmrcKEQ-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f608ea691fso28705955e9.3 for ; Tue, 30 May 2023 13:47:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479630; x=1688071630; 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=KfggFHAybcT4U3+5aRvVJSfCS/jqQSOMQksgngIXpRk=; b=Wl2u1hoauO+/rmTdFfzXr+IfOa7nIHNIh+XGgyk+xtIisMcy20Acc4kItRmzijlJfQ bpP97JFrN3TqVw/nAzC+LHg8IHOleVtGf9jQQzQDjV5kG6rHnWxJI6jMEws1oDidAJmU CjjIw2/UuVp5j7TRYAOvT/KaFDdP8gym4NTzu3JNZeXLmd09t8Mg5AjREnc3kWatu0DH m3o4iHgNASMkpmN2arhEG7n/GrVOQPmjRs5vcsIw+NC87NI566pUW33pk3D0t+pUxR4q wy75Y+iJ6+HtrwuTaqPxvJUjuVeInEvtvfca0SbrkPgiTeyx9iTj3AINBXpI3dwcdVnh 0YGw== X-Gm-Message-State: AC+VfDzGt0WNOttnuVZFasRKS+ydB1pzxBhokU4z3WFmit6y0/KXpSs8 cN57nXwkoifYLSbpaYuYsSze4qusXfIZqUeeAJBwfCB4RrBRF6OrXW5qPIB/qMuGGsYAcq1mgQc HxHJC8IKH6qiAZ8So/qyj73+DK67taTnnh/iC2ek2R9EbajAiczJ6hpdqInoLWzSBr+VZ5/jfsz Ge3WnJlg== X-Received: by 2002:a05:600c:2204:b0:3f6:c7b:d3c8 with SMTP id z4-20020a05600c220400b003f60c7bd3c8mr3521843wml.16.1685479630336; Tue, 30 May 2023 13:47:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50gYYaflFFUP0xw9heFeU5IiM8Rpu6R14jKRiOyjVU10HvYWjaAmu7IUR20E52dPG7KjABmg== X-Received: by 2002:a05:600c:2204:b0:3f6:c7b:d3c8 with SMTP id z4-20020a05600c220400b003f60c7bd3c8mr3521834wml.16.1685479630062; Tue, 30 May 2023 13:47:10 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id f9-20020a1c6a09000000b003f4272c2d0csm18296791wmc.36.2023.05.30.13.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:09 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 8/9] gdb: remove tracepoint_probe_create_sals_from_location_spec Date: Tue, 30 May 2023 21:46:52 +0100 Message-Id: <117ecc2576438f9754b752f0925dde8730998352.1685479504.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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The tracepoint_probe_create_sals_from_location_spec function just forwards all its arguments to bkpt_probe_create_sals_from_location_spec, and is only used in one place. Lets delete tracepoint_probe_create_sals_from_location_spec and replace it with bkpt_probe_create_sals_from_location_spec. There should be no user visible changes after this commit. --- gdb/breakpoint.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 79a55d66f08..4343016b6b2 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -221,9 +221,6 @@ static bool strace_marker_p (struct breakpoint *b); static void bkpt_probe_create_sals_from_location_spec (location_spec *locspec, struct linespec_result *canonical); -static void tracepoint_probe_create_sals_from_location_spec - (location_spec *locspec, - struct linespec_result *canonical); const struct breakpoint_ops code_breakpoint_ops = { @@ -238,10 +235,11 @@ static const struct breakpoint_ops bkpt_probe_breakpoint_ops = create_breakpoints_sal, }; -/* Tracepoints set on probes. */ +/* Tracepoints set on probes. We use the same methods as for breakpoints + on probes. */ static const struct breakpoint_ops tracepoint_probe_breakpoint_ops = { - tracepoint_probe_create_sals_from_location_spec, + bkpt_probe_create_sals_from_location_spec, create_breakpoints_sal, }; @@ -11994,17 +11992,6 @@ tracepoint::print_recreate (struct ui_file *fp) const gdb_printf (fp, " passcount %d\n", pass_count); } -/* Virtual table for tracepoints on static probes. */ - -static void -tracepoint_probe_create_sals_from_location_spec - (location_spec *locspec, - struct linespec_result *canonical) -{ - /* We use the same method for breakpoint on probes. */ - bkpt_probe_create_sals_from_location_spec (locspec, canonical); -} - void dprintf_breakpoint::re_set () { From patchwork Tue May 30 20:46:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 70344 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 BA5FF3855594 for ; Tue, 30 May 2023 20:49:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA5FF3855594 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685479748; bh=KFgpMEZosSt1efT3girmaLR9Gh74Xr/VH67EKTFooFE=; 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=c9tGsbDUJjSKrcf5ZI94W9KkkdDuMahr1qjUfl5kZdz0whbGL6jULFfr3BTBSxYS9 UIIBabSwCMWgkUZ4ln7OeaApdxY9cZgWOnIU//PJ1gos28FCMlQNaaE/vWQBmHFiop 9pLdzD9snX1ZjRbswYlOr6a6GhDkUFmSjaosdjQs= 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 CDEE8385840A for ; Tue, 30 May 2023 20:47:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDEE8385840A Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-uqSwlSdHMhuZ7qNq7-wDtA-1; Tue, 30 May 2023 16:47:14 -0400 X-MC-Unique: uqSwlSdHMhuZ7qNq7-wDtA-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-30aa0cc2152so2662409f8f.2 for ; Tue, 30 May 2023 13:47:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685479632; x=1688071632; 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=KFgpMEZosSt1efT3girmaLR9Gh74Xr/VH67EKTFooFE=; b=SEzBGFQ18dJIJjlNuYXlh+w+dyXg0ba2n3L78TH8onUuHrNwrrUCt+jXItLeFTWrda ovEMeHC0H6MJve27PECU7D61bM8I/2jbEumFwyWLf/nKUrbMCLqKESZn/+GVf4AR3wKD WFy3aq78EvlitlgEQ1ILQHmMw2t8QfF/TWM0k3B5OcmQo75gEnj9wCOlpftVNeVg1+NL bUkKSWXJLgXqmSJhrrERzeavlfx9CJvI5EV6+tWK9AN7ke/b9QJ4kYu/mbfj8hHBAqi2 V6A3T5BLFXKaT7Af5ALrp35dvNSl+SiIbJLw9ayKI35LWVNhCKgMH/Q1Qw2aTQZ5On6P QiVQ== X-Gm-Message-State: AC+VfDyNvVlgQLfXiTP9r5EDkcxxeck7SceY4B1fCxdQQDHc/s/qusTi ubGKUsaUEE3tgVD2FOj2mbnDoGPDikwXiNDMIdPohY10CBvXRw7lX0OawSw8FY0YI20HJpjjdPP 3KnfKyvYqrYet8TFP5wu3obHm/UYUPL9/m0wmc8xshvhCC58TyRpNcbLjsVb58+2BTziwsqC5P2 ySMtPKuw== X-Received: by 2002:adf:fec2:0:b0:30a:e5e3:ea66 with SMTP id q2-20020adffec2000000b0030ae5e3ea66mr2522968wrs.14.1685479632319; Tue, 30 May 2023 13:47:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ61rQwCDFhiEj74vKLt2CeyRqLWzf3fp770lNXwjLC+4RTu3KPsHHkOPJj/wqCgyit474MzQA== X-Received: by 2002:adf:fec2:0:b0:30a:e5e3:ea66 with SMTP id q2-20020adffec2000000b0030ae5e3ea66mr2522954wrs.14.1685479631534; Tue, 30 May 2023 13:47:11 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id e2-20020a5d5302000000b003047ae72b14sm4349912wrv.82.2023.05.30.13.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:47:11 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii Subject: [PATCHv3 9/9] gdb: only insert thread-specific breakpoints in the relevant inferior Date: Tue, 30 May 2023 21:46:53 +0100 Message-Id: <9b23163b1cf8013c5c132ea2f92d013f72cf273e.1685479504.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 updates GDB so that thread-specific breakpoints are only inserted into the inferior that contains the thread we are interested in. Actually, as breakpoints are placed in program spaces, we insert the breakpoint in any inferior that shares a program space with the inferior containing the thread we are interested in. But as far as most users are concerned this really means the one inferior. In terms of implementation, getting this basically working is easy enough, now that a breakpoint's thread field is setup prior to GDB looking for locations, we can easily use the thread to find a suitable program_space and pass this to as a filter when creating the sals. Or we could if breakpoint_ops::create_sals_from_location_spec allowed us to pass in a filter program_space. So, this commit extends breakpoint_ops::create_sals_from_location_spec to take a program_space argument, and uses this to filter the set of returned sals. This accounts for about half the change in this patch. The second set of changes starts from breakpoint_set_thread, this is called when the thread for a thread-specific breakpoint changes, e.g. from the Python API. Previously this call would never result in the locations of a breakpoint changing, after all, locations were inserted in every program space, and we just use the thread field to decide when we should stop. Now though, changing a breakpoint's thread can mean we need to figure out a new set of breakpoint locations. To support this I've added a new breakpoint_re_set_one function, which is like breakpoint_re_set, but takes a single breakpoint, and just updates the locations for that one breakpoint. We only need to call this function if the program_space in which a breakpoint's thread is running actually changes. If the program_space does change then we call the new breakpoint_re_set_one function passing in the program_space which should be used to filter the locations (or nullptr to indicate we should set locations in all program spaces). This filter program_space needs to propagate down to all the re_set methods, this accounts for the remaining half of the changes in this patch. There were a couple of existing tests that created thread-specific breakpoints and then checked the 'info breakpoints' output, these needed updating. These were: gdb.mi/user-selected-context-sync.exp gdb.multi/bp-thread-specific.exp gdb.multi/multi-target-continue.exp gdb.multi/multi-target-ping-pong-next.exp gdb.multi/tids.exp I've also added some additional tests to: gdb.multi/pending-bp.exp I've updated the documentation and added a NEWS entry. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 7 + gdb/ada-lang.c | 6 +- gdb/break-catch-throw.c | 6 +- gdb/breakpoint.c | 236 ++++++++++++++---- gdb/breakpoint.h | 26 +- .../gdb.mi/user-selected-context-sync.exp | 2 +- .../gdb.multi/bp-thread-specific.exp | 7 +- .../gdb.multi/multi-target-continue.exp | 2 +- .../gdb.multi/multi-target-ping-pong-next.exp | 4 +- gdb/testsuite/gdb.multi/pending-bp.exp | 206 +++++++++++++++ gdb/testsuite/gdb.multi/tids.exp | 6 +- 11 files changed, 427 insertions(+), 81 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index d50b01ffa4f..eb7a984af16 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -71,6 +71,13 @@ 'thread' or 'task' keywords are parsed at the time the breakpoint is created, rather than at the time the breakpoint becomes non-pending. +* Thread-specific breakpoints are only inserted into the program space + in which the thread of interest is running. In most cases program + spaces are unique for each inferior, so this means that + thread-specific breakpoints will usually only be inserted for the + inferior containing the thread of interest. The breakpoint will + be hit no less than before. + * New commands maintenance print record-instruction [ N ] diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 237ec09050c..8a56b78ee61 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12176,7 +12176,7 @@ struct ada_catchpoint : public code_breakpoint } struct bp_location *allocate_location () override; - void re_set () override; + void re_set (program_space *pspace) override; void check_status (struct bpstat *bs) override; enum print_stop_action print_it (const bpstat *bs) const override; bool print_one (const bp_location **) const override; @@ -12268,11 +12268,11 @@ ada_catchpoint::allocate_location () catchpoint kinds. */ void -ada_catchpoint::re_set () +ada_catchpoint::re_set (program_space *pspace) { /* Call the base class's method. This updates the catchpoint's locations. */ - this->code_breakpoint::re_set (); + this->code_breakpoint::re_set (pspace); /* Reparse the exception conditional expressions. One for each location. */ diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c index 47d534c5ee8..e661d1624e8 100644 --- a/gdb/break-catch-throw.c +++ b/gdb/break-catch-throw.c @@ -82,10 +82,10 @@ struct exception_catchpoint : public code_breakpoint _("invalid type-matching regexp"))) { pspace = current_program_space; - re_set (); + re_set (pspace); } - void re_set () override; + void re_set (program_space *pspace) override; enum print_stop_action print_it (const bpstat *bs) const override; bool print_one (const bp_location **) const override; void print_mention () const override; @@ -198,7 +198,7 @@ exception_catchpoint::check_status (struct bpstat *bs) /* Implement the 're_set' method. */ void -exception_catchpoint::re_set () +exception_catchpoint::re_set (program_space *pspace) { std::vector sals; struct program_space *filter_pspace = current_program_space; diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 4343016b6b2..9a7d487981c 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -90,9 +90,12 @@ static void map_breakpoint_numbers (const char *, gdb::function_view); -static void - create_sals_from_location_spec_default (location_spec *locspec, - linespec_result *canonical); +static void parse_breakpoint_sals (location_spec *locspec, + linespec_result *canonical, + program_space *search_pspace); + +static void breakpoint_re_set_one (breakpoint *b, + program_space *filter_pspace); static void create_breakpoints_sal (struct gdbarch *, struct linespec_result *, @@ -220,11 +223,12 @@ static bool strace_marker_p (struct breakpoint *b); static void bkpt_probe_create_sals_from_location_spec (location_spec *locspec, - struct linespec_result *canonical); + struct linespec_result *canonical, + struct program_space *search_pspace); const struct breakpoint_ops code_breakpoint_ops = { - create_sals_from_location_spec_default, + parse_breakpoint_sals, create_breakpoints_sal, }; @@ -289,7 +293,7 @@ struct internal_breakpoint : public code_breakpoint disposition = disp_donttouch; } - void re_set () override; + void re_set (program_space *pspace) override; void check_status (struct bpstat *bs) override; enum print_stop_action print_it (const bpstat *bs) const override; void print_mention () const override; @@ -323,7 +327,7 @@ struct momentary_breakpoint : public code_breakpoint thread = thread_; } - void re_set () override; + void re_set (program_space *pspace) override; void check_status (struct bpstat *bs) override; enum print_stop_action print_it (const bpstat *bs) const override; void print_mention () const override; @@ -334,7 +338,7 @@ struct dprintf_breakpoint : public ordinary_breakpoint { using ordinary_breakpoint::ordinary_breakpoint; - void re_set () override; + void re_set (program_space *pspace) override; int breakpoint_hit (const struct bp_location *bl, const address_space *aspace, CORE_ADDR bp_addr, @@ -1461,7 +1465,36 @@ breakpoint_set_thread (struct breakpoint *b, int thread) b->thread = thread; if (old_thread != thread) - gdb::observers::breakpoint_modified.notify (b); + { + /* If THREAD is in a different program_space than OLD_THREAD, or the + breakpoint has switched to or from being thread-specific, then we + need to re-set the locations of this breakpoint. First, figure + out the program_space for the old and new threads, use a value of + nullptr to indicate the breakpoint is in all program spaces. */ + program_space *old_pspace = nullptr; + if (old_thread != -1) + { + struct thread_info *thr = find_thread_global_id (old_thread); + gdb_assert (thr != nullptr); + old_pspace = thr->inf->pspace; + } + + program_space *new_pspace = nullptr; + if (thread != -1) + { + struct thread_info *thr = find_thread_global_id (thread); + gdb_assert (thr != nullptr); + new_pspace = thr->inf->pspace; + } + + /* If the program space has changed for this breakpoint, then + re-evaluate it's locations. */ + if (old_pspace != new_pspace) + breakpoint_re_set_one (b, new_pspace); + + /* Let others know the breakpoint has changed. */ + gdb::observers::breakpoint_modified.notify (b); + } } /* See breakpoint.h. */ @@ -8626,7 +8659,8 @@ create_breakpoints_sal (struct gdbarch *gdbarch, static void parse_breakpoint_sals (location_spec *locspec, - struct linespec_result *canonical) + struct linespec_result *canonical, + struct program_space *search_pspace) { struct symtab_and_line cursal; @@ -8690,7 +8724,7 @@ parse_breakpoint_sals (location_spec *locspec, && strchr ("+-", spec[0]) != NULL && spec[1] != '[')) { - decode_line_full (locspec, DECODE_LINE_FUNFIRSTLINE, NULL, + decode_line_full (locspec, DECODE_LINE_FUNFIRSTLINE, search_pspace, get_last_displayed_symtab (), get_last_displayed_line (), canonical, NULL, NULL); @@ -8698,7 +8732,7 @@ parse_breakpoint_sals (location_spec *locspec, } } - decode_line_full (locspec, DECODE_LINE_FUNFIRSTLINE, NULL, + decode_line_full (locspec, DECODE_LINE_FUNFIRSTLINE, search_pspace, cursal.symtab, cursal.line, canonical, NULL, NULL); } @@ -8797,6 +8831,24 @@ breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type, } } +/* Return the program space to use as a filter when searching for locations + of a breakpoint specific to THREAD. If THREAD is -1, meaning all + threads, then this function returns nullptr, indicating no program space + filtering should be performed. Otherwise, this function returns the + program space for the inferior that contains THREAD. */ + +static struct program_space * +find_program_space_for_global_thread_id (int thread) +{ + if (thread == -1) + return nullptr; + + struct thread_info *thr = find_thread_global_id (thread); + gdb_assert (thr != nullptr); + gdb_assert (thr->inf != nullptr); + return thr->inf->pspace; +} + /* See breakpoint.h. */ const struct breakpoint_ops * @@ -8890,7 +8942,10 @@ create_breakpoint (struct gdbarch *gdbarch, try { - ops->create_sals_from_location_spec (locspec, &canonical); + struct program_space *search_pspace + = find_program_space_for_global_thread_id (thread); + ops->create_sals_from_location_spec (locspec, &canonical, + search_pspace); } catch (const gdb_exception_error &e) { @@ -9361,7 +9416,7 @@ break_range_command (const char *arg, int from_tty) arg_start = arg; location_spec_up start_locspec = string_to_location_spec (&arg, current_language); - parse_breakpoint_sals (start_locspec.get (), &canonical_start); + parse_breakpoint_sals (start_locspec.get (), &canonical_start, nullptr); if (arg[0] != ',') error (_("Too few arguments.")); @@ -9448,7 +9503,7 @@ watchpoint_exp_is_const (const struct expression *exp) /* Implement the "re_set" method for watchpoints. */ void -watchpoint::re_set () +watchpoint::re_set (struct program_space *pspace) { /* Watchpoint can be either on expression using entirely global variables, or it can be on local variables. @@ -11548,7 +11603,7 @@ breakpoint::print_recreate (struct ui_file *fp) const /* Default breakpoint_ops methods. */ void -code_breakpoint::re_set () +code_breakpoint::re_set (struct program_space *pspace) { /* FIXME: is this still reachable? */ if (breakpoint_location_spec_empty_p (this)) @@ -11558,7 +11613,7 @@ code_breakpoint::re_set () return; } - re_set_default (); + re_set_default (pspace); } int @@ -11764,7 +11819,7 @@ code_breakpoint::decode_location_spec (location_spec *locspec, /* Virtual table for internal breakpoints. */ void -internal_breakpoint::re_set () +internal_breakpoint::re_set (struct program_space *pspace) { switch (type) { @@ -11857,7 +11912,7 @@ internal_breakpoint::print_mention () const /* Virtual table for momentary breakpoints */ void -momentary_breakpoint::re_set () +momentary_breakpoint::re_set (struct program_space *pspace) { /* Keep temporary breakpoints, which can be encountered when we step over a dlopen call and solib_add is resetting the breakpoints. @@ -11898,12 +11953,13 @@ longjmp_breakpoint::~longjmp_breakpoint () static void bkpt_probe_create_sals_from_location_spec (location_spec *locspec, - struct linespec_result *canonical) + struct linespec_result *canonical, + struct program_space *search_pspace) { struct linespec_sals lsal; - lsal.sals = parse_probes (locspec, NULL, canonical); + lsal.sals = parse_probes (locspec, search_pspace, canonical); lsal.canonical = xstrdup (canonical->locspec->to_string ()); canonical->lsals.push_back (std::move (lsal)); } @@ -11993,9 +12049,9 @@ tracepoint::print_recreate (struct ui_file *fp) const } void -dprintf_breakpoint::re_set () +dprintf_breakpoint::re_set (struct program_space *pspace) { - re_set_default (); + re_set_default (pspace); /* extra_string should never be non-NULL for dprintf. */ gdb_assert (extra_string != NULL); @@ -12053,8 +12109,10 @@ dprintf_breakpoint::after_condition_true (struct bpstat *bs) markers (`-m'). */ static void -strace_marker_create_sals_from_location_spec (location_spec *locspec, - struct linespec_result *canonical) +strace_marker_create_sals_from_location_spec + (location_spec *locspec, + struct linespec_result *canonical, + struct program_space *search_pspace) { struct linespec_sals lsal; const char *arg_start, *arg; @@ -12561,12 +12619,32 @@ update_breakpoint_locations (code_breakpoint *b, all locations are in the same shared library, that was unloaded. We'd like to retain the location, so that when the library is loaded again, we don't loose the enabled/disabled status of the - individual locations. */ + individual locations. + + Thread specific breakpoints will also trigger this case if the thread + is changed to a different program space, and all of the old locations + go out of scope. In this case we do (currently) discard the old + locations -- we assume the change in thread is permanent and the old + locations will never come back into scope. */ if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) - return; + { + if (b->thread != -1) + b->clear_locations (); + return; + } bp_location_list existing_locations = b->steal_locations (filter_pspace); + /* If this is a thread-specific breakpoint then any locations left on the + breakpoint are for a program space in which the thread of interest + does not operate. This can happen when the user changes the thread of + a thread-specific breakpoint. + + We assume that the change in thread is permanent, and that the old + locations will never be used again, so discard them now. */ + if (b->thread != -1) + b->clear_locations (); + for (const auto &sal : sals) { struct bp_location *new_loc; @@ -12729,40 +12807,45 @@ code_breakpoint::location_spec_to_sals (location_spec *locspec, locations. */ void -code_breakpoint::re_set_default () +code_breakpoint::re_set_default (struct program_space *filter_pspace) { - struct program_space *filter_pspace = current_program_space; std::vector expanded, expanded_end; - int found; - std::vector sals = location_spec_to_sals (locspec.get (), - filter_pspace, - &found); - if (found) - expanded = std::move (sals); - - if (locspec_range_end != nullptr) - { - std::vector sals_end - = location_spec_to_sals (locspec_range_end.get (), - filter_pspace, &found); + /* If this breakpoint is thread-specific then find the program space in + which the specific thread exists. Otherwise, for breakpoints that are + not thread-specific THREAD_PSPACE will be nullptr. */ + program_space *thread_pspace + = find_program_space_for_global_thread_id (this->thread); + + /* If this is not a thread-specific breakpoint, or it is a + thread-specific breakpoint but we are looking for new locations in the + program space that the specific thread is running, then look for new + locations for this breakpoint. */ + if (thread_pspace == nullptr || filter_pspace == thread_pspace) + { + int found; + std::vector sals + = location_spec_to_sals (locspec.get (), filter_pspace, &found); if (found) - expanded_end = std::move (sals_end); + expanded = std::move (sals); + + if (locspec_range_end != nullptr) + { + std::vector sals_end + = location_spec_to_sals (locspec_range_end.get (), + filter_pspace, &found); + if (found) + expanded_end = std::move (sals_end); + } } + /* Update the locations for this breakpoint. For thread-specific + breakpoints this will remove any old locations that are for the wrong + program space -- this can happen if the user changes the thread of a + thread-specific breakpoint. */ update_breakpoint_locations (this, filter_pspace, expanded, expanded_end); } -/* Default method for creating SALs from an address string. It basically - calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ - -static void -create_sals_from_location_spec_default (location_spec *locspec, - struct linespec_result *canonical) -{ - parse_breakpoint_sals (locspec, canonical); -} - /* Re-set breakpoint locations for the current program space. Locations bound to other program spaces are left untouched. */ @@ -12797,7 +12880,7 @@ breakpoint_re_set (void) { input_radix = b.input_radix; set_language (b.language); - b.re_set (); + b.re_set (current_program_space); } catch (const gdb_exception &ex) { @@ -12818,6 +12901,53 @@ breakpoint_re_set (void) /* Now we can insert. */ update_global_location_list (UGLL_MAY_INSERT); } + +/* Re-set locations for breakpoint B in FILTER_PSPACE. If FILTER_PSPACE is + nullptr then re-set locations for B in all program spaces. Locations + bound to program spaces other than FILTER_PSPACE are left untouched. */ + +static void +breakpoint_re_set_one (breakpoint *b, program_space *filter_pspace) +{ + { + scoped_restore_current_language save_language; + scoped_restore save_input_radix = make_scoped_restore (&input_radix); + scoped_restore_current_pspace_and_thread restore_pspace_thread; + + /* To ::re_set each breakpoint we set the current_language to the + language of the breakpoint before re-evaluating the breakpoint's + location. This change can unfortunately get undone by accident if + the language_mode is set to auto, and we either switch frames, or + more likely in this context, we select the current frame. + + We prevent this by temporarily turning the language_mode to + language_mode_manual. We restore it once all breakpoints + have been reset. */ + scoped_restore save_language_mode = make_scoped_restore (&language_mode); + language_mode = language_mode_manual; + + /* Note: we must not try to insert locations until after all + breakpoints have been re-set. Otherwise, e.g., when re-setting + breakpoint 1, we'd insert the locations of breakpoint 2, which + hadn't been re-set yet, and thus may have stale locations. */ + + try + { + input_radix = b->input_radix; + set_language (b->language); + b->re_set (filter_pspace); + } + catch (const gdb_exception &ex) + { + exception_fprintf (gdb_stderr, ex, + "Error in re-setting breakpoint %d: ", + b->number); + } + } + + /* Now we can insert. */ + update_global_location_list (UGLL_MAY_INSERT); +} /* Reset the thread number of this breakpoint: diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 8abb46b54ad..e5293448536 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -558,15 +558,15 @@ enum print_stop_action struct breakpoint_ops { - /* Create SALs from location spec, storing the result in - linespec_result. - - For an explanation about the arguments, see the function - `create_sals_from_location_spec_default'. + /* Create SALs from LOCSPEC, storing the result in linespec_result + CANONICAL. If SEARCH_PSPACE is not nullptr then only results in the + corresponding program space are returned. If SEARCH_PSPACE is nullptr + then results for all program spaces are returned. This function is called inside `create_breakpoint'. */ void (*create_sals_from_location_spec) (location_spec *locspec, - struct linespec_result *canonical); + linespec_result *canonical, + program_space *search_pspace); /* This method will be responsible for creating a breakpoint given its SALs. Usually, it just calls `create_breakpoints_sal' (for ordinary @@ -698,8 +698,12 @@ struct breakpoint : public intrusive_list_node /* Reevaluate a breakpoint. This is necessary after symbols change (e.g., an executable or DSO was loaded, or the inferior just - started). */ - virtual void re_set () + started). + + FILTER_PSPACE is the program space in which symbols may have changed, + or can be nullptr to indicate that all program spaces may have + changed. */ + virtual void re_set (program_space *filter_pspace) { /* Nothing to re-set. */ } @@ -927,7 +931,7 @@ struct code_breakpoint : public breakpoint /* Add a location for SAL to this breakpoint. */ bp_location *add_location (const symtab_and_line &sal); - void re_set () override; + void re_set (program_space *pspace) override; int insert_location (struct bp_location *) override; int remove_location (struct bp_location *, enum remove_bp_reason reason) override; @@ -949,7 +953,7 @@ struct code_breakpoint : public breakpoint struct program_space *search_pspace); /* Helper method that does the basic work of re_set. */ - void re_set_default (); + void re_set_default (program_space *pspace); /* Find the SaL locations corresponding to the given LOCATION. On return, FOUND will be 1 if any SaL was found, zero otherwise. */ @@ -971,7 +975,7 @@ struct watchpoint : public breakpoint { using breakpoint::breakpoint; - void re_set () override; + void re_set (program_space *pspace) override; int insert_location (struct bp_location *) override; int remove_location (struct bp_location *, enum remove_bp_reason reason) override; diff --git a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp index 4889c31aff3..8cc47537e68 100644 --- a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp +++ b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp @@ -370,7 +370,7 @@ proc test_continue_to_start { mode inf } { "thread $inf.2 stops MI" } else { mi_expect_stop "breakpoint-hit" "child_sub_function" \ - "" "$srcfile" "$decimal" {"" "disp=\"del\"" "locno=\"[0-9]+\""} \ + "" "$srcfile" "$decimal" {"" "disp=\"del\""} \ "thread $inf.2 stops MI" } } diff --git a/gdb/testsuite/gdb.multi/bp-thread-specific.exp b/gdb/testsuite/gdb.multi/bp-thread-specific.exp index 85c08f44a2c..68001e92044 100644 --- a/gdb/testsuite/gdb.multi/bp-thread-specific.exp +++ b/gdb/testsuite/gdb.multi/bp-thread-specific.exp @@ -50,7 +50,7 @@ gdb_test "info threads" \ # locations ('foo' in both inferiors) even though only one of those # locations will ever trigger ('foo' in inferior 2). gdb_test "break foo thread 2.1" \ - "Breakpoint $decimal at $hex: foo\\. \\(2 locations\\)" + "Breakpoint $decimal at $hex: file \[^\r\n\]+$srcfile, line $decimal\\." set bpnum [get_integer_valueof "\$bpnum" "INVALID"] @@ -58,10 +58,7 @@ set bpnum [get_integer_valueof "\$bpnum" "INVALID"] # earlier breakpoint. Check that the thread-id used when describing # the earlier breakpoints is correct. gdb_test "break foo thread 1.1" \ - [multi_line \ - "Note: breakpoint $bpnum \\(thread 2.1\\) also set at pc $hex\\." \ - "Note: breakpoint $bpnum \\(thread 2.1\\) also set at pc $hex\\." \ - "Breakpoint $decimal at $hex: foo\\. \\(2 locations\\)"] + "Breakpoint $decimal at $hex: file \[^\r\n\]+$srcfile, line $decimal\\." # Save the breakpoints into a file. if {[is_remote host]} { diff --git a/gdb/testsuite/gdb.multi/multi-target-continue.exp b/gdb/testsuite/gdb.multi/multi-target-continue.exp index bf19cc00968..a1bffb7b613 100644 --- a/gdb/testsuite/gdb.multi/multi-target-continue.exp +++ b/gdb/testsuite/gdb.multi/multi-target-continue.exp @@ -30,7 +30,7 @@ proc test_continue {non-stop} { proc set_break {inf} { gdb_test "break function${inf} thread ${inf}.1" \ - "Breakpoint .* function${inf}\\..*" + "Breakpoint ${::decimal} at ${::hex}: file .*, line ${::decimal}\\." } # Select inferior INF, and then run to a breakpoint on inferior diff --git a/gdb/testsuite/gdb.multi/multi-target-ping-pong-next.exp b/gdb/testsuite/gdb.multi/multi-target-ping-pong-next.exp index 64645b8ec8a..51fd70b018a 100644 --- a/gdb/testsuite/gdb.multi/multi-target-ping-pong-next.exp +++ b/gdb/testsuite/gdb.multi/multi-target-ping-pong-next.exp @@ -52,12 +52,12 @@ proc test_ping_pong_next {} { gdb_test "thread 1.1" "Switching to thread 1.1 .*" gdb_test "break $srcfile:$line1 thread 1.1" \ - "Breakpoint .*$srcfile:$line1\\..*" + "Breakpoint .*$srcfile, line $line1\\." gdb_test "continue" "hit Breakpoint .*" gdb_test "break $srcfile:$line2 thread 2.1" \ - "Breakpoint .*$srcfile:$line2\\..*" + "Breakpoint .*$srcfile, line $line2\\." # Now block inferior 1 and issue "next". We should stop at the # breakpoint for inferior 2, given schedlock off. diff --git a/gdb/testsuite/gdb.multi/pending-bp.exp b/gdb/testsuite/gdb.multi/pending-bp.exp index 4a65f79cfc4..8e1d1234948 100644 --- a/gdb/testsuite/gdb.multi/pending-bp.exp +++ b/gdb/testsuite/gdb.multi/pending-bp.exp @@ -78,6 +78,48 @@ proc do_test_setup { inf_1_stop inf_2_stop } { return true } +# Create a breakpoint on the function 'foo' in THREAD. It is expected +# that the breakpoint created will be pending, this is checked by +# running the 'info breakpoints' command. +# +# Returns the number for the newly created breakpoint. +proc do_create_pending_foo_breakpoint { {thread "1.1"} } { + gdb_test "break foo thread $thread" \ + [multi_line \ + "Function \"foo\" not defined\\." \ + "Breakpoint $::decimal \\(foo\\) pending\."] \ + "set pending thread-specific breakpoint" + set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \ + "get number for thread-specific breakpoint on foo"] + gdb_test "info breakpoints $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "\\s+stop only in thread [string_to_regexp $thread]"] \ + "check thread-specific breakpoint is initially pending" + + return $bpnum +} + +# Create a breakpoint on the function 'foo' in THREAD. It is expected +# that the breakpoint created will not be pending, this is checked by +# running the 'info breakpoints' command. +# +# Returns the number for the newly created breakpoint. +proc do_create_foo_breakpoint { {thread "1.1"} } { + gdb_test "break foo thread $thread" \ + "Breakpoint $::decimal at $::hex" \ + "set thread-specific breakpoint" + set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \ + "get number for thread-specific breakpoint on foo"] + gdb_test "info breakpoints $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex\\s+\]*> inf $::decimal" \ + "\\s+stop only in thread [string_to_regexp $thread]"] \ + "check thread-specific breakpoint is initially pending" + + return $bpnum +} + # Check that when a breakpoint is in the pending state, but that breakpoint # does have some locations (those locations themselves are pending), GDB # doesn't display the inferior list in the 'info breakpoints' output. @@ -111,5 +153,169 @@ proc_with_prefix test_no_inf_display {} { "check info breakpoints while breakpoint is pending" } +# Setup two inferiors. In #1 the symbol 'foo' has not yet been +# loaded, while in #2 the symbol 'foo' has been loaded. +# +# Create a thread-specific breakpoint on 'foo' tied to a thread in +# inferior #1, the breakpoint should be pending -- 'foo' is not yet +# loaded in #1. +# +# Now move inferior #1 forward until 'foo' is loaded, check the +# breakpoint is no longer pending. +# +# Move inferior #1 forward more until 'foo' is unloaded, check that +# the breakpoint returns to the pending state. +proc_with_prefix test_pending_toggle { } { + + do_test_setup "Break before open" "Break before close" + + set bpnum [do_create_pending_foo_breakpoint] + + # Now return to inferior 1 and continue until the shared library is + # loaded, the breakpoint should become non-pending. + gdb_test "inferior 1" "Switching to inferior 1 .*" \ + "switch back to inferior 1" + gdb_continue_to_breakpoint "stop in foo in inferior 1" "foo \\(\\) .*" + + gdb_test "info breakpoint $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex \]*> inf 1" \ + "\\s+stop only in thread 1\\.1" \ + "\\s+breakpoint already hit 1 time"] \ + "check thread-specific breakpoint is no longer pending" + + gdb_breakpoint [gdb_get_line_number "Break after close"] temporary + gdb_continue_to_breakpoint "close library" + gdb_test "info breakpoints $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "\\s+stop only in thread 1\\.1" \ + "\\s+breakpoint already hit 1 time"] \ + "check thread-specific breakpoint is pending again" +} + +# Create a Python variable VAR and set it to the gdb.Breakpoint object +# corresponding to the breakpoint numbered BPNUM. If THREAD is not +# the empty string then THREAD should be an integer, check that +# gdb.Breakpoint.thread is set to the value of THREAD. Otherwise, if +# THREAD is the empty string, check that gdb.Breakpoint.thread is set +# to None. +proc py_find_breakpoint { var bpnum {thread ""} } { + gdb_test_no_output \ + "python ${var}=\[b for b in gdb.breakpoints() if b.number == $bpnum\]\[0\]" \ + "find Python gdb.Breakpoint object" + if { $thread ne "" } { + gdb_test_no_output "python assert(${var}.thread == ${thread})" \ + "check thread attribute is currently correct" + } else { + gdb_test_no_output "python assert(${var}.thread is None)" \ + "check thread attribute is currently correct" + } +} + +# Setup two inferiors. In #1 the symbol 'foo' has not yet been +# loaded, while in #2 the symbol 'foo' has been loaded. +# +# Create a thread-specific breakpoint on 'foo' tied to a thread in +# inferior #1, the breakpoint should be pending -- 'foo' is not yet +# loaded in #1. +# +# Use Python to change the thread of the thread-specific breakpoint to +# a thread in inferior #2, at this point the thread should gain a +# location and become non-pending. +# +# Set the thread back to a thread in inferior #1, the breakpoint +# should return to the pending state. +proc_with_prefix py_test_toggle_thread {} { + do_test_setup "Break before open" "Break after open" + + set bpnum [do_create_pending_foo_breakpoint] + + py_find_breakpoint "bp" $bpnum 1 + + gdb_test_no_output "python bp.thread = 2" \ + "change thread on thread-specific breakpoint" + gdb_test "info breakpoint $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex \]*> inf 2" \ + "\\s+stop only in thread 2\\.1"] \ + "check thread-specific breakpoint now has a location" + + gdb_test_no_output "set call_count = 2" "set call_count in inferior 2" + gdb_continue_to_breakpoint "stop at foo in inferior 2" "foo \\(\\) .*" + + gdb_test_no_output "python bp.thread = 1" \ + "restore thread on thread-specific breakpoint" + gdb_test "info breakpoints $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "\\s+stop only in thread 1\\.1" \ + "\\s+breakpoint already hit 1 time"] \ + "check thread-specific breakpoint has returned to pending" + + gdb_breakpoint [gdb_get_line_number "Break after close"] temporary + gdb_continue_to_breakpoint "stop after close in inferior 2" \ + ".* Break after close\\. .*" + + gdb_test "inferior 1" "Switching to inferior 1 .*" \ + "switch to inferior 1" + gdb_continue_to_breakpoint "stop at foo in inferior 1" "foo \\(\\) .*" +} + +# Setup two inferiors. Both inferiors have the symbol 'foo' +# available. +# +# Create a thread-specific breakpoint on 'foo' tied to a thread in +# inferior #1, the breakpoint should not be pending, but will only +# have a single location, the location in inferior #1. +# +# Use Python to change the thread of the thread-specific breakpoint to +# None. At this point the breakpoint should gain a second location, a +# location in inferior #2. +proc_with_prefix py_test_clear_thread {} { + do_test_setup "Break after open" "Break after open" + + set bpnum [do_create_foo_breakpoint] + + py_find_breakpoint "bp" $bpnum 1 + + gdb_test_no_output "python bp.thread = None" \ + "clear thread on thread-specific breakpoint" + gdb_test "info breakpoints $bpnum" \ + [multi_line \ + "${bpnum}\\s+breakpoint\\s+keep y\\s+\\s*" \ + "${bpnum}\\.1\\s+y\\s+${::hex}\\s+\]*> inf $::decimal" \ + "${bpnum}\\.2\\s+y\\s+${::hex}\\s+\]*> inf $::decimal"] \ + "check for a location in both inferiors" + + gdb_continue_to_breakpoint "stop at foo in inferior 2" "foo \\(\\) .*" + gdb_test_no_output "set call_count = 2" "set call_count in inferior 2" + + gdb_test "inferior 1" "Switching to inferior 1 .*" \ + "switch to inferior 1" + gdb_continue_to_breakpoint "stop at foo in inferior 1" "foo \\(\\) .*" + gdb_test_no_output "set call_count = 2" "set call_count in inferior 1" + + gdb_test_no_output "python bp.thread = 2" + gdb_test "info breakpoints $bpnum" \ + [multi_line \ + "${bpnum}\\s+breakpoint\\s+keep y\\s+${::hex}\\s+\]*> inf 2" \ + "\\s+stop only in thread 2\\.1" \ + "\\s+breakpoint already hit 2 times"] \ + "check for a location only in inferior 2" + + gdb_breakpoint [gdb_get_line_number "Break after close"] temporary + gdb_continue_to_breakpoint "stop after close in inferior 1" \ + ".* Break after close\\. .*" + + gdb_test "inferior 2" "Switching to inferior 2 .*" \ + "switch back to inferior 2" + gdb_continue_to_breakpoint "stop at foo again in inferior 2" \ + "foo \\(\\) .*" +} + # Run all the tests. test_no_inf_display +test_pending_toggle +py_test_toggle_thread +py_test_clear_thread diff --git a/gdb/testsuite/gdb.multi/tids.exp b/gdb/testsuite/gdb.multi/tids.exp index 18fc4970fe7..34c270309de 100644 --- a/gdb/testsuite/gdb.multi/tids.exp +++ b/gdb/testsuite/gdb.multi/tids.exp @@ -433,11 +433,13 @@ if { [allow_python_tests] } { gdb_py_test_silent_cmd "python bp = gdb.breakpoints()\[0\]" \ "get python breakpoint" 0 - gdb_test "python bp.thread = 6" "thread = 6" \ + gdb_test_no_output "python bp.thread = 6" \ "make breakpoint thread-specific with python" # Check that the inferior-qualified ID is correct. gdb_test "info breakpoint" \ - "stop only in thread 1.3\r\n.*" \ + [multi_line \ + "$decimal\\s+\[^\r\n\]+ in thread_function1 at \[^\r\n\]+" \ + "\\s+stop only in thread 1\\.3"] \ "thread specific breakpoint right thread" } }