GDB (xrefs)
Loading...
Searching...
No Matches
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-2023 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 "observable.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
60extern int getthrds (pid_t, struct thrdsinfo64 *, int, tid_t *, int);
61#endif
62
63/* Whether to emit debugging output. */
64static bool 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/* Success and failure values returned by pthdb callbacks. */
72
73#define PDC_SUCCESS PTHDB_SUCCESS
74#define PDC_FAILURE PTHDB_CALLBACK
75
76/* Private data attached to each element in GDB's thread list. */
77
79{
80 pthdb_pthread_t pdtid; /* thread's libpthdebug id */
81 pthdb_tid_t tid; /* kernel thread id */
82};
83
84/* Return the aix_thread_info attached to THREAD. */
85
86static aix_thread_info *
88{
89 return gdb::checked_static_cast<aix_thread_info *> (thread->priv.get ());
90}
91
92/* Information about a thread of which libpthdebug is aware. */
93
94struct 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 "aix-threads",
104 N_("AIX pthread support"),
105 N_("AIX pthread support")
106};
107
108class aix_thread_target final : public target_ops
109{
110public:
111 const target_info &info () const override
112 { return aix_thread_target_info; }
113
114 strata stratum () const override { return thread_stratum; }
115
116 void detach (inferior *, int) override;
117 void resume (ptid_t, int, enum gdb_signal) override;
118 ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
119
120 void fetch_registers (struct regcache *, int) override;
121 void store_registers (struct regcache *, int) override;
122
124 const char *annex,
125 gdb_byte *readbuf,
126 const gdb_byte *writebuf,
127 ULONGEST offset, ULONGEST len,
128 ULONGEST *xfered_len) override;
129
130 void mourn_inferior () override;
131
132 bool thread_alive (ptid_t ptid) override;
133
134 std::string pid_to_str (ptid_t) override;
135
136 const char *extra_thread_info (struct thread_info *) override;
137
138 ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
139};
140
142
143/* Forward declarations for pthdb callbacks. */
144
145static int pdc_symbol_addrs (pthdb_user_t, pthdb_symbol_t *, int);
146static int pdc_read_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
147static int pdc_write_data (pthdb_user_t, void *, pthdb_addr_t, size_t);
148static int pdc_read_regs (pthdb_user_t user, pthdb_tid_t tid,
149 unsigned long long flags,
150 pthdb_context_t *context);
151static int pdc_write_regs (pthdb_user_t user, pthdb_tid_t tid,
152 unsigned long long flags,
153 pthdb_context_t *context);
154static int pdc_alloc (pthdb_user_t, size_t, void **);
155static int pdc_realloc (pthdb_user_t, void *, size_t, void **);
156static int pdc_dealloc (pthdb_user_t, void *);
157
158/* pthdb callbacks. */
159
160static pthdb_callbacks_t pd_callbacks = {
166 pdc_alloc,
169 NULL
170};
171
172/* Aix variable structure. */
174{
175 /* Whether the current application is debuggable by pthdb. */
177
178 /* Whether a threaded application is being debugged. */
180
181 /* Current pthdb session. */
182 pthdb_session_t pd_session;
183
184 /* Address of the function that libpthread will call when libpthdebug
185 is ready to be initialized. */
186 CORE_ADDR pd_brk_addr;
187
188 /* Whether the current architecture is 64-bit.
189 Only valid when pd_able is true. */
191};
192
193/* Key to our per-inferior data. */
196
197/* Function to Get aix_thread_variables data. */
198static struct aix_thread_variables*
200{
201 if (inf == NULL)
202 return NULL;
203
204 struct aix_thread_variables* data;
205
207 if (data == NULL)
208 data = aix_thread_variables_handle.emplace (inf);
209
210 return data;
211}
212
213/* Helper to get data for ptid in a function. */
214
215static struct aix_thread_variables*
217{
218 inferior *inf = find_inferior_ptid (current_inferior ()->process_target (),
219 ptid);
221}
222
223/* Helper to get data for pid in a function. */
224
225static struct aix_thread_variables*
227{
228 inferior *inf = find_inferior_pid (current_inferior ()->process_target (),
229 pid);
231}
232
233/* Return a printable representation of pthdebug function return
234 STATUS. */
235
236static const char *
238{
239 switch (status)
240 {
241 case PTHDB_SUCCESS: return "SUCCESS";
242 case PTHDB_NOSYS: return "NOSYS";
243 case PTHDB_NOTSUP: return "NOTSUP";
244 case PTHDB_BAD_VERSION: return "BAD_VERSION";
245 case PTHDB_BAD_USER: return "BAD_USER";
246 case PTHDB_BAD_SESSION: return "BAD_SESSION";
247 case PTHDB_BAD_MODE: return "BAD_MODE";
248 case PTHDB_BAD_FLAGS: return "BAD_FLAGS";
249 case PTHDB_BAD_CALLBACK: return "BAD_CALLBACK";
250 case PTHDB_BAD_POINTER: return "BAD_POINTER";
251 case PTHDB_BAD_CMD: return "BAD_CMD";
252 case PTHDB_BAD_PTHREAD: return "BAD_PTHREAD";
253 case PTHDB_BAD_ATTR: return "BAD_ATTR";
254 case PTHDB_BAD_MUTEX: return "BAD_MUTEX";
255 case PTHDB_BAD_MUTEXATTR: return "BAD_MUTEXATTR";
256 case PTHDB_BAD_COND: return "BAD_COND";
257 case PTHDB_BAD_CONDATTR: return "BAD_CONDATTR";
258 case PTHDB_BAD_RWLOCK: return "BAD_RWLOCK";
259 case PTHDB_BAD_RWLOCKATTR: return "BAD_RWLOCKATTR";
260 case PTHDB_BAD_KEY: return "BAD_KEY";
261 case PTHDB_BAD_PTID: return "BAD_PTID";
262 case PTHDB_BAD_TID: return "BAD_TID";
263 case PTHDB_CALLBACK: return "CALLBACK";
264 case PTHDB_CONTEXT: return "CONTEXT";
265 case PTHDB_HELD: return "HELD";
266 case PTHDB_NOT_HELD: return "NOT_HELD";
267 case PTHDB_MEMORY: return "MEMORY";
268 case PTHDB_NOT_PTHREADED: return "NOT_PTHREADED";
269 case PTHDB_SYMBOL: return "SYMBOL";
270 case PTHDB_NOT_AVAIL: return "NOT_AVAIL";
271 case PTHDB_INTERNAL: return "INTERNAL";
272 default: return "UNKNOWN";
273 }
274}
275
276/* A call to ptrace(REQ, ID, ...) just returned RET. Check for
277 exceptional conditions and either return nonlocally or else return
278 1 for success and 0 for failure. */
279
280static int
281ptrace_check (int req, int id, int ret)
282{
283 if (ret == 0 && !errno)
284 return 1;
285
286 /* According to ptrace(2), ptrace may fail with EPERM if "the
287 Identifier parameter corresponds to a kernel thread which is
288 stopped in kernel mode and whose computational state cannot be
289 read or written." This happens quite often with register reads. */
290
291 switch (req)
292 {
293 case PTT_READ_GPRS:
294 case PTT_READ_FPRS:
295 case PTT_READ_SPRS:
296 if (ret == -1 && errno == EPERM)
297 {
300 "ptrace (%d, %d) = %d (errno = %d)\n",
301 req, id, ret, errno);
302 return ret == -1 ? 0 : 1;
303 }
304 break;
305 case PTT_READ_VEC:
306 case PTT_READ_VSX:
309 "ptrace (%d, %d) = %d (errno = %d)\n",
310 req, id, ret, errno);
311 if (ret == -1)
312 return -1;
313 break;
314 }
315 error (_("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)"),
316 req, id, ret, errno, safe_strerror (errno));
317 return 0; /* Not reached. */
318}
319
320/* Call ptracex (REQ, ID, ADDR, DATA, BUF) or
321 ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
322 Return success. */
323
324#ifdef HAVE_PTRACE64
325# define ptracex(request, pid, addr, data, buf) \
326 ptrace64 (request, pid, addr, data, buf)
327#endif
328
329static int
330ptrace64aix (int req, int id, long long addr, int data, int *buf)
331{
332 errno = 0;
333 return ptrace_check (req, id, ptracex (req, id, addr, data, buf));
334}
335
336/* Call ptrace (REQ, ID, ADDR, DATA, BUF) or
337 ptrace64 (REQ, ID, ADDR, DATA, BUF) if HAVE_PTRACE64.
338 Return success. */
339
340#ifdef HAVE_PTRACE64
341# define ptrace(request, pid, addr, data, buf) \
342 ptrace64 (request, pid, addr, data, buf)
343# define addr_ptr long long
344#else
345# define addr_ptr int *
346#endif
347
348static int
349ptrace32 (int req, int id, addr_ptr addr, int data, int *buf)
350{
351 errno = 0;
352 return ptrace_check (req, id,
353 ptrace (req, id, addr, data, buf));
354}
355
356/* If *PIDP is a composite process/thread id, convert it to a
357 process id. */
358
359static void
360pid_to_prc (ptid_t *ptidp)
361{
362 ptid_t ptid;
363
364 ptid = *ptidp;
365 if (ptid.tid () != 0)
366 *ptidp = ptid_t (ptid.pid ());
367}
368
369/* pthdb callback: for <i> from 0 to COUNT, set SYMBOLS[<i>].addr to
370 the address of SYMBOLS[<i>].name. */
371
372static int
373pdc_symbol_addrs (pthdb_user_t user_current_pid, pthdb_symbol_t *symbols, int count)
374{
375 struct bound_minimal_symbol ms;
376 int i;
377 char *name;
378
381 "pdc_symbol_addrs (user_current_pid = %ld, symbols = 0x%lx, count = %d)\n",
382 user_current_pid, (long) symbols, count);
383
384 for (i = 0; i < count; i++)
385 {
386 name = symbols[i].name;
389 " symbols[%d].name = \"%s\"\n", i, name);
390
391 if (!*name)
392 symbols[i].addr = 0;
393 else
394 {
395 ms = lookup_minimal_symbol (name, NULL, NULL);
396 if (ms.minsym == NULL)
397 {
399 gdb_printf (gdb_stdlog, " returning PDC_FAILURE\n");
400 return PDC_FAILURE;
401 }
402 symbols[i].addr = ms.value_address ();
403 }
405 gdb_printf (gdb_stdlog, " symbols[%d].addr = %s\n",
406 i, hex_string (symbols[i].addr));
407 }
409 gdb_printf (gdb_stdlog, " returning PDC_SUCCESS\n");
410 return PDC_SUCCESS;
411}
412
413/* Read registers call back function should be able to read the
414 context information of a debuggee kernel thread from an active
415 process or from a core file. The information should be formatted
416 in context64 form for both 32-bit and 64-bit process.
417 If successful return 0, else non-zero is returned. */
418
419static int
420pdc_read_regs (pthdb_user_t user_current_pid,
421 pthdb_tid_t tid,
422 unsigned long long flags,
423 pthdb_context_t *context)
424{
425 /* This function doesn't appear to be used, so we could probably
426 just return 0 here. HOWEVER, if it is not defined, the OS will
427 complain and several thread debug functions will fail. In case
428 this is needed, I have implemented what I think it should do,
429 however this code is untested. */
430
431 uint64_t gprs64[ppc_num_gprs];
432 uint32_t gprs32[ppc_num_gprs];
433 double fprs[ppc_num_fprs];
434 struct ptxsprs sprs64;
435 struct ptsprs sprs32;
436 struct aix_thread_variables *data;
437
438 data = get_thread_data_helper_for_pid (user_current_pid);
439
441 gdb_printf (gdb_stdlog, "pdc_read_regs tid=%d flags=%s\n",
442 (int) tid, hex_string (flags));
443
444 /* General-purpose registers. */
445 if (flags & PTHDB_FLAG_GPRS)
446 {
447 if (data->arch64)
448 {
449 if (!ptrace64aix (PTT_READ_GPRS, tid,
450 (unsigned long) gprs64, 0, NULL))
451 memset (gprs64, 0, sizeof (gprs64));
452 memcpy (context->gpr, gprs64, sizeof(gprs64));
453 }
454 else
455 {
456 if (!ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL))
457 memset (gprs32, 0, sizeof (gprs32));
458 memcpy (context->gpr, gprs32, sizeof(gprs32));
459 }
460 }
461
462 /* Floating-point registers. */
463 if (flags & PTHDB_FLAG_FPRS)
464 {
465 if (!ptrace32 (PTT_READ_FPRS, tid, (uintptr_t) fprs, 0, NULL))
466 memset (fprs, 0, sizeof (fprs));
467 memcpy (context->fpr, fprs, sizeof(fprs));
468 }
469
470 /* Special-purpose registers. */
471 if (flags & PTHDB_FLAG_SPRS)
472 {
473 if (data->arch64)
474 {
475 if (!ptrace64aix (PTT_READ_SPRS, tid,
476 (unsigned long) &sprs64, 0, NULL))
477 memset (&sprs64, 0, sizeof (sprs64));
478 memcpy (&context->msr, &sprs64, sizeof(sprs64));
479 }
480 else
481 {
482 if (!ptrace32 (PTT_READ_SPRS, tid, (uintptr_t) &sprs32, 0, NULL))
483 memset (&sprs32, 0, sizeof (sprs32));
484 memcpy (&context->msr, &sprs32, sizeof(sprs32));
485 }
486 }
487
488 /* vector registers. */
489 __vmx_context_t vmx;
490 if (__power_vmx() && (flags & PTHDB_FLAG_REGS))
491 {
492 if (data->arch64)
493 {
494 if (!ptrace64aix (PTT_READ_VEC, tid, (long long) &vmx, 0, 0))
495 memset (&vmx, 0, sizeof (vmx));
496 memcpy (&context->vmx, &vmx, sizeof(__vmx_context_t));
497 }
498 else
499 {
500 if (!ptrace32 (PTT_READ_VEC, tid, (long long) &vmx, 0, 0))
501 memset (&vmx, 0, sizeof (vmx));
502 memcpy (&context->vmx, &vmx, sizeof(__vmx_context_t));
503 }
504 }
505
506 /* vsx registers. */
507 __vsx_context_t vsx;
508 if (__power_vsx() && (flags & PTHDB_FLAG_REGS))
509 {
510 if (data->arch64)
511 {
512 if (!ptrace64aix (PTT_READ_VSX, tid, (long long) &vsx, 0, 0))
513 memset (&vsx, 0, sizeof (vsx));
514 memcpy (&context->vsx, &vsx, sizeof(__vsx_context_t));
515 }
516 else
517 {
518 if (!ptrace32 (PTT_READ_VSX, tid, (long long) &vsx, 0, 0))
519 memset (&vsx, 0, sizeof (vsx));
520 memcpy (&context->vsx, &vsx, sizeof(__vsx_context_t));
521 }
522 }
523 return 0;
524}
525
526/* Write register function should be able to write requested context
527 information to specified debuggee's kernel thread id.
528 If successful return 0, else non-zero is returned. */
529
530static int
531pdc_write_regs (pthdb_user_t user_current_pid,
532 pthdb_tid_t tid,
533 unsigned long long flags,
534 pthdb_context_t *context)
535{
536 /* This function doesn't appear to be used, so we could probably
537 just return 0 here. HOWEVER, if it is not defined, the OS will
538 complain and several thread debug functions will fail. In case
539 this is needed, I have implemented what I think it should do,
540 however this code is untested. */
541
542 struct aix_thread_variables *data;
543
544 data = get_thread_data_helper_for_pid (user_current_pid);
545
547 gdb_printf (gdb_stdlog, "pdc_write_regs tid=%d flags=%s\n",
548 (int) tid, hex_string (flags));
549
550 /* General-purpose registers. */
551 if (flags & PTHDB_FLAG_GPRS)
552 {
553 if (data->arch64)
554 ptrace64aix (PTT_WRITE_GPRS, tid,
555 (unsigned long) context->gpr, 0, NULL);
556 else
557 ptrace32 (PTT_WRITE_GPRS, tid, (uintptr_t) context->gpr, 0, NULL);
558 }
559
560 /* Floating-point registers. */
561 if (flags & PTHDB_FLAG_FPRS)
562 {
563 ptrace32 (PTT_WRITE_FPRS, tid, (uintptr_t) context->fpr, 0, NULL);
564 }
565
566 /* Special-purpose registers. */
567 if (flags & PTHDB_FLAG_SPRS)
568 {
569 if (data->arch64)
570 {
571 ptrace64aix (PTT_WRITE_SPRS, tid,
572 (unsigned long) &context->msr, 0, NULL);
573 }
574 else
575 {
576 ptrace32 (PTT_WRITE_SPRS, tid, (uintptr_t) &context->msr, 0, NULL);
577 }
578 }
579
580 /* vector registers. */
581 if (__power_vmx() && (flags & PTHDB_FLAG_REGS))
582 {
583 if (data->arch64)
584 ptrace64aix (PTT_WRITE_VEC, tid, (unsigned long) &context->vmx, 0, 0);
585 else
586 ptrace32 (PTT_WRITE_VEC, tid, (uintptr_t) &context->vmx, 0, 0);
587 }
588
589 /* vsx registers. */
590 if (__power_vsx() && (flags & PTHDB_FLAG_REGS))
591 {
592 if (data->arch64)
593 ptrace64aix (PTT_WRITE_VSX, tid, (unsigned long) &context->vsx, 0, 0);
594 else
595 ptrace32 (PTT_WRITE_VSX, tid, (uintptr_t) &context->vsx, 0, 0);
596 }
597 return 0;
598}
599
600/* pthdb callback: read LEN bytes from process ADDR into BUF. */
601
602static int
603pdc_read_data (pthdb_user_t user_current_pid, void *buf,
604 pthdb_addr_t addr, size_t len)
605{
606 int status, ret;
607 inferior *inf = find_inferior_pid (current_inferior ()->process_target (),
608 user_current_pid);
609
612 "pdc_read_data (user_current_pid = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
613 user_current_pid, (long) buf, hex_string (addr), len);
614
615 /* This is needed to eliminate the dependency of current thread
616 which is null so that thread reads the correct target memory. */
617 {
619 status = target_read_memory (addr, (gdb_byte *) buf, len);
620 }
621 ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
622
624 gdb_printf (gdb_stdlog, " status=%d, returning %s\n",
625 status, pd_status2str (ret));
626 return ret;
627}
628
629/* pthdb callback: write LEN bytes from BUF to process ADDR. */
630
631static int
632pdc_write_data (pthdb_user_t user_current_pid, void *buf,
633 pthdb_addr_t addr, size_t len)
634{
635 int status, ret;
636 inferior *inf = find_inferior_pid (current_inferior ()->process_target (),
637 user_current_pid);
638
641 "pdc_write_data (user_current_pid = %ld, buf = 0x%lx, addr = %s, len = %ld)\n",
642 user_current_pid, (long) buf, hex_string (addr), len);
643
644 {
646 status = target_write_memory (addr, (gdb_byte *) buf, len);
647 }
648
649 ret = status == 0 ? PDC_SUCCESS : PDC_FAILURE;
650
652 gdb_printf (gdb_stdlog, " status=%d, returning %s\n", status,
653 pd_status2str (ret));
654 return ret;
655}
656
657/* pthdb callback: allocate a LEN-byte buffer and store a pointer to it
658 in BUFP. */
659
660static int
661pdc_alloc (pthdb_user_t user_current_pid, size_t len, void **bufp)
662{
665 "pdc_alloc (user_current_pid = %ld, len = %ld, bufp = 0x%lx)\n",
666 user_current_pid, len, (long) bufp);
667 *bufp = xmalloc (len);
670 " malloc returned 0x%lx\n", (long) *bufp);
671
672 /* Note: xmalloc() can't return 0; therefore PDC_FAILURE will never
673 be returned. */
674
675 return *bufp ? PDC_SUCCESS : PDC_FAILURE;
676}
677
678/* pthdb callback: reallocate BUF, which was allocated by the alloc or
679 realloc callback, so that it contains LEN bytes, and store a
680 pointer to the result in BUFP. */
681
682static int
683pdc_realloc (pthdb_user_t user_current_pid, void *buf, size_t len, void **bufp)
684{
687 "pdc_realloc (user_current_pid = %ld, buf = 0x%lx, len = %ld, bufp = 0x%lx)\n",
688 user_current_pid, (long) buf, len, (long) bufp);
689 *bufp = xrealloc (buf, len);
692 " realloc returned 0x%lx\n", (long) *bufp);
693 return *bufp ? PDC_SUCCESS : PDC_FAILURE;
694}
695
696/* pthdb callback: free BUF, which was allocated by the alloc or
697 realloc callback. */
698
699static int
700pdc_dealloc (pthdb_user_t user_current_pid, void *buf)
701{
704 "pdc_free (user_current_pid = %ld, buf = 0x%lx)\n", user_current_pid,
705 (long) buf);
706 xfree (buf);
707 return PDC_SUCCESS;
708}
709
710/* Return a printable representation of pthread STATE. */
711
712static char *
713state2str (pthdb_state_t state)
714{
715 switch (state)
716 {
717 case PST_IDLE:
718 /* i18n: Like "Thread-Id %d, [state] idle" */
719 return _("idle"); /* being created */
720 case PST_RUN:
721 /* i18n: Like "Thread-Id %d, [state] running" */
722 return _("running"); /* running */
723 case PST_SLEEP:
724 /* i18n: Like "Thread-Id %d, [state] sleeping" */
725 return _("sleeping"); /* awaiting an event */
726 case PST_READY:
727 /* i18n: Like "Thread-Id %d, [state] ready" */
728 return _("ready"); /* runnable */
729 case PST_TERM:
730 /* i18n: Like "Thread-Id %d, [state] finished" */
731 return _("finished"); /* awaiting a join/detach */
732 default:
733 /* i18n: Like "Thread-Id %d, [state] unknown" */
734 return _("unknown");
735 }
736}
737
738/* qsort() comparison function for sorting pd_thread structs by pthid. */
739
740static int
741pcmp (const void *p1v, const void *p2v)
742{
743 struct pd_thread *p1 = (struct pd_thread *) p1v;
744 struct pd_thread *p2 = (struct pd_thread *) p2v;
745 return p1->pthid < p2->pthid ? -1 : p1->pthid > p2->pthid;
746}
747
748/* ptid comparison function */
749
750static int
751ptid_cmp (ptid_t ptid1, ptid_t ptid2)
752{
753 if (ptid1.pid () < ptid2.pid ())
754 return -1;
755 else if (ptid1.pid () > ptid2.pid ())
756 return 1;
757 else if (ptid1.tid () < ptid2.tid ())
758 return -1;
759 else if (ptid1.tid () > ptid2.tid ())
760 return 1;
761 else if (ptid1.lwp () < ptid2.lwp ())
762 return -1;
763 else if (ptid1.lwp () > ptid2.lwp ())
764 return 1;
765 else
766 return 0;
767}
768
769/* qsort() comparison function for sorting thread_info structs by pid. */
770
771static int
772gcmp (const void *t1v, const void *t2v)
773{
774 struct thread_info *t1 = *(struct thread_info **) t1v;
775 struct thread_info *t2 = *(struct thread_info **) t2v;
776 return ptid_cmp (t1->ptid, t2->ptid);
777}
778
779/* Search through the list of all kernel threads for the thread
780 that has stopped on a SIGTRAP signal, and return its TID.
781 Return 0 if none found. */
782
783static pthdb_tid_t
785{
786 struct thrdsinfo64 thrinf;
787 tid_t ktid = 0;
788
789 while (1)
790 {
791 if (getthrds (pid, &thrinf,
792 sizeof (thrinf), &ktid, 1) != 1)
793 break;
794
795 /* We also need to keep in mind Trap and interrupt or any
796 signal that needs to be handled in pd_update (). */
797
798 if (thrinf.ti_cursig)
799 return thrinf.ti_tid;
800 }
801
802 /* Didn't find any thread stopped on a SIGTRAP signal. */
803 return 0;
804}
805
806/* Synchronize GDB's thread list with libpthdebug's.
807
808 There are some benefits of doing this every time the inferior stops:
809
810 - allows users to run thread-specific commands without needing to
811 run "info threads" first
812
813 - helps pthdb_tid_pthread() work properly (see "libpthdebug
814 peculiarities" at the top of this module)
815
816 - simplifies the demands placed on libpthdebug, which seems to
817 have difficulty with certain call patterns */
818
819static void
821{
822 int cmd, status;
823 int pcount, psize, pi, gcount, gi;
824 struct pd_thread *pbuf;
825 struct thread_info **gbuf, **g, *thread;
826 pthdb_pthread_t pdtid;
827 pthread_t pthid;
828 pthdb_tid_t tid;
830 thread_info *tp;
831 struct aix_thread_variables *data;
833
834 /* Accumulate an array of libpthdebug threads sorted by pthread id. */
835
836 pcount = 0;
837 psize = 1;
838 pbuf = XNEWVEC (struct pd_thread, psize);
839
840 for (cmd = PTHDB_LIST_FIRST;; cmd = PTHDB_LIST_NEXT)
841 {
842 status = pthdb_pthread (data->pd_session, &pdtid, cmd);
843 if (status != PTHDB_SUCCESS || pdtid == PTHDB_INVALID_PTHREAD)
844 break;
845
846 status = pthdb_pthread_ptid (data->pd_session, pdtid, &pthid);
847 if (status != PTHDB_SUCCESS || pthid == PTHDB_INVALID_PTID)
848 continue;
849
850 if (pcount == psize)
851 {
852 psize *= 2;
853 pbuf = (struct pd_thread *) xrealloc (pbuf,
854 psize * sizeof *pbuf);
855 }
856 pbuf[pcount].pdtid = pdtid;
857 pbuf[pcount].pthid = pthid;
858 pcount++;
859 }
860
861 for (pi = 0; pi < pcount; pi++)
862 {
863 status = pthdb_pthread_tid (data->pd_session, pbuf[pi].pdtid, &tid);
864 if (status != PTHDB_SUCCESS)
865 tid = PTHDB_INVALID_TID;
866 pbuf[pi].tid = tid;
867 }
868
869 qsort (pbuf, pcount, sizeof *pbuf, pcmp);
870
871 /* Accumulate an array of GDB threads sorted by pid. */
872
873 /* gcount is GDB thread count and pcount is pthreadlib thread count. */
874
875 gcount = 0;
876 for (thread_info *tp : all_threads (proc_target, ptid_t (pid)))
877 gcount++;
878 g = gbuf = XNEWVEC (struct thread_info *, gcount);
879 for (thread_info *tp : all_threads (proc_target, ptid_t (pid)))
880 *g++ = tp;
881 qsort (gbuf, gcount, sizeof *gbuf, gcmp);
882
883 /* Apply differences between the two arrays to GDB's thread list. */
884
885 for (pi = gi = 0; pi < pcount || gi < gcount;)
886 {
887 if (pi == pcount)
888 {
889 delete_thread (gbuf[gi]);
890 gi++;
891 }
892 else if (gi == gcount)
893 {
895 priv->pdtid = pbuf[pi].pdtid;
896 priv->tid = pbuf[pi].tid;
897
898 thread = add_thread_with_info (proc_target,
899 ptid_t (pid, 0, pbuf[pi].pthid),
901
902 pi++;
903 }
904 else
905 {
906 ptid_t pptid, gptid;
907 int cmp_result;
908
909 pptid = ptid_t (pid, 0, pbuf[pi].pthid);
910 gptid = gbuf[gi]->ptid;
911 pdtid = pbuf[pi].pdtid;
912 tid = pbuf[pi].tid;
913
914 cmp_result = ptid_cmp (pptid, gptid);
915
916 if (cmp_result == 0)
917 {
918 aix_thread_info *priv = get_aix_thread_info (gbuf[gi]);
919
920 priv->pdtid = pdtid;
921 priv->tid = tid;
922 pi++;
923 gi++;
924 }
925 else if (cmp_result > 0)
926 {
927 /* This is to make the main process thread now look
928 like a thread. */
929
930 if (gptid.is_pid ())
931 {
932 tp = proc_target->find_thread (gptid);
933 thread_change_ptid (proc_target, gptid, pptid);
935 priv->pdtid = pbuf[pi].pdtid;
936 priv->tid = pbuf[pi].tid;
937 tp->priv.reset (priv);
938 gi++;
939 pi++;
940 }
941 else
942 {
943 delete_thread (gbuf[gi]);
944 gi++;
945 }
946 }
947 else
948 {
949 thread = add_thread (proc_target, pptid);
950
952 thread->priv.reset (priv);
953 priv->pdtid = pdtid;
954 priv->tid = tid;
955 pi++;
956 }
957 }
958 }
959
960 xfree (pbuf);
961 xfree (gbuf);
962}
963
964/* Iterate_over_threads() callback for locating a thread, using
965 the TID of its associated kernel thread. */
966
967static int
968iter_tid (struct thread_info *thread, void *tidp)
969{
970 const pthdb_tid_t tid = *(pthdb_tid_t *)tidp;
971 aix_thread_info *priv = get_aix_thread_info (thread);
972
973 return priv->tid == tid;
974}
975
976/* Synchronize libpthdebug's state with the inferior and with GDB,
977 generate a composite process/thread <pid> for the current thread,
978 Return the ptid of the event thread if one can be found, else
979 return a pid-only ptid with PID. */
980
981static ptid_t
983{
984 int status;
985 ptid_t ptid;
987 struct thread_info *thread = NULL;
988 struct aix_thread_variables *data;
989
991
992 if (!data->pd_active)
993 return ptid_t (pid);
994
995 status = pthdb_session_update (data->pd_session);
996 if (status != PTHDB_SUCCESS)
997 return ptid_t (pid);
998
1000
1001 /* Define "current thread" as one that just received a trap signal. */
1002
1003 tid = get_signaled_thread (pid);
1004 if (tid != 0)
1005 thread = iterate_over_threads (iter_tid, &tid);
1006 if (!thread)
1007 ptid = ptid_t (pid);
1008 else
1009 ptid = thread->ptid;
1010
1011 return ptid;
1012}
1013
1014/* Try to start debugging threads in the current process.
1015 If successful and there exists and we can find an event thread, return a ptid
1016 for that thread. Otherwise, return a ptid-only ptid using PID. */
1017
1018static ptid_t
1020{
1021 int status;
1022 struct aix_thread_variables *data;
1024
1025 status = pthdb_session_init (pid, data->arch64 ? PEM_64BIT : PEM_32BIT,
1026 PTHDB_FLAG_REGS, &pd_callbacks,
1027 &data->pd_session);
1028 if (status != PTHDB_SUCCESS)
1029 {
1030 return ptid_t (pid);
1031 }
1032 data->pd_active = 1;
1033 return pd_update (pid);
1034}
1035
1036/* An object file has just been loaded. Check whether the current
1037 application is pthreaded, and if so, prepare for thread debugging. */
1038
1039static void
1041{
1042 int status;
1043 char *stub_name;
1044 struct bound_minimal_symbol ms;
1045 struct aix_thread_variables *data;
1046
1047 if (inf == NULL)
1048 return;
1049
1051
1052 /* Don't initialize twice. */
1053 if (data->pd_able)
1054 return;
1055
1056 /* Check application word size. */
1057 data->arch64 = register_size (target_gdbarch (), 0) == 8;
1058
1059 /* Check whether the application is pthreaded. */
1060 stub_name = NULL;
1061 status = pthdb_session_pthreaded (inf->pid, PTHDB_FLAG_REGS,
1062 &pd_callbacks, &stub_name);
1063 if ((status != PTHDB_SUCCESS
1064 && status != PTHDB_NOT_PTHREADED) || !stub_name)
1065 return;
1066
1067 /* Set a breakpoint on the returned stub function. */
1068 ms = lookup_minimal_symbol (stub_name, NULL, NULL);
1069 if (ms.minsym == NULL)
1070 return;
1071 data->pd_brk_addr = ms.value_address ();
1072 if (!create_thread_event_breakpoint (target_gdbarch (), data->pd_brk_addr))
1073 return;
1074
1075 /* Prepare for thread debugging. */
1077 data->pd_able = 1;
1078
1079 /* When attaching / handling fork child, don't try activating
1080 thread debugging until we know about all shared libraries. */
1081 if (inf->in_initial_library_scan)
1082 return;
1083
1084 /* If we're debugging a core file or an attached inferior, the
1085 pthread library may already have been initialized, so try to
1086 activate thread debugging. */
1087 pd_activate (inf->pid);
1088}
1089
1090/* Undo the effects of pd_enable(). */
1091
1092static void
1094{
1095 struct aix_thread_variables *data;
1097
1098 if (!data->pd_able)
1099 return;
1100 if (!data->pd_active)
1101 return;
1102 pthdb_session_destroy (data->pd_session);
1103
1105 data->pd_active = 0;
1106 data->pd_able = 0;
1108}
1109
1110/* new_objfile observer callback.
1111
1112 Check whether a threaded application is being debugged, and if so, prepare
1113 for thread debugging. */
1114
1115static void
1117{
1119}
1120
1121/* Attach to process specified by ARGS. */
1122
1123static void
1128
1129/* Detach from the process attached to by aix_thread_attach(). */
1130
1131void
1133{
1134 target_ops *beneath = this->beneath ();
1135
1136 pd_disable (inf);
1137 beneath->detach (inf, from_tty);
1138}
1139
1140/* Tell the inferior process to continue running thread PID if != -1
1141 and all threads otherwise. */
1142
1143void
1144aix_thread_target::resume (ptid_t ptid, int step, enum gdb_signal sig)
1145{
1146 struct thread_info *thread;
1147 pthdb_tid_t tid[2];
1148 struct aix_thread_variables *data;
1149
1150 data = get_thread_data_helper_for_ptid (ptid);
1151
1152 if (ptid.tid () == 0)
1153 {
1154 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
1155
1156 inferior_ptid = ptid_t (inferior_ptid.pid ());
1157 beneath ()->resume (ptid, step, sig);
1158 }
1159 else
1160 {
1161 thread = current_inferior ()->find_thread (ptid);
1162 if (!thread)
1163 error (_("aix-thread resume: unknown pthread %ld"),
1164 ptid.lwp ());
1165
1166 aix_thread_info *priv = get_aix_thread_info (thread);
1167
1168 tid[0] = priv->tid;
1169 if (tid[0] == PTHDB_INVALID_TID)
1170 error (_("aix-thread resume: no tid for pthread %ld"),
1171 ptid.lwp ());
1172 tid[1] = 0;
1173
1174 if (data->arch64)
1175 ptrace64aix (PTT_CONTINUE, tid[0], (long long) 1,
1176 gdb_signal_to_host (sig), (PTRACE_TYPE_ARG5) tid);
1177 else
1178 ptrace32 (PTT_CONTINUE, tid[0], (addr_ptr) 1,
1179 gdb_signal_to_host (sig), (PTRACE_TYPE_ARG5) tid);
1180 }
1181}
1182
1183/* Wait for thread/process ID if != -1 or for any thread otherwise.
1184 If an error occurs, return -1, else return the pid of the stopped
1185 thread. */
1186
1187ptid_t
1189 target_wait_flags options)
1190{
1191 struct aix_thread_variables *data;
1192 {
1193 pid_to_prc (&ptid);
1194
1195 ptid = beneath ()->wait (ptid, status, options);
1196 }
1197
1198 if (ptid.pid () == -1)
1199 return ptid_t (-1);
1200
1201 /* The target beneath does not deal with threads, so it should only return
1202 pid-only ptids. */
1203 gdb_assert (ptid.is_pid ());
1204
1205 data = get_thread_data_helper_for_ptid (ptid);
1206
1207 /* Check whether libpthdebug might be ready to be initialized. */
1208 if (!data->pd_active && status->kind () == TARGET_WAITKIND_STOPPED
1209 && status->sig () == GDB_SIGNAL_TRAP)
1210 {
1211 process_stratum_target *proc_target
1213 struct regcache *regcache = get_thread_regcache (proc_target, ptid);
1214 struct gdbarch *gdbarch = regcache->arch ();
1215
1217 - gdbarch_decr_pc_after_break (gdbarch) == data->pd_brk_addr)
1218 return pd_activate (ptid.pid ());
1219 }
1220
1221 return pd_update (ptid.pid ());
1222}
1223
1224/* Supply AIX altivec registers, both 64 and 32 bit. */
1225
1226static void
1227supply_altivec_regs (struct regcache *regcache, __vmx_context_t vmx)
1228{
1229 ppc_gdbarch_tdep *tdep
1230 = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
1231 int regno;
1232 for (regno = 0; regno < ppc_num_vrs; regno++)
1233 regcache->raw_supply (tdep->ppc_vr0_regnum + regno,
1234 &(vmx.__vr[regno]));
1235 regcache->raw_supply (tdep->ppc_vrsave_regnum, &(vmx.__vrsave));
1236 regcache->raw_supply (tdep->ppc_vrsave_regnum - 1, &(vmx.__vscr));
1237}
1238
1239/* Supply AIX VSX registers, both 64 and 32 bit. */
1240
1241static void
1242supply_vsx_regs (struct regcache *regcache, __vsx_context_t vsx)
1243{
1244 ppc_gdbarch_tdep *tdep
1245 = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
1246 int regno;
1247
1248 for (regno = 0; regno < ppc_num_vshrs; regno++)
1250 &(vsx.__vsr_dw1[regno]));
1251}
1252
1253/* Record that the 64-bit general-purpose registers contain VALS. */
1254
1255static void
1256supply_gprs64 (struct regcache *regcache, uint64_t *vals)
1257{
1258 ppc_gdbarch_tdep *tdep
1259 = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
1260 int regno;
1261
1262 for (regno = 0; regno < ppc_num_gprs; regno++)
1263 regcache->raw_supply (tdep->ppc_gp0_regnum + regno,
1264 (char *) (vals + regno));
1265}
1266
1267/* Record that 32-bit register REGNO contains VAL. */
1268
1269static void
1270supply_reg32 (struct regcache *regcache, int regno, uint32_t val)
1271{
1272 regcache->raw_supply (regno, (char *) &val);
1273}
1274
1275/* Record that the floating-point registers contain VALS. */
1276
1277static void
1278supply_fprs (struct regcache *regcache, double *vals)
1279{
1280 struct gdbarch *gdbarch = regcache->arch ();
1281 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1282 int regno;
1283
1284 /* This function should never be called on architectures without
1285 floating-point registers. */
1286 gdb_assert (ppc_floating_point_unit_p (gdbarch));
1287
1288 for (regno = tdep->ppc_fp0_regnum;
1289 regno < tdep->ppc_fp0_regnum + ppc_num_fprs;
1290 regno++)
1291 regcache->raw_supply (regno,
1292 (char *) (vals + regno - tdep->ppc_fp0_regnum));
1293}
1294
1295/* Predicate to test whether given register number is a "special" register. */
1296static int
1298{
1299 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1300
1301 return regno == gdbarch_pc_regnum (gdbarch)
1302 || regno == tdep->ppc_ps_regnum
1303 || regno == tdep->ppc_cr_regnum
1304 || regno == tdep->ppc_lr_regnum
1305 || regno == tdep->ppc_ctr_regnum
1306 || regno == tdep->ppc_xer_regnum
1307 || (tdep->ppc_fpscr_regnum >= 0 && regno == tdep->ppc_fpscr_regnum)
1308 || (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum);
1309}
1310
1311
1312/* Record that the special registers contain the specified 64-bit and
1313 32-bit values. */
1314
1315static void
1317 uint64_t iar, uint64_t msr, uint32_t cr,
1318 uint64_t lr, uint64_t ctr, uint32_t xer,
1319 uint32_t fpscr)
1320{
1321 struct gdbarch *gdbarch = regcache->arch ();
1322 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1323
1324 regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
1325 regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
1326 regcache->raw_supply (tdep->ppc_cr_regnum, (char *) &cr);
1327 regcache->raw_supply (tdep->ppc_lr_regnum, (char *) &lr);
1328 regcache->raw_supply (tdep->ppc_ctr_regnum, (char *) &ctr);
1329 regcache->raw_supply (tdep->ppc_xer_regnum, (char *) &xer);
1330 if (tdep->ppc_fpscr_regnum >= 0)
1331 regcache->raw_supply (tdep->ppc_fpscr_regnum, (char *) &fpscr);
1332}
1333
1334/* Record that the special registers contain the specified 32-bit
1335 values. */
1336
1337static void
1339 uint32_t iar, uint32_t msr, uint32_t cr,
1340 uint32_t lr, uint32_t ctr, uint32_t xer,
1341 uint32_t fpscr)
1342{
1343 struct gdbarch *gdbarch = regcache->arch ();
1344 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1345
1346 regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
1347 regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
1348 regcache->raw_supply (tdep->ppc_cr_regnum, (char *) &cr);
1349 regcache->raw_supply (tdep->ppc_lr_regnum, (char *) &lr);
1350 regcache->raw_supply (tdep->ppc_ctr_regnum, (char *) &ctr);
1351 regcache->raw_supply (tdep->ppc_xer_regnum, (char *) &xer);
1352 if (tdep->ppc_fpscr_regnum >= 0)
1353 regcache->raw_supply (tdep->ppc_fpscr_regnum, (char *) &fpscr);
1354}
1355
1356/* Fetch all registers from pthread PDTID, which doesn't have a kernel
1357 thread.
1358
1359 There's no way to query a single register from a non-kernel
1360 pthread, so there's no need for a single-register version of this
1361 function. */
1362
1363static void
1364fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
1365{
1366 struct gdbarch *gdbarch = regcache->arch ();
1367 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1368 int status, i;
1369 pthdb_context_t ctx;
1370 struct aix_thread_variables *data;
1372
1373 if (debug_aix_thread)
1375 "fetch_regs_user_thread %lx\n", (long) pdtid);
1376 status = pthdb_pthread_context (data->pd_session, pdtid, &ctx);
1377 if (status != PTHDB_SUCCESS)
1378 error (_("aix-thread: fetch_registers: pthdb_pthread_context returned %s"),
1380
1381 /* General-purpose registers. */
1382
1383 if (data->arch64)
1384 supply_gprs64 (regcache, ctx.gpr);
1385 else
1386 for (i = 0; i < ppc_num_gprs; i++)
1387 supply_reg32 (regcache, tdep->ppc_gp0_regnum + i, ctx.gpr[i]);
1388
1389 /* Floating-point registers. */
1390
1392 supply_fprs (regcache, ctx.fpr);
1393
1394 /* Special registers. */
1395
1396 if (data->arch64)
1397 supply_sprs64 (regcache, ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr,
1398 ctx.xer, ctx.fpscr);
1399 else
1400 supply_sprs32 (regcache, ctx.iar, ctx.msr, ctx.cr, ctx.lr, ctx.ctr,
1401 ctx.xer, ctx.fpscr);
1402
1403 /* Altivec registers. */
1404 supply_altivec_regs (regcache, ctx.vmx);
1405
1406 /* VSX registers. */
1407 supply_vsx_regs (regcache, ctx.vsx);
1408}
1409
1410/* Fetch register REGNO if != -1 or all registers otherwise from
1411 kernel thread TID.
1412
1413 AIX provides a way to query all of a kernel thread's GPRs, FPRs, or
1414 SPRs, but there's no way to query individual registers within those
1415 groups. Therefore, if REGNO != -1, this function fetches an entire
1416 group.
1417
1418 Unfortunately, kernel thread register queries often fail with
1419 EPERM, indicating that the thread is in kernel space. This breaks
1420 backtraces of threads other than the current one. To make that
1421 breakage obvious without throwing an error to top level (which is
1422 bad e.g. during "info threads" output), zero registers that can't
1423 be retrieved. */
1424
1425static void
1427 pthdb_tid_t tid)
1428{
1429 struct gdbarch *gdbarch = regcache->arch ();
1430 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1431 uint64_t gprs64[ppc_num_gprs];
1432 uint32_t gprs32[ppc_num_gprs];
1433 double fprs[ppc_num_fprs];
1434 struct ptxsprs sprs64;
1435 struct ptsprs sprs32;
1436 int i;
1437 struct aix_thread_variables *data;
1438
1440
1441 if (debug_aix_thread)
1443 "fetch_regs_kernel_thread tid=%lx regno=%d arch64=%d\n",
1444 (long) tid, regno, data->arch64);
1445
1446 /* General-purpose registers. */
1447 if (regno == -1
1448 || (tdep->ppc_gp0_regnum <= regno
1449 && regno < tdep->ppc_gp0_regnum + ppc_num_gprs))
1450 {
1451 if (data->arch64)
1452 {
1453 if (!ptrace64aix (PTT_READ_GPRS, tid,
1454 (unsigned long) gprs64, 0, NULL))
1455 memset (gprs64, 0, sizeof (gprs64));
1456 supply_gprs64 (regcache, gprs64);
1457 }
1458 else
1459 {
1460 if (!ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL))
1461 memset (gprs32, 0, sizeof (gprs32));
1462 for (i = 0; i < ppc_num_gprs; i++)
1463 supply_reg32 (regcache, tdep->ppc_gp0_regnum + i, gprs32[i]);
1464 }
1465 }
1466
1467 /* vector registers. */
1468 if (tdep->ppc_vr0_regnum != -1)
1469 {
1470 int ret = 0;
1471 __vmx_context_t vmx;
1472 if (data->arch64)
1473 ret = ptrace64aix (PTT_READ_VEC, tid, (long long) &vmx, 0, 0);
1474 else
1475 ret = ptrace32 (PTT_READ_VEC, tid, (uintptr_t) &vmx, 0, 0);
1476 if (ret < 0)
1477 memset(&vmx, 0, sizeof(__vmx_context_t));
1478 for (i = 0; i < ppc_num_vrs; i++)
1479 regcache->raw_supply (tdep->ppc_vr0_regnum + i, &(vmx.__vr[i]));
1480 regcache->raw_supply (tdep->ppc_vrsave_regnum, &(vmx.__vrsave));
1481 regcache->raw_supply (tdep->ppc_vrsave_regnum - 1, &(vmx.__vscr));
1482 }
1483
1484 /* vsx registers. */
1485 if (tdep->ppc_vsr0_upper_regnum != -1)
1486 {
1487 __vsx_context_t vsx;
1488 int ret = 0;
1489 if (data->arch64)
1490 ret = ptrace64aix (PTT_READ_VSX, tid, (long long) &vsx, 0, 0);
1491 else
1492 ret = ptrace32 (PTT_READ_VSX, tid, (long long) &vsx, 0, 0);
1493 if (ret < 0)
1494 memset(&vsx, 0, sizeof(__vsx_context_t));
1495 for (i = 0; i < ppc_num_vshrs; i++)
1496 regcache->raw_supply (tdep->ppc_vsr0_upper_regnum + i, &(vsx.__vsr_dw1[i]));
1497 }
1498
1499 /* Floating-point registers. */
1500
1502 && (regno == -1
1503 || (regno >= tdep->ppc_fp0_regnum
1504 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
1505 {
1506 if (!ptrace32 (PTT_READ_FPRS, tid, (uintptr_t) fprs, 0, NULL))
1507 memset (fprs, 0, sizeof (fprs));
1508 supply_fprs (regcache, fprs);
1509 }
1510
1511 /* Special-purpose registers. */
1512
1513 if (regno == -1 || special_register_p (gdbarch, regno))
1514 {
1515 if (data->arch64)
1516 {
1517 if (!ptrace64aix (PTT_READ_SPRS, tid,
1518 (unsigned long) &sprs64, 0, NULL))
1519 memset (&sprs64, 0, sizeof (sprs64));
1520 supply_sprs64 (regcache, sprs64.pt_iar, sprs64.pt_msr,
1521 sprs64.pt_cr, sprs64.pt_lr, sprs64.pt_ctr,
1522 sprs64.pt_xer, sprs64.pt_fpscr);
1523 }
1524 else
1525 {
1526 if (!ptrace32 (PTT_READ_SPRS, tid, (uintptr_t) &sprs32, 0, NULL))
1527 memset (&sprs32, 0, sizeof (sprs32));
1528 supply_sprs32 (regcache, sprs32.pt_iar, sprs32.pt_msr, sprs32.pt_cr,
1529 sprs32.pt_lr, sprs32.pt_ctr, sprs32.pt_xer,
1530 sprs32.pt_fpscr);
1531
1532 if (tdep->ppc_mq_regnum >= 0)
1533 regcache->raw_supply (tdep->ppc_mq_regnum, (char *) &sprs32.pt_mq);
1534 }
1535 }
1536}
1537
1538/* Fetch register REGNO if != -1 or all registers otherwise from the
1539 thread/process connected to REGCACHE. */
1540
1541void
1543{
1544 struct thread_info *thread;
1545 pthdb_tid_t tid;
1546
1547 /* If a new inferior is born, then its pthread debug library is yet to
1548 initialised and hence has no private data. So the below if condition
1549 exists. */
1550
1551 if (regcache->ptid ().tid () == 0)
1552 beneath ()->fetch_registers (regcache, regno);
1553 else
1554 {
1555 thread = current_inferior ()->find_thread (regcache->ptid ());
1556 aix_thread_info *priv = get_aix_thread_info (thread);
1557 tid = priv->tid;
1558
1559 if (tid == PTHDB_INVALID_TID)
1561 else
1562 fetch_regs_kernel_thread (regcache, regno, tid);
1563 }
1564}
1565
1566/* Fill altivec registers. */
1567
1568static void
1569fill_altivec (const struct regcache *regcache, __vmx_context_t *vmx)
1570{
1571 struct gdbarch *gdbarch = regcache->arch ();
1572 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1573 int regno;
1574
1575 for (regno = 0; regno < ppc_num_vrs; regno++)
1576 if (REG_VALID == regcache->get_register_status (tdep->ppc_vr0_regnum + regno))
1577 regcache->raw_collect (tdep->ppc_vr0_regnum + regno,
1578 &(vmx->__vr[regno]));
1579
1580 if (REG_VALID == regcache->get_register_status (tdep->ppc_vrsave_regnum))
1581 regcache->raw_collect (tdep->ppc_vrsave_regnum, &(vmx->__vrsave));
1582 if (REG_VALID == regcache->get_register_status (tdep->ppc_vrsave_regnum - 1))
1583 regcache->raw_collect (tdep->ppc_vrsave_regnum - 1, &(vmx->__vscr));
1584}
1585
1586/* Fill vsx registers. */
1587
1588static void
1589fill_vsx (const struct regcache *regcache, __vsx_context_t *vsx)
1590{
1591 struct gdbarch *gdbarch = regcache->arch ();
1592 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1593 int regno;
1594
1595 for (regno = 0; regno < ppc_num_vshrs; regno++)
1596 if (REG_VALID == regcache->get_register_status ( tdep->ppc_vsr0_upper_regnum + regno))
1598 &(vsx->__vsr_dw1[0]) + regno);
1599}
1600
1601/* Store the gp registers into an array of uint32_t or uint64_t. */
1602
1603static void
1604fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
1605{
1606 ppc_gdbarch_tdep *tdep
1607 = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
1608 int regno;
1609
1610 for (regno = 0; regno < ppc_num_gprs; regno++)
1611 if (REG_VALID == regcache->get_register_status
1612 (tdep->ppc_gp0_regnum + regno))
1613 regcache->raw_collect (tdep->ppc_gp0_regnum + regno, vals + regno);
1614}
1615
1616static void
1617fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
1618{
1619 ppc_gdbarch_tdep *tdep
1620 = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
1621 int regno;
1622
1623 for (regno = 0; regno < ppc_num_gprs; regno++)
1624 if (REG_VALID == regcache->get_register_status
1625 (tdep->ppc_gp0_regnum + regno))
1626 regcache->raw_collect (tdep->ppc_gp0_regnum + regno, vals + regno);
1627}
1628
1629/* Store the floating point registers into a double array. */
1630static void
1631fill_fprs (const struct regcache *regcache, double *vals)
1632{
1633 struct gdbarch *gdbarch = regcache->arch ();
1634 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1635 int regno;
1636
1637 /* This function should never be called on architectures without
1638 floating-point registers. */
1639 gdb_assert (ppc_floating_point_unit_p (gdbarch));
1640
1641 for (regno = tdep->ppc_fp0_regnum;
1642 regno < tdep->ppc_fp0_regnum + ppc_num_fprs;
1643 regno++)
1644 if (REG_VALID == regcache->get_register_status (regno))
1645 regcache->raw_collect (regno, vals + regno - tdep->ppc_fp0_regnum);
1646}
1647
1648/* Store the special registers into the specified 64-bit and 32-bit
1649 locations. */
1650
1651static void
1653 uint64_t *iar, uint64_t *msr, uint32_t *cr,
1654 uint64_t *lr, uint64_t *ctr, uint32_t *xer,
1655 uint32_t *fpscr)
1656{
1657 struct gdbarch *gdbarch = regcache->arch ();
1658 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1659
1660 /* Verify that the size of the size of the IAR buffer is the
1661 same as the raw size of the PC (in the register cache). If
1662 they're not, then either GDB has been built incorrectly, or
1663 there's some other kind of internal error. To be really safe,
1664 we should check all of the sizes. */
1665 gdb_assert (sizeof (*iar) == register_size
1667
1670 if (REG_VALID == regcache->get_register_status (tdep->ppc_ps_regnum))
1671 regcache->raw_collect (tdep->ppc_ps_regnum, msr);
1672 if (REG_VALID == regcache->get_register_status (tdep->ppc_cr_regnum))
1673 regcache->raw_collect (tdep->ppc_cr_regnum, cr);
1674 if (REG_VALID == regcache->get_register_status (tdep->ppc_lr_regnum))
1675 regcache->raw_collect (tdep->ppc_lr_regnum, lr);
1676 if (REG_VALID == regcache->get_register_status (tdep->ppc_ctr_regnum))
1677 regcache->raw_collect (tdep->ppc_ctr_regnum, ctr);
1678 if (REG_VALID == regcache->get_register_status (tdep->ppc_xer_regnum))
1679 regcache->raw_collect (tdep->ppc_xer_regnum, xer);
1680 if (tdep->ppc_fpscr_regnum >= 0
1681 && REG_VALID == regcache->get_register_status (tdep->ppc_fpscr_regnum))
1682 regcache->raw_collect (tdep->ppc_fpscr_regnum, fpscr);
1683}
1684
1685static void
1687 uint32_t *iar, uint32_t *msr, uint32_t *cr,
1688 uint32_t *lr, uint32_t *ctr, uint32_t *xer,
1689 uint32_t *fpscr)
1690{
1691 struct gdbarch *gdbarch = regcache->arch ();
1692 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1693
1694 /* Verify that the size of the size of the IAR buffer is the
1695 same as the raw size of the PC (in the register cache). If
1696 they're not, then either GDB has been built incorrectly, or
1697 there's some other kind of internal error. To be really safe,
1698 we should check all of the sizes. */
1699 gdb_assert (sizeof (*iar) == register_size (gdbarch,
1701
1704 if (REG_VALID == regcache->get_register_status (tdep->ppc_ps_regnum))
1705 regcache->raw_collect (tdep->ppc_ps_regnum, msr);
1706 if (REG_VALID == regcache->get_register_status (tdep->ppc_cr_regnum))
1707 regcache->raw_collect (tdep->ppc_cr_regnum, cr);
1708 if (REG_VALID == regcache->get_register_status (tdep->ppc_lr_regnum))
1709 regcache->raw_collect (tdep->ppc_lr_regnum, lr);
1710 if (REG_VALID == regcache->get_register_status (tdep->ppc_ctr_regnum))
1711 regcache->raw_collect (tdep->ppc_ctr_regnum, ctr);
1712 if (REG_VALID == regcache->get_register_status (tdep->ppc_xer_regnum))
1713 regcache->raw_collect (tdep->ppc_xer_regnum, xer);
1714 if (tdep->ppc_fpscr_regnum >= 0
1715 && REG_VALID == regcache->get_register_status (tdep->ppc_fpscr_regnum))
1716 regcache->raw_collect (tdep->ppc_fpscr_regnum, fpscr);
1717}
1718
1719/* Store all registers into pthread PDTID, which doesn't have a kernel
1720 thread.
1721
1722 It's possible to store a single register into a non-kernel pthread,
1723 but I doubt it's worth the effort. */
1724
1725static void
1726store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
1727{
1728 struct gdbarch *gdbarch = regcache->arch ();
1729 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1730 int status, i;
1731 pthdb_context_t ctx;
1732 uint32_t int32;
1733 uint64_t int64;
1734 struct aix_thread_variables *data;
1736 int ret;
1737 __vmx_context_t vmx;
1738 __vsx_context_t vsx;
1739
1740 if (debug_aix_thread)
1742 "store_regs_user_thread %lx\n", (long) pdtid);
1743
1744 /* Retrieve the thread's current context for its non-register
1745 values. */
1746 status = pthdb_pthread_context (data->pd_session, pdtid, &ctx);
1747 if (status != PTHDB_SUCCESS)
1748 error (_("aix-thread: store_registers: pthdb_pthread_context returned %s"),
1750
1751 /* Fill altivec-registers. */
1752
1753 if (__power_vmx())
1754 {
1755 memset(&vmx, 0, sizeof(__vmx_context_t));
1756 for (i = 0; i < ppc_num_vrs; i++)
1757 if (REG_VALID == regcache->get_register_status (tdep->ppc_vr0_regnum + i))
1758 {
1760 &(vmx.__vr[i]));
1761 ctx.vmx.__vr[i] = vmx.__vr[i];
1762 }
1763 if (REG_VALID == regcache->get_register_status (tdep->ppc_vrsave_regnum))
1764 ctx.vmx.__vrsave = vmx.__vrsave;
1765 if (REG_VALID == regcache->get_register_status (tdep->ppc_vrsave_regnum - 1))
1766 ctx.vmx.__vscr = vmx.__vscr;
1767 }
1768
1769 /* Fill vsx registers. */
1770
1771 if (__power_vsx())
1772 {
1773 memset(&vsx, 0, sizeof(__vsx_context_t));
1774 for (i = 0; i < ppc_num_vshrs; i++)
1775 if (REG_VALID == regcache->get_register_status (tdep->ppc_vsr0_regnum + i))
1776 {
1778 &(vsx.__vsr_dw1[i]));
1779 ctx.vsx.__vsr_dw1[i] = vsx.__vsr_dw1[i];
1780 }
1781 }
1782
1783 /* Collect general-purpose register values from the regcache. */
1784
1785 for (i = 0; i < ppc_num_gprs; i++)
1786 if (REG_VALID == regcache->get_register_status (tdep->ppc_gp0_regnum + i))
1787 {
1788 if (data->arch64)
1789 {
1790 regcache->raw_collect (tdep->ppc_gp0_regnum + i, (void *) &int64);
1791 ctx.gpr[i] = int64;
1792 }
1793 else
1794 {
1795 regcache->raw_collect (tdep->ppc_gp0_regnum + i, (void *) &int32);
1796 ctx.gpr[i] = int32;
1797 }
1798 }
1799
1800 /* Collect floating-point register values from the regcache. */
1802 fill_fprs (regcache, ctx.fpr);
1803
1804 /* Special registers (always kept in ctx as 64 bits). */
1805 if (data->arch64)
1806 {
1807 fill_sprs64 (regcache, &ctx.iar, &ctx.msr, &ctx.cr, &ctx.lr, &ctx.ctr,
1808 &ctx.xer, &ctx.fpscr);
1809 }
1810 else
1811 {
1812 /* Problem: ctx.iar etc. are 64 bits, but raw_registers are 32.
1813 Solution: use 32-bit temp variables. */
1814 uint32_t tmp_iar, tmp_msr, tmp_cr, tmp_lr, tmp_ctr, tmp_xer,
1815 tmp_fpscr;
1816
1817 fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr, &tmp_ctr,
1818 &tmp_xer, &tmp_fpscr);
1819 if (REG_VALID == regcache->get_register_status
1821 ctx.iar = tmp_iar;
1822 if (REG_VALID == regcache->get_register_status (tdep->ppc_ps_regnum))
1823 ctx.msr = tmp_msr;
1824 if (REG_VALID == regcache->get_register_status (tdep->ppc_cr_regnum))
1825 ctx.cr = tmp_cr;
1826 if (REG_VALID == regcache->get_register_status (tdep->ppc_lr_regnum))
1827 ctx.lr = tmp_lr;
1828 if (REG_VALID == regcache->get_register_status (tdep->ppc_ctr_regnum))
1829 ctx.ctr = tmp_ctr;
1830 if (REG_VALID == regcache->get_register_status (tdep->ppc_xer_regnum))
1831 ctx.xer = tmp_xer;
1832 if (REG_VALID == regcache->get_register_status (tdep->ppc_xer_regnum))
1833 ctx.fpscr = tmp_fpscr;
1834 }
1835
1836 status = pthdb_pthread_setcontext (data->pd_session, pdtid, &ctx);
1837 if (status != PTHDB_SUCCESS)
1838 error (_("aix-thread: store_registers: "
1839 "pthdb_pthread_setcontext returned %s"),
1841}
1842
1843/* Store register REGNO if != -1 or all registers otherwise into
1844 kernel thread TID.
1845
1846 AIX provides a way to set all of a kernel thread's GPRs, FPRs, or
1847 SPRs, but there's no way to set individual registers within those
1848 groups. Therefore, if REGNO != -1, this function stores an entire
1849 group. */
1850
1851static void
1853 pthdb_tid_t tid)
1854{
1855 struct gdbarch *gdbarch = regcache->arch ();
1856 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1857 uint64_t gprs64[ppc_num_gprs];
1858 uint32_t gprs32[ppc_num_gprs];
1859 double fprs[ppc_num_fprs];
1860 struct ptxsprs sprs64;
1861 struct ptsprs sprs32;
1862 struct aix_thread_variables *data;
1863 int ret = 0;
1864
1866
1867 if (debug_aix_thread)
1869 "store_regs_kernel_thread tid=%lx regno=%d\n",
1870 (long) tid, regno);
1871
1872 /* General-purpose registers. */
1873 if (regno == -1
1874 || (tdep->ppc_gp0_regnum <= regno
1875 && regno < tdep->ppc_gp0_regnum + ppc_num_fprs))
1876 {
1877 if (data->arch64)
1878 {
1879 /* Pre-fetch: some regs may not be in the cache. */
1880 ptrace64aix (PTT_READ_GPRS, tid, (unsigned long) gprs64, 0, NULL);
1881 fill_gprs64 (regcache, gprs64);
1882 ptrace64aix (PTT_WRITE_GPRS, tid, (unsigned long) gprs64, 0, NULL);
1883 }
1884 else
1885 {
1886 /* Pre-fetch: some regs may not be in the cache. */
1887 ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL);
1888 fill_gprs32 (regcache, gprs32);
1889 ptrace32 (PTT_WRITE_GPRS, tid, (uintptr_t) gprs32, 0, NULL);
1890 }
1891 }
1892
1893 /* Floating-point registers. */
1894
1896 && (regno == -1
1897 || (regno >= tdep->ppc_fp0_regnum
1898 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)))
1899 {
1900 /* Pre-fetch: some regs may not be in the cache. */
1901 ptrace32 (PTT_READ_FPRS, tid, (uintptr_t) fprs, 0, NULL);
1902 fill_fprs (regcache, fprs);
1903 ptrace32 (PTT_WRITE_FPRS, tid, (uintptr_t) fprs, 0, NULL);
1904 }
1905
1906 /* Special-purpose registers. */
1907
1908 if (regno == -1 || special_register_p (gdbarch, regno))
1909 {
1910 if (data->arch64)
1911 {
1912 /* Pre-fetch: some registers won't be in the cache. */
1913 ptrace64aix (PTT_READ_SPRS, tid,
1914 (unsigned long) &sprs64, 0, NULL);
1915 fill_sprs64 (regcache, &sprs64.pt_iar, &sprs64.pt_msr,
1916 &sprs64.pt_cr, &sprs64.pt_lr, &sprs64.pt_ctr,
1917 &sprs64.pt_xer, &sprs64.pt_fpscr);
1918 ptrace64aix (PTT_WRITE_SPRS, tid,
1919 (unsigned long) &sprs64, 0, NULL);
1920 }
1921 else
1922 {
1923 /* The contents of "struct ptspr" were declared as "unsigned
1924 long" up to AIX 5.2, but are "unsigned int" since 5.3.
1925 Use temporaries to work around this problem. Also, add an
1926 assert here to make sure we fail if the system header files
1927 use "unsigned long", and the size of that type is not what
1928 the headers expect. */
1929 uint32_t tmp_iar, tmp_msr, tmp_cr, tmp_lr, tmp_ctr, tmp_xer,
1930 tmp_fpscr;
1931
1932 gdb_assert (sizeof (sprs32.pt_iar) == 4);
1933
1934 /* Pre-fetch: some registers won't be in the cache. */
1935 ptrace32 (PTT_READ_SPRS, tid, (uintptr_t) &sprs32, 0, NULL);
1936
1937 fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr,
1938 &tmp_ctr, &tmp_xer, &tmp_fpscr);
1939
1940 sprs32.pt_iar = tmp_iar;
1941 sprs32.pt_msr = tmp_msr;
1942 sprs32.pt_cr = tmp_cr;
1943 sprs32.pt_lr = tmp_lr;
1944 sprs32.pt_ctr = tmp_ctr;
1945 sprs32.pt_xer = tmp_xer;
1946 sprs32.pt_fpscr = tmp_fpscr;
1947
1948 if (tdep->ppc_mq_regnum >= 0)
1949 if (REG_VALID == regcache->get_register_status
1950 (tdep->ppc_mq_regnum))
1951 regcache->raw_collect (tdep->ppc_mq_regnum, &sprs32.pt_mq);
1952
1953 ptrace32 (PTT_WRITE_SPRS, tid, (uintptr_t) &sprs32, 0, NULL);
1954 }
1955 }
1956
1957 /* Vector registers. */
1958 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1
1959 && (regno == -1 || (regno >= tdep->ppc_vr0_regnum
1960 && regno <= tdep->ppc_vrsave_regnum)))
1961 {
1962 __vmx_context_t vmx;
1963 if (__power_vmx())
1964 {
1965 if (data->arch64)
1966 ret = ptrace64aix (PTT_READ_VEC, tid, (long long) &vmx, 0, 0);
1967 else
1968 ret = ptrace32 (PTT_READ_VEC, tid, (long long) &vmx, 0, 0);
1969 if (ret > 0)
1970 {
1971 fill_altivec(regcache, &vmx);
1972 if (data->arch64)
1973 ret = ptrace64aix (PTT_WRITE_VEC, tid, (long long) &vmx, 0, 0);
1974 else
1975 ret = ptrace32 (PTT_WRITE_VEC, tid, (long long) &vmx, 0, 0);
1976 if (ret < 0)
1977 perror_with_name (_("Unable to store AltiVec register after read"));
1978 }
1979 }
1980 }
1981
1982 /* VSX registers. */
1983 if (tdep->ppc_vsr0_upper_regnum != -1 && (regno == -1
1984 || (regno >=tdep->ppc_vsr0_upper_regnum
1985 && regno < tdep->ppc_vsr0_upper_regnum + ppc_num_vshrs)))
1986 {
1987 __vsx_context_t vsx;
1988 if (__power_vsx())
1989 {
1990 if (data->arch64)
1991 ret = ptrace64aix (PTT_READ_VSX, tid, (long long) &vsx, 0, 0);
1992 else
1993 ret = ptrace32 (PTT_READ_VSX, tid, (long long) &vsx, 0, 0);
1994 if (ret > 0)
1995 {
1996 fill_vsx (regcache, &vsx);
1997 if (data->arch64)
1998 ret = ptrace64aix (PTT_WRITE_VSX, tid, (long long) &vsx, 0, 0);
1999 else
2000 ret = ptrace32 (PTT_WRITE_VSX, tid, (long long) &vsx, 0, 0);
2001 if (ret < 0)
2002 perror_with_name (_("Unable to store VSX register after read"));
2003 }
2004 }
2005 }
2006}
2007
2008/* Store gdb's current view of the register set into the
2009 thread/process connected to REGCACHE. */
2010
2011void
2013{
2014 struct thread_info *thread;
2015 pthdb_tid_t tid;
2016
2017 if (regcache->ptid ().tid () == 0)
2018 beneath ()->store_registers (regcache, regno);
2019 else
2020 {
2021 thread = current_inferior ()->find_thread (regcache->ptid ());
2022 aix_thread_info *priv = get_aix_thread_info (thread);
2023 tid = priv->tid;
2024
2025 if (tid == PTHDB_INVALID_TID)
2027 else
2028 store_regs_kernel_thread (regcache, regno, tid);
2029 }
2030}
2031
2032/* Implement the to_xfer_partial target_ops method. */
2033
2036 const char *annex, gdb_byte *readbuf,
2037 const gdb_byte *writebuf,
2038 ULONGEST offset, ULONGEST len,
2039 ULONGEST *xfered_len)
2040{
2041 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
2042
2043 inferior_ptid = ptid_t (inferior_ptid.pid ());
2044 return beneath ()->xfer_partial (object, annex, readbuf,
2045 writebuf, offset, len, xfered_len);
2046}
2047
2048/* Clean up after the inferior exits. */
2049
2050void
2052{
2053 target_ops *beneath = this->beneath ();
2054
2056 beneath->mourn_inferior ();
2057}
2058
2059/* Return whether thread PID is still valid. */
2060
2061bool
2063{
2064 if (ptid.tid () == 0)
2065 return beneath ()->thread_alive (ptid);
2066
2067 /* We update the thread list every time the child stops, so all
2068 valid threads should be in the thread list. */
2069 process_stratum_target *proc_target
2071 return in_thread_list (proc_target, ptid);
2072}
2073
2074/* Return a printable representation of composite PID for use in
2075 "info threads" output. */
2076
2077std::string
2079{
2080 if (ptid.tid () == 0)
2081 return beneath ()->pid_to_str (ptid);
2082
2083 return string_printf (_("Thread %s"), pulongest (ptid.tid ()));
2084}
2085
2086/* Return a printable representation of extra information about
2087 THREAD, for use in "info threads" output. */
2088
2089const char *
2091{
2092 int status;
2093 pthdb_pthread_t pdtid;
2094 pthdb_tid_t tid;
2095 pthdb_state_t state;
2096 pthdb_suspendstate_t suspendstate;
2097 pthdb_detachstate_t detachstate;
2098 int cancelpend;
2099 static char *ret = NULL;
2100 struct aix_thread_variables *data;
2101
2102 data = get_thread_data_helper_for_ptid (thread->ptid);
2103
2104 if (thread->ptid.tid () == 0)
2105 return NULL;
2106
2107 string_file buf;
2108 aix_thread_info *priv = get_aix_thread_info (thread);
2109
2110 pdtid = priv->pdtid;
2111 tid = priv->tid;
2112
2113 if (tid != PTHDB_INVALID_TID)
2114 /* i18n: Like "thread-identifier %d, [state] running, suspended" */
2115 buf.printf (_("tid %d"), (int)tid);
2116
2117 status = pthdb_pthread_state (data->pd_session, pdtid, &state);
2118 if (status != PTHDB_SUCCESS)
2119 state = PST_NOTSUP;
2120 buf.printf (", %s", state2str (state));
2121
2122 status = pthdb_pthread_suspendstate (data->pd_session, pdtid,
2123 &suspendstate);
2124 if (status == PTHDB_SUCCESS && suspendstate == PSS_SUSPENDED)
2125 /* i18n: Like "Thread-Id %d, [state] running, suspended" */
2126 buf.printf (_(", suspended"));
2127
2128 status = pthdb_pthread_detachstate (data->pd_session, pdtid,
2129 &detachstate);
2130 if (status == PTHDB_SUCCESS && detachstate == PDS_DETACHED)
2131 /* i18n: Like "Thread-Id %d, [state] running, detached" */
2132 buf.printf (_(", detached"));
2133
2134 pthdb_pthread_cancelpend (data->pd_session, pdtid, &cancelpend);
2135 if (status == PTHDB_SUCCESS && cancelpend)
2136 /* i18n: Like "Thread-Id %d, [state] running, cancel pending" */
2137 buf.printf (_(", cancel pending"));
2138
2139 buf.write ("", 1);
2140
2141 xfree (ret); /* Free old buffer. */
2142
2143 ret = xstrdup (buf.c_str ());
2144
2145 return ret;
2146}
2147
2148ptid_t
2149aix_thread_target::get_ada_task_ptid (long lwp, ULONGEST thread)
2150{
2151 return ptid_t (inferior_ptid.pid (), 0, thread);
2152}
2153
2154
2155/* Module startup initialization function, automagically called by
2156 init.c. */
2157
2159void
2161{
2162 /* Notice when object files get loaded and unloaded. */
2163 gdb::observers::new_objfile.attach (new_objfile, "aix-thread");
2164
2165 /* Add ourselves to inferior_created event chain.
2166 This is needed to enable the thread target on "attach". */
2168 "aix-thread");
2169
2171 _("Set debugging of AIX thread module."),
2172 _("Show debugging of AIX thread module."),
2173 _("Enables debugging output (used to debug GDB)."),
2174 NULL, NULL,
2175 /* FIXME: i18n: Debugging of AIX thread
2176 module is \"%d\". */
2178}
const char *const name
void * xmalloc(YYSIZE_T)
#define qsort
Definition ada-exp.c:3129
void xfree(void *)
static void supply_altivec_regs(struct regcache *regcache, __vmx_context_t vmx)
static struct aix_thread_variables * get_thread_data_helper_for_ptid(ptid_t ptid)
Definition aix-thread.c:216
static const target_info aix_thread_target_info
Definition aix-thread.c:102
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)
static int pdc_dealloc(pthdb_user_t, void *)
Definition aix-thread.c:700
static void sync_threadlists(pid_t pid)
Definition aix-thread.c:820
static void pd_enable(inferior *inf)
static aix_thread_target aix_thread_ops
Definition aix-thread.c:141
#define addr_ptr
Definition aix-thread.c:345
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)
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)
static const registry< inferior >::key< aix_thread_variables > aix_thread_variables_handle
Definition aix-thread.c:195
static void fill_fprs(const struct regcache *regcache, double *vals)
static struct aix_thread_variables * get_aix_thread_variables_data(struct inferior *inf)
Definition aix-thread.c:199
#define pthdb_tid_t
Definition aix-thread.c:68
static int ptrace64aix(int req, int id, long long addr, int data, int *buf)
Definition aix-thread.c:330
static bool debug_aix_thread
Definition aix-thread.c:64
static int pdc_symbol_addrs(pthdb_user_t, pthdb_symbol_t *, int)
Definition aix-thread.c:373
static int pdc_write_data(pthdb_user_t, void *, pthdb_addr_t, size_t)
Definition aix-thread.c:632
static const char * pd_status2str(int status)
Definition aix-thread.c:237
static void supply_gprs64(struct regcache *regcache, uint64_t *vals)
static ptid_t pd_activate(pid_t pid)
static void fetch_regs_user_thread(struct regcache *regcache, pthdb_pthread_t pdtid)
static void new_objfile(struct objfile *objfile)
static void fetch_regs_kernel_thread(struct regcache *regcache, int regno, pthdb_tid_t tid)
static void supply_vsx_regs(struct regcache *regcache, __vsx_context_t vsx)
static void fill_gprs64(const struct regcache *regcache, uint64_t *vals)
static int gcmp(const void *t1v, const void *t2v)
Definition aix-thread.c:772
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:420
static void supply_fprs(struct regcache *regcache, double *vals)
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)
static int pdc_alloc(pthdb_user_t, size_t, void **)
Definition aix-thread.c:661
static void pid_to_prc(ptid_t *ptidp)
Definition aix-thread.c:360
static int ptrace_check(int req, int id, int ret)
Definition aix-thread.c:281
static void supply_reg32(struct regcache *regcache, int regno, uint32_t val)
static int pdc_realloc(pthdb_user_t, void *, size_t, void **)
Definition aix-thread.c:683
static int ptid_cmp(ptid_t ptid1, ptid_t ptid2)
Definition aix-thread.c:751
static void fill_vsx(const struct regcache *regcache, __vsx_context_t *vsx)
#define PDC_FAILURE
Definition aix-thread.c:74
static int pcmp(const void *p1v, const void *p2v)
Definition aix-thread.c:741
static int pdc_read_data(pthdb_user_t, void *, pthdb_addr_t, size_t)
Definition aix-thread.c:603
static void store_regs_user_thread(const struct regcache *regcache, pthdb_pthread_t pdtid)
static void pd_disable(inferior *inf)
static aix_thread_info * get_aix_thread_info(thread_info *thread)
Definition aix-thread.c:87
void _initialize_aix_thread()
static struct aix_thread_variables * get_thread_data_helper_for_pid(pid_t pid)
Definition aix-thread.c:226
static pthdb_tid_t get_signaled_thread(int pid)
Definition aix-thread.c:784
static void store_regs_kernel_thread(const struct regcache *regcache, int regno, pthdb_tid_t tid)
static pthdb_callbacks_t pd_callbacks
Definition aix-thread.c:160
static int ptrace32(int req, int id, addr_ptr addr, int data, int *buf)
Definition aix-thread.c:349
static ptid_t pd_update(pid_t pid)
Definition aix-thread.c:982
static void aix_thread_inferior_created(inferior *inf)
static void fill_gprs32(const struct regcache *regcache, uint32_t *vals)
static void fill_altivec(const struct regcache *regcache, __vmx_context_t *vmx)
#define PDC_SUCCESS
Definition aix-thread.c:73
static char * state2str(pthdb_state_t state)
Definition aix-thread.c:713
static int special_register_p(struct gdbarch *gdbarch, int regno)
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:531
static int iter_tid(struct thread_info *thread, void *tidp)
Definition aix-thread.c:968
int getthrds(pid_t, struct thrdsinfo64 *, int, tid_t *, int)
void * xrealloc(void *ptr, size_t size)
Definition alloc.c:65
struct gdbarch * target_gdbarch(void)
struct breakpoint * create_thread_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
void mourn_inferior() override
std::string pid_to_str(ptid_t) override
void fetch_registers(struct regcache *, int) override
const char * extra_thread_info(struct thread_info *) override
void detach(inferior *, int) override
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
void resume(ptid_t, int, enum gdb_signal) override
strata stratum() const override
Definition aix-thread.c:114
bool thread_alive(ptid_t ptid) override
const target_info & info() const override
Definition aix-thread.c:111
void store_registers(struct regcache *, int) override
ptid_t get_ada_task_ptid(long lwp, ULONGEST thread) override
thread_info * find_thread(ptid_t ptid)
Definition inferior.c:238
int unpush_target(struct target_ops *t)
Definition inferior.c:96
void push_target(struct target_ops *t)
Definition inferior.h:406
struct process_stratum_target * process_target()
Definition inferior.h:449
thread_info * find_thread(ptid_t ptid)
gdbarch * arch() const
Definition regcache.c:231
void raw_collect(int regnum, void *buf) const override
Definition regcache.c:1127
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
enum register_status get_register_status(int regnum) const override
Definition regcache.c:304
ptid_t ptid() const
Definition regcache.h:408
void * get(unsigned key)
Definition registry.h:211
void write(const char *buf, long length_buf) override
Definition ui-file.c:214
const char * c_str() const
Definition ui-file.h:222
ptid_t ptid
Definition gdbthread.h:259
private_thread_info_up priv
Definition gdbthread.h:528
void printf(const char *,...) ATTRIBUTE_PRINTF(2
Definition ui-file.c:40
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:167
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:165
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:809
@ class_maintenance
Definition command.h:65
#define ptrace(request, pid, addr, data)
Definition gdb_ptrace.h:141
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2054
CORE_ADDR gdbarch_decr_pc_after_break(struct gdbarch *gdbarch)
Definition gdbarch.c:2903
struct thread_info * add_thread(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:336
all_matching_threads_range all_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
Definition gdbthread.h:742
void delete_thread(thread_info *thread)
Definition thread.c:527
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition thread.c:584
void thread_change_ptid(process_stratum_target *targ, ptid_t old_ptid, ptid_t new_ptid)
Definition thread.c:811
std::unique_ptr< private_thread_info > private_thread_info_up
Definition gdbthread.h:226
struct thread_info * add_thread_with_info(process_stratum_target *targ, ptid_t ptid, private_thread_info_up)
Definition thread.c:321
bool in_thread_list(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:631
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly 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:1861
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1791
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
ptid_t inferior_ptid
Definition infcmd.c:74
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
Definition inferior.c:406
struct inferior * find_inferior_pid(process_stratum_target *targ, int pid)
Definition inferior.c:389
struct inferior * current_inferior(void)
Definition inferior.c:55
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
observable< struct objfile * > new_objfile
observable< inferior * > inferior_created
int ppc_floating_point_unit_p(struct gdbarch *gdbarch)
@ ppc_num_gprs
Definition ppc-tdep.h:318
@ ppc_num_vrs
Definition ppc-tdep.h:321
@ ppc_num_vshrs
Definition ppc-tdep.h:322
@ ppc_num_fprs
Definition ppc-tdep.h:319
CORE_ADDR regcache_read_pc(struct regcache *regcache)
Definition regcache.c:1333
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
Definition regcache.c:400
pthdb_tid_t tid
Definition aix-thread.c:81
pthdb_pthread_t pdtid
Definition aix-thread.c:80
pthdb_session_t pd_session
Definition aix-thread.c:182
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
Definition gnu-nat.c:153
pid_t pid
Definition gnu-nat.c:165
pthdb_tid_t tid
Definition aix-thread.c:97
pthread_t pthid
Definition aix-thread.c:96
pthdb_pthread_t pdtid
Definition aix-thread.c:95
int ppc_vsr0_upper_regnum
Definition ppc-tdep.h:246
virtual ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags options) TARGET_DEFAULT_FUNC(default_target_wait)
virtual std::string pid_to_str(ptid_t) TARGET_DEFAULT_FUNC(default_pid_to_str)
virtual void fetch_registers(struct regcache *, int) TARGET_DEFAULT_IGNORE()
virtual void detach(inferior *, int) TARGET_DEFAULT_IGNORE()
target_ops * beneath() const
Definition target.c:3041
virtual void store_registers(struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
virtual enum target_xfer_status xfer_partial(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)
virtual void resume(ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
virtual void mourn_inferior() TARGET_DEFAULT_FUNC(default_mourn_inferior)
virtual bool thread_alive(ptid_t ptid) TARGET_DEFAULT_RETURN(false)
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition target.c:1861
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1785
target_xfer_status
Definition target.h:219
target_object
Definition target.h:143
strata
Definition target.h:94
@ thread_stratum
Definition target.h:98
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stdlog
Definition utils.h:190
@ TARGET_WAITKIND_STOPPED
Definition waitstatus.h:36