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 E21033858CDA for ; Fri, 20 Jan 2023 09:46:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E21033858CDA 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=1674208009; 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=BIxgI7MCPbrp+tljCoAoYqc/1auXAlovLqIgAMGcbXo=; b=ROfbfkr3Fr/SMha9T9vhC4eJhNs7lWm528DVhQlOQuIFK43PGxUszN7Q8vuy7rMqrNZW3I YaLkHTyeQppFVJYpJ1Obir8H3O+D+o+40CEgyM9A3iMtNkmRelRj0dJ6BKtsqpOTzotZpc uBMa/gbH7vaPNJ2HckU7DrlZ1hXCDe8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-650-KvrZwa6vPumXqHtgzI3k-A-1; Fri, 20 Jan 2023 04:46:48 -0500 X-MC-Unique: KvrZwa6vPumXqHtgzI3k-A-1 Received: by mail-qv1-f71.google.com with SMTP id x6-20020a0cc506000000b005349c8b39d6so2260885qvi.2 for ; Fri, 20 Jan 2023 01:46: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=BIxgI7MCPbrp+tljCoAoYqc/1auXAlovLqIgAMGcbXo=; b=1f6V9S3OXqT4P+Gm9eaGrHj43RGwsrie7fojHMxmkRLDGHl+J9P2sF4ndsiyT1lwyw hzcG3Mnbk0OI/qA0XBXFjvZqQQKGiDzRGbBryysfoMFS8xPga+UmZ5Nou9QzGCTEwV7K Pn+gze8N3MGwE9sXHN0K2EI0bNNGzF1MJeSX2Apiraowvp7goRapLdmXLT8wvv7Fn737 GNSJJmPxwrUwqhwOAx75fAZze/bw3KLNKxdaP8RWzZfWNyENgpYPG5DRELtNqtMm7Ego GTO43y+HeMSHURVhPtUYL2gwt3vtT5KmLu4D7vRkEEG337xjYmMbgNpU2zL9NPv7OpQU II/A== X-Gm-Message-State: AFqh2krd64uqzZh1vSpRR6dihai2W6XQRK+CvK12lz7Ng8U75mgbGGA/ 2JR8TpQxt3r/FpbAPD1jyVKO6rKNVSI2Z6nJcTRL9OVohKHJRQoDMUHSq6hW0gvm+swxcHaa6Li JShpaEZd16G7YzXGpAHYZ7gMjg95YBX1cdcfbSV8GCax6FRRcKlqdXH5Ltft1mwf3sGES/sOpAQ == X-Received: by 2002:a0c:e114:0:b0:534:d4ea:a49b with SMTP id w20-20020a0ce114000000b00534d4eaa49bmr20222816qvk.48.1674208007906; Fri, 20 Jan 2023 01:46:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXt0Y9ragW4JMGapkfyahl4zZx8WzFLKibkSbOLPisHKkhg5zQl4e0R+GrObBPJZAU7132whXQ== X-Received: by 2002:a0c:e114:0:b0:534:d4ea:a49b with SMTP id w20-20020a0ce114000000b00534d4eaa49bmr20222793qvk.48.1674208007480; Fri, 20 Jan 2023 01:46:47 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id v16-20020ac87490000000b003b691005020sm1879497qtq.96.2023.01.20.01.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 01:46:47 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 6/6] gdb: convert the 'start' breakpoint to use inferior keyword Date: Fri, 20 Jan 2023 09:46:29 +0000 Message-Id: <0823d00de1408044915aa3bbcac4de0361d4ac30.1674207665.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Now that we have support for inferior specific breakpoints, the breakpoint created for the 'start' command can make use of this keyword. In most cases the observed functionality should be unchanged from a user's point of view, though the code in GDB is a little cleaner now, we no longer need to change the expression used based on the language. I do wonder if the current mechanism could run into problems if we had different inferiors of different languages. For example, if we had an Ada inferior and a C inferior and followed a process a little like this: 1. Start C inferior, the inferior stops before main for some reason, 2. Start the Ada inferior, this runs to main, 3. I think when we hit main, the condition for both breakpoints will be evaluated, this will include evaluating the expression for the C 'start' breakpoint, which uses '==' and is, I guess, not valid for Ada. I haven't tried to create a testcase for this situation, but it's a possibly interesting edge case. One place where the observed behaviour is different, is that inferior breakpoints, like thread breakpoints, will be auto-deleted when the contained inferior exits. As a result, if an inferior exits before hitting the start breakpoint, then the 'start' breakpoint will be auto-deleted. I have got a test that covers this situation. --- gdb/infcmd.c | 10 +--- .../gdb.base/start-inferior-specific-1.c | 32 +++++++++++ .../gdb.base/start-inferior-specific-2.c | 22 ++++++++ .../gdb.base/start-inferior-specific.exp | 55 +++++++++++++++++++ 4 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 gdb/testsuite/gdb.base/start-inferior-specific-1.c create mode 100644 gdb/testsuite/gdb.base/start-inferior-specific-2.c create mode 100644 gdb/testsuite/gdb.base/start-inferior-specific.exp diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 7d5ec77ff57..7dfef4b5a23 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -429,13 +429,9 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how) have proper inferior-specific breakpoint support, in the breakpoint machinery. We could then avoid inserting a breakpoint in the program spaces unrelated to this inferior. */ - const char *op - = ((current_language->la_language == language_ada - || current_language->la_language == language_pascal - || current_language->la_language == language_m2) ? "=" : "=="); - std::string arg = string_printf - ("-qualified %s if $_inferior %s %d", main_name (), op, - current_inferior ()->num); + std::string arg = string_printf ("-qualified %s inferior %d", + main_name (), + current_inferior ()->num); tbreak_command (arg.c_str (), 0); } diff --git a/gdb/testsuite/gdb.base/start-inferior-specific-1.c b/gdb/testsuite/gdb.base/start-inferior-specific-1.c new file mode 100644 index 00000000000..1717a82b75d --- /dev/null +++ b/gdb/testsuite/gdb.base/start-inferior-specific-1.c @@ -0,0 +1,32 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include + +__attribute__((constructor)) +static void +ctor (void) +{ + exit (1); +} + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/start-inferior-specific-2.c b/gdb/testsuite/gdb.base/start-inferior-specific-2.c new file mode 100644 index 00000000000..b69e218962a --- /dev/null +++ b/gdb/testsuite/gdb.base/start-inferior-specific-2.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/start-inferior-specific.exp b/gdb/testsuite/gdb.base/start-inferior-specific.exp new file mode 100644 index 00000000000..7271f6d49d3 --- /dev/null +++ b/gdb/testsuite/gdb.base/start-inferior-specific.exp @@ -0,0 +1,55 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that a breakpoint created for the 'start' command, will be +# silently deleted if the inferior being started exits before reaching +# main. + +standard_testfile -1.c -2.c + +if {[use_gdb_stub]} { + return +} + +set srcfile1 ${srcfile} + +set binfile1 ${binfile}-1 +set binfile2 ${binfile}-2 + +if {[build_executable ${testfile}.exp ${binfile1} "${srcfile1}"] != 0} { + return -1 +} + +if {[build_executable ${testfile}.exp ${binfile2} "${srcfile2}"] != 0} { + return -1 +} + +clean_restart ${binfile1} + +# Start the first inferior, this will exit before hitting the 'start' +# breakpoint in main. +gdb_test "start" \ + [multi_line \ + "Temporary breakpoint $decimal at \[^\r\n\]+" \ + "Starting program: \[^\r\n\]+" \ + "$inferior_exited_re with code 01\\\]"] + +# Now load a different binary and run it. This inferior should run +# all the way to completion without hitting a breakpoint in main. +gdb_load ${binfile2} +gdb_test "run" \ + [multi_line \ + "Starting program: \[^\r\n\]+" \ + "$inferior_exited_re normally\\\]"] -- 2.25.4