Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: RFA: fix PR gdb/1158
Date: Sun, 27 Jul 2008 00:57:00 -0000	[thread overview]
Message-ID: <m3bq0kcfeq.fsf@fleche.redhat.com> (raw)

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  <tromey@redhat.com>

	PR gdb/1158:
	* valops.c (value_struct_elt): Treat function-valued field as a
	static method.

testsuite/ChangeLog:
2008-07-26  Tom Tromey  <tromey@redhat.com>

	* 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


             reply	other threads:[~2008-07-27  0:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-27  0:57 Tom Tromey [this message]
2008-07-27  1:36 ` Daniel Jacobowitz

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=m3bq0kcfeq.fsf@fleche.redhat.com \
    --to=tromey@redhat.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