Log in

View Full Version : multithread application debugging


crkzone
November 7th, 2004, 03:02
I have some problems debugging a multithread application with softice.How can i find the program's executed code when sleep or sleepex or wait_semaphore functions are called.

Silver
November 7th, 2004, 06:56
Which code? The code in the thread? When the thread is created, a pointer to the function comprising the start of the thread is passed to CreateThread (or whatever). Thus, you have the entry point for your thread.

Your question is a bit vague, but I assume you're asking "How do I know which bit of code is being executed in thread 1 whilst thread 0 is waiting for a semaphore/mutex/section?". There is no simple way to do this, but IMO the best way is to find the call in thread 1 that signals the semaphore/mutex/csection. In other words:

1. Thread 0 creates thread 1.
2. Thread 0 sleeps, waiting for the csection to signal.
3. Thread 1 does stuff.
4. Thread 1 signals the csection.
5. Thread 0 wakes up.

To find what is happening at (3), find (4) and work backwards. This seems the logical way to do it to me, and the way I've done it in the past. Others may be able to suggest a technique/tool that is more efficient.

CreateThread reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createthread.asp

*edit* I lost the ability to type...

crkzone
November 7th, 2004, 10:44
Thanks for your reply and i know that
HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
SIZE_T dwStackSize, // initial stack size
LPTHREAD_START_ROUTINE lpStartAddress, // thread function
LPVOID lpParameter, // thread argument
DWORD dwCreationFlags, // creation option
LPDWORD lpThreadId // thread identifier
);
lpStartAddress is the thread start function but there are 2 problems:
1-The program creates too many threads at the startup and i can't trace from this point.
2-When sleep function called It doesn't mean the execution of thread starts from the beginning,and i want to find first instruction from program which executed.
This is my situation
The program calls SendMessageA,break on PeekMessageA and i land on one of programs dll,then it goes in a loop and calls kernel32.sleep and calls some bad stuff!

dELTA
November 7th, 2004, 17:32
You are still being quite vague, but as far as I can see you want to catch a thread immediately when it returns from a sleep() call? Simply put a breakpoint on the instruction after the sleep() call in the program code. This would be the first instruction of the program's own code being executed after the sleep (while the first instruction in the thread would of course be somewhere inside the sleep API code, but I can't imagine why you would need that anyway).