This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Cast function pointer to expected type
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: gdb-patches at sourceware dot org
- Date: Fri, 16 Mar 2012 13:14:52 +0100
- Subject: [PATCH] Cast function pointer to expected type
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."