From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124166 invoked by alias); 7 Mar 2019 16:18:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 124152 invoked by uid 89); 7 Mar 2019 16:18:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_1,KAM_STOCKGEN,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy=H*M:1b15 X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Mar 2019 16:18:19 +0000 Received: from [172.16.0.89] (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 769211E477; Thu, 7 Mar 2019 11:18:17 -0500 (EST) Subject: Re: [PATCH v2 07/11] Add a helper function to resolve TLS variable addresses for FreeBSD. To: John Baldwin , gdb-patches@sourceware.org References: From: Simon Marchi Message-ID: Date: Thu, 07 Mar 2019 16:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2019-03/txt/msg00151.txt.bz2 On 2019-02-08 7:40 p.m., John Baldwin wrote: > The fbsd_get_thread_local_address function accepts the base address of > a thread's DTV array and the base address of an object file's link map > and uses this to compute a TLS variable's address. FreeBSD > architectures use an architecture-specific method to determine the > address of the DTV array pointer and call this helper function to > perform the rest of the address calculation. I didn't check against FreeBSD's data structures (I trust you for that :)), but in general this LGTM. Just some formatting nits. > +/* Per-program-space data for FreeBSD architectures. */ > +static const struct program_space_data *fbsd_pspace_data_handle; > + > +struct fbsd_pspace_data > + { > + /* Offsets in the runtime linker's 'Obj_Entry' structure. */ > + LONGEST off_linkmap; > + LONGEST off_tlsindex; > + bool rtld_offsets_valid; > + }; Unindent the { } and what's between. > +/* Lookup offsets of fields in the runtime linker's 'Obj_Entry' > + structure needed to determine the TLS index of an object file. */ > + > +static void > +fbsd_fetch_rtld_offsets (struct gdbarch *gdbarch, struct fbsd_pspace_data *data) > +{ > + TRY > + { > + /* Fetch offsets from debug symbols in rtld. */ > + struct symbol *obj_entry_sym > + = lookup_symbol_in_language ("Struct_Obj_Entry", NULL, STRUCT_DOMAIN, > + language_c, NULL).symbol; > + if (obj_entry_sym == NULL) > + error (_("Unable to find Struct_Obj_Entry symbol")); > + data->off_linkmap = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym), > + "linkmap", 0).offset / 8; > + data->off_tlsindex = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym), > + "tlsindex", 0).offset / 8; > + data->rtld_offsets_valid = true; > + return; > + } > + CATCH (e, RETURN_MASK_ERROR) > + { > + data->off_linkmap = -1; > + } > + END_CATCH > + > + TRY > + { > + /* Fetch offsets from global variables in libthr. Note that > + this does not work for single-threaded processes that are not > + linked against libthr. */ > + data->off_linkmap = fbsd_read_integer_by_name(gdbarch, > + "_thread_off_linkmap"); > + data->off_tlsindex = fbsd_read_integer_by_name(gdbarch, > + "_thread_off_tlsindex"); Missing spaces before parentheses. > +/* Helper function to fetch the address of a thread-local variable. > + DTV_ADDR is the base address of the thread's dtv array. LM_ADDR is > + the address of the link_map structure for the associated object > + file. */ > + > +extern CORE_ADDR fbsd_get_thread_local_address (struct gdbarch *gdbarch, > + CORE_ADDR dtv_addr, > + CORE_ADDR lm_addr, > + CORE_ADDR offset); Could you document the offset parameter? I know it's obvious for somebody who already knows how TLS works, but if somebody is still a noob, they will appreciate the comment :). Simon