From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from progateway7-pub.mail.pro1.eigbox.com (gproxy5-pub.mail.unifiedlayer.com [67.222.38.55]) by sourceware.org (Postfix) with ESMTPS id AE1B43858D20 for ; Tue, 15 Mar 2022 22:31:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AE1B43858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id 0D09810047809 for ; Tue, 15 Mar 2022 22:31:57 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id UFhsnSal2wm8iUFhsnU8iH; Tue, 15 Mar 2022 22:31:56 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=DpSTREz+ c=1 sm=1 tr=0 ts=623113dd a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=o8Y5sQTvuykA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=qXnTB5RF2IkCqMmI3a4A:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=5bSdx/J0NZVAU5ly+z9VgJWTV3lsPOcaR6NGswVWO0s=; b=iGCRx4hie8xn0oE26sV8K04c37 kgyKFEVLk6VdgXOM4hNxyAIqiMrTnN5hIFKurD4DdpzifCNg3cq5NzCet+x263JQsF0dg3prSKt0Z tFE24r9CGvNRULijCzIMn/QWb; Received: from [161.98.8.2] (port=47172 helo=prentzel.ci.boulder.co.us) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nUFhs-002ZRo-12; Tue, 15 Mar 2022 16:31:56 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove 'target_mach' global from score-tdep.c Date: Tue, 15 Mar 2022 16:31:54 -0600 Message-Id: <20220315223154.6517-1-tom@tromey.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 161.98.8.2 X-Source-L: No X-Exim-ID: 1nUFhs-002ZRo-12 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (prentzel.ci.boulder.co.us) [161.98.8.2]:47172 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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, 15 Mar 2022 22:31:59 -0000 I randomly noticed that score-tdep.c sets a global variable from score_gdbarch_init, and then reuses this in other spots in the file. This seems incorrect to me, at least if multiple inferiors or targets are used; or potentially if there is a single gdb session that switches back and forth between (sub-)architectures, causing the global to be invalid. This patch fixes the problem by deferring the lookup. I wrote this just based on inspection, though, and have no way to test it. I wonder if other *-tdep.c files have similar issues. --- gdb/score-tdep.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c index e20bee46df9..b5bc47ab694 100644 --- a/gdb/score-tdep.c +++ b/gdb/score-tdep.c @@ -53,13 +53,18 @@ struct score_frame_cache trad_frame_saved_reg *saved_regs; }; -static int target_mach = bfd_mach_score7; +/* Return the bfd_mach_* value for GDBARCH. */ +static int +target_mach (struct gdbarch *gdbarch) +{ + return gdbarch_bfd_arch_info (gdbarch)->mach; +} static struct type * score_register_type (struct gdbarch *gdbarch, int regnum) { gdb_assert (regnum >= 0 - && regnum < ((target_mach == bfd_mach_score7) + && regnum < ((target_mach (gdbarch) == bfd_mach_score7) ? SCORE7_NUM_REGS : SCORE3_NUM_REGS)); return builtin_type (gdbarch)->builtin_uint32; } @@ -108,7 +113,7 @@ static int score_register_sim_regno (struct gdbarch *gdbarch, int regnum) { gdb_assert (regnum >= 0 - && regnum < ((target_mach == bfd_mach_score7) + && regnum < ((target_mach (gdbarch) == bfd_mach_score7) ? SCORE7_NUM_REGS : SCORE3_NUM_REGS)); return regnum; } @@ -388,7 +393,7 @@ score_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr) { CORE_ADDR adjust_pc = bpaddr; - if (target_mach == bfd_mach_score3) + if (target_mach (gdbarch) == bfd_mach_score3) score3_adjust_pc_and_fetch_inst (&adjust_pc, NULL, gdbarch_byte_order (gdbarch)); else @@ -404,13 +409,14 @@ score_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) } static void -score_xfer_register (struct regcache *regcache, int regnum, int length, +score_xfer_register (struct gdbarch *gdbarch, + struct regcache *regcache, int regnum, int length, enum bfd_endian endian, gdb_byte *readbuf, const gdb_byte *writebuf, int buf_offset) { int reg_offset = 0; gdb_assert (regnum >= 0 - && regnum < ((target_mach == bfd_mach_score7) + && regnum < ((target_mach (gdbarch) == bfd_mach_score7) ? SCORE7_NUM_REGS : SCORE3_NUM_REGS)); switch (endian) @@ -458,7 +464,7 @@ score_return_value (struct gdbarch *gdbarch, struct value *function, if (offset + xfer > TYPE_LENGTH (type)) xfer = TYPE_LENGTH (type) - offset; - score_xfer_register (regcache, regnum, xfer, + score_xfer_register (gdbarch, regcache, regnum, xfer, gdbarch_byte_order(gdbarch), readbuf, writebuf, offset); } @@ -1317,7 +1323,8 @@ score_make_prologue_cache (struct frame_info *this_frame, void **this_cache) if (start_addr == 0) return cache; - if (target_mach == bfd_mach_score3) + struct gdbarch *gdbarch = get_frame_arch (this_frame); + if (target_mach (gdbarch) == bfd_mach_score3) score3_analyze_prologue (start_addr, pc, this_frame, (struct score_frame_cache *) *this_cache); else @@ -1447,7 +1454,6 @@ static struct gdbarch * score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { struct gdbarch *gdbarch; - target_mach = info.bfd_arch_info->mach; arches = gdbarch_list_lookup_by_info (arches, &info); if (arches != NULL) @@ -1472,7 +1478,7 @@ score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_frame_align (gdbarch, score_frame_align); set_gdbarch_inner_than (gdbarch, core_addr_lessthan); - switch (target_mach) + switch (info.bfd_arch_info->mach) { case bfd_mach_score7: set_gdbarch_breakpoint_kind_from_pc (gdbarch, -- 2.34.1