Skip to content

Commit f8c6de8

Browse files
author
Michał Górny
committed
[lldb] [llgs] Refactor SendStopReasonForState for multiprocess
Refactor GDBRemoteCommunicationServerLLGS::SendStopReasonForState() to accept process as an argument rather than hardcoding m_current_process, in order to make it work correctly for multiprocess scenarios. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127497
1 parent af93f12 commit f8c6de8

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,8 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited(
983983
Log *log = GetLog(LLDBLog::Process);
984984
LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
985985

986-
PacketResult result = SendStopReasonForState(StateType::eStateExited);
986+
PacketResult result =
987+
SendStopReasonForState(*process, StateType::eStateExited);
987988
if (result != PacketResult::Success) {
988989
LLDB_LOGF(log,
989990
"GDBRemoteCommunicationServerLLGS::%s failed to send stop "
@@ -1015,7 +1016,8 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped(
10151016
break;
10161017
default:
10171018
// In all other cases, send the stop reason.
1018-
PacketResult result = SendStopReasonForState(StateType::eStateStopped);
1019+
PacketResult result =
1020+
SendStopReasonForState(*process, StateType::eStateStopped);
10191021
if (result != PacketResult::Success) {
10201022
LLDB_LOGF(log,
10211023
"GDBRemoteCommunicationServerLLGS::%s failed to send stop "
@@ -1686,12 +1688,13 @@ GDBRemoteCommunicationServerLLGS::Handle_stop_reason(
16861688
if (!m_current_process)
16871689
return SendErrorResponse(02);
16881690

1689-
return SendStopReasonForState(m_current_process->GetState());
1691+
return SendStopReasonForState(*m_current_process,
1692+
m_current_process->GetState());
16901693
}
16911694

16921695
GDBRemoteCommunication::PacketResult
16931696
GDBRemoteCommunicationServerLLGS::SendStopReasonForState(
1694-
lldb::StateType process_state) {
1697+
NativeProcessProtocol &process, lldb::StateType process_state) {
16951698
Log *log = GetLog(LLDBLog::Process);
16961699

16971700
switch (process_state) {
@@ -1707,22 +1710,21 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState(
17071710
case eStateSuspended:
17081711
case eStateStopped:
17091712
case eStateCrashed: {
1710-
assert(m_current_process != nullptr);
1711-
lldb::tid_t tid = m_current_process->GetCurrentThreadID();
1713+
lldb::tid_t tid = process.GetCurrentThreadID();
17121714
// Make sure we set the current thread so g and p packets return the data
17131715
// the gdb will expect.
17141716
SetCurrentThreadID(tid);
1715-
return SendStopReplyPacketForThread(*m_current_process, tid);
1717+
return SendStopReplyPacketForThread(process, tid);
17161718
}
17171719

17181720
case eStateInvalid:
17191721
case eStateUnloaded:
17201722
case eStateExited:
1721-
return SendWResponse(m_current_process);
1723+
return SendWResponse(&process);
17221724

17231725
default:
17241726
LLDB_LOG(log, "pid {0}, current state reporting not handled: {1}",
1725-
m_current_process->GetID(), process_state);
1727+
process.GetID(), process_state);
17261728
break;
17271729
}
17281730

@@ -3172,7 +3174,9 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttach(
31723174
}
31733175

31743176
// Notify we attached by sending a stop packet.
3175-
return SendStopReasonForState(m_current_process->GetState());
3177+
assert(m_current_process);
3178+
return SendStopReasonForState(*m_current_process,
3179+
m_current_process->GetState());
31763180
}
31773181

31783182
GDBRemoteCommunication::PacketResult
@@ -3202,7 +3206,9 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttachWait(
32023206
}
32033207

32043208
// Notify we attached by sending a stop packet.
3205-
return SendStopReasonForState(m_current_process->GetState());
3209+
assert(m_current_process);
3210+
return SendStopReasonForState(*m_current_process,
3211+
m_current_process->GetState());
32063212
}
32073213

32083214
GDBRemoteCommunication::PacketResult
@@ -3238,7 +3244,9 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttachOrWait(
32383244
}
32393245

32403246
// Notify we attached by sending a stop packet.
3241-
return SendStopReasonForState(m_current_process->GetState());
3247+
assert(m_current_process);
3248+
return SendStopReasonForState(*m_current_process,
3249+
m_current_process->GetState());
32423250
}
32433251

32443252
GDBRemoteCommunication::PacketResult
@@ -3266,8 +3274,11 @@ GDBRemoteCommunicationServerLLGS::Handle_vRun(
32663274
m_process_launch_info.GetExecutableFile().SetFile(
32673275
m_process_launch_info.GetArguments()[0].ref(), FileSpec::Style::native);
32683276
m_process_launch_error = LaunchProcess();
3269-
if (m_process_launch_error.Success())
3270-
return SendStopReasonForState(m_current_process->GetState());
3277+
if (m_process_launch_error.Success()) {
3278+
assert(m_current_process);
3279+
return SendStopReasonForState(*m_current_process,
3280+
m_current_process->GetState());
3281+
}
32713282
LLDB_LOG(log, "failed to launch exe: {0}", m_process_launch_error);
32723283
}
32733284
return SendErrorResponse(8);

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class GDBRemoteCommunicationServerLLGS
116116
PacketResult SendStopReplyPacketForThread(NativeProcessProtocol &process,
117117
lldb::tid_t tid);
118118

119-
PacketResult SendStopReasonForState(lldb::StateType process_state);
119+
PacketResult SendStopReasonForState(NativeProcessProtocol &process,
120+
lldb::StateType process_state);
120121

121122
PacketResult Handle_k(StringExtractorGDBRemote &packet);
122123

0 commit comments

Comments
 (0)