td_thr_get_info.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Get thread information.
  2. Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <stddef.h>
  18. #include <string.h>
  19. #include "thread_dbP.h"
  20. td_err_e
  21. td_thr_get_info (const td_thrhandle_t *th, td_thrinfo_t *infop)
  22. {
  23. struct _pthread_descr_struct pds;
  24. LOG ("td_thr_get_info");
  25. /* Handle the case when the thread library is not yet initialized. */
  26. if (th->th_unique == NULL)
  27. {
  28. memset (&pds, '\0', sizeof (pds));
  29. pds.p_tid = PTHREAD_THREADS_MAX;
  30. }
  31. else
  32. /* Get the thread descriptor. */
  33. if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
  34. th->th_ta_p->sizeof_descr) != PS_OK)
  35. return TD_ERR; /* XXX Other error value? */
  36. /* Fill in information. Clear first to provide reproducable
  37. results for the fields we do not fill in. */
  38. memset (infop, '\0', sizeof (td_thrinfo_t));
  39. /* We have to handle the manager thread special since the thread
  40. descriptor in older versions is not fully initialized. */
  41. if (pds.p_nr == 1)
  42. {
  43. infop->ti_tid = th->th_ta_p->pthread_threads_max * 2 + 1;
  44. infop->ti_type = TD_THR_SYSTEM;
  45. infop->ti_state = TD_THR_ACTIVE;
  46. }
  47. else
  48. {
  49. infop->ti_tid = pds.p_tid;
  50. infop->ti_tls = (char *) pds.p_specific;
  51. infop->ti_pri = pds.p_priority;
  52. infop->ti_type = TD_THR_USER;
  53. if (! pds.p_terminated)
  54. /* XXX For now there is no way to get more information. */
  55. infop->ti_state = TD_THR_ACTIVE;
  56. else if (! pds.p_detached)
  57. infop->ti_state = TD_THR_ZOMBIE;
  58. else
  59. infop->ti_state = TD_THR_UNKNOWN;
  60. }
  61. /* Initialization which are the same in both cases. */
  62. infop->ti_lid = pds.p_pid ?: ps_getpid (th->th_ta_p->ph);
  63. infop->ti_ta_p = th->th_ta_p;
  64. infop->ti_startfunc = pds.p_start_args.start_routine;
  65. memcpy (&infop->ti_events, &pds.p_eventbuf.eventmask,
  66. sizeof (td_thr_events_t));
  67. infop->ti_traceme = pds.p_report_events != 0;
  68. return TD_OK;
  69. }