Skip to content

Fix a bug where using "thread backtrace unique" would switch you to #140993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jimingham
Copy link
Collaborator

always using the "frame-format-unique" even when you weren't doing the unique backtrace mode.

always using the "frame-format-unique" even when you weren't doing
the unique backtrace mode.
@jimingham jimingham requested a review from JDevlieghere as a code owner May 22, 2025 02:45
@llvmbot llvmbot added the lldb label May 22, 2025
@llvmbot
Copy link
Member

llvmbot commented May 22, 2025

@llvm/pr-subscribers-lldb

Author: None (jimingham)

Changes

always using the "frame-format-unique" even when you weren't doing the unique backtrace mode.


Full diff: https://github.com/llvm/llvm-project/pull/140993.diff

2 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectThreadUtil.cpp (+2)
  • (modified) lldb/test/API/functionalities/thread/num_threads/TestNumThreads.py (+17-1)
diff --git a/lldb/source/Commands/CommandObjectThreadUtil.cpp b/lldb/source/Commands/CommandObjectThreadUtil.cpp
index cdc5946547f47..a451de137d702 100644
--- a/lldb/source/Commands/CommandObjectThreadUtil.cpp
+++ b/lldb/source/Commands/CommandObjectThreadUtil.cpp
@@ -37,6 +37,8 @@ void CommandObjectIterateOverThreads::DoExecute(Args &command,
   result.SetStatus(m_success_return);
 
   bool all_threads = false;
+  m_unique_stacks = false;
+
   if (command.GetArgumentCount() == 0) {
     Thread *thread = m_exe_ctx.GetThreadPtr();
     if (thread)
diff --git a/lldb/test/API/functionalities/thread/num_threads/TestNumThreads.py b/lldb/test/API/functionalities/thread/num_threads/TestNumThreads.py
index ee9b14f15b6e9..40bc2a175c2f9 100644
--- a/lldb/test/API/functionalities/thread/num_threads/TestNumThreads.py
+++ b/lldb/test/API/functionalities/thread/num_threads/TestNumThreads.py
@@ -132,10 +132,26 @@ def is_thread3(thread):
         # Construct our expected back trace string
         expect_string = "10 thread(s)%s" % (expect_threads)
 
+        # There was a bug where if you used 'thread backtrace unique'
+        # we would switch all future backtraces to use the
+        # "frame-format-unique" not the "frame-format".  Make
+        # sure we don't do that...
+        setting_data = self.dbg.GetSetting("frame-format-unique")
+        setting_str = setting_data.GetStringValue(1000)
+        setting_str = "UNIQUE: " + setting_str
+        lldb.SBDebugger.SetInternalVariable("frame-format-unique", setting_str, self.dbg.GetInstanceName())
         # Now that we are stopped, we should have 10 threads waiting in the
         # thread3 function. All of these threads should show as one stack.
         self.expect(
             "thread backtrace unique",
             "Backtrace with unique stack shown correctly",
-            substrs=[expect_string, "main.cpp:%d" % self.thread3_before_lock_line],
+            substrs=[expect_string, "UNIQUE:", "main.cpp:%d" % self.thread3_before_lock_line],
+        )
+        # Make sure setting the unique flag in the command isn't
+        # persistent:
+        self.expect(
+            "thread backtrace",
+            "Backtrace unique is not sticky",
+            substrs=["UNIQUE:"],
+            matching=False
         )

Copy link

⚠️ Python code formatter, darker found issues in your code. ⚠️

You can test this locally with the following command:
darker --check --diff -r HEAD~1...HEAD lldb/test/API/functionalities/thread/num_threads/TestNumThreads.py
View the diff from darker here.
--- TestNumThreads.py	2025-05-22 02:44:29.000000 +0000
+++ TestNumThreads.py	2025-05-22 02:47:37.902846 +0000
@@ -137,21 +137,27 @@
         # "frame-format-unique" not the "frame-format".  Make
         # sure we don't do that...
         setting_data = self.dbg.GetSetting("frame-format-unique")
         setting_str = setting_data.GetStringValue(1000)
         setting_str = "UNIQUE: " + setting_str
-        lldb.SBDebugger.SetInternalVariable("frame-format-unique", setting_str, self.dbg.GetInstanceName())
+        lldb.SBDebugger.SetInternalVariable(
+            "frame-format-unique", setting_str, self.dbg.GetInstanceName()
+        )
         # Now that we are stopped, we should have 10 threads waiting in the
         # thread3 function. All of these threads should show as one stack.
         self.expect(
             "thread backtrace unique",
             "Backtrace with unique stack shown correctly",
-            substrs=[expect_string, "UNIQUE:", "main.cpp:%d" % self.thread3_before_lock_line],
+            substrs=[
+                expect_string,
+                "UNIQUE:",
+                "main.cpp:%d" % self.thread3_before_lock_line,
+            ],
         )
         # Make sure setting the unique flag in the command isn't
         # persistent:
         self.expect(
             "thread backtrace",
             "Backtrace unique is not sticky",
             substrs=["UNIQUE:"],
-            matching=False
+            matching=False,
         )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants