td_thr_get_info.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <stddef.h>
  17. #include <string.h>
  18. #include "thread_dbP.h"
  19. td_err_e
  20. td_thr_get_info (const td_thrhandle_t *th, td_thrinfo_t *infop)
  21. {
  22. struct _pthread_descr_struct pds;
  23. LOG ("td_thr_get_info");
  24. /* Handle the case when the thread library is not yet initialized. */
  25. if (th->th_unique == NULL)
  26. {
  27. memset (&pds, '\0', sizeof (pds));
  28. pds.p_tid = PTHREAD_THREADS_MAX;
  29. }
  30. else
  31. /* Get the thread descriptor. */
  32. if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
  33. th->th_ta_p->sizeof_descr) != PS_OK)
  34. return TD_ERR; /* XXX Other error value? */
  35. /* Fill in information. Clear first to provide reproducable
  36. results for the fields we do not fill in. */
  37. memset (infop, '\0', sizeof (td_thrinfo_t));
  38. /* We have to handle the manager thread special since the thread
  39. descriptor in older versions is not fully initialized. */
  40. if (pds.p_nr == 1)
  41. {
  42. infop->ti_tid = th->th_ta_p->pthread_threads_max * 2 + 1;
  43. infop->ti_type = TD_THR_SYSTEM;
  44. infop->ti_state = TD_THR_ACTIVE;
  45. }
  46. else
  47. {
  48. infop->ti_tid = pds.p_tid;
  49. infop->ti_tls = (char *) pds.p_specific;
  50. infop->ti_pri = pds.p_priority;
  51. infop->ti_type = TD_THR_USER;
  52. if (! pds.p_terminated)
  53. /* XXX For now there is no way to get more information. */
  54. infop->ti_state = TD_THR_ACTIVE;
  55. else if (! pds.p_detached)
  56. infop->ti_state = TD_THR_ZOMBIE;
  57. else
  58. infop->ti_state = TD_THR_UNKNOWN;
  59. }
  60. /* Initialization which are the same in both cases. */
  61. infop->ti_lid = pds.p_pid ?: ps_getpid (th->th_ta_p->ph);
  62. infop->ti_ta_p = th->th_ta_p;
  63. infop->ti_startfunc = pds.p_start_args.start_routine;
  64. memcpy (&infop->ti_events, &pds.p_eventbuf.eventmask,
  65. sizeof (td_thr_events_t));
  66. infop->ti_traceme = pds.p_report_events != 0;
  67. return TD_OK;
  68. }