-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][target] Add progress report for wait-attaching to process #144768
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
[lldb][target] Add progress report for wait-attaching to process #144768
Conversation
@llvm/pr-subscribers-lldb Author: Chelsea Cassanova (chelcassanova) ChangesThis commit adds a progress report when wait-attaching to a process as well as a test for this. Full diff: https://github.com/llvm/llvm-project/pull/144768.diff 2 Files Affected:
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 45a9e1196a049..8819651378791 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3546,6 +3546,8 @@ llvm::Expected<TraceSP> Target::GetTraceOrCreate() {
}
Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) {
+ std::unique_ptr<Progress> attach_progress;
+ attach_progress = std::make_unique<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..b0ca3939c551b 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,37 @@ 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(), "a.out", 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.assertGreater(len(message), 0)
+ 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()
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! LGTM with comment addressed.
lldb/source/Target/Target.cpp
Outdated
@@ -3546,6 +3546,8 @@ llvm::Expected<TraceSP> Target::GetTraceOrCreate() { | |||
} | |||
|
|||
Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) { | |||
std::unique_ptr<Progress> attach_progress; | |||
attach_progress = std::make_unique<Progress>("Waiting to attach to process"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be a local variable, no need to make it a unique ptr
event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster) | ||
progress_data = lldb.SBDebugger.GetProgressDataFromEvent(event) | ||
message = progress_data.GetValueForKey("message").GetStringValue(100) | ||
self.assertGreater(len(message), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Checking for len(message) > 0
is redundant with the assertEqual
below.
This commit adds a progress report when wait-attaching to a process as well as a test for this.
211e0e2
to
daae7e7
Compare
@bulbazord @medismailben Updated this patch to add both of your suggestions |
This is breaking
on the buildbots for |
Let me know if you need help to reproduce this. Surprised the x86 bot isn't on that list. That might be a clue, I think the remote target for remote-linux-ubuntu might be an Arm board. |
Though I cannot reproduce the failure, so it could be to do with the high load when run on the bots. Some process being deprioritised. |
Well.. IIUC, this test tries to attach to a process called "a.out" -- and hopes that the process doesn't appear. If you run the test suite in parallel, you'll have any number of processes like that going around all the time. Not only will this test fail, but it will mess up the state of a random other test. I guess you could just wait for a sufficiently unique process name... |
@@ -16,6 +17,36 @@ 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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sound like you don't actually need to build anything here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying this locally, removing the self.build() line causes the test to stall out so I'm going to keep it in.
That's pretty much it, I just need to wait-attach to some process to trigger the progress report I'm expecting and then drop the process once we've triggered that report and check that it was emitted correctly.
Great point, I hadn't considered this. I'm also a little surprised this seems to specifically affect ARM Ubuntu here 🤔 .
This is probably the right way to go for this, I'll update the test to do this.
With this and Pavel's comment about the generic process name it's probably how this test works on the bots. I'm not sure if there's a way to preview how this test would run on the bots before actually landing (outside of running it locally or having the GH pre-commit checks), but I'll try relanding and changing the process name to wait on for now since I don't think I have another way to ensure the test would be fine on the bots. |
…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
PR to reland this: #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
…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
…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
This commit adds a progress report when wait-attaching to a process as well as a test for this.