@@ -629,6 +629,7 @@ void Process::SyncIOHandler(uint32_t iohandler_id,
629
629
const Timeout<std::micro> &timeout) {
630
630
// don't sync (potentially context switch) in case where there is no process
631
631
// IO
632
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
632
633
if (!m_process_input_reader)
633
634
return ;
634
635
@@ -2504,7 +2505,11 @@ Status Process::LaunchPrivate(ProcessLaunchInfo &launch_info, StateType &state,
2504
2505
m_jit_loaders_up.reset ();
2505
2506
m_system_runtime_up.reset ();
2506
2507
m_os_up.reset ();
2507
- m_process_input_reader.reset ();
2508
+
2509
+ {
2510
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
2511
+ m_process_input_reader.reset ();
2512
+ }
2508
2513
2509
2514
Module *exe_module = GetTarget ().GetExecutableModulePointer ();
2510
2515
@@ -2802,7 +2807,10 @@ Status Process::WillAttachToProcessWithName(const char *process_name,
2802
2807
2803
2808
Status Process::Attach (ProcessAttachInfo &attach_info) {
2804
2809
m_abi_sp.reset ();
2805
- m_process_input_reader.reset ();
2810
+ {
2811
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
2812
+ m_process_input_reader.reset ();
2813
+ }
2806
2814
m_dyld_up.reset ();
2807
2815
m_jit_loaders_up.reset ();
2808
2816
m_system_runtime_up.reset ();
@@ -3053,7 +3061,10 @@ void Process::CompleteAttach() {
3053
3061
3054
3062
Status Process::ConnectRemote (llvm::StringRef remote_url) {
3055
3063
m_abi_sp.reset ();
3056
- m_process_input_reader.reset ();
3064
+ {
3065
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
3066
+ m_process_input_reader.reset ();
3067
+ }
3057
3068
3058
3069
// Find the process and its architecture. Make sure it matches the
3059
3070
// architecture of the current Target, and if not adjust it.
@@ -3341,10 +3352,13 @@ Status Process::DestroyImpl(bool force_kill) {
3341
3352
m_stdio_communication.Disconnect ();
3342
3353
m_stdin_forward = false ;
3343
3354
3344
- if (m_process_input_reader) {
3345
- m_process_input_reader->SetIsDone (true );
3346
- m_process_input_reader->Cancel ();
3347
- m_process_input_reader.reset ();
3355
+ {
3356
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
3357
+ if (m_process_input_reader) {
3358
+ m_process_input_reader->SetIsDone (true );
3359
+ m_process_input_reader->Cancel ();
3360
+ m_process_input_reader.reset ();
3361
+ }
3348
3362
}
3349
3363
3350
3364
// If we exited when we were waiting for a process to stop, then forward
@@ -4522,20 +4536,25 @@ void Process::SetSTDIOFileDescriptor(int fd) {
4522
4536
m_stdio_communication.StartReadThread ();
4523
4537
4524
4538
// Now read thread is set up, set up input reader.
4525
-
4526
- if (!m_process_input_reader)
4527
- m_process_input_reader =
4528
- std::make_shared<IOHandlerProcessSTDIO>(this , fd);
4539
+ {
4540
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
4541
+ if (!m_process_input_reader)
4542
+ m_process_input_reader =
4543
+ std::make_shared<IOHandlerProcessSTDIO>(this , fd);
4544
+ }
4529
4545
}
4530
4546
}
4531
4547
4532
4548
bool Process::ProcessIOHandlerIsActive () {
4549
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
4533
4550
IOHandlerSP io_handler_sp (m_process_input_reader);
4534
4551
if (io_handler_sp)
4535
4552
return GetTarget ().GetDebugger ().IsTopIOHandler (io_handler_sp);
4536
4553
return false ;
4537
4554
}
4555
+
4538
4556
bool Process::PushProcessIOHandler () {
4557
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
4539
4558
IOHandlerSP io_handler_sp (m_process_input_reader);
4540
4559
if (io_handler_sp) {
4541
4560
Log *log = GetLog (LLDBLog::Process);
@@ -4555,6 +4574,7 @@ bool Process::PushProcessIOHandler() {
4555
4574
}
4556
4575
4557
4576
bool Process::PopProcessIOHandler () {
4577
+ std::lock_guard<std::mutex> guard (m_process_input_reader_mutex);
4558
4578
IOHandlerSP io_handler_sp (m_process_input_reader);
4559
4579
if (io_handler_sp)
4560
4580
return GetTarget ().GetDebugger ().RemoveIOHandler (io_handler_sp);
0 commit comments