Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* How to handle different sizes of pointers in GDB?
@ 2024-08-19 10:20 Iru Cai via Gdb
  2024-08-19 10:42 ` Luis Machado via Gdb
  0 siblings, 1 reply; 3+ messages in thread
From: Iru Cai via Gdb @ 2024-08-19 10:20 UTC (permalink / raw)
  To: gdb

Hi,

I'm porting GDB to a new architecture. Now the application for this
architecture has two kinds of pointers in different sizes, one is 32-bit
and one is 64-bit. I have done the following things:

1. I use set_gdbarch_addr_bit(gdbarch,64) and
set_gdbarch_ptr_bit(gdbarch,64) to set both the addresses and the pointers
64-bit.
2. I tried to add a DW_AT_byte_size and DW_AT_address_class information
under each of the pointer type with DW_TAG_pointer_type in the compiler for
my new architecture.

My program can be like this:

int strlen32(const char *s) { /* s is 32-bit ... */ }
int strlen64(const _PTR64 char *s) { /* s is 64-bit ... */ }

However, GDB doesn't seem to get the correct type when printing the frame
arguments in read_frame_arg(), when I debug into strlen32, GDB can make the
GDB server crash because GDB is trying to read from a 64-bit address, which
it thinks is the value of s. And when I debug this GDB read_frame_arg(), I
see the type length of s in strlen32 is still 8 bytes.

So is there anything missing to make GDB use the type length information
from the DWARF debugging info?

Regards,
Iru

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to handle different sizes of pointers in GDB?
  2024-08-19 10:20 How to handle different sizes of pointers in GDB? Iru Cai via Gdb
@ 2024-08-19 10:42 ` Luis Machado via Gdb
  2024-08-21  1:51   ` Iru Cai via Gdb
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Machado via Gdb @ 2024-08-19 10:42 UTC (permalink / raw)
  To: Iru Cai, gdb

On 8/19/24 11:20, Iru Cai via Gdb wrote:
> Hi,
> 
> I'm porting GDB to a new architecture. Now the application for this
> architecture has two kinds of pointers in different sizes, one is 32-bit
> and one is 64-bit. I have done the following things:
> 
> 1. I use set_gdbarch_addr_bit(gdbarch,64) and
> set_gdbarch_ptr_bit(gdbarch,64) to set both the addresses and the pointers
> 64-bit.
> 2. I tried to add a DW_AT_byte_size and DW_AT_address_class information
> under each of the pointer type with DW_TAG_pointer_type in the compiler for
> my new architecture.
> 
> My program can be like this:
> 
> int strlen32(const char *s) { /* s is 32-bit ... */ }
> int strlen64(const _PTR64 char *s) { /* s is 64-bit ... */ }
> 
> However, GDB doesn't seem to get the correct type when printing the frame
> arguments in read_frame_arg(), when I debug into strlen32, GDB can make the
> GDB server crash because GDB is trying to read from a 64-bit address, which
> it thinks is the value of s. And when I debug this GDB read_frame_arg(), I
> see the type length of s in strlen32 is still 8 bytes.
> 
> So is there anything missing to make GDB use the type length information
> from the DWARF debugging info?
> 
> Regards,
> Iru

From what I recall, you'll need to make sure your address class is correct in DWARF for the
different pointer types. Assuming that is correct, have you also implemented the 3 hooks
that deal with address classes?

set_gdbarch_address_class_type_flags
set_gdbarch_address_class_type_flags_to_name
set_gdbarch_address_class_name_to_type_flags

Check the s390 code for some reference in gdb/s390-tdep.c

Even with those set correct, gdb can still get confused with pointer sizes depending on
which gdb subsystem is handling it. The type information sometimes gets lost when we cross
some gdb internal boundaries, and then we fallback to the default pointer size.

I hope that helps some.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to handle different sizes of pointers in GDB?
  2024-08-19 10:42 ` Luis Machado via Gdb
@ 2024-08-21  1:51   ` Iru Cai via Gdb
  0 siblings, 0 replies; 3+ messages in thread
From: Iru Cai via Gdb @ 2024-08-21  1:51 UTC (permalink / raw)
  To: Luis Machado; +Cc: gdb

Thanks for your help.

On Mon, Aug 19, 2024 at 6:42 PM Luis Machado <luis.machado@arm.com> wrote:

>
> From what I recall, you'll need to make sure your address class is correct
> in DWARF for the
> different pointer types. Assuming that is correct, have you also
> implemented the 3 hooks
> that deal with address classes?
>
> set_gdbarch_address_class_type_flags
> set_gdbarch_address_class_type_flags_to_name
> set_gdbarch_address_class_name_to_type_flags
>
>
Now I'm using set_gdbarch_address_class_type_flags to make the DWARF reader
set the instance_flags of the pointer types, and register a
gdbarch_pointer_to_address method. I can see GDB can call my
pointer_to_address for each pointer, and type->length() is still 8, but I
can get the address class from type->instance_flags() and use it to know
the pointer size.


> Check the s390 code for some reference in gdb/s390-tdep.c
>
> Even with those set correct, gdb can still get confused with pointer sizes
> depending on
> which gdb subsystem is handling it. The type information sometimes gets
> lost when we cross
> some gdb internal boundaries, and then we fallback to the default pointer
> size.
>
> I hope that helps some.
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-21  1:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-19 10:20 How to handle different sizes of pointers in GDB? Iru Cai via Gdb
2024-08-19 10:42 ` Luis Machado via Gdb
2024-08-21  1:51   ` Iru Cai via Gdb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox