[Lldb-commits] [lldb] r222148 - [ProcessWindows] Create a TargetThreadWindows class.
Zachary Turner
zturner at google.com
Mon Nov 17 09:46:44 PST 2014
Author: zturner
Date: Mon Nov 17 11:46:43 2014
New Revision: 222148
URL: http://llvm.org/viewvc/llvm-project?rev=222148&view=rev
Log:
[ProcessWindows] Create a TargetThreadWindows class.
This creates a TargetThreadWindows class and updates the thread
list of the Process with the main thread. Additionally, we
fill out a few more overrides of Process base class methods. We
do not yet update the thread list as threads are created and/or
destroyed, and we do not yet propagate stop reasons to threads as
their states change.
Added:
lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp
lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.h
Modified:
lldb/trunk/include/lldb/lldb-forward.h
lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt
lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h
Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=222148&r1=222147&r2=222148&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Mon Nov 17 11:46:43 2014
@@ -370,6 +370,7 @@ namespace lldb {
typedef std::shared_ptr<lldb_private::SearchFilter> SearchFilterSP;
typedef std::shared_ptr<lldb_private::Settings> SettingsSP;
typedef std::shared_ptr<lldb_private::StackFrame> StackFrameSP;
+ typedef std::unique_ptr<lldb_private::StackFrame> StackFrameUP;
typedef std::weak_ptr<lldb_private::StackFrame> StackFrameWP;
typedef std::shared_ptr<lldb_private::StackFrameList> StackFrameListSP;
typedef std::shared_ptr<lldb_private::StopInfo> StopInfoSP;
Modified: lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt?rev=222148&r1=222147&r2=222148&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt (original)
+++ lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt Mon Nov 17 11:46:43 2014
@@ -7,5 +7,6 @@ add_lldb_library(lldbPluginProcessWindow
DebuggerThread.cpp
LocalDebugDelegate.cpp
ProcessWindows.cpp
+ TargetThreadWindows.cpp
)
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=222148&r1=222147&r2=222148&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp Mon Nov 17 11:46:43 2014
@@ -20,6 +20,7 @@
#include "lldb/Host/Host.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/HostNativeProcessBase.h"
+#include "lldb/Host/HostNativeThreadBase.h"
#include "lldb/Host/MonitoringProcessLauncher.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Host/windows/ProcessLauncherWindows.h"
@@ -32,6 +33,7 @@
#include "ExceptionRecord.h"
#include "LocalDebugDelegate.h"
#include "ProcessWindows.h"
+#include "TargetThreadWindows.h"
using namespace lldb;
using namespace lldb_private;
@@ -197,23 +199,6 @@ ProcessWindows::GetPluginVersion()
return 1;
}
-void
-ProcessWindows::GetPluginCommandHelp(const char *command, Stream *strm)
-{
-}
-
-Error
-ProcessWindows::ExecutePluginCommand(Args &command, Stream *strm)
-{
- return Error(1, eErrorTypeGeneric);
-}
-
-Log *
-ProcessWindows::EnablePluginLogging(Stream *strm, Args &command)
-{
- return NULL;
-}
-
Error
ProcessWindows::DoDetach(bool keep_stopped)
{
@@ -255,6 +240,22 @@ ProcessWindows::IsAlive()
}
}
+Error
+ProcessWindows::DoHalt(bool &caused_stop)
+{
+ Error error;
+ StateType state = GetPrivateState();
+ if (state == eStateStopped)
+ caused_stop = false;
+ else
+ {
+ caused_stop = ::DebugBreakProcess(m_session_data->m_debugger->GetProcess().GetNativeProcess().GetSystemHandle());
+ if (!caused_stop)
+ error.SetError(GetLastError(), eErrorTypeWin32);
+ }
+ return error;
+}
+
size_t
ProcessWindows::DoReadMemory(lldb::addr_t vm_addr,
void *buf,
@@ -289,6 +290,18 @@ ProcessWindows::DoWriteMemory(lldb::addr
return bytes_written;
}
+lldb::addr_t
+ProcessWindows::GetImageInfoAddress()
+{
+ Target &target = GetTarget();
+ ObjectFile *obj_file = target.GetExecutableModule()->GetObjectFile();
+ Address addr = obj_file->GetImageInfoAddress(&target);
+ if (addr.IsValid())
+ return addr.GetLoadAddress(&target);
+ else
+ return LLDB_INVALID_ADDRESS;
+}
+
bool
ProcessWindows::CanDebug(Target &target, bool plugin_specified_by_name)
{
@@ -315,6 +328,10 @@ ProcessWindows::OnDebuggerConnected(lldb
ModuleSP module = GetTarget().GetExecutableModule();
bool load_addr_changed;
module->SetLoadAddress(GetTarget(), image_base, false, load_addr_changed);
+
+ DebuggerThreadSP debugger = m_session_data->m_debugger;
+ ThreadSP main_thread(new TargetThreadWindows(*this, debugger->GetMainThread()));
+ m_thread_list.AddThread(main_thread);
}
ExceptionResult
@@ -365,6 +382,7 @@ ProcessWindows::OnDebugException(bool fi
void
ProcessWindows::OnCreateThread(const HostThread &thread)
{
+ SuspendThread(thread.GetNativeThread().GetSystemHandle());
}
void
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=222148&r1=222147&r2=222148&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h Mon Nov 17 11:46:43 2014
@@ -63,54 +63,44 @@ public:
~ProcessWindows();
- virtual lldb_private::Error
- DoDetach(bool keep_stopped);
+ virtual lldb_private::Error DoDetach(bool keep_stopped) override;
virtual bool
- DetachRequiresHalt() { return true; }
+ DetachRequiresHalt() override
+ {
+ return true;
+ }
- virtual bool
- UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list);
+ virtual bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override;
- virtual lldb_private::Error
- DoLaunch (lldb_private::Module *exe_module,
- lldb_private::ProcessLaunchInfo &launch_info);
+ virtual lldb_private::Error DoLaunch(lldb_private::Module *exe_module, lldb_private::ProcessLaunchInfo &launch_info) override;
- virtual lldb_private::Error
- DoResume ();
+ virtual lldb_private::Error DoResume() override;
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
- virtual lldb_private::ConstString
- GetPluginName();
-
- virtual uint32_t
- GetPluginVersion();
+ virtual lldb_private::ConstString GetPluginName() override;
- virtual void
- GetPluginCommandHelp(const char *command, lldb_private::Stream *strm);
+ virtual uint32_t GetPluginVersion() override;
- virtual lldb_private::Error
- ExecutePluginCommand(lldb_private::Args &command,
- lldb_private::Stream *strm);
-
- virtual lldb_private::Log *
- EnablePluginLogging(lldb_private::Stream *strm,
- lldb_private::Args &command);
+ virtual bool CanDebug(lldb_private::Target &target, bool plugin_specified_by_name) override;
+ virtual lldb_private::Error DoDestroy() override;
virtual bool
- CanDebug(lldb_private::Target &target, bool plugin_specified_by_name);
+ DestroyRequiresHalt() override
+ {
+ return false;
+ }
- virtual lldb_private::Error
- DoDestroy ();
+ virtual void RefreshStateAfterStop() override;
- virtual void
- RefreshStateAfterStop ();
+ virtual bool IsAlive() override;
- virtual bool
- IsAlive ();
+ virtual lldb_private::Error DoHalt(bool &caused_stop) override;
+
+ virtual lldb::addr_t GetImageInfoAddress() override;
virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, lldb_private::Error &error) override;
virtual size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, lldb_private::Error &error) override;
Added: lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp?rev=222148&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp (added)
+++ lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.cpp Mon Nov 17 11:46:43 2014
@@ -0,0 +1,95 @@
+//===-- TargetThreadWindows.cpp----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TargetThreadWindows.h"
+#include "ProcessWindows.h"
+#include "lldb/Host/HostNativeThreadBase.h"
+#include "lldb/Host/windows/HostThreadWindows.h"
+#include "lldb/Host/windows/windows.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+TargetThreadWindows::TargetThreadWindows(ProcessWindows &process, const HostThread &thread)
+ : Thread(process, ((HostThreadWindows &)thread.GetNativeThread()).GetThreadId())
+ , m_host_thread(thread)
+{
+}
+
+TargetThreadWindows::~TargetThreadWindows()
+{
+ DestroyThread();
+}
+
+void
+TargetThreadWindows::RefreshStateAfterStop()
+{
+}
+
+void
+TargetThreadWindows::WillResume(lldb::StateType resume_state)
+{
+}
+
+void
+TargetThreadWindows::DidStop()
+{
+}
+
+RegisterContextSP
+TargetThreadWindows::GetRegisterContext()
+{
+ return RegisterContextSP();
+}
+
+RegisterContextSP
+TargetThreadWindows::CreateRegisterContextForFrame(StackFrame *frame)
+{
+ return RegisterContextSP();
+}
+
+bool
+TargetThreadWindows::CalculateStopInfo()
+{
+ return false;
+}
+
+bool
+TargetThreadWindows::DoResume()
+{
+ StateType resume_state = GetResumeState();
+ StateType current_state = GetState();
+ if (resume_state == current_state)
+ return true;
+
+ bool success = false;
+ DWORD suspend_count = 0;
+ switch (resume_state)
+ {
+ case eStateRunning:
+ SetState(resume_state);
+ do
+ {
+ suspend_count = ::ResumeThread(m_host_thread.GetNativeThread().GetSystemHandle());
+ } while (suspend_count > 1 && suspend_count != (DWORD)-1);
+ success = (suspend_count != (DWORD)-1);
+ break;
+ case eStateStopped:
+ case eStateSuspended:
+ if (current_state != eStateStopped && current_state != eStateSuspended)
+ {
+ suspend_count = SuspendThread(m_host_thread.GetNativeThread().GetSystemHandle());
+ success = (suspend_count != (DWORD)-1);
+ }
+ break;
+ default:
+ success = false;
+ }
+ return success;
+}
Added: lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.h?rev=222148&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.h (added)
+++ lldb/trunk/source/Plugins/Process/Windows/TargetThreadWindows.h Mon Nov 17 11:46:43 2014
@@ -0,0 +1,47 @@
+//===-- TargetThreadWindows.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_TargetThreadWindows_H_
+#define liblldb_Plugins_Process_Windows_TargetThreadWindows_H_
+
+#include "ForwardDecl.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/Host/HostThread.h"
+#include "lldb/Target/Thread.h"
+class ProcessWindows;
+
+namespace lldb_private
+{
+
+class HostThread;
+class StackFrame;
+
+class TargetThreadWindows : public lldb_private::Thread
+{
+ public:
+ TargetThreadWindows(ProcessWindows &process, const HostThread &thread);
+ virtual ~TargetThreadWindows();
+
+ virtual void RefreshStateAfterStop() override;
+ virtual void WillResume(lldb::StateType resume_state) override;
+ virtual void DidStop() override;
+ virtual lldb::RegisterContextSP GetRegisterContext() override;
+ virtual lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) override;
+ virtual bool CalculateStopInfo() override;
+
+ bool DoResume();
+
+ private:
+ lldb::StackFrameUP m_stack_frame;
+
+ HostThread m_host_thread;
+};
+}
+
+#endif
\ No newline at end of file
More information about the lldb-commits
mailing list