See below…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Thursday, January 06, 2011 2:38 PM
To: Kernel Debugging Interest List
Subject: [windbg] Find the parent thread of a child thread
Problem: The issue is I have to find the parent of a thread which has
sometimes paniced.
*****
I was not aware that a thread can panic, but it sounds more like it is need
of psychological counseling than programming help. There are drugs that
deal with panic attacks, but I don’t know how to administer them to threads.
And why do you have to find the parent? And do you need to do this just
while you are debugging, or do you need to do it in code executing in the
thread? And why should the parent matter?
*****
Description:
When our application starts 70 threads gets created which is as per the
requirement.
Later on as per the needs these 70 threads can create more threads.
So apart from these 70 threads a large number of other threads gets
created(from these 70 threads) and destroyed randomly.
So imagine there is a tree of threads.
****
No, you have a *concept* of a tree of threads, but no such entity exists.
Any notion of a tree is like thinking of a tree as a data structure; there
are only bits, nothing more, and if I want to call some of those bits “left
pointer” and “right pointer” I’m free to do so, but the computer has no idea
that these bits represent a tree structure.
****
There is an issue coming up in one such randomly created thread.
****
This is too vague to be meaningful. I could not tell you how to respond to
“an issue”.
****
On debugging the code we saw that the issue will be due to a value set by
its parent thread.
So we have to find the parent thread of this erroneus thread.
We are not able to get the parent thread id of this thread?
****
That’s because the concept does not exist, and unless you program it in, it
will never exist.
It is the responsibility of each thread that might care to know its logical
parent, and this is a requirement of the programmer to provide this
information to the thread. This information is not generally available.
But it is not clear to me why a thread should care about its logical parent
If you are programming in C++, and using worker threads, you would pass in a
base structure to every worker thread, and passing parameters into other
threads would require using classes derived from this base class, so every
thread could find the “parent” thread information by casting that parameter
to this base parameter class. If you are using MFC and UI threads, it is
only moderately more complex.
This app sounds thread-heavy and I question the basic design.
Also, I have no idea what problem you are trying to solve! You are asking a
typical low-level “how do I find out X?” style question instead of saying
why discovering X has any meaning.
There are much deeper questions about what constitutes failure of a thread
and what you expect to do about it.
****
Will anybody let us know how to find the parent of such randomly created
threads using especially windbg/visual studio?
****
It will be whereever you put it, and using a debugger, you would look
whereever you put it. Using my suggestion of using derived classes, you
would look at the thread parameter to the top-level thread function, which
is a void*, cast it to the base type of your parameter block, and look at
the parent ID field you set in it.
class ThreadParam {
public:
DWORD ThreadID;
};
class FirstLevelThreadParam : public ThreadParam {
public:
int something;
DWORD somethingElse;
LPCTSTR somestring;
};
class SecondLevelThreadParam : public ThreadParam {
public:
double value;
int * retval;
};
Etc. Note that if you cast the parameter to ThreadParam, you will always
see the ThreadID field.
But I seriously doubt that thread IDs have much value.
****
WINDBG is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.