Back to index

glibc  2.9
td_ta_event_getmsg.c
Go to the documentation of this file.
00001 /* Retrieve event.
00002    Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stddef.h>
00022 #include <string.h>
00023 
00024 #include "thread_dbP.h"
00025 
00026 
00027 td_err_e
00028 td_ta_event_getmsg (const td_thragent_t *ta_arg, td_event_msg_t *msg)
00029 {
00030   td_thragent_t *const ta = (td_thragent_t *) ta_arg;
00031   td_err_e err;
00032   psaddr_t eventbuf, eventnum, eventdata;
00033   psaddr_t thp, next;
00034   void *copy;
00035 
00036   /* XXX I cannot think of another way but using a static variable.  */
00037   /* XXX Use at least __thread once it is possible.  */
00038   static td_thrhandle_t th;
00039 
00040   LOG ("td_thr_event_getmsg");
00041 
00042   /* Test whether the TA parameter is ok.  */
00043   if (! ta_ok (ta))
00044     return TD_BADTA;
00045 
00046   /* Get the pointer to the thread descriptor with the last event.  */
00047   err = DB_GET_VALUE (thp, ta, __nptl_last_event, 0);
00048   if (err != TD_OK)
00049     return err;
00050 
00051   if (thp == 0)
00052     /* Nothing waiting.  */
00053     return TD_NOMSG;
00054 
00055   /* Copy the event message buffer in from the inferior.  */
00056   err = DB_GET_FIELD_ADDRESS (eventbuf, ta, thp, pthread, eventbuf, 0);
00057   if (err == TD_OK)
00058     err = DB_GET_STRUCT (copy, ta, eventbuf, td_eventbuf_t);
00059   if (err != TD_OK)
00060     return err;
00061 
00062   /* Read the event details from the target thread.  */
00063   err = DB_GET_FIELD_LOCAL (eventnum, ta, copy, td_eventbuf_t, eventnum, 0);
00064   if (err != TD_OK)
00065     return err;
00066   /* If the structure is on the list there better be an event recorded.  */
00067   if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
00068     return TD_DBERR;
00069 
00070   /* Fill the user's data structure.  */
00071   err = DB_GET_FIELD_LOCAL (eventdata, ta, copy, td_eventbuf_t, eventdata, 0);
00072   if (err != TD_OK)
00073     return err;
00074 
00075   /* Generate the thread descriptor.  */
00076   th.th_ta_p = (td_thragent_t *) ta;
00077   th.th_unique = thp;
00078 
00079   /* Fill the user's data structure.  */
00080   msg->msg.data = (uintptr_t) eventdata;
00081   msg->event = (uintptr_t) eventnum;
00082   msg->th_p = &th;
00083 
00084   /* And clear the event message in the target.  */
00085   memset (copy, 0, ta->ta_sizeof_td_eventbuf_t);
00086   err = DB_PUT_STRUCT (ta, eventbuf, td_eventbuf_t, copy);
00087   if (err != TD_OK)
00088     return err;
00089 
00090   /* Get the pointer to the next descriptor with an event.  */
00091   err = DB_GET_FIELD (next, ta, thp, pthread, nextevent, 0);
00092   if (err != TD_OK)
00093     return err;
00094 
00095   /* Store the pointer in the list head variable.  */
00096   err = DB_PUT_VALUE (ta, __nptl_last_event, 0, next);
00097   if (err != TD_OK)
00098     return err;
00099 
00100   if (next != 0)
00101     /* Clear the next pointer in the current descriptor.  */
00102     err = DB_PUT_FIELD (ta, thp, pthread, nextevent, 0, 0);
00103 
00104   return err;
00105 }