Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 4/7] gdbarch: add memory_byte_size method
Date: Wed, 08 Apr 2015 19:56:00 -0000	[thread overview]
Message-ID: <1428522979-28709-5-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1428522979-28709-1-git-send-email-simon.marchi@ericsson.com>

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

gdb/ChangeLog:

	* arch-utils.h (default_memory_byte_size): New.
	* arch-utils.c (default_memory_byte_size): New.
	* gdbarch.sh (memory_byte_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    |  6 ++++++
 gdb/gdbarch.sh   |  4 ++++
 5 files changed, 43 insertions(+)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index e1c8ab0..4f3cb7b 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_memory_byte_size.  By default, a memory byte has
+   a size of 1 octet.  */
+
+int
+default_memory_byte_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..ecf5e0d 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_memory_byte_size (struct gdbarch *gdbarch);
 
 #endif
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 97874c9..58b9630 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_memory_byte_size_ftype *memory_byte_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->memory_byte_size = default_memory_byte_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 memory_byte_size, invalid_p == 0 */
   buf = ui_file_xstrdup (log, &length);
   make_cleanup (xfree, buf);
   if (length > 0)
@@ -1095,6 +1098,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: max_insn_length = %s\n",
                       plongest (gdbarch->max_insn_length));
   fprintf_unfiltered (file,
+                      "gdbarch_dump: memory_byte_size = <%s>\n",
+                      host_address_to_string (gdbarch->memory_byte_size));
+  fprintf_unfiltered (file,
                       "gdbarch_dump: memory_insert_breakpoint = <%s>\n",
                       host_address_to_string (gdbarch->memory_insert_breakpoint));
   fprintf_unfiltered (file,
@@ -4707,6 +4713,23 @@ set_gdbarch_gnu_triplet_regexp (struct gdbarch *gdbarch,
   gdbarch->gnu_triplet_regexp = gnu_triplet_regexp;
 }
 
+int
+gdbarch_memory_byte_size (struct gdbarch *gdbarch)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->memory_byte_size != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_memory_byte_size called\n");
+  return gdbarch->memory_byte_size (gdbarch);
+}
+
+void
+set_gdbarch_memory_byte_size (struct gdbarch *gdbarch,
+                              gdbarch_memory_byte_size_ftype memory_byte_size)
+{
+  gdbarch->memory_byte_size = memory_byte_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..169f752 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1459,6 +1459,12 @@ 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 length in octets of a memory byte on this architecture. */
+
+typedef int (gdbarch_memory_byte_size_ftype) (struct gdbarch *gdbarch);
+extern int gdbarch_memory_byte_size (struct gdbarch *gdbarch);
+extern void set_gdbarch_memory_byte_size (struct gdbarch *gdbarch, gdbarch_memory_byte_size_ftype *memory_byte_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..607caa1 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1109,6 +1109,10 @@ 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 length in octets of a memory byte on this architecture.
+m:int:memory_byte_size:void:::default_memory_byte_size::0
+
 EOF
 }
 
-- 
2.1.4


  parent reply	other threads:[~2015-04-08 19:56 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08 19:56 [PATCH 0/7] Support reading/writing memory on architectures with non 8-bits bytes Simon Marchi
2015-04-08 19:56 ` [PATCH 3/7] Clarify doc about memory read/write and non-8-bits bytes Simon Marchi
2015-04-09  7:02   ` Eli Zaretskii
2015-04-08 19:56 ` [PATCH 7/7] MI: Consider byte size when reading/writing memory Simon Marchi
2015-04-08 19:56 ` [PATCH 5/7] target: consider " Simon Marchi
2015-04-08 19:56 ` [PATCH 1/7] Various cleanups in target read/write code Simon Marchi
2015-04-08 19:56 ` [PATCH 6/7] remote: Consider byte size when reading/writing memory Simon Marchi
2015-04-08 19:56 ` [PATCH 2/7] Cleanup some docs about memory write Simon Marchi
2015-04-08 19:56 ` Simon Marchi [this message]
2015-04-09  8:20 ` [PATCH 0/7] Support reading/writing memory on architectures with non 8-bits bytes Eli Zaretskii
2015-04-09 15:39   ` Simon Marchi
2015-04-09 16:29     ` Eli Zaretskii
2015-04-09 21:00       ` Simon Marchi
2015-04-10  8:11         ` Eli Zaretskii
2015-04-10 16:01           ` Simon Marchi
2015-04-10 16:35             ` Pedro Alves
2015-04-10 16:39             ` Paul_Koning
2015-04-10 17:34               ` Simon Marchi
2015-04-10 17:42             ` Eli Zaretskii
2015-04-10 18:01               ` Simon Marchi
2015-04-10 18:16                 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428522979-28709-5-git-send-email-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox