1 /* Private header for thread debug library
2 Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #define _THREAD_DBP_H 1
28 #include "proc_service.h"
29 #include "thread_db.h"
30 #include "../nptl/pthreadP.h" /* This is for *_BITMASK only. */
33 #define __alloca alloca
36 /* Indeces for the symbol names. */
39 # define DB_STRUCT(type) SYM_SIZEOF_##type,
40 # define DB_STRUCT_FIELD(type, field) SYM_##type##_FIELD_##field,
41 # define DB_SYMBOL(name) SYM_##name,
42 # define DB_FUNCTION(name) SYM_##name,
43 # define DB_VARIABLE(name) SYM_##name, SYM_DESC_##name,
44 # include "structs.def"
46 # undef DB_STRUCT_FIELD
51 SYM_TH_UNIQUE_CONST_THREAD_AREA
,
52 SYM_TH_UNIQUE_REGISTER64
,
53 SYM_TH_UNIQUE_REGISTER32
,
54 SYM_TH_UNIQUE_REGISTER64_THREAD_AREA
,
55 SYM_TH_UNIQUE_REGISTER32_THREAD_AREA
,
61 /* Comment out the following for less verbose output. */
63 # define LOG(c) if (__td_debug) write (2, c "\n", strlen (c "\n"))
64 extern int __td_debug attribute_hidden
;
70 #define DB_DESC_SIZE(desc) ((desc)[0])
71 #define DB_DESC_NELEM(desc) ((desc)[1])
72 #define DB_DESC_OFFSET(desc) ((desc)[2])
73 #define DB_SIZEOF_DESC (3 * sizeof (uint32_t))
74 #define DB_DEFINE_DESC(name, size, nelem, offset) \
75 const uint32_t name[3] = { (size), (nelem), (offset) }
76 typedef uint32_t db_desc_t
[3];
79 /* Handle for a process. This type is opaque. */
82 /* Chain on the list of all agent structures. */
85 /* Delivered by the debugger and we have to pass it back in the
87 struct ps_prochandle
*ph
;
89 /* Cached values read from the inferior. */
90 # define DB_STRUCT(type) \
91 uint32_t ta_sizeof_##type;
92 # define DB_STRUCT_FIELD(type, field) \
93 db_desc_t ta_field_##type##_##field;
94 # define DB_SYMBOL(name) \
95 psaddr_t ta_addr_##name;
96 # define DB_FUNCTION(name) \
97 psaddr_t ta_addr_##name;
98 # define DB_VARIABLE(name) \
99 psaddr_t ta_addr_##name; \
100 db_desc_t ta_var_##name;
101 # include "structs.def"
103 # undef DB_STRUCT_FIELD
108 /* The method of locating a thread's th_unique value. */
113 ta_howto_reg_thread_area
,
114 ta_howto_const_thread_area
118 uint32_t const_thread_area
; /* Constant argument to ps_get_thread_area. */
119 /* These are as if the descriptor of the field in prregset_t,
120 but DB_DESC_NELEM is overloaded as follows: */
121 db_desc_t reg
; /* Signed bias applied to register value. */
122 db_desc_t reg_thread_area
; /* Bits to scale down register value. */
127 /* List of all known descriptors. */
128 extern list_t __td_agent_list attribute_hidden
;
131 /* Function used to test for correct thread agent pointer. */
133 ta_ok (const td_thragent_t
*ta
)
137 list_for_each (runp
, &__td_agent_list
)
138 if (list_entry (runp
, td_thragent_t
, list
) == ta
)
145 /* Internal wrapper around ps_pglobal_lookup. */
146 extern ps_err_e
td_lookup (struct ps_prochandle
*ps
,
147 int idx
, psaddr_t
*sym_addr
) attribute_hidden
;
152 /* Store in psaddr_t VAR the address of inferior's symbol NAME. */
153 #define DB_GET_SYMBOL(var, ta, name) \
154 (((ta)->ta_addr_##name == 0 \
155 && td_lookup ((ta)->ph, SYM_##name, &(ta)->ta_addr_##name) != PS_OK) \
156 ? TD_ERR : ((var) = (ta)->ta_addr_##name, TD_OK))
158 /* Store in psaddr_t VAR the value of ((TYPE) PTR)->FIELD[IDX] in the inferior.
159 A target field smaller than psaddr_t is zero-extended. */
160 #define DB_GET_FIELD(var, ta, ptr, type, field, idx) \
161 _td_fetch_value ((ta), (ta)->ta_field_##type##_##field, \
162 SYM_##type##_FIELD_##field, \
163 (psaddr_t) 0 + (idx), (ptr), &(var))
165 #define DB_GET_FIELD_ADDRESS(var, ta, ptr, type, field, idx) \
166 ((var) = (ptr), _td_locate_field ((ta), (ta)->ta_field_##type##_##field, \
167 SYM_##type##_FIELD_##field, \
168 (psaddr_t) 0 + (idx), &(var)))
170 extern td_err_e
_td_locate_field (td_thragent_t
*ta
,
171 db_desc_t desc
, int descriptor_name
,
173 psaddr_t
*address
) attribute_hidden
;
176 /* Like DB_GET_FIELD, but PTR is a local pointer to a structure that
177 has already been copied in from the inferior. */
178 #define DB_GET_FIELD_LOCAL(var, ta, ptr, type, field, idx) \
179 _td_fetch_value_local ((ta), (ta)->ta_field_##type##_##field, \
180 SYM_##type##_FIELD_##field, \
181 (psaddr_t) 0 + (idx), (ptr), &(var))
183 /* Store in psaddr_t VAR the value of variable NAME[IDX] in the inferior.
184 A target value smaller than psaddr_t is zero-extended. */
185 #define DB_GET_VALUE(var, ta, name, idx) \
186 (((ta)->ta_addr_##name == 0 \
187 && td_lookup ((ta)->ph, SYM_##name, &(ta)->ta_addr_##name) != PS_OK) \
189 : _td_fetch_value ((ta), (ta)->ta_var_##name, SYM_DESC_##name, \
190 (psaddr_t) 0 + (idx), (ta)->ta_addr_##name, &(var)))
192 /* Helper functions for those. */
193 extern td_err_e
_td_fetch_value (td_thragent_t
*ta
,
194 db_desc_t field
, int descriptor_name
,
195 psaddr_t idx
, psaddr_t address
,
196 psaddr_t
*result
) attribute_hidden
;
197 extern td_err_e
_td_fetch_value_local (td_thragent_t
*ta
,
200 psaddr_t idx
, void *address
,
201 psaddr_t
*result
) attribute_hidden
;
203 /* Store psaddr_t VALUE in ((TYPE) PTR)->FIELD[IDX] in the inferior.
204 A target field smaller than psaddr_t is zero-extended. */
205 #define DB_PUT_FIELD(ta, ptr, type, field, idx, value) \
206 _td_store_value ((ta), (ta)->ta_field_##type##_##field, \
207 SYM_##type##_FIELD_##field, \
208 (psaddr_t) 0 + (idx), (ptr), (value))
210 #define DB_PUT_FIELD_LOCAL(ta, ptr, type, field, idx, value) \
211 _td_store_value_local ((ta), (ta)->ta_field_##type##_##field, \
212 SYM_##type##_FIELD_##field, \
213 (psaddr_t) 0 + (idx), (ptr), (value))
215 /* Store psaddr_t VALUE in variable NAME[IDX] in the inferior.
216 A target field smaller than psaddr_t is zero-extended. */
217 #define DB_PUT_VALUE(ta, name, idx, value) \
218 (((ta)->ta_addr_##name == 0 \
219 && td_lookup ((ta)->ph, SYM_##name, &(ta)->ta_addr_##name) != PS_OK) \
221 : _td_store_value ((ta), (ta)->ta_var_##name, SYM_DESC_##name, \
222 (psaddr_t) 0 + (idx), (ta)->ta_addr_##name, (value)))
224 /* Helper functions for those. */
225 extern td_err_e
_td_store_value (td_thragent_t
*ta
,
226 db_desc_t field
, int descriptor_name
,
227 psaddr_t idx
, psaddr_t address
,
228 psaddr_t value
) attribute_hidden
;
229 extern td_err_e
_td_store_value_local (td_thragent_t
*ta
,
230 db_desc_t field
, int descriptor_name
,
231 psaddr_t idx
, void *address
,
232 psaddr_t value
) attribute_hidden
;
234 #define DB_GET_STRUCT(var, ta, ptr, type) \
235 ({ td_err_e _err = TD_OK; \
236 if ((ta)->ta_sizeof_##type == 0) \
237 _err = _td_check_sizeof ((ta), &(ta)->ta_sizeof_##type, \
238 SYM_SIZEOF_##type); \
240 _err = ps_pdread ((ta)->ph, (ptr), \
241 (var) = __alloca ((ta)->ta_sizeof_##type), \
242 (ta)->ta_sizeof_##type) \
243 == PS_OK ? TD_OK : TD_ERR; \
248 #define DB_PUT_STRUCT(ta, ptr, type, copy) \
249 ({ assert ((ta)->ta_sizeof_##type != 0); \
250 ps_pdwrite ((ta)->ph, (ptr), (copy), (ta)->ta_sizeof_##type) \
251 == PS_OK ? TD_OK : TD_ERR; \
254 extern td_err_e
_td_check_sizeof (td_thragent_t
*ta
, uint32_t *sizep
,
255 int sizep_name
) attribute_hidden
;
257 extern td_err_e
__td_ta_lookup_th_unique (const td_thragent_t
*ta
,
258 lwpid_t lwpid
, td_thrhandle_t
*th
);
260 #endif /* thread_dbP.h */