With dbx, you can examine stack traces of each thread, resume all threads, step or next a specific thread, and navigate between threads.
dbx can debug multithreaded applications that use either Solaris threads or POSIX threads.
dbx recognizes a multithreaded program by detecting whether it utilizes libthread.so. The program will use libthread.so either by explicitly being compiled with -lthread or -mt, or implicitly by being compiled with -lpthread.
This chapter describes how to find information about and debug threads using the dbx thread commands.
This chapter is organized into the following sections:
When it detects a multithreaded program, dbx tries to dlopen libthread_db.so, a special system library for thread debugging located in /usr/lib.
dbx is a synchronous dbx; when any thread or lightweight process (LWP) stops, all other threads and LWPs sympathetically stop. This behavior is sometimes referred to as the "stop the world" model.
For information on multithreaded programming and LWPs, see the Solaris Multithreaded Programming Guide.
The following thread information is available:
(dbx) threads t@1 a |@1 ?() running in main() t@2 ?() asleep on 0xef751450 in_swtch() t@3 b |@2 ?() running in sigwait() t@4 consumer() asleep on 0x22bb0 in _lwp_sema_wait() *>t@5 b |@4 consumer() breakpoint in Queue_dequeue() t@6 b |@5 producer() running in _thread_start() (dbx)
The * (asterisk) indicates that an event requiring user attention has occurred in this thread.
An 'o' instead of an asterisk indicates that a dbx internal event has occurred.
The arrow denotes the current thread.
t@num, the thread id, refers to a particular thread. The number is the thread_t value passed back by thr_create.
b l@num or a l@num means the thread is bound to or active on the designated LWP, meaning the thread is actually running.
Start function of the thread as passed to thr_create. A ?() means the start function is not known.
Thread state.
The function that the thread is currently executing.
To switch the viewing context to another thread, use the thread command. The syntax is:
thread [-info] [-hide] [-unhide] [-suspend] [-resume] tid
To display the current thread:
thread
thread tid
The following are commands for viewing the threads list. The syntax is:
threads [-all} [-mode [all|filter] [auto|manual]]
To print the list of all known threads:
threads
To print threads normally not printed (zombies):
threads -all
Use the cont command to resume program execution. Currently, threads use synchronous breakpoints so all threads resume execution.
Normally, you need not be aware of LWPs. There are times, however, when thread level queries cannot be completed. In this case, use the lwps command to show information about LWPs.
(dbx) lwps l@1 running in main() l@2 running in sigwait() l@3 running in _lwp_sema_wait() *>l@4 breakpoint in Queue_dequeue() l@5 running in _thread_start() (dbx)
The * (asterisk) indicates that an event requiring user attention has occurred in this LWP.
The arrow denotes the current LWP.
l@num refers to a particular LWP.
The next item represents the LWP state.
in func_name() identifies the function that the LWP is currently executing.
In the following commands, a missing tid implies the current thread.
Print everything known about the given thread:
thread -info tid
Hide or unhide the given (or current) thread. It will or will not show up in the generic threads listing:
thread [-hide | -unhide] tid
thread -unhide all
Keep the given thread from ever running. A suspended thread shows up with an S in the threads list:
thread -suspend tid
thread -resume tid
threads -mode
Control whether threads prints all threads or filters them by default:
threads -mode [all | filter]
Thread and LWP States |
Description |
---|---|
suspended |
Thread has been explicitly suspended. |
runnable |
Thread is runnable and is waiting for an LWP as a computational resource. |
zombie |
When a detached thread exits (thr_exit)), it is in a zombie state until it has rendezvoused through the use of thr_join(). THR_DETACHED is a flag specified at thread creation time (thr_create()). A non-detached thread that exits is in a zombie state until it has been reaped. |
asleep on syncobj |
Thread is blocked on the given synchronization object. Depending on what level of support libthread and libthread_db provide, syncobj might be as simple as a hexadecimal address or something with more information content. |
active |
The thread is active on an LWP, but dbx cannot access the LWP. |
unknown |
dbx cannot determine the state. |
lwpstate |
A bound or active thread state is the state of the LWP associated with it. |
running |
LWP was running but was stopped in synchrony with some other LWP. |
syscall num |
LWP stopped on an entry into the given system call #. |
syscall return num |
LWP stopped on an exit from the given system call #. |
job control |
LWP stopped due to job control. |
LWP suspended |
LWP is blocked in the kernel. |
single stepped |
LWP has just completed a single step. |
breakpoint |
LWP has just hit a breakpoint. |
fault num |
LWP has incurred the given fault #. |
signal name |
LWP has incurred the given signal. |
process sync |
The process to which this LWP belongs has just started executing. |
LWP death |
LWP is in the process of exiting. |