From patchwork Thu Nov 24 16:04:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 61082 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 953C2382FAE3 for ; Thu, 24 Nov 2022 16:05:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 953C2382FAE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669305920; bh=XJx4AU+m3dfphQS3pwY7icweMwiBWDeo2P07yYlFA8Q=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=x9HW8ZEyPZKkXbuLVi+TWVGblK7fREBseOX/1muK1C4JGS3tCtLQRAIG6EpYKcfnm 41KmIQXi/TclU13bGdQIABJPZFt/Zrd2TENhUCUawXBmXkgVW5LCWK/eximLZryLIg OuSxGlfQ3LctK+zFZhmaQ396baQDGphUXjv2HO/s= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 94BDE3830B22 for ; Thu, 24 Nov 2022 16:04:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 94BDE3830B22 X-ASG-Debug-ID: 1669305869-0c856e02a13061a0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id lgdErnwzeq8yF2yE (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO); Thu, 24 Nov 2022 11:04:29 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id AE986441D64; Thu, 24 Nov 2022 11:04:29 -0500 (EST) X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 4/5] gdb: add inferior parameter to target_find_description Date: Thu, 24 Nov 2022 11:04:27 -0500 X-ASG-Orig-Subj: [PATCH 4/5] gdb: add inferior parameter to target_find_description Message-Id: <20221124160428.83804-5-simon.marchi@efficios.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221124160428.83804-1-simon.marchi@efficios.com> References: <20221124160428.83804-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1669305869 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 7892 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=5.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.102368 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-3498.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Make target_find_description not dependent on the current inferior on entry. Add an inferior parameter, and make it switch the current inferior temporarily where needed. Make callers pass the current inferior, no change in behavior is expected. Change-Id: I6fbe03a91e812c003b7946ba7ccc807a8b7369e6 --- gdb/infcmd.c | 2 +- gdb/infrun.c | 2 +- gdb/remote.c | 6 +++--- gdb/target-descriptions.c | 31 ++++++++++++++++++------------- gdb/target-descriptions.h | 6 +++--- gdb/tracefile-tfile.c | 2 +- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index f7bce0d0399..f281914ce54 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -251,7 +251,7 @@ post_create_inferior (int from_tty) Targets which need to access registers during to_open, to_create_inferior, or to_attach should do it earlier; but many don't need to. */ - target_find_description (); + target_find_description (current_inferior ()); /* Now that we know the register layout, retrieve current PC. But if the PC is unavailable (e.g., we're opening a core file with diff --git a/gdb/infrun.c b/gdb/infrun.c index 96346e1f25b..c678d5accce 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1272,7 +1272,7 @@ follow_exec (ptid_t ptid, const char *exec_file_target) architecture, and the old executable may e.g., be 32-bit, while the new one 64-bit), and before anything involving memory or registers. */ - target_find_description (); + target_find_description (inf); gdb::observers::inferior_execd.notify (inf); diff --git a/gdb/remote.c b/gdb/remote.c index 5118ecd0a31..ca6fd535a54 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4826,7 +4826,7 @@ remote_target::start_remote_1 (int from_tty, int extended_p) /* Next, if the target can specify a description, read it. We do this before anything involving memory or registers. */ - target_find_description (); + target_find_description (current_inferior ()); /* Next, now that we know something about the target, update the address spaces in the program spaces. */ @@ -4963,7 +4963,7 @@ remote_target::start_remote_1 (int from_tty, int extended_p) && gdbarch_target_desc (target_gdbarch ()) == NULL) { target_clear_description (); - target_find_description (); + target_find_description (current_inferior ()); } /* Use the previously fetched status. */ @@ -6187,7 +6187,7 @@ extended_remote_target::attach (const char *args, int from_tty) /* Next, if the target can specify a description, read it. We do this before anything involving memory or registers. */ - target_find_description (); + target_find_description (current_inferior ()); if (!target_is_non_stop_p ()) { diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 57d23747f26..40c04e0770f 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -520,13 +520,12 @@ target_desc_info_free (struct target_desc_info *tdesc_info) static std::string tdesc_filename_cmd_string; -/* Fetch the current target's description, and switch the current - architecture to one which incorporates that description. */ +/* See target-descriptions.h. */ void -target_find_description (void) +target_find_description (inferior *inf) { - target_desc_info *tdesc_info = get_tdesc_info (current_inferior ()); + target_desc_info *tdesc_info = get_tdesc_info (inf); /* If we've already fetched a description from the target, don't do it again. This allows a target to fetch the description early, @@ -538,7 +537,7 @@ target_find_description (void) /* The current architecture should not have any target description specified. It should have been cleared, e.g. when we disconnected from the previous target. */ - gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL); + gdb_assert (gdbarch_target_desc (inf->gdbarch) == nullptr); /* First try to fetch an XML description from the user-specified file. */ @@ -546,16 +545,22 @@ target_find_description (void) if (!tdesc_info->filename.empty ()) tdesc_info->tdesc = file_read_description_xml (tdesc_info->filename.data ()); + /* The calls that get the target description from the target depend on INF + being the current inferior, and some targets need a specific thread to + be selected. */ + scoped_restore_current_thread restore_thread; + thread_info *thread = any_thread_of_inferior (inf); + gdb_assert (thread != nullptr); + switch_to_thread (thread); + /* Next try to read the description from the current target using target objects. */ if (tdesc_info->tdesc == nullptr) - tdesc_info->tdesc = target_read_description_xml - (current_inferior ()->top_target ()); + tdesc_info->tdesc = target_read_description_xml (inf->top_target ()); /* If that failed try a target-specific hook. */ if (tdesc_info->tdesc == nullptr) - tdesc_info->tdesc = target_read_description - (current_inferior ()->top_target ()); + tdesc_info->tdesc = target_read_description (inf->top_target ()); /* If a non-NULL description was returned, then update the current architecture. */ @@ -564,13 +569,13 @@ target_find_description (void) struct gdbarch_info info; info.target_desc = tdesc_info->tdesc; - if (!gdbarch_update_p (current_inferior (), info)) + if (!gdbarch_update_p (inf, info)) warning (_("Architecture rejected target-supplied description")); else { struct tdesc_arch_data *data; - data = get_arch_data (target_gdbarch ()); + data = get_arch_data (inf->gdbarch); if (tdesc_has_registers (tdesc_info->tdesc) && data->arch_regs.empty ()) warning (_("Target-supplied registers are not supported " @@ -1289,7 +1294,7 @@ set_tdesc_filename_cmd (const char *args, int from_tty, tdesc_info->filename = tdesc_filename_cmd_string; target_clear_description (); - target_find_description (); + target_find_description (current_inferior ()); } static void @@ -1316,7 +1321,7 @@ unset_tdesc_filename_cmd (const char *args, int from_tty) tdesc_info->filename.clear (); target_clear_description (); - target_find_description (); + target_find_description (current_inferior ()); } /* Print target description in C. */ diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h index 3049b783e2f..ab534488d65 100644 --- a/gdb/target-descriptions.h +++ b/gdb/target-descriptions.h @@ -31,10 +31,10 @@ struct target_ops; struct target_desc_info; struct inferior; -/* Fetch the current inferior's description, and switch its current - architecture to one which incorporates that description. */ +/* Fetch INFERIOR's target description, and switch its architecture to one which + incorporates that description. */ -void target_find_description (void); +void target_find_description (inferior *inf); /* Discard any description fetched from the target for the current inferior, and switch the current architecture to one with no target diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 3266f357a27..b8302902af4 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -538,7 +538,7 @@ tfile_target_open (const char *arg, int from_tty) } /* By now, tdesc lines have been read from tfile - let's parse them. */ - target_find_description (); + target_find_description (current_inferior ()); /* Record the starting offset of the binary trace data. */ trace_frames_offset = bytes;