From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 359463858C5E for ; Mon, 2 Oct 2023 15:02:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 359463858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696258972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NFgFGWDsti/tDg89JbLtps61KpurrILAZuTk3FfH9FM=; b=EVfZuuAPaL/WJZSsY9JftfjSVLWOyRk9whnQc3/AnV9bRvFExFxgixEk9VtLSu4YpGJhVc wrWYbNyEI33NAdK53O+tJy5gMeb/920x1FCDhJ7q3teEiC96YaCawCgoZH9UuxGEGApQAI gQPewF0WE/V+UN6qyd+5O8ijprqPREI= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-LfnxdOqgOdu1BA_VSB0-EA-1; Mon, 02 Oct 2023 11:02:50 -0400 X-MC-Unique: LfnxdOqgOdu1BA_VSB0-EA-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5219ceead33so13654788a12.2 for ; Mon, 02 Oct 2023 08:02:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696258969; x=1696863769; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G1QKAg62YnvUvUSzKAVlRvXA0OEN0ZriZoexYWvybrE=; b=MgTGR//sYD2bHbIWL50SDmA0okRJ00EwXt7KDdWLYqh57C7b0vGmM1yTvFxa1kCudb rjBkNdzcJvKdd6S4GNkDiQ+ohQGD3bLrRNHPID2rDK5/UC2q9XrMFrW7f5J2KSl/dTgD NH8mIxgwnhraU2DupiKKbUL2uCb2nwFAHb+HJLwRAca2bDAKk/aeGG0qj8elVZatdWqB PS90XrfIQE4AjGlqoCaRaEDkEsJwGyCmXthDAzGNdzIK+Z8WEu9N28isgvUVkT6Yrtyi mKn03mEtbAzx6BypeIgPqQW5Nbi+aeWPjvfiaX+rUwGTrW3Lqh1UkFyd8fvQHBVCG4rJ z70w== X-Gm-Message-State: AOJu0YwbdX4NaRTfucBaH/1gAq8l2cAxfdvAl+Q/3R3w3v8303MzqT/6 mziUpFCES5TqcifrBCLJ0W29tY5RUB5gJyUi3tJE0ih6+zb68hdeP8XwSlcVyqwxvZxnpNLmb7n d2XWvFOPC3NoV/sAsNdQtfA== X-Received: by 2002:aa7:ca41:0:b0:534:78a6:36cb with SMTP id j1-20020aa7ca41000000b0053478a636cbmr8653489edt.39.1696258968013; Mon, 02 Oct 2023 08:02:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOOahserwfNGLmWy4/X5ghPaYPXoxFI9u3gGm1wS9aA+NX9hKDLtUDZOV+t/ePzrTdTml9tA== X-Received: by 2002:aa7:ca41:0:b0:534:78a6:36cb with SMTP id j1-20020aa7ca41000000b0053478a636cbmr8653421edt.39.1696258966673; Mon, 02 Oct 2023 08:02:46 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id s16-20020a05640217d000b0053420e55616sm11205014edy.75.2023.10.02.08.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 08:02:45 -0700 (PDT) From: Andrew Burgess To: Lancelot SIX Cc: gdb-patches@sourceware.org, Eli Zaretskii Subject: Re: [PATCHv4 06/10] gdb: parse pending breakpoint thread/task immediately In-Reply-To: <20230906220616.dg23g3zecaa7l7er@octopus> References: <4ba495dc9505a9d05f3d375f63c0b29176ad696c.1692806099.git.aburgess@redhat.com> <20230906220616.dg23g3zecaa7l7er@octopus> Date: Mon, 02 Oct 2023 16:02:43 +0100 Message-ID: <87leclxe24.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Lancelot SIX writes: > Hi Andrew, > > First, thanks for the patch, I really like what it changes! Lancelot, Thanks for the review, and sorry it's taken me so long to get back around to this work. > > When applying the patch, I get the following warnings from git: > > Applying: gdb: parse pending breakpoint thread/task immediately > .git/rebase-apply/patch:95: indent with spaces. > ^ > .git/rebase-apply/patch:96: indent with spaces. > ptr > .git/rebase-apply/patch:270: indent with spaces. > For the 'if' token we need to capture the entire condition > .git/rebase-apply/patch:271: indent with spaces. > string, so record the start of the condition string and then > .git/rebase-apply/patch:272: indent with spaces. > start scanning backwards looking for the end of the conditio= n > warning: squelched 3 whitespace errors > warning: 8 lines add whitespace errors. > > I have added comments along the patch. I believe these should all be fixed. > > Best, > Lancelot. > > On Wed, Aug 23, 2023 at 04:59:11PM +0100, Andrew Burgess via Gdb-patches = wrote: >> The initial motivation for this commit was to allow thread or 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 to happen in a later commit. >>=20 >> The problem we currently have is that when a thread-specific (or >> inferior-specific) breakpoint is created, the thread (or inferior) >> 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). >>=20 >> 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. >>=20 >> 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, so I can do this: >>=20 >> $ gdb -q ./gdb/testsuite/outputs/gdb.multi/pending-bp/pending-bp >> Reading symbols from ./gdb/testsuite/outputs/gdb.multi/pending-bp/pend= ing-bp... >> (gdb) break foo thread 99 >> Function "foo" not defined. >> Make breakpoint pending on future shared library load? (y or [n]) y >> Breakpoint 1 (foo thread 99) pending. >> (gdb) r >> Starting program: /tmp/gdb/testsuite/outputs/gdb.multi/pending-bp/pend= ing-bp >> [Thread debugging using libthread_db enabled] >> Using host libthread_db library "/lib64/libthread_db.so.1". >> Error in re-setting breakpoint 1: Unknown thread 99. >> [Inferior 1 (process 3329749) exited normally] >> (gdb) >>=20 >> GDB only checked the validity of 'thread 99' at the point the 'foo' >> location became non-pending. In contrast, if I try this: >>=20 >> $ gdb -q ./gdb/testsuite/outputs/gdb.multi/pending-bp/pending-bp >> Reading symbols from ./gdb/testsuite/outputs/gdb.multi/pending-bp/pend= ing-bp... >> (gdb) break main thread 99 >> Unknown thread 99. >> (gdb) >>=20 >> GDB immediately checks if 'thread 99' exists. I think inconsistencies >> like this are confusing, and should be fixed if possible. >>=20 >> In this commit the create_breakpoint function is updated so that the >> extra_string, which contains the thread, inferior, task, and/or >> condition information, is parsed immediately, even for pending >> breakpoints. >>=20 >> Obviously, the condition still can't be validated until the breakpoint >> becomes non-pending, but the thread, inferior, and task information >> can be pulled from the extra-string, and can be validated early on, >> even for pending breakpoints. >>=20 >> There are a couple of benefits to doing this: >>=20 >> 1. Printing of breakpoints is more consistent now. Consider creating >> a conditional breakpoint before this commit: >>=20 >> (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/h= ello.c:18 >> stop only if (0) >> (gdb) >>=20 >> And after this commit: >>=20 >> (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) >>=20 >> Notice that the display of the condition is now the same for the >> pending and non-pending breakpoints. >>=20 >> 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. >>=20 >> 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: >>=20 >> (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) >>=20 >> Notice the 'Error in re-setting breakpoint 2: Unknown thread 2.' >> line, this was triggered when the thread tried to become > ^ > =09=09=09=09 the breakpoint? > >> non-pending, and GDB discovers that the thread no longer exists. >>=20 >> Compare that to the behaviour after this commit: >>=20 >> (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 thr= ead list. >> [Inferior 1 (process 2949240) exited normally] >> (gdb) >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >> Reviewed-By: Eli Zaretskii >> --- >> gdb/Makefile.in | 2 + >> gdb/NEWS | 4 + >> gdb/break-cond-parse.c | 425 ++++++++++++++++++ >> gdb/break-cond-parse.h | 49 ++ >> gdb/breakpoint.c | 374 ++++----------- >> gdb/testsuite/gdb.ada/tasks.exp | 6 +- >> 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.multi/inferior-specific-bp.exp | 4 +- >> .../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 +++++ >> 14 files changed, 826 insertions(+), 303 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 >>=20 >> diff --git a/gdb/Makefile.in b/gdb/Makefile.in >> index 9b992a3d8c0..43b867cd796 100644 >> --- a/gdb/Makefile.in >> +++ b/gdb/Makefile.in >> @@ -1026,6 +1026,7 @@ COMMON_SFILES =3D \ >> =09break-catch-sig.c \ >> =09break-catch-syscall.c \ >> =09break-catch-throw.c \ >> +=09break-cond-parse.c \ >> =09breakpoint.c \ >> =09bt-utils.c \ >> =09btrace.c \ >> @@ -1293,6 +1294,7 @@ HFILES_NO_SRCDIR =3D \ >> =09bfd-target.h \ >> =09bfin-tdep.h \ >> =09block.h \ >> +=09break-cond-parse.h \ >> =09breakpoint.h \ >> =09bsd-kvm.h \ >> =09bsd-uthread.h \ >> diff --git a/gdb/NEWS b/gdb/NEWS >> index c4b1f7a7e3b..7c38ecb8b46 100644 >> --- a/gdb/NEWS >> +++ b/gdb/NEWS >> @@ -105,6 +105,10 @@ >> 'inferior' keyword with either the 'thread' or 'task' keywords when >> creating a breakpoint. >> =20 >> +* 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 >> =20 >> set debug breakpoint on|off >> diff --git a/gdb/break-cond-parse.c b/gdb/break-cond-parse.c >> new file mode 100644 >> index 00000000000..ebe67c90736 >> --- /dev/null >> +++ b/gdb/break-cond-parse.c >> @@ -0,0 +1,425 @@ >> +/* 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 > > Initial indentation with tabs here. > >> + >> + Parsing 'forward' will return the token 'GHI' and update 'ptr' to po= int >> + 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 ne= w >> + 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 p= oint >> + into the same C style string (i.e. there should be no null charact= er >> + between START and END). END must be equal to, or greater than STA= RT, >> + 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 >=3D 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; > > Note here that since we know that m_end >=3D m_start (this is asserted in > the ctor), length must return at least 1. It cannot be 0 (this will > become relevant later). Thanks, I've fixes all the length zero checks you pointed out. > >> + } >> + >> + /* Return true if this token matches STR. If this token is shorter t= han >> + STR then only a partial match is performed and true will be return= ed >> + if the token length sub-string matches. Otherwise, return false. = */ > > I am not sure that partial matching here was a good choice of the > initial implementation (you did not change this). The token you are > interested in here are matched entirely when parsing the locdesc > (linespec_lexer_lex_keyword), doing partial matching seems inconsistent. > See later comments for further details. > >> + bool matches (const char *str) const >> + { >> + return strncmp (m_start, str, length ()) =3D=3D 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 =3D=3D parse_direction::forward) >> + { >> + *curr =3D skip_spaces (*curr); >> + tok_start =3D *curr; >> + *curr =3D skip_to_space (*curr); >> + tok_end =3D *curr - 1; >> + } >> + else >> + { >> + gdb_assert (direction =3D=3D parse_direction::backward); >> + >> + while (isspace (**curr)) >> +=09--(*curr); >> + >> + tok_end =3D *curr; >> + >> + while (!isspace (**curr)) >> +=09--(*curr); >> + >> + tok_start =3D (*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 *inferior, int *task, >> + gdb::unique_xmalloc_ptr *rest, bool *force) >> +{ >> + /* Set up the defaults. */ >> + cond_string->reset (); >> + rest->reset (); >> + *thread =3D -1; >> + *inferior =3D -1; >> + *task =3D -1; >> + *force =3D false; >> + >> + if (tok =3D=3D nullptr) >> + return; >> + >> + const char *cond_start =3D nullptr; >> + const char *cond_end =3D nullptr; >> + parse_direction direction =3D parse_direction::forward; >> + while (*tok !=3D '\0') >> + { >> + /* Find the next token. If moving backward and this token starts= at >> +=09 the same location as the condition then we must have found the >> +=09 other end of the condition string -- we're done. */ >> + token t =3D find_next_token (&tok, direction); >> + if (direction =3D=3D parse_direction::backward && t.start () <=3D= cond_start) >> +=09{ >> +=09 cond_end =3D t.end () + 1; >> +=09 break; >> +=09} >> + >> + /* We only have a single flag option to check for. All the other >> +=09 options take a value so require an additional token to be found. *= / >> + if (t.length () > 0 && t.matches ("-force-condition")) > > First thing, as mentioned above, I don=E2=80=99t think that "t.length () = > 0" > can ever be false, so this part of the test can safely be removed. > > Also, it seems to be a new behavior linked to the fact that you don=E2=80= =99t > use "parse_exp_1" anymore. Before this patch, "-force-condition" could > not really be placed after the condition (at least with C/C++ as current > language) as the expression parser would try to consume it. Now it can > be partially matched, which can give surprising results. > > Doing > > break foo if 0 - > > is now interpreted as > > break foo if 0 -force-condition > > this used to be an error. I've added a t.length() check here to ensure that only a token of length 2 or more will match -force-condition, i.e. '-f' is OK, but '-' is not. > > Similarly, doing > > break foo if var -f > > used to be interpreted as > > break foo if (var - f) > > which could be valid if "var" and "f" are valid, but with the patch it > now interprets it as > > break foo if var -force-condition > > I don=E2=80=99t expect many users will ever notice such change in behavio= r, > but overall I=C2=A0would find that it makes more sense to only match > "-force-condition" entirely. > > This would be consistent with the parsing behavior if -force-condition > is placed before the condition. In such case, > linespec_lexer_lex_keyword only does a full match. There's two issues here, partial matching, which I'll discuss later on in this reply. But there's also the choice of how to handle -force-condition immediately after the condition string. As you point out, -force-condition immediately after the condition string is handled as part of the condition string, while this cut of the patch changes that. I'd like this patch to focus on just restructuring the code, and bringing in those changes which I think are an essential consequence of the restructure. This is things like the say the pending breakpoint is announced and displayed to the user, or that the thread is checked as soon as the breakpoint is created. These changes are "core" to this patch. In contrast, the handling of -force-condition is just a random consequence of the implementation. As such, in the updated patch which I'll post soon I've made a minor change which restores the old handling of -force-condition. That said, I think the points you raised are good ones, and I think more consistent handling of -force-condition would be a good improvement. But I'd like to make that change as part of a later patch (series). > > >> +=09{ >> +=09 *force =3D true; >> +=09 continue; >> +=09} >> + >> + /* Maybe the first token was the last token in the string. If th= is >> +=09 is the case then we definitely can't try to extract a value >> +=09 token. This also means that the token T is meaningless. Reset >> +=09 TOK to point at the start of the unknown content and break out of >> +=09 the loop. We'll record the unknown part of the string outside of >> +=09 the scanning loop (below). */ >> + if (direction =3D=3D parse_direction::forward && *tok =3D=3D '\0'= ) >> +=09{ >> +=09 tok =3D t.start (); >> +=09 break; >> +=09} >> + >> + /* As before, find the next token and, if we are scanning backwar= ds, >> +=09 check that we have not reached the start of the condition string. = */ >> + token v =3D find_next_token (&tok, direction); >> + if (direction =3D=3D parse_direction::backward && v.start () <=3D= cond_start) >> +=09{ >> +=09 /* Use token T here as that must also be part of the condition >> +=09 string. */ >> +=09 cond_end =3D t.end () + 1; >> +=09 break; >> +=09} >> + >> + /* When moving backward we will first parse the value token then = the >> +=09 keyword token, so swap them now. */ >> + if (direction =3D=3D parse_direction::backward) >> +=09std::swap (t, v); >> + >> + /* Check for valid option in token T. If we find a valid option = then >> +=09 parse the value from the token V. Except for 'if', that's handled >> +=09 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. */ > > Initial indentation with tabs here. > >> + if (direction =3D=3D parse_direction::forward && t.length () > 0 > > dito for t.length > >> +=09 && t.matches ("if")) >> +=09{ >> +=09 cond_start =3D v.start (); >> +=09 tok =3D tok + strlen (tok); >> +=09 gdb_assert (*tok =3D=3D '\0'); >> +=09 --tok; >> +=09 direction =3D parse_direction::backward; >> +=09 continue; >> +=09} >> + else if (t.length () > 0 && t.matches ("thread")) > > dito for t.length > > > Also, > > b foo if 0 t 1 > > is ambiguous. The "t" could match both "task" and "thread", and it > really is an implementation detail that "thread" is tested first. > > This ambiguity used to exist before the patch. > > However, since parsing "thread" or "task" just after the linespec does > not accept partial matches, and it does not look that partial matching > has ever been documented, I=E2=80=99d be in favor of just removing partia= l > matching. It's not documented, but, as you point out later, it is tested for, so changing this would be a change in behaviour. Also, it really is a bit of a mess, e.g. as you suggest, this is invalid: (gdb) break main th 1 However, this is valid: (gdb) break *main th 1 Yeah, this is a bit of a mess. Like I said earlier, I don't really want to tie this patch up with trying to sort this out, so my ideal solution is to leave the behaviour as-is for now. But, that doesn't mean that I think you are wrong, I'm inclined to agree with you. In my updated series (I'll post it soon) I've added comments to point out that the thread / task parsing order is important because of the abbreviations, but otherwise I've left the behaviour as is. > > WDYT? > >> +=09{ >> +=09 const char *tmptok; >> +=09 struct thread_info *thr; >> + >> +=09 if (*thread !=3D -1) >> +=09 error(_("You can specify only one thread.")); >> + >> +=09 if (*task !=3D -1 || *inferior !=3D -1) >> +=09 error (_("You can specify only one of thread, inferior, or task.= ")); >> + >> +=09 thr =3D parse_thread_id (v.start (), &tmptok); >> +=09 const char *expected_end =3D skip_spaces (v.end () + 1); >> +=09 if (tmptok !=3D expected_end) >> +=09 error (_("Junk after thread keyword.")); >> +=09 *thread =3D thr->global_num; >> +=09} >> + else if (t.length () > 0 && t.matches ("inferior")) > > dito for t.length > >> +=09{ >> +=09 char *tmptok; >> + >> +=09 if (*inferior !=3D -1) >> +=09 error(_("You can specify only one inferior.")); >> + >> +=09 if (*task !=3D -1 || *thread !=3D -1) >> +=09 error (_("You can specify only one of thread, inferior, or task.= ")); >> + >> +=09 *inferior =3D strtol (v.start (), &tmptok, 0); >> +=09 const char *expected_end =3D v.end () + 1; >> +=09 if (tmptok !=3D expected_end) >> +=09 error (_("Junk after inferior keyword.")); >> +=09} >> + else if (t.length () > 0 && t.matches ("task")) > > dito for t.length > >> +=09{ >> +=09 char *tmptok; >> + >> +=09 if (*task !=3D -1) >> +=09 error(_("You can specify only one task.")); >> + >> +=09 if (*thread !=3D -1 || *inferior !=3D -1) >> +=09 error (_("You can specify only one of thread, inferior, or task.= ")); >> + >> +=09 *task =3D strtol (v.start (), &tmptok, 0); >> +=09 const char *expected_end =3D v.end () + 1; >> +=09 if (tmptok !=3D expected_end) >> +=09 error (_("Junk after task keyword.")); >> +=09 if (!valid_task_id (*task)) >> +=09 error (_("Unknown task %d."), *task); >> +=09} >> + else >> +=09{ >> +=09 /* An unknown token. If we are scanning forward then reset TOK >> +=09 to point at the start of the unknown content, we record this >> +=09 outside of the scanning loop (below). >> + >> +=09 If we are scanning backward then unknown content is assumed to >> +=09 be the other end of the condition string, obviously, this is >> +=09 just a heuristic, we could be looking at a mistyped command >> +=09 line, but this will be spotted when the condition is >> +=09 eventually evaluated. >> + >> +=09 Either way, no more scanning is required after this. */ >> +=09 if (direction =3D=3D parse_direction::forward) >> +=09 tok =3D t.start (); >> +=09 else >> +=09 { >> +=09 gdb_assert (direction =3D=3D parse_direction::backward); >> +=09 cond_end =3D v.end () + 1; >> +=09 } >> +=09 break; >> +=09} >> + } >> + >> + if (cond_start !=3D nullptr) >> + { >> + /* If we found the start of a condition string then we should hav= e >> +=09 switched to backward scan mode, and found the end of the condition >> +=09 string. Capture the whole condition string into COND_STRING now. = */ >> + gdb_assert (direction =3D=3D parse_direction::backward); >> + gdb_assert (cond_end !=3D nullptr); >> + cond_string->reset (savestring (cond_start, cond_end - cond_start= )); >> + } >> + else if (*tok !=3D '\0') >> + { >> + /* If we didn't have a condition start pointer then we should sti= ll >> +=09 be in forward scanning mode. If we didn't reach the end of the >> +=09 input string (TOK is not at the null character) then the rest of >> +=09 the input string is garbage that we didn't understand. >> + >> +=09 Record the unknown content into REST. The caller of this function >> +=09 will report this as an error later on. We could report the error >> +=09 here, but we prefer to allow the caller to run other checks, and >> +=09 prioritise other errors before reporting this problem. */ >> + gdb_assert (direction =3D=3D 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 othe= r >> + arguments are the expected output from >> + create_breakpoint_parse_arg_string. */ >> + >> +static void >> +test (const char *input, const char *condition, int thread =3D -1, >> + int inferior =3D -1, int task =3D -1, bool force =3D false, >> + const char *rest =3D nullptr) >> +{ >> + gdb::unique_xmalloc_ptr extracted_condition; >> + gdb::unique_xmalloc_ptr extracted_rest; >> + int extracted_thread, extracted_inferior, extracted_task; >> + bool extracted_force_condition; >> + std::string exception_msg; >> + >> + try >> + { >> + create_breakpoint_parse_arg_string (input, &extracted_condition, >> +=09=09=09=09=09 &extracted_thread, >> +=09=09=09=09=09 &extracted_inferior, >> +=09=09=09=09=09 &extracted_task, &extracted_rest, >> +=09=09=09=09=09 &extracted_force_condition); >> + } >> + catch (const gdb_exception_error &ex) >> + { >> + string_file buf; >> + >> + exception_print (&buf, ex); >> + exception_msg =3D buf.release (); >> + } >> + >> + if ((condition =3D=3D nullptr) !=3D (extracted_condition.get () =3D= =3D nullptr) >> + || (condition !=3D nullptr >> +=09 && strcmp (condition, extracted_condition.get ()) !=3D 0) >> + || (rest =3D=3D nullptr) !=3D (extracted_rest.get () =3D=3D nullp= tr) >> + || (rest !=3D nullptr && strcmp (rest, extracted_rest.get ()) != =3D 0) >> + || thread !=3D extracted_thread >> + || inferior !=3D extracted_inferior >> + || task !=3D extracted_task >> + || force !=3D extracted_force_condition >> + || !exception_msg.empty ()) >> + { >> + if (run_verbose ()) >> +=09{ >> +=09 debug_printf ("input: '%s'\n", input); >> +=09 debug_printf ("condition: '%s'\n", extracted_condition.get ()); >> +=09 debug_printf ("rest: '%s'\n", extracted_rest.get ()); >> +=09 debug_printf ("thread: %d\n", extracted_thread); >> +=09 debug_printf ("inferior: %d\n", extracted_inferior); >> +=09 debug_printf ("task: %d\n", extracted_task); >> +=09 debug_printf ("forced: %s\n", >> +=09=09=09extracted_force_condition ? "true" : "false"); >> +=09 debug_printf ("exception: '%s'\n", exception_msg.c_str ()); >> +=09} >> + >> + /* 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 =3D current_inferior ()->gdbarch; >> + scoped_restore_current_pspace_and_thread restore; >> + scoped_mock_context mock_target (arch); >> + >> + int global_thread_num =3D mock_target.mock_thread.global_num; >> + >> + test (" if blah ", "blah"); >> + test (" if blah thread 1", "blah", global_thread_num); >> + test (" if blah inferior 1", "blah", -1, 1); >> + test (" if blah thread 1 ", "blah", global_thread_num); >> + test ("thread 1 woof", nullptr, global_thread_num, -1, -1, false, "wo= of"); >> + test ("thread 1 X", nullptr, global_thread_num, -1, -1, false, "X"); >> + test (" if blah thread 1 -force-condition", "blah", global_thread_num= , >> +=09-1, -1, true); >> + test (" -force-condition if blah thread 1", "blah", global_thread_num= , >> +=09-1, -1, true); >> + test (" -force-condition if blah thread 1 ", "blah", global_thread_n= um, >> +=09-1, -1, true); >> + test ("thread 1 -force-condition if blah", "blah", global_thread_num, >> +=09-1, -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..b08b6fc6cc9 >> --- /dev/null >> +++ b/gdb/break-cond-parse.h >> @@ -0,0 +1,49 @@ >> +/* 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, inferio= r, >> + task and force-condition flag, as accepted by the 'break' command, >> + extract the condition string, thread, inferior, task number, and the >> + force_condition flag, then set *COND_STRING, *THREAD, *INFERIOR, *TA= SK, >> + and *FORCE. >> + >> + As TOK is parsed, if an unknown keyword is encountered before the 'i= f' >> + 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 inferior is foun= d, >> + *INFERIOR is set to -1. If no task is found, *TASK is set to -1. I= f >> + 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 'threa= d' >> + 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 *inferior, int *task, >> + gdb::unique_xmalloc_ptr *rest, bool *force); >> + >> +#endif >> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c >> index 5a608ba2495..50225f55522 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" >> =20 >> /* readline include files */ >> #include "readline/tilde.h" >> @@ -6340,20 +6341,7 @@ print_breakpoint_location (const breakpoint *b, c= onst 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 >> -=09 or dprintf arguments. In either case, make sure it is printed, >> -=09 too, but only for non-MI streams. */ >> - if (!uiout->is_mi_like_p () && b->extra_string !=3D NULL) >> -=09{ >> -=09 if (b->type =3D=3D bp_dprintf) >> -=09 uiout->text (","); >> -=09 else >> -=09 uiout->text (" "); >> -=09 uiout->text (b->extra_string.get ()); >> -=09} >> - } >> + uiout->field_string ("pending", b->locspec->to_string ()); >> =20 >> if (loc && is_breakpoint (b) >> && breakpoint_condition_evaluation_mode () =3D=3D condition_evalu= ation_target >> @@ -8718,8 +8706,8 @@ code_breakpoint::code_breakpoint (struct gdbarch *= gdbarch_, >> gdb_assert (extra_string !=3D nullptr); >> update_dprintf_command_list (this); >> } >> - else if (extra_string !=3D nullptr) >> - error (_("Garbage '%s' at end of command"), extra_string.get ()); >> + else >> + gdb_assert (extra_string =3D=3D nullptr); >> =20 >> /* The order of the locations is now stable. Set the location >> condition using the location's number. */ >> @@ -8947,197 +8935,6 @@ check_fast_tracepoint_sals (struct gdbarch *gdba= rch, >> } >> } >> =20 >> -/* Given TOK, a string specification of condition and thread, as accept= ed >> - by the 'break' command, extract the condition string into *COND_STRI= NG. >> - If no condition string is found then *COND_STRING is set to nullptr. >> - >> - If the breakpoint specification has an associated thread, task, or >> - inferior, these are extracted into *THREAD, *TASK, and *INFERIOR >> - respectively, otherwise these arguments are set to -1 (for THREAD an= d >> - INFERIOR) or 0 (for TASK). >> - >> - PC identifies the context at which the condition should be parsed. = */ >> - >> -static void >> -find_condition_and_thread (const char *tok, CORE_ADDR pc, >> -=09=09=09 gdb::unique_xmalloc_ptr *cond_string, >> -=09=09=09 int *thread, int *inferior, int *task, >> -=09=09=09 gdb::unique_xmalloc_ptr *rest) >> -{ >> - cond_string->reset (); >> - *thread =3D -1; >> - *inferior =3D -1; >> - *task =3D -1; >> - rest->reset (); >> - bool force =3D false; >> - >> - while (tok && *tok) >> - { >> - const char *end_tok; >> - int toklen; >> - const char *cond_start =3D NULL; >> - const char *cond_end =3D NULL; >> - >> - tok =3D skip_spaces (tok); >> - >> - if ((*tok =3D=3D '"' || *tok =3D=3D ',') && rest) >> -=09{ >> -=09 rest->reset (savestring (tok, strlen (tok))); >> -=09 break; >> -=09} >> - >> - end_tok =3D skip_to_space (tok); >> - >> - toklen =3D end_tok - tok; >> - >> - if (toklen >=3D 1 && strncmp (tok, "if", toklen) =3D=3D 0) >> -=09{ >> -=09 tok =3D cond_start =3D end_tok + 1; >> -=09 try >> -=09 { >> -=09 parse_exp_1 (&tok, pc, block_for_pc (pc), 0); >> -=09 } >> -=09 catch (const gdb_exception_error &) >> -=09 { >> -=09 if (!force) >> -=09=09throw; >> -=09 else >> -=09=09tok =3D tok + strlen (tok); >> -=09 } >> -=09 cond_end =3D tok; >> -=09 cond_string->reset (savestring (cond_start, cond_end - cond_start)= ); >> -=09} >> - else if (toklen >=3D 1 && strncmp (tok, "-force-condition", tokle= n) =3D=3D 0) >> -=09{ >> -=09 tok =3D tok + toklen; >> -=09 force =3D true; >> -=09} >> - else if (toklen >=3D 1 && strncmp (tok, "thread", toklen) =3D=3D = 0) >> -=09{ >> -=09 const char *tmptok; >> -=09 struct thread_info *thr; >> - >> -=09 if (*thread !=3D -1) >> -=09 error(_("You can specify only one thread.")); >> - >> -=09 if (*task !=3D -1) >> -=09 error (_("You can specify only one of thread or task.")); >> - >> -=09 if (*inferior !=3D -1) >> -=09 error (_("You can specify only one of inferior or thread.")); >> - >> -=09 tok =3D end_tok + 1; >> -=09 thr =3D parse_thread_id (tok, &tmptok); >> -=09 if (tok =3D=3D tmptok) >> -=09 error (_("Junk after thread keyword.")); >> -=09 *thread =3D thr->global_num; >> -=09 tok =3D tmptok; >> -=09} >> - else if (toklen >=3D 1 && strncmp (tok, "inferior", toklen) =3D= =3D 0) >> -=09{ >> -=09 if (*inferior !=3D -1) >> -=09 error(_("You can specify only one inferior.")); >> - >> -=09 if (*task !=3D -1) >> -=09 error (_("You can specify only one of inferior or task.")); >> - >> -=09 if (*thread !=3D -1) >> -=09 error (_("You can specify only one of inferior or thread.")); >> - >> -=09 char *tmptok; >> -=09 tok =3D end_tok + 1; >> -=09 *inferior =3D strtol (tok, &tmptok, 0); >> -=09 if (tok =3D=3D tmptok) >> -=09 error (_("Junk after inferior keyword.")); >> -=09 if (!valid_global_inferior_id (*inferior)) >> -=09 error (_("Unknown inferior number %d."), *inferior); >> -=09 tok =3D tmptok; >> -=09} >> - else if (toklen >=3D 1 && strncmp (tok, "task", toklen) =3D=3D 0) >> -=09{ >> -=09 char *tmptok; >> - >> -=09 if (*task !=3D -1) >> -=09 error(_("You can specify only one task.")); >> - >> -=09 if (*thread !=3D -1) >> -=09 error (_("You can specify only one of thread or task.")); >> - >> -=09 if (*inferior !=3D -1) >> -=09 error (_("You can specify only one of inferior or task.")); >> - >> -=09 tok =3D end_tok + 1; >> -=09 *task =3D strtol (tok, &tmptok, 0); >> -=09 if (tok =3D=3D tmptok) >> -=09 error (_("Junk after task keyword.")); >> -=09 if (!valid_task_id (*task)) >> -=09 error (_("Unknown task %d."), *task); >> -=09 tok =3D tmptok; >> -=09} >> - else if (rest) >> -=09{ >> -=09 rest->reset (savestring (tok, strlen (tok))); >> -=09 break; >> -=09} >> - else >> -=09error (_("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, >> -=09=09=09=09 const char *input, >> -=09=09=09=09 gdb::unique_xmalloc_ptr *cond_string, >> -=09=09=09=09 int *thread, int *inferior, int *task, >> -=09=09=09=09 gdb::unique_xmalloc_ptr *rest) >> -{ >> - int num_failures =3D 0; >> - for (auto &sal : sals) >> - { >> - gdb::unique_xmalloc_ptr cond; >> - int thread_id =3D -1; >> - int inferior_id =3D -1; >> - int task_id =3D -1; >> - gdb::unique_xmalloc_ptr remaining; >> - >> - /* Here we want to parse 'arg' to separate condition from thread >> -=09 number. But because parsing happens in a context and the >> -=09 contexts of sals might be different, try each until there is >> -=09 success. Finding one successful parse is sufficient for our >> -=09 goal. When setting the breakpoint we'll re-parse the >> -=09 condition in the context of each sal. */ >> - try >> -=09{ >> -=09 find_condition_and_thread (input, sal.pc, &cond, &thread_id, >> -=09=09=09=09 &inferior_id, &task_id, &remaining); >> -=09 *cond_string =3D std::move (cond); >> -=09 /* A value of -1 indicates that these fields are unset. At most >> -=09 one of these fields should be set (to a value other than -1) >> -=09 at this point. */ >> -=09 gdb_assert (((thread_id =3D=3D -1 ? 1 : 0) >> -=09=09 + (task_id =3D=3D -1 ? 1 : 0) >> -=09=09 + (inferior_id =3D=3D -1 ? 1 : 0)) >=3D 2); >> -=09 *thread =3D thread_id; >> -=09 *inferior =3D inferior_id; >> -=09 *task =3D task_id; >> -=09 *rest =3D std::move (remaining); >> -=09 break; >> -=09} >> - catch (const gdb_exception_error &e) >> -=09{ >> -=09 num_failures++; >> -=09 /* If no sal remains, do not continue. */ >> -=09 if (num_failures =3D=3D sals.size ()) >> -=09 throw; >> -=09} >> - } >> -} >> - >> /* Decode a static tracepoint marker spec. */ >> =20 >> static std::vector >> @@ -9255,6 +9052,46 @@ create_breakpoint (struct gdbarch *gdbarch, >> =09 || (type_wanted !=3D bp_dprintf >> =09=09 && (extra_string =3D=3D nullptr || parse_extra))); >> =20 >> + /* Will hold either copies of the similarly named function argument, = or >> + will hold a modified version of the function argument, depending o= n >> + 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_co= py, >> +=09=09=09=09=09 &thread, &inferior, &task, >> +=09=09=09=09=09 &extra_string_copy, >> +=09=09=09=09=09 &force_condition); >> + >> + /* We could check that EXTRA_STRING_COPY is empty at this point -= - it >> +=09 should be, as we only get here for things that are not bp_dprintf, >> +=09 however, we prefer to give the location spec parser a chance to >> +=09 run first, this means the user will get errors about invalid >> +=09 location spec instead of an error about garbage at the end of the >> +=09 command line. >> + >> +=09 We still do the EXTRA_STRING_COPY is empty check, just later in >> +=09 this function. */ >> + >> + gdb_assert (thread =3D=3D -1 || thread > 0); >> + gdb_assert (task =3D=3D -1 || task > 0); >> + gdb_assert (inferior =3D=3D -1 || inferior > 0); >> + } >> + else >> + { >> + if (cond_string !=3D nullptr) >> +=09cond_string_copy.reset (xstrdup (cond_string)); >> + if (extra_string !=3D nullptr) >> +=09extra_string_copy.reset (xstrdup (extra_string)); >> + } >> + >> + /* Clear these. Updated values are now held in the *_copy locals. *= / >> + cond_string =3D nullptr; >> + extra_string =3D nullptr; >> + >> try >> { >> ops->create_sals_from_location_spec (locspec, &canonical); >> @@ -9290,6 +9127,13 @@ create_breakpoint (struct gdbarch *gdbarch, >> =09throw; >> } >> =20 >> + /* The only bp_dprintf should have anything in EXTRA_STRING_COPY by t= his >> + point. For all other breakpoints this indicates an error. We cou= ld >> + place this check earlier in the function, but we prefer to see err= ors >> + from the location spec parser before we see this error message. *= / >> + if (type_wanted !=3D bp_dprintf && extra_string_copy.get () !=3D null= ptr) >> + error (_("Garbage '%s' at end of command"), extra_string_copy.get (= )); >> + >> if (!pending && canonical.lsals.empty ()) >> return 0; >> =20 >> @@ -9313,63 +9157,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 t= he >> +=09 condition is invalid at all of the locations and if it is not >> +=09 forced. In the PARSE_EXTRA case above, this check is done when >> +=09 parsing the EXTRA_STRING. */ >> + if (cond_string_copy.get () !=3D nullptr && !force_condition) >> =09{ >> -=09 gdb_assert (type_wanted !=3D bp_dprintf); >> - >> -=09 gdb::unique_xmalloc_ptr rest; >> -=09 gdb::unique_xmalloc_ptr cond; >> - >> -=09 const linespec_sals &lsal =3D canonical.lsals[0]; >> - >> -=09 find_condition_and_thread_for_sals (lsal.sals, extra_string, >> -=09=09=09=09=09 &cond, &thread, &inferior, >> -=09=09=09=09=09 &task, &rest); >> - >> -=09 if (rest.get () !=3D nullptr && *(rest.get ()) !=3D '\0') >> -=09 error (_("Garbage '%s' at end of command"), rest.get ()); >> - >> -=09 cond_string_copy =3D std::move (cond); >> -=09 extra_string_copy =3D std::move (rest); >> -=09} >> - else >> -=09{ >> -=09 /* Check the validity of the condition. We should error out >> -=09 if the condition is invalid at all of the locations and >> -=09 if it is not forced. In the PARSE_EXTRA case above, this >> -=09 check is done when parsing the EXTRA_STRING. */ >> -=09 if (cond_string !=3D nullptr && !force_condition) >> +=09 int num_failures =3D 0; >> + const linespec_sals &lsal =3D canonical.lsals[0]; > > Indentation issue. > >> +=09 for (const auto &sal : lsal.sals) >> =09 { >> -=09 int num_failures =3D 0; >> -=09 const linespec_sals &lsal =3D canonical.lsals[0]; >> -=09 for (const auto &sal : lsal.sals) >> +=09 const char *cond =3D cond_string_copy.get (); >> +=09 try >> =09=09{ >> -=09=09 const char *cond =3D cond_string; >> -=09=09 try >> -=09=09 { >> -=09=09 parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0); >> -=09=09 /* One success is sufficient to keep going. */ >> -=09=09 break; >> -=09=09 } >> -=09=09 catch (const gdb_exception_error &) >> -=09=09 { >> -=09=09 num_failures++; >> -=09=09 /* If this is the last sal, error out. */ >> -=09=09 if (num_failures =3D=3D lsal.sals.size ()) >> -=09=09=09throw; >> -=09=09 } >> +=09=09 parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0); >> +=09=09 /* One success is sufficient to keep going. */ >> +=09=09 break; >> +=09=09} >> +=09 catch (const gdb_exception_error &) >> +=09=09{ >> +=09=09 num_failures++; >> +=09=09 /* If this is the last sal, error out. */ >> +=09=09 if (num_failures =3D=3D lsal.sals.size ()) >> +=09=09 throw; >> =09=09} >> =09 } >> - >> -=09 /* Create a private copy of condition string. */ >> -=09 if (cond_string) >> -=09 cond_string_copy.reset (xstrdup (cond_string)); >> -=09 /* Create a private copy of any extra string. */ >> -=09 if (extra_string) >> -=09 extra_string_copy.reset (xstrdup (extra_string)); >> =09} >> =20 >> ops->create_breakpoints_sal (gdbarch, &canonical, >> @@ -9386,21 +9198,16 @@ create_breakpoint (struct gdbarch *gdbarch, >> =09=09=09=09=09=09=09=09 type_wanted); >> b->locspec =3D locspec->clone (); >> =20 >> - if (parse_extra) >> -=09b->cond_string =3D NULL; >> - else >> -=09{ >> -=09 /* Create a private copy of condition string. */ >> -=09 b->cond_string.reset (cond_string !=3D NULL >> -=09=09=09=09? xstrdup (cond_string) >> -=09=09=09=09: NULL); >> -=09 b->thread =3D thread; >> -=09} >> + /* Create a private copy of the condition string. */ >> + b->cond_string =3D std::move (cond_string_copy); >> + >> + b->thread =3D thread; >> + b->task =3D task; >> + b->inferior =3D inferior; >> =20 >> /* Create a private copy of any extra string. */ >> - b->extra_string.reset (extra_string !=3D NULL >> -=09=09=09 ? xstrdup (extra_string) >> -=09=09=09 : NULL); >> + b->extra_string =3D std::move (extra_string_copy); >> + >> b->ignore_count =3D ignore_count; >> b->disposition =3D tempflag ? disp_del : disp_donttouch; >> b->condition_not_parsed =3D 1; >> @@ -9409,9 +9216,12 @@ create_breakpoint (struct gdbarch *gdbarch, >> =09 && type_wanted !=3D bp_hardware_breakpoint) || thread !=3D -1) >> =09b->pspace =3D current_program_space; >> =20 >> + if (b->type =3D=3D bp_dprintf) >> +=09update_dprintf_command_list (b.get ()); >> + >> install_breakpoint (internal, std::move (b), 0); >> } >> - =20 >> + >> if (canonical.lsals.size () > 1) >> { >> warning (_("Multiple breakpoints were set.\nUse the " >> @@ -13145,24 +12955,6 @@ code_breakpoint::location_spec_to_sals (locatio= n_spec *locspec, >> { >> for (auto &sal : sals) >> =09resolve_sal_pc (&sal); >> - if (condition_not_parsed && extra_string !=3D NULL) >> -=09{ >> -=09 gdb::unique_xmalloc_ptr local_cond, local_extra; >> -=09 int local_thread, local_task, local_inferior; >> - >> -=09 find_condition_and_thread_for_sals (sals, extra_string.get (), >> -=09=09=09=09=09 &local_cond, &local_thread, >> -=09=09=09=09=09 &local_inferior, >> -=09=09=09=09=09 &local_task, &local_extra); >> -=09 gdb_assert (cond_string =3D=3D nullptr); >> -=09 if (local_cond !=3D nullptr) >> -=09 cond_string =3D std::move (local_cond); >> -=09 thread =3D local_thread; >> -=09 task =3D local_task; >> -=09 if (local_extra !=3D nullptr) >> -=09 extra_string =3D std::move (local_extra); >> -=09 condition_not_parsed =3D 0; >> -=09} >> =20 >> if (type =3D=3D bp_static_tracepoint) >> =09sals[0] =3D update_static_tracepoint (this, sals[0]); >> diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tas= ks.exp >> index 603d43f7c36..337ee1b6f07 100644 >> --- a/gdb/testsuite/gdb.ada/tasks.exp >> +++ b/gdb/testsuite/gdb.ada/tasks.exp >> @@ -55,11 +55,11 @@ gdb_test "watch j task 1 task 3" "You can specify on= ly one task\\." >> =20 >> # Check that attempting to combine 'task' and 'thread' gives an error. >> gdb_test "break break_me task 1 thread 1" \ >> - "You can specify only one of thread or task\\." >> + "You can specify only one of thread, inferior, or task\\." >> gdb_test "break break_me thread 1 task 1" \ >> - "You can specify only one of thread or task\\." >> + "You can specify only one of thread, inferior, or task\\." >> gdb_test "break break_me inferior 1 task 1" \ >> - "You can specify only one of inferior or task\\." >> + "You can specify only one of thread, inferior, or task\\." >> gdb_test "watch j task 1 thread 1" \ >> "You can specify only one of thread or task\\." >> gdb_test "watch j thread 1 task 1" \ >> diff --git a/gdb/testsuite/gdb.base/condbreak.exp b/gdb/testsuite/gdb.ba= se/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=3D=3D1) thread 999" \ >> "Unknown thread 999\\." >> gdb_test "break -q main thread 999 if (1=3D=3D1)" \ >> "Unknown thread 999\\." >> +gdb_test "break -q main if (1=3D=3D1) thread 999 -force-condition" \ >> + "Unknown thread 999\\." >> +gdb_test "break -q main thread 999 if (1=3D=3D1) -force-condition" \ >> + "Unknown thread 999\\." >> =20 >> # Verify that both if and thread can be distinguished from a breakpoint >> # address expression. >> @@ -186,20 +190,34 @@ gdb_test "break *main if (1=3D=3D1) thread 999" \ >> "Unknown thread 999\\." >> gdb_test "break *main thread 999 if (1=3D=3D1)" \ >> "Unknown thread 999\\." >> +gdb_test "break *main if (1=3D=3D1) thread 999 -force-condition" \ >> + "Unknown thread 999\\." >> +gdb_test "break *main thread 999 if (1=3D=3D1) -force-condition" \ >> + "Unknown thread 999\\." >> =20 >> # Similarly for task. >> gdb_test "break *main if (1=3D=3D1) task 999" \ >> "Unknown task 999\\." >> gdb_test "break *main task 999 if (1=3D=3D1)" \ >> "Unknown task 999\\." >> +gdb_test "break *main if (1=3D=3D1) task 999 -force-condition" \ >> + "Unknown task 999\\." >> +gdb_test "break *main task 999 if (1=3D=3D1) -force-condition" \ >> + "Unknown task 999\\." >> =20 >> -# GDB accepts abbreviations for "thread" and "task". >> +# GDB accepts abbreviations for "thread" and "task" and "-force-conditi= on" >> gdb_test "break *main if (1=3D=3D1) t 999" \ >> "Unknown thread 999\\." > > As stated above, I=E2=80=99m not a fan of this way to handle the ambiguit= y, but > at least it have been tested. Something like "b *main t 999 if (1=3D=3D1= )" > does not work, which I=C2=A0find inconsistent. I've added some additional tests in this area to cover some of the other "weird" behaviours that you pointed out. This doesn't mean I think these behaviours are the best possible behaviour GDB could have, I'm just trying to ensure that this patch doesn't change the behaviour at all. I'll post an updated version of this series soon. Thanks, Andrew > >> gdb_test "break *main if (1=3D=3D1) th 999" \ >> "Unknown thread 999\\." >> gdb_test "break *main if (1=3D=3D1) ta 999" \ >> "Unknown task 999\\." >> +gdb_test "break *main if (1=3D=3D1) t 999 -force" \ >> + "Unknown thread 999\\." >> +gdb_test "break *main if (1=3D=3D1) th 999 -force" \ >> + "Unknown thread 999\\." >> +gdb_test "break *main if (1=3D=3D1) ta 999 -force" \ >> + "Unknown task 999\\." >> =20 >> 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 =3D=3D 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" >> =20 >> =20 >> @@ -195,8 +196,10 @@ gdb_test "info break" \ >> \[\t \]+stop only if k =3D=3D 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.*ign= ore 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" >> =20 >> # >> @@ -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" \ >> +=09 "get number for foo breakpoint"] >> +gdb_test "info breakpoints $bpnum" \ >> + [multi_line \ >> +=09 "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ >> +=09 "\\s+stop only if \\(unknown_var && another_unknown_var\\)" \ >> +=09 "\\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 668002d9038..8cbefe204ec 100644 >> --- a/gdb/testsuite/gdb.linespec/explicit.exp >> +++ b/gdb/testsuite/gdb.linespec/explicit.exp >> @@ -575,7 +575,7 @@ namespace eval $testfile { >> =09 allow-pending]} { >> =09fail "set $tst" >> } else { >> -=09gdb_test "info break" ".*PENDING.*myfunction if foofoofoo =3D=3D 1.*= " $tst >> +=09gdb_test "info break" ".*PENDING.*myfunction\r\n\\s+stop only if foo= foofoo =3D=3D 1.*" $tst >> } >> =20 >> gdb_exit >> @@ -586,7 +586,7 @@ namespace eval $testfile { >> =09 allow-pending]} { >> =09fail "set $tst" >> } else { >> -=09gdb_test "info break" ".*PENDING.*myfunction if arg =3D=3D 0" $tst >> +=09gdb_test "info break" ".*PENDING.*myfunction\r\n\\s+stop only if arg= =3D=3D 0" $tst >> =20 >> =09gdb_load [standard_output_file $exefile] >> =09gdb_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" \ >> =09 -disp "keep" -enabled "y" -pending "pendfunc1" \ >> -=09 -original-location "pendfunc1"] >> +=09 -original-location "pendfunc1" \ >> +=09 -script {\["printf \\\"hello\\\""\]}] >> mi_gdb_test "-dprintf-insert -f pendfunc1 \"hello\"" \ >> ".*\\^done,$bp" "mi set dprintf" >> =20 >> diff --git a/gdb/testsuite/gdb.multi/inferior-specific-bp.exp b/gdb/test= suite/gdb.multi/inferior-specific-bp.exp >> index 1f6573268da..b8aceabcad6 100644 >> --- a/gdb/testsuite/gdb.multi/inferior-specific-bp.exp >> +++ b/gdb/testsuite/gdb.multi/inferior-specific-bp.exp >> @@ -51,9 +51,9 @@ if {![runto_main]} { >> # this should fail. Try with the keywords in both orders just in case = the >> # parser has a bug. >> gdb_test "break foo thread 1.1 inferior 1" \ >> - "You can specify only one of inferior or thread\\." >> + "You can specify only one of thread, inferior, or task\\." >> gdb_test "break foo inferior 1 thread 1.1" \ >> - "You can specify only one of inferior or thread\\." >> + "You can specify only one of thread, inferior, or task\\." >> =20 >> # Try to create a breakpoint using the 'inferior' keyword multiple time= s. >> gdb_test "break foo inferior 1 inferior 2" \ >> 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 =3D 0; >> + >> +void >> +foo (int arg) >> +{ >> + global_var =3D arg; >> +} >> diff --git a/gdb/testsuite/gdb.threads/del-pending-thread-bp.c b/gdb/tes= tsuite/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 =3D pthread_barrier_wait (b); >> + if (res !=3D 0 && res !=3D 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) !=3D 0) >> + abort (); >> + >> + if (pthread_create (&thread, NULL, thread_worker, NULL) !=3D 0) >> + abort (); >> + >> + breakpt (); >> + >> + /* Allow the worker thread to complete. */ >> + barrier_wait (&barrier); >> + >> + if (pthread_join (thread, NULL) !=3D 0) >> + abort (); >> + >> + breakpt (); >> + >> + /* Now load the shared library. */ >> + handle =3D dlopen (SHLIB_NAME, RTLD_LAZY); >> + if (handle =3D=3D NULL) >> + abort (); >> + >> + /* Find the function symbol. */ >> + func =3D (void (*)(int)) dlsym (handle, "foo"); >> + >> + /* Call the library function. */ >> + func (1); >> + >> + /* Unload the shared library. */ >> + if (dlclose (handle) !=3D 0) >> + abort (); >> + >> + breakpt (); >> + >> + return 0; >> +} >> + >> diff --git a/gdb/testsuite/gdb.threads/del-pending-thread-bp.exp b/gdb/t= estsuite/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 {}] !=3D "" } { >> + 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 \ >> +=09 [list debug \ >> +=09 additional_flags=3D-DSHLIB_NAME=3D\"$binfile_lib_target\" \ >> +=09 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*" \ >> +=09 "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] =3D=3D "remote" >> +=09 || [target_info gdb_protocol] =3D=3D "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 \ >> +=09 "Continuing\\." \ >> +=09 "" \ >> +=09 "Thread 1 \[^\r\n\]+ hit Breakpoint $decimal, breakpt \\(\\) at \[^= \r\n\]+" \ >> +=09 "$decimal\\s+\[^\r\n\]+"] \ >> + "third breakpt call" >> +gdb_test "bt 1" \ >> + [multi_line \ >> +=09 "#0\\s+breakpt \\(\\) at \[^\r\n\]+" \ >> +=09 "\\(More stack frames follow\\.\\.\\.\\)"] >> --=20 >> 2.25.4 >>=20