From: John Baldwin <jhb@FreeBSD.org>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 14/24] gdb: read pseudo register through frame
Date: Sat, 11 Nov 2023 12:11:29 -0800 [thread overview]
Message-ID: <970ec0bf-e2ab-4dfe-8a0a-9eadb97784c4@FreeBSD.org> (raw)
In-Reply-To: <20231108051222.1275306-15-simon.marchi@polymtl.ca>
On 11/7/23 9:00 PM, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@efficios.com>
>
> Change gdbarch_pseudo_register_read_value to take a frame instead of a
> regcache. The frame (and formerly the regcache) is used to read raw
> registers needed to make up the pseudo register value. The problem with
> using the regcache is that it always provides raw register values for
> the current frame (frame 0).
>
> Let's say the user wants to read the ebx register on amd64. ebx is a pseudo
> register, obtained by reading the bottom half (bottom 4 bytes) of the
> rbx register, which is a raw register. If the currently selected frame
> is frame 0, it works fine:
>
> (gdb) frame 0
> #0 break_here_asm () at /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S:36
> 36 in /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S
> (gdb) p/x $ebx
> $1 = 0x24252627
> (gdb) p/x $rbx
> $2 = 0x2021222324252627
>
> But if the user is looking at another frame, and the raw register behind
> the pseudo register has been saved at some point in the call stack, then
> we get a wrong answer:
>
> (gdb) frame 1
> #1 0x000055555555517d in caller () at /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S:56
> 56 in /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S
> (gdb) p/x $ebx
> $3 = 0x24252627
> (gdb) p/x $rbx
> $4 = 0x1011121314151617
>
> Here, the value of ebx was computed using the value of rbx in frame 0
> (through the regcache), it should have been computed using the value of
> rbx in frame 1.
>
> In other to make this work properly, make the following changes:
>
> - Make dwarf2_frame_prev_register return nullptr if it doesn't know how
> to unwind a register and that register is a pseudo register.
> Previously, it returned `frame_unwind_got_register`, meaning, in our
> example, "the value of ebx in frame 1 is the same as the value of ebx
> in frame 0", which is obviously false. Return nullptr as a way to
> say "I don't know".
>
> - In frame_unwind_register_value, when prev_register (for instance
> dwarf2_frame_prev_register) returns nullptr, and we are trying to
> read a pseudo register, try to get the register value through
> gdbarch_pseudo_register_read_value or gdbarch_pseudo_register_read.
> If using gdbarch_pseudo_register_read, the behavior is known to be
> broken. Implementations should be migrated to use
> gdbarch_pseudo_register_read_value to fix that.
>
> - Change gdbarch_pseudo_register_read_value to take a frame_info
> instead of a regcache, update implementations (aarch64, amd64, i386).
> In i386-tdep.c, I made a copy of i386_mmx_regnum_to_fp_regnum that
> uses a frame instead of a regcache. The version using the regcache
> is still used by i386_pseudo_register_write. It will get removed in
> a subsequent patch.
>
> - Add some helpers in value.{c,h} to implement the common cases of
> pseudo registers: taking part of a raw register and concatenating
> multiple raw registers.
These are quite a nice change and reduce a lot of the copy/paste that would
otherwise be present.
> - Update readable_regcache::{cooked_read,cooked_read_value} to pass the
> current frame to gdbarch_pseudo_register_read_value. Passing the
> current frame will give the same behavior as before: for frame 0, raw
> registers will be read from the current thread's regcache.
>
> Notes:
>
> - I do not plan on changing gdbarch_pseudo_register_read to receive a
> frame instead of a regcache. That method is considered deprecated.
> Instead, we should be working on migrating implementations to use
> gdbarch_pseudo_register_read_value instead.
>
> - In frame_unwind_register_value, we still ask the unwinder to try to
> unwind pseudo register values. It's apparently possible for the
> debug info to provide information about [1] pseudo registers, so we
> want to try that first, before falling back to computing them
> ourselves.
Only updating read_value to use a frame seems sensible to me as a plan.
I had to stare at the update to handle reading the BND pseudo registers
for i386 for a while, but it does look correct to me.
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
--
John Baldwin
next prev parent reply other threads:[~2023-11-11 20:11 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 5:00 [PATCH 00/24] Fix reading and writing pseudo registers in non-current frames Simon Marchi
2023-11-08 5:00 ` [PATCH 01/24] gdb: don't handle i386 k registers as pseudo registers Simon Marchi
2023-11-11 19:29 ` John Baldwin
2023-11-08 5:00 ` [PATCH 02/24] gdb: use reg_buffer_common throughout gdbsupport/common-regcache.h Simon Marchi
2023-11-11 19:42 ` John Baldwin
2023-11-08 5:00 ` [PATCH 03/24] gdb: make store_integer take an array_view Simon Marchi
2023-11-08 5:00 ` [PATCH 04/24] gdb: simplify conditions in regcache::{read,write,raw_collect,raw_supply}_part Simon Marchi
2023-11-08 5:00 ` [PATCH 05/24] gdb: change regcache interface to use array_view Simon Marchi
2023-11-13 13:43 ` Andrew Burgess
2023-11-13 14:00 ` Andrew Burgess
2023-11-13 16:47 ` Simon Marchi
2023-11-08 5:00 ` [PATCH 06/24] gdb: fix bugs in {get,put}_frame_register_bytes Simon Marchi
2023-11-13 15:00 ` Andrew Burgess
2023-11-13 19:51 ` Simon Marchi
2023-11-08 5:00 ` [PATCH 07/24] gdb: make put_frame_register take an array_view Simon Marchi
2023-11-08 5:00 ` [PATCH 08/24] gdb: change value_of_register and value_of_register_lazy to take the next frame Simon Marchi
2023-11-08 5:00 ` [PATCH 09/24] gdb: remove frame_register Simon Marchi
2023-11-08 5:00 ` [PATCH 10/24] gdb: make put_frame_register take the next frame Simon Marchi
2023-11-08 5:00 ` [PATCH 11/24] gdb: make put_frame_register_bytes " Simon Marchi
2023-11-08 5:00 ` [PATCH 12/24] gdb: make get_frame_register_bytes " Simon Marchi
2023-11-08 5:00 ` [PATCH 13/24] gdb: add value::allocate_register Simon Marchi
2023-11-08 5:00 ` [PATCH 14/24] gdb: read pseudo register through frame Simon Marchi
2023-11-11 20:11 ` John Baldwin [this message]
2023-11-08 5:00 ` [PATCH 15/24] gdb: change parameter name in frame_unwind_register_unsigned declaration Simon Marchi
2023-11-08 5:01 ` [PATCH 16/24] gdb: rename gdbarch_pseudo_register_write to gdbarch_deprecated_pseudo_register_write Simon Marchi
2023-11-14 12:12 ` Andrew Burgess
2023-11-14 15:16 ` Simon Marchi
2023-11-08 5:01 ` [PATCH 17/24] gdb: add gdbarch_pseudo_register_write that takes a frame Simon Marchi
2023-11-14 12:20 ` Andrew Burgess
2023-11-14 15:20 ` Simon Marchi
2023-11-08 5:01 ` [PATCH 18/24] gdb: migrate i386 and amd64 to the new gdbarch_pseudo_register_write Simon Marchi
2023-11-11 20:16 ` John Baldwin
2023-11-13 2:59 ` Simon Marchi
2023-11-08 5:01 ` [PATCH 19/24] gdb: make aarch64_za_offsets_from_regnum return za_offsets Simon Marchi
2023-11-08 5:01 ` [PATCH 20/24] gdb: add missing raw register read in aarch64_sme_pseudo_register_write Simon Marchi
2023-11-08 5:01 ` [PATCH 21/24] gdb: migrate aarch64 to new gdbarch_pseudo_register_write Simon Marchi
2023-11-08 5:01 ` [PATCH 22/24] gdb: migrate arm to gdbarch_pseudo_register_read_value Simon Marchi
2023-11-08 5:01 ` [PATCH 23/24] gdb: migrate arm to new gdbarch_pseudo_register_write Simon Marchi
2023-11-08 5:01 ` [PATCH 24/24] gdb/testsuite: add tests for unwinding of pseudo registers Simon Marchi
2023-11-08 5:16 ` [PATCH 00/24] Fix reading and writing pseudo registers in non-current frames Simon Marchi
2023-11-09 3:05 ` Simon Marchi
2023-11-08 11:57 ` Luis Machado
2023-11-08 15:47 ` Simon Marchi
2023-11-08 17:08 ` Luis Machado
2023-11-08 19:34 ` Simon Marchi
2023-11-09 19:04 ` Simon Marchi
2023-11-13 13:10 ` Luis Machado
2023-11-13 15:08 ` Luis Machado
2023-11-11 20:26 ` John Baldwin
2023-11-13 3:03 ` Simon Marchi
2023-12-01 16:27 Simon Marchi
2023-12-01 16:27 ` [PATCH 14/24] gdb: read pseudo register through frame Simon Marchi
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=970ec0bf-e2ab-4dfe-8a0a-9eadb97784c4@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).