1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #ifndef _THREAD_DBP_H
21: #define _THREAD_DBP_H 1
22:
23: #include <stdbool.h>
24: #include <stdint.h>
25: #include <string.h>
26: #include <stdlib.h>
27: #include <unistd.h>
28: #include <assert.h>
29: #include "proc_service.h"
30: #include "thread_db.h"
31: #include "../nptl/pthreadP.h"
32:
33:
34: enum
35: {
36: # define DB_STRUCT(type) SYM_SIZEOF_##type,
37: # define DB_STRUCT_FIELD(type, field) SYM_##type##_FIELD_##field,
38: # define DB_SYMBOL(name) SYM_##name,
39: # define DB_FUNCTION(name) SYM_##name,
40: # define DB_VARIABLE(name) SYM_##name, SYM_DESC_##name,
41: # include "structs.def"
42: # undef DB_STRUCT
43: # undef DB_STRUCT_FIELD
44: # undef DB_SYMBOL
45: # undef DB_FUNCTION
46: # undef DB_VARIABLE
47:
48: SYM_TH_UNIQUE_CONST_THREAD_AREA,
49: SYM_TH_UNIQUE_REGISTER64,
50: SYM_TH_UNIQUE_REGISTER32,
51: SYM_TH_UNIQUE_REGISTER64_THREAD_AREA,
52: SYM_TH_UNIQUE_REGISTER32_THREAD_AREA,
53:
54: SYM_NUM_MESSAGES
55: };
56:
57:
58:
59: #ifndef NDEBUG
60: # define LOG(c) if (__td_debug) write (2, c "\n", strlen (c "\n"))
61: extern int __td_debug attribute_hidden;
62: #else
63: # define LOG(c)
64: #endif
65:
66:
67: #define DB_DESC_SIZE(desc) ((desc)[0])
68: #define DB_DESC_NELEM(desc) ((desc)[1])
69: #define DB_DESC_OFFSET(desc) ((desc)[2])
70: #define DB_SIZEOF_DESC (3 * sizeof (uint32_t))
71: #define DB_DEFINE_DESC(name, size, nelem, offset) \
72: const uint32_t name[3] = { (size), (nelem), (offset) }
73: typedef uint32_t db_desc_t[3];
74:
75:
76:
77: struct td_thragent
78: {
79:
80: list_t list;
81:
82:
83:
84: struct ps_prochandle *ph;
85:
86:
87: # define DB_STRUCT(type) \
88: uint32_t ta_sizeof_##type;
89: # define DB_STRUCT_FIELD(type, field) \
90: db_desc_t ta_field_##type##_##field;
91: # define DB_SYMBOL(name) \
92: psaddr_t ta_addr_##name;
93: # define DB_FUNCTION(name) \
94: psaddr_t ta_addr_##name;
95: # define DB_VARIABLE(name) \
96: psaddr_t ta_addr_##name; \
97: db_desc_t ta_var_##name;
98: # include "structs.def"
99: # undef DB_STRUCT
100: # undef DB_STRUCT_FIELD
101: # undef DB_FUNCTION
102: # undef DB_SYMBOL
103: # undef DB_VARIABLE
104:
105:
106: enum
107: {
108: ta_howto_unknown,
109: ta_howto_reg,
110: ta_howto_reg_thread_area,
111: ta_howto_const_thread_area
112: } ta_howto;
113: union
114: {
115: uint32_t const_thread_area;
116:
117:
118: db_desc_t reg;
119: db_desc_t reg_thread_area;
120: } ta_howto_data;
121: };
122:
123:
124:
125: extern list_t __td_agent_list attribute_hidden;
126:
127:
128:
129: static inline bool
130: ta_ok (const td_thragent_t *ta)
131: {
132: list_t *runp;
133:
134: list_for_each (runp, &__td_agent_list)
135: if (list_entry (runp, td_thragent_t, list) == ta)
136: return true;
137:
138: return false;
139: }
140:
141:
142:
143: extern ps_err_e td_lookup (struct ps_prochandle *ps,
144: int idx, psaddr_t *sym_addr) attribute_hidden;
145:
146:
147:
148:
149:
150: #define DB_GET_SYMBOL(var, ta, name) \
151: (((ta)->ta_addr_##name == 0 \
152: && td_lookup ((ta)->ph, SYM_##name, &(ta)->ta_addr_##name) != PS_OK) \
153: ? TD_ERR : ((var) = (ta)->ta_addr_##name, TD_OK))
154:
155:
156:
157: #define DB_GET_FIELD(var, ta, ptr, type, field, idx) \
158: _td_fetch_value ((ta), (ta)->ta_field_##type##_##field, \
159: SYM_##type##_FIELD_##field, \
160: (psaddr_t) 0 + (idx), (ptr), &(var))
161:
162: #define DB_GET_FIELD_ADDRESS(var, ta, ptr, type, field, idx) \
163: ((var) = (ptr), _td_locate_field ((ta), (ta)->ta_field_##type##_##field, \
164: SYM_##type##_FIELD_##field, \
165: (psaddr_t) 0 + (idx), &(var)))
166:
167: extern td_err_e _td_locate_field (td_thragent_t *ta,
168: db_desc_t desc, int descriptor_name,
169: psaddr_t idx,
170: psaddr_t *address) attribute_hidden;
171:
172:
173:
174:
175: #define DB_GET_FIELD_LOCAL(var, ta, ptr, type, field, idx) \
176: _td_fetch_value_local ((ta), (ta)->ta_field_##type##_##field, \
177: SYM_##type##_FIELD_##field, \
178: (psaddr_t) 0 + (idx), (ptr), &(var))
179:
180:
181:
182: #define DB_GET_VALUE(var, ta, name, idx) \
183: (((ta)->ta_addr_##name == 0 \
184: && td_lookup ((ta)->ph, SYM_##name, &(ta)->ta_addr_##name) != PS_OK) \
185: ? TD_ERR \
186: : _td_fetch_value ((ta), (ta)->ta_var_##name, SYM_DESC_##name, \
187: (psaddr_t) 0 + (idx), (ta)->ta_addr_##name, &(var)))
188:
189:
190: extern td_err_e _td_fetch_value (td_thragent_t *ta,
191: db_desc_t field, int descriptor_name,
192: psaddr_t idx, psaddr_t address,
193: psaddr_t *result) attribute_hidden;
194: extern td_err_e _td_fetch_value_local (td_thragent_t *ta,
195: db_desc_t field,
196: int descriptor_name,
197: psaddr_t idx, void *address,
198: psaddr_t *result) attribute_hidden;
199:
200:
201:
202: #define DB_PUT_FIELD(ta, ptr, type, field, idx, value) \
203: _td_store_value ((ta), (ta)->ta_field_##type##_##field, \
204: SYM_##type##_FIELD_##field, \
205: (psaddr_t) 0 + (idx), (ptr), (value))
206:
207: #define DB_PUT_FIELD_LOCAL(ta, ptr, type, field, idx, value) \
208: _td_store_value_local ((ta), (ta)->ta_field_##type##_##field, \
209: SYM_##type##_FIELD_##field, \
210: (psaddr_t) 0 + (idx), (ptr), (value))
211:
212:
213:
214: #define DB_PUT_VALUE(ta, name, idx, value) \
215: (((ta)->ta_addr_##name == 0 \
216: && td_lookup ((ta)->ph, SYM_##name, &(ta)->ta_addr_##name) != PS_OK) \
217: ? TD_ERR \
218: : _td_store_value ((ta), (ta)->ta_var_##name, SYM_DESC_##name, \
219: (psaddr_t) 0 + (idx), (ta)->ta_addr_##name, (value)))
220:
221:
222: extern td_err_e _td_store_value (td_thragent_t *ta,
223: db_desc_t field, int descriptor_name,
224: psaddr_t idx, psaddr_t address,
225: psaddr_t value) attribute_hidden;
226: extern td_err_e _td_store_value_local (td_thragent_t *ta,
227: db_desc_t field, int descriptor_name,
228: psaddr_t idx, void *address,
229: psaddr_t value) attribute_hidden;
230:
231: #define DB_GET_STRUCT(var, ta, ptr, type) \
232: ({ td_err_e _err = TD_OK; \
233: if ((ta)->ta_sizeof_##type == 0) \
234: _err = _td_check_sizeof ((ta), &(ta)->ta_sizeof_##type, \
235: SYM_SIZEOF_##type); \
236: if (_err == TD_OK) \
237: _err = ps_pdread ((ta)->ph, (ptr), \
238: (var) = __alloca ((ta)->ta_sizeof_##type), \
239: (ta)->ta_sizeof_##type) \
240: == PS_OK ? TD_OK : TD_ERR; \
241: else \
242: (var) = NULL; \
243: _err; \
244: })
245: #define DB_PUT_STRUCT(ta, ptr, type, copy) \
246: ({ assert ((ta)->ta_sizeof_##type != 0); \
247: ps_pdwrite ((ta)->ph, (ptr), (copy), (ta)->ta_sizeof_##type) \
248: == PS_OK ? TD_OK : TD_ERR; \
249: })
250:
251: extern td_err_e _td_check_sizeof (td_thragent_t *ta, uint32_t *sizep,
252: int sizep_name) attribute_hidden;
253:
254: extern td_err_e __td_ta_lookup_th_unique (const td_thragent_t *ta,
255: lwpid_t lwpid, td_thrhandle_t *th);
256:
257: #endif