[ProcessWindows] Improve support for launching processes.

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
This commit is contained in:
Zachary Turner
2014-11-12 19:31:56 +00:00
parent d6a7b63f26
commit a32d2cecba
6 changed files with 168 additions and 64 deletions

View File

@@ -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"
@@ -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;
@@ -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;
}
@@ -211,7 +215,33 @@ 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;
}
@@ -219,6 +249,7 @@ DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread
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;
}