[Lldb-commits] [lldb] r223982 - Fix some test failures for Windows.
Zachary Turner
zturner at google.com
Wed Dec 10 15:25:11 PST 2014
Author: zturner
Date: Wed Dec 10 17:25:10 2014
New Revision: 223982
URL: http://llvm.org/viewvc/llvm-project?rev=223982&view=rev
Log:
Fix some test failures for Windows.
Modified:
lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h
lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h
lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h
Modified: lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h?rev=223982&r1=223981&r2=223982&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h Wed Dec 10 17:25:10 2014
@@ -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::enabl
{
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::enabl
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
Modified: lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h?rev=223982&r1=223981&r2=223982&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h Wed Dec 10 17:25:10 2014
@@ -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;
}
Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp?rev=223982&r1=223981&r2=223982&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp Wed Dec 10 17:25:10 2014
@@ -237,10 +237,13 @@ ProcessWindows::DoLaunch(Module *exe_mod
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_stopp
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_
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
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,
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
{
// 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
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 fi
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 Hos
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 HostT
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 ModuleSp
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:
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
Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h?rev=223982&r1=223981&r2=223982&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h Wed Dec 10 17:25:10 2014
@@ -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;
};
More information about the lldb-commits
mailing list