-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
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.
@llvm/pr-subscribers-lldb Author: Alex Langford (bulbazord) ChangesInstead 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:
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);
}
|
auto event_sp = CreateEventFromProcessState(eBroadcastBitSTDOUT); | ||
BroadcastEventIfUnique(event_sp); |
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.
Why not BroadcastEventIfUnique(CreateEventFromProcessState(eBroadcastBitSTDOUT))
? Too long?
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.
I didn't really think about it tbh, but I like the inlining so I'll update this before landing.
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.
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.
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.