@@ -253,16 +253,18 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
253
253
// Statusline setting changed. If we have a statusline instance, update it
254
254
// now. Otherwise it will get created in the default event handler.
255
255
std::lock_guard<std::mutex> guard (m_statusline_mutex);
256
- if (StatuslineSupported ())
256
+ if (StatuslineSupported ()) {
257
257
m_statusline.emplace (*this );
258
- else
258
+ m_statusline->Enable (GetSelectedExecutionContextRef ());
259
+ } else {
259
260
m_statusline.reset ();
261
+ }
260
262
} else if (property_path ==
261
263
g_debugger_properties[ePropertyStatuslineFormat].name ||
262
264
property_path ==
263
265
g_debugger_properties[ePropertySeparator].name ) {
264
266
// Statusline format changed. Redraw the statusline.
265
- RedrawStatusline ();
267
+ RedrawStatusline (std:: nullopt );
266
268
} else if (property_path ==
267
269
g_debugger_properties[ePropertyUseSourceCache].name ) {
268
270
// use-source-cache changed. Wipe out the cache contents if it was
@@ -501,7 +503,7 @@ FormatEntity::Entry Debugger::GetStatuslineFormat() const {
501
503
bool Debugger::SetStatuslineFormat (const FormatEntity::Entry &format) {
502
504
constexpr uint32_t idx = ePropertyStatuslineFormat;
503
505
bool ret = SetPropertyAtIndex (idx, format);
504
- RedrawStatusline ();
506
+ RedrawStatusline (std:: nullopt );
505
507
return ret;
506
508
}
507
509
@@ -526,7 +528,7 @@ llvm::StringRef Debugger::GetDisabledAnsiSuffix() const {
526
528
bool Debugger::SetSeparator (llvm::StringRef s) {
527
529
constexpr uint32_t idx = ePropertySeparator;
528
530
bool ret = SetPropertyAtIndex (idx, s);
529
- RedrawStatusline ();
531
+ RedrawStatusline (std:: nullopt );
530
532
return ret;
531
533
}
532
534
@@ -1210,14 +1212,18 @@ void Debugger::RestoreInputTerminalState() {
1210
1212
{
1211
1213
std::lock_guard<std::mutex> guard (m_statusline_mutex);
1212
1214
if (m_statusline)
1213
- m_statusline->Enable ();
1215
+ m_statusline->Enable (GetSelectedExecutionContext () );
1214
1216
}
1215
1217
}
1216
1218
1217
- void Debugger::RedrawStatusline (bool update) {
1219
+ void Debugger::RedrawStatusline (
1220
+ std::optional<ExecutionContextRef> exe_ctx_ref) {
1218
1221
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);
1221
1227
}
1222
1228
1223
1229
ExecutionContext Debugger::GetSelectedExecutionContext () {
@@ -1226,6 +1232,13 @@ ExecutionContext Debugger::GetSelectedExecutionContext() {
1226
1232
return ExecutionContext (exe_ctx_ref);
1227
1233
}
1228
1234
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
+
1229
1242
void Debugger::DispatchInputInterrupt () {
1230
1243
std::lock_guard<std::recursive_mutex> guard (m_io_handler_stack.GetMutex ());
1231
1244
IOHandlerSP reader_sp (m_io_handler_stack.Top ());
@@ -1941,8 +1954,7 @@ void Debugger::FlushProcessOutput(Process &process, bool flush_stdout,
1941
1954
}
1942
1955
1943
1956
// 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) {
1946
1958
const uint32_t event_type = event_sp->GetType ();
1947
1959
ProcessSP process_sp =
1948
1960
(event_type == Process::eBroadcastBitStructuredData)
@@ -2024,23 +2036,24 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
2024
2036
if (pop_process_io_handler)
2025
2037
process_sp->PopProcessIOHandler ();
2026
2038
}
2039
+ return process_sp;
2027
2040
}
2028
2041
2029
- void Debugger::HandleThreadEvent (const EventSP &event_sp) {
2042
+ ThreadSP Debugger::HandleThreadEvent (const EventSP &event_sp) {
2030
2043
// At present the only thread event we handle is the Frame Changed event, and
2031
2044
// all we do for that is just reprint the thread status for that thread.
2032
- using namespace lldb ;
2033
2045
const uint32_t event_type = event_sp->GetType ();
2034
2046
const bool stop_format = true ;
2047
+ ThreadSP thread_sp;
2035
2048
if (event_type == Thread::eBroadcastBitStackChanged ||
2036
2049
event_type == Thread::eBroadcastBitThreadSelected) {
2037
- ThreadSP thread_sp (
2038
- Thread::ThreadEventData::GetThreadFromEvent (event_sp.get ()));
2050
+ thread_sp = Thread::ThreadEventData::GetThreadFromEvent (event_sp.get ());
2039
2051
if (thread_sp) {
2040
2052
thread_sp->GetStatus (*GetAsyncOutputStream (), 0 , 1 , 1 , stop_format,
2041
2053
/* show_hidden*/ true );
2042
2054
}
2043
2055
}
2056
+ return thread_sp;
2044
2057
}
2045
2058
2046
2059
bool Debugger::IsForwardingEvents () { return (bool )m_forward_listener_sp; }
@@ -2068,6 +2081,11 @@ bool Debugger::StatuslineSupported() {
2068
2081
return false ;
2069
2082
}
2070
2083
2084
+ static bool RequiresFollowChildWorkaround (const Process &process) {
2085
+ // FIXME: https://github.com/llvm/llvm-project/issues/160216
2086
+ return process.GetFollowForkMode () == eFollowChild;
2087
+ }
2088
+
2071
2089
lldb::thread_result_t Debugger::DefaultEventHandler () {
2072
2090
ListenerSP listener_sp (GetListener ());
2073
2091
ConstString broadcaster_class_target (Target::GetStaticBroadcasterClass ());
@@ -2109,28 +2127,37 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
2109
2127
2110
2128
if (StatuslineSupported ()) {
2111
2129
std::lock_guard<std::mutex> guard (m_statusline_mutex);
2112
- if (!m_statusline)
2130
+ if (!m_statusline) {
2113
2131
m_statusline.emplace (*this );
2132
+ m_statusline->Enable (GetSelectedExecutionContextRef ());
2133
+ }
2114
2134
}
2115
2135
2116
2136
bool done = false ;
2117
2137
while (!done) {
2118
2138
EventSP event_sp;
2119
2139
if (listener_sp->GetEvent (event_sp, std::nullopt )) {
2140
+ std::optional<ExecutionContextRef> exe_ctx_ref = std::nullopt ;
2120
2141
if (event_sp) {
2121
2142
Broadcaster *broadcaster = event_sp->GetBroadcaster ();
2122
2143
if (broadcaster) {
2123
2144
uint32_t event_type = event_sp->GetType ();
2124
2145
ConstString broadcaster_class (broadcaster->GetBroadcasterClass ());
2125
2146
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 );
2127
2151
} else if (broadcaster_class == broadcaster_class_target) {
2128
2152
if (Breakpoint::BreakpointEventData::GetEventDataFromEvent (
2129
2153
event_sp.get ())) {
2130
2154
HandleBreakpointEvent (event_sp);
2131
2155
}
2132
2156
} 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 );
2134
2161
} else if (broadcaster == m_command_interpreter_up.get ()) {
2135
2162
if (event_type &
2136
2163
CommandInterpreter::eBroadcastBitQuitCommandReceived) {
@@ -2168,7 +2195,7 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
2168
2195
if (m_forward_listener_sp)
2169
2196
m_forward_listener_sp->AddEvent (event_sp);
2170
2197
}
2171
- RedrawStatusline ();
2198
+ RedrawStatusline (exe_ctx_ref );
2172
2199
}
2173
2200
}
2174
2201
0 commit comments