td_ta_event_getmsg.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Retrieve event.
  2. Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@redhat.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_ta_event_getmsg (const td_thragent_t *ta_arg, td_event_msg_t *msg)
  21. {
  22. td_thragent_t *const ta = (td_thragent_t *) ta_arg;
  23. td_err_e err;
  24. psaddr_t eventbuf, eventnum, eventdata;
  25. psaddr_t thp, next;
  26. void *copy = NULL;
  27. /* XXX I cannot think of another way but using a static variable. */
  28. /* XXX Use at least __thread once it is possible. */
  29. static td_thrhandle_t th;
  30. LOG ("td_thr_event_getmsg");
  31. /* Test whether the TA parameter is ok. */
  32. if (! ta_ok (ta))
  33. return TD_BADTA;
  34. /* Get the pointer to the thread descriptor with the last event. */
  35. err = DB_GET_VALUE (thp, ta, __nptl_last_event, 0);
  36. if (err != TD_OK)
  37. return err;
  38. if (thp == 0)
  39. /* Nothing waiting. */
  40. return TD_NOMSG;
  41. /* Copy the event message buffer in from the inferior. */
  42. err = DB_GET_FIELD_ADDRESS (eventbuf, ta, thp, pthread, eventbuf, 0);
  43. if (err == TD_OK)
  44. err = DB_GET_STRUCT (copy, ta, eventbuf, td_eventbuf_t);
  45. if (err != TD_OK)
  46. return err;
  47. /* Read the event details from the target thread. */
  48. err = DB_GET_FIELD_LOCAL (eventnum, ta, copy, td_eventbuf_t, eventnum, 0);
  49. if (err != TD_OK)
  50. return err;
  51. /* If the structure is on the list there better be an event recorded. */
  52. if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
  53. return TD_DBERR;
  54. /* Fill the user's data structure. */
  55. err = DB_GET_FIELD_LOCAL (eventdata, ta, copy, td_eventbuf_t, eventdata, 0);
  56. if (err != TD_OK)
  57. return err;
  58. /* Generate the thread descriptor. */
  59. th.th_ta_p = (td_thragent_t *) ta;
  60. th.th_unique = thp;
  61. /* Fill the user's data structure. */
  62. msg->msg.data = (uintptr_t) eventdata;
  63. msg->event = (uintptr_t) eventnum;
  64. msg->th_p = &th;
  65. /* And clear the event message in the target. */
  66. memset (copy, 0, ta->ta_sizeof_td_eventbuf_t);
  67. err = DB_PUT_STRUCT (ta, eventbuf, td_eventbuf_t, copy);
  68. if (err != TD_OK)
  69. return err;
  70. /* Get the pointer to the next descriptor with an event. */
  71. err = DB_GET_FIELD (next, ta, thp, pthread, nextevent, 0);
  72. if (err != TD_OK)
  73. return err;
  74. /* Store the pointer in the list head variable. */
  75. err = DB_PUT_VALUE (ta, __nptl_last_event, 0, next);
  76. if (err != TD_OK)
  77. return err;
  78. if (next != 0)
  79. /* Clear the next pointer in the current descriptor. */
  80. err = DB_PUT_FIELD (ta, thp, pthread, nextevent, 0, 0);
  81. return err;
  82. }