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 0D1E3385B835 for ; Tue, 8 Mar 2022 12:58:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D1E3385B835 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-185-aFR67L2xNwm6lj6HFgwJKA-1; Tue, 08 Mar 2022 07:58:44 -0500 X-MC-Unique: aFR67L2xNwm6lj6HFgwJKA-1 Received: by mail-wr1-f72.google.com with SMTP id x15-20020a5d6b4f000000b001ee6c0aa287so5457910wrw.9 for ; Tue, 08 Mar 2022 04:58:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wSwBIlLxc5Xz+BoAUkrunJF9sRoJMSFaR7HtJh28GL8=; b=xhftw1Xs5T8sHFJzXrqFUfc5SzHU1fE42zAwEE0bKYkrcYdymyBvMJxtZNTfM6NfMX O/ccnMi09Ta4AG/9wVtcoaeFWUPUjNe363Ub3RPM5wXAkR4aNjnYfwBA8uI6xm79/FnH hn7kxsefeQMQUvs2iBufQ3XYPrQjzNSXJG20GA4BDwDCsbu/qMZ9Ffp6/vSH/RQVKgWm od9mZhU8hD2ugD5QgUma3ZfyTWGXcCY07YhNmR6ARMA5KNvvhnwf0rxLi3F2CZwzkM3z OgQOeLJoppQV7/9LEEdQ3fmIINOzrYk0pPUzLfQAf2QOVx+uIVJKy1Ml3JMXS/awubkp nVqw== X-Gm-Message-State: AOAM5302yNs2stJlzbQsM8RgIDQ+qxGDJavyyqRFfEvBF8Dg/HmtiozI 8WucMsU22nU0HcMNGPM4Ca4iKjfUpbatmG8+swDsHvr+fIjX2404Mlxjs23xFfsjXwHeqGOV5U/ Vj0Xxwj6oP/PyR0Puc5QOKMFillEnSGKmwC15mAQLqQTH2K/ddVTlQW3TxD8feU36Dmg/btRKZw == X-Received: by 2002:a1c:c907:0:b0:37b:f983:5d4e with SMTP id f7-20020a1cc907000000b0037bf9835d4emr3538212wmb.174.1646744322113; Tue, 08 Mar 2022 04:58:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRXqgSNsIUvSEHhE0B1F/bV0vRplun2R1/SGxug+OYhtbHI5V3Mh2rNZjoTwZXnRbIDB6ZJA== X-Received: by 2002:a1c:c907:0:b0:37b:f983:5d4e with SMTP id f7-20020a1cc907000000b0037bf9835d4emr3538177wmb.174.1646744321594; Tue, 08 Mar 2022 04:58:41 -0800 (PST) Received: from localhost (host86-134-151-205.range86-134.btcentralplus.com. [86.134.151.205]) by smtp.gmail.com with ESMTPSA id b1-20020a5d40c1000000b001f1dd6ea504sm8392515wrq.59.2022.03.08.04.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 04:58:40 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PUSHED 1/2] gdb/mi: fix regression in mi -add-inferior command Date: Tue, 8 Mar 2022 12:58:35 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <0002f2a5-b503-ed36-c9af-1b392531863a@palves.net> 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-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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 08 Mar 2022 12:58:48 -0000 From: Umair Sair Prior to the multi-target support commit: commit 5b6d1e4fa4fc6827c7b3f0e99ff120dfa14d65d2 Date: Fri Jan 10 20:06:08 2020 +0000 Multi-target support When a new inferior was added using the MI -add-inferior command, the new inferior would be using the same target as all the other inferiors. This makes sense, GDB only supported a single target stack at a time. After the above commit, each inferior has its own target stack. To maintain backward compatibility, for the CLI add-inferior command, when a new inferior is added the above commit has the new inferior inherit a copy of the target stack from the current inferior. Unfortunately, this same backward compatibility is missing for the MI. This commit fixes this oversight. Now, when the -add-inferior MI command is used, the new inferior will inherit a copy of the target stack from the current inferior. --- gdb/NEWS | 6 ++ gdb/inferior.c | 6 +- gdb/inferior.h | 7 ++ gdb/mi/mi-main.c | 4 + gdb/testsuite/gdb.mi/mi-add-inferior.exp | 122 +++++++++++++++++++++++ 5 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.mi/mi-add-inferior.exp diff --git a/gdb/NEWS b/gdb/NEWS index ee9eaad63a0..4e12ebfb0bd 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -152,6 +152,12 @@ info win of the floating-point type, and the "f" is the marker for floating point. +* MI changes + + ** The '-add-inferior' with no option flags now inherits the + connection of the current inferior, this restores the behaviour of + GDB as it was prior to GDB 10. + * New targets GNU/Linux/LoongArch loongarch*-*-linux* diff --git a/gdb/inferior.c b/gdb/inferior.c index 965ae65287e..48d5c8bfd15 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -759,11 +759,9 @@ add_inferior_with_spaces (void) return inf; } -/* Switch to inferior NEW_INF, a new inferior, and unless - NO_CONNECTION is true, push the process_stratum_target of ORG_INF - to NEW_INF. */ +/* See inferior.h. */ -static void +void switch_to_inferior_and_push_target (inferior *new_inf, bool no_connection, inferior *org_inf) { diff --git a/gdb/inferior.h b/gdb/inferior.h index 45de3c2d9c8..caabc2ee8d8 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -740,4 +740,11 @@ extern struct inferior *add_inferior_with_spaces (void); /* Print the current selected inferior. */ extern void print_selected_inferior (struct ui_out *uiout); +/* Switch to inferior NEW_INF, a new inferior, and unless + NO_CONNECTION is true, push the process_stratum_target of ORG_INF + to NEW_INF. */ + +extern void switch_to_inferior_and_push_target + (inferior *new_inf, bool no_connection, inferior *org_inf); + #endif /* !defined (INFERIOR_H) */ diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 4860da7536a..2fab592d6fb 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1708,8 +1708,12 @@ mi_cmd_add_inferior (const char *command, char **argv, int argc) if (argc != 0) error (_("-add-inferior should be passed no arguments")); + scoped_restore_current_pspace_and_thread restore_pspace_thread; + inf = add_inferior_with_spaces (); + switch_to_inferior_and_push_target (inf, false, current_inferior ()); + current_uiout->field_fmt ("inferior", "i%d", inf->num); } diff --git a/gdb/testsuite/gdb.mi/mi-add-inferior.exp b/gdb/testsuite/gdb.mi/mi-add-inferior.exp new file mode 100644 index 00000000000..3f0cd7cc06c --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-add-inferior.exp @@ -0,0 +1,122 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test MI '-add-inferior'. + +load_lib mi-support.exp +set MIFLAGS "-i=mi" + +standard_testfile basics.c + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ + executable {debug}] != "" } { + untested "failed to compile" + return -1 +} + +mi_clean_restart ${binfile} + +# Start execution to establish a connection. +mi_runto_main + +# Use 'info inferiors' to find the details of the current connection. +set header_line "" +set inf_line "" +gdb_test_multiple "info inferiors" "" { + + -re "^info inferiors\r\n" { + exp_continue + } + + -re "^&\[^\r\n\]+\r\n" { + exp_continue + } + + -re "~\"( Num\\s+Description\\s+Connection\[^\r\n\]+)\r\n" { + set header_line $expect_out(1,string) + exp_continue + } + + -re "^~\"(\\*\\s+1\\s+\[^\r\n\]+)\r\n" { + set inf_line $expect_out(1,string) + exp_continue + } + + -re "^\\^done\r\n" { + exp_continue + } + + -re "^$mi_gdb_prompt$" { + gdb_assert { [string length "$header_line"] > 0 } + gdb_assert { [string length "$inf_line"] > 0 } + pass $gdb_test_name + } +} + +# Now extract the string that represents the connection, and convert +# it into a regexp. +set idx [string first "Connection" "${header_line}"] +gdb_assert { $idx > -1 } +set inf_line [string range "${inf_line}" $idx end] +regexp "^(${decimal} \\(\[^)\]+\\))" $inf_line conn_info +set conn_pattern [string_to_regexp "${conn_info}"] + +# Now add a new inferior, this should use the connection of the +# current inferior. +mi_gdb_test "-add-inferior" \ + [multi_line "=thread-group-added,id=\"\[^\"\]+\"" \ + "~\"\\\[New inferior 2\\\]\\\\n\"" \ + "\~\"Added inferior 2 on connection ${conn_pattern}\\\\n\"" \ + "\\^done,inferior=\"\[^\"\]+\"" ] \ + "mi add inferior" + +# Now run 'info inferiors' again to check that the currently selected +# inferior has not changed. +set saw_current_inferior false +set saw_new_inferior false +gdb_test_multiple "info inferiors" \ + "info inferiors, after new inferior was created" { + + -re "^info inferiors\r\n" { + exp_continue + } + + -re "^&\[^\r\n\]+\r\n" { + exp_continue + } + + -re "~\"\\s+Num\\s+Description\\s+Connection\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^~\"\\*\\s+1\\s+\[^\r\n\]+\\s+${conn_pattern}\\s+\[^\r\n\]+\r\n" { + set saw_current_inferior true + exp_continue + } + + -re "^~\"\\s+2\\s+\[^\r\n\]+\\s+${conn_pattern}\\s+\[^\r\n\]+\r\n" { + set saw_new_inferior true + exp_continue + } + + -re "^\\^done\r\n" { + exp_continue + } + + -re "^$mi_gdb_prompt$" { + gdb_assert { $saw_current_inferior && $saw_new_inferior } + pass $gdb_test_name + } + } -- 2.25.4