* [PATCH] Cast function pointer to expected type
@ 2012-03-16 12:15 Andreas Schwab
2012-03-19 13:30 ` Jan Kratochvil
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2012-03-16 12:15 UTC (permalink / raw)
To: gdb-patches
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."
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Cast function pointer to expected type
2012-03-16 12:15 [PATCH] Cast function pointer to expected type Andreas Schwab
@ 2012-03-19 13:30 ` Jan Kratochvil
2012-03-19 13:44 ` Andreas Schwab
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2012-03-19 13:30 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
On Fri, 16 Mar 2012 13:14:52 +0100, Andreas Schwab wrote:
> The cast is needed to select the correct function call ABI.
On which arch? Which testcases are affected by it?
Thanks,
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Cast function pointer to expected type
2012-03-19 13:30 ` Jan Kratochvil
@ 2012-03-19 13:44 ` Andreas Schwab
0 siblings, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2012-03-19 13:44 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> On Fri, 16 Mar 2012 13:14:52 +0100, Andreas Schwab wrote:
>> The cast is needed to select the correct function call ABI.
>
> On which arch?
m68k-linux
> Which testcases are affected by it?
checkpoint.exp
Andreas.
--
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."
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-19 13:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-16 12:15 [PATCH] Cast function pointer to expected type Andreas Schwab
2012-03-19 13:30 ` Jan Kratochvil
2012-03-19 13:44 ` Andreas Schwab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox