Add support for the __flash qualifier on AVR
The __flash qualifier is part of the named address spaces for AVR [1]. It
allows putting read-only data in the flash memory, normally reserved for
code.
When used together with a pointer, the DW_AT_address_class attribute is set
to 1 and allows GDB to detect that when it will be dereferenced, the data
will be loaded from the flash memory (with the LPM instruction).
We can now properly debug the following code:
~~~
const __flash char data_in_flash = 0xab;
int
main (void)
{
const __flash char *pointer_to_flash = &data_in_flash;
}
~~~
~~~
(gdb) print pointer_to_flash
$1 = 0x1e8 <data_in_flash> "\253"
(gdb) print/x *pointer_to_flash
$2 = 0xab
(gdb) x/x pointer_to_flash
0x1e8 <data_in_flash>: 0xXXXXXXab
~~~
Whereas previously, GDB would revert to the default address space which is
RAM and mapped in higher memory:
~~~
(gdb) print pointer_to_flash
$1 = 0x8001e8 ""
~~~
[1] https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html
2014-07-15 Pierre Langlois <pierre.langlois@embecosm.com>
gdb/
* avr-tdep.c (AVR_TYPE_ADDRESS_CLASS_FLASH): New macro.
(AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH): Likewise.
(avr_address_to_pointer): Check for AVR_TYPE_ADDRESS_CLASS_FLASH.
(avr_pointer_to_address): Likewise.
(avr_address_class_type_flags): New function.
(avr_address_class_type_flags_to_name): Likewise.
(avr_address_class_name_to_type_flags): Likewise.
(avr_gdbarch_init): Set address_class_type_flags,
address_class_type_flags_to_name and
address_class_name_to_type_flags.
gdb/testsuite/
* gdb.arch/avr-flash-qualifer.c: New.
* gdb.arch/avr-flash-qualifer.exp: New.