Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] Cast function pointer to expected type
Date: Fri, 16 Mar 2012 12:15:00 -0000	[thread overview]
Message-ID: <m2y5r0spxf.fsf@igel.home> (raw)

The cast is needed to select the correct function call ABI.

Andreas.

2012-03-16  Andreas Schwab  <schwab@linux-m68k.org>

	* linux-fork.c (inferior_call_waitpid): Cast function pointer to
	expected type.
	(checkpoint_command): Likewise.

diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 028fcbc..ddbfa26 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -29,6 +29,8 @@
 #include "linux-fork.h"
 #include "linux-nat.h"
 #include "gdbthread.h"
+#include "ui-out.h"
+#include "valprint.h"
 
 #include <sys/ptrace.h>
 #include "gdb_wait.h"
@@ -431,6 +433,7 @@ inferior_call_waitpid (ptid_t pptid, int pid)
   struct objfile *waitpid_objf;
   struct value *waitpid_fn = NULL;
   struct value *argv[4], *retv;
+  struct type *type;
   struct gdbarch *gdbarch = get_current_arch ();
   struct fork_info *oldfp = NULL, *newfp = NULL;
   struct cleanup *old_cleanup;
@@ -459,6 +462,11 @@ inferior_call_waitpid (ptid_t pptid, int pid)
   if (!waitpid_fn)
     goto out;
 
+  /* Cast function pointer to expected type.  */
+  type = lookup_function_type (builtin_type (gdbarch)->builtin_int);
+  type = lookup_pointer_type (type);
+  waitpid_fn = value_cast (type, waitpid_fn);
+
   /* Get the argv.  */
   argv[0] = value_from_longest (builtin_type (gdbarch)->builtin_int, pid);
   argv[1] = value_from_pointer (builtin_type (gdbarch)->builtin_data_ptr, 0);
@@ -650,6 +658,7 @@ checkpoint_command (char *args, int from_tty)
   struct target_waitstatus last_target_waitstatus;
   ptid_t last_target_ptid;
   struct value *fork_fn = NULL, *ret;
+  struct type *type;
   struct fork_info *fp;
   pid_t retpid;
   struct cleanup *old_chain;
@@ -673,13 +682,17 @@ checkpoint_command (char *args, int from_tty)
     error (_("checkpoint: can't find fork function in inferior."));
 
   gdbarch = get_objfile_arch (fork_objf);
-  ret = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
 
   /* Tell linux-nat.c that we're checkpointing this inferior.  */
   old_chain = make_cleanup_restore_integer (&checkpointing_pid);
   checkpointing_pid = PIDGET (inferior_ptid);
 
-  ret = call_function_by_hand (fork_fn, 0, &ret);
+  /* Cast function pointer to expected type.  */
+  type = lookup_function_type (builtin_type (gdbarch)->builtin_int);
+  type = lookup_pointer_type (type);
+  fork_fn = value_cast (type, fork_fn);
+
+  ret = call_function_by_hand (fork_fn, 0, NULL);
   do_cleanups (old_chain);
   if (!ret)	/* Probably can't happen.  */
     error (_("checkpoint: call_function_by_hand returned null."));
-- 
1.7.9.4


-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


             reply	other threads:[~2012-03-16 12:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-16 12:15 Andreas Schwab [this message]
2012-03-19 13:30 ` Jan Kratochvil
2012-03-19 13:44   ` Andreas Schwab

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=m2y5r0spxf.fsf@igel.home \
    --to=schwab@linux-m68k.org \
    --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