From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA] fix "ptype $pc" internal-error
Date: Fri, 04 Jan 2008 09:43:00 -0000 [thread overview]
Message-ID: <20080104094316.GO2179@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1934 bytes --]
Hello,
"ptype $pc" doesn't work anymore. With any program, try the following:
(gdb) ptype $pc
../../src-public/gdb/regcache.c:164: internal-error: register_type: Assertion `regnum >= 0 && regnum < descr->nr_cooked_registers' failed.
[...]
The problem is inside evaluate_subexp_standard, case OP_REGISTER:
regno = frame_map_name_to_regnum (deprecated_safe_get_selected_frame (),
name, strlen (name));
[...]
if (noside == EVAL_AVOID_SIDE_EFFECTS)
val = value_zero (register_type (current_gdbarch, regno), not_lval);
else
val = value_of_register (regno, get_selected_frame (NULL));
In our case, the regno points to a "user" register, and as a result
calling "register_type" with that register number triggers the failed
assertion.
The type of a user register doesn't seem to be conveniently accessible
like with the other registers. So my approach was to return a value_zero
only when the register was not a user register. For user registers,
I get the actual register value, regardless of EVAL_AVOID_SIDE_EFFECTS.
I hope the performance will not be noticeably affected.
Otherwise, a grander way of fixing this would be to extend the user-regs
interface to provide access to these register types. Either through
a new callback function, or by updating the "add_reg" function with
an extra parameter being the type.
I don't remember seeing this need elsewhere, so I think the simple
approach is sufficient for now.
2008-01-04 Joel Brobecker <brobecker@adacore.com>
* eval.c (evaluate_subexp_standard): Add handling of user
registers when in EVAL_AVOID_SIDE_EFFECTS mode.
I also added a new test in gdb.base/ptype.exp:
2008-01-04 Joel Brobecker <brobecker@adacore.com>
* gdb.base/ptype.exp: Add testing of "ptype $pc".
All tested on x86-linux. No regression.
OK to apply?
Thanks,
--
Joel
[-- Attachment #2: ptype_pc.diff --]
[-- Type: text/plain, Size: 952 bytes --]
Index: eval.c
===================================================================
--- eval.c (revision 65)
+++ eval.c (revision 66)
@@ -512,7 +512,15 @@ evaluate_subexp_standard (struct type *e
name, strlen (name));
if (regno == -1)
error (_("Register $%s not available."), name);
- if (noside == EVAL_AVOID_SIDE_EFFECTS)
+
+ /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
+ a value with the appropriate register type. Unfortunately,
+ we don't have easy access to the type of user registers.
+ So for these registers, we fetch the register value regardless
+ of the evaluation mode. */
+ if (noside == EVAL_AVOID_SIDE_EFFECTS
+ && regno < gdbarch_num_regs (current_gdbarch)
+ + gdbarch_num_pseudo_regs (current_gdbarch))
val = value_zero (register_type (current_gdbarch, regno), not_lval);
else
val = value_of_register (regno, get_selected_frame (NULL));
[-- Attachment #3: ptype_pc-tc.diff --]
[-- Type: text/plain, Size: 474 bytes --]
Index: gdb.base/ptype.exp
===================================================================
--- gdb.base/ptype.exp (revision 66)
+++ gdb.base/ptype.exp (revision 67)
@@ -639,4 +639,7 @@ if [runto_main] then {
gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
gdb_test "ptype {4,5,6}\[2\]" "type = int"
gdb_test "ptype *&{4,5,6}\[1\]" "type = int"
+
+ # Test ptype of user register
+ gdb_test "ptype \$pc" "void \\(\\*\\)\\(\\)" "ptype \$pc"
}
next reply other threads:[~2008-01-04 9:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-04 9:43 Joel Brobecker [this message]
2008-01-04 10:36 ` Andreas Schwab
2008-01-04 10:50 ` Joel Brobecker
2008-01-29 17:47 ` Daniel Jacobowitz
2008-01-30 17:31 ` Mark Kettenis
2008-01-30 19:01 ` 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=20080104094316.GO2179@adacore.com \
--to=brobecker@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