]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl_db/thread_dbP.h
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / nptl_db / thread_dbP.h
CommitLineData
7f08f55a 1/* Private header for thread debug library
d4697bc9 2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
7f08f55a
RM
3 This file is part of the GNU C Library.
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
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
7f08f55a 18
76a50749
UD
19#ifndef _THREAD_DBP_H
20#define _THREAD_DBP_H 1
21
22#include <stdbool.h>
7f08f55a 23#include <stdint.h>
76a50749 24#include <string.h>
7f08f55a 25#include <stdlib.h>
76a50749 26#include <unistd.h>
7f08f55a 27#include <assert.h>
76a50749
UD
28#include "proc_service.h"
29#include "thread_db.h"
7f08f55a 30#include "../nptl/pthreadP.h" /* This is for *_BITMASK only. */
7a775e6b 31#include <list.h>
76a50749
UD
32
33/* Indeces for the symbol names. */
34enum
35 {
7f08f55a
RM
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,
d43147cd 39# define DB_FUNCTION(name) SYM_##name,
7f08f55a
RM
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
d43147cd 45# undef DB_FUNCTION
7f08f55a
RM
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
76a50749
UD
54 SYM_NUM_MESSAGES
55 };
56
57
58/* Comment out the following for less verbose output. */
59#ifndef NDEBUG
5ce98c3f 60# define LOG(c) if (__td_debug) write (2, c "\n", strlen (c "\n"))
7f08f55a 61extern int __td_debug attribute_hidden;
76a50749
UD
62#else
63# define LOG(c)
64#endif
65
66
7f08f55a
RM
67#define DB_DESC_SIZE(desc) ((desc)[0])
68#define DB_DESC_NELEM(desc) ((desc)[1])
db2f05ba 69#define DB_DESC_OFFSET(desc) ((desc)[2])
7f08f55a
RM
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) }
73typedef uint32_t db_desc_t[3];
74
75
76a50749
UD
76/* Handle for a process. This type is opaque. */
77struct td_thragent
78{
7f08f55a
RM
79 /* Chain on the list of all agent structures. */
80 list_t list;
81
76a50749
UD
82 /* Delivered by the debugger and we have to pass it back in the
83 proc callbacks. */
84 struct ps_prochandle *ph;
85
7f08f55a
RM
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;
d43147cd
RM
93# define DB_FUNCTION(name) \
94 psaddr_t ta_addr_##name;
7f08f55a
RM
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
d43147cd 101# undef DB_FUNCTION
7f08f55a
RM
102# undef DB_SYMBOL
103# undef DB_VARIABLE
104
105 /* The method of locating a thread's th_unique value. */
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; /* 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;
76a50749
UD
121};
122
123
124/* List of all known descriptors. */
7f08f55a 125extern list_t __td_agent_list attribute_hidden;
76a50749
UD
126
127
128/* Function used to test for correct thread agent pointer. */
129static inline bool
130ta_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/* Internal wrapper around ps_pglobal_lookup. */
7f08f55a
RM
143extern ps_err_e td_lookup (struct ps_prochandle *ps,
144 int idx, psaddr_t *sym_addr) attribute_hidden;
145
146
147
148
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))
154
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))
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
167extern 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/* 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))
179
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)))
188
189/* Helper functions for those. */
190extern 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;
194extern 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/* 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))
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/* 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)))
220
221/* Helper functions for those. */
222extern 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;
226extern 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
251extern td_err_e _td_check_sizeof (td_thragent_t *ta, uint32_t *sizep,
252 int sizep_name) attribute_hidden;
76a50749 253
7d9d8bd1
RM
254extern td_err_e __td_ta_lookup_th_unique (const td_thragent_t *ta,
255 lwpid_t lwpid, td_thrhandle_t *th);
256
76a50749 257#endif /* thread_dbP.h */