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