2003-01-31 Frank Ch. Eigler <fche@redhat.com>
[deliverable/binutils-gdb.git] / gdb / gdb_thread_db.h
CommitLineData
574dd9a9
MK
1#ifdef HAVE_THREAD_DB_H
2#include <thread_db.h>
3#else
4
5#ifdef HAVE_STDINT_H
6#include <stdint.h>
7typedef uint32_t gdb_uint32_t;
8#define GDB_UINT32_C(c) UINT32_C(c)
9#else
10typedef unsigned int gdb_uint32_t;
11#define GDB_UINT32_C(c) c ## U
12#endif
13
b6ba6518 14/* Copyright 1999, 2000 Free Software Foundation, Inc.
ed9a39eb
JM
15 This file is part of the GNU C Library.
16
17 The GNU C Library is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Library General Public License as
19 published by the Free Software Foundation; either version 2 of the
20 License, or (at your option) any later version.
21
22 The GNU C Library is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 Library General Public License for more details.
26
27 You should have received a copy of the GNU Library General Public
28 License along with the GNU C Library; see the file COPYING.LIB. If not,
29 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. */
31
32#ifndef _THREAD_DB_H
33#define _THREAD_DB_H 1
34
35/* This is the debugger interface for the LinuxThreads library. It is
36 modelled closely after the interface with same names in Solaris with
37 the goal to share the same code in the debugger. */
38#include <pthread.h>
ed9a39eb 39#include <sys/types.h>
574dd9a9 40#include <sys/procfs.h>
ed9a39eb
JM
41
42
43/* Error codes of the library. */
44typedef enum
45{
574dd9a9
MK
46 TD_OK, /* No error. */
47 TD_ERR, /* No further specified error. */
48 TD_NOTHR, /* No matching thread found. */
49 TD_NOSV, /* No matching synchronization handle found. */
50 TD_NOLWP, /* No matching light-weighted process found. */
51 TD_BADPH, /* Invalid process handle. */
52 TD_BADTH, /* Invalid thread handle. */
53 TD_BADSH, /* Invalid synchronization handle. */
54 TD_BADTA, /* Invalid thread agent. */
55 TD_BADKEY, /* Invalid key. */
56 TD_NOMSG, /* No event available. */
57 TD_NOFPREGS, /* No floating-point register content available. */
58 TD_NOLIBTHREAD, /* Application not linked with thread library. */
59 TD_NOEVENT, /* Requested event is not supported. */
60 TD_NOCAPAB, /* Capability not available. */
61 TD_DBERR, /* Internal debug library error. */
62 TD_NOAPLIC, /* Operation is not applicable. */
63 TD_NOTSD, /* No thread-specific data available. */
64 TD_MALLOC, /* Out of memory. */
65 TD_PARTIALREG, /* Not entire register set was read or written. */
3f47be5c
EZ
66 TD_NOXREGS, /* X register set not available for given thread. */
67 TD_NOTALLOC /* TLS memory not yet allocated. */
ed9a39eb
JM
68} td_err_e;
69
70
71/* Possible thread states. TD_THR_ANY_STATE is a pseudo-state used to
72 select threads regardless of state in td_ta_thr_iter(). */
73typedef enum
74{
75 TD_THR_ANY_STATE,
76 TD_THR_UNKNOWN,
77 TD_THR_STOPPED,
78 TD_THR_RUN,
79 TD_THR_ACTIVE,
80 TD_THR_ZOMBIE,
81 TD_THR_SLEEP,
82 TD_THR_STOPPED_ASLEEP
83} td_thr_state_e;
84
85/* Thread type: user or system. TD_THR_ANY_TYPE is a pseudo-type used
86 to select threads regardless of type in td_ta_thr_iter(). */
87typedef enum
88{
89 TD_THR_ANY_TYPE,
90 TD_THR_USER,
91 TD_THR_SYSTEM
92} td_thr_type_e;
93
94
95/* Types of the debugging library. */
96
ed9a39eb
JM
97/* Handle for a process. This type is opaque. */
98typedef struct td_thragent td_thragent_t;
99
100/* The actual thread handle type. This is also opaque. */
101typedef struct td_thrhandle
102{
103 td_thragent_t *th_ta_p;
104 psaddr_t th_unique;
105} td_thrhandle_t;
106
107
108/* Flags for `td_ta_thr_iter'. */
109#define TD_THR_ANY_USER_FLAGS 0xffffffff
110#define TD_THR_LOWEST_PRIORITY -20
111#define TD_SIGNO_MASK NULL
112
113
114#define TD_EVENTSIZE 2
115#define BT_UISHIFT 5 /* log base 2 of BT_NBIPUI, to extract word index */
116#define BT_NBIPUI (1 << BT_UISHIFT) /* n bits per uint */
117#define BT_UIMASK (BT_NBIPUI - 1) /* to extract bit index */
118
119/* Bitmask of enabled events. */
120typedef struct td_thr_events
121{
574dd9a9 122 gdb_uint32_t event_bits[TD_EVENTSIZE];
ed9a39eb
JM
123} td_thr_events_t;
124
125/* Event set manipulation macros. */
126#define __td_eventmask(n) \
574dd9a9 127 (GDB_UINT32_C (1) << (((n) - 1) & BT_UIMASK))
ed9a39eb 128#define __td_eventword(n) \
574dd9a9 129 ((GDB_UINT32_C ((n) - 1)) >> BT_UISHIFT)
ed9a39eb
JM
130
131#define td_event_emptyset(setp) \
132 do { \
133 int __i; \
134 for (__i = TD_EVENTSIZE; __i > 0; --__i) \
135 (setp)->event_bits[__i - 1] = 0; \
136 } while (0)
137
138#define td_event_fillset(setp) \
139 do { \
140 int __i; \
141 for (__i = TD_EVENTSIZE; __i > 0; --__i) \
574dd9a9 142 (setp)->event_bits[__i - 1] = GDB_UINT32_C (0xffffffff); \
ed9a39eb
JM
143 } while (0)
144
145#define td_event_addset(setp, n) \
146 (((setp)->event_bits[__td_eventword (n)]) |= __td_eventmask (n))
147#define td_event_delset(setp, n) \
148 (((setp)->event_bits[__td_eventword (n)]) &= ~__td_eventmask (n))
149#define td_eventismember(setp, n) \
150 (__td_eventmask (n) & ((setp)->event_bits[__td_eventword (n)]))
151#if TD_EVENTSIZE == 2
152# define td_eventisempty(setp) \
153 (!((setp)->event_bits[0]) && !((setp)->event_bits[1]))
154#else
155# error "td_eventisempty must be changed to match TD_EVENTSIZE"
156#endif
157
158/* Events reportable by the thread implementation. */
159typedef enum
160{
161 TD_ALL_EVENTS, /* Pseudo-event number. */
162 TD_EVENT_NONE = TD_ALL_EVENTS, /* Depends on context. */
163 TD_READY, /* Is executable now. */
164 TD_SLEEP, /* Blocked in a synchronization obj. */
165 TD_SWITCHTO, /* Now assigned to a process. */
166 TD_SWITCHFROM, /* Not anymore assigned to a process. */
167 TD_LOCK_TRY, /* Trying to get an unavailable lock. */
168 TD_CATCHSIG, /* Signal posted to the thread. */
169 TD_IDLE, /* Process getting idle. */
170 TD_CREATE, /* New thread created. */
171 TD_DEATH, /* Thread terminated. */
172 TD_PREEMPT, /* Preempted. */
173 TD_PRI_INHERIT, /* Inherited elevated priority. */
174 TD_REAP, /* Reaped. */
175 TD_CONCURRENCY, /* Number of processes changing. */
176 TD_TIMEOUT, /* Conditional variable wait timed out. */
177 TD_MIN_EVENT_NUM = TD_READY,
178 TD_MAX_EVENT_NUM = TD_TIMEOUT,
179 TD_EVENTS_ENABLE = 31 /* Event reporting enabled. */
180} td_event_e;
181
182/* Values representing the different ways events are reported. */
183typedef enum
184{
185 NOTIFY_BPT, /* User must insert breakpoint at u.bptaddr. */
186 NOTIFY_AUTOBPT, /* Breakpoint at u.bptaddr is automatically
187 inserted. */
188 NOTIFY_SYSCALL /* System call u.syscallno will be invoked. */
189} td_notify_e;
190
191/* Description how event type is reported. */
192typedef struct td_notify
193{
194 td_notify_e type; /* Way the event is reported. */
195 union
196 {
197 psaddr_t bptaddr; /* Address of breakpoint. */
198 int syscallno; /* Number of system call used. */
199 } u;
200} td_notify_t;
201
202/* Structure used to report event. */
203typedef struct td_event_msg
204{
205 td_event_e event; /* Event type being reported. */
206 const td_thrhandle_t *th_p; /* Thread reporting the event. */
207 union
208 {
574dd9a9 209#if 0
ed9a39eb
JM
210 td_synchandle_t *sh; /* Handle of synchronization object. */
211#endif
212 uintptr_t data; /* Event specific data. */
213 } msg;
214} td_event_msg_t;
215
574dd9a9
MK
216/* Structure containing event data available in each thread structure. */
217typedef struct
218{
219 td_thr_events_t eventmask; /* Mask of enabled events. */
220 td_event_e eventnum; /* Number of last event. */
221 void *eventdata; /* Data associated with event. */
222} td_eventbuf_t;
223
ed9a39eb
JM
224
225/* Gathered statistics about the process. */
226typedef struct td_ta_stats
227{
228 int nthreads; /* Total number of threads in use. */
229 int r_concurrency; /* Concurrency level requested by user. */
230 int nrunnable_num; /* Average runnable threads, numerator. */
231 int nrunnable_den; /* Average runnable threads, denominator. */
232 int a_concurrency_num; /* Achieved concurrency level, numerator. */
233 int a_concurrency_den; /* Achieved concurrency level, denominator. */
234 int nlwps_num; /* Average number of processes in use,
235 numerator. */
236 int nlwps_den; /* Average number of processes in use,
237 denominator. */
238 int nidle_num; /* Average number of idling processes,
239 numerator. */
240 int nidle_den; /* Average number of idling processes,
241 denominator. */
242} td_ta_stats_t;
243
244
245/* Since Sun's library is based on Solaris threads we have to define a few
246 types to map them to POSIX threads. */
247typedef pthread_t thread_t;
248typedef pthread_key_t thread_key_t;
249
ed9a39eb
JM
250
251/* Callback for iteration over threads. */
574dd9a9 252typedef int td_thr_iter_f (const td_thrhandle_t *, void *);
ed9a39eb
JM
253
254/* Callback for iteration over thread local data. */
574dd9a9 255typedef int td_key_iter_f (thread_key_t, void (*) (void *), void *);
ed9a39eb
JM
256
257
258
259/* Forward declaration. This has to be defined by the user. */
260struct ps_prochandle;
261
ed9a39eb
JM
262
263/* Information about the thread. */
264typedef struct td_thrinfo
265{
266 td_thragent_t *ti_ta_p; /* Process handle. */
267 unsigned int ti_user_flags; /* Unused. */
268 thread_t ti_tid; /* Thread ID returned by
269 pthread_create(). */
270 char *ti_tls; /* Pointer to thread-local data. */
271 psaddr_t ti_startfunc; /* Start function passed to
272 pthread_create(). */
273 psaddr_t ti_stkbase; /* Base of thread's stack. */
274 long int ti_stksize; /* Size of thread's stack. */
275 psaddr_t ti_ro_area; /* Unused. */
276 int ti_ro_size; /* Unused. */
277 td_thr_state_e ti_state; /* Thread state. */
278 unsigned char ti_db_suspended; /* Nonzero if suspended by debugger. */
279 td_thr_type_e ti_type; /* Type of the thread (system vs
280 user thread). */
281 intptr_t ti_pc; /* Unused. */
282 intptr_t ti_sp; /* Unused. */
283 short int ti_flags; /* Unused. */
284 int ti_pri; /* Thread priority. */
285 lwpid_t ti_lid; /* Unused. */
286 sigset_t ti_sigmask; /* Signal mask. */
287 unsigned char ti_traceme; /* Nonzero if event reporting
288 enabled. */
289 unsigned char ti_preemptflag; /* Unused. */
290 unsigned char ti_pirecflag; /* Unused. */
291 sigset_t ti_pending; /* Set of pending signals. */
292 td_thr_events_t ti_events; /* Set of enabled events. */
293} td_thrinfo_t;
294
295
296
297/* Prototypes for exported library functions. */
298
299/* Initialize the thread debug support library. */
300extern td_err_e td_init (void);
301
302/* Historical relict. Should not be used anymore. */
303extern td_err_e td_log (void);
304
305/* Generate new thread debug library handle for process PS. */
306extern td_err_e td_ta_new (struct ps_prochandle *__ps, td_thragent_t **__ta);
307
308/* Free resources allocated for TA. */
309extern td_err_e td_ta_delete (td_thragent_t *__ta);
310
311/* Get number of currently running threads in process associated with TA. */
312extern td_err_e td_ta_get_nthreads (const td_thragent_t *__ta, int *__np);
313
314/* Return process handle passed in `td_ta_new' for process associated with
315 TA. */
316extern td_err_e td_ta_get_ph (const td_thragent_t *__ta,
317 struct ps_prochandle **__ph);
318
319/* Map thread library handle PT to thread debug library handle for process
320 associated with TA and store result in *TH. */
321extern td_err_e td_ta_map_id2thr (const td_thragent_t *__ta, pthread_t __pt,
322 td_thrhandle_t *__th);
323
324/* Map process ID LWPID to thread debug library handle for process
325 associated with TA and store result in *TH. */
326extern td_err_e td_ta_map_lwp2thr (const td_thragent_t *__ta, lwpid_t __lwpid,
327 td_thrhandle_t *__th);
328
329
330/* Call for each thread in a process associated with TA the callback function
331 CALLBACK. */
332extern td_err_e td_ta_thr_iter (const td_thragent_t *__ta,
333 td_thr_iter_f *__callback, void *__cbdata_p,
334 td_thr_state_e __state, int __ti_pri,
335 sigset_t *__ti_sigmask_p,
336 unsigned int __ti_user_flags);
337
338/* Call for each defined thread local data entry the callback function KI. */
339extern td_err_e td_ta_tsd_iter (const td_thragent_t *__ta, td_key_iter_f *__ki,
340 void *__p);
341
342
343/* Get event address for EVENT. */
344extern td_err_e td_ta_event_addr (const td_thragent_t *__ta,
345 td_event_e __event, td_notify_t *__ptr);
346
574dd9a9
MK
347/* Enable EVENT in global mask. */
348extern td_err_e td_ta_set_event (const td_thragent_t *__ta,
349 td_thr_events_t *__event);
350
351/* Disable EVENT in global mask. */
352extern td_err_e td_ta_clear_event (const td_thragent_t *__ta,
353 td_thr_events_t *__event);
354
355/* Return information about last event. */
356extern td_err_e td_ta_event_getmsg (const td_thragent_t *__ta,
357 td_event_msg_t *msg);
358
ed9a39eb
JM
359
360/* Set suggested concurrency level for process associated with TA. */
361extern td_err_e td_ta_setconcurrency (const td_thragent_t *__ta, int __level);
362
363
364/* Enable collecting statistics for process associated with TA. */
365extern td_err_e td_ta_enable_stats (const td_thragent_t *__ta, int __enable);
366
367/* Reset statistics. */
368extern td_err_e td_ta_reset_stats (const td_thragent_t *__ta);
369
370/* Retrieve statistics from process associated with TA. */
371extern td_err_e td_ta_get_stats (const td_thragent_t *__ta,
372 td_ta_stats_t *__statsp);
373
374
375/* Validate that TH is a thread handle. */
376extern td_err_e td_thr_validate (const td_thrhandle_t *__th);
377
378/* Return information about thread TH. */
379extern td_err_e td_thr_get_info (const td_thrhandle_t *__th,
380 td_thrinfo_t *__infop);
381
382/* Retrieve floating-point register contents of process running thread TH. */
383extern td_err_e td_thr_getfpregs (const td_thrhandle_t *__th,
384 prfpregset_t *__regset);
385
386/* Retrieve general register contents of process running thread TH. */
387extern td_err_e td_thr_getgregs (const td_thrhandle_t *__th,
388 prgregset_t __gregs);
389
390/* Retrieve extended register contents of process running thread TH. */
391extern td_err_e td_thr_getxregs (const td_thrhandle_t *__th, void *__xregs);
392
393/* Get size of extended register set of process running thread TH. */
394extern td_err_e td_thr_getxregsize (const td_thrhandle_t *__th, int *__sizep);
395
396/* Set floating-point register contents of process running thread TH. */
397extern td_err_e td_thr_setfpregs (const td_thrhandle_t *__th,
398 const prfpregset_t *__fpregs);
399
400/* Set general register contents of process running thread TH. */
401extern td_err_e td_thr_setgregs (const td_thrhandle_t *__th,
402 prgregset_t __gregs);
403
404/* Set extended register contents of process running thread TH. */
405extern td_err_e td_thr_setxregs (const td_thrhandle_t *__th,
406 const void *__addr);
407
408
409/* Enable reporting for EVENT for thread TH. */
410extern td_err_e td_thr_event_enable (const td_thrhandle_t *__th, int __event);
411
412/* Enable EVENT for thread TH. */
413extern td_err_e td_thr_set_event (const td_thrhandle_t *__th,
414 td_thr_events_t *__event);
415
416/* Disable EVENT for thread TH. */
417extern td_err_e td_thr_clear_event (const td_thrhandle_t *__th,
418 td_thr_events_t *__event);
419
420/* Get event message for thread TH. */
421extern td_err_e td_thr_event_getmsg (const td_thrhandle_t *__th,
422 td_event_msg_t *__msg);
423
424
425/* Set priority of thread TH. */
426extern td_err_e td_thr_setprio (const td_thrhandle_t *__th, int __prio);
427
428
429/* Set pending signals for thread TH. */
430extern td_err_e td_thr_setsigpending (const td_thrhandle_t *__th,
431 unsigned char __n, const sigset_t *__ss);
432
433/* Set signal mask for thread TH. */
434extern td_err_e td_thr_sigsetmask (const td_thrhandle_t *__th,
435 const sigset_t *__ss);
436
437
438/* Return thread local data associated with key TK in thread TH. */
439extern td_err_e td_thr_tsd (const td_thrhandle_t *__th,
440 const thread_key_t __tk, void **__data);
441
442
443/* Suspend execution of thread TH. */
444extern td_err_e td_thr_dbsuspend (const td_thrhandle_t *__th);
445
446/* Resume execution of thread TH. */
447extern td_err_e td_thr_dbresume (const td_thrhandle_t *__th);
448
449#endif /* thread_db.h */
574dd9a9
MK
450
451#endif /* HAVE_THREAD_DB_H */
This page took 0.235223 seconds and 4 git commands to generate.