td_thr_get_info.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Get thread information.
  2. Copyright (C) 1999, 2000 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 (__FUNCTION__);
  25. /* Get the thread descriptor. */
  26. if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
  27. th->th_ta_p->sizeof_descr) != PS_OK)
  28. return TD_ERR; /* XXX Other error value? */
  29. /* Fill in information. Clear first to provide reproducable
  30. results for the fields we do not fill in. */
  31. memset (infop, '\0', sizeof (td_thrinfo_t));
  32. /* We have to handle the manager thread special since the thread
  33. descriptor in older versions is not fully initialized. */
  34. if (pds.p_nr == 1)
  35. {
  36. infop->ti_tid = th->th_ta_p->pthread_threads_max * 2 + 1;
  37. infop->ti_type = TD_THR_SYSTEM;
  38. infop->ti_state = TD_THR_ACTIVE;
  39. }
  40. else
  41. {
  42. infop->ti_tid = pds.p_tid;
  43. infop->ti_tls = (char *) pds.p_specific;
  44. infop->ti_pri = pds.p_priority;
  45. infop->ti_type = TD_THR_USER;
  46. if (! pds.p_terminated)
  47. /* XXX For now there is no way to get more information. */
  48. infop->ti_state = TD_THR_ACTIVE;
  49. else if (! pds.p_detached)
  50. infop->ti_state = TD_THR_ZOMBIE;
  51. else
  52. infop->ti_state = TD_THR_UNKNOWN;
  53. }
  54. /* Initialization which are the same in both cases. */
  55. infop->ti_lid = pds.p_pid ?: ps_getpid (th->th_ta_p->ph);
  56. infop->ti_ta_p = th->th_ta_p;
  57. infop->ti_startfunc = pds.p_start_args.start_routine;
  58. memcpy (&infop->ti_events, &pds.p_eventbuf.eventmask,
  59. sizeof (td_thr_events_t));
  60. infop->ti_traceme = pds.p_report_events != 0;
  61. return TD_OK;
  62. }