Skip to content

[lldb][NFCI] Remove EventData* parameter from BroadcastEventIfUnique #79045

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
merged 1 commit into from
Jan 26, 2024

Conversation

bulbazord
Copy link
Member

Instead of passing the data to BroadcastEventIfUnique to create an Event object on the behalf of the caller, the caller can create the Event up-front.

Instead of passing the data to BroadcastEventIfUnique to create an Event
object on the behalf of the caller, the caller can create the Event
up-front.
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2024

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

Changes

Instead of passing the data to BroadcastEventIfUnique to create an Event object on the behalf of the caller, the caller can create the Event up-front.


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

4 Files Affected:

  • (modified) lldb/include/lldb/Target/Process.h (+2)
  • (modified) lldb/include/lldb/Utility/Broadcaster.h (+3-5)
  • (modified) lldb/source/Target/Process.cpp (+12-6)
  • (modified) lldb/source/Utility/Broadcaster.cpp (+2-3)
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 24c599e044c78f..4599a0dc882196 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -3216,6 +3216,8 @@ void PruneThreadPlans();
   Status LaunchPrivate(ProcessLaunchInfo &launch_info, lldb::StateType &state,
                        lldb::EventSP &event_sp);
 
+  lldb::EventSP CreateEventFromProcessState(uint32_t event_type);
+
   Process(const Process &) = delete;
   const Process &operator=(const Process &) = delete;
 };
diff --git a/lldb/include/lldb/Utility/Broadcaster.h b/lldb/include/lldb/Utility/Broadcaster.h
index c8127f0a921d88..f39e677fe9ee04 100644
--- a/lldb/include/lldb/Utility/Broadcaster.h
+++ b/lldb/include/lldb/Utility/Broadcaster.h
@@ -181,9 +181,8 @@ class Broadcaster {
     m_broadcaster_sp->BroadcastEvent(event_type);
   }
 
-  void BroadcastEventIfUnique(uint32_t event_type,
-                              EventData *event_data = nullptr) {
-    m_broadcaster_sp->BroadcastEventIfUnique(event_type, event_data);
+  void BroadcastEventIfUnique(uint32_t event_type) {
+    m_broadcaster_sp->BroadcastEventIfUnique(event_type);
   }
 
   void Clear() { m_broadcaster_sp->Clear(); }
@@ -351,8 +350,7 @@ class Broadcaster {
     void BroadcastEvent(uint32_t event_type,
                         const lldb::EventDataSP &event_data_sp);
 
-    void BroadcastEventIfUnique(uint32_t event_type,
-                                EventData *event_data = nullptr);
+    void BroadcastEventIfUnique(uint32_t event_type);
 
     void Clear();
 
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index e1c16ca2164322..23a8a66645c02d 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4281,25 +4281,31 @@ void Process::CalculateExecutionContext(ExecutionContext &exe_ctx) {
 //    return Host::GetArchSpecForExistingProcess (process_name);
 //}
 
+EventSP Process::CreateEventFromProcessState(uint32_t event_type) {
+  auto event_data_sp =
+      std::make_shared<ProcessEventData>(shared_from_this(), GetState());
+  return std::make_shared<Event>(event_type, event_data_sp);
+}
+
 void Process::AppendSTDOUT(const char *s, size_t len) {
   std::lock_guard<std::recursive_mutex> guard(m_stdio_communication_mutex);
   m_stdout_data.append(s, len);
-  BroadcastEventIfUnique(eBroadcastBitSTDOUT,
-                         new ProcessEventData(shared_from_this(), GetState()));
+  auto event_sp = CreateEventFromProcessState(eBroadcastBitSTDOUT);
+  BroadcastEventIfUnique(event_sp);
 }
 
 void Process::AppendSTDERR(const char *s, size_t len) {
   std::lock_guard<std::recursive_mutex> guard(m_stdio_communication_mutex);
   m_stderr_data.append(s, len);
-  BroadcastEventIfUnique(eBroadcastBitSTDERR,
-                         new ProcessEventData(shared_from_this(), GetState()));
+  auto event_sp = CreateEventFromProcessState(eBroadcastBitSTDERR);
+  BroadcastEventIfUnique(event_sp);
 }
 
 void Process::BroadcastAsyncProfileData(const std::string &one_profile_data) {
   std::lock_guard<std::recursive_mutex> guard(m_profile_data_comm_mutex);
   m_profile_data.push_back(one_profile_data);
-  BroadcastEventIfUnique(eBroadcastBitProfileData,
-                         new ProcessEventData(shared_from_this(), GetState()));
+  auto event_sp = CreateEventFromProcessState(eBroadcastBitProfileData);
+  BroadcastEventIfUnique(event_sp);
 }
 
 void Process::BroadcastStructuredData(const StructuredData::ObjectSP &object_sp,
diff --git a/lldb/source/Utility/Broadcaster.cpp b/lldb/source/Utility/Broadcaster.cpp
index 33cd49963e7c74..12903edc36b1b9 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -311,9 +311,8 @@ void Broadcaster::BroadcasterImpl::BroadcastEvent(
   PrivateBroadcastEvent(event_sp, false);
 }
 
-void Broadcaster::BroadcasterImpl::BroadcastEventIfUnique(
-    uint32_t event_type, EventData *event_data) {
-  auto event_sp = std::make_shared<Event>(event_type, event_data);
+void Broadcaster::BroadcasterImpl::BroadcastEventIfUnique(uint32_t event_type) {
+  auto event_sp = std::make_shared<Event>(event_type, /*data = */ nullptr);
   PrivateBroadcastEvent(event_sp, true);
 }
 

@bulbazord bulbazord requested a review from jimingham January 22, 2024 23:14
Comment on lines +4293 to +4294
auto event_sp = CreateEventFromProcessState(eBroadcastBitSTDOUT);
BroadcastEventIfUnique(event_sp);
Copy link
Member

Choose a reason for hiding this comment

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

Why not BroadcastEventIfUnique(CreateEventFromProcessState(eBroadcastBitSTDOUT))? Too long?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't really think about it tbh, but I like the inlining so I'll update this before landing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I remember why I didn't do this now! BroadcastEventIfUnique expects an lvalue argument but inlining the call would make it an rvalue. I don't think this matters tremendously so I'll land as-is and we can revisit as needed later.

@bulbazord bulbazord merged commit 02d3a79 into llvm:main Jan 26, 2024
@bulbazord bulbazord deleted the broadcast-event-if-unique branch January 26, 2024 18:40
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