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 #define LIBTHREAD_DB_SEARCH_PATH ""
14 /* Copyright (C) 1999, 2000, 2007, 2008, 2009 Free Software Foundation, Inc.
15 This file is part of the GNU C Library.
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 3 of the
20 License, or (at your option) any later version.
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.
27 You should have received a copy of the GNU General Public License
28 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 #define _THREAD_DB_H 1
33 /* This is the debugger interface for the LinuxThreads library. It is
34 modelled closely after the interface with same names in Solaris with
35 the goal to share the same code in the debugger. */
37 #include <sys/types.h>
38 #include <sys/procfs.h>
41 /* Error codes of the library. */
44 TD_OK
, /* No error. */
45 TD_ERR
, /* No further specified error. */
46 TD_NOTHR
, /* No matching thread found. */
47 TD_NOSV
, /* No matching synchronization handle found. */
48 TD_NOLWP
, /* No matching light-weighted process found. */
49 TD_BADPH
, /* Invalid process handle. */
50 TD_BADTH
, /* Invalid thread handle. */
51 TD_BADSH
, /* Invalid synchronization handle. */
52 TD_BADTA
, /* Invalid thread agent. */
53 TD_BADKEY
, /* Invalid key. */
54 TD_NOMSG
, /* No event available. */
55 TD_NOFPREGS
, /* No floating-point register content available. */
56 TD_NOLIBTHREAD
, /* Application not linked with thread library. */
57 TD_NOEVENT
, /* Requested event is not supported. */
58 TD_NOCAPAB
, /* Capability not available. */
59 TD_DBERR
, /* Internal debug library error. */
60 TD_NOAPLIC
, /* Operation is not applicable. */
61 TD_NOTSD
, /* No thread-specific data available. */
62 TD_MALLOC
, /* Out of memory. */
63 TD_PARTIALREG
, /* Not entire register set was read or written. */
64 TD_NOXREGS
, /* X register set not available for given thread. */
65 TD_NOTALLOC
/* TLS memory not yet allocated. */
69 /* Possible thread states. TD_THR_ANY_STATE is a pseudo-state used to
70 select threads regardless of state in td_ta_thr_iter(). */
83 /* Thread type: user or system. TD_THR_ANY_TYPE is a pseudo-type used
84 to select threads regardless of type in td_ta_thr_iter(). */
93 /* Types of the debugging library. */
95 /* Handle for a process. This type is opaque. */
96 typedef struct td_thragent td_thragent_t
;
98 /* The actual thread handle type. This is also opaque. */
99 typedef struct td_thrhandle
101 td_thragent_t
*th_ta_p
;
106 /* Flags for `td_ta_thr_iter'. */
107 #define TD_THR_ANY_USER_FLAGS 0xffffffff
108 #define TD_THR_LOWEST_PRIORITY -20
109 #define TD_SIGNO_MASK NULL
112 #define TD_EVENTSIZE 2
113 #define BT_UISHIFT 5 /* log base 2 of BT_NBIPUI, to extract word index */
114 #define BT_NBIPUI (1 << BT_UISHIFT) /* n bits per uint */
115 #define BT_UIMASK (BT_NBIPUI - 1) /* to extract bit index */
117 /* Bitmask of enabled events. */
118 typedef struct td_thr_events
120 uint32_t event_bits
[TD_EVENTSIZE
];
123 /* Event set manipulation macros. */
124 #define __td_eventmask(n) \
125 (UINT32_C (1) << (((n) - 1) & BT_UIMASK))
126 #define __td_eventword(n) \
127 ((UINT32_C ((n) - 1)) >> BT_UISHIFT)
129 #define td_event_emptyset(setp) \
132 for (__i = TD_EVENTSIZE; __i > 0; --__i) \
133 (setp)->event_bits[__i - 1] = 0; \
136 #define td_event_fillset(setp) \
139 for (__i = TD_EVENTSIZE; __i > 0; --__i) \
140 (setp)->event_bits[__i - 1] = UINT32_C (0xffffffff); \
143 #define td_event_addset(setp, n) \
144 (((setp)->event_bits[__td_eventword (n)]) |= __td_eventmask (n))
145 #define td_event_delset(setp, n) \
146 (((setp)->event_bits[__td_eventword (n)]) &= ~__td_eventmask (n))
147 #define td_eventismember(setp, n) \
148 (__td_eventmask (n) & ((setp)->event_bits[__td_eventword (n)]))
149 #if TD_EVENTSIZE == 2
150 # define td_eventisempty(setp) \
151 (!((setp)->event_bits[0]) && !((setp)->event_bits[1]))
153 # error "td_eventisempty must be changed to match TD_EVENTSIZE"
156 /* Events reportable by the thread implementation. */
159 TD_ALL_EVENTS
, /* Pseudo-event number. */
160 TD_EVENT_NONE
= TD_ALL_EVENTS
, /* Depends on context. */
161 TD_READY
, /* Is executable now. */
162 TD_SLEEP
, /* Blocked in a synchronization obj. */
163 TD_SWITCHTO
, /* Now assigned to a process. */
164 TD_SWITCHFROM
, /* Not anymore assigned to a process. */
165 TD_LOCK_TRY
, /* Trying to get an unavailable lock. */
166 TD_CATCHSIG
, /* Signal posted to the thread. */
167 TD_IDLE
, /* Process getting idle. */
168 TD_CREATE
, /* New thread created. */
169 TD_DEATH
, /* Thread terminated. */
170 TD_PREEMPT
, /* Preempted. */
171 TD_PRI_INHERIT
, /* Inherited elevated priority. */
172 TD_REAP
, /* Reaped. */
173 TD_CONCURRENCY
, /* Number of processes changing. */
174 TD_TIMEOUT
, /* Conditional variable wait timed out. */
175 TD_MIN_EVENT_NUM
= TD_READY
,
176 TD_MAX_EVENT_NUM
= TD_TIMEOUT
,
177 TD_EVENTS_ENABLE
= 31 /* Event reporting enabled. */
180 /* Values representing the different ways events are reported. */
183 NOTIFY_BPT
, /* User must insert breakpoint at u.bptaddr. */
184 NOTIFY_AUTOBPT
, /* Breakpoint at u.bptaddr is automatically
186 NOTIFY_SYSCALL
/* System call u.syscallno will be invoked. */
189 /* Description how event type is reported. */
190 typedef struct td_notify
192 td_notify_e type
; /* Way the event is reported. */
195 psaddr_t bptaddr
; /* Address of breakpoint. */
196 int syscallno
; /* Number of system call used. */
200 /* Some people still have libc5 or old glibc with no uintptr_t.
201 They lose. glibc 2.1.3 was released on 2000-02-25, and it has
202 uintptr_t, so it's reasonable to force these people to upgrade. */
204 #ifndef HAVE_UINTPTR_T
205 #error No uintptr_t available; your C library is too old.
206 /* Inhibit further compilation errors after this error. */
207 #define uintptr_t void *
210 /* Structure used to report event. */
211 typedef struct td_event_msg
213 td_event_e event
; /* Event type being reported. */
214 const td_thrhandle_t
*th_p
; /* Thread reporting the event. */
218 td_synchandle_t
*sh
; /* Handle of synchronization object. */
220 uintptr_t data
; /* Event specific data. */
224 /* Structure containing event data available in each thread structure. */
227 td_thr_events_t eventmask
; /* Mask of enabled events. */
228 td_event_e eventnum
; /* Number of last event. */
229 void *eventdata
; /* Data associated with event. */
233 /* Gathered statistics about the process. */
234 typedef struct td_ta_stats
236 int nthreads
; /* Total number of threads in use. */
237 int r_concurrency
; /* Concurrency level requested by user. */
238 int nrunnable_num
; /* Average runnable threads, numerator. */
239 int nrunnable_den
; /* Average runnable threads, denominator. */
240 int a_concurrency_num
; /* Achieved concurrency level, numerator. */
241 int a_concurrency_den
; /* Achieved concurrency level, denominator. */
242 int nlwps_num
; /* Average number of processes in use,
244 int nlwps_den
; /* Average number of processes in use,
246 int nidle_num
; /* Average number of idling processes,
248 int nidle_den
; /* Average number of idling processes,
253 /* Since Sun's library is based on Solaris threads we have to define a few
254 types to map them to POSIX threads. */
255 typedef pthread_t thread_t
;
256 typedef pthread_key_t thread_key_t
;
259 /* Callback for iteration over threads. */
260 typedef int td_thr_iter_f (const td_thrhandle_t
*, void *);
262 /* Callback for iteration over thread local data. */
263 typedef int td_key_iter_f (thread_key_t
, void (*) (void *), void *);
267 /* Forward declaration. This has to be defined by the user. */
268 struct ps_prochandle
;
271 /* Information about the thread. */
272 typedef struct td_thrinfo
274 td_thragent_t
*ti_ta_p
; /* Process handle. */
275 unsigned int ti_user_flags
; /* Unused. */
276 thread_t ti_tid
; /* Thread ID returned by
278 char *ti_tls
; /* Pointer to thread-local data. */
279 psaddr_t ti_startfunc
; /* Start function passed to
281 psaddr_t ti_stkbase
; /* Base of thread's stack. */
282 long int ti_stksize
; /* Size of thread's stack. */
283 psaddr_t ti_ro_area
; /* Unused. */
284 int ti_ro_size
; /* Unused. */
285 td_thr_state_e ti_state
; /* Thread state. */
286 unsigned char ti_db_suspended
; /* Nonzero if suspended by debugger. */
287 td_thr_type_e ti_type
; /* Type of the thread (system vs
289 intptr_t ti_pc
; /* Unused. */
290 intptr_t ti_sp
; /* Unused. */
291 short int ti_flags
; /* Unused. */
292 int ti_pri
; /* Thread priority. */
293 lwpid_t ti_lid
; /* Kernel pid for this thread. */
294 sigset_t ti_sigmask
; /* Signal mask. */
295 unsigned char ti_traceme
; /* Nonzero if event reporting
297 unsigned char ti_preemptflag
; /* Unused. */
298 unsigned char ti_pirecflag
; /* Unused. */
299 sigset_t ti_pending
; /* Set of pending signals. */
300 td_thr_events_t ti_events
; /* Set of enabled events. */
305 /* Prototypes for exported library functions. */
307 /* Initialize the thread debug support library. */
308 extern td_err_e
td_init (void);
310 /* Historical relict. Should not be used anymore. */
311 extern td_err_e
td_log (void);
313 /* Generate new thread debug library handle for process PS. */
314 extern td_err_e
td_ta_new (struct ps_prochandle
*__ps
, td_thragent_t
**__ta
);
316 /* Free resources allocated for TA. */
317 extern td_err_e
td_ta_delete (td_thragent_t
*__ta
);
319 /* Get number of currently running threads in process associated with TA. */
320 extern td_err_e
td_ta_get_nthreads (const td_thragent_t
*__ta
, int *__np
);
322 /* Return process handle passed in `td_ta_new' for process associated with
324 extern td_err_e
td_ta_get_ph (const td_thragent_t
*__ta
,
325 struct ps_prochandle
**__ph
);
327 /* Map thread library handle PT to thread debug library handle for process
328 associated with TA and store result in *TH. */
329 extern td_err_e
td_ta_map_id2thr (const td_thragent_t
*__ta
, pthread_t __pt
,
330 td_thrhandle_t
*__th
);
332 /* Map process ID LWPID to thread debug library handle for process
333 associated with TA and store result in *TH. */
334 extern td_err_e
td_ta_map_lwp2thr (const td_thragent_t
*__ta
, lwpid_t __lwpid
,
335 td_thrhandle_t
*__th
);
338 /* Call for each thread in a process associated with TA the callback function
340 extern td_err_e
td_ta_thr_iter (const td_thragent_t
*__ta
,
341 td_thr_iter_f
*__callback
, void *__cbdata_p
,
342 td_thr_state_e __state
, int __ti_pri
,
343 sigset_t
*__ti_sigmask_p
,
344 unsigned int __ti_user_flags
);
346 /* Call for each defined thread local data entry the callback function KI. */
347 extern td_err_e
td_ta_tsd_iter (const td_thragent_t
*__ta
, td_key_iter_f
*__ki
,
351 /* Get event address for EVENT. */
352 extern td_err_e
td_ta_event_addr (const td_thragent_t
*__ta
,
353 td_event_e __event
, td_notify_t
*__ptr
);
355 /* Enable EVENT in global mask. */
356 extern td_err_e
td_ta_set_event (const td_thragent_t
*__ta
,
357 td_thr_events_t
*__event
);
359 /* Disable EVENT in global mask. */
360 extern td_err_e
td_ta_clear_event (const td_thragent_t
*__ta
,
361 td_thr_events_t
*__event
);
363 /* Return information about last event. */
364 extern td_err_e
td_ta_event_getmsg (const td_thragent_t
*__ta
,
365 td_event_msg_t
*msg
);
368 /* Set suggested concurrency level for process associated with TA. */
369 extern td_err_e
td_ta_setconcurrency (const td_thragent_t
*__ta
, int __level
);
372 /* Enable collecting statistics for process associated with TA. */
373 extern td_err_e
td_ta_enable_stats (const td_thragent_t
*__ta
, int __enable
);
375 /* Reset statistics. */
376 extern td_err_e
td_ta_reset_stats (const td_thragent_t
*__ta
);
378 /* Retrieve statistics from process associated with TA. */
379 extern td_err_e
td_ta_get_stats (const td_thragent_t
*__ta
,
380 td_ta_stats_t
*__statsp
);
383 /* Validate that TH is a thread handle. */
384 extern td_err_e
td_thr_validate (const td_thrhandle_t
*__th
);
386 /* Return information about thread TH. */
387 extern td_err_e
td_thr_get_info (const td_thrhandle_t
*__th
,
388 td_thrinfo_t
*__infop
);
390 /* Retrieve floating-point register contents of process running thread TH. */
391 extern td_err_e
td_thr_getfpregs (const td_thrhandle_t
*__th
,
392 prfpregset_t
*__regset
);
394 /* Retrieve general register contents of process running thread TH. */
395 extern td_err_e
td_thr_getgregs (const td_thrhandle_t
*__th
,
396 prgregset_t __gregs
);
398 /* Retrieve extended register contents of process running thread TH. */
399 extern td_err_e
td_thr_getxregs (const td_thrhandle_t
*__th
, void *__xregs
);
401 /* Get size of extended register set of process running thread TH. */
402 extern td_err_e
td_thr_getxregsize (const td_thrhandle_t
*__th
, int *__sizep
);
404 /* Set floating-point register contents of process running thread TH. */
405 extern td_err_e
td_thr_setfpregs (const td_thrhandle_t
*__th
,
406 const prfpregset_t
*__fpregs
);
408 /* Set general register contents of process running thread TH. */
409 extern td_err_e
td_thr_setgregs (const td_thrhandle_t
*__th
,
410 prgregset_t __gregs
);
412 /* Set extended register contents of process running thread TH. */
413 extern td_err_e
td_thr_setxregs (const td_thrhandle_t
*__th
,
417 /* Enable reporting for EVENT for thread TH. */
418 extern td_err_e
td_thr_event_enable (const td_thrhandle_t
*__th
, int __event
);
420 /* Enable EVENT for thread TH. */
421 extern td_err_e
td_thr_set_event (const td_thrhandle_t
*__th
,
422 td_thr_events_t
*__event
);
424 /* Disable EVENT for thread TH. */
425 extern td_err_e
td_thr_clear_event (const td_thrhandle_t
*__th
,
426 td_thr_events_t
*__event
);
428 /* Get event message for thread TH. */
429 extern td_err_e
td_thr_event_getmsg (const td_thrhandle_t
*__th
,
430 td_event_msg_t
*__msg
);
433 /* Set priority of thread TH. */
434 extern td_err_e
td_thr_setprio (const td_thrhandle_t
*__th
, int __prio
);
437 /* Set pending signals for thread TH. */
438 extern td_err_e
td_thr_setsigpending (const td_thrhandle_t
*__th
,
439 unsigned char __n
, const sigset_t
*__ss
);
441 /* Set signal mask for thread TH. */
442 extern td_err_e
td_thr_sigsetmask (const td_thrhandle_t
*__th
,
443 const sigset_t
*__ss
);
446 /* Return thread local data associated with key TK in thread TH. */
447 extern td_err_e
td_thr_tsd (const td_thrhandle_t
*__th
,
448 const thread_key_t __tk
, void **__data
);
451 /* Suspend execution of thread TH. */
452 extern td_err_e
td_thr_dbsuspend (const td_thrhandle_t
*__th
);
454 /* Resume execution of thread TH. */
455 extern td_err_e
td_thr_dbresume (const td_thrhandle_t
*__th
);
457 #endif /* thread_db.h */
459 #endif /* HAVE_THREAD_DB_H */