[Lldb-commits] [PATCH] D122176: [trace] clear any existing tracing sessions before relaunching the binary

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 21 13:34:51 PDT 2022


wallace created this revision.
wallace added reviewers: jj10306, zrthxn.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

There's a bug caused when a process is relaunched: the target, which
doesn't change, keeps the Trace object from the previous process, which
is already defunct, and causes segmentation faults when it's attempted
to be used.
A fix is to clean up the Trace object when the target is disposing of
the previous process during relaunches.

A way to reproduce this:

  lldb a.out
  b main
  r
  process trace start
  c
  r
  process trace start


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122176

Files:
  lldb/source/Target/Target.cpp
  lldb/test/API/commands/trace/TestTraceStartStop.py


Index: lldb/test/API/commands/trace/TestTraceStartStop.py
===================================================================
--- lldb/test/API/commands/trace/TestTraceStartStop.py
+++ lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,13 @@
 
         self.expect("thread trace stop", error=True,
             substrs=["error: Process must be launched"])
+
+        # We should be able to trace the program if we relaunch it
+        self.expect("r")
+        self.expect("thread trace start")
+        # We can reconstruct the single instruction executed in the first line
+        self.expect("n")
+        self.expect("thread trace dump instructions -f",
+            patterns=[f'''thread #1: tid = .*
+  a.out`main \+ 4 at main.cpp:2
+    \[ 0\] {ADDRESS_REGEX}    movl'''])
Index: lldb/source/Target/Target.cpp
===================================================================
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@
 
 void Target::DeleteCurrentProcess() {
   if (m_process_sp) {
+    // We dispose any active tracing sessions on the current process
+    m_trace_sp.reset();
     m_section_load_history.Clear();
     if (m_process_sp->IsAlive())
       m_process_sp->Destroy(false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122176.417075.patch
Type: text/x-patch
Size: 1255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220321/fa8d0670/attachment.bin>


More information about the lldb-commits mailing list