@@ -251,6 +251,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
251
251
g_debugger_properties[ePropertyShowStatusline].name ) {
252
252
// Statusline setting changed. If we have a statusline instance, update it
253
253
// now. Otherwise it will get created in the default event handler.
254
+ std::lock_guard<std::mutex> guard (m_statusline_mutex);
254
255
if (StatuslineSupported ())
255
256
m_statusline.emplace (*this );
256
257
else
@@ -391,8 +392,13 @@ bool Debugger::SetTerminalWidth(uint64_t term_width) {
391
392
392
393
if (auto handler_sp = m_io_handler_stack.Top ())
393
394
handler_sp->TerminalSizeChanged ();
394
- if (m_statusline)
395
- m_statusline->TerminalSizeChanged ();
395
+
396
+ {
397
+ // This might get called from a signal handler.
398
+ std::unique_lock<std::mutex> lock (m_statusline_mutex, std::try_to_lock);
399
+ if (m_statusline)
400
+ m_statusline->TerminalSizeChanged ();
401
+ }
396
402
397
403
return success;
398
404
}
@@ -409,8 +415,13 @@ bool Debugger::SetTerminalHeight(uint64_t term_height) {
409
415
410
416
if (auto handler_sp = m_io_handler_stack.Top ())
411
417
handler_sp->TerminalSizeChanged ();
412
- if (m_statusline)
413
- m_statusline->TerminalSizeChanged ();
418
+
419
+ {
420
+ // This might get called from a signal handler.
421
+ std::unique_lock<std::mutex> lock (m_statusline_mutex, std::try_to_lock);
422
+ if (m_statusline)
423
+ m_statusline->TerminalSizeChanged ();
424
+ }
414
425
415
426
return success;
416
427
}
@@ -1141,20 +1152,29 @@ void Debugger::SetErrorFile(FileSP file_sp) {
1141
1152
}
1142
1153
1143
1154
void Debugger::SaveInputTerminalState () {
1144
- if (m_statusline)
1145
- m_statusline->Disable ();
1155
+ {
1156
+ // This might get called from a signal handler.
1157
+ std::unique_lock<std::mutex> lock (m_statusline_mutex, std::try_to_lock);
1158
+ if (m_statusline)
1159
+ m_statusline->Disable ();
1160
+ }
1146
1161
int fd = GetInputFile ().GetDescriptor ();
1147
1162
if (fd != File::kInvalidDescriptor )
1148
1163
m_terminal_state.Save (fd, true );
1149
1164
}
1150
1165
1151
1166
void Debugger::RestoreInputTerminalState () {
1152
1167
m_terminal_state.Restore ();
1153
- if (m_statusline)
1154
- m_statusline->Enable ();
1168
+ {
1169
+ // This might get called from a signal handler.
1170
+ std::unique_lock<std::mutex> lock (m_statusline_mutex, std::try_to_lock);
1171
+ if (m_statusline)
1172
+ m_statusline->Enable ();
1173
+ }
1155
1174
}
1156
1175
1157
1176
void Debugger::RedrawStatusline (bool update) {
1177
+ std::lock_guard<std::mutex> guard (m_statusline_mutex);
1158
1178
if (m_statusline)
1159
1179
m_statusline->Redraw (update);
1160
1180
}
@@ -2032,8 +2052,11 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
2032
2052
// are now listening to all required events so no events get missed
2033
2053
m_sync_broadcaster.BroadcastEvent (eBroadcastBitEventThreadIsListening);
2034
2054
2035
- if (!m_statusline && StatuslineSupported ())
2036
- m_statusline.emplace (*this );
2055
+ if (StatuslineSupported ()) {
2056
+ std::lock_guard<std::mutex> guard (m_statusline_mutex);
2057
+ if (!m_statusline)
2058
+ m_statusline.emplace (*this );
2059
+ }
2037
2060
2038
2061
bool done = false ;
2039
2062
while (!done) {
@@ -2094,8 +2117,11 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
2094
2117
}
2095
2118
}
2096
2119
2097
- if (m_statusline)
2098
- m_statusline.reset ();
2120
+ {
2121
+ std::lock_guard<std::mutex> guard (m_statusline_mutex);
2122
+ if (m_statusline)
2123
+ m_statusline.reset ();
2124
+ }
2099
2125
2100
2126
return {};
2101
2127
}
0 commit comments