Skip to content

Reland "[lldb][target] Add progress report for wait-attaching to proc… #145111

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

Merged

Conversation

chelcassanova
Copy link
Contributor

…ess" (#144810)

This relands commit e0933ab. The original commit was causing the test TestCreateAfterAttach.py to fail on ARM Ubuntu bots. It's possible that this could've been happening because the test for wait-attach progress reporting is waiting on a process named "a.out" which could be too generic as multiple other tests (when run in parallel on the bots) could also be using processes named "a.out". This commit changes the wait-attach progress report test to wait on a unique process name.

Original PR description:

This commit adds a progress report when wait-attaching to a process as well as a test for this.

Original PR link: #144768

@llvmbot
Copy link
Member

llvmbot commented Jun 20, 2025

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

…ess" (#144810)

This relands commit e0933ab. The original commit was causing the test TestCreateAfterAttach.py to fail on ARM Ubuntu bots. It's possible that this could've been happening because the test for wait-attach progress reporting is waiting on a process named "a.out" which could be too generic as multiple other tests (when run in parallel on the bots) could also be using processes named "a.out". This commit changes the wait-attach progress report test to wait on a unique process name.

Original PR description:

This commit adds a progress report when wait-attaching to a process as well as a test for this.

Original PR link: #144768


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

2 Files Affected:

  • (modified) lldb/source/Target/Target.cpp (+1)
  • (modified) lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py (+34)
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 45a9e1196a049..8f8d2ef21cc5f 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3546,6 +3546,7 @@ llvm::Expected<TraceSP> Target::GetTraceOrCreate() {
 }
 
 Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) {
+  Progress attach_progress("Waiting to attach to process");
   m_stats.SetLaunchOrAttachTime();
   auto state = eStateInvalid;
   auto process_sp = GetProcessSP();
diff --git a/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py b/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
index 9af53845ca1b7..7da920723f951 100644
--- a/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ b/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,6 +2,7 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
+import threading
 
 import lldbsuite.test.lldbutil as lldbutil
 
@@ -16,6 +17,39 @@ def setUp(self):
             self.broadcaster, lldb.SBDebugger.eBroadcastBitProgress
         )
 
+    def test_wait_attach_progress_reporting(self):
+        """Test that progress reports for wait attaching work as intended."""
+        self.build()
+        target = self.dbg.CreateTarget(None)
+
+        # Wait attach to a process, then check to see that a progress report was created
+        # and that its message is correct for waiting to attach to a process.
+        class AttachThread(threading.Thread):
+            def __init__(self, target):
+                threading.Thread.__init__(self)
+                self.target = target
+
+            def run(self):
+                self.target.AttachToProcessWithName(
+                    lldb.SBListener(),
+                    "wait-attach-progress-report",
+                    True,
+                    lldb.SBError(),
+                )
+
+        thread = AttachThread(target)
+        thread.start()
+
+        event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
+        progress_data = lldb.SBDebugger.GetProgressDataFromEvent(event)
+        message = progress_data.GetValueForKey("message").GetStringValue(100)
+        self.assertEqual(message, "Waiting to attach to process")
+
+        # Interrupt the process attach to keep the test from stalling.
+        target.process.SendAsyncInterrupt()
+
+        thread.join()
+
     def test_dwarf_symbol_loading_progress_report(self):
         """Test that we are able to fetch dwarf symbol loading progress events"""
         self.build()

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Linux CI failure is real and reproduces locally. I'm looking for a way to make it work.

@DavidSpickett
Copy link
Collaborator

The test waits forever trying to attach, the AsyncInterrupt doesn't stop it doing that. I thought maybe these "threads" were not actually parallel so I tried multiprocessing, same result (also I'm not sure this would work because it uses a separate process).

I wonder if you would be better off actually attaching to something. Then you don't have to do all this waiting around, the progress message should still be there.

@chelcassanova
Copy link
Contributor Author

I wonder if you would be better off actually attaching to something. Then you don't have to do all this waiting around, the progress message should still be there.

This is best thing to try here, I'll update the test to do this.

@chelcassanova chelcassanova force-pushed the reland-wait-attach-progress-report branch 2 times, most recently from 9d9404b to def09f2 Compare June 24, 2025 18:31
# progres events and check that the waiting to attach one was emitted at all.
target.AttachToProcessWithName(
self.listener,
"a.out",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not bring back the previous problem that sometimes there will be an a.out process and attaching to it may get in the way of something else trying to debug it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had wondered if attaching to the process instead of having it wait in another thread could avoid the issue, but you're correct and it wouldn't. I'll update the test to change this, and this shouldn't need any extra setup to work IIUC?

…ess" (llvm#144810)

This relands commit e0933ab. The
original commit was causing the test TestCreateAfterAttach.py to fail on
ARM Ubuntu bots. It's possible that this could've been happening because
the test for wait-attach progress reporting is waiting on a process
named "a.out" which could be too generic as multiple other tests (when
run in parallel on the bots) could also be using processes named
"a.out". This commit changes the wait-attach progress report test to
wait on a unique process name.

Original PR description:

This commit adds a progress report when wait-attaching to a process as
well as a test for this.

Original PR link: llvm#144768
@chelcassanova chelcassanova force-pushed the reland-wait-attach-progress-report branch from def09f2 to 15551c3 Compare June 25, 2025 19:44
Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes locally and it shouldn't accidentally attach to a real process now, so LGTM.

@chelcassanova chelcassanova merged commit e880cf7 into llvm:main Jun 26, 2025
7 checks passed
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
llvm#145111)

…ess" (llvm#144810)

This relands commit e0933ab. The
original commit was causing the test TestCreateAfterAttach.py to fail on
ARM Ubuntu bots. It's possible that this could've been happening because
the test for wait-attach progress reporting is waiting on a process
named "a.out" which could be too generic as multiple other tests (when
run in parallel on the bots) could also be using processes named
"a.out". This commit changes the wait-attach progress report test to
wait on a unique process name.

Original PR description:

This commit adds a progress report when wait-attaching to a process as
well as a test for this.

Original PR link: llvm#144768
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.

4 participants