1 #ifdef HAVE_THREAD_DB_H
4 #ifndef LIBTHREAD_DB_SO
5 #define LIBTHREAD_DB_SO "libthread_db.so.1"
8 #ifndef LIBTHREAD_DB_SEARCH_PATH
9 /* $sdir appears before $pdir for some minimal security protection:
10 we trust the system libthread_db.so a bit more than some random
11 libthread_db associated with whatever libpthread the app is using. */
12 #define LIBTHREAD_DB_SEARCH_PATH "$sdir:$pdir"
17 /* Copyright (C) 1999, 2000, 2007, 2008, 2009, 2010, 2011
18 Free Software Foundation, Inc.
19 This file is part of the GNU C Library.
21 The GNU C Library is free software; you can redistribute it and/or
22 modify it under the terms of the GNU Library General Public License as
23 published by the Free Software Foundation; either version 3 of the
24 License, or (at your option) any later version.
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Library General Public License for more details.
31 You should have received a copy of the GNU General Public License
32 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #define _THREAD_DB_H 1
37 /* This is the debugger interface for the LinuxThreads library. It is
38 modelled closely after the interface with same names in Solaris with
39 the goal to share the same code in the debugger. */
41 #include <sys/types.h>
42 #include <sys/procfs.h>
45 /* Error codes of the library. */
48 TD_OK
, /* No error. */
49 TD_ERR
, /* No further specified error. */
50 TD_NOTHR
, /* No matching thread found. */
51 TD_NOSV
, /* No matching synchronization handle found. */
52 TD_NOLWP
, /* No matching light-weighted process found. */
53 TD_BADPH
, /* Invalid process handle. */
54 TD_BADTH
, /* Invalid thread handle. */
55 TD_BADSH
, /* Invalid synchronization handle. */
56 TD_BADTA
, /* Invalid thread agent. */
57 TD_BADKEY
, /* Invalid key. */
58 TD_NOMSG
, /* No event available. */
59 TD_NOFPREGS
, /* No floating-point register content available. */
60 TD_NOLIBTHREAD
, /* Application not linked with thread library. */
61 TD_NOEVENT
, /* Requested event is not supported. */
62 TD_NOCAPAB
, /* Capability not available. */
63 TD_DBERR
, /* Internal debug library error. */
64 TD_NOAPLIC
, /* Operation is not applicable. */
65 TD_NOTSD
, /* No thread-specific data available. */
66 TD_MALLOC
, /* Out of memory. */
67 TD_PARTIALREG
, /* Not entire register set was read or written. */
68 TD_NOXREGS
, /* X register set not available for given thread. */
69 TD_NOTALLOC
/* TLS memory not yet allocated. */
73 /* Possible thread states. TD_THR_ANY_STATE is a pseudo-state used to
74 select threads regardless of state in td_ta_thr_iter(). */
87 /* Thread type: user or system. TD_THR_ANY_TYPE is a pseudo-type used
88 to select threads regardless of type in td_ta_thr_iter(). */
97 /* Types of the debugging library. */
99 /* Handle for a process. This type is opaque. */
100 typedef struct td_thragent td_thragent_t
;
102 /* The actual thread handle type. This is also opaque. */
103 typedef struct td_thrhandle
105 td_thragent_t
*th_ta_p
;
110 /* Flags for `td_ta_thr_iter'. */
111 #define TD_THR_ANY_USER_FLAGS 0xffffffff
112 #define TD_THR_LOWEST_PRIORITY -20
113 #define TD_SIGNO_MASK NULL
116 #define TD_EVENTSIZE 2
117 #define BT_UISHIFT 5 /* log base 2 of BT_NBIPUI, to
118 extract word index. */
119 #define BT_NBIPUI (1 << BT_UISHIFT) /* n bits per uint. */
120 #define BT_UIMASK (BT_NBIPUI - 1) /* to extract bit index. */
122 /* Bitmask of enabled events. */
123 typedef struct td_thr_events
125 uint32_t event_bits
[TD_EVENTSIZE
];
128 /* Event set manipulation macros. */
129 #define __td_eventmask(n) \
130 (UINT32_C (1) << (((n) - 1) & BT_UIMASK))
131 #define __td_eventword(n) \
132 ((UINT32_C ((n) - 1)) >> BT_UISHIFT)
134 #define td_event_emptyset(setp) \
137 for (__i = TD_EVENTSIZE; __i > 0; --__i) \
138 (setp)->event_bits[__i - 1] = 0; \
141 #define td_event_fillset(setp) \
144 for (__i = TD_EVENTSIZE; __i > 0; --__i) \
145 (setp)->event_bits[__i - 1] = UINT32_C (0xffffffff); \
148 #define td_event_addset(setp, n) \
149 (((setp)->event_bits[__td_eventword (n)]) |= __td_eventmask (n))
150 #define td_event_delset(setp, n) \
151 (((setp)->event_bits[__td_eventword (n)]) &= ~__td_eventmask (n))
152 #define td_eventismember(setp, n) \
153 (__td_eventmask (n) & ((setp)->event_bits[__td_eventword (n)]))
154 #if TD_EVENTSIZE == 2
155 # define td_eventisempty(setp) \
156 (!((setp)->event_bits[0]) && !((setp)->event_bits[1]))
158 # error "td_eventisempty must be changed to match TD_EVENTSIZE"
161 /* Events reportable by the thread implementation. */
164 TD_ALL_EVENTS
, /* Pseudo-event number. */
165 TD_EVENT_NONE
= TD_ALL_EVENTS
, /* Depends on context. */
166 TD_READY
, /* Is executable now. */
167 TD_SLEEP
, /* Blocked in a synchronization obj. */
168 TD_SWITCHTO
, /* Now assigned to a process. */
169 TD_SWITCHFROM
, /* Not anymore assigned to a process. */
170 TD_LOCK_TRY
, /* Trying to get an unavailable lock. */
171 TD_CATCHSIG
, /* Signal posted to the thread. */
172 TD_IDLE
, /* Process getting idle. */
173 TD_CREATE
, /* New thread created. */
174 TD_DEATH
, /* Thread terminated. */
175 TD_PREEMPT
, /* Preempted. */
176 TD_PRI_INHERIT
, /* Inherited elevated priority. */
177 TD_REAP
, /* Reaped. */
178 TD_CONCURRENCY
, /* Number of processes changing. */
179 TD_TIMEOUT
, /* Conditional variable wait timed out. */
180 TD_MIN_EVENT_NUM
= TD_READY
,
181 TD_MAX_EVENT_NUM
= TD_TIMEOUT
,
182 TD_EVENTS_ENABLE
= 31 /* Event reporting enabled. */
185 /* Values representing the different ways events are reported. */
188 NOTIFY_BPT
, /* User must insert breakpoint at
190 NOTIFY_AUTOBPT
, /* Breakpoint at u.bptaddr is automatically
192 NOTIFY_SYSCALL
/* System call u.syscallno will be invoked. */
195 /* Description how event type is reported. */
196 typedef struct td_notify
198 td_notify_e type
; /* Way the event is reported. */
201 psaddr_t bptaddr
; /* Address of breakpoint. */
202 int syscallno
; /* Number of system call used. */
206 /* Structure used to report event. */
207 typedef struct td_event_msg
209 td_event_e event
; /* Event type being reported. */
210 const td_thrhandle_t
*th_p
; /* Thread reporting the event. */
214 td_synchandle_t
*sh
; /* Handle of synchronization object. */
216 uintptr_t data
; /* Event specific data. */
220 /* Structure containing event data available in each thread structure. */
223 td_thr_events_t eventmask
; /* Mask of enabled events. */
224 td_event_e eventnum
; /* Number of last event. */
225 void *eventdata
; /* Data associated with event. */
229 /* Gathered statistics about the process. */
230 typedef struct td_ta_stats
232 int nthreads
; /* Total number of threads in use. */
233 int r_concurrency
; /* Concurrency level requested by user. */
234 int nrunnable_num
; /* Average runnable threads, numerator. */
235 int nrunnable_den
; /* Average runnable threads, denominator. */
236 int a_concurrency_num
; /* Achieved concurrency level, numerator. */
237 int a_concurrency_den
; /* Achieved concurrency level, denominator. */
238 int nlwps_num
; /* Average number of processes in use,
240 int nlwps_den
; /* Average number of processes in use,
242 int nidle_num
; /* Average number of idling processes,
244 int nidle_den
; /* Average number of idling processes,
249 /* Since Sun's library is based on Solaris threads we have to define a few
250 types to map them to POSIX threads. */
251 typedef pthread_t thread_t
;
252 typedef pthread_key_t thread_key_t
;
255 /* Callback for iteration over threads. */
256 typedef int td_thr_iter_f (const td_thrhandle_t
*, void *);
258 /* Callback for iteration over thread local data. */
259 typedef int td_key_iter_f (thread_key_t
, void (*) (void *), void *);
263 /* Forward declaration. This has to be defined by the user. */
264 struct ps_prochandle
;
267 /* Information about the thread. */
268 typedef struct td_thrinfo
270 td_thragent_t
*ti_ta_p
; /* Process handle. */
271 unsigned int ti_user_flags
; /* Unused. */
272 thread_t ti_tid
; /* Thread ID returned by
274 char *ti_tls
; /* Pointer to thread-local data. */
275 psaddr_t ti_startfunc
; /* Start function passed to
277 psaddr_t ti_stkbase
; /* Base of thread's stack. */
278 long int ti_stksize
; /* Size of thread's stack. */
279 psaddr_t ti_ro_area
; /* Unused. */
280 int ti_ro_size
; /* Unused. */
281 td_thr_state_e ti_state
; /* Thread state. */
282 unsigned char ti_db_suspended
; /* Nonzero if suspended by
284 td_thr_type_e ti_type
; /* Type of the thread (system vs
286 intptr_t ti_pc
; /* Unused. */
287 intptr_t ti_sp
; /* Unused. */
288 short int ti_flags
; /* Unused. */
289 int ti_pri
; /* Thread priority. */
290 lwpid_t ti_lid
; /* Kernel pid for this thread. */
291 sigset_t ti_sigmask
; /* Signal mask. */
292 unsigned char ti_traceme
; /* Nonzero if event reporting
294 unsigned char ti_preemptflag
; /* Unused. */
295 unsigned char ti_pirecflag
; /* Unused. */
296 sigset_t ti_pending
; /* Set of pending signals. */
297 td_thr_events_t ti_events
; /* Set of enabled events. */
302 /* Prototypes for exported library functions. */
304 /* Initialize the thread debug support library. */
305 extern td_err_e
td_init (void);
307 /* Historical relict. Should not be used anymore. */
308 extern td_err_e
td_log (void);
310 /* Generate new thread debug library handle for process PS. */
311 extern td_err_e
td_ta_new (struct ps_prochandle
*__ps
, td_thragent_t
**__ta
);
313 /* Free resources allocated for TA. */
314 extern td_err_e
td_ta_delete (td_thragent_t
*__ta
);
316 /* Get number of currently running threads in process associated with TA. */
317 extern td_err_e
td_ta_get_nthreads (const td_thragent_t
*__ta
, int *__np
);
319 /* Return process handle passed in `td_ta_new' for process associated with
321 extern td_err_e
td_ta_get_ph (const td_thragent_t
*__ta
,
322 struct ps_prochandle
**__ph
);
324 /* Map thread library handle PT to thread debug library handle for process
325 associated with TA and store result in *TH. */
326 extern td_err_e
td_ta_map_id2thr (const td_thragent_t
*__ta
, pthread_t __pt
,
327 td_thrhandle_t
*__th
);
329 /* Map process ID LWPID to thread debug library handle for process
330 associated with TA and store result in *TH. */
331 extern td_err_e
td_ta_map_lwp2thr (const td_thragent_t
*__ta
, lwpid_t __lwpid
,
332 td_thrhandle_t
*__th
);
335 /* Call for each thread in a process associated with TA the callback function
337 extern td_err_e
td_ta_thr_iter (const td_thragent_t
*__ta
,
338 td_thr_iter_f
*__callback
, void *__cbdata_p
,
339 td_thr_state_e __state
, int __ti_pri
,
340 sigset_t
*__ti_sigmask_p
,
341 unsigned int __ti_user_flags
);
343 /* Call for each defined thread local data entry the callback function KI. */
344 extern td_err_e
td_ta_tsd_iter (const td_thragent_t
*__ta
, td_key_iter_f
*__ki
,
348 /* Get event address for EVENT. */
349 extern td_err_e
td_ta_event_addr (const td_thragent_t
*__ta
,
350 td_event_e __event
, td_notify_t
*__ptr
);
352 /* Enable EVENT in global mask. */
353 extern td_err_e
td_ta_set_event (const td_thragent_t
*__ta
,
354 td_thr_events_t
*__event
);
356 /* Disable EVENT in global mask. */
357 extern td_err_e
td_ta_clear_event (const td_thragent_t
*__ta
,
358 td_thr_events_t
*__event
);
360 /* Return information about last event. */
361 extern td_err_e
td_ta_event_getmsg (const td_thragent_t
*__ta
,
362 td_event_msg_t
*msg
);
365 /* Set suggested concurrency level for process associated with TA. */
366 extern td_err_e
td_ta_setconcurrency (const td_thragent_t
*__ta
, int __level
);
369 /* Enable collecting statistics for process associated with TA. */
370 extern td_err_e
td_ta_enable_stats (const td_thragent_t
*__ta
, int __enable
);
372 /* Reset statistics. */
373 extern td_err_e
td_ta_reset_stats (const td_thragent_t
*__ta
);
375 /* Retrieve statistics from process associated with TA. */
376 extern td_err_e
td_ta_get_stats (const td_thragent_t
*__ta
,
377 td_ta_stats_t
*__statsp
);
380 /* Validate that TH is a thread handle. */
381 extern td_err_e
td_thr_validate (const td_thrhandle_t
*__th
);
383 /* Return information about thread TH. */
384 extern td_err_e
td_thr_get_info (const td_thrhandle_t
*__th
,
385 td_thrinfo_t
*__infop
);
387 /* Retrieve floating-point register contents of process running thread TH. */
388 extern td_err_e
td_thr_getfpregs (const td_thrhandle_t
*__th
,
389 prfpregset_t
*__regset
);
391 /* Retrieve general register contents of process running thread TH. */
392 extern td_err_e
td_thr_getgregs (const td_thrhandle_t
*__th
,
393 prgregset_t __gregs
);
395 /* Retrieve extended register contents of process running thread TH. */
396 extern td_err_e
td_thr_getxregs (const td_thrhandle_t
*__th
, void *__xregs
);
398 /* Get size of extended register set of process running thread TH. */
399 extern td_err_e
td_thr_getxregsize (const td_thrhandle_t
*__th
, int *__sizep
);
401 /* Set floating-point register contents of process running thread TH. */
402 extern td_err_e
td_thr_setfpregs (const td_thrhandle_t
*__th
,
403 const prfpregset_t
*__fpregs
);
405 /* Set general register contents of process running thread TH. */
406 extern td_err_e
td_thr_setgregs (const td_thrhandle_t
*__th
,
407 prgregset_t __gregs
);
409 /* Set extended register contents of process running thread TH. */
410 extern td_err_e
td_thr_setxregs (const td_thrhandle_t
*__th
,
414 /* Enable reporting for EVENT for thread TH. */
415 extern td_err_e
td_thr_event_enable (const td_thrhandle_t
*__th
, int __event
);
417 /* Enable EVENT for thread TH. */
418 extern td_err_e
td_thr_set_event (const td_thrhandle_t
*__th
,
419 td_thr_events_t
*__event
);
421 /* Disable EVENT for thread TH. */
422 extern td_err_e
td_thr_clear_event (const td_thrhandle_t
*__th
,
423 td_thr_events_t
*__event
);
425 /* Get event message for thread TH. */
426 extern td_err_e
td_thr_event_getmsg (const td_thrhandle_t
*__th
,
427 td_event_msg_t
*__msg
);
430 /* Set priority of thread TH. */
431 extern td_err_e
td_thr_setprio (const td_thrhandle_t
*__th
, int __prio
);
434 /* Set pending signals for thread TH. */
435 extern td_err_e
td_thr_setsigpending (const td_thrhandle_t
*__th
,
436 unsigned char __n
, const sigset_t
*__ss
);
438 /* Set signal mask for thread TH. */
439 extern td_err_e
td_thr_sigsetmask (const td_thrhandle_t
*__th
,
440 const sigset_t
*__ss
);
443 /* Return thread local data associated with key TK in thread TH. */
444 extern td_err_e
td_thr_tsd (const td_thrhandle_t
*__th
,
445 const thread_key_t __tk
, void **__data
);
448 /* Suspend execution of thread TH. */
449 extern td_err_e
td_thr_dbsuspend (const td_thrhandle_t
*__th
);
451 /* Resume execution of thread TH. */
452 extern td_err_e
td_thr_dbresume (const td_thrhandle_t
*__th
);
454 #endif /* thread_db.h */
456 #endif /* HAVE_THREAD_DB_H */