From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14470 invoked by alias); 4 Jan 2008 09:43:46 -0000 Received: (qmail 14454 invoked by uid 22791); 4 Jan 2008 09:43:45 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 04 Jan 2008 09:43:26 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id CA9AA2A961B for ; Fri, 4 Jan 2008 04:43:24 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 6LrKxfoRjJGA for ; Fri, 4 Jan 2008 04:43:24 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id B37D12A9619 for ; Fri, 4 Jan 2008 04:43:23 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 3FFDDE7ACB; Fri, 4 Jan 2008 01:43:16 -0800 (PST) Date: Fri, 04 Jan 2008 09:43:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA] fix "ptype $pc" internal-error Message-ID: <20080104094316.GO2179@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0ntfKIWw70PvrIHh" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00050.txt.bz2 --0ntfKIWw70PvrIHh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1934 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 * 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 * gdb.base/ptype.exp: Add testing of "ptype $pc". All tested on x86-linux. No regression. OK to apply? Thanks, -- Joel --0ntfKIWw70PvrIHh Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ptype_pc.diff" Content-length: 952 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)); --0ntfKIWw70PvrIHh Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ptype_pc-tc.diff" Content-length: 474 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" } --0ntfKIWw70PvrIHh--