From: John Baldwin <jhb@FreeBSD.org>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [RFC 02/13] i387-tdep: Add function to read XSAVE layout from NT_X86_CPUID
Date: Mon, 16 Oct 2023 16:52:35 -0700 [thread overview]
Message-ID: <dd92661f-0463-aaf9-de48-2dad4ca5e3d6@FreeBSD.org> (raw)
In-Reply-To: <44bfb99d-7c4a-4916-9812-21c7d84b5c7e@polymtl.ca>
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_key, cpuid_values> cpuid_map;
>
> For new stuff I would suggest:
>
> using cpuid_map = std::unordered_map<cpuid_key, cpuid_values>;
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
next prev parent reply other threads:[~2023-10-16 23:52 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-09 18:36 [RFC 00/13] Proposal for a new NT_X86_CPUID core dump note John Baldwin
2023-10-09 18:36 ` [RFC 01/13] binutils: Support for the " John Baldwin
2023-10-16 9:23 ` Lancelot SIX
2023-10-16 23:23 ` John Baldwin
2023-10-09 18:36 ` [RFC 02/13] i387-tdep: Add function to read XSAVE layout from NT_X86_CPUID John Baldwin
2023-10-12 4:27 ` Simon Marchi
2023-10-16 23:52 ` John Baldwin [this message]
2023-10-16 9:17 ` Lancelot SIX
2023-10-17 0:04 ` John Baldwin
2023-10-09 18:36 ` [RFC 03/13] gdb: Use NT_X86_CPUID in x86 FreeBSD architectures to read XSAVE layouts John Baldwin
2023-10-09 18:36 ` [RFC 04/13] " John Baldwin
2023-10-12 4:28 ` Simon Marchi
2023-10-17 0:07 ` John Baldwin
2023-10-09 18:36 ` [RFC 05/13] nat/x86-cpuid.h: Remove non-x86 fallbacks John Baldwin
2023-10-12 4:29 ` Simon Marchi
2023-10-09 18:36 ` [RFC 06/13] nat/x86-cpuid: Add a function to build the contents of a NT_X86_CPUID note John Baldwin
2023-10-12 4:41 ` Simon Marchi
2023-10-17 0:22 ` John Baldwin
2023-10-09 18:36 ` [RFC 07/13] x86_elf_make_cpuid_note: Helper routine to build NT_X86_CPUID ELF note John Baldwin
2023-10-09 18:36 ` [RFC 08/13] x86-fbsd-nat: Support fetching TARGET_OBJECT_X86_CPUID objects John Baldwin
2023-10-09 18:36 ` [RFC 09/13] fbsd-tdep: Export fbsd_make_corefile_notes John Baldwin
2023-10-09 18:36 ` [RFC 10/13] {amd64, i386}-fbsd-tdep: Include NT_X86_CPUID notes in core dumps from gcore John Baldwin
2023-10-16 9:31 ` Lancelot SIX
2023-10-17 0:26 ` John Baldwin
2023-10-09 18:36 ` [RFC 11/13] x86-linux-nat: Support fetching TARGET_OBJECT_X86_CPUID objects John Baldwin
2023-10-09 18:36 ` [RFC 12/13] linux-tdep: Export linux_make_corefile_notes John Baldwin
2023-10-09 18:36 ` [RFC 13/13] {amd64, i386}-linux-tdep: Include NT_X86_CPUID notes in core dumps from gcore John Baldwin
2023-10-10 16:30 ` [RFC 00/13] Proposal for a new NT_X86_CPUID core dump note George, Jini Susan
2023-10-12 4:01 ` Simon Marchi
2023-10-12 14:33 ` Simon Marchi
2023-10-12 17:18 ` John Baldwin
2023-10-13 9:38 ` George, Jini Susan
2023-10-17 0:36 ` John Baldwin
2023-10-26 16:18 ` George, Jini Susan
2023-10-27 2:53 ` John Baldwin
2023-10-27 11:11 ` George, Jini Susan
2023-10-31 16:41 ` John Baldwin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dd92661f-0463-aaf9-de48-2dad4ca5e3d6@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox