[PATCH v2 4/7] gdbarch: add addressable_memory_unit_size method

Simon Marchi
2015-04-15T19:47:53Z

Add a new gdbarch method to get the length of an addressable memory unit
for a given architecture. The default implementation returns 1.

gdb/ChangeLog:

* arch-utils.h (default_addressable_memory_unit_size): New.
* arch-utils.c (default_addressable_memory_unit_size): New.
* gdbarch.sh (addressable_memory_unit_size): New.
* gdbarch.h: Re-generated.
* gdbarch.c: Re-generated.
---
gdb/arch-utils.c | 9 +++++++++
gdb/arch-utils.h | 1 +
gdb/gdbarch.c | 23 +++++++++++++++++++++++
gdb/gdbarch.h | 7 +++++++
gdb/gdbarch.sh | 5 +++++
5 files changed, 45 insertions(+)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index e1c8ab0..3bb182e 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -882,6 +882,15 @@ default_gnu_triplet_regexp (struct gdbarch *gdbarch)
return gdbarch_bfd_arch_info (gdbarch)->arch_name;
}

+/* Default method for gdbarch_addressable_memory_unit_size. */
+
+int
+default_addressable_memory_unit_size (struct gdbarch *gdbarch)
+{
+ return 1;
+}
+
/* -Wmissing-prototypes */
extern initialize_file_ftype _initialize_gdbarch_utils;

diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index ed3bec9..b2d20c6 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -202,5 +202,6 @@ extern void default_skip_permanent_breakpoint (struct regcache *regcache);
extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot);
extern char *default_gcc_target_options (struct gdbarch *gdbarch);
extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch);
+extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch);

#endif
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 97874c9..1cdc2df 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -328,6 +328,7 @@ struct gdbarch
gdbarch_infcall_mmap_ftype *infcall_mmap;
gdbarch_gcc_target_options_ftype *gcc_target_options;
gdbarch_gnu_triplet_regexp_ftype *gnu_triplet_regexp;
+ gdbarch_addressable_memory_unit_size_ftype *addressable_memory_unit_size;
};

/* Create a new ``struct gdbarch'' based on information provided by
@@ -428,6 +429,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
gdbarch->infcall_mmap = default_infcall_mmap;
gdbarch->gcc_target_options = default_gcc_target_options;
gdbarch->gnu_triplet_regexp = default_gnu_triplet_regexp;
+ gdbarch->addressable_memory_unit_size = default_addressable_memory_unit_size;
/* gdbarch_alloc() */

return gdbarch;
@@ -660,6 +662,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of infcall_mmap, invalid_p == 0 */
/* Skip verify of gcc_target_options, invalid_p == 0 */
/* Skip verify of gnu_triplet_regexp, invalid_p == 0 */
+ /* Skip verify of addressable_memory_unit_size, invalid_p == 0 */
buf = ui_file_xstrdup (log, &length);
make_cleanup (xfree, buf);
if (length > 0)
@@ -711,6 +714,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: address_to_pointer = <%s>\n",
host_address_to_string (gdbarch->address_to_pointer));
fprintf_unfiltered (file,
+ "gdbarch_dump: addressable_memory_unit_size = <%s>\n",
+ host_address_to_string (gdbarch->addressable_memory_unit_size));
+ fprintf_unfiltered (file,
"gdbarch_dump: gdbarch_adjust_breakpoint_address_p() = %d\n",
gdbarch_adjust_breakpoint_address_p (gdbarch));
fprintf_unfiltered (file,
@@ -4707,6 +4713,23 @@ set_gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch,
gdbarch->gnu_triplet_regexp = gnu_triplet_regexp;
}

+int
+gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->addressable_memory_unit_size != NULL);
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_addressable_memory_unit_size called\n");
+ return gdbarch->addressable_memory_unit_size (gdbarch);
+}
+
+void
+set_gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch,
+ gdbarch_addressable_memory_unit_size_ftype addressable_memory_unit_size)
+{
+ gdbarch->addressable_memory_unit_size = addressable_memory_unit_size;
+}
+

/* Keep a registry of per-architecture data-pointers required by GDB
modules. */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index c94c19c..79197a4 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1459,6 +1459,13 @@ typedef const char * (gdbarch_gnu_triplet_regexp_ftype) (struct gdbarch *gdbarch
extern const char * gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch);
extern void set_gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch, gdbarch_gnu_triplet_regexp_ftype *gnu_triplet_regexp);

+/* Return the size in bytes of an addressable memory unit on this architecture.
+ This corresponds to the number of bytes associated to each address in memory. */
+
+typedef int (gdbarch_addressable_memory_unit_size_ftype) (struct gdbarch *gdbarch);
+extern int gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch);
+extern void set_gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch, gdbarch_addressable_memory_unit_size_ftype *addressable_memory_unit_size);
+
/* Definition for an unknown syscall, used basically in error-cases. */
#define UNKNOWN_SYSCALL (-1)

diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 0f303a4..43b6adc 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1109,6 +1109,11 @@ m:char *:gcc_target_options:void:::default_gcc_target_options::0
# returns the BFD architecture name, which is correct in nearly every
# case.
m:const char *:gnu_triplet_regexp:void:::default_gnu_triplet_regexp::0
+
+# Return the size in bytes of an addressable memory unit on this architecture.
+# This corresponds to the number of bytes associated to each address in memory.
+m:int:addressable_memory_unit_size:void:::default_addressable_memory_unit_size::0
+
EOF
}

--
2.1.4