Fix some test failures for Windows.

llvm-svn: 223982
This commit is contained in:
Zachary Turner 2014-12-10 23:25:10 +00:00
parent ceeaba7932
commit fb6c3494e7
4 changed files with 53 additions and 7 deletions

View File

@ -10,14 +10,14 @@
#ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_ #ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_
#define liblldb_Plugins_Process_Windows_DebuggerThread_H_ #define liblldb_Plugins_Process_Windows_DebuggerThread_H_
#include <memory>
#include "ForwardDecl.h" #include "ForwardDecl.h"
#include "lldb/Host/HostProcess.h" #include "lldb/Host/HostProcess.h"
#include "lldb/Host/HostThread.h" #include "lldb/Host/HostThread.h"
#include "lldb/Host/Predicate.h" #include "lldb/Host/Predicate.h"
#include "lldb/Host/windows/windows.h" #include "lldb/Host/windows/windows.h"
#include <memory>
namespace lldb_private namespace lldb_private
{ {
@ -45,10 +45,10 @@ class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
{ {
return m_main_thread; return m_main_thread;
} }
ExceptionRecord * std::weak_ptr<ExceptionRecord>
GetActiveException() GetActiveException()
{ {
return m_active_exception.get(); return m_active_exception;
} }
Error StopDebugging(bool terminate); Error StopDebugging(bool terminate);
@ -74,7 +74,7 @@ class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
HostThread m_main_thread; // The main thread of the inferior. HostThread m_main_thread; // The main thread of the inferior.
HANDLE m_image_file; // The image file of the process being debugged. 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 Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception
// is finished processing and the debug loop can be // is finished processing and the debug loop can be

View File

@ -34,6 +34,7 @@ class ExceptionRecord;
typedef std::shared_ptr<IDebugDelegate> DebugDelegateSP; typedef std::shared_ptr<IDebugDelegate> DebugDelegateSP;
typedef std::shared_ptr<DebuggerThread> DebuggerThreadSP; typedef std::shared_ptr<DebuggerThread> DebuggerThreadSP;
typedef std::shared_ptr<ExceptionRecord> ExceptionRecordSP;
typedef std::unique_ptr<ExceptionRecord> ExceptionRecordUP; typedef std::unique_ptr<ExceptionRecord> ExceptionRecordUP;
} }

View File

@ -237,10 +237,13 @@ ProcessWindows::DoLaunch(Module *exe_module,
Error Error
ProcessWindows::DoResume() ProcessWindows::DoResume()
{ {
llvm::sys::ScopedLock lock(m_mutex);
Error error; Error error;
if (GetPrivateState() == eStateStopped || GetPrivateState() == eStateCrashed) 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 // 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. // from the process's view, there is no indication that anything happened.
@ -278,6 +281,8 @@ ProcessWindows::DoDetach(bool keep_stopped)
Error Error
ProcessWindows::DoDestroy() ProcessWindows::DoDestroy()
{ {
llvm::sys::ScopedLock lock(m_mutex);
Error error; Error error;
if (GetPrivateState() != eStateExited && GetPrivateState() != eStateDetached && m_session_data) if (GetPrivateState() != eStateExited && GetPrivateState() != eStateDetached && m_session_data)
{ {
@ -291,9 +296,15 @@ ProcessWindows::DoDestroy()
void void
ProcessWindows::RefreshStateAfterStop() ProcessWindows::RefreshStateAfterStop()
{ {
llvm::sys::ScopedLock lock(m_mutex);
if (!m_session_data)
return;
m_thread_list.RefreshStateAfterStop(); 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) if (!active_exception)
return; return;
@ -365,6 +376,8 @@ ProcessWindows::DoHalt(bool &caused_stop)
void ProcessWindows::DidLaunch() void ProcessWindows::DidLaunch()
{ {
llvm::sys::ScopedLock lock(m_mutex);
StateType state = GetPrivateState(); StateType state = GetPrivateState();
// The initial stop won't broadcast the state change event, so account for that here. // The initial stop won't broadcast the state change event, so account for that here.
if (m_session_data && GetPrivateState() == eStateStopped && if (m_session_data && GetPrivateState() == eStateStopped &&
@ -381,6 +394,8 @@ ProcessWindows::DoReadMemory(lldb::addr_t vm_addr,
if (!m_session_data) if (!m_session_data)
return 0; return 0;
llvm::sys::ScopedLock lock(m_mutex);
HostProcess process = m_session_data->m_debugger->GetProcess(); HostProcess process = m_session_data->m_debugger->GetProcess();
void *addr = reinterpret_cast<void *>(vm_addr); void *addr = reinterpret_cast<void *>(vm_addr);
SIZE_T bytes_read = 0; SIZE_T bytes_read = 0;
@ -395,6 +410,8 @@ ProcessWindows::DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size
if (!m_session_data) if (!m_session_data)
return 0; return 0;
llvm::sys::ScopedLock lock(m_mutex);
HostProcess process = m_session_data->m_debugger->GetProcess(); HostProcess process = m_session_data->m_debugger->GetProcess();
void *addr = reinterpret_cast<void *>(vm_addr); void *addr = reinterpret_cast<void *>(vm_addr);
SIZE_T bytes_written = 0; SIZE_T bytes_written = 0;
@ -434,6 +451,8 @@ ProcessWindows::CanDebug(Target &target, bool plugin_specified_by_name)
void void
ProcessWindows::OnExitProcess(uint32_t exit_code) ProcessWindows::OnExitProcess(uint32_t exit_code)
{ {
llvm::sys::ScopedLock lock(m_mutex);
ModuleSP executable_module = GetTarget().GetExecutableModule(); ModuleSP executable_module = GetTarget().GetExecutableModule();
ModuleList unloaded_modules; ModuleList unloaded_modules;
unloaded_modules.Append(executable_module); unloaded_modules.Append(executable_module);
@ -448,6 +467,8 @@ ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base)
{ {
// Either we successfully attached to an existing process, or we successfully launched a new // Either we successfully attached to an existing process, or we successfully launched a new
// process under the debugger. // process under the debugger.
llvm::sys::ScopedLock lock(m_mutex);
ModuleSP module = GetTarget().GetExecutableModule(); ModuleSP module = GetTarget().GetExecutableModule();
bool load_addr_changed; bool load_addr_changed;
module->SetLoadAddress(GetTarget(), image_base, false, load_addr_changed); module->SetLoadAddress(GetTarget(), image_base, false, load_addr_changed);
@ -466,6 +487,16 @@ ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base)
ExceptionResult ExceptionResult
ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &record) 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; ExceptionResult result = ExceptionResult::SendToApplication;
switch (record.GetExceptionCode()) switch (record.GetExceptionCode())
{ {
@ -511,6 +542,8 @@ ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &recor
void void
ProcessWindows::OnCreateThread(const HostThread &new_thread) ProcessWindows::OnCreateThread(const HostThread &new_thread)
{ {
llvm::sys::ScopedLock lock(m_mutex);
const HostThreadWindows &wnew_thread = new_thread.GetNativeThread(); const HostThreadWindows &wnew_thread = new_thread.GetNativeThread();
m_session_data->m_new_threads[wnew_thread.GetThreadId()] = new_thread; m_session_data->m_new_threads[wnew_thread.GetThreadId()] = new_thread;
} }
@ -518,6 +551,8 @@ ProcessWindows::OnCreateThread(const HostThread &new_thread)
void void
ProcessWindows::OnExitThread(const HostThread &exited_thread) 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. // 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. // Just remove it from the new threads list in that case.
const HostThreadWindows &wexited_thread = exited_thread.GetNativeThread(); const HostThreadWindows &wexited_thread = exited_thread.GetNativeThread();
@ -531,6 +566,8 @@ ProcessWindows::OnExitThread(const HostThread &exited_thread)
void void
ProcessWindows::OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) 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 // 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. // a new module will add it to the module list and return a corresponding ModuleSP.
Error error; Error error;
@ -546,6 +583,8 @@ ProcessWindows::OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_add
void void
ProcessWindows::OnUnloadDll(lldb::addr_t module_addr) ProcessWindows::OnUnloadDll(lldb::addr_t module_addr)
{ {
llvm::sys::ScopedLock lock(m_mutex);
Address resolved_addr; Address resolved_addr;
if (GetTarget().ResolveLoadAddress(module_addr, resolved_addr)) if (GetTarget().ResolveLoadAddress(module_addr, resolved_addr))
{ {
@ -567,6 +606,8 @@ ProcessWindows::OnDebugString(const std::string &string)
void void
ProcessWindows::OnDebuggerError(const Error &error, uint32_t type) ProcessWindows::OnDebuggerError(const Error &error, uint32_t type)
{ {
llvm::sys::ScopedLock lock(m_mutex);
if (!m_session_data->m_initial_stop_received) if (!m_session_data->m_initial_stop_received)
{ {
// If we haven't actually launched the process yet, this was an error launching the // If we haven't actually launched the process yet, this was an error launching the

View File

@ -24,6 +24,8 @@
#include "lldb/Host/HostThread.h" #include "lldb/Host/HostThread.h"
#include "lldb/Target/Process.h" #include "lldb/Target/Process.h"
#include "llvm/Support/Mutex.h"
class ProcessMonitor; class ProcessMonitor;
namespace lldb_private namespace lldb_private
@ -113,6 +115,8 @@ public:
void OnDebuggerError(const lldb_private::Error &error, uint32_t type) override; void OnDebuggerError(const lldb_private::Error &error, uint32_t type) override;
private: private:
llvm::sys::Mutex m_mutex;
// Data for the active debugging session. // Data for the active debugging session.
std::unique_ptr<lldb_private::ProcessWindowsData> m_session_data; std::unique_ptr<lldb_private::ProcessWindowsData> m_session_data;
}; };