Remove duplicate entries.
[glibc/history.git] / nptl_db / thread_dbP.h
blobe5db9bf94b0fda073b22edfc87b2537166e8d5a8
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _THREAD_DBP_H
21 #define _THREAD_DBP_H 1
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" /* This is for *_BITMASK only. */
33 /* Indeces for the symbol names. */
34 enum
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
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,
54 SYM_NUM_MESSAGES
58 /* Comment out the following for less verbose output. */
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
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];
76 /* Handle for a process. This type is opaque. */
77 struct td_thragent
79 /* Chain on the list of all agent structures. */
80 list_t list;
82 /* Delivered by the debugger and we have to pass it back in the
83 proc callbacks. */
84 struct ps_prochandle *ph;
86 /* Cached values read from the inferior. */
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
105 /* The method of locating a thread's th_unique value. */
106 enum
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
115 uint32_t const_thread_area; /* Constant argument to ps_get_thread_area. */
116 /* These are as if the descriptor of the field in prregset_t,
117 but DB_DESC_NELEM is overloaded as follows: */
118 db_desc_t reg; /* Signed bias applied to register value. */
119 db_desc_t reg_thread_area; /* Bits to scale down register value. */
120 } ta_howto_data;
124 /* List of all known descriptors. */
125 extern list_t __td_agent_list attribute_hidden;
128 /* Function used to test for correct thread agent pointer. */
129 static inline bool
130 ta_ok (const td_thragent_t *ta)
132 list_t *runp;
134 list_for_each (runp, &__td_agent_list)
135 if (list_entry (runp, td_thragent_t, list) == ta)
136 return true;
138 return false;
142 /* Internal wrapper around ps_pglobal_lookup. */
143 extern ps_err_e td_lookup (struct ps_prochandle *ps,
144 int idx, psaddr_t *sym_addr) attribute_hidden;
149 /* Store in psaddr_t VAR the address of inferior's symbol NAME. */
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))
155 /* Store in psaddr_t VAR the value of ((TYPE) PTR)->FIELD[IDX] in the inferior.
156 A target field smaller than psaddr_t is zero-extended. */
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))
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)))
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;
173 /* Like DB_GET_FIELD, but PTR is a local pointer to a structure that
174 has already been copied in from the inferior. */
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))
180 /* Store in psaddr_t VAR the value of variable NAME[IDX] in the inferior.
181 A target value smaller than psaddr_t is zero-extended. */
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)))
189 /* Helper functions for those. */
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;
200 /* Store psaddr_t VALUE in ((TYPE) PTR)->FIELD[IDX] in the inferior.
201 A target field smaller than psaddr_t is zero-extended. */
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))
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))
212 /* Store psaddr_t VALUE in variable NAME[IDX] in the inferior.
213 A target field smaller than psaddr_t is zero-extended. */
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)))
221 /* Helper functions for those. */
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;
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; \
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; \
251 extern td_err_e _td_check_sizeof (td_thragent_t *ta, uint32_t *sizep,
252 int sizep_name) attribute_hidden;
254 extern td_err_e __td_ta_lookup_th_unique (const td_thragent_t *ta,
255 lwpid_t lwpid, td_thrhandle_t *th);
257 #endif /* thread_dbP.h */