From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19632 invoked by alias); 1 Jan 2008 13:48:45 -0000 Received: (qmail 19624 invoked by uid 22791); 1 Jan 2008 13:48:44 -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; Tue, 01 Jan 2008 13:47:02 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EDDCF2A9665 for ; Tue, 1 Jan 2008 08:47:00 -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 9sbcFW2VabZx for ; Tue, 1 Jan 2008 08:47:00 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 3C7092A9661 for ; Tue, 1 Jan 2008 08:46:59 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 3D745E7ACB; Tue, 1 Jan 2008 05:46:52 -0800 (PST) Date: Tue, 01 Jan 2008 13:48:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA] no frame needed when computing address of subprogram Message-ID: <20080101134652.GB3770@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="k+w/mQv8wyuph6w0" 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/msg00006.txt.bz2 --k+w/mQv8wyuph6w0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1455 Trying to compute the address of a procedure fails when the inferior is not running: (gdb) p foo'address No registers. To reproduce, use the trivial Ada program pasted at the end of this email, and compile it with: % gnatmake -g foo Then try the command above. The problem is inside eval.c:evaluate_subexp_for_address, in the case handling the OP_VAR_VALUE case. Unless we are in EVAL_AVOID_SIDE_EFFECT mode, we end up doing: if (noside == EVAL_AVOID_SIDE_EFFECTS) [...] else return locate_var_value (var, block_innermost_frame (exp->elts[pc + 1].block)); In particular, we are trying to get the block_innermost_frame, which doesn't exist in our case. The attached patch changes that to first check that we need a frame to get the object address, otherwise, we locate the value without a frame. 2008-01-01 Paul N. Hilfinger * eval.c (evaluate_subexp_for_address): Provide frame address to locate_var_value only if it will be needed. I also wrote a tiny testcase that verifies the fix. 2008-01-01 Joel Brobecker * gdb.ada/fun_addr/foo.adb: New file. * gdb.ada/fun_addr.exp: New testcase. All tested on x86-linux, no regression. The patch has also been in AdaCore's tree since Aug 2003 (shame on us!). OK to commit? Thanks, -- Joel procedure Foo is begin null; end Foo; --k+w/mQv8wyuph6w0 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fun_addr.diff" Content-length: 533 Index: eval.c =================================================================== --- eval.c (revision 29) +++ eval.c (revision 30) @@ -2150,11 +2150,13 @@ evaluate_subexp_for_address (struct expr return value_zero (type, not_lval); } - else + else if (symbol_read_needs_frame (var)) return locate_var_value (var, block_innermost_frame (exp->elts[pc + 1].block)); + else + return locate_var_value (var, NULL); case OP_SCOPE: tem = longest_to_int (exp->elts[pc + 2].longconst); --k+w/mQv8wyuph6w0 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fun_addr-testcase.diff" Content-length: 2525 Index: gdb.ada/fun_addr.exp =================================================================== --- gdb.ada/fun_addr.exp (revision 0) +++ gdb.ada/fun_addr.exp (revision 31) @@ -0,0 +1,44 @@ +# Copyright 2008 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if $tracelevel then { + strace $tracelevel +} + +load_lib "ada.exp" + +set testdir "fun_addr" +set testfile "${testdir}/foo" +set srcfile ${srcdir}/${subdir}/${testfile}.adb +set binfile ${objdir}/${subdir}/${testfile} + +file mkdir ${objdir}/${subdir}/${testdir} +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# Verify that we are able to print the address of a function when +# the inferior is *not* running (no frame). + +gdb_test "print foo'address" \ + "0x\[0-9a-zA-Z\]+" \ + "print foo'address" + + Index: gdb.ada/fun_addr/foo.adb =================================================================== --- gdb.ada/fun_addr/foo.adb (revision 0) +++ gdb.ada/fun_addr/foo.adb (revision 31) @@ -0,0 +1,19 @@ +-- Copyright 2008 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +procedure Foo is +begin + null; +end Foo; --k+w/mQv8wyuph6w0--