From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4127 invoked by alias); 27 Jul 2008 00:57:55 -0000 Received: (qmail 4118 invoked by uid 22791); 27 Jul 2008 00:57:55 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 27 Jul 2008 00:57:37 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m6R0vZs6024477 for ; Sat, 26 Jul 2008 20:57:35 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m6R0vYES002958; Sat, 26 Jul 2008 20:57:34 -0400 Received: from opsy.redhat.com (vpn-10-41.bos.redhat.com [10.16.10.41]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m6R0vYsZ002475; Sat, 26 Jul 2008 20:57:34 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id C2095378251; Sat, 26 Jul 2008 18:57:33 -0600 (MDT) To: gdb-patches@sourceware.org Subject: RFA: fix PR gdb/1158 From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Sun, 27 Jul 2008 00:57:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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-07/txt/msg00502.txt.bz2 PR gdb/1158 concerns calling a function via a function pointer that appears in a struct: struct struct_with_fnptr { int (*func) PARAMS((int)); } function_struct; (gdb) p function_struct.func(5) Currently, gdb treats this as a method call, and erroneously adds a 'this' pointer to the call. This yields the wrong result. This patch fixes the problem by noticing when the right-hand-side of the member operation is an ordinary data field, and then treating this as if it were a static member function. I checked all callers to value_struct_elt, and I think this is the correct thing to do in all cases. Regression test included. Built and tested on x86 F8. Ok? Tom ChangeLog: 2008-07-26 Tom Tromey PR gdb/1158: * valops.c (value_struct_elt): Treat function-valued field as a static method. testsuite/ChangeLog: 2008-07-26 Tom Tromey * gdb.base/callfuncs.c (struct struct_with_fnptr): New struct. (function_struct, function_struct_ptr): New globals. * gdb.base/callfuncs.exp (do_function_calls): Test calling via a function pointer in a struct. Index: valops.c =================================================================== RCS file: /cvs/src/src/gdb/valops.c,v retrieving revision 1.192 diff -u -r1.192 valops.c --- valops.c 15 Jul 2008 22:13:42 -0000 1.192 +++ valops.c 27 Jul 2008 00:52:21 -0000 @@ -1819,6 +1819,10 @@ back. If it's not callable (i.e., a pointer to function), gdb should give an error. */ v = search_struct_field (name, *argp, 0, t, 0); + /* If we found an ordinary field, then it is not a method call. + So, treat it as if it were a static member function. */ + if (v && static_memfuncp) + *static_memfuncp = 1; } if (!v) Index: testsuite/gdb.base/callfuncs.c =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/callfuncs.c,v retrieving revision 1.11 diff -u -r1.11 callfuncs.c --- testsuite/gdb.base/callfuncs.c 6 Feb 2008 03:54:12 -0000 1.11 +++ testsuite/gdb.base/callfuncs.c 27 Jul 2008 00:52:22 -0000 @@ -490,6 +490,14 @@ return ((*func_arg1)(a, b)); } +struct struct_with_fnptr +{ + int (*func) PARAMS((int)); +}; + +struct struct_with_fnptr function_struct = { doubleit }; + +struct struct_with_fnptr *function_struct_ptr = &function_struct; /* Gotta have a main to be able to generate a linked, runnable executable, and also provide a useful place to set a breakpoint. */ Index: testsuite/gdb.base/callfuncs.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/callfuncs.exp,v retrieving revision 1.24 diff -u -r1.24 callfuncs.exp --- testsuite/gdb.base/callfuncs.exp 6 Feb 2008 03:54:12 -0000 1.24 +++ testsuite/gdb.base/callfuncs.exp 27 Jul 2008 00:52:22 -0000 @@ -190,6 +190,9 @@ gdb_test "p t_func_values(func_val2,func_val1)" " = 0" gdb_test "p t_func_values(func_val1,func_val2)" " = 1" + gdb_test "p function_struct.func(5)" " = 10" + gdb_test "p function_struct_ptr->func(10)" " = 20" + # GDB currently screws up the passing of function parameters for # ABIs that use function descriptors. Instead of passing the # address of te function descriptor, GDB passes the address of the