Fix some test failures for Windows.
llvm-svn: 223982
diff --git a/lldb/source/Plugins/Process/Windows/DebuggerThread.h b/lldb/source/Plugins/Process/Windows/DebuggerThread.h
index 586a1a7..a11aede 100644
--- a/lldb/source/Plugins/Process/Windows/DebuggerThread.h
+++ b/lldb/source/Plugins/Process/Windows/DebuggerThread.h
@@ -10,14 +10,14 @@
#ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_
#define liblldb_Plugins_Process_Windows_DebuggerThread_H_
+#include <memory>
+
#include "ForwardDecl.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Predicate.h"
#include "lldb/Host/windows/windows.h"
-#include <memory>
-
namespace lldb_private
{
@@ -45,10 +45,10 @@
{
return m_main_thread;
}
- ExceptionRecord *
+ std::weak_ptr<ExceptionRecord>
GetActiveException()
{
- return m_active_exception.get();
+ return m_active_exception;
}
Error StopDebugging(bool terminate);
@@ -74,7 +74,7 @@
HostThread m_main_thread; // The main thread of the inferior.
HANDLE m_image_file; // The image file of the process being debugged.
- ExceptionRecordUP m_active_exception; // The current exception waiting to be handled
+ ExceptionRecordSP m_active_exception; // The current exception waiting to be handled
Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception
// is finished processing and the debug loop can be
diff --git a/lldb/source/Plugins/Process/Windows/ForwardDecl.h b/lldb/source/Plugins/Process/Windows/ForwardDecl.h
index afc7e6a..5b35b9c 100644
--- a/lldb/source/Plugins/Process/Windows/ForwardDecl.h
+++ b/lldb/source/Plugins/Process/Windows/ForwardDecl.h
@@ -34,6 +34,7 @@
typedef std::shared_ptr<IDebugDelegate> DebugDelegateSP;
typedef std::shared_ptr<DebuggerThread> DebuggerThreadSP;
+typedef std::shared_ptr<ExceptionRecord> ExceptionRecordSP;
typedef std::unique_ptr<ExceptionRecord> ExceptionRecordUP;
}
diff --git a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp
index bedecd4..1d914df 100644
--- a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp
@@ -237,10 +237,13 @@
Error
ProcessWindows::DoResume()
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
Error error;
if (GetPrivateState() == eStateStopped || GetPrivateState() == eStateCrashed)
{
- if (m_session_data->m_debugger->GetActiveException())
+ ExceptionRecordSP active_exception = m_session_data->m_debugger->GetActiveException().lock();
+ if (active_exception)
{
// Resume the process and continue processing debug events. Mask the exception so that
// from the process's view, there is no indication that anything happened.
@@ -278,6 +281,8 @@
Error
ProcessWindows::DoDestroy()
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
Error error;
if (GetPrivateState() != eStateExited && GetPrivateState() != eStateDetached && m_session_data)
{
@@ -291,9 +296,15 @@
void
ProcessWindows::RefreshStateAfterStop()
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
+ if (!m_session_data)
+ return;
+
m_thread_list.RefreshStateAfterStop();
- ExceptionRecord *active_exception = m_session_data->m_debugger->GetActiveException();
+ std::weak_ptr<ExceptionRecord> exception_record = m_session_data->m_debugger->GetActiveException();
+ ExceptionRecordSP active_exception = exception_record.lock();
if (!active_exception)
return;
@@ -365,6 +376,8 @@
void ProcessWindows::DidLaunch()
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
StateType state = GetPrivateState();
// The initial stop won't broadcast the state change event, so account for that here.
if (m_session_data && GetPrivateState() == eStateStopped &&
@@ -381,6 +394,8 @@
if (!m_session_data)
return 0;
+ llvm::sys::ScopedLock lock(m_mutex);
+
HostProcess process = m_session_data->m_debugger->GetProcess();
void *addr = reinterpret_cast<void *>(vm_addr);
SIZE_T bytes_read = 0;
@@ -395,6 +410,8 @@
if (!m_session_data)
return 0;
+ llvm::sys::ScopedLock lock(m_mutex);
+
HostProcess process = m_session_data->m_debugger->GetProcess();
void *addr = reinterpret_cast<void *>(vm_addr);
SIZE_T bytes_written = 0;
@@ -434,6 +451,8 @@
void
ProcessWindows::OnExitProcess(uint32_t exit_code)
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
ModuleSP executable_module = GetTarget().GetExecutableModule();
ModuleList unloaded_modules;
unloaded_modules.Append(executable_module);
@@ -448,6 +467,8 @@
{
// Either we successfully attached to an existing process, or we successfully launched a new
// process under the debugger.
+ llvm::sys::ScopedLock lock(m_mutex);
+
ModuleSP module = GetTarget().GetExecutableModule();
bool load_addr_changed;
module->SetLoadAddress(GetTarget(), image_base, false, load_addr_changed);
@@ -466,6 +487,16 @@
ExceptionResult
ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &record)
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
+ // FIXME: Without this check, occasionally when running the test suite there is
+ // an issue where m_session_data can be null. It's not clear how this could happen
+ // but it only surfaces while running the test suite. In order to properly diagnose
+ // this, we probably need to first figure allow the test suite to print out full
+ // lldb logs, and then add logging to the process plugin.
+ if (!m_session_data)
+ return ExceptionResult::SendToApplication;
+
ExceptionResult result = ExceptionResult::SendToApplication;
switch (record.GetExceptionCode())
{
@@ -511,6 +542,8 @@
void
ProcessWindows::OnCreateThread(const HostThread &new_thread)
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
const HostThreadWindows &wnew_thread = new_thread.GetNativeThread();
m_session_data->m_new_threads[wnew_thread.GetThreadId()] = new_thread;
}
@@ -518,6 +551,8 @@
void
ProcessWindows::OnExitThread(const HostThread &exited_thread)
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
// A thread may have started and exited before the debugger stopped allowing a refresh.
// Just remove it from the new threads list in that case.
const HostThreadWindows &wexited_thread = exited_thread.GetNativeThread();
@@ -531,6 +566,8 @@
void
ProcessWindows::OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr)
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
// Confusingly, there is no Target::AddSharedModule. Instead, calling GetSharedModule() with
// a new module will add it to the module list and return a corresponding ModuleSP.
Error error;
@@ -546,6 +583,8 @@
void
ProcessWindows::OnUnloadDll(lldb::addr_t module_addr)
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
Address resolved_addr;
if (GetTarget().ResolveLoadAddress(module_addr, resolved_addr))
{
@@ -567,6 +606,8 @@
void
ProcessWindows::OnDebuggerError(const Error &error, uint32_t type)
{
+ llvm::sys::ScopedLock lock(m_mutex);
+
if (!m_session_data->m_initial_stop_received)
{
// If we haven't actually launched the process yet, this was an error launching the
diff --git a/lldb/source/Plugins/Process/Windows/ProcessWindows.h b/lldb/source/Plugins/Process/Windows/ProcessWindows.h
index 61afcba..dee8b78 100644
--- a/lldb/source/Plugins/Process/Windows/ProcessWindows.h
+++ b/lldb/source/Plugins/Process/Windows/ProcessWindows.h
@@ -24,6 +24,8 @@
#include "lldb/Host/HostThread.h"
#include "lldb/Target/Process.h"
+#include "llvm/Support/Mutex.h"
+
class ProcessMonitor;
namespace lldb_private
@@ -113,6 +115,8 @@
void OnDebuggerError(const lldb_private::Error &error, uint32_t type) override;
private:
+ llvm::sys::Mutex m_mutex;
+
// Data for the active debugging session.
std::unique_ptr<lldb_private::ProcessWindowsData> m_session_data;
};