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 C7FDE3857C41 for ; Wed, 16 Mar 2022 11:38:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7FDE3857C41 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-486--ROGjkqQOAaSVmsCcH_7VQ-1; Wed, 16 Mar 2022 07:38:04 -0400 X-MC-Unique: -ROGjkqQOAaSVmsCcH_7VQ-1 Received: by mail-wm1-f71.google.com with SMTP id i6-20020a05600c354600b0038be262d9d9so1492294wmq.8 for ; Wed, 16 Mar 2022 04:38:04 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version; bh=AmAnCWrbFEk+GoiYRtIqPzyIGcjccRiVXOkTIouqISg=; b=e4pMZa/QZnykTjlqZp2E9gubgdVbYQvm+43QUDDJREMwkd3CCrEkMsbdyHSRRQEJ+F pjM+z1XNNQww/upq9vRGK61WbbZRnTCq74q8ET26uGM6lw3NKIZRa2oHgNhZfSCWRItD Lxs5srcpi/J416BcanZgBUiXGs+ZOkWE0hGV7m/9qSRPNbk8FLrFJYrNdR8uBVbHTqFs wFvi/IqeVHqNR/uB8Li6FwWeLr5RlWUvvp7rntRr9HsoSbiWXZ/U4YWp2cNQdxfatoTA GvB0HWaE4MKfrST7LojJsnPl4ruiOasWXavLz9Yt+YuaO15zJsQ4rW1j9+9ed1Uzt/Hr vM5g== X-Gm-Message-State: AOAM531h49PUkldZp2/Xfmmcb1SRPfv5oYWuwtCsg9zVjTy1LBvNcG7w JHVO9nMroPCsmKaDhI2ppqJUwGGuUh8VF9SzNmJOz6lHH173jFZujOoW0D079WZqIIqNOn76mCN HFNT2Im+IPyjJAXUSA2uRsg== X-Received: by 2002:a5d:6d83:0:b0:203:6a0e:8854 with SMTP id l3-20020a5d6d83000000b002036a0e8854mr23327209wrs.259.1647430682851; Wed, 16 Mar 2022 04:38:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD3FpH7zRaN/vK6DKCmyOK3iAKNu2Ib0Ce0I2PWJAid2/R+6dFHshXWz5mXtYTp5hMrqUqgw== X-Received: by 2002:a5d:6d83:0:b0:203:6a0e:8854 with SMTP id l3-20020a5d6d83000000b002036a0e8854mr23327197wrs.259.1647430682619; Wed, 16 Mar 2022 04:38:02 -0700 (PDT) Received: from localhost (host109-154-72-186.range109-154.btcentralplus.com. [109.154.72.186]) by smtp.gmail.com with ESMTPSA id x14-20020adfffce000000b001f1dfee4867sm1951668wrs.99.2022.03.16.04.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 04:38:02 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Remove 'target_mach' global from score-tdep.c In-Reply-To: <20220315223154.6517-1-tom@tromey.com> References: <20220315223154.6517-1-tom@tromey.com> Date: Wed, 16 Mar 2022 11:38:01 +0000 Message-ID: <874k3yunza.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.6 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_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: Wed, 16 Mar 2022 11:38:07 -0000 Tom Tromey writes: > 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. I know nothing about the score architecture, but just by inspection this change looks good to me. Thanks, Andrew > --- > 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