GDB (API)
/home/stan/gdb/src/gdb/aix-thread.c
Go to the documentation of this file.
00001 /* Low level interface for debugging AIX 4.3+ pthreads.
00002 
00003    Copyright (C) 1999-2013 Free Software Foundation, Inc.
00004    Written by Nick Duffek <nsd@redhat.com>.
00005 
00006    This file is part of GDB.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 3 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 
00022 /* This module uses the libpthdebug.a library provided by AIX 4.3+ for
00023    debugging pthread applications.
00024 
00025    Some name prefix conventions:
00026      pthdb_     provided by libpthdebug.a
00027      pdc_       callbacks that this module provides to libpthdebug.a
00028      pd_        variables or functions interfacing with libpthdebug.a
00029 
00030    libpthdebug peculiarities:
00031 
00032      - pthdb_ptid_pthread() is prototyped in <sys/pthdebug.h>, but
00033        it's not documented, and after several calls it stops working
00034        and causes other libpthdebug functions to fail.
00035 
00036      - pthdb_tid_pthread() doesn't always work after
00037        pthdb_session_update(), but it does work after cycling through
00038        all threads using pthdb_pthread().
00039 
00040      */
00041 
00042 #include "defs.h"
00043 #include "gdb_assert.h"
00044 #include "gdbthread.h"
00045 #include "target.h"
00046 #include "inferior.h"
00047 #include "regcache.h"
00048 #include "gdbcmd.h"
00049 #include "ppc-tdep.h"
00050 #include "gdb_string.h"
00051 #include "observer.h"
00052 
00053 #include <procinfo.h>
00054 #include <sys/types.h>
00055 #include <sys/ptrace.h>
00056 #include <sys/reg.h>
00057 #include <sched.h>
00058 #include <sys/pthdebug.h>
00059 
00060 #if !HAVE_DECL_GETTHRDS
00061 extern int getthrds (pid_t, struct thrdsinfo64 *, int, tid_t *, int);
00062 #endif
00063 
00064 /* Whether to emit debugging output.  */
00065 static int debug_aix_thread;
00066 
00067 /* In AIX 5.1, functions use pthdb_tid_t instead of tid_t.  */
00068 #ifndef PTHDB_VERSION_3
00069 #define pthdb_tid_t     tid_t
00070 #endif
00071 
00072 /* Return whether to treat PID as a debuggable thread id.  */
00073 
00074 #define PD_TID(ptid)    (pd_active && ptid_get_tid (ptid) != 0)
00075 
00076 /* pthdb_user_t value that we pass to pthdb functions.  0 causes
00077    PTHDB_BAD_USER errors, so use 1.  */
00078 
00079 #define PD_USER 1
00080 
00081 /* Success and failure values returned by pthdb callbacks.  */
00082 
00083 #define PDC_SUCCESS     PTHDB_SUCCESS
00084 #define PDC_FAILURE     PTHDB_CALLBACK
00085 
00086 /* Private data attached to each element in GDB's thread list.  */
00087 
00088 struct private_thread_info {
00089   pthdb_pthread_t pdtid;         /* thread's libpthdebug id */
00090   pthdb_tid_t tid;                      /* kernel thread id */
00091 };
00092 
00093 /* Information about a thread of which libpthdebug is aware.  */
00094 
00095 struct pd_thread {
00096   pthdb_pthread_t pdtid;
00097   pthread_t pthid;
00098   pthdb_tid_t tid;
00099 };
00100 
00101 /* This module's target-specific operations, active while pd_able is true.  */
00102 
00103 static struct target_ops aix_thread_ops;
00104 
00105 /* Address of the function that libpthread will call when libpthdebug
00106    is ready to be initialized.  */
00107 
00108 static CORE_ADDR pd_brk_addr;
00109 
00110 /* Whether the current application is debuggable by pthdb.  */
00111 
00112 static int pd_able = 0;
00113 
00114 /* Whether a threaded application is being debugged.  */
00115 
00116 static int pd_active = 0;
00117 
00118 /* Whether the current architecture is 64-bit.  
00119    Only valid when pd_able is true.  */
00120 
00121 static int arch64;
00122 
00123 /* Forward declarations for pthdb callbacks.  */
00124 
00125 static int pdc_symbol_addrs (pthdb_user_t, pthdb_symbol_t *, int);
00126 static int pdc_read_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
00127 static int pdc_write_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
00128 static int pdc_read_regs (pthdb_user_t user, pthdb_tid_t tid,
00129                           unsigned long long flags, 
00130                           pthdb_context_t *context);
00131 static int pdc_write_regs (pthdb_user_t user, pthdb_tid_t tid,
00132                            unsigned long long flags, 
00133                            pthdb_context_t *context);
00134 static int pdc_alloc (pthdb_user_t, size_t, void **);
00135 static int pdc_realloc (pthdb_user_t, void *, size_t, void **);
00136 static int pdc_dealloc (pthdb_user_t, void *);
00137 
00138 /* pthdb callbacks.  */
00139 
00140 static pthdb_callbacks_t pd_callbacks = {
00141   pdc_symbol_addrs,
00142   pdc_read_data,
00143   pdc_write_data,
00144   pdc_read_regs,
00145   pdc_write_regs,
00146   pdc_alloc,
00147   pdc_realloc,
00148   pdc_dealloc,
00149   NULL
00150 };
00151 
00152 /* Current pthdb session.  */
00153 
00154 static pthdb_session_t pd_session;
00155 
00156 /* Return a printable representation of pthdebug function return
00157    STATUS.  */
00158 
00159 static char *
00160 pd_status2str (int status)
00161 {
00162   switch (status)
00163     {
00164     case PTHDB_SUCCESS:         return "SUCCESS";
00165     case PTHDB_NOSYS:           return "NOSYS";
00166     case PTHDB_NOTSUP:          return "NOTSUP";
00167     case PTHDB_BAD_VERSION:     return "BAD_VERSION";
00168     case PTHDB_BAD_USER:        return "BAD_USER";
00169     case PTHDB_BAD_SESSION:     return "BAD_SESSION";
00170     case PTHDB_BAD_MODE:        return "BAD_MODE";
00171     case PTHDB_BAD_FLAGS:       return "BAD_FLAGS";
00172     case PTHDB_BAD_CALLBACK:    return "BAD_CALLBACK";
00173     case PTHDB_BAD_POINTER:     return "BAD_POINTER";
00174     case PTHDB_BAD_CMD:         return "BAD_CMD";
00175     case PTHDB_BAD_PTHREAD:     return "BAD_PTHREAD";
00176     case PTHDB_BAD_ATTR:        return "BAD_ATTR";
00177     case PTHDB_BAD_MUTEX:       return "BAD_MUTEX";
00178     case PTHDB_BAD_MUTEXATTR:   return "BAD_MUTEXATTR";
00179     case PTHDB_BAD_COND:        return "BAD_COND";
00180     case PTHDB_BAD_CONDATTR:    return "BAD_CONDATTR";
00181     case PTHDB_BAD_RWLOCK:      return "BAD_RWLOCK";
00182     case PTHDB_BAD_RWLOCKATTR:  return "BAD_RWLOCKATTR";
00183     case PTHDB_BAD_KEY:         return "BAD_KEY";
00184     case PTHDB_BAD_PTID:        return "BAD_PTID";
00185     case PTHDB_BAD_TID:         return "BAD_TID";
00186     case PTHDB_CALLBACK:        return "CALLBACK";
00187     case PTHDB_CONTEXT:         return "CONTEXT";
00188     case PTHDB_HELD:            return "HELD";
00189     case PTHDB_NOT_HELD:        return "NOT_HELD";
00190     case PTHDB_MEMORY:          return "MEMORY";
00191     case PTHDB_NOT_PTHREADED:   return "NOT_PTHREADED";
00192     case PTHDB_SYMBOL:          return "SYMBOL";
00193     case PTHDB_NOT_AVAIL:       return "NOT_AVAIL";
00194     case PTHDB_INTERNAL:        return "INTERNAL";
00195     default:                    return "UNKNOWN";
00196     }
00197 }
00198 
00199 /* A call to ptrace(REQ, ID, ...) just returned RET.  Check for
00200    exceptional conditions and either return nonlocally or else return
00201    1 for success and 0 for failure.  */
00202 
00203 static int
00204 ptrace_check (int req, int id, int ret)
00205 {
00206   if (ret == 0 && !errno)
00207     return 1;
00208 
00209   /* According to ptrace(2), ptrace may fail with EPERM if "the
00210      Identifier parameter corresponds to a kernel thread which is
00211      stopped in kernel mode and whose computational state cannot be
00212      read or written."  This happens quite often with register reads.  */
00213 
00214   switch (req)
00215     {
00216     case PTT_READ_GPRS:
00217     case PTT_READ_FPRS:
00218     case PTT_READ_SPRS:
00219       if (ret == -1 && errno == EPERM)
00220         {
00221           if (debug_aix_thread)
00222             fprintf_unfiltered (gdb_stdlog, 
00223                                 "ptrace (%d, %d) = %d (errno = %d)\n",
00224                                 req, id, ret, errno);
00225           return ret == -1 ? 0 : 1;
00226         }
00227       break;
00228     }
00229   error (_("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)"),
00230          req, id, ret, errno, safe_strerror (errno));
00231   return 0;  /* Not reached.  */
00232 }
00233 
00234 /* Call ptracex (REQ, ID, ADDR, DATA, BUF) or
00235    ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
00236    Return success.  */
00237 
00238 #ifdef HAVE_PTRACE64
00239 # define ptracex(request, pid, addr, data, buf) \
00240          ptrace64 (request, pid, addr, data, buf)
00241 #endif
00242 
00243 static int
00244 ptrace64aix (int req, int id, long long addr, int data, int *buf)
00245 {
00246   errno = 0;
00247   return ptrace_check (req, id, ptracex (req, id, addr, data, buf));
00248 }
00249 
00250 /* Call ptrace (REQ, ID, ADDR, DATA, BUF) or
00251    ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
00252    Return success.  */
00253 
00254 #ifdef HAVE_PTRACE64
00255 # define ptrace(request, pid, addr, data, buf) \
00256          ptrace64 (request, pid, addr, data, buf)
00257 # define addr_ptr long long
00258 #else
00259 # define addr_ptr int *
00260 #endif
00261 
00262 static int
00263 ptrace32 (int req, int id, addr_ptr addr, int data, int *buf)
00264 {
00265   errno = 0;
00266   return ptrace_check (req, id, 
00267                        ptrace (req, id, addr, data, buf));
00268 }
00269 
00270 /* If *PIDP is a composite process/thread id, convert it to a
00271    process id.  */
00272 
00273 static void
00274 pid_to_prc (ptid_t *ptidp)
00275 {
00276   ptid_t ptid;
00277 
00278   ptid = *ptidp;
00279   if (PD_TID (ptid))
00280     *ptidp = pid_to_ptid (ptid_get_pid (ptid));
00281 }
00282 
00283 /* pthdb callback: for <i> from 0 to COUNT, set SYMBOLS[<i>].addr to
00284    the address of SYMBOLS[<i>].name.  */
00285 
00286 static int
00287 pdc_symbol_addrs (pthdb_user_t user, pthdb_symbol_t *symbols, int count)
00288 {
00289   struct minimal_symbol *ms;
00290   int i;
00291   char *name;
00292 
00293   if (debug_aix_thread)
00294     fprintf_unfiltered (gdb_stdlog,
00295       "pdc_symbol_addrs (user = %ld, symbols = 0x%lx, count = %d)\n",
00296       user, (long) symbols, count);
00297 
00298   for (i = 0; i < count; i++)
00299     {
00300       name = symbols[i].name;
00301       if (debug_aix_thread)
00302         fprintf_unfiltered (gdb_stdlog, 
00303                             "  symbols[%d].name = \"%s\"\n", i, name);
00304 
00305       if (!*name)
00306         symbols[i].addr = 0;
00307       else
00308         {
00309           if (!(ms = lookup_minimal_symbol (name, NULL, NULL)))
00310             {
00311               if (debug_aix_thread)
00312                 fprintf_unfiltered (gdb_stdlog, " returning PDC_FAILURE\n");
00313               return PDC_FAILURE;
00314             }
00315           symbols[i].addr = SYMBOL_VALUE_ADDRESS (ms);
00316         }
00317       if (debug_aix_thread)
00318         fprintf_unfiltered (gdb_stdlog, "  symbols[%d].addr = %s\n",
00319                             i, hex_string (symbols[i].addr));
00320     }
00321   if (debug_aix_thread)
00322     fprintf_unfiltered (gdb_stdlog, " returning PDC_SUCCESS\n");
00323   return PDC_SUCCESS;
00324 }
00325 
00326 /* Read registers call back function should be able to read the
00327    context information of a debuggee kernel thread from an active
00328    process or from a core file.  The information should be formatted
00329    in context64 form for both 32-bit and 64-bit process.  
00330    If successful return 0, else non-zero is returned.  */
00331 
00332 static int
00333 pdc_read_regs (pthdb_user_t user, 
00334                pthdb_tid_t tid,
00335                unsigned long long flags,
00336                pthdb_context_t *context)
00337 {
00338   /* This function doesn't appear to be used, so we could probably
00339    just return 0 here.  HOWEVER, if it is not defined, the OS will
00340    complain and several thread debug functions will fail.  In case
00341    this is needed, I have implemented what I think it should do,
00342    however this code is untested.  */
00343 
00344   uint64_t gprs64[ppc_num_gprs];
00345   uint32_t gprs32[ppc_num_gprs];
00346   double fprs[ppc_num_fprs];
00347   struct ptxsprs sprs64;
00348   struct ptsprs sprs32;
00349   
00350   if (debug_aix_thread)
00351     fprintf_unfiltered (gdb_stdlog, "pdc_read_regs tid=%d flags=%s\n",
00352                         (int) tid, hex_string (flags));
00353 
00354   /* General-purpose registers.  */
00355   if (flags & PTHDB_FLAG_GPRS)
00356     {
00357       if (arch64)
00358         {
00359           if (!ptrace64aix (PTT_READ_GPRS, tid, 
00360                             (unsigned long) gprs64, 0, NULL))
00361             memset (gprs64, 0, sizeof (gprs64));
00362           memcpy (context->gpr, gprs64, sizeof(gprs64));
00363         }
00364       else
00365         {
00366           if (!ptrace32 (PTT_READ_GPRS, tid, gprs32, 0, NULL))
00367             memset (gprs32, 0, sizeof (gprs32));
00368           memcpy (context->gpr, gprs32, sizeof(gprs32));
00369         }
00370     }
00371 
00372   /* Floating-point registers.  */
00373   if (flags & PTHDB_FLAG_FPRS)
00374     {
00375       if (!ptrace32 (PTT_READ_FPRS, tid, (addr_ptr) fprs, 0, NULL))
00376         memset (fprs, 0, sizeof (fprs));
00377       memcpy (context->fpr, fprs, sizeof(fprs));
00378     }
00379 
00380   /* Special-purpose registers.  */
00381   if (flags & PTHDB_FLAG_SPRS)
00382     {
00383       if (arch64)
00384         {
00385           if (!ptrace64aix (PTT_READ_SPRS, tid, 
00386                             (unsigned long) &sprs64, 0, NULL))
00387             memset (&sprs64, 0, sizeof (sprs64));
00388           memcpy (&context->msr, &sprs64, sizeof(sprs64));
00389         }
00390       else
00391         {
00392           if (!ptrace32 (PTT_READ_SPRS, tid, (addr_ptr) &sprs32, 0, NULL))
00393             memset (&sprs32, 0, sizeof (sprs32));
00394           memcpy (&context->msr, &sprs32, sizeof(sprs32));
00395         }
00396     }  
00397   return 0;
00398 }
00399 
00400 /* Write register function should be able to write requested context
00401    information to specified debuggee's kernel thread id.
00402    If successful return 0, else non-zero is returned.  */
00403 
00404 static int
00405 pdc_write_regs (pthdb_user_t user,
00406                 pthdb_tid_t tid,
00407                 unsigned long long flags,
00408                 pthdb_context_t *context)
00409 { 
00410   /* This function doesn't appear to be used, so we could probably
00411      just return 0 here.  HOWEVER, if it is not defined, the OS will
00412      complain and several thread debug functions will fail.  In case
00413      this is needed, I have implemented what I think it should do,
00414      however this code is untested.  */
00415 
00416   if (debug_aix_thread)
00417     fprintf_unfiltered (gdb_stdlog, "pdc_write_regs tid=%d flags=%s\n",
00418                         (int) tid, hex_string (flags));
00419 
00420   /* General-purpose registers.  */
00421   if (flags & PTHDB_FLAG_GPRS)
00422     {
00423       if (arch64)
00424         ptrace64aix (PTT_WRITE_GPRS, tid, 
00425                      (unsigned long) context->gpr, 0, NULL);
00426       else
00427         ptrace32 (PTT_WRITE_GPRS, tid, (addr_ptr) context->gpr, 0, NULL);
00428     }
00429 
00430  /* Floating-point registers.  */
00431   if (flags & PTHDB_FLAG_FPRS)
00432     {
00433       ptrace32 (PTT_WRITE_FPRS, tid, (addr_ptr) context->fpr, 0, NULL);
00434     }
00435 
00436   /* Special-purpose registers.  */
00437   if (flags & PTHDB_FLAG_SPRS)
00438     {
00439       if (arch64)
00440         {
00441           ptrace64aix (PTT_WRITE_SPRS, tid, 
00442                        (unsigned long) &context->msr, 0, NULL);
00443         }
00444       else
00445         {
00446           ptrace32 (PTT_WRITE_SPRS, tid, (addr_ptr) &context->msr, 0, NULL);
00447         }
00448     }
00449   return 0;
00450 }
00451 
00452 /* pthdb callback: read LEN bytes from process ADDR into BUF.  */
00453 
00454 static int
00455 pdc_read_data (pthdb_user_t user, void *buf, 
00456                pthdb_addr_t addr, size_t len)
00457 {
00458   int status, ret;
00459 
00460   if (debug_aix_thread)
00461     fprintf_unfiltered (gdb_stdlog,
00462       "pdc_read_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
00463       user, (long) buf, hex_string (addr), len);
00464 
00465   status = target_read_memory (addr, buf, len);
00466   ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
00467 
00468   if (debug_aix_thread)
00469     fprintf_unfiltered (gdb_stdlog, "  status=%d, returning %s\n",
00470                         status, pd_status2str (ret));
00471   return ret;
00472 }
00473 
00474 /* pthdb callback: write LEN bytes from BUF to process ADDR.  */
00475 
00476 static int
00477 pdc_write_data (pthdb_user_t user, void *buf, 
00478                 pthdb_addr_t addr, size_t len)
00479 {
00480   int status, ret;
00481 
00482   if (debug_aix_thread)
00483     fprintf_unfiltered (gdb_stdlog,
00484       "pdc_write_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
00485       user, (long) buf, hex_string (addr), len);
00486 
00487   status = target_write_memory (addr, buf, len);
00488   ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
00489 
00490   if (debug_aix_thread)
00491     fprintf_unfiltered (gdb_stdlog, "  status=%d, returning %s\n", status,
00492                         pd_status2str (ret));
00493   return ret;
00494 }
00495 
00496 /* pthdb callback: allocate a LEN-byte buffer and store a pointer to it
00497    in BUFP.  */
00498 
00499 static int
00500 pdc_alloc (pthdb_user_t user, size_t len, void **bufp)
00501 {
00502   if (debug_aix_thread)
00503     fprintf_unfiltered (gdb_stdlog,
00504                         "pdc_alloc (user = %ld, len = %ld, bufp = 0x%lx)\n",
00505                         user, len, (long) bufp);
00506   *bufp = xmalloc (len);
00507   if (debug_aix_thread)
00508     fprintf_unfiltered (gdb_stdlog, 
00509                         "  malloc returned 0x%lx\n", (long) *bufp);
00510 
00511   /* Note: xmalloc() can't return 0; therefore PDC_FAILURE will never
00512      be returned.  */
00513 
00514   return *bufp ? PDC_SUCCESS : PDC_FAILURE;
00515 }
00516 
00517 /* pthdb callback: reallocate BUF, which was allocated by the alloc or
00518    realloc callback, so that it contains LEN bytes, and store a
00519    pointer to the result in BUFP.  */
00520 
00521 static int
00522 pdc_realloc (pthdb_user_t user, void *buf, size_t len, void **bufp)
00523 {
00524   if (debug_aix_thread)
00525     fprintf_unfiltered (gdb_stdlog,
00526       "pdc_realloc (user = %ld, buf = 0x%lx, len = %ld, bufp = 0x%lx)\n",
00527       user, (long) buf, len, (long) bufp);
00528   *bufp = xrealloc (buf, len);
00529   if (debug_aix_thread)
00530     fprintf_unfiltered (gdb_stdlog, 
00531                         "  realloc returned 0x%lx\n", (long) *bufp);
00532   return *bufp ? PDC_SUCCESS : PDC_FAILURE;
00533 }
00534 
00535 /* pthdb callback: free BUF, which was allocated by the alloc or
00536    realloc callback.  */
00537 
00538 static int
00539 pdc_dealloc (pthdb_user_t user, void *buf)
00540 {
00541   if (debug_aix_thread)
00542     fprintf_unfiltered (gdb_stdlog, 
00543                         "pdc_free (user = %ld, buf = 0x%lx)\n", user,
00544                         (long) buf);
00545   xfree (buf);
00546   return PDC_SUCCESS;
00547 }
00548 
00549 /* Return a printable representation of pthread STATE.  */
00550 
00551 static char *
00552 state2str (pthdb_state_t state)
00553 {
00554   switch (state)
00555     {
00556     case PST_IDLE:
00557       /* i18n: Like "Thread-Id %d, [state] idle" */
00558       return _("idle");      /* being created */
00559     case PST_RUN:
00560       /* i18n: Like "Thread-Id %d, [state] running" */
00561       return _("running");   /* running */
00562     case PST_SLEEP:
00563       /* i18n: Like "Thread-Id %d, [state] sleeping" */
00564       return _("sleeping");  /* awaiting an event */
00565     case PST_READY:
00566       /* i18n: Like "Thread-Id %d, [state] ready" */
00567       return _("ready");     /* runnable */
00568     case PST_TERM:
00569       /* i18n: Like "Thread-Id %d, [state] finished" */
00570       return _("finished");  /* awaiting a join/detach */
00571     default:
00572       /* i18n: Like "Thread-Id %d, [state] unknown" */
00573       return _("unknown");
00574     }
00575 }
00576 
00577 /* qsort() comparison function for sorting pd_thread structs by pthid.  */
00578 
00579 static int
00580 pcmp (const void *p1v, const void *p2v)
00581 {
00582   struct pd_thread *p1 = (struct pd_thread *) p1v;
00583   struct pd_thread *p2 = (struct pd_thread *) p2v;
00584   return p1->pthid < p2->pthid ? -1 : p1->pthid > p2->pthid;
00585 }
00586 
00587 /* iterate_over_threads() callback for counting GDB threads.
00588 
00589    Do not count the main thread (whose tid is zero).  This matches
00590    the list of threads provided by the pthreaddebug library, which
00591    does not include that main thread either, and thus allows us
00592    to compare the two lists.  */
00593 
00594 static int
00595 giter_count (struct thread_info *thread, void *countp)
00596 {
00597   if (PD_TID (thread->ptid))
00598     (*(int *) countp)++;
00599   return 0;
00600 }
00601 
00602 /* iterate_over_threads() callback for accumulating GDB thread pids.
00603 
00604    Do not include the main thread (whose tid is zero).  This matches
00605    the list of threads provided by the pthreaddebug library, which
00606    does not include that main thread either, and thus allows us
00607    to compare the two lists.  */
00608 
00609 static int
00610 giter_accum (struct thread_info *thread, void *bufp)
00611 {
00612   if (PD_TID (thread->ptid))
00613     {
00614       **(struct thread_info ***) bufp = thread;
00615       (*(struct thread_info ***) bufp)++;
00616     }
00617   return 0;
00618 }
00619 
00620 /* ptid comparison function */
00621 
00622 static int
00623 ptid_cmp (ptid_t ptid1, ptid_t ptid2)
00624 {
00625   int pid1, pid2;
00626 
00627   if (ptid_get_pid (ptid1) < ptid_get_pid (ptid2))
00628     return -1;
00629   else if (ptid_get_pid (ptid1) > ptid_get_pid (ptid2))
00630     return 1;
00631   else if (ptid_get_tid (ptid1) < ptid_get_tid (ptid2))
00632     return -1;
00633   else if (ptid_get_tid (ptid1) > ptid_get_tid (ptid2))
00634     return 1;
00635   else if (ptid_get_lwp (ptid1) < ptid_get_lwp (ptid2))
00636     return -1;
00637   else if (ptid_get_lwp (ptid1) > ptid_get_lwp (ptid2))
00638     return 1;
00639   else
00640     return 0;
00641 }
00642 
00643 /* qsort() comparison function for sorting thread_info structs by pid.  */
00644 
00645 static int
00646 gcmp (const void *t1v, const void *t2v)
00647 {
00648   struct thread_info *t1 = *(struct thread_info **) t1v;
00649   struct thread_info *t2 = *(struct thread_info **) t2v;
00650   return ptid_cmp (t1->ptid, t2->ptid);
00651 }
00652 
00653 /* Search through the list of all kernel threads for the thread
00654    that has stopped on a SIGTRAP signal, and return its TID.
00655    Return 0 if none found.  */
00656 
00657 static pthdb_tid_t
00658 get_signaled_thread (void)
00659 {
00660   struct thrdsinfo64 thrinf;
00661   tid_t ktid = 0;
00662   int result = 0;
00663 
00664   while (1)
00665   {
00666     if (getthrds (ptid_get_pid (inferior_ptid), &thrinf, 
00667                   sizeof (thrinf), &ktid, 1) != 1)
00668       break;
00669 
00670     if (thrinf.ti_cursig == SIGTRAP)
00671       return thrinf.ti_tid;
00672   }
00673 
00674   /* Didn't find any thread stopped on a SIGTRAP signal.  */
00675   return 0;
00676 }
00677 
00678 /* Synchronize GDB's thread list with libpthdebug's.
00679 
00680    There are some benefits of doing this every time the inferior stops:
00681 
00682      - allows users to run thread-specific commands without needing to
00683        run "info threads" first
00684 
00685      - helps pthdb_tid_pthread() work properly (see "libpthdebug
00686        peculiarities" at the top of this module)
00687 
00688      - simplifies the demands placed on libpthdebug, which seems to
00689        have difficulty with certain call patterns */
00690 
00691 static void
00692 sync_threadlists (void)
00693 {
00694   int cmd, status, infpid;
00695   int pcount, psize, pi, gcount, gi;
00696   struct pd_thread *pbuf;
00697   struct thread_info **gbuf, **g, *thread;
00698   pthdb_pthread_t pdtid;
00699   pthread_t pthid;
00700   pthdb_tid_t tid;
00701 
00702   /* Accumulate an array of libpthdebug threads sorted by pthread id.  */
00703 
00704   pcount = 0;
00705   psize = 1;
00706   pbuf = (struct pd_thread *) xmalloc (psize * sizeof *pbuf);
00707 
00708   for (cmd = PTHDB_LIST_FIRST;; cmd = PTHDB_LIST_NEXT)
00709     {
00710       status = pthdb_pthread (pd_session, &pdtid, cmd);
00711       if (status != PTHDB_SUCCESS || pdtid == PTHDB_INVALID_PTHREAD)
00712         break;
00713 
00714       status = pthdb_pthread_ptid (pd_session, pdtid, &pthid);
00715       if (status != PTHDB_SUCCESS || pthid == PTHDB_INVALID_PTID)
00716         continue;
00717 
00718       if (pcount == psize)
00719         {
00720           psize *= 2;
00721           pbuf = (struct pd_thread *) xrealloc (pbuf, 
00722                                                 psize * sizeof *pbuf);
00723         }
00724       pbuf[pcount].pdtid = pdtid;
00725       pbuf[pcount].pthid = pthid;
00726       pcount++;
00727     }
00728 
00729   for (pi = 0; pi < pcount; pi++)
00730     {
00731       status = pthdb_pthread_tid (pd_session, pbuf[pi].pdtid, &tid);
00732       if (status != PTHDB_SUCCESS)
00733         tid = PTHDB_INVALID_TID;
00734       pbuf[pi].tid = tid;
00735     }
00736 
00737   qsort (pbuf, pcount, sizeof *pbuf, pcmp);
00738 
00739   /* Accumulate an array of GDB threads sorted by pid.  */
00740 
00741   gcount = 0;
00742   iterate_over_threads (giter_count, &gcount);
00743   g = gbuf = (struct thread_info **) xmalloc (gcount * sizeof *gbuf);
00744   iterate_over_threads (giter_accum, &g);
00745   qsort (gbuf, gcount, sizeof *gbuf, gcmp);
00746 
00747   /* Apply differences between the two arrays to GDB's thread list.  */
00748 
00749   infpid = ptid_get_pid (inferior_ptid);
00750   for (pi = gi = 0; pi < pcount || gi < gcount;)
00751     {
00752       if (pi == pcount)
00753         {
00754           delete_thread (gbuf[gi]->ptid);
00755           gi++;
00756         }
00757       else if (gi == gcount)
00758         {
00759           thread = add_thread (ptid_build (infpid, 0, pbuf[pi].pthid));
00760           thread->private = xmalloc (sizeof (struct private_thread_info));
00761           thread->private->pdtid = pbuf[pi].pdtid;
00762           thread->private->tid = pbuf[pi].tid;
00763           pi++;
00764         }
00765       else
00766         {
00767           ptid_t pptid, gptid;
00768           int cmp_result;
00769 
00770           pptid = ptid_build (infpid, 0, pbuf[pi].pthid);
00771           gptid = gbuf[gi]->ptid;
00772           pdtid = pbuf[pi].pdtid;
00773           tid = pbuf[pi].tid;
00774 
00775           cmp_result = ptid_cmp (pptid, gptid);
00776 
00777           if (cmp_result == 0)
00778             {
00779               gbuf[gi]->private->pdtid = pdtid;
00780               gbuf[gi]->private->tid = tid;
00781               pi++;
00782               gi++;
00783             }
00784           else if (cmp_result > 0)
00785             {
00786               delete_thread (gptid);
00787               gi++;
00788             }
00789           else
00790             {
00791               thread = add_thread (pptid);
00792               thread->private = xmalloc (sizeof (struct private_thread_info));
00793               thread->private->pdtid = pdtid;
00794               thread->private->tid = tid;
00795               pi++;
00796             }
00797         }
00798     }
00799 
00800   xfree (pbuf);
00801   xfree (gbuf);
00802 }
00803 
00804 /* Iterate_over_threads() callback for locating a thread, using
00805    the TID of its associated kernel thread.  */
00806 
00807 static int
00808 iter_tid (struct thread_info *thread, void *tidp)
00809 {
00810   const pthdb_tid_t tid = *(pthdb_tid_t *)tidp;
00811 
00812   return (thread->private->tid == tid);
00813 }
00814 
00815 /* Synchronize libpthdebug's state with the inferior and with GDB,
00816    generate a composite process/thread <pid> for the current thread,
00817    set inferior_ptid to <pid> if SET_INFPID, and return <pid>.  */
00818 
00819 static ptid_t
00820 pd_update (int set_infpid)
00821 {
00822   int status;
00823   ptid_t ptid;
00824   pthdb_tid_t tid;
00825   struct thread_info *thread = NULL;
00826 
00827   if (!pd_active)
00828     return inferior_ptid;
00829 
00830   status = pthdb_session_update (pd_session);
00831   if (status != PTHDB_SUCCESS)
00832     return inferior_ptid;
00833 
00834   sync_threadlists ();
00835 
00836   /* Define "current thread" as one that just received a trap signal.  */
00837 
00838   tid = get_signaled_thread ();
00839   if (tid != 0)
00840     thread = iterate_over_threads (iter_tid, &tid);
00841   if (!thread)
00842     ptid = inferior_ptid;
00843   else
00844     {
00845       ptid = thread->ptid;
00846       if (set_infpid)
00847         inferior_ptid = ptid;
00848     }
00849   return ptid;
00850 }
00851 
00852 /* Try to start debugging threads in the current process.
00853    If successful and SET_INFPID, set inferior_ptid to reflect the
00854    current thread.  */
00855 
00856 static ptid_t
00857 pd_activate (int set_infpid)
00858 {
00859   int status;
00860                 
00861   status = pthdb_session_init (PD_USER, arch64 ? PEM_64BIT : PEM_32BIT,
00862                                PTHDB_FLAG_REGS, &pd_callbacks, 
00863                                &pd_session);
00864   if (status != PTHDB_SUCCESS)
00865     {
00866       return inferior_ptid;
00867     }
00868   pd_active = 1;
00869   return pd_update (set_infpid);
00870 }
00871 
00872 /* Undo the effects of pd_activate().  */
00873 
00874 static void
00875 pd_deactivate (void)
00876 {
00877   if (!pd_active)
00878     return;
00879   pthdb_session_destroy (pd_session);
00880   
00881   pid_to_prc (&inferior_ptid);
00882   pd_active = 0;
00883 }
00884 
00885 /* An object file has just been loaded.  Check whether the current
00886    application is pthreaded, and if so, prepare for thread debugging.  */
00887 
00888 static void
00889 pd_enable (void)
00890 {
00891   int status;
00892   char *stub_name;
00893   struct minimal_symbol *ms;
00894 
00895   /* Don't initialize twice.  */
00896   if (pd_able)
00897     return;
00898 
00899   /* Check application word size.  */
00900   arch64 = register_size (target_gdbarch (), 0) == 8;
00901 
00902   /* Check whether the application is pthreaded.  */
00903   stub_name = NULL;
00904   status = pthdb_session_pthreaded (PD_USER, PTHDB_FLAG_REGS,
00905                                     &pd_callbacks, &stub_name);
00906   if ((status != PTHDB_SUCCESS
00907        && status != PTHDB_NOT_PTHREADED) || !stub_name)
00908     return;
00909 
00910   /* Set a breakpoint on the returned stub function.  */
00911   if (!(ms = lookup_minimal_symbol (stub_name, NULL, NULL)))
00912     return;
00913   pd_brk_addr = SYMBOL_VALUE_ADDRESS (ms);
00914   if (!create_thread_event_breakpoint (target_gdbarch (), pd_brk_addr))
00915     return;
00916 
00917   /* Prepare for thread debugging.  */
00918   push_target (&aix_thread_ops);
00919   pd_able = 1;
00920 
00921   /* If we're debugging a core file or an attached inferior, the
00922      pthread library may already have been initialized, so try to
00923      activate thread debugging.  */
00924   pd_activate (1);
00925 }
00926 
00927 /* Undo the effects of pd_enable().  */
00928 
00929 static void
00930 pd_disable (void)
00931 {
00932   if (!pd_able)
00933     return;
00934   if (pd_active)
00935     pd_deactivate ();
00936   pd_able = 0;
00937   unpush_target (&aix_thread_ops);
00938 }
00939 
00940 /* new_objfile observer callback.
00941 
00942    If OBJFILE is non-null, check whether a threaded application is
00943    being debugged, and if so, prepare for thread debugging.
00944 
00945    If OBJFILE is null, stop debugging threads.  */
00946 
00947 static void
00948 new_objfile (struct objfile *objfile)
00949 {
00950   if (objfile)
00951     pd_enable ();
00952   else
00953     pd_disable ();
00954 }
00955 
00956 /* Attach to process specified by ARGS.  */
00957 
00958 static void
00959 aix_thread_attach (struct target_ops *ops, char *args, int from_tty)
00960 {
00961   struct target_ops *beneath = find_target_beneath (ops);
00962   
00963   beneath->to_attach (beneath, args, from_tty);
00964   pd_activate (1);
00965 }
00966 
00967 /* Detach from the process attached to by aix_thread_attach().  */
00968 
00969 static void
00970 aix_thread_detach (struct target_ops *ops, char *args, int from_tty)
00971 {
00972   struct target_ops *beneath = find_target_beneath (ops);
00973 
00974   pd_disable ();
00975   beneath->to_detach (beneath, args, from_tty);
00976 }
00977 
00978 /* Tell the inferior process to continue running thread PID if != -1
00979    and all threads otherwise.  */
00980 
00981 static void
00982 aix_thread_resume (struct target_ops *ops,
00983                    ptid_t ptid, int step, enum gdb_signal sig)
00984 {
00985   struct thread_info *thread;
00986   pthdb_tid_t tid[2];
00987 
00988   if (!PD_TID (ptid))
00989     {
00990       struct cleanup *cleanup = save_inferior_ptid ();
00991       struct target_ops *beneath = find_target_beneath (ops);
00992       
00993       inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
00994       beneath->to_resume (beneath, ptid, step, sig);
00995       do_cleanups (cleanup);
00996     }
00997   else
00998     {
00999       thread = find_thread_ptid (ptid);
01000       if (!thread)
01001         error (_("aix-thread resume: unknown pthread %ld"),
01002                ptid_get_lwp (ptid));
01003 
01004       tid[0] = thread->private->tid;
01005       if (tid[0] == PTHDB_INVALID_TID)
01006         error (_("aix-thread resume: no tid for pthread %ld"),
01007                ptid_get_lwp (ptid));
01008       tid[1] = 0;
01009 
01010       if (arch64)
01011         ptrace64aix (PTT_CONTINUE, tid[0], (long long) 1,
01012                      gdb_signal_to_host (sig), (void *) tid);
01013       else
01014         ptrace32 (PTT_CONTINUE, tid[0], (addr_ptr) 1,
01015                   gdb_signal_to_host (sig), (void *) tid);
01016     }
01017 }
01018 
01019 /* Wait for thread/process ID if != -1 or for any thread otherwise.
01020    If an error occurs, return -1, else return the pid of the stopped
01021    thread.  */
01022 
01023 static ptid_t
01024 aix_thread_wait (struct target_ops *ops,
01025                  ptid_t ptid, struct target_waitstatus *status, int options)
01026 {
01027   struct cleanup *cleanup = save_inferior_ptid ();
01028   struct target_ops *beneath = find_target_beneath (ops);
01029 
01030   pid_to_prc (&ptid);
01031 
01032   inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
01033   ptid = beneath->to_wait (beneath, ptid, status, options);
01034   do_cleanups (cleanup);
01035 
01036   if (ptid_get_pid (ptid) == -1)
01037     return pid_to_ptid (-1);
01038 
01039   /* Check whether libpthdebug might be ready to be initialized.  */
01040   if (!pd_active && status->kind == TARGET_WAITKIND_STOPPED
01041       && status->value.sig == GDB_SIGNAL_TRAP)
01042     {
01043       struct regcache *regcache = get_thread_regcache (ptid);
01044       struct gdbarch *gdbarch = get_regcache_arch (regcache);
01045 
01046       if (regcache_read_pc (regcache)
01047           - gdbarch_decr_pc_after_break (gdbarch) == pd_brk_addr)
01048         return pd_activate (0);
01049     }
01050 
01051   return pd_update (0);
01052 }
01053 
01054 /* Record that the 64-bit general-purpose registers contain VALS.  */
01055 
01056 static void
01057 supply_gprs64 (struct regcache *regcache, uint64_t *vals)
01058 {
01059   struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
01060   int regno;
01061 
01062   for (regno = 0; regno < ppc_num_gprs; regno++)
01063     regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + regno,
01064                          (char *) (vals + regno));
01065 }
01066 
01067 /* Record that 32-bit register REGNO contains VAL.  */
01068 
01069 static void
01070 supply_reg32 (struct regcache *regcache, int regno, uint32_t val)
01071 {
01072   regcache_raw_supply (regcache, regno, (char *) &val);
01073 }
01074 
01075 /* Record that the floating-point registers contain VALS.  */
01076 
01077 static void
01078 supply_fprs (struct regcache *regcache, double *vals)
01079 {
01080   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01081   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01082   int regno;
01083 
01084   /* This function should never be called on architectures without
01085      floating-point registers.  */
01086   gdb_assert (ppc_floating_point_unit_p (gdbarch));
01087 
01088   for (regno = tdep->ppc_fp0_regnum;
01089        regno < tdep->ppc_fp0_regnum + ppc_num_fprs;
01090        regno++)
01091     regcache_raw_supply (regcache, regno,
01092                          (char *) (vals + regno - tdep->ppc_fp0_regnum));
01093 }
01094 
01095 /* Predicate to test whether given register number is a "special" register.  */
01096 static int
01097 special_register_p (struct gdbarch *gdbarch, int regno)
01098 {
01099   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01100 
01101   return regno == gdbarch_pc_regnum (gdbarch)
01102       || regno == tdep->ppc_ps_regnum
01103       || regno == tdep->ppc_cr_regnum
01104       || regno == tdep->ppc_lr_regnum
01105       || regno == tdep->ppc_ctr_regnum
01106       || regno == tdep->ppc_xer_regnum
01107       || (tdep->ppc_fpscr_regnum >= 0 && regno == tdep->ppc_fpscr_regnum)
01108       || (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum);
01109 }
01110 
01111 
01112 /* Record that the special registers contain the specified 64-bit and
01113    32-bit values.  */
01114 
01115 static void
01116 supply_sprs64 (struct regcache *regcache,
01117                uint64_t iar, uint64_t msr, uint32_t cr,
01118                uint64_t lr, uint64_t ctr, uint32_t xer,
01119                uint32_t fpscr)
01120 {
01121   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01122   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01123 
01124   regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch),
01125                        (char *) &iar);
01126   regcache_raw_supply (regcache, tdep->ppc_ps_regnum, (char *) &msr);
01127   regcache_raw_supply (regcache, tdep->ppc_cr_regnum, (char *) &cr);
01128   regcache_raw_supply (regcache, tdep->ppc_lr_regnum, (char *) &lr);
01129   regcache_raw_supply (regcache, tdep->ppc_ctr_regnum, (char *) &ctr);
01130   regcache_raw_supply (regcache, tdep->ppc_xer_regnum, (char *) &xer);
01131   if (tdep->ppc_fpscr_regnum >= 0)
01132     regcache_raw_supply (regcache, tdep->ppc_fpscr_regnum,
01133                          (char *) &fpscr);
01134 }
01135 
01136 /* Record that the special registers contain the specified 32-bit
01137    values.  */
01138 
01139 static void
01140 supply_sprs32 (struct regcache *regcache,
01141                uint32_t iar, uint32_t msr, uint32_t cr,
01142                uint32_t lr, uint32_t ctr, uint32_t xer,
01143                uint32_t fpscr)
01144 {
01145   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01146   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01147 
01148   regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch),
01149                        (char *) &iar);
01150   regcache_raw_supply (regcache, tdep->ppc_ps_regnum, (char *) &msr);
01151   regcache_raw_supply (regcache, tdep->ppc_cr_regnum, (char *) &cr);
01152   regcache_raw_supply (regcache, tdep->ppc_lr_regnum, (char *) &lr);
01153   regcache_raw_supply (regcache, tdep->ppc_ctr_regnum, (char *) &ctr);
01154   regcache_raw_supply (regcache, tdep->ppc_xer_regnum, (char *) &xer);
01155   if (tdep->ppc_fpscr_regnum >= 0)
01156     regcache_raw_supply (regcache, tdep->ppc_fpscr_regnum,
01157                          (char *) &fpscr);
01158 }
01159 
01160 /* Fetch all registers from pthread PDTID, which doesn't have a kernel
01161    thread.
01162 
01163    There's no way to query a single register from a non-kernel
01164    pthread, so there's no need for a single-register version of this
01165    function.  */
01166 
01167 static void
01168 fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
01169 {
01170   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01171   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01172   int status, i;
01173   pthdb_context_t ctx;
01174 
01175   if (debug_aix_thread)
01176     fprintf_unfiltered (gdb_stdlog, 
01177                         "fetch_regs_user_thread %lx\n", (long) pdtid);
01178   status = pthdb_pthread_context (pd_session, pdtid, &ctx);
01179   if (status != PTHDB_SUCCESS)
01180     error (_("aix-thread: fetch_registers: pthdb_pthread_context returned %s"),
01181            pd_status2str (status));
01182 
01183   /* General-purpose registers.  */
01184 
01185   if (arch64)
01186     supply_gprs64 (regcache, ctx.gpr);
01187   else
01188     for (i = 0; i < ppc_num_gprs; i++)
01189       supply_reg32 (regcache, tdep->ppc_gp0_regnum + i, ctx.gpr[i]);
01190 
01191   /* Floating-point registers.  */
01192 
01193   if (ppc_floating_point_unit_p (gdbarch))
01194     supply_fprs (regcache, ctx.fpr);
01195 
01196   /* Special registers.  */
01197 
01198   if (arch64)
01199     supply_sprs64 (regcache, ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr,
01200                              ctx.xer, ctx.fpscr);
01201   else
01202     supply_sprs32 (regcache, ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr,
01203                              ctx.xer, ctx.fpscr);
01204 }
01205 
01206 /* Fetch register REGNO if != -1 or all registers otherwise from
01207    kernel thread TID.
01208 
01209    AIX provides a way to query all of a kernel thread's GPRs, FPRs, or
01210    SPRs, but there's no way to query individual registers within those
01211    groups.  Therefore, if REGNO != -1, this function fetches an entire
01212    group.
01213 
01214    Unfortunately, kernel thread register queries often fail with
01215    EPERM, indicating that the thread is in kernel space.  This breaks
01216    backtraces of threads other than the current one.  To make that
01217    breakage obvious without throwing an error to top level (which is
01218    bad e.g. during "info threads" output), zero registers that can't
01219    be retrieved.  */
01220 
01221 static void
01222 fetch_regs_kernel_thread (struct regcache *regcache, int regno,
01223                           pthdb_tid_t tid)
01224 {
01225   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01226   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01227   uint64_t gprs64[ppc_num_gprs];
01228   uint32_t gprs32[ppc_num_gprs];
01229   double fprs[ppc_num_fprs];
01230   struct ptxsprs sprs64;
01231   struct ptsprs sprs32;
01232   int i;
01233 
01234   if (debug_aix_thread)
01235     fprintf_unfiltered (gdb_stdlog,
01236         "fetch_regs_kernel_thread tid=%lx regno=%d arch64=%d\n",
01237         (long) tid, regno, arch64);
01238 
01239   /* General-purpose registers.  */
01240   if (regno == -1
01241       || (tdep->ppc_gp0_regnum <= regno
01242           && regno < tdep->ppc_gp0_regnum + ppc_num_gprs))
01243     {
01244       if (arch64)
01245         {
01246           if (!ptrace64aix (PTT_READ_GPRS, tid, 
01247                             (unsigned long) gprs64, 0, NULL))
01248             memset (gprs64, 0, sizeof (gprs64));
01249           supply_gprs64 (regcache, gprs64);
01250         }
01251       else
01252         {
01253           if (!ptrace32 (PTT_READ_GPRS, tid, (addr_ptr) gprs32, 0, NULL))
01254             memset (gprs32, 0, sizeof (gprs32));
01255           for (i = 0; i < ppc_num_gprs; i++)
01256             supply_reg32 (regcache, tdep->ppc_gp0_regnum + i, gprs32[i]);
01257         }
01258     }
01259 
01260   /* Floating-point registers.  */
01261 
01262   if (ppc_floating_point_unit_p (gdbarch)
01263       && (regno == -1
01264           || (regno >= tdep->ppc_fp0_regnum
01265               && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
01266     {
01267       if (!ptrace32 (PTT_READ_FPRS, tid, (addr_ptr) fprs, 0, NULL))
01268         memset (fprs, 0, sizeof (fprs));
01269       supply_fprs (regcache, fprs);
01270     }
01271 
01272   /* Special-purpose registers.  */
01273 
01274   if (regno == -1 || special_register_p (gdbarch, regno))
01275     {
01276       if (arch64)
01277         {
01278           if (!ptrace64aix (PTT_READ_SPRS, tid, 
01279                             (unsigned long) &sprs64, 0, NULL))
01280             memset (&sprs64, 0, sizeof (sprs64));
01281           supply_sprs64 (regcache, sprs64.pt_iar, sprs64.pt_msr,
01282                          sprs64.pt_cr, sprs64.pt_lr, sprs64.pt_ctr,
01283                          sprs64.pt_xer, sprs64.pt_fpscr);
01284         }
01285       else
01286         {
01287           struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01288 
01289           if (!ptrace32 (PTT_READ_SPRS, tid, (addr_ptr) &sprs32, 0, NULL))
01290             memset (&sprs32, 0, sizeof (sprs32));
01291           supply_sprs32 (regcache, sprs32.pt_iar, sprs32.pt_msr, sprs32.pt_cr,
01292                          sprs32.pt_lr, sprs32.pt_ctr, sprs32.pt_xer,
01293                          sprs32.pt_fpscr);
01294 
01295           if (tdep->ppc_mq_regnum >= 0)
01296             regcache_raw_supply (regcache, tdep->ppc_mq_regnum,
01297                                  (char *) &sprs32.pt_mq);
01298         }
01299     }
01300 }
01301 
01302 /* Fetch register REGNO if != -1 or all registers otherwise in the
01303    thread/process specified by inferior_ptid.  */
01304 
01305 static void
01306 aix_thread_fetch_registers (struct target_ops *ops,
01307                             struct regcache *regcache, int regno)
01308 {
01309   struct thread_info *thread;
01310   pthdb_tid_t tid;
01311   struct target_ops *beneath = find_target_beneath (ops);
01312 
01313   if (!PD_TID (inferior_ptid))
01314     beneath->to_fetch_registers (beneath, regcache, regno);
01315   else
01316     {
01317       thread = find_thread_ptid (inferior_ptid);
01318       tid = thread->private->tid;
01319 
01320       if (tid == PTHDB_INVALID_TID)
01321         fetch_regs_user_thread (regcache, thread->private->pdtid);
01322       else
01323         fetch_regs_kernel_thread (regcache, regno, tid);
01324     }
01325 }
01326 
01327 /* Store the gp registers into an array of uint32_t or uint64_t.  */
01328 
01329 static void
01330 fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
01331 {
01332   struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
01333   int regno;
01334 
01335   for (regno = 0; regno < ppc_num_gprs; regno++)
01336     if (REG_VALID == regcache_register_status (regcache,
01337                                                tdep->ppc_gp0_regnum + regno))
01338       regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + regno,
01339                             vals + regno);
01340 }
01341 
01342 static void 
01343 fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
01344 {
01345   struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
01346   int regno;
01347 
01348   for (regno = 0; regno < ppc_num_gprs; regno++)
01349     if (REG_VALID == regcache_register_status (regcache,
01350                                                tdep->ppc_gp0_regnum + regno))
01351       regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + regno,
01352                             vals + regno);
01353 }
01354 
01355 /* Store the floating point registers into a double array.  */
01356 static void
01357 fill_fprs (const struct regcache *regcache, double *vals)
01358 {
01359   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01360   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01361   int regno;
01362 
01363   /* This function should never be called on architectures without
01364      floating-point registers.  */
01365   gdb_assert (ppc_floating_point_unit_p (gdbarch));
01366 
01367   for (regno = tdep->ppc_fp0_regnum;
01368        regno < tdep->ppc_fp0_regnum + ppc_num_fprs;
01369        regno++)
01370     if (REG_VALID == regcache_register_status (regcache, regno))
01371       regcache_raw_collect (regcache, regno,
01372                             vals + regno - tdep->ppc_fp0_regnum);
01373 }
01374 
01375 /* Store the special registers into the specified 64-bit and 32-bit
01376    locations.  */
01377 
01378 static void
01379 fill_sprs64 (const struct regcache *regcache,
01380              uint64_t *iar, uint64_t *msr, uint32_t *cr,
01381              uint64_t *lr, uint64_t *ctr, uint32_t *xer,
01382              uint32_t *fpscr)
01383 {
01384   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01385   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01386 
01387   /* Verify that the size of the size of the IAR buffer is the
01388      same as the raw size of the PC (in the register cache).  If
01389      they're not, then either GDB has been built incorrectly, or
01390      there's some other kind of internal error.  To be really safe,
01391      we should check all of the sizes.   */
01392   gdb_assert (sizeof (*iar) == register_size
01393                                  (gdbarch, gdbarch_pc_regnum (gdbarch)));
01394 
01395   if (REG_VALID == regcache_register_status (regcache,
01396                                              gdbarch_pc_regnum (gdbarch)))
01397     regcache_raw_collect (regcache, gdbarch_pc_regnum (gdbarch), iar);
01398   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum))
01399     regcache_raw_collect (regcache, tdep->ppc_ps_regnum, msr);
01400   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum))
01401     regcache_raw_collect (regcache, tdep->ppc_cr_regnum, cr);
01402   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum))
01403     regcache_raw_collect (regcache, tdep->ppc_lr_regnum, lr);
01404   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ctr_regnum))
01405     regcache_raw_collect (regcache, tdep->ppc_ctr_regnum, ctr);
01406   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_xer_regnum))
01407     regcache_raw_collect (regcache, tdep->ppc_xer_regnum, xer);
01408   if (tdep->ppc_fpscr_regnum >= 0
01409       && REG_VALID == regcache_register_status (regcache,
01410                                                 tdep->ppc_fpscr_regnum))
01411     regcache_raw_collect (regcache, tdep->ppc_fpscr_regnum, fpscr);
01412 }
01413 
01414 static void
01415 fill_sprs32 (const struct regcache *regcache,
01416              uint32_t *iar, uint32_t *msr, uint32_t *cr,
01417              uint32_t *lr, uint32_t *ctr, uint32_t *xer,
01418              uint32_t *fpscr)
01419 {
01420   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01421   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01422 
01423   /* Verify that the size of the size of the IAR buffer is the
01424      same as the raw size of the PC (in the register cache).  If
01425      they're not, then either GDB has been built incorrectly, or
01426      there's some other kind of internal error.  To be really safe,
01427      we should check all of the sizes.  */
01428   gdb_assert (sizeof (*iar) == register_size (gdbarch,
01429                                               gdbarch_pc_regnum (gdbarch)));
01430 
01431   if (REG_VALID == regcache_register_status (regcache,
01432                                              gdbarch_pc_regnum (gdbarch)))
01433     regcache_raw_collect (regcache, gdbarch_pc_regnum (gdbarch), iar);
01434   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum))
01435     regcache_raw_collect (regcache, tdep->ppc_ps_regnum, msr);
01436   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum))
01437     regcache_raw_collect (regcache, tdep->ppc_cr_regnum, cr);
01438   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum))
01439     regcache_raw_collect (regcache, tdep->ppc_lr_regnum, lr);
01440   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ctr_regnum))
01441     regcache_raw_collect (regcache, tdep->ppc_ctr_regnum, ctr);
01442   if (REG_VALID == regcache_register_status (regcache, tdep->ppc_xer_regnum))
01443     regcache_raw_collect (regcache, tdep->ppc_xer_regnum, xer);
01444   if (tdep->ppc_fpscr_regnum >= 0
01445       && REG_VALID == regcache_register_status (regcache, tdep->ppc_fpscr_regnum))
01446     regcache_raw_collect (regcache, tdep->ppc_fpscr_regnum, fpscr);
01447 }
01448 
01449 /* Store all registers into pthread PDTID, which doesn't have a kernel
01450    thread.
01451 
01452    It's possible to store a single register into a non-kernel pthread,
01453    but I doubt it's worth the effort.  */
01454 
01455 static void
01456 store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
01457 {
01458   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01459   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01460   int status, i;
01461   pthdb_context_t ctx;
01462   uint32_t int32;
01463   uint64_t int64;
01464   double   dbl;
01465 
01466   if (debug_aix_thread)
01467     fprintf_unfiltered (gdb_stdlog, 
01468                         "store_regs_user_thread %lx\n", (long) pdtid);
01469 
01470   /* Retrieve the thread's current context for its non-register
01471      values.  */
01472   status = pthdb_pthread_context (pd_session, pdtid, &ctx);
01473   if (status != PTHDB_SUCCESS)
01474     error (_("aix-thread: store_registers: pthdb_pthread_context returned %s"),
01475            pd_status2str (status));
01476 
01477   /* Collect general-purpose register values from the regcache.  */
01478 
01479   for (i = 0; i < ppc_num_gprs; i++)
01480     if (REG_VALID == regcache_register_status (regcache,
01481                                                tdep->ppc_gp0_regnum + i))
01482       {
01483         if (arch64)
01484           {
01485             regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + i,
01486                                   (void *) &int64);
01487             ctx.gpr[i] = int64;
01488           }
01489         else
01490           {
01491             regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + i,
01492                                   (void *) &int32);
01493             ctx.gpr[i] = int32;
01494           }
01495       }
01496 
01497   /* Collect floating-point register values from the regcache.  */
01498   if (ppc_floating_point_unit_p (gdbarch))
01499     fill_fprs (regcache, ctx.fpr);
01500 
01501   /* Special registers (always kept in ctx as 64 bits).  */
01502   if (arch64)
01503     {
01504       fill_sprs64 (regcache, &ctx.iar, &ctx.msr, &ctx.cr, &ctx.lr, &ctx.ctr,
01505                              &ctx.xer, &ctx.fpscr);
01506     }
01507   else
01508     {
01509       /* Problem: ctx.iar etc. are 64 bits, but raw_registers are 32.
01510          Solution: use 32-bit temp variables.  */
01511       uint32_t tmp_iar, tmp_msr, tmp_cr, tmp_lr, tmp_ctr, tmp_xer,
01512                tmp_fpscr;
01513 
01514       fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr, &tmp_ctr,
01515                              &tmp_xer, &tmp_fpscr);
01516       if (REG_VALID == regcache_register_status (regcache,
01517                                                  gdbarch_pc_regnum (gdbarch)))
01518         ctx.iar = tmp_iar;
01519       if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum))
01520         ctx.msr = tmp_msr;
01521       if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum))
01522         ctx.cr  = tmp_cr;
01523       if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum))
01524         ctx.lr  = tmp_lr;
01525       if (REG_VALID == regcache_register_status (regcache,
01526                                                  tdep->ppc_ctr_regnum))
01527         ctx.ctr = tmp_ctr;
01528       if (REG_VALID == regcache_register_status (regcache,
01529                                                  tdep->ppc_xer_regnum))
01530         ctx.xer = tmp_xer;
01531       if (REG_VALID == regcache_register_status (regcache,
01532                                                  tdep->ppc_xer_regnum))
01533         ctx.fpscr = tmp_fpscr;
01534     }
01535 
01536   status = pthdb_pthread_setcontext (pd_session, pdtid, &ctx);
01537   if (status != PTHDB_SUCCESS)
01538     error (_("aix-thread: store_registers: "
01539              "pthdb_pthread_setcontext returned %s"),
01540            pd_status2str (status));
01541 }
01542 
01543 /* Store register REGNO if != -1 or all registers otherwise into
01544    kernel thread TID.
01545 
01546    AIX provides a way to set all of a kernel thread's GPRs, FPRs, or
01547    SPRs, but there's no way to set individual registers within those
01548    groups.  Therefore, if REGNO != -1, this function stores an entire
01549    group.  */
01550 
01551 static void
01552 store_regs_kernel_thread (const struct regcache *regcache, int regno,
01553                           pthdb_tid_t tid)
01554 {
01555   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01556   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01557   uint64_t gprs64[ppc_num_gprs];
01558   uint32_t gprs32[ppc_num_gprs];
01559   double fprs[ppc_num_fprs];
01560   struct ptxsprs sprs64;
01561   struct ptsprs  sprs32;
01562   int i;
01563 
01564   if (debug_aix_thread)
01565     fprintf_unfiltered (gdb_stdlog, 
01566                         "store_regs_kernel_thread tid=%lx regno=%d\n",
01567                         (long) tid, regno);
01568 
01569   /* General-purpose registers.  */
01570   if (regno == -1
01571       || (tdep->ppc_gp0_regnum <= regno
01572           && regno < tdep->ppc_gp0_regnum + ppc_num_fprs))
01573     {
01574       if (arch64)
01575         {
01576           /* Pre-fetch: some regs may not be in the cache.  */
01577           ptrace64aix (PTT_READ_GPRS, tid, (unsigned long) gprs64, 0, NULL);
01578           fill_gprs64 (regcache, gprs64);
01579           ptrace64aix (PTT_WRITE_GPRS, tid, (unsigned long) gprs64, 0, NULL);
01580         }
01581       else
01582         {
01583           /* Pre-fetch: some regs may not be in the cache.  */
01584           ptrace32 (PTT_READ_GPRS, tid, (addr_ptr) gprs32, 0, NULL);
01585           fill_gprs32 (regcache, gprs32);
01586           ptrace32 (PTT_WRITE_GPRS, tid, (addr_ptr) gprs32, 0, NULL);
01587         }
01588     }
01589 
01590   /* Floating-point registers.  */
01591 
01592   if (ppc_floating_point_unit_p (gdbarch)
01593       && (regno == -1
01594           || (regno >= tdep->ppc_fp0_regnum
01595               && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
01596     {
01597       /* Pre-fetch: some regs may not be in the cache.  */
01598       ptrace32 (PTT_READ_FPRS, tid, (addr_ptr) fprs, 0, NULL);
01599       fill_fprs (regcache, fprs);
01600       ptrace32 (PTT_WRITE_FPRS, tid, (addr_ptr) fprs, 0, NULL);
01601     }
01602 
01603   /* Special-purpose registers.  */
01604 
01605   if (regno == -1 || special_register_p (gdbarch, regno))
01606     {
01607       if (arch64)
01608         {
01609           /* Pre-fetch: some registers won't be in the cache.  */
01610           ptrace64aix (PTT_READ_SPRS, tid, 
01611                        (unsigned long) &sprs64, 0, NULL);
01612           fill_sprs64 (regcache, &sprs64.pt_iar, &sprs64.pt_msr,
01613                        &sprs64.pt_cr, &sprs64.pt_lr, &sprs64.pt_ctr,
01614                        &sprs64.pt_xer, &sprs64.pt_fpscr);
01615           ptrace64aix (PTT_WRITE_SPRS, tid, 
01616                        (unsigned long) &sprs64, 0, NULL);
01617         }
01618       else
01619         {
01620           /* The contents of "struct ptspr" were declared as "unsigned
01621              long" up to AIX 5.2, but are "unsigned int" since 5.3.
01622              Use temporaries to work around this problem.  Also, add an
01623              assert here to make sure we fail if the system header files
01624              use "unsigned long", and the size of that type is not what
01625              the headers expect.  */
01626           uint32_t tmp_iar, tmp_msr, tmp_cr, tmp_lr, tmp_ctr, tmp_xer,
01627                    tmp_fpscr;
01628 
01629           gdb_assert (sizeof (sprs32.pt_iar) == 4);
01630 
01631           /* Pre-fetch: some registers won't be in the cache.  */
01632           ptrace32 (PTT_READ_SPRS, tid, (addr_ptr) &sprs32, 0, NULL);
01633 
01634           fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr,
01635                        &tmp_ctr, &tmp_xer, &tmp_fpscr);
01636 
01637           sprs32.pt_iar = tmp_iar;
01638           sprs32.pt_msr = tmp_msr;
01639           sprs32.pt_cr = tmp_cr;
01640           sprs32.pt_lr = tmp_lr;
01641           sprs32.pt_ctr = tmp_ctr;
01642           sprs32.pt_xer = tmp_xer;
01643           sprs32.pt_fpscr = tmp_fpscr;
01644 
01645           if (tdep->ppc_mq_regnum >= 0)
01646             if (REG_VALID == regcache_register_status (regcache,
01647                                                        tdep->ppc_mq_regnum))
01648               regcache_raw_collect (regcache, tdep->ppc_mq_regnum,
01649                                     &sprs32.pt_mq);
01650 
01651           ptrace32 (PTT_WRITE_SPRS, tid, (addr_ptr) &sprs32, 0, NULL);
01652         }
01653     }
01654 }
01655 
01656 /* Store gdb's current view of the register set into the
01657    thread/process specified by inferior_ptid.  */
01658 
01659 static void
01660 aix_thread_store_registers (struct target_ops *ops,
01661                             struct regcache *regcache, int regno)
01662 {
01663   struct thread_info *thread;
01664   pthdb_tid_t tid;
01665   struct target_ops *beneath = find_target_beneath (ops);
01666 
01667   if (!PD_TID (inferior_ptid))
01668     beneath->to_store_registers (beneath, regcache, regno);
01669   else
01670     {
01671       thread = find_thread_ptid (inferior_ptid);
01672       tid = thread->private->tid;
01673 
01674       if (tid == PTHDB_INVALID_TID)
01675         store_regs_user_thread (regcache, thread->private->pdtid);
01676       else
01677         store_regs_kernel_thread (regcache, regno, tid);
01678     }
01679 }
01680 
01681 /* Attempt a transfer all LEN bytes starting at OFFSET between the
01682    inferior's OBJECT:ANNEX space and GDB's READBUF/WRITEBUF buffer.
01683    Return the number of bytes actually transferred.  */
01684 
01685 static LONGEST
01686 aix_thread_xfer_partial (struct target_ops *ops, enum target_object object,
01687                          const char *annex, gdb_byte *readbuf,
01688                          const gdb_byte *writebuf,
01689                          ULONGEST offset, LONGEST len)
01690 {
01691   struct cleanup *old_chain = save_inferior_ptid ();
01692   LONGEST xfer;
01693   struct target_ops *beneath = find_target_beneath (ops);
01694 
01695   inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
01696   xfer = beneath->to_xfer_partial (beneath, object, annex,
01697                                    readbuf, writebuf, offset, len);
01698 
01699   do_cleanups (old_chain);
01700   return xfer;
01701 }
01702 
01703 /* Clean up after the inferior exits.  */
01704 
01705 static void
01706 aix_thread_mourn_inferior (struct target_ops *ops)
01707 {
01708   struct target_ops *beneath = find_target_beneath (ops);
01709 
01710   pd_deactivate ();
01711   beneath->to_mourn_inferior (beneath);
01712 }
01713 
01714 /* Return whether thread PID is still valid.  */
01715 
01716 static int
01717 aix_thread_thread_alive (struct target_ops *ops, ptid_t ptid)
01718 {
01719   struct target_ops *beneath = find_target_beneath (ops);
01720 
01721   if (!PD_TID (ptid))
01722     return beneath->to_thread_alive (beneath, ptid);
01723 
01724   /* We update the thread list every time the child stops, so all
01725      valid threads should be in the thread list.  */
01726   return in_thread_list (ptid);
01727 }
01728 
01729 /* Return a printable representation of composite PID for use in
01730    "info threads" output.  */
01731 
01732 static char *
01733 aix_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
01734 {
01735   static char *ret = NULL;
01736   struct target_ops *beneath = find_target_beneath (ops);
01737 
01738   if (!PD_TID (ptid))
01739     return beneath->to_pid_to_str (beneath, ptid);
01740 
01741   /* Free previous return value; a new one will be allocated by
01742      xstrprintf().  */
01743   xfree (ret);
01744 
01745   ret = xstrprintf (_("Thread %ld"), ptid_get_tid (ptid));
01746   return ret;
01747 }
01748 
01749 /* Return a printable representation of extra information about
01750    THREAD, for use in "info threads" output.  */
01751 
01752 static char *
01753 aix_thread_extra_thread_info (struct thread_info *thread)
01754 {
01755   struct ui_file *buf;
01756   int status;
01757   pthdb_pthread_t pdtid;
01758   pthdb_tid_t tid;
01759   pthdb_state_t state;
01760   pthdb_suspendstate_t suspendstate;
01761   pthdb_detachstate_t detachstate;
01762   int cancelpend;
01763   static char *ret = NULL;
01764 
01765   if (!PD_TID (thread->ptid))
01766     return NULL;
01767 
01768   buf = mem_fileopen ();
01769 
01770   pdtid = thread->private->pdtid;
01771   tid = thread->private->tid;
01772 
01773   if (tid != PTHDB_INVALID_TID)
01774     /* i18n: Like "thread-identifier %d, [state] running, suspended" */
01775     fprintf_unfiltered (buf, _("tid %d"), (int)tid);
01776 
01777   status = pthdb_pthread_state (pd_session, pdtid, &state);
01778   if (status != PTHDB_SUCCESS)
01779     state = PST_NOTSUP;
01780   fprintf_unfiltered (buf, ", %s", state2str (state));
01781 
01782   status = pthdb_pthread_suspendstate (pd_session, pdtid, 
01783                                        &suspendstate);
01784   if (status == PTHDB_SUCCESS && suspendstate == PSS_SUSPENDED)
01785     /* i18n: Like "Thread-Id %d, [state] running, suspended" */
01786     fprintf_unfiltered (buf, _(", suspended"));
01787 
01788   status = pthdb_pthread_detachstate (pd_session, pdtid, 
01789                                       &detachstate);
01790   if (status == PTHDB_SUCCESS && detachstate == PDS_DETACHED)
01791     /* i18n: Like "Thread-Id %d, [state] running, detached" */
01792     fprintf_unfiltered (buf, _(", detached"));
01793 
01794   pthdb_pthread_cancelpend (pd_session, pdtid, &cancelpend);
01795   if (status == PTHDB_SUCCESS && cancelpend)
01796     /* i18n: Like "Thread-Id %d, [state] running, cancel pending" */
01797     fprintf_unfiltered (buf, _(", cancel pending"));
01798 
01799   ui_file_write (buf, "", 1);
01800 
01801   xfree (ret);                  /* Free old buffer.  */
01802 
01803   ret = ui_file_xstrdup (buf, NULL);
01804   ui_file_delete (buf);
01805 
01806   return ret;
01807 }
01808 
01809 static ptid_t
01810 aix_thread_get_ada_task_ptid (long lwp, long thread)
01811 {
01812   return ptid_build (ptid_get_pid (inferior_ptid), 0, thread);
01813 }
01814 
01815 /* Initialize target aix_thread_ops.  */
01816 
01817 static void
01818 init_aix_thread_ops (void)
01819 {
01820   aix_thread_ops.to_shortname = "aix-threads";
01821   aix_thread_ops.to_longname = _("AIX pthread support");
01822   aix_thread_ops.to_doc = _("AIX pthread support");
01823 
01824   aix_thread_ops.to_attach = aix_thread_attach;
01825   aix_thread_ops.to_detach = aix_thread_detach;
01826   aix_thread_ops.to_resume = aix_thread_resume;
01827   aix_thread_ops.to_wait = aix_thread_wait;
01828   aix_thread_ops.to_fetch_registers = aix_thread_fetch_registers;
01829   aix_thread_ops.to_store_registers = aix_thread_store_registers;
01830   aix_thread_ops.to_xfer_partial = aix_thread_xfer_partial;
01831   /* No need for aix_thread_ops.to_create_inferior, because we activate thread
01832      debugging when the inferior reaches pd_brk_addr.  */
01833   aix_thread_ops.to_mourn_inferior = aix_thread_mourn_inferior;
01834   aix_thread_ops.to_thread_alive = aix_thread_thread_alive;
01835   aix_thread_ops.to_pid_to_str = aix_thread_pid_to_str;
01836   aix_thread_ops.to_extra_thread_info = aix_thread_extra_thread_info;
01837   aix_thread_ops.to_get_ada_task_ptid = aix_thread_get_ada_task_ptid;
01838   aix_thread_ops.to_stratum = thread_stratum;
01839   aix_thread_ops.to_magic = OPS_MAGIC;
01840 }
01841 
01842 /* Module startup initialization function, automagically called by
01843    init.c.  */
01844 
01845 void _initialize_aix_thread (void);
01846 
01847 void
01848 _initialize_aix_thread (void)
01849 {
01850   init_aix_thread_ops ();
01851   complete_target_initialization (&aix_thread_ops);
01852 
01853   /* Notice when object files get loaded and unloaded.  */
01854   observer_attach_new_objfile (new_objfile);
01855 
01856   add_setshow_boolean_cmd ("aix-thread", class_maintenance, &debug_aix_thread,
01857                            _("Set debugging of AIX thread module."),
01858                            _("Show debugging of AIX thread module."),
01859                            _("Enables debugging output (used to debug GDB)."),
01860                            NULL, NULL,
01861                            /* FIXME: i18n: Debugging of AIX thread
01862                               module is \"%d\".  */
01863                            &setdebuglist, &showdebuglist);
01864 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines