1 /* Low level interface for debugging AIX 4.3+ pthreads.
3 Copyright (C) 1999-2023 Free Software Foundation, Inc.
4 Written by Nick Duffek <nsd@redhat.com>.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* This module uses the libpthdebug.a library provided by AIX 4.3+ for
23 debugging pthread applications.
25 Some name prefix conventions:
26 pthdb_ provided by libpthdebug.a
27 pdc_ callbacks that this module provides to libpthdebug.a
28 pd_ variables or functions interfacing with libpthdebug.a
30 libpthdebug peculiarities:
32 - pthdb_ptid_pthread() is prototyped in <sys/pthdebug.h>, but
33 it's not documented, and after several calls it stops working
34 and causes other libpthdebug functions to fail.
36 - pthdb_tid_pthread() doesn't always work after
37 pthdb_session_update(), but it does work after cycling through
38 all threads using pthdb_pthread().
43 #include "gdbthread.h"
49 #include "observable.h"
53 #include <sys/types.h>
54 #include <sys/ptrace.h>
57 #include <sys/pthdebug.h>
59 #if !HAVE_DECL_GETTHRDS
60 extern int getthrds (pid_t
, struct thrdsinfo64
*, int, tid_t
*, int);
63 /* Whether to emit debugging output. */
64 static bool debug_aix_thread
;
66 /* In AIX 5.1, functions use pthdb_tid_t instead of tid_t. */
67 #ifndef PTHDB_VERSION_3
68 #define pthdb_tid_t tid_t
71 /* Success and failure values returned by pthdb callbacks. */
73 #define PDC_SUCCESS PTHDB_SUCCESS
74 #define PDC_FAILURE PTHDB_CALLBACK
76 /* Private data attached to each element in GDB's thread list. */
78 struct aix_thread_info
: public private_thread_info
80 pthdb_pthread_t pdtid
; /* thread's libpthdebug id */
81 pthdb_tid_t tid
; /* kernel thread id */
84 /* Return the aix_thread_info attached to THREAD. */
86 static aix_thread_info
*
87 get_aix_thread_info (thread_info
*thread
)
89 return gdb::checked_static_cast
<aix_thread_info
*> (thread
->priv
.get ());
92 /* Information about a thread of which libpthdebug is aware. */
95 pthdb_pthread_t pdtid
;
100 /* This module's target-specific operations, active while pd_able is true. */
102 static const target_info aix_thread_target_info
= {
104 N_("AIX pthread support"),
105 N_("AIX pthread support")
108 class aix_thread_target final
: public target_ops
111 const target_info
&info () const override
112 { return aix_thread_target_info
; }
114 strata
stratum () const override
{ return thread_stratum
; }
116 void detach (inferior
*, int) override
;
117 void resume (ptid_t
, int, enum gdb_signal
) override
;
118 ptid_t
wait (ptid_t
, struct target_waitstatus
*, target_wait_flags
) override
;
120 void fetch_registers (struct regcache
*, int) override
;
121 void store_registers (struct regcache
*, int) override
;
123 enum target_xfer_status
xfer_partial (enum target_object object
,
126 const gdb_byte
*writebuf
,
127 ULONGEST offset
, ULONGEST len
,
128 ULONGEST
*xfered_len
) override
;
130 void mourn_inferior () override
;
132 bool thread_alive (ptid_t ptid
) override
;
134 std::string
pid_to_str (ptid_t
) override
;
136 const char *extra_thread_info (struct thread_info
*) override
;
138 ptid_t
get_ada_task_ptid (long lwp
, ULONGEST thread
) override
;
141 static aix_thread_target aix_thread_ops
;
143 /* Forward declarations for pthdb callbacks. */
145 static int pdc_symbol_addrs (pthdb_user_t
, pthdb_symbol_t
*, int);
146 static int pdc_read_data (pthdb_user_t
, void *, pthdb_addr_t
, size_t);
147 static int pdc_write_data (pthdb_user_t
, void *, pthdb_addr_t
, size_t);
148 static int pdc_read_regs (pthdb_user_t user
, pthdb_tid_t tid
,
149 unsigned long long flags
,
150 pthdb_context_t
*context
);
151 static int pdc_write_regs (pthdb_user_t user
, pthdb_tid_t tid
,
152 unsigned long long flags
,
153 pthdb_context_t
*context
);
154 static int pdc_alloc (pthdb_user_t
, size_t, void **);
155 static int pdc_realloc (pthdb_user_t
, void *, size_t, void **);
156 static int pdc_dealloc (pthdb_user_t
, void *);
158 /* pthdb callbacks. */
160 static pthdb_callbacks_t pd_callbacks
= {
172 /* Aix variable structure. */
173 struct aix_thread_variables
175 /* Whether the current application is debuggable by pthdb. */
178 /* Whether a threaded application is being debugged. */
181 /* Current pthdb session. */
182 pthdb_session_t pd_session
;
184 /* Address of the function that libpthread will call when libpthdebug
185 is ready to be initialized. */
186 CORE_ADDR pd_brk_addr
;
188 /* Whether the current architecture is 64-bit.
189 Only valid when pd_able is true. */
193 /* Key to our per-inferior data. */
194 static const registry
<inferior
>::key
<aix_thread_variables
>
195 aix_thread_variables_handle
;
197 /* Function to Get aix_thread_variables data. */
198 static struct aix_thread_variables
*
199 get_aix_thread_variables_data (struct inferior
*inf
)
204 struct aix_thread_variables
* data
;
206 data
= aix_thread_variables_handle
.get (inf
);
208 data
= aix_thread_variables_handle
.emplace (inf
);
213 /* Helper to get data for ptid in a function. */
215 static struct aix_thread_variables
*
216 get_thread_data_helper_for_ptid (ptid_t ptid
)
218 inferior
*inf
= find_inferior_ptid (current_inferior ()->process_target (),
220 return get_aix_thread_variables_data (inf
);
223 /* Helper to get data for pid in a function. */
225 static struct aix_thread_variables
*
226 get_thread_data_helper_for_pid (pid_t pid
)
228 inferior
*inf
= find_inferior_pid (current_inferior ()->process_target (),
230 return get_aix_thread_variables_data (inf
);
233 /* Return a printable representation of pthdebug function return
237 pd_status2str (int status
)
241 case PTHDB_SUCCESS
: return "SUCCESS";
242 case PTHDB_NOSYS
: return "NOSYS";
243 case PTHDB_NOTSUP
: return "NOTSUP";
244 case PTHDB_BAD_VERSION
: return "BAD_VERSION";
245 case PTHDB_BAD_USER
: return "BAD_USER";
246 case PTHDB_BAD_SESSION
: return "BAD_SESSION";
247 case PTHDB_BAD_MODE
: return "BAD_MODE";
248 case PTHDB_BAD_FLAGS
: return "BAD_FLAGS";
249 case PTHDB_BAD_CALLBACK
: return "BAD_CALLBACK";
250 case PTHDB_BAD_POINTER
: return "BAD_POINTER";
251 case PTHDB_BAD_CMD
: return "BAD_CMD";
252 case PTHDB_BAD_PTHREAD
: return "BAD_PTHREAD";
253 case PTHDB_BAD_ATTR
: return "BAD_ATTR";
254 case PTHDB_BAD_MUTEX
: return "BAD_MUTEX";
255 case PTHDB_BAD_MUTEXATTR
: return "BAD_MUTEXATTR";
256 case PTHDB_BAD_COND
: return "BAD_COND";
257 case PTHDB_BAD_CONDATTR
: return "BAD_CONDATTR";
258 case PTHDB_BAD_RWLOCK
: return "BAD_RWLOCK";
259 case PTHDB_BAD_RWLOCKATTR
: return "BAD_RWLOCKATTR";
260 case PTHDB_BAD_KEY
: return "BAD_KEY";
261 case PTHDB_BAD_PTID
: return "BAD_PTID";
262 case PTHDB_BAD_TID
: return "BAD_TID";
263 case PTHDB_CALLBACK
: return "CALLBACK";
264 case PTHDB_CONTEXT
: return "CONTEXT";
265 case PTHDB_HELD
: return "HELD";
266 case PTHDB_NOT_HELD
: return "NOT_HELD";
267 case PTHDB_MEMORY
: return "MEMORY";
268 case PTHDB_NOT_PTHREADED
: return "NOT_PTHREADED";
269 case PTHDB_SYMBOL
: return "SYMBOL";
270 case PTHDB_NOT_AVAIL
: return "NOT_AVAIL";
271 case PTHDB_INTERNAL
: return "INTERNAL";
272 default: return "UNKNOWN";
276 /* A call to ptrace(REQ, ID, ...) just returned RET. Check for
277 exceptional conditions and either return nonlocally or else return
278 1 for success and 0 for failure. */
281 ptrace_check (int req
, int id
, int ret
)
283 if (ret
== 0 && !errno
)
286 /* According to ptrace(2), ptrace may fail with EPERM if "the
287 Identifier parameter corresponds to a kernel thread which is
288 stopped in kernel mode and whose computational state cannot be
289 read or written." This happens quite often with register reads. */
296 if (ret
== -1 && errno
== EPERM
)
298 if (debug_aix_thread
)
299 gdb_printf (gdb_stdlog
,
300 "ptrace (%d, %d) = %d (errno = %d)\n",
301 req
, id
, ret
, errno
);
302 return ret
== -1 ? 0 : 1;
307 if (debug_aix_thread
)
308 gdb_printf (gdb_stdlog
,
309 "ptrace (%d, %d) = %d (errno = %d)\n",
310 req
, id
, ret
, errno
);
315 error (_("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)"),
316 req
, id
, ret
, errno
, safe_strerror (errno
));
317 return 0; /* Not reached. */
320 /* Call ptracex (REQ, ID, ADDR, DATA, BUF) or
321 ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
325 # define ptracex(request, pid, addr, data, buf) \
326 ptrace64 (request, pid, addr, data, buf)
330 ptrace64aix (int req
, int id
, long long addr
, int data
, int *buf
)
333 return ptrace_check (req
, id
, ptracex (req
, id
, addr
, data
, buf
));
336 /* Call ptrace (REQ, ID, ADDR, DATA, BUF) or
337 ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
341 # define ptrace(request, pid, addr, data, buf) \
342 ptrace64 (request, pid, addr, data, buf)
343 # define addr_ptr long long
345 # define addr_ptr int *
349 ptrace32 (int req
, int id
, addr_ptr addr
, int data
, int *buf
)
352 return ptrace_check (req
, id
,
353 ptrace (req
, id
, addr
, data
, buf
));
356 /* If *PIDP is a composite process/thread id, convert it to a
360 pid_to_prc (ptid_t
*ptidp
)
365 if (ptid
.tid () != 0)
366 *ptidp
= ptid_t (ptid
.pid ());
369 /* pthdb callback: for <i> from 0 to COUNT, set SYMBOLS[<i>].addr to
370 the address of SYMBOLS[<i>].name. */
373 pdc_symbol_addrs (pthdb_user_t user_current_pid
, pthdb_symbol_t
*symbols
, int count
)
375 struct bound_minimal_symbol ms
;
379 if (debug_aix_thread
)
380 gdb_printf (gdb_stdlog
,
381 "pdc_symbol_addrs (user_current_pid = %ld, symbols = 0x%lx, count = %d)\n",
382 user_current_pid
, (long) symbols
, count
);
384 for (i
= 0; i
< count
; i
++)
386 name
= symbols
[i
].name
;
387 if (debug_aix_thread
)
388 gdb_printf (gdb_stdlog
,
389 " symbols[%d].name = \"%s\"\n", i
, name
);
395 ms
= lookup_minimal_symbol (name
, NULL
, NULL
);
396 if (ms
.minsym
== NULL
)
398 if (debug_aix_thread
)
399 gdb_printf (gdb_stdlog
, " returning PDC_FAILURE\n");
402 symbols
[i
].addr
= ms
.value_address ();
404 if (debug_aix_thread
)
405 gdb_printf (gdb_stdlog
, " symbols[%d].addr = %s\n",
406 i
, hex_string (symbols
[i
].addr
));
408 if (debug_aix_thread
)
409 gdb_printf (gdb_stdlog
, " returning PDC_SUCCESS\n");
413 /* Read registers call back function should be able to read the
414 context information of a debuggee kernel thread from an active
415 process or from a core file. The information should be formatted
416 in context64 form for both 32-bit and 64-bit process.
417 If successful return 0, else non-zero is returned. */
420 pdc_read_regs (pthdb_user_t user_current_pid
,
422 unsigned long long flags
,
423 pthdb_context_t
*context
)
425 /* This function doesn't appear to be used, so we could probably
426 just return 0 here. HOWEVER, if it is not defined, the OS will
427 complain and several thread debug functions will fail. In case
428 this is needed, I have implemented what I think it should do,
429 however this code is untested. */
431 uint64_t gprs64
[ppc_num_gprs
];
432 uint32_t gprs32
[ppc_num_gprs
];
433 double fprs
[ppc_num_fprs
];
434 struct ptxsprs sprs64
;
435 struct ptsprs sprs32
;
436 struct aix_thread_variables
*data
;
438 data
= get_thread_data_helper_for_pid (user_current_pid
);
440 if (debug_aix_thread
)
441 gdb_printf (gdb_stdlog
, "pdc_read_regs tid=%d flags=%s\n",
442 (int) tid
, hex_string (flags
));
444 /* General-purpose registers. */
445 if (flags
& PTHDB_FLAG_GPRS
)
449 if (!ptrace64aix (PTT_READ_GPRS
, tid
,
450 (unsigned long) gprs64
, 0, NULL
))
451 memset (gprs64
, 0, sizeof (gprs64
));
452 memcpy (context
->gpr
, gprs64
, sizeof(gprs64
));
456 if (!ptrace32 (PTT_READ_GPRS
, tid
, (uintptr_t) gprs32
, 0, NULL
))
457 memset (gprs32
, 0, sizeof (gprs32
));
458 memcpy (context
->gpr
, gprs32
, sizeof(gprs32
));
462 /* Floating-point registers. */
463 if (flags
& PTHDB_FLAG_FPRS
)
465 if (!ptrace32 (PTT_READ_FPRS
, tid
, (uintptr_t) fprs
, 0, NULL
))
466 memset (fprs
, 0, sizeof (fprs
));
467 memcpy (context
->fpr
, fprs
, sizeof(fprs
));
470 /* Special-purpose registers. */
471 if (flags
& PTHDB_FLAG_SPRS
)
475 if (!ptrace64aix (PTT_READ_SPRS
, tid
,
476 (unsigned long) &sprs64
, 0, NULL
))
477 memset (&sprs64
, 0, sizeof (sprs64
));
478 memcpy (&context
->msr
, &sprs64
, sizeof(sprs64
));
482 if (!ptrace32 (PTT_READ_SPRS
, tid
, (uintptr_t) &sprs32
, 0, NULL
))
483 memset (&sprs32
, 0, sizeof (sprs32
));
484 memcpy (&context
->msr
, &sprs32
, sizeof(sprs32
));
488 /* vector registers. */
490 if (__power_vmx() && (flags
& PTHDB_FLAG_REGS
))
494 if (!ptrace64aix (PTT_READ_VEC
, tid
, (long long) &vmx
, 0, 0))
495 memset (&vmx
, 0, sizeof (vmx
));
496 memcpy (&context
->vmx
, &vmx
, sizeof(__vmx_context_t
));
500 if (!ptrace32 (PTT_READ_VEC
, tid
, (long long) &vmx
, 0, 0))
501 memset (&vmx
, 0, sizeof (vmx
));
502 memcpy (&context
->vmx
, &vmx
, sizeof(__vmx_context_t
));
508 if (__power_vsx() && (flags
& PTHDB_FLAG_REGS
))
512 if (!ptrace64aix (PTT_READ_VSX
, tid
, (long long) &vsx
, 0, 0))
513 memset (&vsx
, 0, sizeof (vsx
));
514 memcpy (&context
->vsx
, &vsx
, sizeof(__vsx_context_t
));
518 if (!ptrace32 (PTT_READ_VSX
, tid
, (long long) &vsx
, 0, 0))
519 memset (&vsx
, 0, sizeof (vsx
));
520 memcpy (&context
->vsx
, &vsx
, sizeof(__vsx_context_t
));
526 /* Write register function should be able to write requested context
527 information to specified debuggee's kernel thread id.
528 If successful return 0, else non-zero is returned. */
531 pdc_write_regs (pthdb_user_t user_current_pid
,
533 unsigned long long flags
,
534 pthdb_context_t
*context
)
536 /* This function doesn't appear to be used, so we could probably
537 just return 0 here. HOWEVER, if it is not defined, the OS will
538 complain and several thread debug functions will fail. In case
539 this is needed, I have implemented what I think it should do,
540 however this code is untested. */
542 struct aix_thread_variables
*data
;
544 data
= get_thread_data_helper_for_pid (user_current_pid
);
546 if (debug_aix_thread
)
547 gdb_printf (gdb_stdlog
, "pdc_write_regs tid=%d flags=%s\n",
548 (int) tid
, hex_string (flags
));
550 /* General-purpose registers. */
551 if (flags
& PTHDB_FLAG_GPRS
)
554 ptrace64aix (PTT_WRITE_GPRS
, tid
,
555 (unsigned long) context
->gpr
, 0, NULL
);
557 ptrace32 (PTT_WRITE_GPRS
, tid
, (uintptr_t) context
->gpr
, 0, NULL
);
560 /* Floating-point registers. */
561 if (flags
& PTHDB_FLAG_FPRS
)
563 ptrace32 (PTT_WRITE_FPRS
, tid
, (uintptr_t) context
->fpr
, 0, NULL
);
566 /* Special-purpose registers. */
567 if (flags
& PTHDB_FLAG_SPRS
)
571 ptrace64aix (PTT_WRITE_SPRS
, tid
,
572 (unsigned long) &context
->msr
, 0, NULL
);
576 ptrace32 (PTT_WRITE_SPRS
, tid
, (uintptr_t) &context
->msr
, 0, NULL
);
580 /* vector registers. */
581 if (__power_vmx() && (flags
& PTHDB_FLAG_REGS
))
584 ptrace64aix (PTT_WRITE_VEC
, tid
, (unsigned long) &context
->vmx
, 0, 0);
586 ptrace32 (PTT_WRITE_VEC
, tid
, (uintptr_t) &context
->vmx
, 0, 0);
590 if (__power_vsx() && (flags
& PTHDB_FLAG_REGS
))
593 ptrace64aix (PTT_WRITE_VSX
, tid
, (unsigned long) &context
->vsx
, 0, 0);
595 ptrace32 (PTT_WRITE_VSX
, tid
, (uintptr_t) &context
->vsx
, 0, 0);
600 /* pthdb callback: read LEN bytes from process ADDR into BUF. */
603 pdc_read_data (pthdb_user_t user_current_pid
, void *buf
,
604 pthdb_addr_t addr
, size_t len
)
607 inferior
*inf
= find_inferior_pid (current_inferior ()->process_target (),
610 if (debug_aix_thread
)
611 gdb_printf (gdb_stdlog
,
612 "pdc_read_data (user_current_pid = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
613 user_current_pid
, (long) buf
, hex_string (addr
), len
);
615 /* This is needed to eliminate the dependency of current thread
616 which is null so that thread reads the correct target memory. */
618 scoped_restore_current_inferior_for_memory
save_inferior (inf
);
619 status
= target_read_memory (addr
, (gdb_byte
*) buf
, len
);
621 ret
= status
== 0 ? PDC_SUCCESS
: PDC_FAILURE
;
623 if (debug_aix_thread
)
624 gdb_printf (gdb_stdlog
, " status=%d, returning %s\n",
625 status
, pd_status2str (ret
));
629 /* pthdb callback: write LEN bytes from BUF to process ADDR. */
632 pdc_write_data (pthdb_user_t user_current_pid
, void *buf
,
633 pthdb_addr_t addr
, size_t len
)
636 inferior
*inf
= find_inferior_pid (current_inferior ()->process_target (),
639 if (debug_aix_thread
)
640 gdb_printf (gdb_stdlog
,
641 "pdc_write_data (user_current_pid = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
642 user_current_pid
, (long) buf
, hex_string (addr
), len
);
645 scoped_restore_current_inferior_for_memory
save_inferior (inf
);
646 status
= target_write_memory (addr
, (gdb_byte
*) buf
, len
);
649 ret
= status
== 0 ? PDC_SUCCESS
: PDC_FAILURE
;
651 if (debug_aix_thread
)
652 gdb_printf (gdb_stdlog
, " status=%d, returning %s\n", status
,
653 pd_status2str (ret
));
657 /* pthdb callback: allocate a LEN-byte buffer and store a pointer to it
661 pdc_alloc (pthdb_user_t user_current_pid
, size_t len
, void **bufp
)
663 if (debug_aix_thread
)
664 gdb_printf (gdb_stdlog
,
665 "pdc_alloc (user_current_pid = %ld, len = %ld, bufp = 0x%lx)\n",
666 user_current_pid
, len
, (long) bufp
);
667 *bufp
= xmalloc (len
);
668 if (debug_aix_thread
)
669 gdb_printf (gdb_stdlog
,
670 " malloc returned 0x%lx\n", (long) *bufp
);
672 /* Note: xmalloc() can't return 0; therefore PDC_FAILURE will never
675 return *bufp
? PDC_SUCCESS
: PDC_FAILURE
;
678 /* pthdb callback: reallocate BUF, which was allocated by the alloc or
679 realloc callback, so that it contains LEN bytes, and store a
680 pointer to the result in BUFP. */
683 pdc_realloc (pthdb_user_t user_current_pid
, void *buf
, size_t len
, void **bufp
)
685 if (debug_aix_thread
)
686 gdb_printf (gdb_stdlog
,
687 "pdc_realloc (user_current_pid = %ld, buf = 0x%lx, len = %ld, bufp = 0x%lx)\n",
688 user_current_pid
, (long) buf
, len
, (long) bufp
);
689 *bufp
= xrealloc (buf
, len
);
690 if (debug_aix_thread
)
691 gdb_printf (gdb_stdlog
,
692 " realloc returned 0x%lx\n", (long) *bufp
);
693 return *bufp
? PDC_SUCCESS
: PDC_FAILURE
;
696 /* pthdb callback: free BUF, which was allocated by the alloc or
700 pdc_dealloc (pthdb_user_t user_current_pid
, void *buf
)
702 if (debug_aix_thread
)
703 gdb_printf (gdb_stdlog
,
704 "pdc_free (user_current_pid = %ld, buf = 0x%lx)\n", user_current_pid
,
710 /* Return a printable representation of pthread STATE. */
713 state2str (pthdb_state_t state
)
718 /* i18n: Like "Thread-Id %d, [state] idle" */
719 return _("idle"); /* being created */
721 /* i18n: Like "Thread-Id %d, [state] running" */
722 return _("running"); /* running */
724 /* i18n: Like "Thread-Id %d, [state] sleeping" */
725 return _("sleeping"); /* awaiting an event */
727 /* i18n: Like "Thread-Id %d, [state] ready" */
728 return _("ready"); /* runnable */
730 /* i18n: Like "Thread-Id %d, [state] finished" */
731 return _("finished"); /* awaiting a join/detach */
733 /* i18n: Like "Thread-Id %d, [state] unknown" */
738 /* qsort() comparison function for sorting pd_thread structs by pthid. */
741 pcmp (const void *p1v
, const void *p2v
)
743 struct pd_thread
*p1
= (struct pd_thread
*) p1v
;
744 struct pd_thread
*p2
= (struct pd_thread
*) p2v
;
745 return p1
->pthid
< p2
->pthid
? -1 : p1
->pthid
> p2
->pthid
;
748 /* ptid comparison function */
751 ptid_cmp (ptid_t ptid1
, ptid_t ptid2
)
753 if (ptid1
.pid () < ptid2
.pid ())
755 else if (ptid1
.pid () > ptid2
.pid ())
757 else if (ptid1
.tid () < ptid2
.tid ())
759 else if (ptid1
.tid () > ptid2
.tid ())
761 else if (ptid1
.lwp () < ptid2
.lwp ())
763 else if (ptid1
.lwp () > ptid2
.lwp ())
769 /* qsort() comparison function for sorting thread_info structs by pid. */
772 gcmp (const void *t1v
, const void *t2v
)
774 struct thread_info
*t1
= *(struct thread_info
**) t1v
;
775 struct thread_info
*t2
= *(struct thread_info
**) t2v
;
776 return ptid_cmp (t1
->ptid
, t2
->ptid
);
779 /* Search through the list of all kernel threads for the thread
780 that has stopped on a SIGTRAP signal, and return its TID.
781 Return 0 if none found. */
784 get_signaled_thread (int pid
)
786 struct thrdsinfo64 thrinf
;
791 if (getthrds (pid
, &thrinf
,
792 sizeof (thrinf
), &ktid
, 1) != 1)
795 /* We also need to keep in mind Trap and interrupt or any
796 signal that needs to be handled in pd_update (). */
798 if (thrinf
.ti_cursig
)
799 return thrinf
.ti_tid
;
802 /* Didn't find any thread stopped on a SIGTRAP signal. */
806 /* Synchronize GDB's thread list with libpthdebug's.
808 There are some benefits of doing this every time the inferior stops:
810 - allows users to run thread-specific commands without needing to
811 run "info threads" first
813 - helps pthdb_tid_pthread() work properly (see "libpthdebug
814 peculiarities" at the top of this module)
816 - simplifies the demands placed on libpthdebug, which seems to
817 have difficulty with certain call patterns */
820 sync_threadlists (pid_t pid
)
823 int pcount
, psize
, pi
, gcount
, gi
;
824 struct pd_thread
*pbuf
;
825 struct thread_info
**gbuf
, **g
, *thread
;
826 pthdb_pthread_t pdtid
;
829 process_stratum_target
*proc_target
= current_inferior ()->process_target ();
831 struct aix_thread_variables
*data
;
832 data
= get_thread_data_helper_for_pid (pid
);
834 /* Accumulate an array of libpthdebug threads sorted by pthread id. */
838 pbuf
= XNEWVEC (struct pd_thread
, psize
);
840 for (cmd
= PTHDB_LIST_FIRST
;; cmd
= PTHDB_LIST_NEXT
)
842 status
= pthdb_pthread (data
->pd_session
, &pdtid
, cmd
);
843 if (status
!= PTHDB_SUCCESS
|| pdtid
== PTHDB_INVALID_PTHREAD
)
846 status
= pthdb_pthread_ptid (data
->pd_session
, pdtid
, &pthid
);
847 if (status
!= PTHDB_SUCCESS
|| pthid
== PTHDB_INVALID_PTID
)
853 pbuf
= (struct pd_thread
*) xrealloc (pbuf
,
854 psize
* sizeof *pbuf
);
856 pbuf
[pcount
].pdtid
= pdtid
;
857 pbuf
[pcount
].pthid
= pthid
;
861 for (pi
= 0; pi
< pcount
; pi
++)
863 status
= pthdb_pthread_tid (data
->pd_session
, pbuf
[pi
].pdtid
, &tid
);
864 if (status
!= PTHDB_SUCCESS
)
865 tid
= PTHDB_INVALID_TID
;
869 qsort (pbuf
, pcount
, sizeof *pbuf
, pcmp
);
871 /* Accumulate an array of GDB threads sorted by pid. */
873 /* gcount is GDB thread count and pcount is pthreadlib thread count. */
876 for (thread_info
*tp
: all_threads (proc_target
, ptid_t (pid
)))
878 g
= gbuf
= XNEWVEC (struct thread_info
*, gcount
);
879 for (thread_info
*tp
: all_threads (proc_target
, ptid_t (pid
)))
881 qsort (gbuf
, gcount
, sizeof *gbuf
, gcmp
);
883 /* Apply differences between the two arrays to GDB's thread list. */
885 for (pi
= gi
= 0; pi
< pcount
|| gi
< gcount
;)
889 delete_thread (gbuf
[gi
]);
892 else if (gi
== gcount
)
894 aix_thread_info
*priv
= new aix_thread_info
;
895 priv
->pdtid
= pbuf
[pi
].pdtid
;
896 priv
->tid
= pbuf
[pi
].tid
;
898 thread
= add_thread_with_info (proc_target
,
899 ptid_t (pid
, 0, pbuf
[pi
].pthid
),
900 private_thread_info_up (priv
));
909 pptid
= ptid_t (pid
, 0, pbuf
[pi
].pthid
);
910 gptid
= gbuf
[gi
]->ptid
;
911 pdtid
= pbuf
[pi
].pdtid
;
914 cmp_result
= ptid_cmp (pptid
, gptid
);
918 aix_thread_info
*priv
= get_aix_thread_info (gbuf
[gi
]);
925 else if (cmp_result
> 0)
927 /* This is to make the main process thread now look
932 tp
= proc_target
->find_thread (gptid
);
933 thread_change_ptid (proc_target
, gptid
, pptid
);
934 aix_thread_info
*priv
= new aix_thread_info
;
935 priv
->pdtid
= pbuf
[pi
].pdtid
;
936 priv
->tid
= pbuf
[pi
].tid
;
937 tp
->priv
.reset (priv
);
943 delete_thread (gbuf
[gi
]);
949 thread
= add_thread (proc_target
, pptid
);
951 aix_thread_info
*priv
= new aix_thread_info
;
952 thread
->priv
.reset (priv
);
964 /* Iterate_over_threads() callback for locating a thread, using
965 the TID of its associated kernel thread. */
968 iter_tid (struct thread_info
*thread
, void *tidp
)
970 const pthdb_tid_t tid
= *(pthdb_tid_t
*)tidp
;
971 aix_thread_info
*priv
= get_aix_thread_info (thread
);
973 return priv
->tid
== tid
;
976 /* Synchronize libpthdebug's state with the inferior and with GDB,
977 generate a composite process/thread <pid> for the current thread,
978 Return the ptid of the event thread if one can be found, else
979 return a pid-only ptid with PID. */
982 pd_update (pid_t pid
)
987 struct thread_info
*thread
= NULL
;
988 struct aix_thread_variables
*data
;
990 data
= get_thread_data_helper_for_pid (pid
);
992 if (!data
->pd_active
)
995 status
= pthdb_session_update (data
->pd_session
);
996 if (status
!= PTHDB_SUCCESS
)
999 sync_threadlists (pid
);
1001 /* Define "current thread" as one that just received a trap signal. */
1003 tid
= get_signaled_thread (pid
);
1005 thread
= iterate_over_threads (iter_tid
, &tid
);
1007 ptid
= ptid_t (pid
);
1009 ptid
= thread
->ptid
;
1014 /* Try to start debugging threads in the current process.
1015 If successful and there exists and we can find an event thread, return a ptid
1016 for that thread. Otherwise, return a ptid-only ptid using PID. */
1019 pd_activate (pid_t pid
)
1022 struct aix_thread_variables
*data
;
1023 data
= get_thread_data_helper_for_pid (pid
);
1025 status
= pthdb_session_init (pid
, data
->arch64
? PEM_64BIT
: PEM_32BIT
,
1026 PTHDB_FLAG_REGS
, &pd_callbacks
,
1028 if (status
!= PTHDB_SUCCESS
)
1030 return ptid_t (pid
);
1032 data
->pd_active
= 1;
1033 return pd_update (pid
);
1036 /* An object file has just been loaded. Check whether the current
1037 application is pthreaded, and if so, prepare for thread debugging. */
1040 pd_enable (inferior
*inf
)
1044 struct bound_minimal_symbol ms
;
1045 struct aix_thread_variables
*data
;
1050 data
= get_aix_thread_variables_data (inf
);
1052 /* Don't initialize twice. */
1056 /* Check application word size. */
1057 data
->arch64
= register_size (current_inferior ()->arch (), 0) == 8;
1059 /* Check whether the application is pthreaded. */
1061 status
= pthdb_session_pthreaded (inf
->pid
, PTHDB_FLAG_REGS
,
1062 &pd_callbacks
, &stub_name
);
1063 if ((status
!= PTHDB_SUCCESS
1064 && status
!= PTHDB_NOT_PTHREADED
) || !stub_name
)
1067 /* Set a breakpoint on the returned stub function. */
1068 ms
= lookup_minimal_symbol (stub_name
, NULL
, NULL
);
1069 if (ms
.minsym
== NULL
)
1071 data
->pd_brk_addr
= ms
.value_address ();
1072 if (!create_thread_event_breakpoint (current_inferior ()->arch (),
1076 /* Prepare for thread debugging. */
1077 current_inferior ()->push_target (&aix_thread_ops
);
1080 /* When attaching / handling fork child, don't try activating
1081 thread debugging until we know about all shared libraries. */
1082 if (inf
->in_initial_library_scan
)
1085 /* If we're debugging a core file or an attached inferior, the
1086 pthread library may already have been initialized, so try to
1087 activate thread debugging. */
1088 pd_activate (inf
->pid
);
1091 /* Undo the effects of pd_enable(). */
1094 pd_disable (inferior
*inf
)
1096 struct aix_thread_variables
*data
;
1097 data
= get_aix_thread_variables_data (inf
);
1101 if (!data
->pd_active
)
1103 pthdb_session_destroy (data
->pd_session
);
1105 pid_to_prc (&inferior_ptid
);
1106 data
->pd_active
= 0;
1108 current_inferior ()->unpush_target (&aix_thread_ops
);
1111 /* new_objfile observer callback.
1113 Check whether a threaded application is being debugged, and if so, prepare
1114 for thread debugging. */
1117 new_objfile (struct objfile
*objfile
)
1119 pd_enable (current_inferior ());
1122 /* Attach to process specified by ARGS. */
1125 aix_thread_inferior_created (inferior
*inf
)
1130 /* Detach from the process attached to by aix_thread_attach(). */
1133 aix_thread_target::detach (inferior
*inf
, int from_tty
)
1135 target_ops
*beneath
= this->beneath ();
1138 beneath
->detach (inf
, from_tty
);
1141 /* Tell the inferior process to continue running thread PID if != -1
1142 and all threads otherwise. */
1145 aix_thread_target::resume (ptid_t ptid
, int step
, enum gdb_signal sig
)
1147 struct thread_info
*thread
;
1149 struct aix_thread_variables
*data
;
1151 data
= get_thread_data_helper_for_ptid (ptid
);
1153 if (ptid
.tid () == 0)
1155 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
1157 inferior_ptid
= ptid_t (inferior_ptid
.pid ());
1158 beneath ()->resume (ptid
, step
, sig
);
1162 thread
= current_inferior ()->find_thread (ptid
);
1164 error (_("aix-thread resume: unknown pthread %ld"),
1167 aix_thread_info
*priv
= get_aix_thread_info (thread
);
1170 if (tid
[0] == PTHDB_INVALID_TID
)
1171 error (_("aix-thread resume: no tid for pthread %ld"),
1176 ptrace64aix (PTT_CONTINUE
, tid
[0], (long long) 1,
1177 gdb_signal_to_host (sig
), (PTRACE_TYPE_ARG5
) tid
);
1179 ptrace32 (PTT_CONTINUE
, tid
[0], (addr_ptr
) 1,
1180 gdb_signal_to_host (sig
), (PTRACE_TYPE_ARG5
) tid
);
1184 /* Wait for thread/process ID if != -1 or for any thread otherwise.
1185 If an error occurs, return -1, else return the pid of the stopped
1189 aix_thread_target::wait (ptid_t ptid
, struct target_waitstatus
*status
,
1190 target_wait_flags options
)
1192 struct aix_thread_variables
*data
;
1196 ptid
= beneath ()->wait (ptid
, status
, options
);
1199 if (ptid
.pid () == -1)
1202 /* The target beneath does not deal with threads, so it should only return
1204 gdb_assert (ptid
.is_pid ());
1206 data
= get_thread_data_helper_for_ptid (ptid
);
1208 /* Check whether libpthdebug might be ready to be initialized. */
1209 if (!data
->pd_active
&& status
->kind () == TARGET_WAITKIND_STOPPED
1210 && status
->sig () == GDB_SIGNAL_TRAP
)
1212 process_stratum_target
*proc_target
1213 = current_inferior ()->process_target ();
1214 struct regcache
*regcache
= get_thread_regcache (proc_target
, ptid
);
1215 struct gdbarch
*gdbarch
= regcache
->arch ();
1217 if (regcache_read_pc (regcache
)
1218 - gdbarch_decr_pc_after_break (gdbarch
) == data
->pd_brk_addr
)
1219 return pd_activate (ptid
.pid ());
1222 return pd_update (ptid
.pid ());
1225 /* Supply AIX altivec registers, both 64 and 32 bit. */
1228 supply_altivec_regs (struct regcache
*regcache
, __vmx_context_t vmx
)
1230 ppc_gdbarch_tdep
*tdep
1231 = gdbarch_tdep
<ppc_gdbarch_tdep
> (regcache
->arch ());
1233 for (regno
= 0; regno
< ppc_num_vrs
; regno
++)
1234 regcache
->raw_supply (tdep
->ppc_vr0_regnum
+ regno
,
1235 &(vmx
.__vr
[regno
]));
1236 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
, &(vmx
.__vrsave
));
1237 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
- 1, &(vmx
.__vscr
));
1240 /* Supply AIX VSX registers, both 64 and 32 bit. */
1243 supply_vsx_regs (struct regcache
*regcache
, __vsx_context_t vsx
)
1245 ppc_gdbarch_tdep
*tdep
1246 = gdbarch_tdep
<ppc_gdbarch_tdep
> (regcache
->arch ());
1249 for (regno
= 0; regno
< ppc_num_vshrs
; regno
++)
1250 regcache
->raw_supply (tdep
->ppc_vsr0_upper_regnum
+ regno
,
1251 &(vsx
.__vsr_dw1
[regno
]));
1254 /* Record that the 64-bit general-purpose registers contain VALS. */
1257 supply_gprs64 (struct regcache
*regcache
, uint64_t *vals
)
1259 ppc_gdbarch_tdep
*tdep
1260 = gdbarch_tdep
<ppc_gdbarch_tdep
> (regcache
->arch ());
1263 for (regno
= 0; regno
< ppc_num_gprs
; regno
++)
1264 regcache
->raw_supply (tdep
->ppc_gp0_regnum
+ regno
,
1265 (char *) (vals
+ regno
));
1268 /* Record that 32-bit register REGNO contains VAL. */
1271 supply_reg32 (struct regcache
*regcache
, int regno
, uint32_t val
)
1273 regcache
->raw_supply (regno
, (char *) &val
);
1276 /* Record that the floating-point registers contain VALS. */
1279 supply_fprs (struct regcache
*regcache
, double *vals
)
1281 struct gdbarch
*gdbarch
= regcache
->arch ();
1282 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1285 /* This function should never be called on architectures without
1286 floating-point registers. */
1287 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1289 for (regno
= tdep
->ppc_fp0_regnum
;
1290 regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
;
1292 regcache
->raw_supply (regno
,
1293 (char *) (vals
+ regno
- tdep
->ppc_fp0_regnum
));
1296 /* Predicate to test whether given register number is a "special" register. */
1298 special_register_p (struct gdbarch
*gdbarch
, int regno
)
1300 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1302 return regno
== gdbarch_pc_regnum (gdbarch
)
1303 || regno
== tdep
->ppc_ps_regnum
1304 || regno
== tdep
->ppc_cr_regnum
1305 || regno
== tdep
->ppc_lr_regnum
1306 || regno
== tdep
->ppc_ctr_regnum
1307 || regno
== tdep
->ppc_xer_regnum
1308 || (tdep
->ppc_fpscr_regnum
>= 0 && regno
== tdep
->ppc_fpscr_regnum
)
1309 || (tdep
->ppc_mq_regnum
>= 0 && regno
== tdep
->ppc_mq_regnum
);
1313 /* Record that the special registers contain the specified 64-bit and
1317 supply_sprs64 (struct regcache
*regcache
,
1318 uint64_t iar
, uint64_t msr
, uint32_t cr
,
1319 uint64_t lr
, uint64_t ctr
, uint32_t xer
,
1322 struct gdbarch
*gdbarch
= regcache
->arch ();
1323 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1325 regcache
->raw_supply (gdbarch_pc_regnum (gdbarch
), (char *) &iar
);
1326 regcache
->raw_supply (tdep
->ppc_ps_regnum
, (char *) &msr
);
1327 regcache
->raw_supply (tdep
->ppc_cr_regnum
, (char *) &cr
);
1328 regcache
->raw_supply (tdep
->ppc_lr_regnum
, (char *) &lr
);
1329 regcache
->raw_supply (tdep
->ppc_ctr_regnum
, (char *) &ctr
);
1330 regcache
->raw_supply (tdep
->ppc_xer_regnum
, (char *) &xer
);
1331 if (tdep
->ppc_fpscr_regnum
>= 0)
1332 regcache
->raw_supply (tdep
->ppc_fpscr_regnum
, (char *) &fpscr
);
1335 /* Record that the special registers contain the specified 32-bit
1339 supply_sprs32 (struct regcache
*regcache
,
1340 uint32_t iar
, uint32_t msr
, uint32_t cr
,
1341 uint32_t lr
, uint32_t ctr
, uint32_t xer
,
1344 struct gdbarch
*gdbarch
= regcache
->arch ();
1345 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1347 regcache
->raw_supply (gdbarch_pc_regnum (gdbarch
), (char *) &iar
);
1348 regcache
->raw_supply (tdep
->ppc_ps_regnum
, (char *) &msr
);
1349 regcache
->raw_supply (tdep
->ppc_cr_regnum
, (char *) &cr
);
1350 regcache
->raw_supply (tdep
->ppc_lr_regnum
, (char *) &lr
);
1351 regcache
->raw_supply (tdep
->ppc_ctr_regnum
, (char *) &ctr
);
1352 regcache
->raw_supply (tdep
->ppc_xer_regnum
, (char *) &xer
);
1353 if (tdep
->ppc_fpscr_regnum
>= 0)
1354 regcache
->raw_supply (tdep
->ppc_fpscr_regnum
, (char *) &fpscr
);
1357 /* Fetch all registers from pthread PDTID, which doesn't have a kernel
1360 There's no way to query a single register from a non-kernel
1361 pthread, so there's no need for a single-register version of this
1365 fetch_regs_user_thread (struct regcache
*regcache
, pthdb_pthread_t pdtid
)
1367 struct gdbarch
*gdbarch
= regcache
->arch ();
1368 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1370 pthdb_context_t ctx
;
1371 struct aix_thread_variables
*data
;
1372 data
= get_thread_data_helper_for_ptid (inferior_ptid
);
1374 if (debug_aix_thread
)
1375 gdb_printf (gdb_stdlog
,
1376 "fetch_regs_user_thread %lx\n", (long) pdtid
);
1377 status
= pthdb_pthread_context (data
->pd_session
, pdtid
, &ctx
);
1378 if (status
!= PTHDB_SUCCESS
)
1379 error (_("aix-thread: fetch_registers: pthdb_pthread_context returned %s"),
1380 pd_status2str (status
));
1382 /* General-purpose registers. */
1385 supply_gprs64 (regcache
, ctx
.gpr
);
1387 for (i
= 0; i
< ppc_num_gprs
; i
++)
1388 supply_reg32 (regcache
, tdep
->ppc_gp0_regnum
+ i
, ctx
.gpr
[i
]);
1390 /* Floating-point registers. */
1392 if (ppc_floating_point_unit_p (gdbarch
))
1393 supply_fprs (regcache
, ctx
.fpr
);
1395 /* Special registers. */
1398 supply_sprs64 (regcache
, ctx
.iar
, ctx
.msr
, ctx
.cr
, ctx
.lr
, ctx
.ctr
,
1399 ctx
.xer
, ctx
.fpscr
);
1401 supply_sprs32 (regcache
, ctx
.iar
, ctx
.msr
, ctx
.cr
, ctx
.lr
, ctx
.ctr
,
1402 ctx
.xer
, ctx
.fpscr
);
1404 /* Altivec registers. */
1405 supply_altivec_regs (regcache
, ctx
.vmx
);
1407 /* VSX registers. */
1408 supply_vsx_regs (regcache
, ctx
.vsx
);
1411 /* Fetch register REGNO if != -1 or all registers otherwise from
1414 AIX provides a way to query all of a kernel thread's GPRs, FPRs, or
1415 SPRs, but there's no way to query individual registers within those
1416 groups. Therefore, if REGNO != -1, this function fetches an entire
1419 Unfortunately, kernel thread register queries often fail with
1420 EPERM, indicating that the thread is in kernel space. This breaks
1421 backtraces of threads other than the current one. To make that
1422 breakage obvious without throwing an error to top level (which is
1423 bad e.g. during "info threads" output), zero registers that can't
1427 fetch_regs_kernel_thread (struct regcache
*regcache
, int regno
,
1430 struct gdbarch
*gdbarch
= regcache
->arch ();
1431 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1432 uint64_t gprs64
[ppc_num_gprs
];
1433 uint32_t gprs32
[ppc_num_gprs
];
1434 double fprs
[ppc_num_fprs
];
1435 struct ptxsprs sprs64
;
1436 struct ptsprs sprs32
;
1438 struct aix_thread_variables
*data
;
1440 data
= get_thread_data_helper_for_ptid (regcache
->ptid ());
1442 if (debug_aix_thread
)
1443 gdb_printf (gdb_stdlog
,
1444 "fetch_regs_kernel_thread tid=%lx regno=%d arch64=%d\n",
1445 (long) tid
, regno
, data
->arch64
);
1447 /* General-purpose registers. */
1449 || (tdep
->ppc_gp0_regnum
<= regno
1450 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
))
1454 if (!ptrace64aix (PTT_READ_GPRS
, tid
,
1455 (unsigned long) gprs64
, 0, NULL
))
1456 memset (gprs64
, 0, sizeof (gprs64
));
1457 supply_gprs64 (regcache
, gprs64
);
1461 if (!ptrace32 (PTT_READ_GPRS
, tid
, (uintptr_t) gprs32
, 0, NULL
))
1462 memset (gprs32
, 0, sizeof (gprs32
));
1463 for (i
= 0; i
< ppc_num_gprs
; i
++)
1464 supply_reg32 (regcache
, tdep
->ppc_gp0_regnum
+ i
, gprs32
[i
]);
1468 /* vector registers. */
1469 if (tdep
->ppc_vr0_regnum
!= -1)
1472 __vmx_context_t vmx
;
1474 ret
= ptrace64aix (PTT_READ_VEC
, tid
, (long long) &vmx
, 0, 0);
1476 ret
= ptrace32 (PTT_READ_VEC
, tid
, (uintptr_t) &vmx
, 0, 0);
1478 memset(&vmx
, 0, sizeof(__vmx_context_t
));
1479 for (i
= 0; i
< ppc_num_vrs
; i
++)
1480 regcache
->raw_supply (tdep
->ppc_vr0_regnum
+ i
, &(vmx
.__vr
[i
]));
1481 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
, &(vmx
.__vrsave
));
1482 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
- 1, &(vmx
.__vscr
));
1485 /* vsx registers. */
1486 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
1488 __vsx_context_t vsx
;
1491 ret
= ptrace64aix (PTT_READ_VSX
, tid
, (long long) &vsx
, 0, 0);
1493 ret
= ptrace32 (PTT_READ_VSX
, tid
, (long long) &vsx
, 0, 0);
1495 memset(&vsx
, 0, sizeof(__vsx_context_t
));
1496 for (i
= 0; i
< ppc_num_vshrs
; i
++)
1497 regcache
->raw_supply (tdep
->ppc_vsr0_upper_regnum
+ i
, &(vsx
.__vsr_dw1
[i
]));
1500 /* Floating-point registers. */
1502 if (ppc_floating_point_unit_p (gdbarch
)
1504 || (regno
>= tdep
->ppc_fp0_regnum
1505 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)))
1507 if (!ptrace32 (PTT_READ_FPRS
, tid
, (uintptr_t) fprs
, 0, NULL
))
1508 memset (fprs
, 0, sizeof (fprs
));
1509 supply_fprs (regcache
, fprs
);
1512 /* Special-purpose registers. */
1514 if (regno
== -1 || special_register_p (gdbarch
, regno
))
1518 if (!ptrace64aix (PTT_READ_SPRS
, tid
,
1519 (unsigned long) &sprs64
, 0, NULL
))
1520 memset (&sprs64
, 0, sizeof (sprs64
));
1521 supply_sprs64 (regcache
, sprs64
.pt_iar
, sprs64
.pt_msr
,
1522 sprs64
.pt_cr
, sprs64
.pt_lr
, sprs64
.pt_ctr
,
1523 sprs64
.pt_xer
, sprs64
.pt_fpscr
);
1527 if (!ptrace32 (PTT_READ_SPRS
, tid
, (uintptr_t) &sprs32
, 0, NULL
))
1528 memset (&sprs32
, 0, sizeof (sprs32
));
1529 supply_sprs32 (regcache
, sprs32
.pt_iar
, sprs32
.pt_msr
, sprs32
.pt_cr
,
1530 sprs32
.pt_lr
, sprs32
.pt_ctr
, sprs32
.pt_xer
,
1533 if (tdep
->ppc_mq_regnum
>= 0)
1534 regcache
->raw_supply (tdep
->ppc_mq_regnum
, (char *) &sprs32
.pt_mq
);
1539 /* Fetch register REGNO if != -1 or all registers otherwise from the
1540 thread/process connected to REGCACHE. */
1543 aix_thread_target::fetch_registers (struct regcache
*regcache
, int regno
)
1545 struct thread_info
*thread
;
1548 /* If a new inferior is born, then its pthread debug library is yet to
1549 initialised and hence has no private data. So the below if condition
1552 if (regcache
->ptid ().tid () == 0)
1553 beneath ()->fetch_registers (regcache
, regno
);
1556 thread
= current_inferior ()->find_thread (regcache
->ptid ());
1557 aix_thread_info
*priv
= get_aix_thread_info (thread
);
1560 if (tid
== PTHDB_INVALID_TID
)
1561 fetch_regs_user_thread (regcache
, priv
->pdtid
);
1563 fetch_regs_kernel_thread (regcache
, regno
, tid
);
1567 /* Fill altivec registers. */
1570 fill_altivec (const struct regcache
*regcache
, __vmx_context_t
*vmx
)
1572 struct gdbarch
*gdbarch
= regcache
->arch ();
1573 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1576 for (regno
= 0; regno
< ppc_num_vrs
; regno
++)
1577 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_vr0_regnum
+ regno
))
1578 regcache
->raw_collect (tdep
->ppc_vr0_regnum
+ regno
,
1579 &(vmx
->__vr
[regno
]));
1581 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_vrsave_regnum
))
1582 regcache
->raw_collect (tdep
->ppc_vrsave_regnum
, &(vmx
->__vrsave
));
1583 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_vrsave_regnum
- 1))
1584 regcache
->raw_collect (tdep
->ppc_vrsave_regnum
- 1, &(vmx
->__vscr
));
1587 /* Fill vsx registers. */
1590 fill_vsx (const struct regcache
*regcache
, __vsx_context_t
*vsx
)
1592 struct gdbarch
*gdbarch
= regcache
->arch ();
1593 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1596 for (regno
= 0; regno
< ppc_num_vshrs
; regno
++)
1597 if (REG_VALID
== regcache
->get_register_status ( tdep
->ppc_vsr0_upper_regnum
+ regno
))
1598 regcache
->raw_collect (tdep
->ppc_vsr0_upper_regnum
+ regno
,
1599 &(vsx
->__vsr_dw1
[0]) + regno
);
1602 /* Store the gp registers into an array of uint32_t or uint64_t. */
1605 fill_gprs64 (const struct regcache
*regcache
, uint64_t *vals
)
1607 ppc_gdbarch_tdep
*tdep
1608 = gdbarch_tdep
<ppc_gdbarch_tdep
> (regcache
->arch ());
1611 for (regno
= 0; regno
< ppc_num_gprs
; regno
++)
1612 if (REG_VALID
== regcache
->get_register_status
1613 (tdep
->ppc_gp0_regnum
+ regno
))
1614 regcache
->raw_collect (tdep
->ppc_gp0_regnum
+ regno
, vals
+ regno
);
1618 fill_gprs32 (const struct regcache
*regcache
, uint32_t *vals
)
1620 ppc_gdbarch_tdep
*tdep
1621 = gdbarch_tdep
<ppc_gdbarch_tdep
> (regcache
->arch ());
1624 for (regno
= 0; regno
< ppc_num_gprs
; regno
++)
1625 if (REG_VALID
== regcache
->get_register_status
1626 (tdep
->ppc_gp0_regnum
+ regno
))
1627 regcache
->raw_collect (tdep
->ppc_gp0_regnum
+ regno
, vals
+ regno
);
1630 /* Store the floating point registers into a double array. */
1632 fill_fprs (const struct regcache
*regcache
, double *vals
)
1634 struct gdbarch
*gdbarch
= regcache
->arch ();
1635 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1638 /* This function should never be called on architectures without
1639 floating-point registers. */
1640 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
1642 for (regno
= tdep
->ppc_fp0_regnum
;
1643 regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
;
1645 if (REG_VALID
== regcache
->get_register_status (regno
))
1646 regcache
->raw_collect (regno
, vals
+ regno
- tdep
->ppc_fp0_regnum
);
1649 /* Store the special registers into the specified 64-bit and 32-bit
1653 fill_sprs64 (const struct regcache
*regcache
,
1654 uint64_t *iar
, uint64_t *msr
, uint32_t *cr
,
1655 uint64_t *lr
, uint64_t *ctr
, uint32_t *xer
,
1658 struct gdbarch
*gdbarch
= regcache
->arch ();
1659 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1661 /* Verify that the size of the size of the IAR buffer is the
1662 same as the raw size of the PC (in the register cache). If
1663 they're not, then either GDB has been built incorrectly, or
1664 there's some other kind of internal error. To be really safe,
1665 we should check all of the sizes. */
1666 gdb_assert (sizeof (*iar
) == register_size
1667 (gdbarch
, gdbarch_pc_regnum (gdbarch
)));
1669 if (REG_VALID
== regcache
->get_register_status (gdbarch_pc_regnum (gdbarch
)))
1670 regcache
->raw_collect (gdbarch_pc_regnum (gdbarch
), iar
);
1671 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_ps_regnum
))
1672 regcache
->raw_collect (tdep
->ppc_ps_regnum
, msr
);
1673 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_cr_regnum
))
1674 regcache
->raw_collect (tdep
->ppc_cr_regnum
, cr
);
1675 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_lr_regnum
))
1676 regcache
->raw_collect (tdep
->ppc_lr_regnum
, lr
);
1677 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_ctr_regnum
))
1678 regcache
->raw_collect (tdep
->ppc_ctr_regnum
, ctr
);
1679 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_xer_regnum
))
1680 regcache
->raw_collect (tdep
->ppc_xer_regnum
, xer
);
1681 if (tdep
->ppc_fpscr_regnum
>= 0
1682 && REG_VALID
== regcache
->get_register_status (tdep
->ppc_fpscr_regnum
))
1683 regcache
->raw_collect (tdep
->ppc_fpscr_regnum
, fpscr
);
1687 fill_sprs32 (const struct regcache
*regcache
,
1688 uint32_t *iar
, uint32_t *msr
, uint32_t *cr
,
1689 uint32_t *lr
, uint32_t *ctr
, uint32_t *xer
,
1692 struct gdbarch
*gdbarch
= regcache
->arch ();
1693 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1695 /* Verify that the size of the size of the IAR buffer is the
1696 same as the raw size of the PC (in the register cache). If
1697 they're not, then either GDB has been built incorrectly, or
1698 there's some other kind of internal error. To be really safe,
1699 we should check all of the sizes. */
1700 gdb_assert (sizeof (*iar
) == register_size (gdbarch
,
1701 gdbarch_pc_regnum (gdbarch
)));
1703 if (REG_VALID
== regcache
->get_register_status (gdbarch_pc_regnum (gdbarch
)))
1704 regcache
->raw_collect (gdbarch_pc_regnum (gdbarch
), iar
);
1705 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_ps_regnum
))
1706 regcache
->raw_collect (tdep
->ppc_ps_regnum
, msr
);
1707 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_cr_regnum
))
1708 regcache
->raw_collect (tdep
->ppc_cr_regnum
, cr
);
1709 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_lr_regnum
))
1710 regcache
->raw_collect (tdep
->ppc_lr_regnum
, lr
);
1711 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_ctr_regnum
))
1712 regcache
->raw_collect (tdep
->ppc_ctr_regnum
, ctr
);
1713 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_xer_regnum
))
1714 regcache
->raw_collect (tdep
->ppc_xer_regnum
, xer
);
1715 if (tdep
->ppc_fpscr_regnum
>= 0
1716 && REG_VALID
== regcache
->get_register_status (tdep
->ppc_fpscr_regnum
))
1717 regcache
->raw_collect (tdep
->ppc_fpscr_regnum
, fpscr
);
1720 /* Store all registers into pthread PDTID, which doesn't have a kernel
1723 It's possible to store a single register into a non-kernel pthread,
1724 but I doubt it's worth the effort. */
1727 store_regs_user_thread (const struct regcache
*regcache
, pthdb_pthread_t pdtid
)
1729 struct gdbarch
*gdbarch
= regcache
->arch ();
1730 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1732 pthdb_context_t ctx
;
1735 struct aix_thread_variables
*data
;
1736 data
= get_thread_data_helper_for_ptid (inferior_ptid
);
1738 __vmx_context_t vmx
;
1739 __vsx_context_t vsx
;
1741 if (debug_aix_thread
)
1742 gdb_printf (gdb_stdlog
,
1743 "store_regs_user_thread %lx\n", (long) pdtid
);
1745 /* Retrieve the thread's current context for its non-register
1747 status
= pthdb_pthread_context (data
->pd_session
, pdtid
, &ctx
);
1748 if (status
!= PTHDB_SUCCESS
)
1749 error (_("aix-thread: store_registers: pthdb_pthread_context returned %s"),
1750 pd_status2str (status
));
1752 /* Fill altivec-registers. */
1756 memset(&vmx
, 0, sizeof(__vmx_context_t
));
1757 for (i
= 0; i
< ppc_num_vrs
; i
++)
1758 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_vr0_regnum
+ i
))
1760 regcache
->raw_collect (tdep
->ppc_vr0_regnum
+ i
,
1762 ctx
.vmx
.__vr
[i
] = vmx
.__vr
[i
];
1764 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_vrsave_regnum
))
1765 ctx
.vmx
.__vrsave
= vmx
.__vrsave
;
1766 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_vrsave_regnum
- 1))
1767 ctx
.vmx
.__vscr
= vmx
.__vscr
;
1770 /* Fill vsx registers. */
1774 memset(&vsx
, 0, sizeof(__vsx_context_t
));
1775 for (i
= 0; i
< ppc_num_vshrs
; i
++)
1776 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_vsr0_regnum
+ i
))
1778 regcache
->raw_collect (tdep
->ppc_vr0_regnum
+ i
,
1779 &(vsx
.__vsr_dw1
[i
]));
1780 ctx
.vsx
.__vsr_dw1
[i
] = vsx
.__vsr_dw1
[i
];
1784 /* Collect general-purpose register values from the regcache. */
1786 for (i
= 0; i
< ppc_num_gprs
; i
++)
1787 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_gp0_regnum
+ i
))
1791 regcache
->raw_collect (tdep
->ppc_gp0_regnum
+ i
, (void *) &int64
);
1796 regcache
->raw_collect (tdep
->ppc_gp0_regnum
+ i
, (void *) &int32
);
1801 /* Collect floating-point register values from the regcache. */
1802 if (ppc_floating_point_unit_p (gdbarch
))
1803 fill_fprs (regcache
, ctx
.fpr
);
1805 /* Special registers (always kept in ctx as 64 bits). */
1808 fill_sprs64 (regcache
, &ctx
.iar
, &ctx
.msr
, &ctx
.cr
, &ctx
.lr
, &ctx
.ctr
,
1809 &ctx
.xer
, &ctx
.fpscr
);
1813 /* Problem: ctx.iar etc. are 64 bits, but raw_registers are 32.
1814 Solution: use 32-bit temp variables. */
1815 uint32_t tmp_iar
, tmp_msr
, tmp_cr
, tmp_lr
, tmp_ctr
, tmp_xer
,
1818 fill_sprs32 (regcache
, &tmp_iar
, &tmp_msr
, &tmp_cr
, &tmp_lr
, &tmp_ctr
,
1819 &tmp_xer
, &tmp_fpscr
);
1820 if (REG_VALID
== regcache
->get_register_status
1821 (gdbarch_pc_regnum (gdbarch
)))
1823 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_ps_regnum
))
1825 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_cr_regnum
))
1827 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_lr_regnum
))
1829 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_ctr_regnum
))
1831 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_xer_regnum
))
1833 if (REG_VALID
== regcache
->get_register_status (tdep
->ppc_xer_regnum
))
1834 ctx
.fpscr
= tmp_fpscr
;
1837 status
= pthdb_pthread_setcontext (data
->pd_session
, pdtid
, &ctx
);
1838 if (status
!= PTHDB_SUCCESS
)
1839 error (_("aix-thread: store_registers: "
1840 "pthdb_pthread_setcontext returned %s"),
1841 pd_status2str (status
));
1844 /* Store register REGNO if != -1 or all registers otherwise into
1847 AIX provides a way to set all of a kernel thread's GPRs, FPRs, or
1848 SPRs, but there's no way to set individual registers within those
1849 groups. Therefore, if REGNO != -1, this function stores an entire
1853 store_regs_kernel_thread (const struct regcache
*regcache
, int regno
,
1856 struct gdbarch
*gdbarch
= regcache
->arch ();
1857 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
1858 uint64_t gprs64
[ppc_num_gprs
];
1859 uint32_t gprs32
[ppc_num_gprs
];
1860 double fprs
[ppc_num_fprs
];
1861 struct ptxsprs sprs64
;
1862 struct ptsprs sprs32
;
1863 struct aix_thread_variables
*data
;
1866 data
= get_thread_data_helper_for_ptid (regcache
->ptid ());
1868 if (debug_aix_thread
)
1869 gdb_printf (gdb_stdlog
,
1870 "store_regs_kernel_thread tid=%lx regno=%d\n",
1873 /* General-purpose registers. */
1875 || (tdep
->ppc_gp0_regnum
<= regno
1876 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_fprs
))
1880 /* Pre-fetch: some regs may not be in the cache. */
1881 ptrace64aix (PTT_READ_GPRS
, tid
, (unsigned long) gprs64
, 0, NULL
);
1882 fill_gprs64 (regcache
, gprs64
);
1883 ptrace64aix (PTT_WRITE_GPRS
, tid
, (unsigned long) gprs64
, 0, NULL
);
1887 /* Pre-fetch: some regs may not be in the cache. */
1888 ptrace32 (PTT_READ_GPRS
, tid
, (uintptr_t) gprs32
, 0, NULL
);
1889 fill_gprs32 (regcache
, gprs32
);
1890 ptrace32 (PTT_WRITE_GPRS
, tid
, (uintptr_t) gprs32
, 0, NULL
);
1894 /* Floating-point registers. */
1896 if (ppc_floating_point_unit_p (gdbarch
)
1898 || (regno
>= tdep
->ppc_fp0_regnum
1899 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)))
1901 /* Pre-fetch: some regs may not be in the cache. */
1902 ptrace32 (PTT_READ_FPRS
, tid
, (uintptr_t) fprs
, 0, NULL
);
1903 fill_fprs (regcache
, fprs
);
1904 ptrace32 (PTT_WRITE_FPRS
, tid
, (uintptr_t) fprs
, 0, NULL
);
1907 /* Special-purpose registers. */
1909 if (regno
== -1 || special_register_p (gdbarch
, regno
))
1913 /* Pre-fetch: some registers won't be in the cache. */
1914 ptrace64aix (PTT_READ_SPRS
, tid
,
1915 (unsigned long) &sprs64
, 0, NULL
);
1916 fill_sprs64 (regcache
, &sprs64
.pt_iar
, &sprs64
.pt_msr
,
1917 &sprs64
.pt_cr
, &sprs64
.pt_lr
, &sprs64
.pt_ctr
,
1918 &sprs64
.pt_xer
, &sprs64
.pt_fpscr
);
1919 ptrace64aix (PTT_WRITE_SPRS
, tid
,
1920 (unsigned long) &sprs64
, 0, NULL
);
1924 /* The contents of "struct ptspr" were declared as "unsigned
1925 long" up to AIX 5.2, but are "unsigned int" since 5.3.
1926 Use temporaries to work around this problem. Also, add an
1927 assert here to make sure we fail if the system header files
1928 use "unsigned long", and the size of that type is not what
1929 the headers expect. */
1930 uint32_t tmp_iar
, tmp_msr
, tmp_cr
, tmp_lr
, tmp_ctr
, tmp_xer
,
1933 gdb_assert (sizeof (sprs32
.pt_iar
) == 4);
1935 /* Pre-fetch: some registers won't be in the cache. */
1936 ptrace32 (PTT_READ_SPRS
, tid
, (uintptr_t) &sprs32
, 0, NULL
);
1938 fill_sprs32 (regcache
, &tmp_iar
, &tmp_msr
, &tmp_cr
, &tmp_lr
,
1939 &tmp_ctr
, &tmp_xer
, &tmp_fpscr
);
1941 sprs32
.pt_iar
= tmp_iar
;
1942 sprs32
.pt_msr
= tmp_msr
;
1943 sprs32
.pt_cr
= tmp_cr
;
1944 sprs32
.pt_lr
= tmp_lr
;
1945 sprs32
.pt_ctr
= tmp_ctr
;
1946 sprs32
.pt_xer
= tmp_xer
;
1947 sprs32
.pt_fpscr
= tmp_fpscr
;
1949 if (tdep
->ppc_mq_regnum
>= 0)
1950 if (REG_VALID
== regcache
->get_register_status
1951 (tdep
->ppc_mq_regnum
))
1952 regcache
->raw_collect (tdep
->ppc_mq_regnum
, &sprs32
.pt_mq
);
1954 ptrace32 (PTT_WRITE_SPRS
, tid
, (uintptr_t) &sprs32
, 0, NULL
);
1958 /* Vector registers. */
1959 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1
1960 && (regno
== -1 || (regno
>= tdep
->ppc_vr0_regnum
1961 && regno
<= tdep
->ppc_vrsave_regnum
)))
1963 __vmx_context_t vmx
;
1967 ret
= ptrace64aix (PTT_READ_VEC
, tid
, (long long) &vmx
, 0, 0);
1969 ret
= ptrace32 (PTT_READ_VEC
, tid
, (long long) &vmx
, 0, 0);
1972 fill_altivec(regcache
, &vmx
);
1974 ret
= ptrace64aix (PTT_WRITE_VEC
, tid
, (long long) &vmx
, 0, 0);
1976 ret
= ptrace32 (PTT_WRITE_VEC
, tid
, (long long) &vmx
, 0, 0);
1978 perror_with_name (_("Unable to store AltiVec register after read"));
1983 /* VSX registers. */
1984 if (tdep
->ppc_vsr0_upper_regnum
!= -1 && (regno
== -1
1985 || (regno
>=tdep
->ppc_vsr0_upper_regnum
1986 && regno
< tdep
->ppc_vsr0_upper_regnum
+ ppc_num_vshrs
)))
1988 __vsx_context_t vsx
;
1992 ret
= ptrace64aix (PTT_READ_VSX
, tid
, (long long) &vsx
, 0, 0);
1994 ret
= ptrace32 (PTT_READ_VSX
, tid
, (long long) &vsx
, 0, 0);
1997 fill_vsx (regcache
, &vsx
);
1999 ret
= ptrace64aix (PTT_WRITE_VSX
, tid
, (long long) &vsx
, 0, 0);
2001 ret
= ptrace32 (PTT_WRITE_VSX
, tid
, (long long) &vsx
, 0, 0);
2003 perror_with_name (_("Unable to store VSX register after read"));
2009 /* Store gdb's current view of the register set into the
2010 thread/process connected to REGCACHE. */
2013 aix_thread_target::store_registers (struct regcache
*regcache
, int regno
)
2015 struct thread_info
*thread
;
2018 if (regcache
->ptid ().tid () == 0)
2019 beneath ()->store_registers (regcache
, regno
);
2022 thread
= current_inferior ()->find_thread (regcache
->ptid ());
2023 aix_thread_info
*priv
= get_aix_thread_info (thread
);
2026 if (tid
== PTHDB_INVALID_TID
)
2027 store_regs_user_thread (regcache
, priv
->pdtid
);
2029 store_regs_kernel_thread (regcache
, regno
, tid
);
2033 /* Implement the to_xfer_partial target_ops method. */
2035 enum target_xfer_status
2036 aix_thread_target::xfer_partial (enum target_object object
,
2037 const char *annex
, gdb_byte
*readbuf
,
2038 const gdb_byte
*writebuf
,
2039 ULONGEST offset
, ULONGEST len
,
2040 ULONGEST
*xfered_len
)
2042 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
2044 inferior_ptid
= ptid_t (inferior_ptid
.pid ());
2045 return beneath ()->xfer_partial (object
, annex
, readbuf
,
2046 writebuf
, offset
, len
, xfered_len
);
2049 /* Clean up after the inferior exits. */
2052 aix_thread_target::mourn_inferior ()
2054 target_ops
*beneath
= this->beneath ();
2056 pd_disable (current_inferior ());
2057 beneath
->mourn_inferior ();
2060 /* Return whether thread PID is still valid. */
2063 aix_thread_target::thread_alive (ptid_t ptid
)
2065 if (ptid
.tid () == 0)
2066 return beneath ()->thread_alive (ptid
);
2068 /* We update the thread list every time the child stops, so all
2069 valid threads should be in the thread list. */
2070 process_stratum_target
*proc_target
2071 = current_inferior ()->process_target ();
2072 return in_thread_list (proc_target
, ptid
);
2075 /* Return a printable representation of composite PID for use in
2076 "info threads" output. */
2079 aix_thread_target::pid_to_str (ptid_t ptid
)
2081 if (ptid
.tid () == 0)
2082 return beneath ()->pid_to_str (ptid
);
2084 return string_printf (_("Thread %s"), pulongest (ptid
.tid ()));
2087 /* Return a printable representation of extra information about
2088 THREAD, for use in "info threads" output. */
2091 aix_thread_target::extra_thread_info (struct thread_info
*thread
)
2094 pthdb_pthread_t pdtid
;
2096 pthdb_state_t state
;
2097 pthdb_suspendstate_t suspendstate
;
2098 pthdb_detachstate_t detachstate
;
2100 static char *ret
= NULL
;
2101 struct aix_thread_variables
*data
;
2103 data
= get_thread_data_helper_for_ptid (thread
->ptid
);
2105 if (thread
->ptid
.tid () == 0)
2109 aix_thread_info
*priv
= get_aix_thread_info (thread
);
2111 pdtid
= priv
->pdtid
;
2114 if (tid
!= PTHDB_INVALID_TID
)
2115 /* i18n: Like "thread-identifier %d, [state] running, suspended" */
2116 buf
.printf (_("tid %d"), (int)tid
);
2118 status
= pthdb_pthread_state (data
->pd_session
, pdtid
, &state
);
2119 if (status
!= PTHDB_SUCCESS
)
2121 buf
.printf (", %s", state2str (state
));
2123 status
= pthdb_pthread_suspendstate (data
->pd_session
, pdtid
,
2125 if (status
== PTHDB_SUCCESS
&& suspendstate
== PSS_SUSPENDED
)
2126 /* i18n: Like "Thread-Id %d, [state] running, suspended" */
2127 buf
.printf (_(", suspended"));
2129 status
= pthdb_pthread_detachstate (data
->pd_session
, pdtid
,
2131 if (status
== PTHDB_SUCCESS
&& detachstate
== PDS_DETACHED
)
2132 /* i18n: Like "Thread-Id %d, [state] running, detached" */
2133 buf
.printf (_(", detached"));
2135 pthdb_pthread_cancelpend (data
->pd_session
, pdtid
, &cancelpend
);
2136 if (status
== PTHDB_SUCCESS
&& cancelpend
)
2137 /* i18n: Like "Thread-Id %d, [state] running, cancel pending" */
2138 buf
.printf (_(", cancel pending"));
2142 xfree (ret
); /* Free old buffer. */
2144 ret
= xstrdup (buf
.c_str ());
2150 aix_thread_target::get_ada_task_ptid (long lwp
, ULONGEST thread
)
2152 return ptid_t (inferior_ptid
.pid (), 0, thread
);
2156 /* Module startup initialization function, automagically called by
2159 void _initialize_aix_thread ();
2161 _initialize_aix_thread ()
2163 /* Notice when object files get loaded and unloaded. */
2164 gdb::observers::new_objfile
.attach (new_objfile
, "aix-thread");
2166 /* Add ourselves to inferior_created event chain.
2167 This is needed to enable the thread target on "attach". */
2168 gdb::observers::inferior_created
.attach (aix_thread_inferior_created
,
2171 add_setshow_boolean_cmd ("aix-thread", class_maintenance
, &debug_aix_thread
,
2172 _("Set debugging of AIX thread module."),
2173 _("Show debugging of AIX thread module."),
2174 _("Enables debugging output (used to debug GDB)."),
2176 /* FIXME: i18n: Debugging of AIX thread
2177 module is \"%d\". */
2178 &setdebuglist
, &showdebuglist
);