td_thr_get_info.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Get thread information.
  2. Copyright (C) 1999 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 Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. 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. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 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_RUN;
  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_exited)
  47. /* This should not happen. */
  48. infop->ti_state = TD_THR_ZOMBIE;
  49. else
  50. /* XXX For now there is no way to get more information. */
  51. infop->ti_state = TD_THR_RUN;
  52. }
  53. /* Initialization which are the same in both cases. */
  54. infop->ti_lid = pds.p_pid ?: ps_getpid (th->th_ta_p->ph);
  55. infop->ti_ta_p = th->th_ta_p;
  56. infop->ti_startfunc = pds.p_start_args.start_routine;
  57. memcpy (&infop->ti_events, &pds.p_eventbuf.eventmask,
  58. sizeof (td_thr_events_t));
  59. infop->ti_traceme = pds.p_report_events != 0;
  60. return TD_OK;
  61. }