1 /* Low level interface for debugging AIX 4.3+ pthreads.
3 Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
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 2 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, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 /* This module uses the libpthdebug.a library provided by AIX 4.3+ for
25 debugging pthread applications.
27 Some name prefix conventions:
28 pthdb_ provided by libpthdebug.a
29 pdc_ callbacks that this module provides to libpthdebug.a
30 pd_ variables or functions interfacing with libpthdebug.a
32 libpthdebug peculiarities:
34 - pthdb_ptid_pthread() is prototyped in <sys/pthdebug.h>, but
35 it's not documented, and after several calls it stops working
36 and causes other libpthdebug functions to fail.
38 - pthdb_tid_pthread() doesn't always work after
39 pthdb_session_update(), but it does work after cycling through
40 all threads using pthdb_pthread().
45 #include "gdb_assert.h"
46 #include "gdbthread.h"
51 #include "language.h" /* for local_hex_string() */
55 #include <sys/types.h>
56 #include <sys/ptrace.h>
59 #include <sys/pthdebug.h>
61 /* Whether to emit debugging output. */
62 static int debug_aix_thread;
64 /* In AIX 5.1, functions use pthdb_tid_t instead of tid_t. */
65 #ifndef PTHDB_VERSION_3
66 #define pthdb_tid_t tid_t
69 /* Return whether to treat PID as a debuggable thread id. */
71 #define PD_TID(ptid) (pd_active && ptid_get_tid (ptid) != 0)
73 /* Build a thread ptid. */
74 #define BUILD_THREAD(TID, PID) ptid_build (PID, 0, TID)
76 /* Build and lwp ptid. */
77 #define BUILD_LWP(LWP, PID) MERGEPID (PID, LWP)
79 /* pthdb_user_t value that we pass to pthdb functions. 0 causes
80 PTHDB_BAD_USER errors, so use 1. */
84 /* Success and failure values returned by pthdb callbacks. */
86 #define PDC_SUCCESS PTHDB_SUCCESS
87 #define PDC_FAILURE PTHDB_CALLBACK
89 /* Private data attached to each element in GDB's thread list. */
91 struct private_thread_info {
92 pthdb_pthread_t pdtid; /* thread's libpthdebug id */
93 pthdb_tid_t tid; /* kernel thread id */
96 /* Information about a thread of which libpthdebug is aware. */
99 pthdb_pthread_t pdtid;
104 /* This module's target-specific operations, active while pd_able is true. */
106 static struct target_ops aix_thread_ops;
108 /* Copy of the target over which ops is pushed.
109 This is more convenient than a pointer to child_ops or core_ops,
110 because they lack current_target's default callbacks. */
112 static struct target_ops base_target;
114 /* Address of the function that libpthread will call when libpthdebug
115 is ready to be initialized. */
117 static CORE_ADDR pd_brk_addr;
119 /* Whether the current application is debuggable by pthdb. */
121 static int pd_able = 0;
123 /* Whether a threaded application is being debugged. */
125 static int pd_active = 0;
127 /* Whether the current architecture is 64-bit.
128 Only valid when pd_able is true. */
132 /* Saved pointer to previous owner of target_new_objfile_hook. */
134 static void (*target_new_objfile_chain)(struct objfile *);
136 /* Forward declarations for pthdb callbacks. */
138 static int pdc_symbol_addrs (pthdb_user_t, pthdb_symbol_t *, int);
139 static int pdc_read_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
140 static int pdc_write_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
141 static int pdc_read_regs (pthdb_user_t user, pthdb_tid_t tid,
142 unsigned long long flags,
143 pthdb_context_t *context);
144 static int pdc_write_regs (pthdb_user_t user, pthdb_tid_t tid,
145 unsigned long long flags,
146 pthdb_context_t *context);
147 static int pdc_alloc (pthdb_user_t, size_t, void **);
148 static int pdc_realloc (pthdb_user_t, void *, size_t, void **);
149 static int pdc_dealloc (pthdb_user_t, void *);
151 /* pthdb callbacks. */
153 static pthdb_callbacks_t pd_callbacks = {
165 /* Current pthdb session. */
167 static pthdb_session_t pd_session;
169 /* Return a printable representation of pthdebug function return
173 pd_status2str (int status)
177 case PTHDB_SUCCESS: return "SUCCESS";
178 case PTHDB_NOSYS: return "NOSYS";
179 case PTHDB_NOTSUP: return "NOTSUP";
180 case PTHDB_BAD_VERSION: return "BAD_VERSION";
181 case PTHDB_BAD_USER: return "BAD_USER";
182 case PTHDB_BAD_SESSION: return "BAD_SESSION";
183 case PTHDB_BAD_MODE: return "BAD_MODE";
184 case PTHDB_BAD_FLAGS: return "BAD_FLAGS";
185 case PTHDB_BAD_CALLBACK: return "BAD_CALLBACK";
186 case PTHDB_BAD_POINTER: return "BAD_POINTER";
187 case PTHDB_BAD_CMD: return "BAD_CMD";
188 case PTHDB_BAD_PTHREAD: return "BAD_PTHREAD";
189 case PTHDB_BAD_ATTR: return "BAD_ATTR";
190 case PTHDB_BAD_MUTEX: return "BAD_MUTEX";
191 case PTHDB_BAD_MUTEXATTR: return "BAD_MUTEXATTR";
192 case PTHDB_BAD_COND: return "BAD_COND";
193 case PTHDB_BAD_CONDATTR: return "BAD_CONDATTR";
194 case PTHDB_BAD_RWLOCK: return "BAD_RWLOCK";
195 case PTHDB_BAD_RWLOCKATTR: return "BAD_RWLOCKATTR";
196 case PTHDB_BAD_KEY: return "BAD_KEY";
197 case PTHDB_BAD_PTID: return "BAD_PTID";
198 case PTHDB_BAD_TID: return "BAD_TID";
199 case PTHDB_CALLBACK: return "CALLBACK";
200 case PTHDB_CONTEXT: return "CONTEXT";
201 case PTHDB_HELD: return "HELD";
202 case PTHDB_NOT_HELD: return "NOT_HELD";
203 case PTHDB_MEMORY: return "MEMORY";
204 case PTHDB_NOT_PTHREADED: return "NOT_PTHREADED";
205 case PTHDB_SYMBOL: return "SYMBOL";
206 case PTHDB_NOT_AVAIL: return "NOT_AVAIL";
207 case PTHDB_INTERNAL: return "INTERNAL";
208 default: return "UNKNOWN";
212 /* A call to ptrace(REQ, ID, ...) just returned RET. Check for
213 exceptional conditions and either return nonlocally or else return
214 1 for success and 0 for failure. */
217 ptrace_check (int req, int id, int ret)
219 if (ret == 0 && !errno)
222 /* According to ptrace(2), ptrace may fail with EPERM if "the
223 Identifier parameter corresponds to a kernel thread which is
224 stopped in kernel mode and whose computational state cannot be
225 read or written." This happens quite often with register reads. */
232 if (ret == -1 && errno == EPERM)
234 if (debug_aix_thread)
235 fprintf_unfiltered (gdb_stdlog,
236 "ptrace (%d, %d) = %d (errno = %d)\n",
237 req, id, ret, errno);
238 return ret == -1 ? 0 : 1;
242 error ("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)",
243 req, id, ret, errno, safe_strerror (errno));
244 return 0; /* Not reached. */
247 /* Call ptracex (REQ, ID, ADDR, DATA, BUF). Return success. */
250 ptrace64aix (int req, int id, long long addr, int data, int *buf)
253 return ptrace_check (req, id, ptracex (req, id, addr, data, buf));
256 /* Call ptrace (REQ, ID, ADDR, DATA, BUF). Return success. */
259 ptrace32 (int req, int id, int *addr, int data, int *buf)
262 return ptrace_check (req, id,
263 ptrace (req, id, (int *) addr, data, buf));
266 /* If *PIDP is a composite process/thread id, convert it to a
270 pid_to_prc (ptid_t *ptidp)
276 *ptidp = pid_to_ptid (PIDGET (ptid));
279 /* pthdb callback: for <i> from 0 to COUNT, set SYMBOLS[<i>].addr to
280 the address of SYMBOLS[<i>].name. */
283 pdc_symbol_addrs (pthdb_user_t user, pthdb_symbol_t *symbols, int count)
285 struct minimal_symbol *ms;
289 if (debug_aix_thread)
290 fprintf_unfiltered (gdb_stdlog,
291 "pdc_symbol_addrs (user = %ld, symbols = 0x%lx, count = %d)\n",
292 user, (long) symbols, count);
294 for (i = 0; i < count; i++)
296 name = symbols[i].name;
297 if (debug_aix_thread)
298 fprintf_unfiltered (gdb_stdlog,
299 " symbols[%d].name = \"%s\"\n", i, name);
305 if (!(ms = lookup_minimal_symbol (name, NULL, NULL)))
307 if (debug_aix_thread)
308 fprintf_unfiltered (gdb_stdlog, " returning PDC_FAILURE\n");
311 symbols[i].addr = SYMBOL_VALUE_ADDRESS (ms);
313 if (debug_aix_thread)
314 fprintf_unfiltered (gdb_stdlog, " symbols[%d].addr = %s\n",
315 i, local_hex_string (symbols[i].addr));
317 if (debug_aix_thread)
318 fprintf_unfiltered (gdb_stdlog, " returning PDC_SUCCESS\n");
322 /* Read registers call back function should be able to read the
323 context information of a debuggee kernel thread from an active
324 process or from a core file. The information should be formatted
325 in context64 form for both 32-bit and 64-bit process.
326 If successful return 0, else non-zero is returned. */
329 pdc_read_regs (pthdb_user_t user,
331 unsigned long long flags,
332 pthdb_context_t *context)
334 /* This function doesn't appear to be used, so we could probably
335 just return 0 here. HOWEVER, if it is not defined, the OS will
336 complain and several thread debug functions will fail. In case
337 this is needed, I have implemented what I think it should do,
338 however this code is untested. */
343 struct ptxsprs sprs64;
344 struct ptsprs sprs32;
346 if (debug_aix_thread)
347 fprintf_unfiltered (gdb_stdlog, "pdc_read_regs tid=%d flags=%s\n",
348 (int) tid, local_hex_string (flags));
350 /* General-purpose registers. */
351 if (flags & PTHDB_FLAG_GPRS)
355 if (!ptrace64aix (PTT_READ_GPRS, tid,
356 (unsigned long) gprs64, 0, NULL))
357 memset (gprs64, 0, sizeof (gprs64));
358 memcpy (context->gpr, gprs64, sizeof(gprs64));
362 if (!ptrace32 (PTT_READ_GPRS, tid, gprs32, 0, NULL))
363 memset (gprs32, 0, sizeof (gprs32));
364 memcpy (context->gpr, gprs32, sizeof(gprs32));
368 /* Floating-point registers. */
369 if (flags & PTHDB_FLAG_FPRS)
371 if (!ptrace32 (PTT_READ_FPRS, tid, (int *) fprs, 0, NULL))
372 memset (fprs, 0, sizeof (fprs));
373 memcpy (context->fpr, fprs, sizeof(fprs));
376 /* Special-purpose registers. */
377 if (flags & PTHDB_FLAG_SPRS)
381 if (!ptrace64aix (PTT_READ_SPRS, tid,
382 (unsigned long) &sprs64, 0, NULL))
383 memset (&sprs64, 0, sizeof (sprs64));
384 memcpy (&context->msr, &sprs64, sizeof(sprs64));
388 if (!ptrace32 (PTT_READ_SPRS, tid, (int *) &sprs32, 0, NULL))
389 memset (&sprs32, 0, sizeof (sprs32));
390 memcpy (&context->msr, &sprs32, sizeof(sprs32));
396 /* Write register function should be able to write requested context
397 information to specified debuggee's kernel thread id.
398 If successful return 0, else non-zero is returned. */
401 pdc_write_regs (pthdb_user_t user,
403 unsigned long long flags,
404 pthdb_context_t *context)
406 /* This function doesn't appear to be used, so we could probably
407 just return 0 here. HOWEVER, if it is not defined, the OS will
408 complain and several thread debug functions will fail. In case
409 this is needed, I have implemented what I think it should do,
410 however this code is untested. */
412 if (debug_aix_thread)
413 fprintf_unfiltered (gdb_stdlog, "pdc_write_regs tid=%d flags=%s\n",
414 (int) tid, local_hex_string (flags));
416 /* General-purpose registers. */
417 if (flags & PTHDB_FLAG_GPRS)
420 ptrace64aix (PTT_WRITE_GPRS, tid,
421 (unsigned long) context->gpr, 0, NULL);
423 ptrace32 (PTT_WRITE_GPRS, tid, (int *) context->gpr, 0, NULL);
426 /* Floating-point registers. */
427 if (flags & PTHDB_FLAG_FPRS)
429 ptrace32 (PTT_WRITE_FPRS, tid, (int *) context->fpr, 0, NULL);
432 /* Special-purpose registers. */
433 if (flags & PTHDB_FLAG_SPRS)
437 ptrace64aix (PTT_WRITE_SPRS, tid,
438 (unsigned long) &context->msr, 0, NULL);
442 ptrace32 (PTT_WRITE_SPRS, tid, (int *) &context->msr, 0, NULL);
448 /* pthdb callback: read LEN bytes from process ADDR into BUF. */
451 pdc_read_data (pthdb_user_t user, void *buf,
452 pthdb_addr_t addr, size_t len)
456 if (debug_aix_thread)
457 fprintf_unfiltered (gdb_stdlog,
458 "pdc_read_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
459 user, (long) buf, local_hex_string (addr), len);
461 status = target_read_memory (addr, buf, len);
462 ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
464 if (debug_aix_thread)
465 fprintf_unfiltered (gdb_stdlog, " status=%d, returning %s\n",
466 status, pd_status2str (ret));
470 /* pthdb callback: write LEN bytes from BUF to process ADDR. */
473 pdc_write_data (pthdb_user_t user, void *buf,
474 pthdb_addr_t addr, size_t len)
478 if (debug_aix_thread)
479 fprintf_unfiltered (gdb_stdlog,
480 "pdc_write_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
481 user, (long) buf, local_hex_string (addr), len);
483 status = target_write_memory (addr, buf, len);
484 ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
486 if (debug_aix_thread)
487 fprintf_unfiltered (gdb_stdlog, " status=%d, returning %s\n", status,
488 pd_status2str (ret));
492 /* pthdb callback: allocate a LEN-byte buffer and store a pointer to it
496 pdc_alloc (pthdb_user_t user, size_t len, void **bufp)
498 if (debug_aix_thread)
499 fprintf_unfiltered (gdb_stdlog,
500 "pdc_alloc (user = %ld, len = %ld, bufp = 0x%lx)\n",
501 user, len, (long) bufp);
502 *bufp = xmalloc (len);
503 if (debug_aix_thread)
504 fprintf_unfiltered (gdb_stdlog,
505 " malloc returned 0x%lx\n", (long) *bufp);
507 /* Note: xmalloc() can't return 0; therefore PDC_FAILURE will never
510 return *bufp ? PDC_SUCCESS : PDC_FAILURE;
513 /* pthdb callback: reallocate BUF, which was allocated by the alloc or
514 realloc callback, so that it contains LEN bytes, and store a
515 pointer to the result in BUFP. */
518 pdc_realloc (pthdb_user_t user, void *buf, size_t len, void **bufp)
520 if (debug_aix_thread)
521 fprintf_unfiltered (gdb_stdlog,
522 "pdc_realloc (user = %ld, buf = 0x%lx, len = %ld, bufp = 0x%lx)\n",
523 user, (long) buf, len, (long) bufp);
524 *bufp = xrealloc (buf, len);
525 if (debug_aix_thread)
526 fprintf_unfiltered (gdb_stdlog,
527 " realloc returned 0x%lx\n", (long) *bufp);
528 return *bufp ? PDC_SUCCESS : PDC_FAILURE;
531 /* pthdb callback: free BUF, which was allocated by the alloc or
535 pdc_dealloc (pthdb_user_t user, void *buf)
537 if (debug_aix_thread)
538 fprintf_unfiltered (gdb_stdlog,
539 "pdc_free (user = %ld, buf = 0x%lx)\n", user,
545 /* Return a printable representation of pthread STATE. */
548 state2str (pthdb_state_t state)
552 case PST_IDLE: return "idle"; /* being created */
553 case PST_RUN: return "running"; /* running */
554 case PST_SLEEP: return "sleeping"; /* awaiting an event */
555 case PST_READY: return "ready"; /* runnable */
556 case PST_TERM: return "finished"; /* awaiting a join/detach */
557 default: return "unknown";
561 /* qsort() comparison function for sorting pd_thread structs by pthid. */
564 pcmp (const void *p1v, const void *p2v)
566 struct pd_thread *p1 = (struct pd_thread *) p1v;
567 struct pd_thread *p2 = (struct pd_thread *) p2v;
568 return p1->pthid < p2->pthid ? -1 : p1->pthid > p2->pthid;
571 /* iterate_over_threads() callback for counting GDB threads. */
574 giter_count (struct thread_info *thread, void *countp)
580 /* iterate_over_threads() callback for accumulating GDB thread pids. */
583 giter_accum (struct thread_info *thread, void *bufp)
585 **(struct thread_info ***) bufp = thread;
586 (*(struct thread_info ***) bufp)++;
590 /* ptid comparison function */
593 ptid_cmp (ptid_t ptid1, ptid_t ptid2)
597 if (ptid_get_pid (ptid1) < ptid_get_pid (ptid2))
599 else if (ptid_get_pid (ptid1) > ptid_get_pid (ptid2))
601 else if (ptid_get_tid (ptid1) < ptid_get_tid (ptid2))
603 else if (ptid_get_tid (ptid1) > ptid_get_tid (ptid2))
605 else if (ptid_get_lwp (ptid1) < ptid_get_lwp (ptid2))
607 else if (ptid_get_lwp (ptid1) > ptid_get_lwp (ptid2))
613 /* qsort() comparison function for sorting thread_info structs by pid. */
616 gcmp (const void *t1v, const void *t2v)
618 struct thread_info *t1 = *(struct thread_info **) t1v;
619 struct thread_info *t2 = *(struct thread_info **) t2v;
620 return ptid_cmp (t1->ptid, t2->ptid);
623 /* Synchronize GDB's thread list with libpthdebug's.
625 There are some benefits of doing this every time the inferior stops:
627 - allows users to run thread-specific commands without needing to
628 run "info threads" first
630 - helps pthdb_tid_pthread() work properly (see "libpthdebug
631 peculiarities" at the top of this module)
633 - simplifies the demands placed on libpthdebug, which seems to
634 have difficulty with certain call patterns */
637 sync_threadlists (void)
639 int cmd, status, infpid;
640 int pcount, psize, pi, gcount, gi;
641 struct pd_thread *pbuf;
642 struct thread_info **gbuf, **g, *thread;
643 pthdb_pthread_t pdtid;
647 /* Accumulate an array of libpthdebug threads sorted by pthread id. */
651 pbuf = (struct pd_thread *) xmalloc (psize * sizeof *pbuf);
653 for (cmd = PTHDB_LIST_FIRST;; cmd = PTHDB_LIST_NEXT)
655 status = pthdb_pthread (pd_session, &pdtid, cmd);
656 if (status != PTHDB_SUCCESS || pdtid == PTHDB_INVALID_PTHREAD)
659 status = pthdb_pthread_ptid (pd_session, pdtid, &pthid);
660 if (status != PTHDB_SUCCESS || pthid == PTHDB_INVALID_PTID)
666 pbuf = (struct pd_thread *) xrealloc (pbuf,
667 psize * sizeof *pbuf);
669 pbuf[pcount].pdtid = pdtid;
670 pbuf[pcount].pthid = pthid;
674 for (pi = 0; pi < pcount; pi++)
676 status = pthdb_pthread_tid (pd_session, pbuf[pi].pdtid, &tid);
677 if (status != PTHDB_SUCCESS)
678 tid = PTHDB_INVALID_TID;
682 qsort (pbuf, pcount, sizeof *pbuf, pcmp);
684 /* Accumulate an array of GDB threads sorted by pid. */
687 iterate_over_threads (giter_count, &gcount);
688 g = gbuf = (struct thread_info **) xmalloc (gcount * sizeof *gbuf);
689 iterate_over_threads (giter_accum, &g);
690 qsort (gbuf, gcount, sizeof *gbuf, gcmp);
692 /* Apply differences between the two arrays to GDB's thread list. */
694 infpid = PIDGET (inferior_ptid);
695 for (pi = gi = 0; pi < pcount || gi < gcount;)
699 delete_thread (gbuf[gi]->ptid);
702 else if (gi == gcount)
704 thread = add_thread (BUILD_THREAD (pbuf[pi].pthid, infpid));
705 thread->private = xmalloc (sizeof (struct private_thread_info));
706 thread->private->pdtid = pbuf[pi].pdtid;
707 thread->private->tid = pbuf[pi].tid;
715 pptid = BUILD_THREAD (pbuf[pi].pthid, infpid);
716 gptid = gbuf[gi]->ptid;
717 pdtid = pbuf[pi].pdtid;
720 cmp_result = ptid_cmp (pptid, gptid);
724 gbuf[gi]->private->pdtid = pdtid;
725 gbuf[gi]->private->tid = tid;
729 else if (cmp_result > 0)
731 delete_thread (gptid);
736 thread = add_thread (pptid);
737 thread->private = xmalloc (sizeof (struct private_thread_info));
738 thread->private->pdtid = pdtid;
739 thread->private->tid = tid;
749 /* Iterate_over_threads() callback for locating a thread whose kernel
750 thread just received a trap signal. */
753 iter_trap (struct thread_info *thread, void *unused)
755 struct thrdsinfo64 thrinf;
758 /* getthrds(3) isn't prototyped in any AIX 4.3.3 #include file. */
759 extern int getthrds (pid_t, struct thrdsinfo64 *,
760 int, pthdb_tid_t *, int);
762 tid = thread->private->tid;
763 if (tid == PTHDB_INVALID_TID)
766 if (getthrds (PIDGET (inferior_ptid), &thrinf,
767 sizeof (thrinf), &tid, 1) != 1)
770 return thrinf.ti_cursig == SIGTRAP;
773 /* Synchronize libpthdebug's state with the inferior and with GDB,
774 generate a composite process/thread <pid> for the current thread,
775 set inferior_ptid to <pid> if SET_INFPID, and return <pid>. */
778 pd_update (int set_infpid)
782 struct thread_info *thread;
785 return inferior_ptid;
787 status = pthdb_session_update (pd_session);
788 if (status != PTHDB_SUCCESS)
789 return inferior_ptid;
793 /* Define "current thread" as one that just received a trap signal. */
795 thread = iterate_over_threads (iter_trap, NULL);
797 ptid = inferior_ptid;
802 inferior_ptid = ptid;
807 /* Try to start debugging threads in the current process.
808 If successful and SET_INFPID, set inferior_ptid to reflect the
812 pd_activate (int set_infpid)
816 status = pthdb_session_init (PD_USER, arch64 ? PEM_64BIT : PEM_32BIT,
817 PTHDB_FLAG_REGS, &pd_callbacks,
819 if (status != PTHDB_SUCCESS)
821 return inferior_ptid;
824 return pd_update (set_infpid);
827 /* Undo the effects of pd_activate(). */
834 pthdb_session_destroy (pd_session);
836 pid_to_prc (&inferior_ptid);
840 /* An object file has just been loaded. Check whether the current
841 application is pthreaded, and if so, prepare for thread debugging. */
848 struct minimal_symbol *ms;
850 /* Don't initialize twice. */
854 /* Check application word size. */
855 arch64 = DEPRECATED_REGISTER_RAW_SIZE (0) == 8;
857 /* Check whether the application is pthreaded. */
859 status = pthdb_session_pthreaded (PD_USER, PTHDB_FLAG_REGS,
860 &pd_callbacks, &stub_name);
861 if ((status != PTHDB_SUCCESS &&
862 status != PTHDB_NOT_PTHREADED) || !stub_name)
865 /* Set a breakpoint on the returned stub function. */
866 if (!(ms = lookup_minimal_symbol (stub_name, NULL, NULL)))
868 pd_brk_addr = SYMBOL_VALUE_ADDRESS (ms);
869 if (!create_thread_event_breakpoint (pd_brk_addr))
872 /* Prepare for thread debugging. */
873 base_target = current_target;
874 push_target (&aix_thread_ops);
877 /* If we're debugging a core file or an attached inferior, the
878 pthread library may already have been initialized, so try to
879 activate thread debugging. */
883 /* Undo the effects of pd_enable(). */
893 unpush_target (&aix_thread_ops);
896 /* target_new_objfile_hook callback.
898 If OBJFILE is non-null, check whether a threaded application is
899 being debugged, and if so, prepare for thread debugging.
901 If OBJFILE is null, stop debugging threads. */
904 new_objfile (struct objfile *objfile)
911 if (target_new_objfile_chain)
912 target_new_objfile_chain (objfile);
915 /* Attach to process specified by ARGS. */
918 aix_thread_attach (char *args, int from_tty)
920 base_target.to_attach (args, from_tty);
924 /* Detach from the process attached to by aix_thread_attach(). */
927 aix_thread_detach (char *args, int from_tty)
930 base_target.to_detach (args, from_tty);
933 /* Tell the inferior process to continue running thread PID if != -1
934 and all threads otherwise. */
937 aix_thread_resume (ptid_t ptid, int step, enum target_signal sig)
939 struct thread_info *thread;
944 struct cleanup *cleanup = save_inferior_ptid ();
945 inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid));
946 base_target.to_resume (ptid, step, sig);
947 do_cleanups (cleanup);
951 thread = find_thread_pid (ptid);
953 error ("aix-thread resume: unknown pthread %ld",
956 tid[0] = thread->private->tid;
957 if (tid[0] == PTHDB_INVALID_TID)
958 error ("aix-thread resume: no tid for pthread %ld",
963 ptrace64aix (PTT_CONTINUE, tid[0], 1,
964 target_signal_to_host (sig), (int *) tid);
966 ptrace32 (PTT_CONTINUE, tid[0], (int *) 1,
967 target_signal_to_host (sig), (int *) tid);
971 /* Wait for thread/process ID if != -1 or for any thread otherwise.
972 If an error occurs, return -1, else return the pid of the stopped
976 aix_thread_wait (ptid_t ptid, struct target_waitstatus *status)
978 struct cleanup *cleanup = save_inferior_ptid ();
982 inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid));
983 ptid = base_target.to_wait (ptid, status);
984 do_cleanups (cleanup);
986 if (PIDGET (ptid) == -1)
987 return pid_to_ptid (-1);
989 /* Check whether libpthdebug might be ready to be initialized. */
990 if (!pd_active && status->kind == TARGET_WAITKIND_STOPPED &&
991 status->value.sig == TARGET_SIGNAL_TRAP &&
992 read_pc_pid (ptid) - DECR_PC_AFTER_BREAK == pd_brk_addr)
993 return pd_activate (0);
995 return pd_update (0);
998 /* Record that the 64-bit general-purpose registers contain VALS. */
1001 supply_gprs64 (uint64_t *vals)
1005 for (regno = 0; regno < 32; regno++)
1006 supply_register (regno, (char *) (vals + regno));
1009 /* Record that 32-bit register REGNO contains VAL. */
1012 supply_reg32 (int regno, uint32_t val)
1014 supply_register (regno, (char *) &val);
1017 /* Record that the floating-point registers contain VALS. */
1020 supply_fprs (double *vals)
1024 for (regno = 0; regno < 32; regno++)
1025 supply_register (regno + FP0_REGNUM, (char *) (vals + regno));
1028 /* Predicate to test whether given register number is a "special" register. */
1030 special_register_p (int regno)
1032 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1034 return regno == PC_REGNUM
1035 || regno == tdep->ppc_ps_regnum
1036 || regno == tdep->ppc_cr_regnum
1037 || regno == tdep->ppc_lr_regnum
1038 || regno == tdep->ppc_ctr_regnum
1039 || regno == tdep->ppc_xer_regnum
1040 || regno == tdep->ppc_fpscr_regnum
1041 || (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum);
1045 /* Record that the special registers contain the specified 64-bit and
1049 supply_sprs64 (uint64_t iar, uint64_t msr, uint32_t cr,
1050 uint64_t lr, uint64_t ctr, uint32_t xer,
1053 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1055 supply_register (PC_REGNUM, (char *) &iar);
1056 supply_register (tdep->ppc_ps_regnum, (char *) &msr);
1057 supply_register (tdep->ppc_cr_regnum, (char *) &cr);
1058 supply_register (tdep->ppc_lr_regnum, (char *) &lr);
1059 supply_register (tdep->ppc_ctr_regnum, (char *) &ctr);
1060 supply_register (tdep->ppc_xer_regnum, (char *) &xer);
1061 supply_register (tdep->ppc_fpscr_regnum, (char *) &fpscr);
1064 /* Record that the special registers contain the specified 32-bit
1068 supply_sprs32 (uint32_t iar, uint32_t msr, uint32_t cr,
1069 uint32_t lr, uint32_t ctr, uint32_t xer,
1072 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1074 supply_register (PC_REGNUM, (char *) &iar);
1075 supply_register (tdep->ppc_ps_regnum, (char *) &msr);
1076 supply_register (tdep->ppc_cr_regnum, (char *) &cr);
1077 supply_register (tdep->ppc_lr_regnum, (char *) &lr);
1078 supply_register (tdep->ppc_ctr_regnum, (char *) &ctr);
1079 supply_register (tdep->ppc_xer_regnum, (char *) &xer);
1080 supply_register (tdep->ppc_fpscr_regnum, (char *) &fpscr);
1083 /* Fetch all registers from pthread PDTID, which doesn't have a kernel
1086 There's no way to query a single register from a non-kernel
1087 pthread, so there's no need for a single-register version of this
1091 fetch_regs_user_thread (pthdb_pthread_t pdtid)
1094 pthdb_context_t ctx;
1096 if (debug_aix_thread)
1097 fprintf_unfiltered (gdb_stdlog,
1098 "fetch_regs_user_thread %lx\n", (long) pdtid);
1099 status = pthdb_pthread_context (pd_session, pdtid, &ctx);
1100 if (status != PTHDB_SUCCESS)
1101 error ("aix-thread: fetch_registers: pthdb_pthread_context returned %s",
1102 pd_status2str (status));
1104 /* General-purpose registers. */
1107 supply_gprs64 (ctx.gpr);
1109 for (i = 0; i < 32; i++)
1110 supply_reg32 (i, ctx.gpr[i]);
1112 /* Floating-point registers. */
1114 supply_fprs (ctx.fpr);
1116 /* Special registers. */
1119 supply_sprs64 (ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr, ctx.xer,
1122 supply_sprs32 (ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr, ctx.xer,
1126 /* Fetch register REGNO if != -1 or all registers otherwise from
1129 AIX provides a way to query all of a kernel thread's GPRs, FPRs, or
1130 SPRs, but there's no way to query individual registers within those
1131 groups. Therefore, if REGNO != -1, this function fetches an entire
1134 Unfortunately, kernel thread register queries often fail with
1135 EPERM, indicating that the thread is in kernel space. This breaks
1136 backtraces of threads other than the current one. To make that
1137 breakage obvious without throwing an error to top level (which is
1138 bad e.g. during "info threads" output), zero registers that can't
1142 fetch_regs_kernel_thread (int regno, pthdb_tid_t tid)
1144 uint64_t gprs64[32];
1145 uint32_t gprs32[32];
1147 struct ptxsprs sprs64;
1148 struct ptsprs sprs32;
1151 if (debug_aix_thread)
1152 fprintf_unfiltered (gdb_stdlog,
1153 "fetch_regs_kernel_thread tid=%lx regno=%d arch64=%d\n",
1154 (long) tid, regno, arch64);
1156 /* General-purpose registers. */
1157 if (regno == -1 || regno < FP0_REGNUM)
1161 if (!ptrace64aix (PTT_READ_GPRS, tid,
1162 (unsigned long) gprs64, 0, NULL))
1163 memset (gprs64, 0, sizeof (gprs64));
1164 supply_gprs64 (gprs64);
1168 if (!ptrace32 (PTT_READ_GPRS, tid, gprs32, 0, NULL))
1169 memset (gprs32, 0, sizeof (gprs32));
1170 for (i = 0; i < 32; i++)
1171 supply_reg32 (i, gprs32[i]);
1175 /* Floating-point registers. */
1177 if (regno == -1 || (regno >= FP0_REGNUM && regno <= FPLAST_REGNUM))
1179 if (!ptrace32 (PTT_READ_FPRS, tid, (int *) fprs, 0, NULL))
1180 memset (fprs, 0, sizeof (fprs));
1184 /* Special-purpose registers. */
1186 if (regno == -1 || special_register_p (regno))
1190 if (!ptrace64aix (PTT_READ_SPRS, tid,
1191 (unsigned long) &sprs64, 0, NULL))
1192 memset (&sprs64, 0, sizeof (sprs64));
1193 supply_sprs64 (sprs64.pt_iar, sprs64.pt_msr, sprs64.pt_cr,
1194 sprs64.pt_lr, sprs64.pt_ctr, sprs64.pt_xer,
1199 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1201 if (!ptrace32 (PTT_READ_SPRS, tid, (int *) &sprs32, 0, NULL))
1202 memset (&sprs32, 0, sizeof (sprs32));
1203 supply_sprs32 (sprs32.pt_iar, sprs32.pt_msr, sprs32.pt_cr,
1204 sprs32.pt_lr, sprs32.pt_ctr, sprs32.pt_xer,
1207 if (tdep->ppc_mq_regnum >= 0)
1208 supply_register (tdep->ppc_mq_regnum, (char *) &sprs32.pt_mq);
1213 /* Fetch register REGNO if != -1 or all registers otherwise in the
1214 thread/process specified by inferior_ptid. */
1217 aix_thread_fetch_registers (int regno)
1219 struct thread_info *thread;
1222 if (!PD_TID (inferior_ptid))
1223 base_target.to_fetch_registers (regno);
1226 thread = find_thread_pid (inferior_ptid);
1227 tid = thread->private->tid;
1229 if (tid == PTHDB_INVALID_TID)
1230 fetch_regs_user_thread (thread->private->pdtid);
1232 fetch_regs_kernel_thread (regno, tid);
1236 /* Store the gp registers into an array of uint32_t or uint64_t. */
1239 fill_gprs64 (uint64_t *vals)
1243 for (regno = 0; regno < FP0_REGNUM; regno++)
1244 if (register_cached (regno))
1245 regcache_collect (regno, vals + regno);
1249 fill_gprs32 (uint32_t *vals)
1253 for (regno = 0; regno < FP0_REGNUM; regno++)
1254 if (register_cached (regno))
1255 regcache_collect (regno, vals + regno);
1258 /* Store the floating point registers into a double array. */
1260 fill_fprs (double *vals)
1264 for (regno = FP0_REGNUM; regno < FPLAST_REGNUM; regno++)
1265 if (register_cached (regno))
1266 regcache_collect (regno, vals + regno);
1269 /* Store the special registers into the specified 64-bit and 32-bit
1273 fill_sprs64 (uint64_t *iar, uint64_t *msr, uint32_t *cr,
1274 uint64_t *lr, uint64_t *ctr, uint32_t *xer,
1277 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1279 /* Verify that the size of the size of the IAR buffer is the
1280 same as the raw size of the PC (in the register cache). If
1281 they're not, then either GDB has been built incorrectly, or
1282 there's some other kind of internal error. To be really safe,
1283 we should check all of the sizes. */
1284 gdb_assert (sizeof (*iar) == DEPRECATED_REGISTER_RAW_SIZE (PC_REGNUM));
1286 if (register_cached (PC_REGNUM))
1287 regcache_collect (PC_REGNUM, iar);
1288 if (register_cached (tdep->ppc_ps_regnum))
1289 regcache_collect (tdep->ppc_ps_regnum, msr);
1290 if (register_cached (tdep->ppc_cr_regnum))
1291 regcache_collect (tdep->ppc_cr_regnum, cr);
1292 if (register_cached (tdep->ppc_lr_regnum))
1293 regcache_collect (tdep->ppc_lr_regnum, lr);
1294 if (register_cached (tdep->ppc_ctr_regnum))
1295 regcache_collect (tdep->ppc_ctr_regnum, ctr);
1296 if (register_cached (tdep->ppc_xer_regnum))
1297 regcache_collect (tdep->ppc_xer_regnum, xer);
1298 if (register_cached (tdep->ppc_fpscr_regnum))
1299 regcache_collect (tdep->ppc_fpscr_regnum, fpscr);
1303 fill_sprs32 (unsigned long *iar, unsigned long *msr, unsigned long *cr,
1304 unsigned long *lr, unsigned long *ctr, unsigned long *xer,
1305 unsigned long *fpscr)
1307 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1309 /* Verify that the size of the size of the IAR buffer is the
1310 same as the raw size of the PC (in the register cache). If
1311 they're not, then either GDB has been built incorrectly, or
1312 there's some other kind of internal error. To be really safe,
1313 we should check all of the sizes.
1315 If this assert() fails, the most likely reason is that GDB was
1316 built incorrectly. In order to make use of many of the header
1317 files in /usr/include/sys, GDB needs to be configured so that
1318 sizeof (long) == 4). */
1319 gdb_assert (sizeof (*iar) == DEPRECATED_REGISTER_RAW_SIZE (PC_REGNUM));
1321 if (register_cached (PC_REGNUM))
1322 regcache_collect (PC_REGNUM, iar);
1323 if (register_cached (tdep->ppc_ps_regnum))
1324 regcache_collect (tdep->ppc_ps_regnum, msr);
1325 if (register_cached (tdep->ppc_cr_regnum))
1326 regcache_collect (tdep->ppc_cr_regnum, cr);
1327 if (register_cached (tdep->ppc_lr_regnum))
1328 regcache_collect (tdep->ppc_lr_regnum, lr);
1329 if (register_cached (tdep->ppc_ctr_regnum))
1330 regcache_collect (tdep->ppc_ctr_regnum, ctr);
1331 if (register_cached (tdep->ppc_xer_regnum))
1332 regcache_collect (tdep->ppc_xer_regnum, xer);
1333 if (register_cached (tdep->ppc_fpscr_regnum))
1334 regcache_collect (tdep->ppc_fpscr_regnum, fpscr);
1337 /* Store all registers into pthread PDTID, which doesn't have a kernel
1340 It's possible to store a single register into a non-kernel pthread,
1341 but I doubt it's worth the effort. */
1344 store_regs_user_thread (pthdb_pthread_t pdtid)
1347 pthdb_context_t ctx;
1352 if (debug_aix_thread)
1353 fprintf_unfiltered (gdb_stdlog,
1354 "store_regs_user_thread %lx\n", (long) pdtid);
1356 /* Retrieve the thread's current context for its non-register
1358 status = pthdb_pthread_context (pd_session, pdtid, &ctx);
1359 if (status != PTHDB_SUCCESS)
1360 error ("aix-thread: store_registers: pthdb_pthread_context returned %s",
1361 pd_status2str (status));
1363 /* Collect general-purpose register values from the regcache. */
1365 for (i = 0; i < 32; i++)
1366 if (register_cached (i))
1370 regcache_collect (i, (void *) &int64);
1375 regcache_collect (i, (void *) &int32);
1380 /* Collect floating-point register values from the regcache. */
1381 fill_fprs (ctx.fpr);
1383 /* Special registers (always kept in ctx as 64 bits). */
1386 fill_sprs64 (&ctx.iar, &ctx.msr, &ctx.cr, &ctx.lr, &ctx.ctr, &ctx.xer,
1391 /* Problem: ctx.iar etc. are 64 bits, but raw_registers are 32.
1392 Solution: use 32-bit temp variables. (The assert() in fill_sprs32()
1393 will fail if the size of an unsigned long is incorrect. If this
1394 happens, GDB needs to be reconfigured so that longs are 32-bits.) */
1395 unsigned long tmp_iar, tmp_msr, tmp_cr, tmp_lr, tmp_ctr, tmp_xer,
1397 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1399 fill_sprs32 (&tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr, &tmp_ctr, &tmp_xer,
1401 if (register_cached (PC_REGNUM))
1403 if (register_cached (tdep->ppc_ps_regnum))
1405 if (register_cached (tdep->ppc_cr_regnum))
1407 if (register_cached (tdep->ppc_lr_regnum))
1409 if (register_cached (tdep->ppc_ctr_regnum))
1411 if (register_cached (tdep->ppc_xer_regnum))
1413 if (register_cached (tdep->ppc_xer_regnum))
1414 ctx.fpscr = tmp_fpscr;
1417 status = pthdb_pthread_setcontext (pd_session, pdtid, &ctx);
1418 if (status != PTHDB_SUCCESS)
1419 error ("aix-thread: store_registers: pthdb_pthread_setcontext returned %s",
1420 pd_status2str (status));
1423 /* Store register REGNO if != -1 or all registers otherwise into
1426 AIX provides a way to set all of a kernel thread's GPRs, FPRs, or
1427 SPRs, but there's no way to set individual registers within those
1428 groups. Therefore, if REGNO != -1, this function stores an entire
1432 store_regs_kernel_thread (int regno, pthdb_tid_t tid)
1434 uint64_t gprs64[32];
1435 uint32_t gprs32[32];
1437 struct ptxsprs sprs64;
1438 struct ptsprs sprs32;
1440 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1442 if (debug_aix_thread)
1443 fprintf_unfiltered (gdb_stdlog,
1444 "store_regs_kernel_thread tid=%lx regno=%d\n",
1447 /* General-purpose registers. */
1448 if (regno == -1 || regno < FP0_REGNUM)
1452 /* Pre-fetch: some regs may not be in the cache. */
1453 ptrace64aix (PTT_READ_GPRS, tid, (unsigned long) gprs64, 0, NULL);
1454 fill_gprs64 (gprs64);
1455 ptrace64aix (PTT_WRITE_GPRS, tid, (unsigned long) gprs64, 0, NULL);
1459 /* Pre-fetch: some regs may not be in the cache. */
1460 ptrace32 (PTT_READ_GPRS, tid, gprs32, 0, NULL);
1461 fill_gprs32 (gprs32);
1462 ptrace32 (PTT_WRITE_GPRS, tid, gprs32, 0, NULL);
1466 /* Floating-point registers. */
1468 if (regno == -1 || (regno >= FP0_REGNUM && regno <= FPLAST_REGNUM))
1470 /* Pre-fetch: some regs may not be in the cache. */
1471 ptrace32 (PTT_READ_FPRS, tid, (int *) fprs, 0, NULL);
1473 ptrace32 (PTT_WRITE_FPRS, tid, (int *) fprs, 0, NULL);
1476 /* Special-purpose registers. */
1478 if (regno == -1 || special_register_p (regno))
1482 /* Pre-fetch: some registers won't be in the cache. */
1483 ptrace64aix (PTT_READ_SPRS, tid,
1484 (unsigned long) &sprs64, 0, NULL);
1485 fill_sprs64 (&sprs64.pt_iar, &sprs64.pt_msr, &sprs64.pt_cr,
1486 &sprs64.pt_lr, &sprs64.pt_ctr, &sprs64.pt_xer,
1488 ptrace64aix (PTT_WRITE_SPRS, tid,
1489 (unsigned long) &sprs64, 0, NULL);
1493 /* Pre-fetch: some registers won't be in the cache. */
1494 ptrace32 (PTT_READ_SPRS, tid, (int *) &sprs32, 0, NULL);
1496 fill_sprs32 (&sprs32.pt_iar, &sprs32.pt_msr, &sprs32.pt_cr,
1497 &sprs32.pt_lr, &sprs32.pt_ctr, &sprs32.pt_xer,
1500 if (tdep->ppc_mq_regnum >= 0)
1501 if (register_cached (tdep->ppc_mq_regnum))
1502 regcache_collect (tdep->ppc_mq_regnum, &sprs32.pt_mq);
1504 ptrace32 (PTT_WRITE_SPRS, tid, (int *) &sprs32, 0, NULL);
1509 /* Store gdb's current view of the register set into the
1510 thread/process specified by inferior_ptid. */
1513 aix_thread_store_registers (int regno)
1515 struct thread_info *thread;
1518 if (!PD_TID (inferior_ptid))
1519 base_target.to_store_registers (regno);
1522 thread = find_thread_pid (inferior_ptid);
1523 tid = thread->private->tid;
1525 if (tid == PTHDB_INVALID_TID)
1526 store_regs_user_thread (thread->private->pdtid);
1528 store_regs_kernel_thread (regno, tid);
1532 /* Transfer LEN bytes of memory from GDB address MYADDR to target
1533 address MEMADDR if WRITE and vice versa otherwise. */
1536 aix_thread_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
1537 struct mem_attrib *attrib,
1538 struct target_ops *target)
1541 struct cleanup *cleanup = save_inferior_ptid ();
1543 inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid));
1544 n = base_target.to_xfer_memory (memaddr, myaddr, len,
1545 write, attrib, &base_target);
1546 do_cleanups (cleanup);
1551 /* Kill and forget about the inferior process. */
1554 aix_thread_kill (void)
1556 struct cleanup *cleanup = save_inferior_ptid ();
1558 inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid));
1559 base_target.to_kill ();
1560 do_cleanups (cleanup);
1563 /* Clean up after the inferior exits. */
1566 aix_thread_mourn_inferior (void)
1569 base_target.to_mourn_inferior ();
1572 /* Return whether thread PID is still valid. */
1575 aix_thread_thread_alive (ptid_t ptid)
1578 return base_target.to_thread_alive (ptid);
1580 /* We update the thread list every time the child stops, so all
1581 valid threads should be in the thread list. */
1582 return in_thread_list (ptid);
1585 /* Return a printable representation of composite PID for use in
1586 "info threads" output. */
1589 aix_thread_pid_to_str (ptid_t ptid)
1591 static char *ret = NULL;
1594 return base_target.to_pid_to_str (ptid);
1596 /* Free previous return value; a new one will be allocated by
1600 xasprintf (&ret, "Thread %ld", ptid_get_tid (ptid));
1604 /* Return a printable representation of extra information about
1605 THREAD, for use in "info threads" output. */
1608 aix_thread_extra_thread_info (struct thread_info *thread)
1610 struct ui_file *buf;
1612 pthdb_pthread_t pdtid;
1614 pthdb_state_t state;
1615 pthdb_suspendstate_t suspendstate;
1616 pthdb_detachstate_t detachstate;
1619 static char *ret = NULL;
1621 if (!PD_TID (thread->ptid))
1624 buf = mem_fileopen ();
1626 pdtid = thread->private->pdtid;
1627 tid = thread->private->tid;
1629 if (tid != PTHDB_INVALID_TID)
1630 fprintf_unfiltered (buf, "tid %d", tid);
1632 status = pthdb_pthread_state (pd_session, pdtid, &state);
1633 if (status != PTHDB_SUCCESS)
1635 fprintf_unfiltered (buf, ", %s", state2str (state));
1637 status = pthdb_pthread_suspendstate (pd_session, pdtid,
1639 if (status == PTHDB_SUCCESS && suspendstate == PSS_SUSPENDED)
1640 fprintf_unfiltered (buf, ", suspended");
1642 status = pthdb_pthread_detachstate (pd_session, pdtid,
1644 if (status == PTHDB_SUCCESS && detachstate == PDS_DETACHED)
1645 fprintf_unfiltered (buf, ", detached");
1647 pthdb_pthread_cancelpend (pd_session, pdtid, &cancelpend);
1648 if (status == PTHDB_SUCCESS && cancelpend)
1649 fprintf_unfiltered (buf, ", cancel pending");
1651 ui_file_write (buf, "", 1);
1653 xfree (ret); /* Free old buffer. */
1655 ret = ui_file_xstrdup (buf, &length);
1656 ui_file_delete (buf);
1661 /* Initialize target aix_thread_ops. */
1664 init_aix_thread_ops (void)
1666 aix_thread_ops.to_shortname = "aix-threads";
1667 aix_thread_ops.to_longname = "AIX pthread support";
1668 aix_thread_ops.to_doc = "AIX pthread support";
1670 aix_thread_ops.to_attach = aix_thread_attach;
1671 aix_thread_ops.to_detach = aix_thread_detach;
1672 aix_thread_ops.to_resume = aix_thread_resume;
1673 aix_thread_ops.to_wait = aix_thread_wait;
1674 aix_thread_ops.to_fetch_registers = aix_thread_fetch_registers;
1675 aix_thread_ops.to_store_registers = aix_thread_store_registers;
1676 aix_thread_ops.to_xfer_memory = aix_thread_xfer_memory;
1677 /* No need for aix_thread_ops.to_create_inferior, because we activate thread
1678 debugging when the inferior reaches pd_brk_addr. */
1679 aix_thread_ops.to_kill = aix_thread_kill;
1680 aix_thread_ops.to_mourn_inferior = aix_thread_mourn_inferior;
1681 aix_thread_ops.to_thread_alive = aix_thread_thread_alive;
1682 aix_thread_ops.to_pid_to_str = aix_thread_pid_to_str;
1683 aix_thread_ops.to_extra_thread_info = aix_thread_extra_thread_info;
1684 aix_thread_ops.to_stratum = thread_stratum;
1685 aix_thread_ops.to_magic = OPS_MAGIC;
1688 /* Module startup initialization function, automagically called by
1692 _initialize_aix_thread (void)
1694 init_aix_thread_ops ();
1695 add_target (&aix_thread_ops);
1697 /* Notice when object files get loaded and unloaded. */
1698 target_new_objfile_chain = target_new_objfile_hook;
1699 target_new_objfile_hook = new_objfile;
1701 add_show_from_set (add_set_cmd ("aix-thread", no_class, var_zinteger,
1702 (char *) &debug_aix_thread,
1703 "Set debugging of AIX thread module.\n"
1704 "Enables printf debugging output.\n",