Re: Questions on XML register descriptions

"H. Peter Anvin via Gdb" <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.