Blame nptl_db/td_ta_event_getmsg.c

Packit 6c4009
/* Retrieve event.
Packit 6c4009
   Copyright (C) 1999-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <stddef.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
#include "thread_dbP.h"
Packit 6c4009
Packit 6c4009
Packit 6c4009
td_err_e
Packit 6c4009
td_ta_event_getmsg (const td_thragent_t *ta_arg, td_event_msg_t *msg)
Packit 6c4009
{
Packit 6c4009
  td_thragent_t *const ta = (td_thragent_t *) ta_arg;
Packit 6c4009
  td_err_e err;
Packit 6c4009
  psaddr_t eventbuf, eventnum, eventdata;
Packit 6c4009
  psaddr_t thp, next;
Packit 6c4009
  void *copy;
Packit 6c4009
Packit 6c4009
  /* XXX I cannot think of another way but using a static variable.  */
Packit 6c4009
  /* XXX Use at least __thread once it is possible.  */
Packit 6c4009
  static td_thrhandle_t th;
Packit 6c4009
Packit 6c4009
  LOG ("td_thr_event_getmsg");
Packit 6c4009
Packit 6c4009
  /* Test whether the TA parameter is ok.  */
Packit 6c4009
  if (! ta_ok (ta))
Packit 6c4009
    return TD_BADTA;
Packit 6c4009
Packit 6c4009
  /* Get the pointer to the thread descriptor with the last event.  */
Packit 6c4009
  err = DB_GET_VALUE (thp, ta, __nptl_last_event, 0);
Packit 6c4009
  if (err != TD_OK)
Packit 6c4009
    return err;
Packit 6c4009
Packit 6c4009
  if (thp == 0)
Packit 6c4009
    /* Nothing waiting.  */
Packit 6c4009
    return TD_NOMSG;
Packit 6c4009
Packit 6c4009
  /* Copy the event message buffer in from the inferior.  */
Packit 6c4009
  err = DB_GET_FIELD_ADDRESS (eventbuf, ta, thp, pthread, eventbuf, 0);
Packit 6c4009
  if (err == TD_OK)
Packit 6c4009
    err = DB_GET_STRUCT (copy, ta, eventbuf, td_eventbuf_t);
Packit 6c4009
  if (err != TD_OK)
Packit 6c4009
    return err;
Packit 6c4009
Packit 6c4009
  /* Read the event details from the target thread.  */
Packit 6c4009
  err = DB_GET_FIELD_LOCAL (eventnum, ta, copy, td_eventbuf_t, eventnum, 0);
Packit 6c4009
  if (err != TD_OK)
Packit 6c4009
    return err;
Packit 6c4009
  /* If the structure is on the list there better be an event recorded.  */
Packit 6c4009
  if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
Packit 6c4009
    return TD_DBERR;
Packit 6c4009
Packit 6c4009
  /* Fill the user's data structure.  */
Packit 6c4009
  err = DB_GET_FIELD_LOCAL (eventdata, ta, copy, td_eventbuf_t, eventdata, 0);
Packit 6c4009
  if (err != TD_OK)
Packit 6c4009
    return err;
Packit 6c4009
Packit 6c4009
  /* Generate the thread descriptor.  */
Packit 6c4009
  th.th_ta_p = (td_thragent_t *) ta;
Packit 6c4009
  th.th_unique = thp;
Packit 6c4009
Packit 6c4009
  /* Fill the user's data structure.  */
Packit 6c4009
  msg->msg.data = (uintptr_t) eventdata;
Packit 6c4009
  msg->event = (uintptr_t) eventnum;
Packit 6c4009
  msg->th_p = &th;
Packit 6c4009
Packit 6c4009
  /* And clear the event message in the target.  */
Packit 6c4009
  memset (copy, 0, ta->ta_sizeof_td_eventbuf_t);
Packit 6c4009
  err = DB_PUT_STRUCT (ta, eventbuf, td_eventbuf_t, copy);
Packit 6c4009
  if (err != TD_OK)
Packit 6c4009
    return err;
Packit 6c4009
Packit 6c4009
  /* Get the pointer to the next descriptor with an event.  */
Packit 6c4009
  err = DB_GET_FIELD (next, ta, thp, pthread, nextevent, 0);
Packit 6c4009
  if (err != TD_OK)
Packit 6c4009
    return err;
Packit 6c4009
Packit 6c4009
  /* Store the pointer in the list head variable.  */
Packit 6c4009
  err = DB_PUT_VALUE (ta, __nptl_last_event, 0, next);
Packit 6c4009
  if (err != TD_OK)
Packit 6c4009
    return err;
Packit 6c4009
Packit 6c4009
  if (next != 0)
Packit 6c4009
    /* Clear the next pointer in the current descriptor.  */
Packit 6c4009
    err = DB_PUT_FIELD (ta, thp, pthread, nextevent, 0, 0);
Packit 6c4009
Packit 6c4009
  return err;
Packit 6c4009
}