td_thr_event_getmsg.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "thread_dbP.h"
  18. #include <assert.h>
  19. td_err_e
  20. td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg)
  21. {
  22. td_err_e err;
  23. psaddr_t eventbuf, eventnum, eventdata;
  24. psaddr_t thp, prevp;
  25. void *copy = NULL;
  26. LOG ("td_thr_event_getmsg");
  27. /* Copy the event message buffer in from the inferior. */
  28. err = DB_GET_FIELD_ADDRESS (eventbuf, th->th_ta_p, th->th_unique, pthread,
  29. eventbuf, 0);
  30. if (err == TD_OK)
  31. err = DB_GET_STRUCT (copy, th->th_ta_p, eventbuf, td_eventbuf_t);
  32. if (err != TD_OK)
  33. return err;
  34. /* Check whether an event occurred. */
  35. err = DB_GET_FIELD_LOCAL (eventnum, th->th_ta_p, copy,
  36. td_eventbuf_t, eventnum, 0);
  37. if (err != TD_OK)
  38. return err;
  39. if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
  40. /* Nothing. */
  41. return TD_NOMSG;
  42. /* Fill the user's data structure. */
  43. err = DB_GET_FIELD_LOCAL (eventdata, th->th_ta_p, copy,
  44. td_eventbuf_t, eventdata, 0);
  45. if (err != TD_OK)
  46. return err;
  47. msg->msg.data = (uintptr_t) eventdata;
  48. msg->event = (uintptr_t) eventnum;
  49. msg->th_p = th;
  50. /* And clear the event message in the target. */
  51. memset (copy, 0, th->th_ta_p->ta_sizeof_td_eventbuf_t);
  52. err = DB_PUT_STRUCT (th->th_ta_p, eventbuf, td_eventbuf_t, copy);
  53. if (err != TD_OK)
  54. return err;
  55. /* Get the pointer to the thread descriptor with the last event.
  56. If it doesn't match TH, then walk down the list until we find it.
  57. We must splice it out of the list so that there is no dangling
  58. pointer to it later when it dies. */
  59. err = DB_GET_SYMBOL (prevp, th->th_ta_p, __nptl_last_event);
  60. if (err != TD_OK)
  61. return err;
  62. err = DB_GET_VALUE (thp, th->th_ta_p, __nptl_last_event, 0);
  63. if (err != TD_OK)
  64. return err;
  65. while (thp != 0)
  66. {
  67. psaddr_t next;
  68. err = DB_GET_FIELD (next, th->th_ta_p, th->th_unique, pthread,
  69. nextevent, 0);
  70. if (err != TD_OK)
  71. return err;
  72. if (next == thp)
  73. return TD_DBERR;
  74. if (thp == th->th_unique)
  75. {
  76. /* PREVP points at this thread, splice it out. */
  77. psaddr_t next_nextp;
  78. err = DB_GET_FIELD_ADDRESS (next_nextp, th->th_ta_p, next, pthread,
  79. nextevent, 0);
  80. assert (err == TD_OK); /* We used this field before. */
  81. if (prevp == next_nextp)
  82. return TD_DBERR;
  83. err = _td_store_value (th->th_ta_p,
  84. th->th_ta_p->ta_var___nptl_last_event, -1,
  85. 0, prevp, next);
  86. if (err != TD_OK)
  87. return err;
  88. /* Now clear this thread's own next pointer so it's not dangling
  89. when the thread resumes and then chains on for its next event. */
  90. return DB_PUT_FIELD (th->th_ta_p, thp, pthread, nextevent, 0, 0);
  91. }
  92. err = DB_GET_FIELD_ADDRESS (prevp, th->th_ta_p, thp, pthread,
  93. nextevent, 0);
  94. assert (err == TD_OK); /* We used this field before. */
  95. thp = next;
  96. }
  97. /* Ack! This should not happen. */
  98. return TD_DBERR;
  99. }