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.129.124]) by sourceware.org (Postfix) with ESMTPS id 4C6ED385782B for ; Mon, 28 Nov 2022 11:25:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C6ED385782B 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=1669634749; 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=xSFKnJxly2El5OxWzNp/KbJ5b+cn6y8Nke/cx3aq1og=; b=ffzh+N77Ao2Af/Zq2YRMBOWvn2Lb6ahF7bb9J/WpS88VDUF/nFth6SJMyZ2598CQyBbHpZ +OYpmWRzvZosyHIlbFFD9367VIuADWyK3B11M+aT4aqa++JsnPtuyz1n6IrKmeMY1nMULa fzgTK1mB/0WAo3AdIv38HFNrysIbO8s= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-59-zZT27EohM_ybZoH1gqN3uQ-1; Mon, 28 Nov 2022 06:25:48 -0500 X-MC-Unique: zZT27EohM_ybZoH1gqN3uQ-1 Received: by mail-wr1-f70.google.com with SMTP id m24-20020adfa3d8000000b00242168ce9d1so525308wrb.15 for ; Mon, 28 Nov 2022 03:25:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xSFKnJxly2El5OxWzNp/KbJ5b+cn6y8Nke/cx3aq1og=; b=xxx5urVZv2dv6fr8epOoT+JfR1/zp4cp1sSRA7LjxN/tUJOxJv5jjTCjhHeuhPC4I/ wElWCXi5wyPJxkqgwsoBZHhZBGrXrio0FZ2/esl08gFGC69veuUJKx9RvshUmuSbgDwG bH5MJoH7APrjKDEhYg9hZENhrfgJEBm2ocJuBjeb/cflpyzBTPMGMqmaSQyUK/7cvMme WwDaGr+4BRb7nefrru861KEOAii1KPuU2gTtOG7a6fM3zrNd01JpuCINhKmRRuwNdiZz jStrcAJ1sYrVyJFiCagerOwIx8h8PIwKcKFDneJNitudPy7gCZucpW6PHHpx92vxqxJd Zo6Q== X-Gm-Message-State: ANoB5pkzwB3/+AthbNirFr6GUZfjj6PnIOD52VTJxll+ZPdRfIwkAYt6 SJqOZo0cTL94O70dyt186LaGYcdq28PcANq6sCICJqbBlP9qyUlXE/Ju7JIga5HLBExT5PPfgo1 O4TfdbfjCPnrxbgjc32esZB5a6eZrHabQ7B4Mrg/6zxomqACBUnB9M2BxYxR67aiwFcPMhdzvrQ == X-Received: by 2002:a5d:526b:0:b0:242:380:c10e with SMTP id l11-20020a5d526b000000b002420380c10emr10522876wrc.132.1669634747327; Mon, 28 Nov 2022 03:25:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf7es/rb1URRWjPOVmyoQnliVySHSazg+PKrtF8QbMUxv+0745EwRJklVjHVbpTNAiEHfYCkKw== X-Received: by 2002:a5d:526b:0:b0:242:380:c10e with SMTP id l11-20020a5d526b000000b002420380c10emr10522859wrc.132.1669634747056; Mon, 28 Nov 2022 03:25:47 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id p1-20020a1c5441000000b003b4cba4ef71sm18507788wmi.41.2022.11.28.03.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 03:25:46 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 4/6] gdb: error if 'thread' or 'task' keywords are overused Date: Mon, 28 Nov 2022 11:25:36 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When creating a breakpoint or watchpoint, the 'thread' and 'task' keywords can be used to create a thread or task specific breakpoint or watchpoint. Currently, a thread or task specific breakpoint can only apply for a single thread or task, if multiple threads or tasks are specified when creating the breakpoint (or watchpoint), then the last specified id will be used. The exception to the above is that when the 'thread' keyword is used during the creation of a watchpoint, GDB will give an error if 'thread' is given more than once. In this commit I propose making this behaviour consistent, if the 'thread' or 'task' keywords are used more than once when creating either a breakpoint or watchpoint, then GDB will give an error. I haven't updated the manual, we don't explicitly say that these keywords can be repeated, and (to me), given the keyword takes a single id, I don't think it makes much sense to repeat the keyword. As such, I see this more as adding a missing error to GDB, rather than making some big change. However, I have added an entry to the NEWS file as I guess it is possible that some people might hit this new error with an existing (I claim, badly written) GDB script. I've added some new tests to check for the new error. Just one test needed updating, gdb.linespec/keywords.exp, this test did use the 'thread' keyword twice, and expected the breakpoint to be created. Looking at what this test was for though, it was checking the use of '-force-condition', and I don't think that being able to repeat 'thread' was actually a critical part of this test. As such, I've updated this test to expect the error when 'thread' is repeated. --- gdb/NEWS | 9 +++++++++ gdb/breakpoint.c | 9 +++++++++ gdb/testsuite/gdb.ada/tasks.exp | 4 ++++ gdb/testsuite/gdb.linespec/keywords.exp | 10 ++++++++-- gdb/testsuite/gdb.threads/thread-specific-bp.exp | 4 ++++ gdb/testsuite/gdb.threads/watchthreads2.exp | 3 +++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index dddef6525de..1f2233082ae 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -101,6 +101,15 @@ (gdb) disable $_hit_bpnum are both disabling the breakpoint. +* For the break command, multiple uses of the 'thread' or 'task' + keywords will now given an error instead of just using the thread or + task id from the last instance of the keyword. + +* For the watch command, multiple uses of the 'task' keyword will now + given an error instead of just using the task id from the last + instance of the keyword. The 'thread' keyword already gave an error + when used multiple times with the watch command. + * New commands maintenance set ignore-prologue-end-flag on|off diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 2ec8ca364b6..bf99297a250 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8793,6 +8793,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, const char *tmptok; struct thread_info *thr; + if (*thread != -1) + error(_("You can specify only one thread.")); + tok = end_tok + 1; thr = parse_thread_id (tok, &tmptok); if (tok == tmptok) @@ -8804,6 +8807,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, { char *tmptok; + if (*task != 0) + error(_("You can specify only one task.")); + tok = end_tok + 1; *task = strtol (tok, &tmptok, 0); if (tok == tmptok) @@ -10086,6 +10092,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, { char *tmp; + if (task != 0) + error(_("You can specify only one task.")); + task = strtol (value_start, &tmp, 0); if (tmp == value_start) error (_("Junk after task keyword.")); diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp index 2ca03396d7c..c2ab6c6724d 100644 --- a/gdb/testsuite/gdb.ada/tasks.exp +++ b/gdb/testsuite/gdb.ada/tasks.exp @@ -39,6 +39,10 @@ gdb_test "info tasks" \ "\r\n"] \ "info tasks before inserting breakpoint" +# Check that multiple uses of the 'task' keyword will give an error. +gdb_test "break break_me task 1 task 3" "You can specify only one task\\." +gdb_test "watch j task 1 task 3" "You can specify only one task\\." + # Insert a breakpoint that should stop only if task 1 stops. Since # task 1 never calls break_me, this shouldn't actually ever trigger. # The fact that this breakpoint is created _before_ the next one diff --git a/gdb/testsuite/gdb.linespec/keywords.exp b/gdb/testsuite/gdb.linespec/keywords.exp index 94536df4670..dca854d3f59 100644 --- a/gdb/testsuite/gdb.linespec/keywords.exp +++ b/gdb/testsuite/gdb.linespec/keywords.exp @@ -80,8 +80,14 @@ foreach prefix {"" "thread 1 "} { foreach suffix {"" " " " thread 1"} { foreach cond {"" " if 1"} { with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" { - gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ - "message" + + if { [regexp thread $prefix] && [regexp thread $suffix] } { + gdb_test "break main ${prefix}-force-condition${suffix}${cond}" \ + "You can specify only one thread\\." + } else { + gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ + "message" + } } } } diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp index dc822f37b7b..a300f3ef7ab 100644 --- a/gdb/testsuite/gdb.threads/thread-specific-bp.exp +++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp @@ -63,6 +63,10 @@ proc check_thread_specific_breakpoint {non_stop} { return -1 } + # Check that multiple uses of 'thread' keyword give an error. + gdb_test "break main thread $start_thre thread $main_thre" \ + "You can specify only one thread\\." + # Set a thread-specific breakpoint at "main". This can't ever # be hit, but that's OK. gdb_breakpoint "main thread $start_thre" diff --git a/gdb/testsuite/gdb.threads/watchthreads2.exp b/gdb/testsuite/gdb.threads/watchthreads2.exp index 2c18b20257c..ef502507f9f 100644 --- a/gdb/testsuite/gdb.threads/watchthreads2.exp +++ b/gdb/testsuite/gdb.threads/watchthreads2.exp @@ -73,6 +73,9 @@ if { $nr_started == $NR_THREADS } { return -1 } +# Check that multiple uses of the 'thread' keyword will give an error. +gdb_test "watch x thread 1 thread 2" "You can specify only one thread\\." + # Watch X, it will be modified by all threads. # We want this watchpoint to be set *after* all threads are running. gdb_test "watch x" "Hardware watchpoint 3: x" -- 2.25.4