Add support for the __flash qualifier on AVR
authorPierre Langlois <pierre.langlois@embecosm.com>
Tue, 15 Jul 2014 16:03:09 +0000 (17:03 +0100)
committerPierre Langlois <pierre.langlois@embecosm.com>
Tue, 15 Jul 2014 16:03:09 +0000 (17:03 +0100)
commit487d975399dfcb2bb2f0998a7d12bd62acdd9fa1
tree2420529857d9215dbd6d63a98a1c38ed98c58e60
parent57745c903f78ffdb10a6198a6e35e5a1e63ea4b0
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.
gdb/ChangeLog
gdb/avr-tdep.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.arch/avr-flash-qualifier.c [new file with mode: 0644]
gdb/testsuite/gdb.arch/avr-flash-qualifier.exp [new file with mode: 0644]