From: Alan Hayward <Alan.Hayward@arm.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: nd <nd@arm.com>
Subject: [PATCH] Remove MAX_REGISTER_SIZE from regcache.c
Date: Fri, 24 Feb 2017 10:19:00 -0000 [thread overview]
Message-ID: <562B2F6F-F3C6-4A76-9489-57539F396C94@arm.com> (raw)
Also adds functionality to calculate maximum register size.
Cannot remove buffer from regcache_restore becuase we need to keep the
register value if the read fails.
Leaves two asserts check with MAX_REGISTER_SIZE which must be kept
until MAX_REGISTER_SIZE is fully removed from all files.
Tested using make check with board files unix and native-gdbserver.
Ok to commit?
Alan.
2017-02-24 Alan Hayward <alan.hayward@arm.com>
* regcache.c (struct regcache_descr): Add max_register_size
(init_regcache_descr): Calculate maximum register size.
(max_register_size): New function.
(regcache_save): Avoid buffer use.
(regcache_restore): Use vec instead of array.
(regcache_dump): Avoid buffer use.
* regcache.h (struct regcache_descr): Add max_register_size
(max_register_size): New function.
index 59233308f926ebd52db9958cba168daacc77c1ee..a4a47c8f738ee5df69074375a3f169558891cf0e 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -206,6 +206,8 @@ extern struct type *register_type (struct gdbarch *gdbarch, int regnum);
extern int register_size (struct gdbarch *gdbarch, int regnum);
+/* Return the size of the largest register. */
+extern long max_register_size (struct gdbarch *gdbarch);
/* Save/restore a register cache. The set of registers saved /
restored into the DST regcache determined by the save_reggroup /
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 31aa1baf7ef69c27c00e45e3c8d4eb3c41dc4203..0da184cb7c6ea3a171139a40676658322e62ad2e 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -73,6 +73,9 @@ struct regcache_descr
/* Cached table containing the type of each register. */
struct type **register_type;
+
+ /* Size of the largest register. */
+ long max_register_size;
};
static void *
@@ -126,6 +129,8 @@ init_regcache_descr (struct gdbarch *gdbarch)
descr->register_offset[i] = offset;
offset += descr->sizeof_register[i];
gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
+ descr->max_register_size = std::max (descr->max_register_size,
+ descr->sizeof_register[i]);
}
/* Set the real size of the raw register cache buffer. */
descr->sizeof_raw_registers = offset;
@@ -136,6 +141,8 @@ init_regcache_descr (struct gdbarch *gdbarch)
descr->register_offset[i] = offset;
offset += descr->sizeof_register[i];
gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
+ descr->max_register_size = std::max (descr->max_register_size,
+ descr->sizeof_register[i]);
}
/* Set the real size of the readonly register cache buffer. */
descr->sizeof_cooked_registers = offset;
@@ -187,6 +194,13 @@ regcache_register_size (const struct regcache *regcache, int n)
return register_size (get_regcache_arch (regcache), n);
}
+long
+max_register_size (struct gdbarch *gdbarch)
+{
+ struct regcache_descr *descr = regcache_descr (gdbarch);
+ return descr->max_register_size;
+}
+
/* The register cache for storing raw register values. */
struct regcache
@@ -327,7 +341,6 @@ regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
void *src)
{
struct gdbarch *gdbarch = dst->descr->gdbarch;
- gdb_byte buf[MAX_REGISTER_SIZE];
int regnum;
/* The DST should be `read-only', if it wasn't then the save would
@@ -346,17 +359,13 @@ regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
{
if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
{
- enum register_status status = cooked_read (src, regnum, buf);
+ gdb_byte *dst_buf = register_buffer (dst, regnum);
+ enum register_status status = cooked_read (src, regnum, dst_buf);
- if (status == REG_VALID)
- memcpy (register_buffer (dst, regnum), buf,
- register_size (gdbarch, regnum));
- else
+ if (status != REG_VALID)
{
gdb_assert (status != REG_UNKNOWN);
-
- memset (register_buffer (dst, regnum), 0,
- register_size (gdbarch, regnum));
+ memset (dst_buf, 0, register_size (gdbarch, regnum));
}
dst->register_status[regnum] = status;
}
@@ -369,7 +378,7 @@ regcache_restore (struct regcache *dst,
void *cooked_read_context)
{
struct gdbarch *gdbarch = dst->descr->gdbarch;
- gdb_byte buf[MAX_REGISTER_SIZE];
+ std::vector<gdb_byte> buf (max_register_size (gdbarch));
int regnum;
/* The dst had better not be read-only. If it is, the `restore'
@@ -385,9 +394,9 @@ regcache_restore (struct regcache *dst,
{
enum register_status status;
- status = cooked_read (cooked_read_context, regnum, buf);
+ status = cooked_read (cooked_read_context, regnum, buf.data ());
if (status == REG_VALID)
- regcache_cooked_write (dst, regnum, buf);
+ regcache_cooked_write (dst, regnum, buf.data ());
}
}
}
@@ -1324,7 +1333,6 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
int footnote_register_offset = 0;
int footnote_register_type_name_null = 0;
long register_offset = 0;
- gdb_byte buf[MAX_REGISTER_SIZE];
#if 0
fprintf_unfiltered (file, "nr_raw_registers %d\n",
@@ -1451,8 +1459,8 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
fprintf_unfiltered (file, "<unavailable>");
else
{
- regcache_raw_read (regcache, regnum, buf);
- print_hex_chars (file, buf,
+ regcache_raw_update (regcache, regnum);
+ print_hex_chars (file, register_buffer (regcache, regnum),
regcache->descr->sizeof_register[regnum],
gdbarch_byte_order (gdbarch));
}
@@ -1465,17 +1473,19 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
fprintf_unfiltered (file, "Cooked value");
else
{
- enum register_status status;
+ struct value *value = regcache_cooked_read_value (regcache,
+ regnum);
- status = regcache_cooked_read (regcache, regnum, buf);
- if (status == REG_UNKNOWN)
- fprintf_unfiltered (file, "<invalid>");
- else if (status == REG_UNAVAILABLE)
+ if (value_optimized_out (value)
+ || !value_entirely_available (value))
fprintf_unfiltered (file, "<unavailable>");
else
- print_hex_chars (file, buf,
+ print_hex_chars (file, value_contents_all (value),
regcache->descr->sizeof_register[regnum],
gdbarch_byte_order (gdbarch));
+
+ release_value (value);
+ value_free (value);
}
}
next reply other threads:[~2017-02-24 10:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 10:19 Alan Hayward [this message]
2017-03-23 14:45 ` Alan Hayward
2017-03-24 8:49 ` Yao Qi
2017-03-24 10:28 ` Alan Hayward
2017-04-05 14:53 ` Alan Hayward
2017-04-05 16:01 ` Yao Qi
2017-04-05 18:10 ` Alan Hayward
2017-04-10 8:59 ` Yao Qi
2017-04-10 10:53 ` Alan Hayward
2017-04-21 14:01 ` Yao Qi
2017-04-26 14:03 ` Alan Hayward
2017-04-27 9:43 ` Yao Qi
2017-04-27 9:52 ` Alan Hayward
2017-05-03 8:21 ` Yao Qi
2017-05-03 10:42 ` Alan Hayward
2017-06-07 8:49 ` Alan Hayward
2017-06-07 9:12 ` Yao Qi
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=562B2F6F-F3C6-4A76-9489-57539F396C94@arm.com \
--to=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).