[Lldb-commits] [PATCH] D33674: Implementation of Intel(R) Processor Trace support for Linux

Ravitheja Addepally via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 16 06:27:29 PDT 2017

ravitheja added a comment.

Just to make things clear, I will explain a use case

Suppose if we are debugging an application where the main thread spawns a second new thread ->

  int main() {
  int i = 0;   // user starts tracing on main thread -> gets traceid 1
  .....  // Some statements
  i++; // Here he starts tracing the whole process -> gets traceid 2.
          // Now traceid=2 represents the tracing instance on the 
          // whole process, meaning all new threads spawned in 
          //  the process will be traced with this id. Although the 
          //main thread is already being traced hence 
          // will not be a part of traceid =2
  std::thread (thread_function) // New thread spawned, this will be traced with id =2
  .....  // Some statements
          // To obtain the trace data or stop the trace on main thread
         //  the user can simply work with trace id =1 and not specify the
        // thread id anywhere.
          // For threads under the process trace id hood, the thread id needs to be specified for
          // obtaining the trace data or if the tracing needs to be stopped only for that thread.
         // Now if the tracing on the process is switched off then the tracing on the main thread
        // is not affected.

Now the set of threads


will track threads that are being traced under the process trace id. Hence when a thread exits,
we need to update this set accordingly.

Comment at: source/Plugins/Process/Linux/NativeProcessLinux.cpp:2644
+  if (iter != m_processor_trace_monitor.end())
+    error = StopTrace(iter->second->GetTraceID(), thread);
labath wrote:
> Should you delete the iterator from the map after this? In fact, the mere act of deleting the iterator should probably be what triggers the trace stop, in line with RAII principles.
Yes, but the thing is i have to update the Set of threads 

which is tracking how many threads are being traced under the process trace id. The StopTrace calls StopProcessorTracingOnThread eventually which deletes the element from the various containers. I can directly call StopProcessorTracingOnThread instead of StopTrace.


More information about the lldb-commits mailing list