X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Faix-thread.c;h=0a9fae32c42d369413467175d9fbb488807daa86;hb=eb8c5f3f23278cba03de9b5b2739b1395ec60b16;hp=1eeeadb6d4fc3919a2115034fcef204533295639;hpb=7fc0c7b58f8ac2ceb2cd08084849674325af3d86;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 1eeeadb6d4..0a9fae32c4 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -1,7 +1,7 @@ /* Low level interface for debugging AIX 4.3+ pthreads. - Copyright (C) 1999, 2000, 2002, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2007-2012 Free Software Foundation, + Inc. Written by Nick Duffek . This file is part of GDB. @@ -58,6 +58,10 @@ #include #include +#if !HAVE_DECL_GETTHRDS +extern int getthrds (pid_t, struct thrdsinfo64 *, int, pthdb_tid_t *, int); +#endif + /* Whether to emit debugging output. */ static int debug_aix_thread; @@ -384,7 +388,7 @@ pdc_read_regs (pthdb_user_t user, } /* Write register function should be able to write requested context - information to specified debuggee's kernel thread id. + information to specified debuggee's kernel thread id. If successful return 0, else non-zero is returned. */ static int @@ -570,22 +574,36 @@ pcmp (const void *p1v, const void *p2v) return p1->pthid < p2->pthid ? -1 : p1->pthid > p2->pthid; } -/* iterate_over_threads() callback for counting GDB threads. */ +/* iterate_over_threads() callback for counting GDB threads. + + Do not count the main thread (whose tid is zero). This matches + the list of threads provided by the pthreaddebug library, which + does not include that main thread either, and thus allows us + to compare the two lists. */ static int giter_count (struct thread_info *thread, void *countp) { - (*(int *) countp)++; + if (PD_TID (thread->ptid)) + (*(int *) countp)++; return 0; } -/* iterate_over_threads() callback for accumulating GDB thread pids. */ +/* iterate_over_threads() callback for accumulating GDB thread pids. + + Do not include the main thread (whose tid is zero). This matches + the list of threads provided by the pthreaddebug library, which + does not include that main thread either, and thus allows us + to compare the two lists. */ static int giter_accum (struct thread_info *thread, void *bufp) { - **(struct thread_info ***) bufp = thread; - (*(struct thread_info ***) bufp)++; + if (PD_TID (thread->ptid)) + { + **(struct thread_info ***) bufp = thread; + (*(struct thread_info ***) bufp)++; + } return 0; } @@ -633,10 +651,6 @@ get_signaled_thread (void) pthdb_tid_t ktid = 0; int result = 0; - /* getthrds(3) isn't prototyped in any AIX 4.3.3 #include file. */ - extern int getthrds (pid_t, struct thrdsinfo64 *, - int, pthdb_tid_t *, int); - while (1) { if (getthrds (PIDGET (inferior_ptid), &thrinf, @@ -825,7 +839,7 @@ pd_update (int set_infpid) return ptid; } -/* Try to start debugging threads in the current process. +/* Try to start debugging threads in the current process. If successful and SET_INFPID, set inferior_ptid to reflect the current thread. */ @@ -873,21 +887,21 @@ pd_enable (void) return; /* Check application word size. */ - arch64 = register_size (current_gdbarch, 0) == 8; + arch64 = register_size (target_gdbarch, 0) == 8; /* Check whether the application is pthreaded. */ stub_name = NULL; status = pthdb_session_pthreaded (PD_USER, PTHDB_FLAG_REGS, &pd_callbacks, &stub_name); - if ((status != PTHDB_SUCCESS && - status != PTHDB_NOT_PTHREADED) || !stub_name) + if ((status != PTHDB_SUCCESS + && status != PTHDB_NOT_PTHREADED) || !stub_name) return; /* Set a breakpoint on the returned stub function. */ if (!(ms = lookup_minimal_symbol (stub_name, NULL, NULL))) return; pd_brk_addr = SYMBOL_VALUE_ADDRESS (ms); - if (!create_thread_event_breakpoint (pd_brk_addr)) + if (!create_thread_event_breakpoint (target_gdbarch, pd_brk_addr)) return; /* Prepare for thread debugging. */ @@ -972,7 +986,7 @@ aix_thread_resume (struct target_ops *ops, } else { - thread = find_thread_pid (ptid); + thread = find_thread_ptid (ptid); if (!thread) error (_("aix-thread resume: unknown pthread %ld"), TIDGET (ptid)); @@ -998,7 +1012,7 @@ aix_thread_resume (struct target_ops *ops, static ptid_t aix_thread_wait (struct target_ops *ops, - ptid_t ptid, struct target_waitstatus *status) + ptid_t ptid, struct target_waitstatus *status, int options) { struct cleanup *cleanup = save_inferior_ptid (); struct target_ops *beneath = find_target_beneath (ops); @@ -1006,7 +1020,7 @@ aix_thread_wait (struct target_ops *ops, pid_to_prc (&ptid); inferior_ptid = pid_to_ptid (PIDGET (inferior_ptid)); - ptid = beneath->to_wait (beneath, ptid, status); + ptid = beneath->to_wait (beneath, ptid, status, options); do_cleanups (cleanup); if (PIDGET (ptid) == -1) @@ -1288,7 +1302,7 @@ aix_thread_fetch_registers (struct target_ops *ops, beneath->to_fetch_registers (beneath, regcache, regno); else { - thread = find_thread_pid (inferior_ptid); + thread = find_thread_ptid (inferior_ptid); tid = thread->private->tid; if (tid == PTHDB_INVALID_TID) @@ -1307,7 +1321,8 @@ fill_gprs64 (const struct regcache *regcache, uint64_t *vals) int regno; for (regno = 0; regno < ppc_num_gprs; regno++) - if (regcache_valid_p (regcache, tdep->ppc_gp0_regnum + regno)) + if (REG_VALID == regcache_register_status (regcache, + tdep->ppc_gp0_regnum + regno)) regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + regno, vals + regno); } @@ -1319,7 +1334,8 @@ fill_gprs32 (const struct regcache *regcache, uint32_t *vals) int regno; for (regno = 0; regno < ppc_num_gprs; regno++) - if (regcache_valid_p (regcache, tdep->ppc_gp0_regnum + regno)) + if (REG_VALID == regcache_register_status (regcache, + tdep->ppc_gp0_regnum + regno)) regcache_raw_collect (regcache, tdep->ppc_gp0_regnum + regno, vals + regno); } @@ -1339,7 +1355,7 @@ fill_fprs (const struct regcache *regcache, double *vals) for (regno = tdep->ppc_fp0_regnum; regno < tdep->ppc_fp0_regnum + ppc_num_fprs; regno++) - if (regcache_valid_p (regcache, regno)) + if (REG_VALID == regcache_register_status (regcache, regno)) regcache_raw_collect (regcache, regno, vals + regno); } @@ -1363,20 +1379,22 @@ fill_sprs64 (const struct regcache *regcache, gdb_assert (sizeof (*iar) == register_size (gdbarch, gdbarch_pc_regnum (gdbarch))); - if (regcache_valid_p (regcache, gdbarch_pc_regnum (gdbarch))) + if (REG_VALID == regcache_register_status (regcache, + gdbarch_pc_regnum (gdbarch))) regcache_raw_collect (regcache, gdbarch_pc_regnum (gdbarch), iar); - if (regcache_valid_p (regcache, tdep->ppc_ps_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum)) regcache_raw_collect (regcache, tdep->ppc_ps_regnum, msr); - if (regcache_valid_p (regcache, tdep->ppc_cr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum)) regcache_raw_collect (regcache, tdep->ppc_cr_regnum, cr); - if (regcache_valid_p (regcache, tdep->ppc_lr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum)) regcache_raw_collect (regcache, tdep->ppc_lr_regnum, lr); - if (regcache_valid_p (regcache, tdep->ppc_ctr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ctr_regnum)) regcache_raw_collect (regcache, tdep->ppc_ctr_regnum, ctr); - if (regcache_valid_p (regcache, tdep->ppc_xer_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_xer_regnum)) regcache_raw_collect (regcache, tdep->ppc_xer_regnum, xer); if (tdep->ppc_fpscr_regnum >= 0 - && regcache_valid_p (regcache, tdep->ppc_fpscr_regnum)) + && REG_VALID == regcache_register_status (regcache, + tdep->ppc_fpscr_regnum)) regcache_raw_collect (regcache, tdep->ppc_fpscr_regnum, fpscr); } @@ -1397,20 +1415,21 @@ fill_sprs32 (const struct regcache *regcache, gdb_assert (sizeof (*iar) == register_size (gdbarch, gdbarch_pc_regnum (gdbarch))); - if (regcache_valid_p (regcache, gdbarch_pc_regnum (gdbarch))) + if (REG_VALID == regcache_register_status (regcache, + gdbarch_pc_regnum (gdbarch))) regcache_raw_collect (regcache, gdbarch_pc_regnum (gdbarch), iar); - if (regcache_valid_p (regcache, tdep->ppc_ps_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum)) regcache_raw_collect (regcache, tdep->ppc_ps_regnum, msr); - if (regcache_valid_p (regcache, tdep->ppc_cr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum)) regcache_raw_collect (regcache, tdep->ppc_cr_regnum, cr); - if (regcache_valid_p (regcache, tdep->ppc_lr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum)) regcache_raw_collect (regcache, tdep->ppc_lr_regnum, lr); - if (regcache_valid_p (regcache, tdep->ppc_ctr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ctr_regnum)) regcache_raw_collect (regcache, tdep->ppc_ctr_regnum, ctr); - if (regcache_valid_p (regcache, tdep->ppc_xer_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_xer_regnum)) regcache_raw_collect (regcache, tdep->ppc_xer_regnum, xer); if (tdep->ppc_fpscr_regnum >= 0 - && regcache_valid_p (regcache, tdep->ppc_fpscr_regnum)) + && REG_VALID == regcache_register_status (regcache, tdep->ppc_fpscr_regnum)) regcache_raw_collect (regcache, tdep->ppc_fpscr_regnum, fpscr); } @@ -1445,7 +1464,8 @@ store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid) /* Collect general-purpose register values from the regcache. */ for (i = 0; i < ppc_num_gprs; i++) - if (regcache_valid_p (regcache, tdep->ppc_gp0_regnum + i)) + if (REG_VALID == regcache_register_status (regcache, + tdep->ppc_gp0_regnum + i)) { if (arch64) { @@ -1480,25 +1500,30 @@ store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid) fill_sprs32 (regcache, &tmp_iar, &tmp_msr, &tmp_cr, &tmp_lr, &tmp_ctr, &tmp_xer, &tmp_fpscr); - if (regcache_valid_p (regcache, gdbarch_pc_regnum (gdbarch))) + if (REG_VALID == regcache_register_status (regcache, + gdbarch_pc_regnum (gdbarch))) ctx.iar = tmp_iar; - if (regcache_valid_p (regcache, tdep->ppc_ps_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_ps_regnum)) ctx.msr = tmp_msr; - if (regcache_valid_p (regcache, tdep->ppc_cr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_cr_regnum)) ctx.cr = tmp_cr; - if (regcache_valid_p (regcache, tdep->ppc_lr_regnum)) + if (REG_VALID == regcache_register_status (regcache, tdep->ppc_lr_regnum)) ctx.lr = tmp_lr; - if (regcache_valid_p (regcache, tdep->ppc_ctr_regnum)) + if (REG_VALID == regcache_register_status (regcache, + tdep->ppc_ctr_regnum)) ctx.ctr = tmp_ctr; - if (regcache_valid_p (regcache, tdep->ppc_xer_regnum)) + if (REG_VALID == regcache_register_status (regcache, + tdep->ppc_xer_regnum)) ctx.xer = tmp_xer; - if (regcache_valid_p (regcache, tdep->ppc_xer_regnum)) + if (REG_VALID == regcache_register_status (regcache, + tdep->ppc_xer_regnum)) ctx.fpscr = tmp_fpscr; } status = pthdb_pthread_setcontext (pd_session, pdtid, &ctx); if (status != PTHDB_SUCCESS) - error (_("aix-thread: store_registers: pthdb_pthread_setcontext returned %s"), + error (_("aix-thread: store_registers: " + "pthdb_pthread_setcontext returned %s"), pd_status2str (status)); } @@ -1605,7 +1630,8 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno, sprs32.pt_fpscr = tmp_fpscr; if (tdep->ppc_mq_regnum >= 0) - if (regcache_valid_p (regcache, tdep->ppc_mq_regnum)) + if (REG_VALID == regcache_register_status (regcache, + tdep->ppc_mq_regnum)) regcache_raw_collect (regcache, tdep->ppc_mq_regnum, &sprs32.pt_mq); @@ -1629,7 +1655,7 @@ aix_thread_store_registers (struct target_ops *ops, beneath->to_store_registers (beneath, regcache, regno); else { - thread = find_thread_pid (inferior_ptid); + thread = find_thread_ptid (inferior_ptid); tid = thread->private->tid; if (tid == PTHDB_INVALID_TID) @@ -1646,7 +1672,8 @@ aix_thread_store_registers (struct target_ops *ops, static LONGEST aix_thread_xfer_partial (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, - const gdb_byte *writebuf, ULONGEST offset, LONGEST len) + const gdb_byte *writebuf, + ULONGEST offset, LONGEST len) { struct cleanup *old_chain = save_inferior_ptid (); LONGEST xfer; @@ -1720,7 +1747,6 @@ aix_thread_extra_thread_info (struct thread_info *thread) pthdb_suspendstate_t suspendstate; pthdb_detachstate_t detachstate; int cancelpend; - long length; static char *ret = NULL; if (!PD_TID (thread->ptid)) @@ -1761,7 +1787,7 @@ aix_thread_extra_thread_info (struct thread_info *thread) xfree (ret); /* Free old buffer. */ - ret = ui_file_xstrdup (buf, &length); + ret = ui_file_xstrdup (buf, NULL); ui_file_delete (buf); return ret; @@ -1778,26 +1804,26 @@ aix_thread_get_ada_task_ptid (long lwp, long thread) static void init_aix_thread_ops (void) { - aix_thread_ops.to_shortname = "aix-threads"; - aix_thread_ops.to_longname = _("AIX pthread support"); - aix_thread_ops.to_doc = _("AIX pthread support"); - - aix_thread_ops.to_attach = aix_thread_attach; - aix_thread_ops.to_detach = aix_thread_detach; - aix_thread_ops.to_resume = aix_thread_resume; - aix_thread_ops.to_wait = aix_thread_wait; - aix_thread_ops.to_fetch_registers = aix_thread_fetch_registers; - aix_thread_ops.to_store_registers = aix_thread_store_registers; - aix_thread_ops.to_xfer_partial = aix_thread_xfer_partial; + aix_thread_ops.to_shortname = "aix-threads"; + aix_thread_ops.to_longname = _("AIX pthread support"); + aix_thread_ops.to_doc = _("AIX pthread support"); + + aix_thread_ops.to_attach = aix_thread_attach; + aix_thread_ops.to_detach = aix_thread_detach; + aix_thread_ops.to_resume = aix_thread_resume; + aix_thread_ops.to_wait = aix_thread_wait; + aix_thread_ops.to_fetch_registers = aix_thread_fetch_registers; + aix_thread_ops.to_store_registers = aix_thread_store_registers; + aix_thread_ops.to_xfer_partial = aix_thread_xfer_partial; /* No need for aix_thread_ops.to_create_inferior, because we activate thread debugging when the inferior reaches pd_brk_addr. */ - aix_thread_ops.to_mourn_inferior = aix_thread_mourn_inferior; - aix_thread_ops.to_thread_alive = aix_thread_thread_alive; - aix_thread_ops.to_pid_to_str = aix_thread_pid_to_str; - aix_thread_ops.to_extra_thread_info = aix_thread_extra_thread_info; - aix_thread_ops.to_get_ada_task_ptid = aix_thread_get_ada_task_ptid; - aix_thread_ops.to_stratum = thread_stratum; - aix_thread_ops.to_magic = OPS_MAGIC; + aix_thread_ops.to_mourn_inferior = aix_thread_mourn_inferior; + aix_thread_ops.to_thread_alive = aix_thread_thread_alive; + aix_thread_ops.to_pid_to_str = aix_thread_pid_to_str; + aix_thread_ops.to_extra_thread_info = aix_thread_extra_thread_info; + aix_thread_ops.to_get_ada_task_ptid = aix_thread_get_ada_task_ptid; + aix_thread_ops.to_stratum = thread_stratum; + aix_thread_ops.to_magic = OPS_MAGIC; } /* Module startup initialization function, automagically called by @@ -1813,9 +1839,11 @@ _initialize_aix_thread (void) observer_attach_new_objfile (new_objfile); add_setshow_boolean_cmd ("aix-thread", class_maintenance, &debug_aix_thread, - _("Set debugging of AIX thread module."), - _("Show debugging of AIX thread module."), - _("Enables debugging output (used to debug GDB)."), - NULL, NULL, /* FIXME: i18n: Debugging of AIX thread module is \"%d\". */ - &setdebuglist, &showdebuglist); + _("Set debugging of AIX thread module."), + _("Show debugging of AIX thread module."), + _("Enables debugging output (used to debug GDB)."), + NULL, NULL, + /* FIXME: i18n: Debugging of AIX thread + module is \"%d\". */ + &setdebuglist, &showdebuglist); }