]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl_db/td_thr_event_getmsg.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / nptl_db / td_thr_event_getmsg.c
CommitLineData
76a50749 1/* Retrieve event.
dff8da6b 2 Copyright (C) 1999-2024 Free Software Foundation, Inc.
76a50749 3 This file is part of the GNU C Library.
76a50749
UD
4
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
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
76a50749 18
76a50749 19#include "thread_dbP.h"
7f08f55a 20#include <assert.h>
76a50749
UD
21
22
23td_err_e
24td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg)
25{
7f08f55a
RM
26 td_err_e err;
27 psaddr_t eventbuf, eventnum, eventdata;
28 psaddr_t thp, prevp;
29 void *copy;
76a50749
UD
30
31 LOG ("td_thr_event_getmsg");
32
7f08f55a
RM
33 /* Copy the event message buffer in from the inferior. */
34 err = DB_GET_FIELD_ADDRESS (eventbuf, th->th_ta_p, th->th_unique, pthread,
35 eventbuf, 0);
36 if (err == TD_OK)
37 err = DB_GET_STRUCT (copy, th->th_ta_p, eventbuf, td_eventbuf_t);
38 if (err != TD_OK)
39 return err;
76a50749
UD
40
41 /* Check whether an event occurred. */
7f08f55a
RM
42 err = DB_GET_FIELD_LOCAL (eventnum, th->th_ta_p, copy,
43 td_eventbuf_t, eventnum, 0);
44 if (err != TD_OK)
45 return err;
46 if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
76a50749
UD
47 /* Nothing. */
48 return TD_NOMSG;
49
50 /* Fill the user's data structure. */
7f08f55a
RM
51 err = DB_GET_FIELD_LOCAL (eventdata, th->th_ta_p, copy,
52 td_eventbuf_t, eventdata, 0);
53 if (err != TD_OK)
54 return err;
55
56 msg->msg.data = (uintptr_t) eventdata;
57 msg->event = (uintptr_t) eventnum;
76a50749 58 msg->th_p = th;
76a50749
UD
59
60 /* And clear the event message in the target. */
7f08f55a
RM
61 memset (copy, 0, th->th_ta_p->ta_sizeof_td_eventbuf_t);
62 err = DB_PUT_STRUCT (th->th_ta_p, eventbuf, td_eventbuf_t, copy);
63 if (err != TD_OK)
64 return err;
76a50749 65
90758db4
RM
66 /* Get the pointer to the thread descriptor with the last event.
67 If it doesn't match TH, then walk down the list until we find it.
68 We must splice it out of the list so that there is no dangling
69 pointer to it later when it dies. */
7f08f55a
RM
70 err = DB_GET_SYMBOL (prevp, th->th_ta_p, __nptl_last_event);
71 if (err != TD_OK)
72 return err;
73 err = DB_GET_VALUE (thp, th->th_ta_p, __nptl_last_event, 0);
74 if (err != TD_OK)
75 return err;
90758db4 76
90758db4
RM
77 while (thp != 0)
78 {
7f08f55a
RM
79 psaddr_t next;
80 err = DB_GET_FIELD (next, th->th_ta_p, th->th_unique, pthread,
81 nextevent, 0);
82 if (err != TD_OK)
83 return err;
90758db4
RM
84
85 if (next == thp)
86 return TD_DBERR;
87
88 if (thp == th->th_unique)
89 {
90 /* PREVP points at this thread, splice it out. */
7f08f55a
RM
91 psaddr_t next_nextp;
92 err = DB_GET_FIELD_ADDRESS (next_nextp, th->th_ta_p, next, pthread,
93 nextevent, 0);
94 assert (err == TD_OK); /* We used this field before. */
95 if (prevp == next_nextp)
90758db4
RM
96 return TD_DBERR;
97
7f08f55a
RM
98 err = _td_store_value (th->th_ta_p,
99 th->th_ta_p->ta_var___nptl_last_event, -1,
100 0, prevp, next);
101 if (err != TD_OK)
102 return err;
90758db4
RM
103
104 /* Now clear this thread's own next pointer so it's not dangling
105 when the thread resumes and then chains on for its next event. */
7f08f55a 106 return DB_PUT_FIELD (th->th_ta_p, thp, pthread, nextevent, 0, 0);
90758db4
RM
107 }
108
7f08f55a
RM
109 err = DB_GET_FIELD_ADDRESS (prevp, th->th_ta_p, thp, pthread,
110 nextevent, 0);
111 assert (err == TD_OK); /* We used this field before. */
90758db4
RM
112 thp = next;
113 }
114
115 /* Ack! This should not happen. */
116 return TD_DBERR;
76a50749 117}