/* Low level interface for debugging AIX 4.3+ pthreads.
- Copyright (C) 1999-2000, 2002, 2007-2012 Free Software Foundation,
- Inc.
+ Copyright (C) 1999-2014 Free Software Foundation, Inc.
Written by Nick Duffek <nsd@redhat.com>.
This file is part of GDB.
#include "regcache.h"
#include "gdbcmd.h"
#include "ppc-tdep.h"
-#include "gdb_string.h"
+#include <string.h>
#include "observer.h"
#include <procinfo.h>
#include <sys/pthdebug.h>
#if !HAVE_DECL_GETTHRDS
-extern int getthrds (pid_t, struct thrdsinfo64 *, int, pthdb_tid_t *, int);
+extern int getthrds (pid_t, struct thrdsinfo64 *, int, tid_t *, int);
#endif
/* Whether to emit debugging output. */
#define PD_TID(ptid) (pd_active && ptid_get_tid (ptid) != 0)
-/* Build a thread ptid. */
-#define BUILD_THREAD(TID, PID) ptid_build (PID, 0, TID)
-
-/* Build and lwp ptid. */
-#define BUILD_LWP(LWP, PID) MERGEPID (PID, LWP)
-
/* pthdb_user_t value that we pass to pthdb functions. 0 causes
PTHDB_BAD_USER errors, so use 1. */
return 0; /* Not reached. */
}
-/* Call ptracex (REQ, ID, ADDR, DATA, BUF). Return success. */
+/* Call ptracex (REQ, ID, ADDR, DATA, BUF) or
+ ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
+ Return success. */
+
+#ifdef HAVE_PTRACE64
+# define ptracex(request, pid, addr, data, buf) \
+ ptrace64 (request, pid, addr, data, buf)
+#endif
static int
ptrace64aix (int req, int id, long long addr, int data, int *buf)
return ptrace_check (req, id, ptracex (req, id, addr, data, buf));
}
-/* Call ptrace (REQ, ID, ADDR, DATA, BUF). Return success. */
+/* Call ptrace (REQ, ID, ADDR, DATA, BUF) or
+ ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
+ Return success. */
+
+#ifdef HAVE_PTRACE64
+# define ptrace(request, pid, addr, data, buf) \
+ ptrace64 (request, pid, addr, data, buf)
+# define addr_ptr long long
+#else
+# define addr_ptr int *
+#endif
static int
-ptrace32 (int req, int id, int *addr, int data, int *buf)
+ptrace32 (int req, int id, addr_ptr addr, int data, int *buf)
{
errno = 0;
return ptrace_check (req, id,
- ptrace (req, id, (int *) addr, data, buf));
+ ptrace (req, id, addr, data, buf));
}
/* If *PIDP is a composite process/thread id, convert it to a
ptid = *ptidp;
if (PD_TID (ptid))
- *ptidp = pid_to_ptid (PIDGET (ptid));
+ *ptidp = pid_to_ptid (ptid_get_pid (ptid));
}
/* pthdb callback: for <i> from 0 to COUNT, set SYMBOLS[<i>].addr to
/* Floating-point registers. */
if (flags & PTHDB_FLAG_FPRS)
{
- if (!ptrace32 (PTT_READ_FPRS, tid, (void *) fprs, 0, NULL))
+ if (!ptrace32 (PTT_READ_FPRS, tid, (addr_ptr) fprs, 0, NULL))
memset (fprs, 0, sizeof (fprs));
memcpy (context->fpr, fprs, sizeof(fprs));
}
}
else
{
- if (!ptrace32 (PTT_READ_SPRS, tid, (int *) &sprs32, 0, NULL))
+ if (!ptrace32 (PTT_READ_SPRS, tid, (addr_ptr) &sprs32, 0, NULL))
memset (&sprs32, 0, sizeof (sprs32));
memcpy (&context->msr, &sprs32, sizeof(sprs32));
}
ptrace64aix (PTT_WRITE_GPRS, tid,
(unsigned long) context->gpr, 0, NULL);
else
- ptrace32 (PTT_WRITE_GPRS, tid, (int *) context->gpr, 0, NULL);
+ ptrace32 (PTT_WRITE_GPRS, tid, (addr_ptr) context->gpr, 0, NULL);
}
/* Floating-point registers. */
if (flags & PTHDB_FLAG_FPRS)
{
- ptrace32 (PTT_WRITE_FPRS, tid, (int *) context->fpr, 0, NULL);
+ ptrace32 (PTT_WRITE_FPRS, tid, (addr_ptr) context->fpr, 0, NULL);
}
/* Special-purpose registers. */
}
else
{
- ptrace32 (PTT_WRITE_SPRS, tid, (void *) &context->msr, 0, NULL);
+ ptrace32 (PTT_WRITE_SPRS, tid, (addr_ptr) &context->msr, 0, NULL);
}
}
return 0;
get_signaled_thread (void)
{
struct thrdsinfo64 thrinf;
- pthdb_tid_t ktid = 0;
+ tid_t ktid = 0;
int result = 0;
while (1)
{
- if (getthrds (PIDGET (inferior_ptid), &thrinf,
+ if (getthrds (ptid_get_pid (inferior_ptid), &thrinf,
sizeof (thrinf), &ktid, 1) != 1)
break;
/* Apply differences between the two arrays to GDB's thread list. */
- infpid = PIDGET (inferior_ptid);
+ infpid = ptid_get_pid (inferior_ptid);
for (pi = gi = 0; pi < pcount || gi < gcount;)
{
if (pi == pcount)
}
else if (gi == gcount)
{
- thread = add_thread (BUILD_THREAD (pbuf[pi].pthid, infpid));
+ thread = add_thread (ptid_build (infpid, 0, pbuf[pi].pthid));
thread->private = xmalloc (sizeof (struct private_thread_info));
thread->private->pdtid = pbuf[pi].pdtid;
thread->private->tid = pbuf[pi].tid;
ptid_t pptid, gptid;
int cmp_result;
- pptid = BUILD_THREAD (pbuf[pi].pthid, infpid);
+ pptid = ptid_build (infpid, 0, pbuf[pi].pthid);
gptid = gbuf[gi]->ptid;
pdtid = pbuf[pi].pdtid;
tid = pbuf[pi].tid;
return;
/* Check application word size. */
- arch64 = register_size (target_gdbarch, 0) == 8;
+ arch64 = register_size (target_gdbarch (), 0) == 8;
/* Check whether the application is pthreaded. */
stub_name = NULL;
if (!(ms = lookup_minimal_symbol (stub_name, NULL, NULL)))
return;
pd_brk_addr = SYMBOL_VALUE_ADDRESS (ms);
- if (!create_thread_event_breakpoint (target_gdbarch, pd_brk_addr))
+ if (!create_thread_event_breakpoint (target_gdbarch (), pd_brk_addr))
return;
/* Prepare for thread debugging. */
/* Detach from the process attached to by aix_thread_attach(). */
static void
-aix_thread_detach (struct target_ops *ops, char *args, int from_tty)
+aix_thread_detach (struct target_ops *ops, const char *args, int from_tty)
{
struct target_ops *beneath = find_target_beneath (ops);
struct cleanup *cleanup = save_inferior_ptid ();
struct target_ops *beneath = find_target_beneath (ops);
- inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid));
+ inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
beneath->to_resume (beneath, ptid, step, sig);
do_cleanups (cleanup);
}
thread = find_thread_ptid (ptid);
if (!thread)
error (_("aix-thread resume: unknown pthread %ld"),
- TIDGET (ptid));
+ ptid_get_lwp (ptid));
tid[0] = thread->private->tid;
if (tid[0] == PTHDB_INVALID_TID)
error (_("aix-thread resume: no tid for pthread %ld"),
- TIDGET (ptid));
+ ptid_get_lwp (ptid));
tid[1] = 0;
if (arch64)
- ptrace64aix (PTT_CONTINUE, tid[0], 1,
+ ptrace64aix (PTT_CONTINUE, tid[0], (long long) 1,
gdb_signal_to_host (sig), (void *) tid);
else
- ptrace32 (PTT_CONTINUE, tid[0], (int *) 1,
+ ptrace32 (PTT_CONTINUE, tid[0], (addr_ptr) 1,
gdb_signal_to_host (sig), (void *) tid);
}
}
pid_to_prc (&ptid);
- inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid));
+ inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
ptid = beneath->to_wait (beneath, ptid, status, options);
do_cleanups (cleanup);
- if (PIDGET (ptid) == -1)
+ if (ptid_get_pid (ptid) == -1)
return pid_to_ptid (-1);
/* Check whether libpthdebug might be ready to be initialized. */
}
else
{
- if (!ptrace32 (PTT_READ_GPRS, tid, gprs32, 0, NULL))
+ if (!ptrace32 (PTT_READ_GPRS, tid, (addr_ptr) gprs32, 0, NULL))
memset (gprs32, 0, sizeof (gprs32));
for (i = 0; i < ppc_num_gprs; i++)
supply_reg32 (regcache, tdep->ppc_gp0_regnum + i, gprs32[i]);
|| (regno >= tdep->ppc_fp0_regnum
&& regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
{
- if (!ptrace32 (PTT_READ_FPRS, tid, (void *) fprs, 0, NULL))
+ if (!ptrace32 (PTT_READ_FPRS, tid, (addr_ptr) fprs, 0, NULL))
memset (fprs, 0, sizeof (fprs));
supply_fprs (regcache, fprs);
}
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
- if (!ptrace32 (PTT_READ_SPRS, tid, (int *) &sprs32, 0, NULL))
+ if (!ptrace32 (PTT_READ_SPRS, tid, (addr_ptr) &sprs32, 0, NULL))
memset (&sprs32, 0, sizeof (sprs32));
supply_sprs32 (regcache, sprs32.pt_iar, sprs32.pt_msr, sprs32.pt_cr,
sprs32.pt_lr, sprs32.pt_ctr, sprs32.pt_xer,
else
{
/* Pre-fetch: some regs may not be in the cache. */
- ptrace32 (PTT_READ_GPRS, tid, gprs32, 0, NULL);
+ ptrace32 (PTT_READ_GPRS, tid, (addr_ptr) gprs32, 0, NULL);
fill_gprs32 (regcache, gprs32);
- ptrace32 (PTT_WRITE_GPRS, tid, gprs32, 0, NULL);
+ ptrace32 (PTT_WRITE_GPRS, tid, (addr_ptr) gprs32, 0, NULL);
}
}
&& regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
{
/* Pre-fetch: some regs may not be in the cache. */
- ptrace32 (PTT_READ_FPRS, tid, (void *) fprs, 0, NULL);
+ ptrace32 (PTT_READ_FPRS, tid, (addr_ptr) fprs, 0, NULL);
fill_fprs (regcache, fprs);
- ptrace32 (PTT_WRITE_FPRS, tid, (void *) fprs, 0, NULL);
+ ptrace32 (PTT_WRITE_FPRS, tid, (addr_ptr) fprs, 0, NULL);
}
/* Special-purpose registers. */
gdb_assert (sizeof (sprs32.pt_iar) == 4);
/* Pre-fetch: some registers won't be in the cache. */
- ptrace32 (PTT_READ_SPRS, tid, (int *) &sprs32, 0, NULL);
+ ptrace32 (PTT_READ_SPRS, tid, (addr_ptr) &sprs32, 0, NULL);
fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr,
&tmp_ctr, &tmp_xer, &tmp_fpscr);
regcache_raw_collect (regcache, tdep->ppc_mq_regnum,
&sprs32.pt_mq);
- ptrace32 (PTT_WRITE_SPRS, tid, (int *) &sprs32, 0, NULL);
+ ptrace32 (PTT_WRITE_SPRS, tid, (addr_ptr) &sprs32, 0, NULL);
}
}
}
LONGEST xfer;
struct target_ops *beneath = find_target_beneath (ops);
- inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid));
+ inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
xfer = beneath->to_xfer_partial (beneath, object, annex,
readbuf, writebuf, offset, len);
_initialize_aix_thread (void)
{
init_aix_thread_ops ();
- add_target (&aix_thread_ops);
+ complete_target_initialization (&aix_thread_ops);
/* Notice when object files get loaded and unloaded. */
observer_attach_new_objfile (new_objfile);