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_
#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 @@ class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
{
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 @@ class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
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

View File

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

View File

@ -237,10 +237,13 @@ ProcessWindows::DoLaunch(Module *exe_module,
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 @@ ProcessWindows::DoDetach(bool keep_stopped)
Error
ProcessWindows::DoDestroy()
{
llvm::sys::ScopedLock lock(m_mutex);
Error error;
if (GetPrivateState() != eStateExited && GetPrivateState() != eStateDetached && m_session_data)
{
@ -291,9 +296,15 @@ ProcessWindows::DoDestroy()
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 @@ ProcessWindows::DoHalt(bool &caused_stop)
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 @@ ProcessWindows::DoReadMemory(lldb::addr_t vm_addr,
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 @@ ProcessWindows::DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size
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 @@ ProcessWindows::CanDebug(Target &target, bool plugin_specified_by_name)
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 @@ ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base)
{
// 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 @@ ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base)
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 @@ ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &recor
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 @@ ProcessWindows::OnCreateThread(const HostThread &new_thread)
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 @@ ProcessWindows::OnExitThread(const HostThread &exited_thread)
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 @@ ProcessWindows::OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_add
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 @@ ProcessWindows::OnDebugString(const std::string &string)
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

View File

@ -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 @@ public:
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;
};