td_ta_map_lwp2thr.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Which thread is running on an lwp?
  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 "thread_dbP.h"
  18. td_err_e
  19. td_ta_map_lwp2thr (const td_thragent_t *ta, lwpid_t lwpid, td_thrhandle_t *th)
  20. {
  21. int pthread_threads_max = ta->pthread_threads_max;
  22. size_t sizeof_descr = ta->sizeof_descr;
  23. struct pthread_handle_struct phc[pthread_threads_max];
  24. size_t cnt;
  25. #ifdef ALL_THREADS_STOPPED
  26. int num;
  27. #else
  28. # define num 1
  29. #endif
  30. LOG (__FUNCTION__);
  31. /* Test whether the TA parameter is ok. */
  32. if (! ta_ok (ta))
  33. return TD_BADTA;
  34. /* Read all the descriptors. */
  35. if (ps_pdread (ta->ph, ta->handles, phc,
  36. sizeof (struct pthread_handle_struct) * pthread_threads_max)
  37. != PS_OK)
  38. return TD_ERR; /* XXX Other error value? */
  39. #ifdef ALL_THREADS_STOPPED
  40. /* Read the number of currently active threads. */
  41. if (ps_pdread (ta->ph, ta->pthread_handles_num, &num, sizeof (int)) != PS_OK)
  42. return TD_ERR; /* XXX Other error value? */
  43. #endif
  44. /* Get the entries one after the other and find out whether the ID
  45. matches. */
  46. for (cnt = 0; cnt < pthread_threads_max && num > 0; ++cnt)
  47. if (phc[cnt].h_descr != NULL)
  48. {
  49. struct _pthread_descr_struct pds;
  50. #ifdef ALL_THREADS_STOPPED
  51. /* First count this active thread. */
  52. --num;
  53. #endif
  54. if (ps_pdread (ta->ph, phc[cnt].h_descr, &pds, sizeof_descr) != PS_OK)
  55. return TD_ERR; /* XXX Other error value? */
  56. if ((pds.p_pid ?: ps_getpid (ta->ph)) == lwpid)
  57. {
  58. /* Found it. Now fill in the `td_thrhandle_t' object. */
  59. th->th_ta_p = (td_thragent_t *) ta;
  60. th->th_unique = phc[cnt].h_descr;
  61. return TD_OK;
  62. }
  63. }
  64. return TD_NOLWP;
  65. }