Multi-threaded applications
Multi-threaded applications
The thread buttons
Controlling how the debuggee starts a new thread
Single stepping more than one thread
Concentrating on certain threads
Traffic light control
Checking thread creation and termination (using the log)

Multi-threaded applications
I have read that multi-threaded applications should be avoided at all costs. Certainly life would then be easier. But the truth is that using the multi-thread capabilities of Windows brings some applications to life. GoBug is designed specifically to deal with more than one thread in your application. However, as in any debugger relying on Win32 debugging support, there is only one debug loop. And this means that debugging is done on a process wide basis. If any thread is in the debug loop, the whole process (including all its threads) are suspended. If you then single step through the code, the process is unsuspended and an instruction is carried out. However, the system may then decide to give processor time to another thread. It may be that other thread which then comes into the debug loop. This makes it possible to single step more than one thread see below.

The thread buttons
Each thread in the debuggee has a thread button. If a thread is currently in the debug loop, its thread button will be wider. Here thread E0h is at the input gate. This thread button is coloured red, showing that the thread's action is single-step. The second thread, B0h is F9 action. This can be seen because the colour of the thread is black. B0h is also the main thread. This is shown by the asterisk. Thread E0h is currently showing in the panes. We know this because the thread button is "pushed". Clicking on thread button B0h will display the last known state of the thread. However, because it is running (no trap) the results will be uncertain. Hence the panes will be greyed if you click on this button.
Here GoBug's window is too small to show all the threadbuttons, but you can scroll them all into view. You know from the number in brackets that there are 7 thread buttons in all. Here none of the threads are at the input gate.

Controlling how the debuggee starts a new thread
GoBug starts new threads with the current action, that is, the action last put in by the user. So for example, if the last GoBug keypress was F9, then all new threads are going to have the same action. If you want to single-step a new thread, simply use the "action" menu to make a breakpoint at "new thread". If you want to make sure you catch a specific new thread (instead of any thread), insert a breakpoint at the code address of the thread start (set a breakpoint at the address label). Some threads are started by the system temporarily, for example the system's open file dialog will be in a new thread. These are not caught by GoBug's new thread breakpoint. Also these threads always start as running in the background (F9 action).

Single stepping more than one thread
Single stepping more than one thread provides some insight into how the system switches the processor between threads. This assumes that the system works the same way when in slow motion. Can anyone in the online community confirm this? If this is indeed how the system works then you will see that there are frequent switches between threads. This may well have important implications when considering thread conflict in your multi-threaded application. In practice when debugging, this means that the thread in the input gate will often change. When this occurs GoBug "sweeps" the panes, that is you see the pane information for the thread being viewed, being replaced by the pane information for the new thread now being viewed. To achieve single stepping in more than one thread, either single step through the call to CreateThread, or set a breakpoint at the new threads start address, or use the "action" menu to make a breakpoint at "new thread".

Concentrating on certain threads
You may need to single step one particular thread or more than one particular threads, and have no desire to single step through other threads. In this case make the other threads run using F9. To achieve this, press F9 each time a thread in which you have no interest comes into the input gate. Alternatively you can wait for all the threads to be made and then use the traffic light control to cause to run all threads in which you have no interest. Currently GoBug will not allow you to suspend a thread in which you have no interest, although technically this is possible. If anyone would like this function added please let me know on JG@JGnet.co.uk.

Traffic Light control
When you have several threads running, clicking on the traffic light toolbar button provides a useful way of viewing and controlling how the threads act. This can also be invoked from the "action" menu or by using pressing the Crtl+T keys.
Here we see that the main thread 6CCh (marked with an asterisk) is at the input gate and its action is single-step. Threads 71Ch and 63Ch are set to F7, threads 698h and 610h are set to F8 and threads 62Ch and 654h are set to F9.