DCE for the HP e3000 (B3821-90002)

Programming with Kernel Threads
Debugging Threaded Applications
Chapter 5
59
Debugging Threaded Applications
The following are hints for debugging threaded applications:
Set breakpoints for global data bugs — To simplify debugging problems involving
unexpected changes in global data, use HPDEBUG to set task-wide data
breakpoints. Otherwise, make sure there is a breakpoint that every thread will hit.
Even when you are single-stepping, another thread can intervene between source
statements executed by the thread you are following. One way you can know that this
is happening is if the intervening thread hits a breakpoint.
You can preventother threadsfrom intervening while single stepping in HPDEBUG.
This is done by setting the HPDEBUG environment variable
SS_TERM_KEEPLOCK. Setting this variable causes you to hold the terminal
semaphore for the current thread until a CONTINUE command is issued. Effectively,
no other thread is able to obtain the terminal semaphore and interfere with your
debug session. Another method is to create breakpoints within your task that have
the “Stop-all-Threads” options. This option, when hit by any thread in the task, stops
execution of all threads in the task until a CONTINUE command is issued. It is
possible to create a deadlock situation when using SS_TERM_KEEPLOCK with
“Stop-all-Threads” set in your task.
Debugging a threaded server — Do not debug multiple threads in the server, debug
one at a time. To do this, set a breakpoint at the procedure you want to catch and
continue. Then make only one remote procedure call from the client; you will hit the
breakpoint, step through until you locate the bug, then continue or quit.
Debugging a threaded client — If the threads in a client do not interact, debug only
one of them at a time.