From: Jerome Guitton <guitton@adacore.com>
To: gdb-patches@sourceware.org
Cc: Jerome Guitton <guitton@adacore.com>
Subject: [RFC] setting the raw content of a register
Date: Tue, 22 May 2012 14:37:00 -0000 [thread overview]
Message-ID: <1337697398-25866-1-git-send-email-guitton@adacore.com> (raw)
When trying to set the raw content of a fp register, many users try
something like:
(gdb) set $f14 := 0xFFF0000000000050
(gdb) info registers $f14
f14 -4503599627370416.0 (raw 0xc32fffffffffff60)
Of course, GDB sets the value of $f14, not its raw content. Now
this can be worked around by writing the raw content in memory,
re-read it as a float and store the value into register f14. Quite
kludgy though, and it often hits some limitations of the interpreter
regarding floats (e.g. signs of NaN are lost).
Maybe the simplest solution would be to add a new command to set the
raw content of a register. Attached a first candidate implementation,
to give an idea of how it could look like. The name of the command
here is "set register", but I would be happy to change it.
(gdb) help set register
Write raw value into register
Usage: set register REGNAME VALUE.
(gdb) set register f14 0xFFF0000000000050
(gdb) info registers $f14
f14 NaN(0x000000050) (raw 0xfff0000000000050)
Of course this would need some documentation, a new testcase, and
maybe a new python command as well (?). But I'd like to have your
opinion on the general idea first.
gdb/ChangeLog:
* printcmd.c (set_register_command): New function.
(_initialize_printcmd): New command "set register".
---
gdb/printcmd.c | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 030a4f2..7080d0e 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -49,6 +49,8 @@
#include "charset.h"
#include "arch-utils.h"
#include "cli/cli-utils.h"
+#include "regcache.h"
+#include "user-regs.h"
#ifdef TUI
#include "tui/tui.h" /* For tui_active et al. */
@@ -1077,6 +1079,34 @@ output_command (char *exp, int from_tty)
}
static void
+set_register_command (char *exp, int from_tty)
+{
+ struct regcache *cache = get_current_regcache();
+ char *regname = exp, *exp2 = exp;
+ struct expression *expr;
+ struct cleanup *old_chain;
+ struct value *val, *reg;
+ int regnum;
+
+ exp2 = skip_to_space (exp);
+ if (*exp == '\0' || *exp2 == '\0')
+ error_no_arg (_("Two arguments required."));
+ *exp2 = '\0';
+ exp2 += 1;
+
+ regnum = user_reg_map_name_to_regnum (get_regcache_arch (cache),
+ regname, strlen (regname));
+ if (regnum == -1)
+ error (_("First argument must be a register."));
+
+ expr = parse_expression (exp2);
+ old_chain = make_cleanup (free_current_contents, &expr);
+ val = evaluate_expression (expr);
+ regcache_raw_write_unsigned (cache, regnum, value_as_long (val));
+ do_cleanups (old_chain);
+}
+
+static void
set_command (char *exp, int from_tty)
{
struct expression *expr = parse_expression (exp);
@@ -2851,6 +2881,11 @@ variable in the program being debugged. EXP is any valid expression.\n\
This may usually be abbreviated to simply \"set\"."),
&setlist);
+ add_cmd ("register", class_vars, set_register_command, _("\
+Write raw value into register\n\
+Usage: set register REGNAME VALUE."),
+ &setlist);
+
c = add_com ("print", class_vars, print_command, _("\
Print value of expression EXP.\n\
Variables accessible are those of the lexical environment of the selected\n\
--
1.7.0.2
next reply other threads:[~2012-05-22 14:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-22 14:37 Jerome Guitton [this message]
2012-05-22 14:55 ` Pedro Alves
2012-05-22 15:25 ` Jerome Guitton
2012-05-22 16:32 ` Pedro Alves
2012-05-23 15:22 ` Doug Evans
2012-05-23 15:28 ` Pedro Alves
2012-05-23 15:42 ` Jerome Guitton
2012-05-23 16:03 ` Pedro Alves
2012-05-23 16:10 ` Pedro Alves
2012-05-23 16:22 ` Joel Brobecker
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=1337697398-25866-1-git-send-email-guitton@adacore.com \
--to=guitton@adacore.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