Skip to content

Commit

Permalink
[ProcessWindows] Improve support for launching processes.
Browse files Browse the repository at this point in the history
This sends notifications for module load / unload to the process
plugin, and also manages the state more accurately during the
loading sequence.

Similar work by Virgile Bello was referenced during the
implementation of this patch.

Differential Revision: http://reviews.llvm.org/D6224

llvm-svn: 221807
  • Loading branch information
Zachary Turner committed Nov 12, 2014
1 parent d6a7b63 commit a32d2ce
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 63 deletions.
35 changes: 33 additions & 2 deletions lldb/source/Plugins/Process/Windows/DebuggerThread.cpp
Expand Up @@ -13,6 +13,8 @@

#include "lldb/Core/Error.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Predicate.h"
#include "lldb/Host/ThisThread.h"
#include "lldb/Host/ThreadLauncher.h"
Expand All @@ -21,6 +23,7 @@
#include "lldb/Host/windows/ProcessLauncherWindows.h"
#include "lldb/Target/ProcessLaunchInfo.h"

#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/raw_ostream.h"

using namespace lldb;
Expand Down Expand Up @@ -185,7 +188,8 @@ DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
((HostThreadWindows &)m_main_thread.GetNativeThread()).SetOwnsHandle(false);
m_image_file = info.hFile;

m_debug_delegate->OnDebuggerConnected();
lldb::addr_t load_addr = reinterpret_cast<lldb::addr_t>(info.lpBaseOfImage);
m_debug_delegate->OnDebuggerConnected(load_addr);

return DBG_CONTINUE;
}
Expand All @@ -211,14 +215,41 @@ DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWOR
DWORD
DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id)
{
// Windows does not automatically close info.hFile when the DLL is unloaded.
if (info.hFile == nullptr)
{
// Not sure what this is, so just ignore it.
return DBG_CONTINUE;
}

std::vector<char> buffer(1);
DWORD required_size = GetFinalPathNameByHandle(info.hFile, &buffer[0], 0, VOLUME_NAME_DOS);
if (required_size > 0)
{
buffer.resize(required_size + 1);
required_size = GetFinalPathNameByHandle(info.hFile, &buffer[0], required_size + 1, VOLUME_NAME_DOS);
llvm::StringRef path_str(&buffer[0]);
const char *path = path_str.data();
if (path_str.startswith("\\\\?\\"))
path += 4;

FileSpec file_spec(path, false);
ModuleSpec module_spec(file_spec);
lldb::addr_t load_addr = reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll);
m_debug_delegate->OnLoadDll(module_spec, load_addr);
}
else
{
// An unknown error occurred getting the path name.
}
// Windows does not automatically close info.hFile, so we need to do it.
::CloseHandle(info.hFile);
return DBG_CONTINUE;
}

DWORD
DebuggerThread::HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, DWORD thread_id)
{
m_debug_delegate->OnUnloadDll(reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll));
return DBG_CONTINUE;
}

Expand Down
8 changes: 5 additions & 3 deletions lldb/source/Plugins/Process/Windows/IDebugDelegate.h
Expand Up @@ -11,6 +11,8 @@
#define liblldb_Plugins_Process_Windows_IDebugDelegate_H_

#include "ForwardDecl.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-types.h"
#include <string>

namespace lldb_private
Expand All @@ -30,12 +32,12 @@ class IDebugDelegate
virtual ~IDebugDelegate() {}

virtual void OnExitProcess(uint32_t exit_code) = 0;
virtual void OnDebuggerConnected() = 0;
virtual void OnDebuggerConnected(lldb::addr_t image_base) = 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 OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) = 0;
virtual void OnUnloadDll(lldb::addr_t module_addr) = 0;
virtual void OnDebugString(const std::string &string) = 0;
virtual void OnDebuggerError(const Error &error, uint32_t type) = 0;
};
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/Process/Windows/LocalDebugDelegate.cpp
Expand Up @@ -25,9 +25,9 @@ LocalDebugDelegate::OnExitProcess(uint32_t exit_code)
}

void
LocalDebugDelegate::OnDebuggerConnected()
LocalDebugDelegate::OnDebuggerConnected(lldb::addr_t image_base)
{
((ProcessWindows &)*m_process).OnDebuggerConnected();
((ProcessWindows &)*m_process).OnDebuggerConnected(image_base);
}

ExceptionResult
Expand All @@ -49,15 +49,15 @@ LocalDebugDelegate::OnExitThread(const HostThread &thread)
}

void
LocalDebugDelegate::OnLoadDll()
LocalDebugDelegate::OnLoadDll(const lldb_private::ModuleSpec &module_spec, lldb::addr_t module_addr)
{
((ProcessWindows &)*m_process).OnLoadDll();
((ProcessWindows &)*m_process).OnLoadDll(module_spec, module_addr);
}

void
LocalDebugDelegate::OnUnloadDll()
LocalDebugDelegate::OnUnloadDll(lldb::addr_t module_addr)
{
((ProcessWindows &)*m_process).OnUnloadDll();
((ProcessWindows &)*m_process).OnUnloadDll(module_addr);
}

void
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Plugins/Process/Windows/LocalDebugDelegate.h
Expand Up @@ -43,12 +43,12 @@ class LocalDebugDelegate : public IDebugDelegate
explicit LocalDebugDelegate::LocalDebugDelegate(lldb::ProcessSP process);

virtual void OnExitProcess(uint32_t exit_code) override;
virtual void OnDebuggerConnected() override;
virtual void OnDebuggerConnected(lldb::addr_t image_base) 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 OnLoadDll(const lldb_private::ModuleSpec &module_spec, lldb::addr_t module_addr) override;
virtual void OnUnloadDll(lldb::addr_t module_addr) override;
virtual void OnDebugString(const std::string &message) override;
virtual void OnDebuggerError(const Error &error, uint32_t type) override;

Expand Down

0 comments on commit a32d2ce

Please sign in to comment.