@@ -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 ());
@@ -1941,8 +1954,7 @@ void Debugger::FlushProcessOutput(Process &process, bool flush_stdout,
19411954}
19421955
19431956// This function handles events that were broadcast by the process.
1944- void Debugger::HandleProcessEvent (const EventSP &event_sp) {
1945- using namespace lldb ;
1957+ ProcessSP Debugger::HandleProcessEvent (const EventSP &event_sp) {
19461958 const uint32_t event_type = event_sp->GetType ();
19471959 ProcessSP process_sp =
19481960 (event_type == Process::eBroadcastBitStructuredData)
@@ -2024,23 +2036,24 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
20242036 if (pop_process_io_handler)
20252037 process_sp->PopProcessIOHandler ();
20262038 }
2039+ return process_sp;
20272040}
20282041
2029- void Debugger::HandleThreadEvent (const EventSP &event_sp) {
2042+ ThreadSP Debugger::HandleThreadEvent (const EventSP &event_sp) {
20302043 // At present the only thread event we handle is the Frame Changed event, and
20312044 // all we do for that is just reprint the thread status for that thread.
2032- using namespace lldb ;
20332045 const uint32_t event_type = event_sp->GetType ();
20342046 const bool stop_format = true ;
2047+ ThreadSP thread_sp;
20352048 if (event_type == Thread::eBroadcastBitStackChanged ||
20362049 event_type == Thread::eBroadcastBitThreadSelected) {
2037- ThreadSP thread_sp (
2038- Thread::ThreadEventData::GetThreadFromEvent (event_sp.get ()));
2050+ thread_sp = Thread::ThreadEventData::GetThreadFromEvent (event_sp.get ());
20392051 if (thread_sp) {
20402052 thread_sp->GetStatus (*GetAsyncOutputStream (), 0 , 1 , 1 , stop_format,
20412053 /* show_hidden*/ true );
20422054 }
20432055 }
2056+ return thread_sp;
20442057}
20452058
20462059bool Debugger::IsForwardingEvents () { return (bool )m_forward_listener_sp; }
@@ -2068,6 +2081,11 @@ bool Debugger::StatuslineSupported() {
20682081 return false ;
20692082}
20702083
2084+ static bool RequiresFollowChildWorkaround (const Process &process) {
2085+ // FIXME: https://github.com/llvm/llvm-project/issues/160216
2086+ return process.GetFollowForkMode () == eFollowChild;
2087+ }
2088+
20712089lldb::thread_result_t Debugger::DefaultEventHandler () {
20722090 ListenerSP listener_sp (GetListener ());
20732091 ConstString broadcaster_class_target (Target::GetStaticBroadcasterClass ());
@@ -2109,28 +2127,37 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
21092127
21102128 if (StatuslineSupported ()) {
21112129 std::lock_guard<std::mutex> guard (m_statusline_mutex);
2112- if (!m_statusline)
2130+ if (!m_statusline) {
21132131 m_statusline.emplace (*this );
2132+ m_statusline->Enable (GetSelectedExecutionContextRef ());
2133+ }
21142134 }
21152135
21162136 bool done = false ;
21172137 while (!done) {
21182138 EventSP event_sp;
21192139 if (listener_sp->GetEvent (event_sp, std::nullopt )) {
2140+ std::optional<ExecutionContextRef> exe_ctx_ref = std::nullopt ;
21202141 if (event_sp) {
21212142 Broadcaster *broadcaster = event_sp->GetBroadcaster ();
21222143 if (broadcaster) {
21232144 uint32_t event_type = event_sp->GetType ();
21242145 ConstString broadcaster_class (broadcaster->GetBroadcasterClass ());
21252146 if (broadcaster_class == broadcaster_class_process) {
2126- HandleProcessEvent (event_sp);
2147+ if (ProcessSP process_sp = HandleProcessEvent (event_sp))
2148+ if (!RequiresFollowChildWorkaround (*process_sp))
2149+ exe_ctx_ref = ExecutionContextRef (process_sp.get (),
2150+ /* adopt_selected=*/ true );
21272151 } else if (broadcaster_class == broadcaster_class_target) {
21282152 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent (
21292153 event_sp.get ())) {
21302154 HandleBreakpointEvent (event_sp);
21312155 }
21322156 } else if (broadcaster_class == broadcaster_class_thread) {
2133- HandleThreadEvent (event_sp);
2157+ if (ThreadSP thread_sp = HandleThreadEvent (event_sp))
2158+ if (!RequiresFollowChildWorkaround (*thread_sp->GetProcess ()))
2159+ exe_ctx_ref = ExecutionContextRef (thread_sp.get (),
2160+ /* adopt_selected=*/ true );
21342161 } else if (broadcaster == m_command_interpreter_up.get ()) {
21352162 if (event_type &
21362163 CommandInterpreter::eBroadcastBitQuitCommandReceived) {
@@ -2168,7 +2195,7 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
21682195 if (m_forward_listener_sp)
21692196 m_forward_listener_sp->AddEvent (event_sp);
21702197 }
2171- RedrawStatusline ();
2198+ RedrawStatusline (exe_ctx_ref );
21722199 }
21732200 }
21742201
0 commit comments