[lldb-dev] How to enumerate stopped threads in C++ API?
Greg Clayton via lldb-dev
lldb-dev at lists.llvm.org
Thu Mar 3 12:41:16 PST 2016
Each call into the lldb::SB* API will take a target lock and possible a process read/write lock.
We do have a SBThreadCollection class that we can use. Feel free to add an API like this to SBProcess:
The current API on process SBProcess::GetNumThreads() and SBProcess::GetThreadAtIndex() might have issues if you are doing things like evaluating an expression on another thread where you might request the number of threads and get 10, but then an expression runs on another thread and there are now maybe 8 or 12 threads, and then you call SBProcess::GetThreadAtIndex() and it might return you results that are different that what you wanted. If we return all threads at once, we won't run into this issue. Then you can have SBThreadCollection add a new methods to return a new list for all threads with stop reasons.
That being said, hundreds of threads should not cause a huge bottleneck for single stop, but if you doing it many many many times it could be.
> On Mar 3, 2016, at 9:54 AM, Eugene Birukov via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> I am working on a custom debugger on Linux and I am using LLDB C++ API for that. So far, from the functionality point of view the life is good, but I am running into severe performance issue.
> The problem is that the target application has literally hundreds of threads, and when the target process stops, I need to identify all the threads that have non-trivial stop reason. So, I am doing something like that:
> // Loop over threads
> int numThreads = m_Process.GetNumThreads();
> for (int threadIndex = 0; threadIndex < numThreads; ++threadIndex)
> // Inspect the thread state
> sbThread = m_Process.GetThreadAtIndex(threadIndex);
> stopReason = sbThread.GetStopReason();
> Well, this loop turns out to be a bottleneck.
> So, is there any way to find all the stopped threads without iterating over the whole world?
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
More information about the lldb-dev