From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 842633858C5E for ; Wed, 11 Oct 2023 15:37:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 842633858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B00B52185D; Wed, 11 Oct 2023 15:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697038626; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HpE2fbsyJjcNIq2ULP02ZUfTd1p6U7oPIpn2N+WFkkI=; b=kVcXtRdTAlSf7p88GeXc+lzJK3ra+V8FPJFHYa28S6Jcypd/qAzPnutkaR3OPpOsBEus/1 Yx+P7g8QMQGvA0Lqjbti3iM1eECWWELICOHDiGnb73eXrqRS7acPNI4ASCzqXbpilacYyc HNMo3ynlVJel0A5CFGAnBWLW5HdInpc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697038626; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HpE2fbsyJjcNIq2ULP02ZUfTd1p6U7oPIpn2N+WFkkI=; b=5fos5/krx92GBjeAyO5NEc4LeF06OMM6NsXdMRChq46w/wfZAe2P4I5D9eULhMFQj/xUiJ 9NdsxPaj9fmJD7Dw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9AF2A134F5; Wed, 11 Oct 2023 15:37:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UuDEJCLBJmWZEgAAMHmgww (envelope-from ); Wed, 11 Oct 2023 15:37:06 +0000 Message-ID: <3f08d572-0043-4d43-9ab8-b4f48865b6ab@suse.de> Date: Wed, 11 Oct 2023 17:37:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index Content-Language: en-US To: Tom Tromey , Tom de Vries via Gdb-patches References: <20231006183104.27689-1-tdevries@suse.de> <20231006183104.27689-2-tdevries@suse.de> <87cyxmuvy9.fsf@tromey.com> From: Tom de Vries In-Reply-To: <87cyxmuvy9.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -4.09 X-Spamd-Result: default: False [-4.09 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,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 List-Id: On 10/10/23 21:19, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries via Gdb-patches writes: > > Tom> From: Matheus Branco Borella > Tom> This patch adds a new section to the DWARF index containing the name > Tom> and the language of the main function symbol, gathered from > Tom> `cooked_index::get_main`, if available. > > This patch has a bunch of formatting nits. I think it's also a little > incorrect in its handling of unknown languages / its understanding of > its own idea of how the "0" case is handled. > > Tom> +@item The shortcut table > Tom> +This is a data structure with the following fields: > Tom> + > Tom> +@table @asis > Tom> +@item Language of main > Tom> +An @code{offset_type} value indicating the language of the main function as a > Tom> +@code{DW_LANG_} constant. This value will be zero if main function information > Tom> +is not present. > Tom> + > Tom> +@item Name of main > Tom> +An @code{offset_type} value indicating the offset of the main function's name > Tom> +in the constant pool. This value must be ignored if the value for the language > Tom> +of main is zero. > > This phrasing is a little strange. The index-writing code seems to omit > the name field if the language is unknown. However, the text here makes > it sound like the field is present but must be ignored. > > If the writing code is correct, I would suggest changing this to say > "This field is not present if..." > > Tom> + dwarf_source_language dw_lang = (dwarf_source_language)0; > > gdb style puts a space after the ")" of a cast. > There's a lot of cases like this. > Done. > Tom> + shortcuts.append_uint (4, BFD_ENDIAN_LITTLE, dw_lang); > Tom> + shortcuts.append_offset (main_name_offset); > > The first ljne using append_uint seems confusing... it made me wonder > why it isn't using offset_type. But in the end I don't think there's > any reason. "offset_type" is used for all kinds of fields in the index, > it's better to just use that here. It is 4 bytes anyway. > Done. > Tom> +/* Sets the name and language of the main function from the shortcut table. */ > Tom> + > Tom> +static void > Tom> +set_main_name_from_gdb_index (dwarf2_per_objfile *per_objfile, > Tom> + mapped_gdb_index *index) > Tom> +{ > Tom> + const auto expected_size = 4 + sizeof (offset_type); > > Better to use 2 * sizeof (offset_type) IMO. > Done. > Tom> + if (index->shortcut_table.size () < expected_size) > Tom> + /* The data in the section is not present, is corrupted or is in a version > Tom> + * we don't know about. Regardless, we can't make use of it. */ > Tom> + return; > > The leading "*" on comments is not gdb style. Several cases of this. > Done. > This is where the reader seems to expect that both members are always > written. > > Tom> + > Tom> + auto ptr = index->shortcut_table.data (); > Tom> + const auto dw_lang = extract_unsigned_integer (ptr, 4, BFD_ENDIAN_LITTLE); > Tom> + if (dw_lang >= DW_LANG_hi_user) > Tom> + { > Tom> + complaint (_(".gdb_index shortcut table has invalid main language %u"), > Tom> + (unsigned) dw_lang); > Tom> + return; > Tom> + } > > IMO it would be better for this check to happen in > dwarf_lang_to_enum_language. Suppose gdb adds support for a new language. > That version of gdb may still emit index version 9, but the index > won't be directly usable by an older gdb. > AFAIU the check is the usual: is the value we've just read in the valid range. It makes no assumption about which language gdb supports. So I'm not sure this needs to be moved. > Tom> + const auto name = (const char*) (index->constant_pool.data () + name_offset); > > Space before "*". There were some with "&" as well but I didn't > remember to point them out before deleting the patch text. > Done. Submitted here ( https://sourceware.org/pipermail/gdb-patches/2023-October/203161.html ). Thanks, - Tom