#define PD_TID(ptid) (pd_active && ptid.tid () != 0)
-/* pthdb_user_t value that we pass to pthdb functions. 0 causes
- PTHDB_BAD_USER errors, so use 1. */
-
-#define PD_USER 1
-
/* Success and failure values returned by pthdb callbacks. */
#define PDC_SUCCESS PTHDB_SUCCESS
the address of SYMBOLS[<i>].name. */
static int
-pdc_symbol_addrs (pthdb_user_t user, pthdb_symbol_t *symbols, int count)
+pdc_symbol_addrs (pthdb_user_t user_current_pid, pthdb_symbol_t *symbols, int count)
{
struct bound_minimal_symbol ms;
int i;
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
- "pdc_symbol_addrs (user = %ld, symbols = 0x%lx, count = %d)\n",
- user, (long) symbols, count);
+ "pdc_symbol_addrs (user_current_pid = %ld, symbols = 0x%lx, count = %d)\n",
+ user_current_pid, (long) symbols, count);
for (i = 0; i < count; i++)
{
If successful return 0, else non-zero is returned. */
static int
-pdc_read_regs (pthdb_user_t user,
+pdc_read_regs (pthdb_user_t user_current_pid,
pthdb_tid_t tid,
unsigned long long flags,
pthdb_context_t *context)
If successful return 0, else non-zero is returned. */
static int
-pdc_write_regs (pthdb_user_t user,
+pdc_write_regs (pthdb_user_t user_current_pid,
pthdb_tid_t tid,
unsigned long long flags,
pthdb_context_t *context)
/* pthdb callback: read LEN bytes from process ADDR into BUF. */
static int
-pdc_read_data (pthdb_user_t user, void *buf,
+pdc_read_data (pthdb_user_t user_current_pid, void *buf,
pthdb_addr_t addr, size_t len)
{
int status, ret;
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
- "pdc_read_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
- user, (long) buf, hex_string (addr), len);
+ "pdc_read_data (user_current_pid = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
+ user_current_pid, (long) buf, hex_string (addr), len);
- status = target_read_memory (addr, (gdb_byte *) buf, len);
+ /* This is needed to eliminate the dependency of current thread
+ which is null so that thread reads the correct target memory. */
+ {
+ scoped_restore_current_thread restore_current_thread;
+ /* Before the first inferior is added, we pass inferior_ptid.pid ()
+ from pd_enable () which is 0. There is no need to switch threads
+ during first initialisation. In the rest of the callbacks the
+ current thread needs to be correct. */
+ if (user_current_pid != 0)
+ switch_to_thread (current_inferior ()->process_target (),
+ ptid_t (user_current_pid));
+ status = target_read_memory (addr, (gdb_byte *) buf, len);
+ }
ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
if (debug_aix_thread)
/* pthdb callback: write LEN bytes from BUF to process ADDR. */
static int
-pdc_write_data (pthdb_user_t user, void *buf,
+pdc_write_data (pthdb_user_t user_current_pid, void *buf,
pthdb_addr_t addr, size_t len)
{
int status, ret;
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
- "pdc_write_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
- user, (long) buf, hex_string (addr), len);
+ "pdc_write_data (user_current_pid = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
+ user_current_pid, (long) buf, hex_string (addr), len);
status = target_write_memory (addr, (gdb_byte *) buf, len);
ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
in BUFP. */
static int
-pdc_alloc (pthdb_user_t user, size_t len, void **bufp)
+pdc_alloc (pthdb_user_t user_current_pid, size_t len, void **bufp)
{
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
- "pdc_alloc (user = %ld, len = %ld, bufp = 0x%lx)\n",
- user, len, (long) bufp);
+ "pdc_alloc (user_current_pid = %ld, len = %ld, bufp = 0x%lx)\n",
+ user_current_pid, len, (long) bufp);
*bufp = xmalloc (len);
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
pointer to the result in BUFP. */
static int
-pdc_realloc (pthdb_user_t user, void *buf, size_t len, void **bufp)
+pdc_realloc (pthdb_user_t user_current_pid, void *buf, size_t len, void **bufp)
{
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
- "pdc_realloc (user = %ld, buf = 0x%lx, len = %ld, bufp = 0x%lx)\n",
- user, (long) buf, len, (long) bufp);
+ "pdc_realloc (user_current_pid = %ld, buf = 0x%lx, len = %ld, bufp = 0x%lx)\n",
+ user_current_pid, (long) buf, len, (long) bufp);
*bufp = xrealloc (buf, len);
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
realloc callback. */
static int
-pdc_dealloc (pthdb_user_t user, void *buf)
+pdc_dealloc (pthdb_user_t user_current_pid, void *buf)
{
if (debug_aix_thread)
gdb_printf (gdb_stdlog,
- "pdc_free (user = %ld, buf = 0x%lx)\n", user,
+ "pdc_free (user_current_pid = %ld, buf = 0x%lx)\n", user_current_pid,
(long) buf);
xfree (buf);
return PDC_SUCCESS;
{
int status;
- status = pthdb_session_init (PD_USER, arch64 ? PEM_64BIT : PEM_32BIT,
+ status = pthdb_session_init (pid, arch64 ? PEM_64BIT : PEM_32BIT,
PTHDB_FLAG_REGS, &pd_callbacks,
&pd_session);
if (status != PTHDB_SUCCESS)
/* Check whether the application is pthreaded. */
stub_name = NULL;
- status = pthdb_session_pthreaded (PD_USER, PTHDB_FLAG_REGS,
+ status = pthdb_session_pthreaded (inferior_ptid.pid (), PTHDB_FLAG_REGS,
&pd_callbacks, &stub_name);
if ((status != PTHDB_SUCCESS
&& status != PTHDB_NOT_PTHREADED) || !stub_name)
/* If we're debugging a core file or an attached inferior, the
pthread library may already have been initialized, so try to
activate thread debugging. */
- pd_activate (1);
+ pd_activate (inferior_ptid.pid ());
}
/* Undo the effects of pd_enable(). */