td_ta_event_getmsg.c 3.3 KB

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