From: "H. Peter Anvin via Gdb" <gdb@sourceware.org>
To: Luis Machado <luis.machado@arm.com>, gdb@sourceware.org
Subject: Re: Questions on XML register descriptions
Date: Sun, 7 Jan 2024 22:21:16 -0800 [thread overview]
Message-ID: <8588938b-b2c1-46e8-b6ba-5ad00b9e9b17@zytor.com> (raw)
In-Reply-To: <a6348a4c-6b2b-40ab-a03f-b6f4c448d255@arm.com>
On 12/29/23 05:41, Luis Machado via Gdb wrote:
>
> Ok, I went to check this again, as I had forgotten what gdb did. It looks like you're right. From the code comment about handling the g packet reply from the remote:
>
> /* If this is smaller than we guessed the 'g' packet would be,
> update our records. A 'g' reply that doesn't include a register's
> value implies either that the register is not available, or that
> the 'p' packet must be used. */
>
> So it looks like you can force gdb to fallback to the p packet by making the g reply packet of minimum size.
>
That's great.
>>
>> The compiler communicating it isn't essential here as I'm not trying to expose things that are visible to the compiler. What I want to do is to be able to use gdb to examine/access non-CPU-visible address spaces, like the physical RAM even when it is paged out, or the I/O address space.
>>
>> The problem becomes that the type of the pointer is lost if it is simply converted to an integer, and casting it back to a pointer causes it to be truncated back to 16 bits.
>
> Yeah, so this is the type of knowledge gdb must have in order to handle things correctly. Technically you could handle things correctly from the remote's side by inspecing the memory read/write packets, determining what the address space should be, what the pointer size might be and then going to fetch that information from wherever address space it belongs to.
>
>>
>> I tried doing a Python script like this, but it ran into the above problem (plus the connection problem mentioned below):
>>
>
> What particular error do you get, out of curiosity?
>
>> #!/usr/bin/python
>>
>> import gdb
>>
>> class Addrspace (gdb.Function):
>> """Convert an address or a pointer to the named address space."""
>> def __init__ (self, name, base, mask):
>> self.name = name
>> self.mask = mask
>> self.base = base
>> arch = gdb.selected_inferior().architecture()
>> bits = 8
>> while (mask|base) >> bits:
>> bits <<= 1
>> self.itype = arch.integer_type(bits, False)
>> super (Addrspace, self).__init__ (name)
>>
>> def invoke (self, val):
>> type = val.type
>> return ((val.cast(self.itype) & self.mask) \
>> + self.base).cast(type)
>>
>> _io = Addrspace ("io", 0x01000000, 0xffff)
>>
The problem is that when the address is cast back to a pointer, it is
truncated to the pointer size.
Having thought about this some more I wonder if it is possible to create
a new Type similar to a normal pointer but larger, and use that as the
new type instead of val.type.
-hpa
prev parent reply other threads:[~2024-01-08 6:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-26 22:42 H. Peter Anvin via Gdb
2023-12-27 11:28 ` Luis Machado via Gdb
2023-12-28 22:09 ` H. Peter Anvin via Gdb
2023-12-29 13:41 ` Luis Machado via Gdb
2024-01-08 6:21 ` H. Peter Anvin via Gdb [this message]
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=8588938b-b2c1-46e8-b6ba-5ad00b9e9b17@zytor.com \
--to=gdb@sourceware.org \
--cc=hpa@zytor.com \
--cc=luis.machado@arm.com \
/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