@@ -253,16 +253,18 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
253253 // Statusline setting changed. If we have a statusline instance, update it
254254 // now. Otherwise it will get created in the default event handler.
255255 std::lock_guard<std::mutex> guard (m_statusline_mutex);
256- if (StatuslineSupported ())
256+ if (StatuslineSupported ()) {
257257 m_statusline.emplace (*this );
258- else
258+ m_statusline->Enable (GetSelectedExecutionContextRef ());
259+ } else {
259260 m_statusline.reset ();
261+ }
260262 } else if (property_path ==
261263 g_debugger_properties[ePropertyStatuslineFormat].name ||
262264 property_path ==
263265 g_debugger_properties[ePropertySeparator].name ) {
264266 // Statusline format changed. Redraw the statusline.
265- RedrawStatusline ();
267+ RedrawStatusline (std:: nullopt );
266268 } else if (property_path ==
267269 g_debugger_properties[ePropertyUseSourceCache].name ) {
268270 // use-source-cache changed. Wipe out the cache contents if it was
@@ -501,7 +503,7 @@ FormatEntity::Entry Debugger::GetStatuslineFormat() const {
501503bool Debugger::SetStatuslineFormat (const FormatEntity::Entry &format) {
502504 constexpr uint32_t idx = ePropertyStatuslineFormat;
503505 bool ret = SetPropertyAtIndex (idx, format);
504- RedrawStatusline ();
506+ RedrawStatusline (std:: nullopt );
505507 return ret;
506508}
507509
@@ -526,7 +528,7 @@ llvm::StringRef Debugger::GetDisabledAnsiSuffix() const {
526528bool Debugger::SetSeparator (llvm::StringRef s) {
527529 constexpr uint32_t idx = ePropertySeparator;
528530 bool ret = SetPropertyAtIndex (idx, s);
529- RedrawStatusline ();
531+ RedrawStatusline (std:: nullopt );
530532 return ret;
531533}
532534
@@ -1210,14 +1212,18 @@ void Debugger::RestoreInputTerminalState() {
12101212 {
12111213 std::lock_guard<std::mutex> guard (m_statusline_mutex);
12121214 if (m_statusline)
1213- m_statusline->Enable ();
1215+ m_statusline->Enable (GetSelectedExecutionContext () );
12141216 }
12151217}
12161218
1217- void Debugger::RedrawStatusline (bool update) {
1219+ void Debugger::RedrawStatusline (
1220+ std::optional<ExecutionContextRef> exe_ctx_ref) {
12181221 std::lock_guard<std::mutex> guard (m_statusline_mutex);
1219- if (m_statusline)
1220- m_statusline->Redraw (update);
1222+
1223+ if (!m_statusline)
1224+ return ;
1225+
1226+ m_statusline->Redraw (exe_ctx_ref);
12211227}
12221228
12231229ExecutionContext Debugger::GetSelectedExecutionContext () {
@@ -1226,6 +1232,13 @@ ExecutionContext Debugger::GetSelectedExecutionContext() {
12261232 return ExecutionContext (exe_ctx_ref);
12271233}
12281234
1235+ ExecutionContextRef Debugger::GetSelectedExecutionContextRef () {
1236+ if (TargetSP selected_target_sp = GetSelectedTarget ())
1237+ return ExecutionContextRef (selected_target_sp.get (),
1238+ /* adopt_selected=*/ true );
1239+ return ExecutionContextRef (m_dummy_target_sp.get (), /* adopt_selected=*/ false );
1240+ }
1241+
12291242void Debugger::DispatchInputInterrupt () {
12301243 std::lock_guard<std::recursive_mutex> guard (m_io_handler_stack.GetMutex ());
12311244 IOHandlerSP reader_sp (m_io_handler_stack.Top ());
@@ -1980,8 +1993,7 @@ void Debugger::FlushProcessOutput(Process &process, bool flush_stdout,
19801993}
19811994
19821995// This function handles events that were broadcast by the process.
1983- void Debugger::HandleProcessEvent (const EventSP &event_sp) {
1984- using namespace lldb ;
1996+ ProcessSP Debugger::HandleProcessEvent (const EventSP &event_sp) {
19851997 const uint32_t event_type = event_sp->GetType ();
19861998 ProcessSP process_sp =
19871999 (event_type == Process::eBroadcastBitStructuredData)
@@ -2076,23 +2088,24 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
20762088 process_sp->PopProcessIOHandler (pop_command_interpreter);
20772089 // END SWIFT
20782090 }
2091+ return process_sp;
20792092}
20802093
2081- void Debugger::HandleThreadEvent (const EventSP &event_sp) {
2094+ ThreadSP Debugger::HandleThreadEvent (const EventSP &event_sp) {
20822095 // At present the only thread event we handle is the Frame Changed event, and
20832096 // all we do for that is just reprint the thread status for that thread.
2084- using namespace lldb ;
20852097 const uint32_t event_type = event_sp->GetType ();
20862098 const bool stop_format = true ;
2099+ ThreadSP thread_sp;
20872100 if (event_type == Thread::eBroadcastBitStackChanged ||
20882101 event_type == Thread::eBroadcastBitThreadSelected) {
2089- ThreadSP thread_sp (
2090- Thread::ThreadEventData::GetThreadFromEvent (event_sp.get ()));
2102+ thread_sp = Thread::ThreadEventData::GetThreadFromEvent (event_sp.get ());
20912103 if (thread_sp) {
20922104 thread_sp->GetStatus (*GetAsyncOutputStream (), 0 , 1 , 1 , stop_format,
20932105 /* show_hidden*/ true );
20942106 }
20952107 }
2108+ return thread_sp;
20962109}
20972110
20982111bool Debugger::IsForwardingEvents () { return (bool )m_forward_listener_sp; }
@@ -2120,6 +2133,11 @@ bool Debugger::StatuslineSupported() {
21202133 return false ;
21212134}
21222135
2136+ static bool RequiresFollowChildWorkaround (const Process &process) {
2137+ // FIXME: https://github.com/llvm/llvm-project/issues/160216
2138+ return process.GetFollowForkMode () == eFollowChild;
2139+ }
2140+
21232141lldb::thread_result_t Debugger::DefaultEventHandler () {
21242142 ListenerSP listener_sp (GetListener ());
21252143 ConstString broadcaster_class_target (Target::GetStaticBroadcasterClass ());
@@ -2161,28 +2179,37 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
21612179
21622180 if (StatuslineSupported ()) {
21632181 std::lock_guard<std::mutex> guard (m_statusline_mutex);
2164- if (!m_statusline)
2182+ if (!m_statusline) {
21652183 m_statusline.emplace (*this );
2184+ m_statusline->Enable (GetSelectedExecutionContextRef ());
2185+ }
21662186 }
21672187
21682188 bool done = false ;
21692189 while (!done) {
21702190 EventSP event_sp;
21712191 if (listener_sp->GetEvent (event_sp, std::nullopt )) {
2192+ std::optional<ExecutionContextRef> exe_ctx_ref = std::nullopt ;
21722193 if (event_sp) {
21732194 Broadcaster *broadcaster = event_sp->GetBroadcaster ();
21742195 if (broadcaster) {
21752196 uint32_t event_type = event_sp->GetType ();
21762197 ConstString broadcaster_class (broadcaster->GetBroadcasterClass ());
21772198 if (broadcaster_class == broadcaster_class_process) {
2178- HandleProcessEvent (event_sp);
2199+ if (ProcessSP process_sp = HandleProcessEvent (event_sp))
2200+ if (!RequiresFollowChildWorkaround (*process_sp))
2201+ exe_ctx_ref = ExecutionContextRef (process_sp.get (),
2202+ /* adopt_selected=*/ true );
21792203 } else if (broadcaster_class == broadcaster_class_target) {
21802204 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent (
21812205 event_sp.get ())) {
21822206 HandleBreakpointEvent (event_sp);
21832207 }
21842208 } else if (broadcaster_class == broadcaster_class_thread) {
2185- HandleThreadEvent (event_sp);
2209+ if (ThreadSP thread_sp = HandleThreadEvent (event_sp))
2210+ if (!RequiresFollowChildWorkaround (*thread_sp->GetProcess ()))
2211+ exe_ctx_ref = ExecutionContextRef (thread_sp.get (),
2212+ /* adopt_selected=*/ true );
21862213 } else if (broadcaster == m_command_interpreter_up.get ()) {
21872214 if (event_type &
21882215 CommandInterpreter::eBroadcastBitQuitCommandReceived) {
@@ -2220,7 +2247,7 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
22202247 if (m_forward_listener_sp)
22212248 m_forward_listener_sp->AddEvent (event_sp);
22222249 }
2223- RedrawStatusline ();
2250+ RedrawStatusline (exe_ctx_ref );
22242251 }
22252252 }
22262253
0 commit comments