forked from OSchip/llvm-project
[ProcessWindows] Simplify the DebugDelegate interface.
Due to a previous multi-threaded design involving message passing, we used message classes to pass event information to the delegate. Since the multi-threaded design has gone away, we simplify this by passing event arguments as direct function parameters, which is more clear and easier to understand. llvm-svn: 221806
This commit is contained in:
parent
b5363110c7
commit
d6a7b63f26
|
|
@ -10,7 +10,6 @@
|
|||
#include "DebuggerThread.h"
|
||||
#include "ExceptionRecord.h"
|
||||
#include "IDebugDelegate.h"
|
||||
#include "ProcessMessages.h"
|
||||
|
||||
#include "lldb/Core/Error.h"
|
||||
#include "lldb/Core/Log.h"
|
||||
|
|
@ -90,10 +89,7 @@ DebuggerThread::DebuggerThreadRoutine(const ProcessLaunchInfo &launch_info)
|
|||
if (error.Success())
|
||||
DebugLoop();
|
||||
else
|
||||
{
|
||||
ProcessMessageDebuggerError message(m_process, error, 0);
|
||||
m_debug_delegate->OnDebuggerError(message);
|
||||
}
|
||||
m_debug_delegate->OnDebuggerError(error, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -163,8 +159,7 @@ ExceptionResult
|
|||
DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id)
|
||||
{
|
||||
bool first_chance = (info.dwFirstChance != 0);
|
||||
ProcessMessageException message(m_process, ExceptionRecord(info.ExceptionRecord), first_chance);
|
||||
return m_debug_delegate->OnDebugException(message);
|
||||
return m_debug_delegate->OnDebugException(first_chance, ExceptionRecord(info.ExceptionRecord));
|
||||
}
|
||||
|
||||
DWORD
|
||||
|
|
@ -190,8 +185,7 @@ DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
|
|||
((HostThreadWindows &)m_main_thread.GetNativeThread()).SetOwnsHandle(false);
|
||||
m_image_file = info.hFile;
|
||||
|
||||
ProcessMessageDebuggerConnected message(m_process);
|
||||
m_debug_delegate->OnDebuggerConnected(message);
|
||||
m_debug_delegate->OnDebuggerConnected();
|
||||
|
||||
return DBG_CONTINUE;
|
||||
}
|
||||
|
|
@ -205,8 +199,7 @@ DebuggerThread::HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD
|
|||
DWORD
|
||||
DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWORD thread_id)
|
||||
{
|
||||
ProcessMessageExitProcess message(m_process, info.dwExitCode);
|
||||
m_debug_delegate->OnExitProcess(message);
|
||||
m_debug_delegate->OnExitProcess(info.dwExitCode);
|
||||
|
||||
m_process = HostProcess();
|
||||
m_main_thread = HostThread();
|
||||
|
|
@ -239,8 +232,7 @@ DWORD
|
|||
DebuggerThread::HandleRipEvent(const RIP_INFO &info, DWORD thread_id)
|
||||
{
|
||||
Error error(info.dwError, eErrorTypeWin32);
|
||||
ProcessMessageDebuggerError message(m_process, error, info.dwType);
|
||||
m_debug_delegate->OnDebuggerError(message);
|
||||
m_debug_delegate->OnDebuggerError(error, info.dwType);
|
||||
|
||||
return DBG_CONTINUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,21 +30,8 @@ namespace lldb_private
|
|||
|
||||
class IDebugDelegate;
|
||||
class DebuggerThread;
|
||||
|
||||
class ExceptionRecord;
|
||||
|
||||
// Process message forward declarations.
|
||||
class ProcessMessageBase;
|
||||
class ProcessMessageExitProcess;
|
||||
class ProcessMessageDebuggerConnected;
|
||||
class ProcessMessageException;
|
||||
class ProcessMessageCreateThread;
|
||||
class ProcessMessageExitThread;
|
||||
class ProcessMessageLoadDll;
|
||||
class ProcessMessageUnloadDll;
|
||||
class ProcessMessageDebugString;
|
||||
class ProcessMessageDebuggerError;
|
||||
|
||||
typedef std::shared_ptr<IDebugDelegate> DebugDelegateSP;
|
||||
typedef std::shared_ptr<DebuggerThread> DebuggerThreadSP;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,12 @@
|
|||
#define liblldb_Plugins_Process_Windows_IDebugDelegate_H_
|
||||
|
||||
#include "ForwardDecl.h"
|
||||
#include <string>
|
||||
|
||||
namespace lldb_private
|
||||
{
|
||||
class Error;
|
||||
class HostThread;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// IDebugDelegate
|
||||
|
|
@ -26,15 +29,15 @@ class IDebugDelegate
|
|||
public:
|
||||
virtual ~IDebugDelegate() {}
|
||||
|
||||
virtual void OnExitProcess(const ProcessMessageExitProcess &message) = 0;
|
||||
virtual void OnDebuggerConnected(const ProcessMessageDebuggerConnected &message) = 0;
|
||||
virtual ExceptionResult OnDebugException(const ProcessMessageException &message) = 0;
|
||||
virtual void OnCreateThread(const ProcessMessageCreateThread &message) = 0;
|
||||
virtual void OnExitThread(const ProcessMessageExitThread &message) = 0;
|
||||
virtual void OnLoadDll(const ProcessMessageLoadDll &message) = 0;
|
||||
virtual void OnUnloadDll(const ProcessMessageUnloadDll &message) = 0;
|
||||
virtual void OnDebugString(const ProcessMessageDebugString &message) = 0;
|
||||
virtual void OnDebuggerError(const ProcessMessageDebuggerError &message) = 0;
|
||||
virtual void OnExitProcess(uint32_t exit_code) = 0;
|
||||
virtual void OnDebuggerConnected() = 0;
|
||||
virtual ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) = 0;
|
||||
virtual void OnCreateThread(const HostThread &thread) = 0;
|
||||
virtual void OnExitThread(const HostThread &thread) = 0;
|
||||
virtual void OnLoadDll() = 0;
|
||||
virtual void OnUnloadDll() = 0;
|
||||
virtual void OnDebugString(const std::string &string) = 0;
|
||||
virtual void OnDebuggerError(const Error &error, uint32_t type) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,55 +19,55 @@ LocalDebugDelegate::LocalDebugDelegate(ProcessSP process)
|
|||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnExitProcess(const ProcessMessageExitProcess &message)
|
||||
LocalDebugDelegate::OnExitProcess(uint32_t exit_code)
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnExitProcess(message);
|
||||
((ProcessWindows &)*m_process).OnExitProcess(exit_code);
|
||||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnDebuggerConnected(const ProcessMessageDebuggerConnected &message)
|
||||
LocalDebugDelegate::OnDebuggerConnected()
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnDebuggerConnected(message);
|
||||
((ProcessWindows &)*m_process).OnDebuggerConnected();
|
||||
}
|
||||
|
||||
ExceptionResult
|
||||
LocalDebugDelegate::OnDebugException(const ProcessMessageException &message)
|
||||
LocalDebugDelegate::OnDebugException(bool first_chance, const ExceptionRecord &record)
|
||||
{
|
||||
return ((ProcessWindows &)*m_process).OnDebugException(message);
|
||||
return ((ProcessWindows &)*m_process).OnDebugException(first_chance, record);
|
||||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnCreateThread(const ProcessMessageCreateThread &message)
|
||||
LocalDebugDelegate::OnCreateThread(const HostThread &thread)
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnCreateThread(message);
|
||||
((ProcessWindows &)*m_process).OnCreateThread(thread);
|
||||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnExitThread(const ProcessMessageExitThread &message)
|
||||
LocalDebugDelegate::OnExitThread(const HostThread &thread)
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnExitThread(message);
|
||||
((ProcessWindows &)*m_process).OnExitThread(thread);
|
||||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnLoadDll(const ProcessMessageLoadDll &message)
|
||||
LocalDebugDelegate::OnLoadDll()
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnLoadDll(message);
|
||||
((ProcessWindows &)*m_process).OnLoadDll();
|
||||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnUnloadDll(const ProcessMessageUnloadDll &message)
|
||||
LocalDebugDelegate::OnUnloadDll()
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnUnloadDll(message);
|
||||
((ProcessWindows &)*m_process).OnUnloadDll();
|
||||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnDebugString(const ProcessMessageDebugString &message)
|
||||
LocalDebugDelegate::OnDebugString(const std::string &string)
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnDebugString(message);
|
||||
((ProcessWindows &)*m_process).OnDebugString(string);
|
||||
}
|
||||
|
||||
void
|
||||
LocalDebugDelegate::OnDebuggerError(const ProcessMessageDebuggerError &message)
|
||||
LocalDebugDelegate::OnDebuggerError(const Error &error, uint32_t type)
|
||||
{
|
||||
((ProcessWindows &)*m_process).OnDebuggerError(message);
|
||||
((ProcessWindows &)*m_process).OnDebuggerError(error, type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,15 +42,15 @@ class LocalDebugDelegate : public IDebugDelegate
|
|||
public:
|
||||
explicit LocalDebugDelegate::LocalDebugDelegate(lldb::ProcessSP process);
|
||||
|
||||
void OnExitProcess(const ProcessMessageExitProcess &message) override;
|
||||
void OnDebuggerConnected(const ProcessMessageDebuggerConnected &message) override;
|
||||
ExceptionResult OnDebugException(const ProcessMessageException &message) override;
|
||||
void OnCreateThread(const ProcessMessageCreateThread &message) override;
|
||||
void OnExitThread(const ProcessMessageExitThread &message) override;
|
||||
void OnLoadDll(const ProcessMessageLoadDll &message) override;
|
||||
void OnUnloadDll(const ProcessMessageUnloadDll &message) override;
|
||||
void OnDebugString(const ProcessMessageDebugString &message) override;
|
||||
void OnDebuggerError(const ProcessMessageDebuggerError &message) override;
|
||||
virtual void OnExitProcess(uint32_t exit_code) override;
|
||||
virtual void OnDebuggerConnected() override;
|
||||
virtual ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override;
|
||||
virtual void OnCreateThread(const HostThread &thread) override;
|
||||
virtual void OnExitThread(const HostThread &thread) override;
|
||||
virtual void OnLoadDll() override;
|
||||
virtual void OnUnloadDll() override;
|
||||
virtual void OnDebugString(const std::string &message) override;
|
||||
virtual void OnDebuggerError(const Error &error, uint32_t type) override;
|
||||
|
||||
private:
|
||||
lldb::ProcessSP m_process;
|
||||
|
|
|
|||
|
|
@ -1,125 +0,0 @@
|
|||
//===-- ProcessMessages.h -----------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef liblldb_Plugins_Process_Windows_ProcessMessages_H_
|
||||
#define liblldb_Plugins_Process_Windows_ProcessMessages_H_
|
||||
|
||||
#include "ExceptionRecord.h"
|
||||
|
||||
#include "lldb/Core/Error.h"
|
||||
#include "lldb/Host/HostProcess.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace lldb_private
|
||||
{
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ProcessMessageBase
|
||||
//
|
||||
// ProcessMessageBase serves as a base class for all messages which represent
|
||||
// events that happen in the context of debugging a single process.
|
||||
//----------------------------------------------------------------------
|
||||
class ProcessMessageBase
|
||||
{
|
||||
public:
|
||||
ProcessMessageBase(const HostProcess &process)
|
||||
: m_process(process)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ProcessMessageBase() {}
|
||||
|
||||
const HostProcess &
|
||||
GetProcess() const
|
||||
{
|
||||
return m_process;
|
||||
}
|
||||
|
||||
protected:
|
||||
HostProcess m_process;
|
||||
};
|
||||
|
||||
class ProcessMessageDebuggerConnected : public ProcessMessageBase
|
||||
{
|
||||
public:
|
||||
ProcessMessageDebuggerConnected(const HostProcess &process)
|
||||
: ProcessMessageBase(process)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ProcessMessageException : public ProcessMessageBase
|
||||
{
|
||||
public:
|
||||
ProcessMessageException(const HostProcess &process, const ExceptionRecord &exception, bool first_chance)
|
||||
: ProcessMessageBase(process)
|
||||
, m_exception(exception)
|
||||
, m_first_chance(first_chance)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
IsFirstChance() const
|
||||
{
|
||||
return m_first_chance;
|
||||
}
|
||||
const ExceptionRecord &
|
||||
GetExceptionRecord() const
|
||||
{
|
||||
return m_exception;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_first_chance;
|
||||
ExceptionRecord m_exception;
|
||||
};
|
||||
|
||||
class ProcessMessageExitProcess : public ProcessMessageBase
|
||||
{
|
||||
public:
|
||||
ProcessMessageExitProcess(const HostProcess &process, DWORD exit_code)
|
||||
: ProcessMessageBase(process)
|
||||
, m_exit_code(exit_code)
|
||||
{
|
||||
}
|
||||
|
||||
DWORD
|
||||
GetExitCode() const { return m_exit_code; }
|
||||
|
||||
private:
|
||||
DWORD m_exit_code;
|
||||
};
|
||||
|
||||
class ProcessMessageDebuggerError : public ProcessMessageBase
|
||||
{
|
||||
public:
|
||||
ProcessMessageDebuggerError(const HostProcess &process, const Error &error, DWORD type)
|
||||
: ProcessMessageBase(process)
|
||||
, m_error(error)
|
||||
, m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
const Error &
|
||||
GetError() const
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
|
||||
DWORD
|
||||
GetType() const { return m_type; }
|
||||
|
||||
private:
|
||||
Error m_error;
|
||||
DWORD m_type;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -30,7 +30,6 @@
|
|||
#include "DebuggerThread.h"
|
||||
#include "ExceptionRecord.h"
|
||||
#include "LocalDebugDelegate.h"
|
||||
#include "ProcessMessages.h"
|
||||
#include "ProcessWindows.h"
|
||||
|
||||
using namespace lldb;
|
||||
|
|
@ -244,23 +243,22 @@ ProcessWindows::CanDebug(Target &target, bool plugin_specified_by_name)
|
|||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnExitProcess(const ProcessMessageExitProcess &message)
|
||||
ProcessWindows::OnExitProcess(uint32_t exit_code)
|
||||
{
|
||||
SetProcessExitStatus(nullptr, GetID(), true, 0, message.GetExitCode());
|
||||
SetProcessExitStatus(nullptr, GetID(), true, 0, exit_code);
|
||||
SetPrivateState(eStateExited);
|
||||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnDebuggerConnected(const ProcessMessageDebuggerConnected &message)
|
||||
ProcessWindows::OnDebuggerConnected()
|
||||
{
|
||||
::SetEvent(m_data_up->m_launched_event);
|
||||
}
|
||||
|
||||
ExceptionResult
|
||||
ProcessWindows::OnDebugException(const ProcessMessageException &message)
|
||||
ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &record)
|
||||
{
|
||||
ExceptionResult result = ExceptionResult::Handled;
|
||||
const ExceptionRecord &record = message.GetExceptionRecord();
|
||||
m_active_exception.reset(new ExceptionRecord(record));
|
||||
switch (record.GetExceptionCode())
|
||||
{
|
||||
|
|
@ -273,39 +271,39 @@ ProcessWindows::OnDebugException(const ProcessMessageException &message)
|
|||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnCreateThread(const ProcessMessageCreateThread &message)
|
||||
ProcessWindows::OnCreateThread(const HostThread &thread)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnExitThread(const ProcessMessageExitThread &message)
|
||||
ProcessWindows::OnExitThread(const HostThread &thread)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnLoadDll(const ProcessMessageLoadDll &message)
|
||||
ProcessWindows::OnLoadDll()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnUnloadDll(const ProcessMessageUnloadDll &message)
|
||||
ProcessWindows::OnUnloadDll()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnDebugString(const ProcessMessageDebugString &message)
|
||||
ProcessWindows::OnDebugString(const std::string &string)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ProcessWindows::OnDebuggerError(const ProcessMessageDebuggerError &message)
|
||||
ProcessWindows::OnDebuggerError(const Error &error, uint32_t type)
|
||||
{
|
||||
DWORD result = ::WaitForSingleObject(m_data_up->m_launched_event, 0);
|
||||
if (result == WAIT_TIMEOUT)
|
||||
{
|
||||
// If we haven't actually launched the process yet, this was an error
|
||||
// launching the process. Set the internal error and signal.
|
||||
m_launch_error = message.GetError();
|
||||
m_launch_error = error;
|
||||
::SetEvent(m_data_up->m_launched_event);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,15 +115,15 @@ public:
|
|||
virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, lldb_private::Error &error);
|
||||
|
||||
// IDebugDelegate overrides.
|
||||
virtual void OnExitProcess(const lldb_private::ProcessMessageExitProcess &message) override;
|
||||
virtual void OnDebuggerConnected(const lldb_private::ProcessMessageDebuggerConnected &message) override;
|
||||
virtual ExceptionResult OnDebugException(const lldb_private::ProcessMessageException &message) override;
|
||||
virtual void OnCreateThread(const lldb_private::ProcessMessageCreateThread &message) override;
|
||||
virtual void OnExitThread(const lldb_private::ProcessMessageExitThread &message) override;
|
||||
virtual void OnLoadDll(const lldb_private::ProcessMessageLoadDll &message) override;
|
||||
virtual void OnUnloadDll(const lldb_private::ProcessMessageUnloadDll &message) override;
|
||||
virtual void OnDebugString(const lldb_private::ProcessMessageDebugString &message) override;
|
||||
virtual void OnDebuggerError(const lldb_private::ProcessMessageDebuggerError &message) override;
|
||||
virtual void OnExitProcess(uint32_t exit_code) override;
|
||||
virtual void OnDebuggerConnected() override;
|
||||
virtual ExceptionResult OnDebugException(bool first_chance, const lldb_private::ExceptionRecord &record) override;
|
||||
virtual void OnCreateThread(const lldb_private::HostThread &thread) override;
|
||||
virtual void OnExitThread(const lldb_private::HostThread &thread) override;
|
||||
virtual void OnLoadDll() override;
|
||||
virtual void OnUnloadDll() override;
|
||||
virtual void OnDebugString(const std::string &string) override;
|
||||
virtual void OnDebuggerError(const lldb_private::Error &error, uint32_t type) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<lldb_private::ExceptionRecord> m_active_exception;
|
||||
|
|
|
|||
Loading…
Reference in New Issue