Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] fix "ptype $pc" internal-error
@ 2008-01-04  9:43 Joel Brobecker
  2008-01-04 10:36 ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2008-01-04  9:43 UTC (permalink / raw)
  To: gdb-patches

[-- 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"
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-01-30 18:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-04  9:43 [RFA] fix "ptype $pc" internal-error Joel Brobecker
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox