aboutsummaryrefslogtreecommitdiff
path: root/gdb/avr-tdep.c
diff options
context:
space:
mode:
authorPierre Langlois <pierre.langlois@embecosm.com>2014-07-15 17:03:09 +0100
committerPierre Langlois <pierre.langlois@embecosm.com>2014-07-15 17:03:09 +0100
commit487d975399dfcb2bb2f0998a7d12bd62acdd9fa1 (patch)
tree2420529857d9215dbd6d63a98a1c38ed98c58e60 /gdb/avr-tdep.c
parent57745c903f78ffdb10a6198a6e35e5a1e63ea4b0 (diff)
downloadgdb-487d975399dfcb2bb2f0998a7d12bd62acdd9fa1.zip
gdb-487d975399dfcb2bb2f0998a7d12bd62acdd9fa1.tar.gz
gdb-487d975399dfcb2bb2f0998a7d12bd62acdd9fa1.tar.bz2
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.
Diffstat (limited to 'gdb/avr-tdep.c')
-rw-r--r--gdb/avr-tdep.c86
1 files changed, 81 insertions, 5 deletions
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 9b0bfaf..be0b543 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -71,6 +71,16 @@
/* Constants: prefixed with AVR_ to avoid name space clashes */
+/* Address space flags */
+
+/* We are assigning the TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 to the flash address
+ space. */
+
+#define AVR_TYPE_ADDRESS_CLASS_FLASH TYPE_ADDRESS_CLASS_1
+#define AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH \
+ TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
+
+
enum
{
AVR_REG_W = 24,
@@ -295,10 +305,19 @@ avr_address_to_pointer (struct gdbarch *gdbarch,
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ /* Is it a data address in flash? */
+ if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
+ {
+ /* A data address in flash is always byte addressed. */
+ store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
+ avr_convert_iaddr_to_raw (addr));
+ }
/* Is it a code address? */
- if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
- || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
+ else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
+ || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
{
+ /* A code address, either a function pointer or the program counter, is
+ word (16 bits) addressed. */
store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
avr_convert_iaddr_to_raw (addr >> 1));
}
@@ -318,10 +337,13 @@ avr_pointer_to_address (struct gdbarch *gdbarch,
CORE_ADDR addr
= extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order);
+ /* Is it a data address in flash? */
+ if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
+ return avr_make_iaddr (addr);
/* Is it a code address? */
- if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
- || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD
- || TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)))
+ else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
+ || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD
+ || TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)))
return avr_make_iaddr (addr << 1);
else
return avr_make_saddr (addr);
@@ -1342,6 +1364,54 @@ avr_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
return -1;
}
+/* Implementation of `address_class_type_flags' gdbarch method.
+
+ This method maps DW_AT_address_class attributes to a
+ type_instance_flag_value. */
+
+static int
+avr_address_class_type_flags (int byte_size, int dwarf2_addr_class)
+{
+ /* The value 1 of the DW_AT_address_class attribute corresponds to the
+ __flash qualifier. Note that this attribute is only valid with
+ pointer types and therefore the flag is set to the pointer type and
+ not its target type. */
+ if (dwarf2_addr_class == 1 && byte_size == 2)
+ return AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH;
+ return 0;
+}
+
+/* Implementation of `address_class_type_flags_to_name' gdbarch method.
+
+ Convert a type_instance_flag_value to an address space qualifier. */
+
+static const char*
+avr_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
+{
+ if (type_flags & AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH)
+ return "flash";
+ else
+ return NULL;
+}
+
+/* Implementation of `address_class_name_to_type_flags' gdbarch method.
+
+ Convert an address space qualifier to a type_instance_flag_value. */
+
+static int
+avr_address_class_name_to_type_flags (struct gdbarch *gdbarch,
+ const char* name,
+ int *type_flags_ptr)
+{
+ if (strcmp (name, "flash") == 0)
+ {
+ *type_flags_ptr = AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH;
+ return 1;
+ }
+ else
+ return 0;
+}
+
/* Initialize the gdbarch structure for the AVR's. */
static struct gdbarch *
@@ -1452,6 +1522,12 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_unwind_pc (gdbarch, avr_unwind_pc);
set_gdbarch_unwind_sp (gdbarch, avr_unwind_sp);
+ set_gdbarch_address_class_type_flags (gdbarch, avr_address_class_type_flags);
+ set_gdbarch_address_class_name_to_type_flags
+ (gdbarch, avr_address_class_name_to_type_flags);
+ set_gdbarch_address_class_type_flags_to_name
+ (gdbarch, avr_address_class_type_flags_to_name);
+
return gdbarch;
}