From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id 75C3D3858C54 for ; Mon, 16 Oct 2023 23:52:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75C3D3858C54 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 75C3D3858C54 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=96.47.72.81 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697500358; cv=pass; b=tfTbASNGEZ/+8WGnT8j35MtYP4LYO5UcB2YAgJnC63S2kMEneoALtQggTtUH/h21Xn3GF8DmA0COPME6w+tdyjwsGLJ7lrMzMdY8/FRQTBi9YEMWWSWXSakh+zauCQx26hCOi5vcU3NWKIVcrWL4+nKwRYIACtO+l/ASn/OReBs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697500358; c=relaxed/simple; bh=9b5VUix+dC1ORFAO6TXdbD6K7BD3g/cPQbUFG/JkeqM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=C5L+yNy+hytPLpgGfHEpehZ3gG3v0NDYXLFoh3TrwC8GBe7HnoSZdbN30ohiIVGO2Hfr6nBWHU0PzMWDezF8m31GPB81/ebg1fBNPJ68zetnB6KeTDPFrCHYRLAiLqF0ClQxgGPp5K8xuPsE7P10FI4UMi6TwUL4PrXDr8VJpSk= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4S8Ynd2NV3z3VGV; Mon, 16 Oct 2023 23:52:37 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S8Ynd1XWqz3HHP; Mon, 16 Oct 2023 23:52:37 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697500357; h=from:from:reply-to:subject:subject: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=n4zkSbA8eb2jhGmyS7gqC8NaTGm0zuPIFnSlnDzL3Xg=; b=NSPnnBsUZA9FH96SRqj6x+cJ/ePBoh+JAH5AjNGNEBg+NszD15MxeW7kNz90ShAi6RiVAc 0/vC9MQBGW1io/9BTeHZeK6kgte0TA5+fLGWDhbvXPu0oCLvlEz/wowbEYYTw5wXVhr2xA fi5TKN9p1xIOZgsdCptNH3u/inunJAnj1SbzJB94CYSMxn6Se+FWUsnqZ5Rwzcm/qyQVuk EKXF4JLlI8ERpeto6oktimXTV8mNnzqN7Rq9eeLo0X328oM3OMfR2HkKJyFiQ/X5Umezhd E/6s96v+rVWxOKSXoTuwbbtn//cvd773wf7QingsYksZepAVJGJttFVSM+mo5A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697500357; a=rsa-sha256; cv=none; b=JdMmVj2tzNNN697VjYSQqyhRGzTYmp4zkZx1zNrN8GlAvIy5F/k9mUbwo5G0ecLNAnKnZx AzYRuJu1AymqZW0mCVrKU1sEr/ydUmVosjNDoWVxm89DQhQV9N87lfdvv7Froo50MQb4ad TTjET3aOI50vU3K3dcp1A6T9oXqohFM1Lyox+JaS0WHU0GNUVhyRjoPQxI3aGJquH1vhrb 8wSBLwya5zhjpHl/rOGzjcQgEQRTotUsMido7C0MDHW275n1HH0vpK6PU2M/+jKYSguaBu cmXPWEwEkuVMYKT4X66UwvmwRJKh+RBUbTI/FbOFVBkjDYjvkr0Kj/GBxRQ2oA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697500357; h=from:from:reply-to:subject:subject: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=n4zkSbA8eb2jhGmyS7gqC8NaTGm0zuPIFnSlnDzL3Xg=; b=gLv/K1F7Obenfxj0fzfLKwA1DIQkQy/N/YxsF929brP0/kkumRDKybY/yyTfmyDKmi7RAF fc5Qqd+NVFiQ8AXRnJCJHLgQWE18K3acPlnKPDk9f+Zi03IfM2GC8CulnzzqaeGW0CAhRG O2nz1CarAYcpJWyIU1fBn8+ZHS3a4v7hfewUJq7LiLNhj1TC3k0Qi2VZduPCTidhHR6bn1 84mRiOmyCCKoAFpRjagDJ4BwCEra4hjq8QAepgm1hHNTx8dFSoGUREz20uPR05kw8M3vjm 2yjxL6Jzo0C16f+0c0GCU40k/ckwOVqjmoVfZIvoTUntkkx1quYL+IySGX3yCA== Received: from [IPV6:2601:648:8683:39a0:f055:f679:76c4:bebe] (unknown [IPv6:2601:648:8683:39a0:f055:f679:76c4:bebe]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4S8Ync5s0Yztww; Mon, 16 Oct 2023 23:52:36 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Mon, 16 Oct 2023 16:52:35 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [RFC 02/13] i387-tdep: Add function to read XSAVE layout from NT_X86_CPUID Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org References: <20231009183617.24862-1-jhb@FreeBSD.org> <20231009183617.24862-3-jhb@FreeBSD.org> <44bfb99d-7c4a-4916-9812-21c7d84b5c7e@polymtl.ca> From: John Baldwin In-Reply-To: <44bfb99d-7c4a-4916-9812-21c7d84b5c7e@polymtl.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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/11/23 9:27 PM, Simon Marchi wrote: > > > On 2023-10-09 14:36, John Baldwin wrote: >> This can be used by x86 arches to determine the XSAVE layout instead >> of guessing based on the XCR0 mask and XSAVE register note size. > > Just some nits below: > >> +typedef std::unordered_map cpuid_map; > > For new stuff I would suggest: > > using cpuid_map = std::unordered_map; Ok. >> + >> +static cpuid_map >> +i387_parse_cpuid_from_core (bfd *bfd) >> +{ >> + asection *section = bfd_get_section_by_name (bfd, ".reg-x86-cpuid"); >> + if (section == nullptr) >> + return {}; >> + >> + size_t size = bfd_section_size (section); >> + if (size == 0 || (size % (6 * 4)) != 0) > > That 4 could be `sizeof (uint32_t)`. And `6 * 4` appears below again, > it could a constexpr value with a name like entry_size. Ok. >> + return {}; >> + >> + char contents[size]; >> + if (!bfd_get_section_contents (bfd, section, contents, 0, size)) >> + { >> + warning (_("Couldn't read `.reg-x86-cpuid' section in core file.")); >> + return {}; >> + } >> + >> + cpuid_map map; >> + size_t index = 0; >> + while (index < size) >> + { >> + uint32_t leaf = bfd_get_32 (bfd, contents + index); >> + uint32_t count = bfd_get_32 (bfd, contents + index + 4); >> + uint32_t eax = bfd_get_32 (bfd, contents + index + 8); >> + uint32_t ebx = bfd_get_32 (bfd, contents + index + 12); >> + uint32_t ecx = bfd_get_32 (bfd, contents + index + 16); >> + uint32_t edx = bfd_get_32 (bfd, contents + index + 20); >> + >> + if (map.count (cpuid_key (leaf, count)) != 0) >> + { >> + warning (_("Duplicate cpuid leaf %#x,%#x"), leaf, count); >> + return {}; >> + } >> + map.emplace (cpuid_key (leaf, count), >> + cpuid_values (eax, ebx, ecx, edx)); > > This could be slightly more optimal using map::try_emplace (to avoid > having two map lookups). Ok. Presumably C++17 will be required before this series lands, and I don't plan to backport it to GDB 14. (If I did it could also turn back into a loop + emplace though as part of the backport.) -- John Baldwin