[Lldb-commits] [lldb] a80c6c7 - [trace] clear any existing tracing sessions before relaunching the binary
Walter Erquinigo via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 21 16:03:46 PDT 2022
Author: Walter Erquinigo
Date: 2022-03-21T16:03:37-07:00
New Revision: a80c6c7d36d25999a28cfad32e1f461db95ba4dc
URL: https://github.com/llvm/llvm-project/commit/a80c6c7d36d25999a28cfad32e1f461db95ba4dc
DIFF: https://github.com/llvm/llvm-project/commit/a80c6c7d36d25999a28cfad32e1f461db95ba4dc.diff
LOG: [trace] clear any existing tracing sessions before relaunching the binary
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
```
Differential Revision: https://reviews.llvm.org/D122176
Added:
Modified:
lldb/source/Target/Target.cpp
lldb/test/API/commands/trace/TestTraceStartStop.py
Removed:
################################################################################
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 00e9fd1eda571..71991085145ab 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -185,6 +185,8 @@ void Target::CleanupProcess() {
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);
diff --git a/lldb/test/API/commands/trace/TestTraceStartStop.py b/lldb/test/API/commands/trace/TestTraceStartStop.py
index 841ca437b29f6..d0d65fdd9cf9c 100644
--- a/lldb/test/API/commands/trace/TestTraceStartStop.py
+++ b/lldb/test/API/commands/trace/TestTraceStartStop.py
@@ -166,3 +166,16 @@ def testStartStopLiveThreads(self):
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
+ # For this, we'll trace starting at a
diff erent point in the new
+ # process.
+ self.expect("breakpoint disable")
+ self.expect("b main.cpp:4")
+ self.expect("r")
+ self.expect("thread trace start")
+ # We can reconstruct the single instruction executed in the first line
+ self.expect("si")
+ self.expect("thread trace dump instructions -c 1",
+ patterns=[f'''thread #1: tid = .*
+ a.out`main \+ 11 at main.cpp:4'''])
More information about the lldb-commits
mailing list