Skip to content

Commit 02d3a79

Browse files
authored
[lldb][NFCI] Remove EventData* parameter from BroadcastEventIfUnique (#79045)
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.
1 parent a58c62f commit 02d3a79

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,6 +3216,8 @@ void PruneThreadPlans();
32163216
Status LaunchPrivate(ProcessLaunchInfo &launch_info, lldb::StateType &state,
32173217
lldb::EventSP &event_sp);
32183218

3219+
lldb::EventSP CreateEventFromProcessState(uint32_t event_type);
3220+
32193221
Process(const Process &) = delete;
32203222
const Process &operator=(const Process &) = delete;
32213223
};

lldb/include/lldb/Utility/Broadcaster.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ class Broadcaster {
181181
m_broadcaster_sp->BroadcastEvent(event_type);
182182
}
183183

184-
void BroadcastEventIfUnique(uint32_t event_type,
185-
EventData *event_data = nullptr) {
186-
m_broadcaster_sp->BroadcastEventIfUnique(event_type, event_data);
184+
void BroadcastEventIfUnique(uint32_t event_type) {
185+
m_broadcaster_sp->BroadcastEventIfUnique(event_type);
187186
}
188187

189188
void Clear() { m_broadcaster_sp->Clear(); }
@@ -351,8 +350,7 @@ class Broadcaster {
351350
void BroadcastEvent(uint32_t event_type,
352351
const lldb::EventDataSP &event_data_sp);
353352

354-
void BroadcastEventIfUnique(uint32_t event_type,
355-
EventData *event_data = nullptr);
353+
void BroadcastEventIfUnique(uint32_t event_type);
356354

357355
void Clear();
358356

lldb/source/Target/Process.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4281,25 +4281,31 @@ void Process::CalculateExecutionContext(ExecutionContext &exe_ctx) {
42814281
// return Host::GetArchSpecForExistingProcess (process_name);
42824282
//}
42834283

4284+
EventSP Process::CreateEventFromProcessState(uint32_t event_type) {
4285+
auto event_data_sp =
4286+
std::make_shared<ProcessEventData>(shared_from_this(), GetState());
4287+
return std::make_shared<Event>(event_type, event_data_sp);
4288+
}
4289+
42844290
void Process::AppendSTDOUT(const char *s, size_t len) {
42854291
std::lock_guard<std::recursive_mutex> guard(m_stdio_communication_mutex);
42864292
m_stdout_data.append(s, len);
4287-
BroadcastEventIfUnique(eBroadcastBitSTDOUT,
4288-
new ProcessEventData(shared_from_this(), GetState()));
4293+
auto event_sp = CreateEventFromProcessState(eBroadcastBitSTDOUT);
4294+
BroadcastEventIfUnique(event_sp);
42894295
}
42904296

42914297
void Process::AppendSTDERR(const char *s, size_t len) {
42924298
std::lock_guard<std::recursive_mutex> guard(m_stdio_communication_mutex);
42934299
m_stderr_data.append(s, len);
4294-
BroadcastEventIfUnique(eBroadcastBitSTDERR,
4295-
new ProcessEventData(shared_from_this(), GetState()));
4300+
auto event_sp = CreateEventFromProcessState(eBroadcastBitSTDERR);
4301+
BroadcastEventIfUnique(event_sp);
42964302
}
42974303

42984304
void Process::BroadcastAsyncProfileData(const std::string &one_profile_data) {
42994305
std::lock_guard<std::recursive_mutex> guard(m_profile_data_comm_mutex);
43004306
m_profile_data.push_back(one_profile_data);
4301-
BroadcastEventIfUnique(eBroadcastBitProfileData,
4302-
new ProcessEventData(shared_from_this(), GetState()));
4307+
auto event_sp = CreateEventFromProcessState(eBroadcastBitProfileData);
4308+
BroadcastEventIfUnique(event_sp);
43034309
}
43044310

43054311
void Process::BroadcastStructuredData(const StructuredData::ObjectSP &object_sp,

lldb/source/Utility/Broadcaster.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,8 @@ void Broadcaster::BroadcasterImpl::BroadcastEvent(
311311
PrivateBroadcastEvent(event_sp, false);
312312
}
313313

314-
void Broadcaster::BroadcasterImpl::BroadcastEventIfUnique(
315-
uint32_t event_type, EventData *event_data) {
316-
auto event_sp = std::make_shared<Event>(event_type, event_data);
314+
void Broadcaster::BroadcasterImpl::BroadcastEventIfUnique(uint32_t event_type) {
315+
auto event_sp = std::make_shared<Event>(event_type, /*data = */ nullptr);
317316
PrivateBroadcastEvent(event_sp, true);
318317
}
319318

0 commit comments

Comments
 (0)