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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
8 changes: 3 additions & 5 deletions lldb/include/lldb/Utility/Broadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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();

Expand Down
18 changes: 12 additions & 6 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +4293 to +4294
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.

}

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,
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Utility/Broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down