GDB (xrefs)
/tmp/gdb-7.10/gdb/aix-thread.c
Go to the documentation of this file.
1 /* Low level interface for debugging AIX 4.3+ pthreads.
2 
3  Copyright (C) 1999-2015 Free Software Foundation, Inc.
4  Written by Nick Duffek <nsd@redhat.com>.
5 
6  This file is part of GDB.
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
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.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 
21 
22 /* This module uses the libpthdebug.a library provided by AIX 4.3+ for
23  debugging pthread applications.
24 
25  Some name prefix conventions:
26  pthdb_ provided by libpthdebug.a
27  pdc_ callbacks that this module provides to libpthdebug.a
28  pd_ variables or functions interfacing with libpthdebug.a
29 
30  libpthdebug peculiarities:
31 
32  - pthdb_ptid_pthread() is prototyped in <sys/pthdebug.h>, but
33  it's not documented, and after several calls it stops working
34  and causes other libpthdebug functions to fail.
35 
36  - pthdb_tid_pthread() doesn't always work after
37  pthdb_session_update(), but it does work after cycling through
38  all threads using pthdb_pthread().
39 
40  */
41 
42 #include "defs.h"
43 #include "gdbthread.h"
44 #include "target.h"
45 #include "inferior.h"
46 #include "regcache.h"
47 #include "gdbcmd.h"
48 #include "ppc-tdep.h"
49 #include "observer.h"
50 #include "objfiles.h"
51 
52 #include <procinfo.h>
53 #include <sys/types.h>
54 #include <sys/ptrace.h>
55 #include <sys/reg.h>
56 #include <sched.h>
57 #include <sys/pthdebug.h>
58 
59 #if !HAVE_DECL_GETTHRDS
60 extern int getthrds (pid_t, struct thrdsinfo64 *, int, tid_t *, int);
61 #endif
62 
63 /* Whether to emit debugging output. */
64 static int debug_aix_thread;
65 
66 /* In AIX 5.1, functions use pthdb_tid_t instead of tid_t. */
67 #ifndef PTHDB_VERSION_3
68 #define pthdb_tid_t tid_t
69 #endif
70 
71 /* Return whether to treat PID as a debuggable thread id. */
72 
73 #define PD_TID(ptid) (pd_active && ptid_get_tid (ptid) != 0)
74 
75 /* pthdb_user_t value that we pass to pthdb functions. 0 causes
76  PTHDB_BAD_USER errors, so use 1. */
77 
78 #define PD_USER 1
79 
80 /* Success and failure values returned by pthdb callbacks. */
81 
82 #define PDC_SUCCESS PTHDB_SUCCESS
83 #define PDC_FAILURE PTHDB_CALLBACK
84 
85 /* Private data attached to each element in GDB's thread list. */
86 
88  pthdb_pthread_t pdtid; /* thread's libpthdebug id */
89  pthdb_tid_t tid; /* kernel thread id */
90 };
91 
92 /* Information about a thread of which libpthdebug is aware. */
93 
94 struct pd_thread {
95  pthdb_pthread_t pdtid;
96  pthread_t pthid;
98 };
99 
100 /* This module's target-specific operations, active while pd_able is true. */
101 
103 
104 /* Address of the function that libpthread will call when libpthdebug
105  is ready to be initialized. */
106 
108 
109 /* Whether the current application is debuggable by pthdb. */
110 
111 static int pd_able = 0;
112 
113 /* Whether a threaded application is being debugged. */
114 
115 static int pd_active = 0;
116 
117 /* Whether the current architecture is 64-bit.
118  Only valid when pd_able is true. */
119 
120 static int arch64;
121 
122 /* Forward declarations for pthdb callbacks. */
123 
124 static int pdc_symbol_addrs (pthdb_user_t, pthdb_symbol_t *, int);
125 static int pdc_read_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
126 static int pdc_write_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
127 static int pdc_read_regs (pthdb_user_t user, pthdb_tid_t tid,
128  unsigned long long flags,
129  pthdb_context_t *context);
130 static int pdc_write_regs (pthdb_user_t user, pthdb_tid_t tid,
131  unsigned long long flags,
132  pthdb_context_t *context);
133 static int pdc_alloc (pthdb_user_t, size_t, void **);
134 static int pdc_realloc (pthdb_user_t, void *, size_t, void **);
135 static int pdc_dealloc (pthdb_user_t, void *);
136 
137 /* pthdb callbacks. */
138 
139 static pthdb_callbacks_t pd_callbacks = {
145  pdc_alloc,
146  pdc_realloc,
147  pdc_dealloc,
148  NULL
149 };
150 
151 /* Current pthdb session. */
152 
153 static pthdb_session_t pd_session;
154 
155 /* Return a printable representation of pthdebug function return
156  STATUS. */
157 
158 static char *
160 {
161  switch (status)
162  {
163  case PTHDB_SUCCESS: return "SUCCESS";
164  case PTHDB_NOSYS: return "NOSYS";
165  case PTHDB_NOTSUP: return "NOTSUP";
166  case PTHDB_BAD_VERSION: return "BAD_VERSION";
167  case PTHDB_BAD_USER: return "BAD_USER";
168  case PTHDB_BAD_SESSION: return "BAD_SESSION";
169  case PTHDB_BAD_MODE: return "BAD_MODE";
170  case PTHDB_BAD_FLAGS: return "BAD_FLAGS";
171  case PTHDB_BAD_CALLBACK: return "BAD_CALLBACK";
172  case PTHDB_BAD_POINTER: return "BAD_POINTER";
173  case PTHDB_BAD_CMD: return "BAD_CMD";
174  case PTHDB_BAD_PTHREAD: return "BAD_PTHREAD";
175  case PTHDB_BAD_ATTR: return "BAD_ATTR";
176  case PTHDB_BAD_MUTEX: return "BAD_MUTEX";
177  case PTHDB_BAD_MUTEXATTR: return "BAD_MUTEXATTR";
178  case PTHDB_BAD_COND: return "BAD_COND";
179  case PTHDB_BAD_CONDATTR: return "BAD_CONDATTR";
180  case PTHDB_BAD_RWLOCK: return "BAD_RWLOCK";
181  case PTHDB_BAD_RWLOCKATTR: return "BAD_RWLOCKATTR";
182  case PTHDB_BAD_KEY: return "BAD_KEY";
183  case PTHDB_BAD_PTID: return "BAD_PTID";
184  case PTHDB_BAD_TID: return "BAD_TID";
185  case PTHDB_CALLBACK: return "CALLBACK";
186  case PTHDB_CONTEXT: return "CONTEXT";
187  case PTHDB_HELD: return "HELD";
188  case PTHDB_NOT_HELD: return "NOT_HELD";
189  case PTHDB_MEMORY: return "MEMORY";
190  case PTHDB_NOT_PTHREADED: return "NOT_PTHREADED";
191  case PTHDB_SYMBOL: return "SYMBOL";
192  case PTHDB_NOT_AVAIL: return "NOT_AVAIL";
193  case PTHDB_INTERNAL: return "INTERNAL";
194  default: return "UNKNOWN";
195  }
196 }
197 
198 /* A call to ptrace(REQ, ID, ...) just returned RET. Check for
199  exceptional conditions and either return nonlocally or else return
200  1 for success and 0 for failure. */
201 
202 static int
203 ptrace_check (int req, int id, int ret)
204 {
205  if (ret == 0 && !errno)
206  return 1;
207 
208  /* According to ptrace(2), ptrace may fail with EPERM if "the
209  Identifier parameter corresponds to a kernel thread which is
210  stopped in kernel mode and whose computational state cannot be
211  read or written." This happens quite often with register reads. */
212 
213  switch (req)
214  {
215  case PTT_READ_GPRS:
216  case PTT_READ_FPRS:
217  case PTT_READ_SPRS:
218  if (ret == -1 && errno == EPERM)
219  {
220  if (debug_aix_thread)
222  "ptrace (%d, %d) = %d (errno = %d)\n",
223  req, id, ret, errno);
224  return ret == -1 ? 0 : 1;
225  }
226  break;
227  }
228  error (_("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)"),
229  req, id, ret, errno, safe_strerror (errno));
230  return 0; /* Not reached. */
231 }
232 
233 /* Call ptracex (REQ, ID, ADDR, DATA, BUF) or
234  ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
235  Return success. */
236 
237 #ifdef HAVE_PTRACE64
238 # define ptracex(request, pid, addr, data, buf) \
239  ptrace64 (request, pid, addr, data, buf)
240 #endif
241 
242 static int
243 ptrace64aix (int req, int id, long long addr, int data, int *buf)
244 {
245  errno = 0;
246  return ptrace_check (req, id, ptracex (req, id, addr, data, buf));
247 }
248 
249 /* Call ptrace (REQ, ID, ADDR, DATA, BUF) or
250  ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
251  Return success. */
252 
253 #ifdef HAVE_PTRACE64
254 # define ptrace(request, pid, addr, data, buf) \
255  ptrace64 (request, pid, addr, data, buf)
256 # define addr_ptr long long
257 #else
258 # define addr_ptr int *
259 #endif
260 
261 static int
262 ptrace32 (int req, int id, addr_ptr addr, int data, int *buf)
263 {
264  errno = 0;
265  return ptrace_check (req, id,
266  ptrace (req, id, addr, data, buf));
267 }
268 
269 /* If *PIDP is a composite process/thread id, convert it to a
270  process id. */
271 
272 static void
274 {
275  ptid_t ptid;
276 
277  ptid = *ptidp;
278  if (PD_TID (ptid))
279  *ptidp = pid_to_ptid (ptid_get_pid (ptid));
280 }
281 
282 /* pthdb callback: for <i> from 0 to COUNT, set SYMBOLS[<i>].addr to
283  the address of SYMBOLS[<i>].name. */
284 
285 static int
286 pdc_symbol_addrs (pthdb_user_t user, pthdb_symbol_t *symbols, int count)
287 {
288  struct bound_minimal_symbol ms;
289  int i;
290  char *name;
291 
292  if (debug_aix_thread)
294  "pdc_symbol_addrs (user = %ld, symbols = 0x%lx, count = %d)\n",
295  user, (long) symbols, count);
296 
297  for (i = 0; i < count; i++)
298  {
299  name = symbols[i].name;
300  if (debug_aix_thread)
302  " symbols[%d].name = \"%s\"\n", i, name);
303 
304  if (!*name)
305  symbols[i].addr = 0;
306  else
307  {
308  ms = lookup_minimal_symbol (name, NULL, NULL);
309  if (ms.minsym == NULL)
310  {
311  if (debug_aix_thread)
312  fprintf_unfiltered (gdb_stdlog, " returning PDC_FAILURE\n");
313  return PDC_FAILURE;
314  }
315  symbols[i].addr = BMSYMBOL_VALUE_ADDRESS (ms);
316  }
317  if (debug_aix_thread)
318  fprintf_unfiltered (gdb_stdlog, " symbols[%d].addr = %s\n",
319  i, hex_string (symbols[i].addr));
320  }
321  if (debug_aix_thread)
322  fprintf_unfiltered (gdb_stdlog, " returning PDC_SUCCESS\n");
323  return PDC_SUCCESS;
324 }
325 
326 /* Read registers call back function should be able to read the
327  context information of a debuggee kernel thread from an active
328  process or from a core file. The information should be formatted
329  in context64 form for both 32-bit and 64-bit process.
330  If successful return 0, else non-zero is returned. */
331 
332 static int
333 pdc_read_regs (pthdb_user_t user,
334  pthdb_tid_t tid,
335  unsigned long long flags,
336  pthdb_context_t *context)
337 {
338  /* This function doesn't appear to be used, so we could probably
339  just return 0 here. HOWEVER, if it is not defined, the OS will
340  complain and several thread debug functions will fail. In case
341  this is needed, I have implemented what I think it should do,
342  however this code is untested. */
343 
344  uint64_t gprs64[ppc_num_gprs];
345  uint32_t gprs32[ppc_num_gprs];
346  double fprs[ppc_num_fprs];
347  struct ptxsprs sprs64;
348  struct ptsprs sprs32;
349 
350  if (debug_aix_thread)
351  fprintf_unfiltered (gdb_stdlog, "pdc_read_regs tid=%d flags=%s\n",
352  (int) tid, hex_string (flags));
353 
354  /* General-purpose registers. */
355  if (flags & PTHDB_FLAG_GPRS)
356  {
357  if (arch64)
358  {
359  if (!ptrace64aix (PTT_READ_GPRS, tid,
360  (unsigned long) gprs64, 0, NULL))
361  memset (gprs64, 0, sizeof (gprs64));
362  memcpy (context->gpr, gprs64, sizeof(gprs64));
363  }
364  else
365  {
366  if (!ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL))
367  memset (gprs32, 0, sizeof (gprs32));
368  memcpy (context->gpr, gprs32, sizeof(gprs32));
369  }
370  }
371 
372  /* Floating-point registers. */
373  if (flags & PTHDB_FLAG_FPRS)
374  {
375  if (!ptrace32 (PTT_READ_FPRS, tid, (uintptr_t) fprs, 0, NULL))
376  memset (fprs, 0, sizeof (fprs));
377  memcpy (context->fpr, fprs, sizeof(fprs));
378  }
379 
380  /* Special-purpose registers. */
381  if (flags & PTHDB_FLAG_SPRS)
382  {
383  if (arch64)
384  {
385  if (!ptrace64aix (PTT_READ_SPRS, tid,
386  (unsigned long) &sprs64, 0, NULL))
387  memset (&sprs64, 0, sizeof (sprs64));
388  memcpy (&context->msr, &sprs64, sizeof(sprs64));
389  }
390  else
391  {
392  if (!ptrace32 (PTT_READ_SPRS, tid, (uintptr_t) &sprs32, 0, NULL))
393  memset (&sprs32, 0, sizeof (sprs32));
394  memcpy (&context->msr, &sprs32, sizeof(sprs32));
395  }
396  }
397  return 0;
398 }
399 
400 /* Write register function should be able to write requested context
401  information to specified debuggee's kernel thread id.
402  If successful return 0, else non-zero is returned. */
403 
404 static int
405 pdc_write_regs (pthdb_user_t user,
406  pthdb_tid_t tid,
407  unsigned long long flags,
408  pthdb_context_t *context)
409 {
410  /* This function doesn't appear to be used, so we could probably
411  just return 0 here. HOWEVER, if it is not defined, the OS will
412  complain and several thread debug functions will fail. In case
413  this is needed, I have implemented what I think it should do,
414  however this code is untested. */
415 
416  if (debug_aix_thread)
417  fprintf_unfiltered (gdb_stdlog, "pdc_write_regs tid=%d flags=%s\n",
418  (int) tid, hex_string (flags));
419 
420  /* General-purpose registers. */
421  if (flags & PTHDB_FLAG_GPRS)
422  {
423  if (arch64)
424  ptrace64aix (PTT_WRITE_GPRS, tid,
425  (unsigned long) context->gpr, 0, NULL);
426  else
427  ptrace32 (PTT_WRITE_GPRS, tid, (uintptr_t) context->gpr, 0, NULL);
428  }
429 
430  /* Floating-point registers. */
431  if (flags & PTHDB_FLAG_FPRS)
432  {
433  ptrace32 (PTT_WRITE_FPRS, tid, (uintptr_t) context->fpr, 0, NULL);
434  }
435 
436  /* Special-purpose registers. */
437  if (flags & PTHDB_FLAG_SPRS)
438  {
439  if (arch64)
440  {
441  ptrace64aix (PTT_WRITE_SPRS, tid,
442  (unsigned long) &context->msr, 0, NULL);
443  }
444  else
445  {
446  ptrace32 (PTT_WRITE_SPRS, tid, (uintptr_t) &context->msr, 0, NULL);
447  }
448  }
449  return 0;
450 }
451 
452 /* pthdb callback: read LEN bytes from process ADDR into BUF. */
453 
454 static int
455 pdc_read_data (pthdb_user_t user, void *buf,
456  pthdb_addr_t addr, size_t len)
457 {
458  int status, ret;
459 
460  if (debug_aix_thread)
462  "pdc_read_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
463  user, (long) buf, hex_string (addr), len);
464 
465  status = target_read_memory (addr, buf, len);
466  ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
467 
468  if (debug_aix_thread)
469  fprintf_unfiltered (gdb_stdlog, " status=%d, returning %s\n",
470  status, pd_status2str (ret));
471  return ret;
472 }
473 
474 /* pthdb callback: write LEN bytes from BUF to process ADDR. */
475 
476 static int
477 pdc_write_data (pthdb_user_t user, void *buf,
478  pthdb_addr_t addr, size_t len)
479 {
480  int status, ret;
481 
482  if (debug_aix_thread)
484  "pdc_write_data (user = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
485  user, (long) buf, hex_string (addr), len);
486 
487  status = target_write_memory (addr, buf, len);
488  ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
489 
490  if (debug_aix_thread)
491  fprintf_unfiltered (gdb_stdlog, " status=%d, returning %s\n", status,
492  pd_status2str (ret));
493  return ret;
494 }
495 
496 /* pthdb callback: allocate a LEN-byte buffer and store a pointer to it
497  in BUFP. */
498 
499 static int
500 pdc_alloc (pthdb_user_t user, size_t len, void **bufp)
501 {
502  if (debug_aix_thread)
504  "pdc_alloc (user = %ld, len = %ld, bufp = 0x%lx)\n",
505  user, len, (long) bufp);
506  *bufp = xmalloc (len);
507  if (debug_aix_thread)
509  " malloc returned 0x%lx\n", (long) *bufp);
510 
511  /* Note: xmalloc() can't return 0; therefore PDC_FAILURE will never
512  be returned. */
513 
514  return *bufp ? PDC_SUCCESS : PDC_FAILURE;
515 }
516 
517 /* pthdb callback: reallocate BUF, which was allocated by the alloc or
518  realloc callback, so that it contains LEN bytes, and store a
519  pointer to the result in BUFP. */
520 
521 static int
522 pdc_realloc (pthdb_user_t user, void *buf, size_t len, void **bufp)
523 {
524  if (debug_aix_thread)
526  "pdc_realloc (user = %ld, buf = 0x%lx, len = %ld, bufp = 0x%lx)\n",
527  user, (long) buf, len, (long) bufp);
528  *bufp = xrealloc (buf, len);
529  if (debug_aix_thread)
531  " realloc returned 0x%lx\n", (long) *bufp);
532  return *bufp ? PDC_SUCCESS : PDC_FAILURE;
533 }
534 
535 /* pthdb callback: free BUF, which was allocated by the alloc or
536  realloc callback. */
537 
538 static int
539 pdc_dealloc (pthdb_user_t user, void *buf)
540 {
541  if (debug_aix_thread)
543  "pdc_free (user = %ld, buf = 0x%lx)\n", user,
544  (long) buf);
545  xfree (buf);
546  return PDC_SUCCESS;
547 }
548 
549 /* Return a printable representation of pthread STATE. */
550 
551 static char *
552 state2str (pthdb_state_t state)
553 {
554  switch (state)
555  {
556  case PST_IDLE:
557  /* i18n: Like "Thread-Id %d, [state] idle" */
558  return _("idle"); /* being created */
559  case PST_RUN:
560  /* i18n: Like "Thread-Id %d, [state] running" */
561  return _("running"); /* running */
562  case PST_SLEEP:
563  /* i18n: Like "Thread-Id %d, [state] sleeping" */
564  return _("sleeping"); /* awaiting an event */
565  case PST_READY:
566  /* i18n: Like "Thread-Id %d, [state] ready" */
567  return _("ready"); /* runnable */
568  case PST_TERM:
569  /* i18n: Like "Thread-Id %d, [state] finished" */
570  return _("finished"); /* awaiting a join/detach */
571  default:
572  /* i18n: Like "Thread-Id %d, [state] unknown" */
573  return _("unknown");
574  }
575 }
576 
577 /* qsort() comparison function for sorting pd_thread structs by pthid. */
578 
579 static int
580 pcmp (const void *p1v, const void *p2v)
581 {
582  struct pd_thread *p1 = (struct pd_thread *) p1v;
583  struct pd_thread *p2 = (struct pd_thread *) p2v;
584  return p1->pthid < p2->pthid ? -1 : p1->pthid > p2->pthid;
585 }
586 
587 /* iterate_over_threads() callback for counting GDB threads.
588 
589  Do not count the main thread (whose tid is zero). This matches
590  the list of threads provided by the pthreaddebug library, which
591  does not include that main thread either, and thus allows us
592  to compare the two lists. */
593 
594 static int
595 giter_count (struct thread_info *thread, void *countp)
596 {
597  if (PD_TID (thread->ptid))
598  (*(int *) countp)++;
599  return 0;
600 }
601 
602 /* iterate_over_threads() callback for accumulating GDB thread pids.
603 
604  Do not include the main thread (whose tid is zero). This matches
605  the list of threads provided by the pthreaddebug library, which
606  does not include that main thread either, and thus allows us
607  to compare the two lists. */
608 
609 static int
610 giter_accum (struct thread_info *thread, void *bufp)
611 {
612  if (PD_TID (thread->ptid))
613  {
614  **(struct thread_info ***) bufp = thread;
615  (*(struct thread_info ***) bufp)++;
616  }
617  return 0;
618 }
619 
620 /* ptid comparison function */
621 
622 static int
623 ptid_cmp (ptid_t ptid1, ptid_t ptid2)
624 {
625  int pid1, pid2;
626 
627  if (ptid_get_pid (ptid1) < ptid_get_pid (ptid2))
628  return -1;
629  else if (ptid_get_pid (ptid1) > ptid_get_pid (ptid2))
630  return 1;
631  else if (ptid_get_tid (ptid1) < ptid_get_tid (ptid2))
632  return -1;
633  else if (ptid_get_tid (ptid1) > ptid_get_tid (ptid2))
634  return 1;
635  else if (ptid_get_lwp (ptid1) < ptid_get_lwp (ptid2))
636  return -1;
637  else if (ptid_get_lwp (ptid1) > ptid_get_lwp (ptid2))
638  return 1;
639  else
640  return 0;
641 }
642 
643 /* qsort() comparison function for sorting thread_info structs by pid. */
644 
645 static int
646 gcmp (const void *t1v, const void *t2v)
647 {
648  struct thread_info *t1 = *(struct thread_info **) t1v;
649  struct thread_info *t2 = *(struct thread_info **) t2v;
650  return ptid_cmp (t1->ptid, t2->ptid);
651 }
652 
653 /* Search through the list of all kernel threads for the thread
654  that has stopped on a SIGTRAP signal, and return its TID.
655  Return 0 if none found. */
656 
657 static pthdb_tid_t
659 {
660  struct thrdsinfo64 thrinf;
661  tid_t ktid = 0;
662  int result = 0;
663 
664  while (1)
665  {
666  if (getthrds (ptid_get_pid (inferior_ptid), &thrinf,
667  sizeof (thrinf), &ktid, 1) != 1)
668  break;
669 
670  if (thrinf.ti_cursig == SIGTRAP)
671  return thrinf.ti_tid;
672  }
673 
674  /* Didn't find any thread stopped on a SIGTRAP signal. */
675  return 0;
676 }
677 
678 /* Synchronize GDB's thread list with libpthdebug's.
679 
680  There are some benefits of doing this every time the inferior stops:
681 
682  - allows users to run thread-specific commands without needing to
683  run "info threads" first
684 
685  - helps pthdb_tid_pthread() work properly (see "libpthdebug
686  peculiarities" at the top of this module)
687 
688  - simplifies the demands placed on libpthdebug, which seems to
689  have difficulty with certain call patterns */
690 
691 static void
693 {
694  int cmd, status, infpid;
695  int pcount, psize, pi, gcount, gi;
696  struct pd_thread *pbuf;
697  struct thread_info **gbuf, **g, *thread;
698  pthdb_pthread_t pdtid;
699  pthread_t pthid;
700  pthdb_tid_t tid;
701 
702  /* Accumulate an array of libpthdebug threads sorted by pthread id. */
703 
704  pcount = 0;
705  psize = 1;
706  pbuf = (struct pd_thread *) xmalloc (psize * sizeof *pbuf);
707 
708  for (cmd = PTHDB_LIST_FIRST;; cmd = PTHDB_LIST_NEXT)
709  {
710  status = pthdb_pthread (pd_session, &pdtid, cmd);
711  if (status != PTHDB_SUCCESS || pdtid == PTHDB_INVALID_PTHREAD)
712  break;
713 
714  status = pthdb_pthread_ptid (pd_session, pdtid, &pthid);
715  if (status != PTHDB_SUCCESS || pthid == PTHDB_INVALID_PTID)
716  continue;
717 
718  if (pcount == psize)
719  {
720  psize *= 2;
721  pbuf = (struct pd_thread *) xrealloc (pbuf,
722  psize * sizeof *pbuf);
723  }
724  pbuf[pcount].pdtid = pdtid;
725  pbuf[pcount].pthid = pthid;
726  pcount++;
727  }
728 
729  for (pi = 0; pi < pcount; pi++)
730  {
731  status = pthdb_pthread_tid (pd_session, pbuf[pi].pdtid, &tid);
732  if (status != PTHDB_SUCCESS)
733  tid = PTHDB_INVALID_TID;
734  pbuf[pi].tid = tid;
735  }
736 
737  qsort (pbuf, pcount, sizeof *pbuf, pcmp);
738 
739  /* Accumulate an array of GDB threads sorted by pid. */
740 
741  gcount = 0;
743  g = gbuf = (struct thread_info **) xmalloc (gcount * sizeof *gbuf);
745  qsort (gbuf, gcount, sizeof *gbuf, gcmp);
746 
747  /* Apply differences between the two arrays to GDB's thread list. */
748 
749  infpid = ptid_get_pid (inferior_ptid);
750  for (pi = gi = 0; pi < pcount || gi < gcount;)
751  {
752  if (pi == pcount)
753  {
754  delete_thread (gbuf[gi]->ptid);
755  gi++;
756  }
757  else if (gi == gcount)
758  {
759  thread = add_thread (ptid_build (infpid, 0, pbuf[pi].pthid));
760  thread->priv = xmalloc (sizeof (struct private_thread_info));
761  thread->priv->pdtid = pbuf[pi].pdtid;
762  thread->priv->tid = pbuf[pi].tid;
763  pi++;
764  }
765  else
766  {
767  ptid_t pptid, gptid;
768  int cmp_result;
769 
770  pptid = ptid_build (infpid, 0, pbuf[pi].pthid);
771  gptid = gbuf[gi]->ptid;
772  pdtid = pbuf[pi].pdtid;
773  tid = pbuf[pi].tid;
774 
775  cmp_result = ptid_cmp (pptid, gptid);
776 
777  if (cmp_result == 0)
778  {
779  gbuf[gi]->priv->pdtid = pdtid;
780  gbuf[gi]->priv->tid = tid;
781  pi++;
782  gi++;
783  }
784  else if (cmp_result > 0)
785  {
786  delete_thread (gptid);
787  gi++;
788  }
789  else
790  {
791  thread = add_thread (pptid);
792  thread->priv = xmalloc (sizeof (struct private_thread_info));
793  thread->priv->pdtid = pdtid;
794  thread->priv->tid = tid;
795  pi++;
796  }
797  }
798  }
799 
800  xfree (pbuf);
801  xfree (gbuf);
802 }
803 
804 /* Iterate_over_threads() callback for locating a thread, using
805  the TID of its associated kernel thread. */
806 
807 static int
808 iter_tid (struct thread_info *thread, void *tidp)
809 {
810  const pthdb_tid_t tid = *(pthdb_tid_t *)tidp;
811 
812  return (thread->priv->tid == tid);
813 }
814 
815 /* Synchronize libpthdebug's state with the inferior and with GDB,
816  generate a composite process/thread <pid> for the current thread,
817  set inferior_ptid to <pid> if SET_INFPID, and return <pid>. */
818 
819 static ptid_t
820 pd_update (int set_infpid)
821 {
822  int status;
823  ptid_t ptid;
824  pthdb_tid_t tid;
825  struct thread_info *thread = NULL;
826 
827  if (!pd_active)
828  return inferior_ptid;
829 
830  status = pthdb_session_update (pd_session);
831  if (status != PTHDB_SUCCESS)
832  return inferior_ptid;
833 
834  sync_threadlists ();
835 
836  /* Define "current thread" as one that just received a trap signal. */
837 
838  tid = get_signaled_thread ();
839  if (tid != 0)
840  thread = iterate_over_threads (iter_tid, &tid);
841  if (!thread)
842  ptid = inferior_ptid;
843  else
844  {
845  ptid = thread->ptid;
846  if (set_infpid)
848  }
849  return ptid;
850 }
851 
852 /* Try to start debugging threads in the current process.
853  If successful and SET_INFPID, set inferior_ptid to reflect the
854  current thread. */
855 
856 static ptid_t
857 pd_activate (int set_infpid)
858 {
859  int status;
860 
861  status = pthdb_session_init (PD_USER, arch64 ? PEM_64BIT : PEM_32BIT,
862  PTHDB_FLAG_REGS, &pd_callbacks,
863  &pd_session);
864  if (status != PTHDB_SUCCESS)
865  {
866  return inferior_ptid;
867  }
868  pd_active = 1;
869  return pd_update (set_infpid);
870 }
871 
872 /* Undo the effects of pd_activate(). */
873 
874 static void
876 {
877  if (!pd_active)
878  return;
879  pthdb_session_destroy (pd_session);
880 
882  pd_active = 0;
883 }
884 
885 /* An object file has just been loaded. Check whether the current
886  application is pthreaded, and if so, prepare for thread debugging. */
887 
888 static void
889 pd_enable (void)
890 {
891  int status;
892  char *stub_name;
893  struct bound_minimal_symbol ms;
894 
895  /* Don't initialize twice. */
896  if (pd_able)
897  return;
898 
899  /* Check application word size. */
900  arch64 = register_size (target_gdbarch (), 0) == 8;
901 
902  /* Check whether the application is pthreaded. */
903  stub_name = NULL;
904  status = pthdb_session_pthreaded (PD_USER, PTHDB_FLAG_REGS,
905  &pd_callbacks, &stub_name);
906  if ((status != PTHDB_SUCCESS
907  && status != PTHDB_NOT_PTHREADED) || !stub_name)
908  return;
909 
910  /* Set a breakpoint on the returned stub function. */
911  ms = lookup_minimal_symbol (stub_name, NULL, NULL);
912  if (ms.minsym == NULL)
913  return;
916  return;
917 
918  /* Prepare for thread debugging. */
920  pd_able = 1;
921 
922  /* If we're debugging a core file or an attached inferior, the
923  pthread library may already have been initialized, so try to
924  activate thread debugging. */
925  pd_activate (1);
926 }
927 
928 /* Undo the effects of pd_enable(). */
929 
930 static void
932 {
933  if (!pd_able)
934  return;
935  if (pd_active)
936  pd_deactivate ();
937  pd_able = 0;
939 }
940 
941 /* new_objfile observer callback.
942 
943  If OBJFILE is non-null, check whether a threaded application is
944  being debugged, and if so, prepare for thread debugging.
945 
946  If OBJFILE is null, stop debugging threads. */
947 
948 static void
950 {
951  if (objfile)
952  pd_enable ();
953  else
954  pd_disable ();
955 }
956 
957 /* Attach to process specified by ARGS. */
958 
959 static void
960 aix_thread_inferior_created (struct target_ops *ops, int from_tty)
961 {
962  pd_enable ();
963 }
964 
965 /* Detach from the process attached to by aix_thread_attach(). */
966 
967 static void
968 aix_thread_detach (struct target_ops *ops, const char *args, int from_tty)
969 {
970  struct target_ops *beneath = find_target_beneath (ops);
971 
972  pd_disable ();
973  beneath->to_detach (beneath, args, from_tty);
974 }
975 
976 /* Tell the inferior process to continue running thread PID if != -1
977  and all threads otherwise. */
978 
979 static void
981  ptid_t ptid, int step, enum gdb_signal sig)
982 {
983  struct thread_info *thread;
984  pthdb_tid_t tid[2];
985 
986  if (!PD_TID (ptid))
987  {
988  struct cleanup *cleanup = save_inferior_ptid ();
989  struct target_ops *beneath = find_target_beneath (ops);
990 
992  beneath->to_resume (beneath, ptid, step, sig);
993  do_cleanups (cleanup);
994  }
995  else
996  {
997  thread = find_thread_ptid (ptid);
998  if (!thread)
999  error (_("aix-thread resume: unknown pthread %ld"),
1000  ptid_get_lwp (ptid));
1001 
1002  tid[0] = thread->priv->tid;
1003  if (tid[0] == PTHDB_INVALID_TID)
1004  error (_("aix-thread resume: no tid for pthread %ld"),
1005  ptid_get_lwp (ptid));
1006  tid[1] = 0;
1007 
1008  if (arch64)
1009  ptrace64aix (PTT_CONTINUE, tid[0], (long long) 1,
1010  gdb_signal_to_host (sig), (void *) tid);
1011  else
1012  ptrace32 (PTT_CONTINUE, tid[0], (addr_ptr) 1,
1013  gdb_signal_to_host (sig), (void *) tid);
1014  }
1015 }
1016 
1017 /* Wait for thread/process ID if != -1 or for any thread otherwise.
1018  If an error occurs, return -1, else return the pid of the stopped
1019  thread. */
1020 
1021 static ptid_t
1023  ptid_t ptid, struct target_waitstatus *status, int options)
1024 {
1025  struct cleanup *cleanup = save_inferior_ptid ();
1026  struct target_ops *beneath = find_target_beneath (ops);
1027 
1028  pid_to_prc (&ptid);
1029 
1031  ptid = beneath->to_wait (beneath, ptid, status, options);
1032  do_cleanups (cleanup);
1033 
1034  if (ptid_get_pid (ptid) == -1)
1035  return pid_to_ptid (-1);
1036 
1037  /* Check whether libpthdebug might be ready to be initialized. */
1038  if (!pd_active && status->kind == TARGET_WAITKIND_STOPPED
1039  && status->value.sig == GDB_SIGNAL_TRAP)
1040  {
1041  struct regcache *regcache = get_thread_regcache (ptid);
1042  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1043 
1044  if (regcache_read_pc (regcache)
1046  return pd_activate (0);
1047  }
1048 
1049  return pd_update (0);
1050 }
1051 
1052 /* Record that the 64-bit general-purpose registers contain VALS. */
1053 
1054 static void
1055 supply_gprs64 (struct regcache *regcache, uint64_t *vals)
1056 {
1057  struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
1058  int regno;
1059 
1060  for (regno = 0; regno < ppc_num_gprs; regno++)
1061  regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + regno,
1062  (char *) (vals + regno));
1063 }
1064 
1065 /* Record that 32-bit register REGNO contains VAL. */
1066 
1067 static void
1068 supply_reg32 (struct regcache *regcache, int regno, uint32_t val)
1069 {
1070  regcache_raw_supply (regcache, regno, (char *) &val);
1071 }
1072 
1073 /* Record that the floating-point registers contain VALS. */
1074 
1075 static void
1076 supply_fprs (struct regcache *regcache, double *vals)
1077 {
1078  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1079  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1080  int regno;
1081 
1082  /* This function should never be called on architectures without
1083  floating-point registers. */
1085 
1086  for (regno = tdep->ppc_fp0_regnum;
1087  regno < tdep->ppc_fp0_regnum + ppc_num_fprs;
1088  regno++)
1089  regcache_raw_supply (regcache, regno,
1090  (char *) (vals + regno - tdep->ppc_fp0_regnum));
1091 }
1092 
1093 /* Predicate to test whether given register number is a "special" register. */
1094 static int
1095 special_register_p (struct gdbarch *gdbarch, int regno)
1096 {
1097  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1098 
1099  return regno == gdbarch_pc_regnum (gdbarch)
1100  || regno == tdep->ppc_ps_regnum
1101  || regno == tdep->ppc_cr_regnum
1102  || regno == tdep->ppc_lr_regnum
1103  || regno == tdep->ppc_ctr_regnum
1104  || regno == tdep->ppc_xer_regnum
1105  || (tdep->ppc_fpscr_regnum >= 0 && regno == tdep->ppc_fpscr_regnum)
1106  || (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum);
1107 }
1108 
1109 
1110 /* Record that the special registers contain the specified 64-bit and
1111  32-bit values. */
1112 
1113 static void
1115  uint64_t iar, uint64_t msr, uint32_t cr,
1116  uint64_t lr, uint64_t ctr, uint32_t xer,
1117  uint32_t fpscr)
1118 {
1119  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1120  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1121 
1122  regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch),
1123  (char *) &iar);
1124  regcache_raw_supply (regcache, tdep->ppc_ps_regnum, (char *) &msr);
1125  regcache_raw_supply (regcache, tdep->ppc_cr_regnum, (char *) &cr);
1126  regcache_raw_supply (regcache, tdep->ppc_lr_regnum, (char *) &lr);
1127  regcache_raw_supply (regcache, tdep->ppc_ctr_regnum, (char *) &ctr);
1128  regcache_raw_supply (regcache, tdep->ppc_xer_regnum, (char *) &xer);
1129  if (tdep->ppc_fpscr_regnum >= 0)
1130  regcache_raw_supply (regcache, tdep->ppc_fpscr_regnum,
1131  (char *) &fpscr);
1132 }
1133 
1134 /* Record that the special registers contain the specified 32-bit
1135  values. */
1136 
1137 static void
1139  uint32_t iar, uint32_t msr, uint32_t cr,
1140  uint32_t lr, uint32_t ctr, uint32_t xer,
1141  uint32_t fpscr)
1142 {
1143  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1144  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1145 
1146  regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch),
1147  (char *) &iar);
1148  regcache_raw_supply (regcache, tdep->ppc_ps_regnum, (char *) &msr);
1149  regcache_raw_supply (regcache, tdep->ppc_cr_regnum, (char *) &cr);
1150  regcache_raw_supply (regcache, tdep->ppc_lr_regnum, (char *) &lr);
1151  regcache_raw_supply (regcache, tdep->ppc_ctr_regnum, (char *) &ctr);
1152  regcache_raw_supply (regcache, tdep->ppc_xer_regnum, (char *) &xer);
1153  if (tdep->ppc_fpscr_regnum >= 0)
1154  regcache_raw_supply (regcache, tdep->ppc_fpscr_regnum,
1155  (char *) &fpscr);
1156 }
1157 
1158 /* Fetch all registers from pthread PDTID, which doesn't have a kernel
1159  thread.
1160 
1161  There's no way to query a single register from a non-kernel
1162  pthread, so there's no need for a single-register version of this
1163  function. */
1164 
1165 static void
1166 fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
1167 {
1168  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1169  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1170  int status, i;
1171  pthdb_context_t ctx;
1172 
1173  if (debug_aix_thread)
1175  "fetch_regs_user_thread %lx\n", (long) pdtid);
1176  status = pthdb_pthread_context (pd_session, pdtid, &ctx);
1177  if (status != PTHDB_SUCCESS)
1178  error (_("aix-thread: fetch_registers: pthdb_pthread_context returned %s"),
1179  pd_status2str (status));
1180 
1181  /* General-purpose registers. */
1182 
1183  if (arch64)
1184  supply_gprs64 (regcache, ctx.gpr);
1185  else
1186  for (i = 0; i < ppc_num_gprs; i++)
1187  supply_reg32 (regcache, tdep->ppc_gp0_regnum + i, ctx.gpr[i]);
1188 
1189  /* Floating-point registers. */
1190 
1191  if (ppc_floating_point_unit_p (gdbarch))
1192  supply_fprs (regcache, ctx.fpr);
1193 
1194  /* Special registers. */
1195 
1196  if (arch64)
1197  supply_sprs64 (regcache, ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr,
1198  ctx.xer, ctx.fpscr);
1199  else
1200  supply_sprs32 (regcache, ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr,
1201  ctx.xer, ctx.fpscr);
1202 }
1203 
1204 /* Fetch register REGNO if != -1 or all registers otherwise from
1205  kernel thread TID.
1206 
1207  AIX provides a way to query all of a kernel thread's GPRs, FPRs, or
1208  SPRs, but there's no way to query individual registers within those
1209  groups. Therefore, if REGNO != -1, this function fetches an entire
1210  group.
1211 
1212  Unfortunately, kernel thread register queries often fail with
1213  EPERM, indicating that the thread is in kernel space. This breaks
1214  backtraces of threads other than the current one. To make that
1215  breakage obvious without throwing an error to top level (which is
1216  bad e.g. during "info threads" output), zero registers that can't
1217  be retrieved. */
1218 
1219 static void
1221  pthdb_tid_t tid)
1222 {
1223  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1224  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1225  uint64_t gprs64[ppc_num_gprs];
1226  uint32_t gprs32[ppc_num_gprs];
1227  double fprs[ppc_num_fprs];
1228  struct ptxsprs sprs64;
1229  struct ptsprs sprs32;
1230  int i;
1231 
1232  if (debug_aix_thread)
1234  "fetch_regs_kernel_thread tid=%lx regno=%d arch64=%d\n",
1235  (long) tid, regno, arch64);
1236 
1237  /* General-purpose registers. */
1238  if (regno == -1
1239  || (tdep->ppc_gp0_regnum <= regno
1240  && regno < tdep->ppc_gp0_regnum + ppc_num_gprs))
1241  {
1242  if (arch64)
1243  {
1244  if (!ptrace64aix (PTT_READ_GPRS, tid,
1245  (unsigned long) gprs64, 0, NULL))
1246  memset (gprs64, 0, sizeof (gprs64));
1247  supply_gprs64 (regcache, gprs64);
1248  }
1249  else
1250  {
1251  if (!ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL))
1252  memset (gprs32, 0, sizeof (gprs32));
1253  for (i = 0; i < ppc_num_gprs; i++)
1254  supply_reg32 (regcache, tdep->ppc_gp0_regnum + i, gprs32[i]);
1255  }
1256  }
1257 
1258  /* Floating-point registers. */
1259 
1260  if (ppc_floating_point_unit_p (gdbarch)
1261  && (regno == -1
1262  || (regno >= tdep->ppc_fp0_regnum
1263  && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
1264  {
1265  if (!ptrace32 (PTT_READ_FPRS, tid, (uintptr_t) fprs, 0, NULL))
1266  memset (fprs, 0, sizeof (fprs));
1267  supply_fprs (regcache, fprs);
1268  }
1269 
1270  /* Special-purpose registers. */
1271 
1272  if (regno == -1 || special_register_p (gdbarch, regno))
1273  {
1274  if (arch64)
1275  {
1276  if (!ptrace64aix (PTT_READ_SPRS, tid,
1277  (unsigned long) &sprs64, 0, NULL))
1278  memset (&sprs64, 0, sizeof (sprs64));
1279  supply_sprs64 (regcache, sprs64.pt_iar, sprs64.pt_msr,
1280  sprs64.pt_cr, sprs64.pt_lr, sprs64.pt_ctr,
1281  sprs64.pt_xer, sprs64.pt_fpscr);
1282  }
1283  else
1284  {
1285  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1286 
1287  if (!ptrace32 (PTT_READ_SPRS, tid, (uintptr_t) &sprs32, 0, NULL))
1288  memset (&sprs32, 0, sizeof (sprs32));
1289  supply_sprs32 (regcache, sprs32.pt_iar, sprs32.pt_msr, sprs32.pt_cr,
1290  sprs32.pt_lr, sprs32.pt_ctr, sprs32.pt_xer,
1291  sprs32.pt_fpscr);
1292 
1293  if (tdep->ppc_mq_regnum >= 0)
1294  regcache_raw_supply (regcache, tdep->ppc_mq_regnum,
1295  (char *) &sprs32.pt_mq);
1296  }
1297  }
1298 }
1299 
1300 /* Fetch register REGNO if != -1 or all registers otherwise in the
1301  thread/process specified by inferior_ptid. */
1302 
1303 static void
1305  struct regcache *regcache, int regno)
1306 {
1307  struct thread_info *thread;
1308  pthdb_tid_t tid;
1309  struct target_ops *beneath = find_target_beneath (ops);
1310 
1311  if (!PD_TID (inferior_ptid))
1312  beneath->to_fetch_registers (beneath, regcache, regno);
1313  else
1314  {
1315  thread = find_thread_ptid (inferior_ptid);
1316  tid = thread->priv->tid;
1317 
1318  if (tid == PTHDB_INVALID_TID)
1319  fetch_regs_user_thread (regcache, thread->priv->pdtid);
1320  else
1321  fetch_regs_kernel_thread (regcache, regno, tid);
1322  }
1323 }
1324 
1325 /* Store the gp registers into an array of uint32_t or uint64_t. */
1326 
1327 static void
1328 fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
1329 {
1330  struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
1331  int regno;
1332 
1333  for (regno = 0; regno < ppc_num_gprs; regno++)
1334  if (REG_VALID == regcache_register_status (regcache,
1335  tdep->ppc_gp0_regnum + regno))
1336  regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + regno,
1337  vals + regno);
1338 }
1339 
1340 static void
1341 fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
1342 {
1343  struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
1344  int regno;
1345 
1346  for (regno = 0; regno < ppc_num_gprs; regno++)
1347  if (REG_VALID == regcache_register_status (regcache,
1348  tdep->ppc_gp0_regnum + regno))
1349  regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + regno,
1350  vals + regno);
1351 }
1352 
1353 /* Store the floating point registers into a double array. */
1354 static void
1355 fill_fprs (const struct regcache *regcache, double *vals)
1356 {
1357  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1358  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1359  int regno;
1360 
1361  /* This function should never be called on architectures without
1362  floating-point registers. */
1364 
1365  for (regno = tdep->ppc_fp0_regnum;
1366  regno < tdep->ppc_fp0_regnum + ppc_num_fprs;
1367  regno++)
1368  if (REG_VALID == regcache_register_status (regcache, regno))
1369  regcache_raw_collect (regcache, regno,
1370  vals + regno - tdep->ppc_fp0_regnum);
1371 }
1372 
1373 /* Store the special registers into the specified 64-bit and 32-bit
1374  locations. */
1375 
1376 static void
1378  uint64_t *iar, uint64_t *msr, uint32_t *cr,
1379  uint64_t *lr, uint64_t *ctr, uint32_t *xer,
1380  uint32_t *fpscr)
1381 {
1382  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1383  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1384 
1385  /* Verify that the size of the size of the IAR buffer is the
1386  same as the raw size of the PC (in the register cache). If
1387  they're not, then either GDB has been built incorrectly, or
1388  there's some other kind of internal error. To be really safe,
1389  we should check all of the sizes. */
1390  gdb_assert (sizeof (*iar) == register_size
1391  (gdbarch, gdbarch_pc_regnum (gdbarch)));
1392 
1393  if (REG_VALID == regcache_register_status (regcache,
1394  gdbarch_pc_regnum (gdbarch)))
1395  regcache_raw_collect (regcache, gdbarch_pc_regnum (gdbarch), iar);
1396  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum))
1397  regcache_raw_collect (regcache, tdep->ppc_ps_regnum, msr);
1398  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum))
1399  regcache_raw_collect (regcache, tdep->ppc_cr_regnum, cr);
1400  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum))
1401  regcache_raw_collect (regcache, tdep->ppc_lr_regnum, lr);
1402  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ctr_regnum))
1403  regcache_raw_collect (regcache, tdep->ppc_ctr_regnum, ctr);
1404  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_xer_regnum))
1405  regcache_raw_collect (regcache, tdep->ppc_xer_regnum, xer);
1406  if (tdep->ppc_fpscr_regnum >= 0
1407  && REG_VALID == regcache_register_status (regcache,
1408  tdep->ppc_fpscr_regnum))
1409  regcache_raw_collect (regcache, tdep->ppc_fpscr_regnum, fpscr);
1410 }
1411 
1412 static void
1414  uint32_t *iar, uint32_t *msr, uint32_t *cr,
1415  uint32_t *lr, uint32_t *ctr, uint32_t *xer,
1416  uint32_t *fpscr)
1417 {
1418  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1419  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1420 
1421  /* Verify that the size of the size of the IAR buffer is the
1422  same as the raw size of the PC (in the register cache). If
1423  they're not, then either GDB has been built incorrectly, or
1424  there's some other kind of internal error. To be really safe,
1425  we should check all of the sizes. */
1426  gdb_assert (sizeof (*iar) == register_size (gdbarch,
1427  gdbarch_pc_regnum (gdbarch)));
1428 
1429  if (REG_VALID == regcache_register_status (regcache,
1430  gdbarch_pc_regnum (gdbarch)))
1431  regcache_raw_collect (regcache, gdbarch_pc_regnum (gdbarch), iar);
1432  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum))
1433  regcache_raw_collect (regcache, tdep->ppc_ps_regnum, msr);
1434  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum))
1435  regcache_raw_collect (regcache, tdep->ppc_cr_regnum, cr);
1436  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum))
1437  regcache_raw_collect (regcache, tdep->ppc_lr_regnum, lr);
1438  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ctr_regnum))
1439  regcache_raw_collect (regcache, tdep->ppc_ctr_regnum, ctr);
1440  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_xer_regnum))
1441  regcache_raw_collect (regcache, tdep->ppc_xer_regnum, xer);
1442  if (tdep->ppc_fpscr_regnum >= 0
1443  && REG_VALID == regcache_register_status (regcache, tdep->ppc_fpscr_regnum))
1444  regcache_raw_collect (regcache, tdep->ppc_fpscr_regnum, fpscr);
1445 }
1446 
1447 /* Store all registers into pthread PDTID, which doesn't have a kernel
1448  thread.
1449 
1450  It's possible to store a single register into a non-kernel pthread,
1451  but I doubt it's worth the effort. */
1452 
1453 static void
1454 store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
1455 {
1456  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1457  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1458  int status, i;
1459  pthdb_context_t ctx;
1460  uint32_t int32;
1461  uint64_t int64;
1462  double dbl;
1463 
1464  if (debug_aix_thread)
1466  "store_regs_user_thread %lx\n", (long) pdtid);
1467 
1468  /* Retrieve the thread's current context for its non-register
1469  values. */
1470  status = pthdb_pthread_context (pd_session, pdtid, &ctx);
1471  if (status != PTHDB_SUCCESS)
1472  error (_("aix-thread: store_registers: pthdb_pthread_context returned %s"),
1473  pd_status2str (status));
1474 
1475  /* Collect general-purpose register values from the regcache. */
1476 
1477  for (i = 0; i < ppc_num_gprs; i++)
1478  if (REG_VALID == regcache_register_status (regcache,
1479  tdep->ppc_gp0_regnum + i))
1480  {
1481  if (arch64)
1482  {
1483  regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + i,
1484  (void *) &int64);
1485  ctx.gpr[i] = int64;
1486  }
1487  else
1488  {
1489  regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + i,
1490  (void *) &int32);
1491  ctx.gpr[i] = int32;
1492  }
1493  }
1494 
1495  /* Collect floating-point register values from the regcache. */
1496  if (ppc_floating_point_unit_p (gdbarch))
1497  fill_fprs (regcache, ctx.fpr);
1498 
1499  /* Special registers (always kept in ctx as 64 bits). */
1500  if (arch64)
1501  {
1502  fill_sprs64 (regcache, &ctx.iar, &ctx.msr, &ctx.cr, &ctx.lr, &ctx.ctr,
1503  &ctx.xer, &ctx.fpscr);
1504  }
1505  else
1506  {
1507  /* Problem: ctx.iar etc. are 64 bits, but raw_registers are 32.
1508  Solution: use 32-bit temp variables. */
1509  uint32_t tmp_iar, tmp_msr, tmp_cr, tmp_lr, tmp_ctr, tmp_xer,
1510  tmp_fpscr;
1511 
1512  fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr, &tmp_ctr,
1513  &tmp_xer, &tmp_fpscr);
1514  if (REG_VALID == regcache_register_status (regcache,
1515  gdbarch_pc_regnum (gdbarch)))
1516  ctx.iar = tmp_iar;
1517  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum))
1518  ctx.msr = tmp_msr;
1519  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum))
1520  ctx.cr = tmp_cr;
1521  if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum))
1522  ctx.lr = tmp_lr;
1523  if (REG_VALID == regcache_register_status (regcache,
1524  tdep->ppc_ctr_regnum))
1525  ctx.ctr = tmp_ctr;
1526  if (REG_VALID == regcache_register_status (regcache,
1527  tdep->ppc_xer_regnum))
1528  ctx.xer = tmp_xer;
1529  if (REG_VALID == regcache_register_status (regcache,
1530  tdep->ppc_xer_regnum))
1531  ctx.fpscr = tmp_fpscr;
1532  }
1533 
1534  status = pthdb_pthread_setcontext (pd_session, pdtid, &ctx);
1535  if (status != PTHDB_SUCCESS)
1536  error (_("aix-thread: store_registers: "
1537  "pthdb_pthread_setcontext returned %s"),
1538  pd_status2str (status));
1539 }
1540 
1541 /* Store register REGNO if != -1 or all registers otherwise into
1542  kernel thread TID.
1543 
1544  AIX provides a way to set all of a kernel thread's GPRs, FPRs, or
1545  SPRs, but there's no way to set individual registers within those
1546  groups. Therefore, if REGNO != -1, this function stores an entire
1547  group. */
1548 
1549 static void
1550 store_regs_kernel_thread (const struct regcache *regcache, int regno,
1551  pthdb_tid_t tid)
1552 {
1553  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1554  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1555  uint64_t gprs64[ppc_num_gprs];
1556  uint32_t gprs32[ppc_num_gprs];
1557  double fprs[ppc_num_fprs];
1558  struct ptxsprs sprs64;
1559  struct ptsprs sprs32;
1560  int i;
1561 
1562  if (debug_aix_thread)
1564  "store_regs_kernel_thread tid=%lx regno=%d\n",
1565  (long) tid, regno);
1566 
1567  /* General-purpose registers. */
1568  if (regno == -1
1569  || (tdep->ppc_gp0_regnum <= regno
1570  && regno < tdep->ppc_gp0_regnum + ppc_num_fprs))
1571  {
1572  if (arch64)
1573  {
1574  /* Pre-fetch: some regs may not be in the cache. */
1575  ptrace64aix (PTT_READ_GPRS, tid, (unsigned long) gprs64, 0, NULL);
1576  fill_gprs64 (regcache, gprs64);
1577  ptrace64aix (PTT_WRITE_GPRS, tid, (unsigned long) gprs64, 0, NULL);
1578  }
1579  else
1580  {
1581  /* Pre-fetch: some regs may not be in the cache. */
1582  ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL);
1583  fill_gprs32 (regcache, gprs32);
1584  ptrace32 (PTT_WRITE_GPRS, tid, (uintptr_t) gprs32, 0, NULL);
1585  }
1586  }
1587 
1588  /* Floating-point registers. */
1589 
1590  if (ppc_floating_point_unit_p (gdbarch)
1591  && (regno == -1
1592  || (regno >= tdep->ppc_fp0_regnum
1593  && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
1594  {
1595  /* Pre-fetch: some regs may not be in the cache. */
1596  ptrace32 (PTT_READ_FPRS, tid, (uintptr_t) fprs, 0, NULL);
1597  fill_fprs (regcache, fprs);
1598  ptrace32 (PTT_WRITE_FPRS, tid, (uintptr_t) fprs, 0, NULL);
1599  }
1600 
1601  /* Special-purpose registers. */
1602 
1603  if (regno == -1 || special_register_p (gdbarch, regno))
1604  {
1605  if (arch64)
1606  {
1607  /* Pre-fetch: some registers won't be in the cache. */
1608  ptrace64aix (PTT_READ_SPRS, tid,
1609  (unsigned long) &sprs64, 0, NULL);
1610  fill_sprs64 (regcache, &sprs64.pt_iar, &sprs64.pt_msr,
1611  &sprs64.pt_cr, &sprs64.pt_lr, &sprs64.pt_ctr,
1612  &sprs64.pt_xer, &sprs64.pt_fpscr);
1613  ptrace64aix (PTT_WRITE_SPRS, tid,
1614  (unsigned long) &sprs64, 0, NULL);
1615  }
1616  else
1617  {
1618  /* The contents of "struct ptspr" were declared as "unsigned
1619  long" up to AIX 5.2, but are "unsigned int" since 5.3.
1620  Use temporaries to work around this problem. Also, add an
1621  assert here to make sure we fail if the system header files
1622  use "unsigned long", and the size of that type is not what
1623  the headers expect. */
1624  uint32_t tmp_iar, tmp_msr, tmp_cr, tmp_lr, tmp_ctr, tmp_xer,
1625  tmp_fpscr;
1626 
1627  gdb_assert (sizeof (sprs32.pt_iar) == 4);
1628 
1629  /* Pre-fetch: some registers won't be in the cache. */
1630  ptrace32 (PTT_READ_SPRS, tid, (uintptr_t) &sprs32, 0, NULL);
1631 
1632  fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr,
1633  &tmp_ctr, &tmp_xer, &tmp_fpscr);
1634 
1635  sprs32.pt_iar = tmp_iar;
1636  sprs32.pt_msr = tmp_msr;
1637  sprs32.pt_cr = tmp_cr;
1638  sprs32.pt_lr = tmp_lr;
1639  sprs32.pt_ctr = tmp_ctr;
1640  sprs32.pt_xer = tmp_xer;
1641  sprs32.pt_fpscr = tmp_fpscr;
1642 
1643  if (tdep->ppc_mq_regnum >= 0)
1644  if (REG_VALID == regcache_register_status (regcache,
1645  tdep->ppc_mq_regnum))
1646  regcache_raw_collect (regcache, tdep->ppc_mq_regnum,
1647  &sprs32.pt_mq);
1648 
1649  ptrace32 (PTT_WRITE_SPRS, tid, (uintptr_t) &sprs32, 0, NULL);
1650  }
1651  }
1652 }
1653 
1654 /* Store gdb's current view of the register set into the
1655  thread/process specified by inferior_ptid. */
1656 
1657 static void
1659  struct regcache *regcache, int regno)
1660 {
1661  struct thread_info *thread;
1662  pthdb_tid_t tid;
1663  struct target_ops *beneath = find_target_beneath (ops);
1664 
1665  if (!PD_TID (inferior_ptid))
1666  beneath->to_store_registers (beneath, regcache, regno);
1667  else
1668  {
1669  thread = find_thread_ptid (inferior_ptid);
1670  tid = thread->priv->tid;
1671 
1672  if (tid == PTHDB_INVALID_TID)
1673  store_regs_user_thread (regcache, thread->priv->pdtid);
1674  else
1675  store_regs_kernel_thread (regcache, regno, tid);
1676  }
1677 }
1678 
1679 /* Implement the to_xfer_partial target_ops method. */
1680 
1681 static enum target_xfer_status
1683  const char *annex, gdb_byte *readbuf,
1684  const gdb_byte *writebuf,
1685  ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
1686 {
1687  struct cleanup *old_chain = save_inferior_ptid ();
1688  enum target_xfer_status xfer;
1689  struct target_ops *beneath = find_target_beneath (ops);
1690 
1692  xfer = beneath->to_xfer_partial (beneath, object, annex, readbuf,
1693  writebuf, offset, len, xfered_len);
1694 
1695  do_cleanups (old_chain);
1696  return xfer;
1697 }
1698 
1699 /* Clean up after the inferior exits. */
1700 
1701 static void
1703 {
1704  struct target_ops *beneath = find_target_beneath (ops);
1705 
1706  pd_deactivate ();
1707  beneath->to_mourn_inferior (beneath);
1708 }
1709 
1710 /* Return whether thread PID is still valid. */
1711 
1712 static int
1714 {
1715  struct target_ops *beneath = find_target_beneath (ops);
1716 
1717  if (!PD_TID (ptid))
1718  return beneath->to_thread_alive (beneath, ptid);
1719 
1720  /* We update the thread list every time the child stops, so all
1721  valid threads should be in the thread list. */
1722  return in_thread_list (ptid);
1723 }
1724 
1725 /* Return a printable representation of composite PID for use in
1726  "info threads" output. */
1727 
1728 static char *
1730 {
1731  static char *ret = NULL;
1732  struct target_ops *beneath = find_target_beneath (ops);
1733 
1734  if (!PD_TID (ptid))
1735  return beneath->to_pid_to_str (beneath, ptid);
1736 
1737  /* Free previous return value; a new one will be allocated by
1738  xstrprintf(). */
1739  xfree (ret);
1740 
1741  ret = xstrprintf (_("Thread %ld"), ptid_get_tid (ptid));
1742  return ret;
1743 }
1744 
1745 /* Return a printable representation of extra information about
1746  THREAD, for use in "info threads" output. */
1747 
1748 static char *
1750  struct thread_info *thread)
1751 {
1752  struct ui_file *buf;
1753  int status;
1754  pthdb_pthread_t pdtid;
1755  pthdb_tid_t tid;
1756  pthdb_state_t state;
1757  pthdb_suspendstate_t suspendstate;
1758  pthdb_detachstate_t detachstate;
1759  int cancelpend;
1760  static char *ret = NULL;
1761 
1762  if (!PD_TID (thread->ptid))
1763  return NULL;
1764 
1765  buf = mem_fileopen ();
1766 
1767  pdtid = thread->priv->pdtid;
1768  tid = thread->priv->tid;
1769 
1770  if (tid != PTHDB_INVALID_TID)
1771  /* i18n: Like "thread-identifier %d, [state] running, suspended" */
1772  fprintf_unfiltered (buf, _("tid %d"), (int)tid);
1773 
1774  status = pthdb_pthread_state (pd_session, pdtid, &state);
1775  if (status != PTHDB_SUCCESS)
1776  state = PST_NOTSUP;
1777  fprintf_unfiltered (buf, ", %s", state2str (state));
1778 
1779  status = pthdb_pthread_suspendstate (pd_session, pdtid,
1780  &suspendstate);
1781  if (status == PTHDB_SUCCESS && suspendstate == PSS_SUSPENDED)
1782  /* i18n: Like "Thread-Id %d, [state] running, suspended" */
1783  fprintf_unfiltered (buf, _(", suspended"));
1784 
1785  status = pthdb_pthread_detachstate (pd_session, pdtid,
1786  &detachstate);
1787  if (status == PTHDB_SUCCESS && detachstate == PDS_DETACHED)
1788  /* i18n: Like "Thread-Id %d, [state] running, detached" */
1789  fprintf_unfiltered (buf, _(", detached"));
1790 
1791  pthdb_pthread_cancelpend (pd_session, pdtid, &cancelpend);
1792  if (status == PTHDB_SUCCESS && cancelpend)
1793  /* i18n: Like "Thread-Id %d, [state] running, cancel pending" */
1794  fprintf_unfiltered (buf, _(", cancel pending"));
1795 
1796  ui_file_write (buf, "", 1);
1797 
1798  xfree (ret); /* Free old buffer. */
1799 
1800  ret = ui_file_xstrdup (buf, NULL);
1801  ui_file_delete (buf);
1802 
1803  return ret;
1804 }
1805 
1806 static ptid_t
1807 aix_thread_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
1808 {
1809  return ptid_build (ptid_get_pid (inferior_ptid), 0, thread);
1810 }
1811 
1812 /* Initialize target aix_thread_ops. */
1813 
1814 static void
1816 {
1817  aix_thread_ops.to_shortname = "aix-threads";
1818  aix_thread_ops.to_longname = _("AIX pthread support");
1819  aix_thread_ops.to_doc = _("AIX pthread support");
1820 
1834 }
1835 
1836 /* Module startup initialization function, automagically called by
1837  init.c. */
1838 
1839 void _initialize_aix_thread (void);
1840 
1841 void
1843 {
1846 
1847  /* Notice when object files get loaded and unloaded. */
1849 
1850  /* Add ourselves to inferior_created event chain.
1851  This is needed to enable the thread target on "attach". */
1853 
1855  _("Set debugging of AIX thread module."),
1856  _("Show debugging of AIX thread module."),
1857  _("Enables debugging output (used to debug GDB)."),
1858  NULL, NULL,
1859  /* FIXME: i18n: Debugging of AIX thread
1860  module is \"%d\". */
1862 }
static void fill_fprs(const struct regcache *regcache, double *vals)
Definition: aix-thread.c:1355
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5143
struct private_thread_info * priv
Definition: gdbthread.h:270
static void pd_disable(void)
Definition: aix-thread.c:931
struct thread_info * add_thread(ptid_t ptid)
Definition: thread.c:305
struct thread_info * find_thread_ptid(ptid_t ptid)
Definition: thread.c:393
static int ptid_cmp(ptid_t ptid1, ptid_t ptid2)
Definition: aix-thread.c:623
const char * to_longname
Definition: target.h:433
int getthrds(pid_t, struct thrdsinfo64 *, int, tid_t *, int)
bfd_vma CORE_ADDR
Definition: common-types.h:41
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition: target.c:1474
struct regcache * get_thread_regcache(ptid_t ptid)
Definition: regcache.c:529
void delete_thread(ptid_t)
Definition: thread.c:368
void xfree(void *)
Definition: common-utils.c:97
static void aix_thread_detach(struct target_ops *ops, const char *args, int from_tty)
Definition: aix-thread.c:968
static pthdb_callbacks_t pd_callbacks
Definition: aix-thread.c:139
int ppc_lr_regnum
Definition: ppc-tdep.h:218
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
#define BMSYMBOL_VALUE_ADDRESS(symbol)
Definition: symtab.h:393
char *(* to_pid_to_str)(struct target_ops *, ptid_t) TARGET_DEFAULT_FUNC(default_pid_to_str)
Definition: target.h:631
char * ui_file_xstrdup(struct ui_file *file, long *length)
Definition: ui-file.c:345
static char * pd_status2str(int status)
Definition: aix-thread.c:159
void push_target(struct target_ops *t)
Definition: target.c:664
void ui_file_delete(struct ui_file *file)
Definition: ui-file.c:76
char *(* to_extra_thread_info)(struct target_ops *, struct thread_info *) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:633
int ppc_fpscr_regnum
Definition: ppc-tdep.h:228
int unpush_target(struct target_ops *t)
Definition: target.c:711
static CORE_ADDR pd_brk_addr
Definition: aix-thread.c:107
static int pdc_read_data(pthdb_user_t, void *, pthdb_addr_t, size_t)
Definition: aix-thread.c:455
static enum target_xfer_status aix_thread_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
Definition: aix-thread.c:1682
static void aix_thread_fetch_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: aix-thread.c:1304
void _initialize_aix_thread(void)
Definition: aix-thread.c:1842
static int giter_accum(struct thread_info *thread, void *bufp)
Definition: aix-thread.c:610
static void store_regs_kernel_thread(const struct regcache *regcache, int regno, pthdb_tid_t tid)
Definition: aix-thread.c:1550
static int pdc_alloc(pthdb_user_t, size_t, void **)
Definition: aix-thread.c:500
struct breakpoint * create_thread_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
Definition: breakpoint.c:7620
static void pd_enable(void)
Definition: aix-thread.c:889
ptid_t(* to_wait)(struct target_ops *, ptid_t, struct target_waitstatus *, int TARGET_DEBUG_PRINTER(target_debug_print_options)) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:468
static void supply_fprs(struct regcache *regcache, double *vals)
Definition: aix-thread.c:1076
#define _(String)
Definition: gdb_locale.h:40
static int giter_count(struct thread_info *thread, void *countp)
Definition: aix-thread.c:595
int ppc_cr_regnum
Definition: ppc-tdep.h:217
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
long tid
Definition: ptid.h:44
PTRACE_TYPE_RET ptrace()
Definition: ptid.h:35
ptid_t ptid_build(int pid, long lwp, long tid)
Definition: ptid.c:31
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition: gnu-nat.c:1885
struct observer * observer_attach_inferior_created(observer_inferior_created_ftype *f)
int in_thread_list(ptid_t ptid)
Definition: thread.c:482
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition: thread.c:419
static int pdc_write_regs(pthdb_user_t user, pthdb_tid_t tid, unsigned long long flags, pthdb_context_t *context)
Definition: aix-thread.c:405
const char *const name
Definition: aarch64-tdep.c:68
static int iter_tid(struct thread_info *thread, void *tidp)
Definition: aix-thread.c:808
struct cleanup * save_inferior_ptid(void)
Definition: infrun.c:7538
#define OPS_MAGIC
Definition: target.h:1233
CORE_ADDR gdbarch_decr_pc_after_break(struct gdbarch *gdbarch)
Definition: gdbarch.c:2754
static int pdc_write_data(pthdb_user_t, void *, pthdb_addr_t, size_t)
Definition: aix-thread.c:477
static void pid_to_prc(ptid_t *ptidp)
Definition: aix-thread.c:273
static void store_regs_user_thread(const struct regcache *regcache, pthdb_pthread_t pdtid)
Definition: aix-thread.c:1454
void complete_target_initialization(struct target_ops *t)
Definition: target.c:317
static pthdb_session_t pd_session
Definition: aix-thread.c:153
enum gdb_signal sig
Definition: waitstatus.h:108
static char * state2str(pthdb_state_t state)
Definition: aix-thread.c:552
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2361
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
Definition: gnu-nat.c:1816
void(* to_resume)(struct target_ops *, ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:464
int ppc_gp0_regnum
Definition: ppc-tdep.h:214
static void supply_sprs32(struct regcache *regcache, uint32_t iar, uint32_t msr, uint32_t cr, uint32_t lr, uint32_t ctr, uint32_t xer, uint32_t fpscr)
Definition: aix-thread.c:1138
static void supply_gprs64(struct regcache *regcache, uint64_t *vals)
Definition: aix-thread.c:1055
ptid_t pid_to_ptid(int pid)
Definition: ptid.c:44
struct type * int32
Definition: m32c-tdep.c:125
static void fill_sprs64(const struct regcache *regcache, uint64_t *iar, uint64_t *msr, uint32_t *cr, uint64_t *lr, uint64_t *ctr, uint32_t *xer, uint32_t *fpscr)
Definition: aix-thread.c:1377
union target_waitstatus::@161 value
target_xfer_status
Definition: target.h:219
static int pcmp(const void *p1v, const void *p2v)
Definition: aix-thread.c:580
struct type * int64
Definition: m32c-tdep.c:125
int gdb_signal_to_host(enum gdb_signal)
Definition: signals.c:631
static pthdb_tid_t get_signaled_thread(void)
Definition: aix-thread.c:658
static void sync_threadlists(void)
Definition: aix-thread.c:692
#define PD_USER
Definition: aix-thread.c:78
#define gdb_assert(expr)
Definition: gdb_assert.h:33
const char * to_doc
Definition: target.h:434
static int pdc_symbol_addrs(pthdb_user_t, pthdb_symbol_t *, int)
Definition: aix-thread.c:286
static void new_objfile(struct objfile *objfile)
Definition: aix-thread.c:949
#define PDC_SUCCESS
Definition: aix-thread.c:82
static void aix_thread_mourn_inferior(struct target_ops *ops)
Definition: aix-thread.c:1702
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
Definition: target.h:724
struct target_ops * find_target_beneath(struct target_ops *t)
Definition: target.c:3148
char * xstrprintf(const char *format,...)
Definition: common-utils.c:107
static ptid_t aix_thread_wait(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options)
Definition: aix-thread.c:1022
struct cmd_list_element * setdebuglist
Definition: cli-cmds.c:173
void(* to_detach)(struct target_ops *ops, const char *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:460
void * xmalloc(YYSIZE_T)
struct ui_file * gdb_stdlog
Definition: main.c:73
struct ui_file * mem_fileopen(void)
Definition: ui-file.c:427
pthdb_pthread_t pdtid
Definition: aix-thread.c:88
target_object
Definition: target.h:136
static int pdc_realloc(pthdb_user_t, void *, size_t, void **)
Definition: aix-thread.c:522
static int aix_thread_thread_alive(struct target_ops *ops, ptid_t ptid)
Definition: aix-thread.c:1713
pthread_t pthid
Definition: aix-thread.c:96
static ptid_t aix_thread_get_ada_task_ptid(struct target_ops *self, long lwp, long thread)
Definition: aix-thread.c:1807
int ptid_get_pid(ptid_t ptid)
Definition: ptid.c:52
#define addr_ptr
Definition: aix-thread.c:258
pthdb_tid_t tid
Definition: aix-thread.c:89
static void supply_sprs64(struct regcache *regcache, uint64_t iar, uint64_t msr, uint32_t cr, uint64_t lr, uint64_t ctr, uint32_t xer, uint32_t fpscr)
Definition: aix-thread.c:1114
PTR xrealloc(PTR ptr, size_t size)
Definition: common-utils.c:51
static void fill_gprs64(const struct regcache *regcache, uint64_t *vals)
Definition: aix-thread.c:1328
bfd_byte gdb_byte
Definition: common-types.h:38
int ppc_ctr_regnum
Definition: ppc-tdep.h:219
static int pd_able
Definition: aix-thread.c:111
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:472
long ptid_get_tid(ptid_t ptid)
Definition: ptid.c:68
static int pd_active
Definition: aix-thread.c:115
void(* to_mourn_inferior)(struct target_ops *) TARGET_DEFAULT_FUNC(default_mourn_inferior)
Definition: target.h:607
enum register_status regcache_register_status(const struct regcache *regcache, int regnum)
Definition: regcache.c:446
ptid_t ptid
Definition: gdbthread.h:169
enum target_waitkind kind
Definition: waitstatus.h:100
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1393
CORE_ADDR regcache_read_pc(struct regcache *regcache)
Definition: regcache.c:1174
ptid_t inferior_ptid
Definition: infcmd.c:124
struct minimal_symbol * minsym
Definition: minsyms.h:32
char * safe_strerror(int)
enum strata to_stratum
Definition: target.h:650
int ppc_ps_regnum
Definition: ppc-tdep.h:216
static void fill_sprs32(const struct regcache *regcache, uint32_t *iar, uint32_t *msr, uint32_t *cr, uint32_t *lr, uint32_t *ctr, uint32_t *xer, uint32_t *fpscr)
Definition: aix-thread.c:1413
void ui_file_write(struct ui_file *file, const char *buf, long length_buf)
Definition: ui-file.c:218
int offset
Definition: agent.c:65
static void init_aix_thread_ops(void)
Definition: aix-thread.c:1815
int ppc_xer_regnum
Definition: ppc-tdep.h:220
#define qsort
Definition: ada-exp.c:2747
static int gcmp(const void *t1v, const void *t2v)
Definition: aix-thread.c:646
int ppc_mq_regnum
Definition: ppc-tdep.h:231
static int ptrace32(int req, int id, addr_ptr addr, int data, int *buf)
Definition: aix-thread.c:262
static void fill_gprs32(const struct regcache *regcache, uint32_t *vals)
Definition: aix-thread.c:1341
static void supply_reg32(struct regcache *regcache, int regno, uint32_t val)
Definition: aix-thread.c:1068
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1041
#define PDC_FAILURE
Definition: aix-thread.c:83
const char * to_shortname
Definition: target.h:432
unsigned long long ULONGEST
Definition: common-types.h:53
static int ptrace64aix(int req, int id, long long addr, int data, int *buf)
Definition: aix-thread.c:243
int to_magic
Definition: target.h:1224
int register_size(struct gdbarch *gdbarch, int regnum)
Definition: regcache.c:169
struct observer * observer_attach_new_objfile(observer_new_objfile_ftype *f)
long ptid_get_lwp(ptid_t ptid)
Definition: ptid.c:60
static void aix_thread_inferior_created(struct target_ops *ops, int from_tty)
Definition: aix-thread.c:960
static struct target_ops aix_thread_ops
Definition: aix-thread.c:102
static int pdc_read_regs(pthdb_user_t user, pthdb_tid_t tid, unsigned long long flags, pthdb_context_t *context)
Definition: aix-thread.c:333
#define pthdb_tid_t
Definition: aix-thread.c:68
pthdb_tid_t tid
Definition: aix-thread.c:97
static void aix_thread_resume(struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal sig)
Definition: aix-thread.c:980
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1071
struct cmd_list_element * showdebuglist
Definition: cli-cmds.c:175
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:1998
int(* to_thread_alive)(struct target_ops *, ptid_t ptid) TARGET_DEFAULT_RETURN(0)
Definition: target.h:627
static void fetch_regs_user_thread(struct regcache *regcache, pthdb_pthread_t pdtid)
Definition: aix-thread.c:1166
static void pd_deactivate(void)
Definition: aix-thread.c:875
static char * aix_thread_pid_to_str(struct target_ops *ops, ptid_t ptid)
Definition: aix-thread.c:1729
static void aix_thread_store_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: aix-thread.c:1658
#define PD_TID(ptid)
Definition: aix-thread.c:73
static ptid_t pd_activate(int set_infpid)
Definition: aix-thread.c:857
static int ptrace_check(int req, int id, int ret)
Definition: aix-thread.c:203
static int special_register_p(struct gdbarch *gdbarch, int regno)
Definition: aix-thread.c:1095
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:474
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition: minsyms.c:163
int ppc_floating_point_unit_p(struct gdbarch *gdbarch)
Definition: rs6000-tdep.c:212
static int arch64
Definition: aix-thread.c:120
ptid_t(* to_get_ada_task_ptid)(struct target_ops *, long lwp, long thread) TARGET_DEFAULT_FUNC(default_get_ada_task_ptid)
Definition: target.h:776
void error(const char *fmt,...)
Definition: errors.c:38
int ppc_fp0_regnum
Definition: ppc-tdep.h:227
static ptid_t pd_update(int set_infpid)
Definition: aix-thread.c:820
struct target_ops * beneath
Definition: target.h:431
pthdb_pthread_t pdtid
Definition: aix-thread.c:95
static int debug_aix_thread
Definition: aix-thread.c:64
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:541
static int pdc_dealloc(pthdb_user_t, void *)
Definition: aix-thread.c:539
static void fetch_regs_kernel_thread(struct regcache *regcache, int regno, pthdb_tid_t tid)
Definition: aix-thread.c:1220
static char * aix_thread_extra_thread_info(struct target_ops *self, struct thread_info *thread)
Definition: aix-thread.c:1749
const ULONGEST const LONGEST len
Definition: target.h:309