Skip to content

Commit

Permalink
[lldb] Convert ProcessWindowsLog to the new API
Browse files Browse the repository at this point in the history
  • Loading branch information
labath committed Jan 27, 2022
1 parent 7afd052 commit 6730df4
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 76 deletions.
36 changes: 15 additions & 21 deletions lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
Expand Up @@ -64,7 +64,7 @@ DebuggerThread::DebuggerThread(DebugDelegateSP debug_delegate)
DebuggerThread::~DebuggerThread() { ::CloseHandle(m_debugging_ended_event); }

Status DebuggerThread::DebugLaunch(const ProcessLaunchInfo &launch_info) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "launching '{0}'", launch_info.GetExecutableFile().GetPath());

Status result;
Expand All @@ -83,7 +83,7 @@ Status DebuggerThread::DebugLaunch(const ProcessLaunchInfo &launch_info) {

Status DebuggerThread::DebugAttach(lldb::pid_t pid,
const ProcessAttachInfo &attach_info) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "attaching to '{0}'", pid);

Status result;
Expand Down Expand Up @@ -122,7 +122,7 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadLaunchRoutine(
// until after the thread routine has exited.
std::shared_ptr<DebuggerThread> this_ref(shared_from_this());

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "preparing to launch '{0}' on background thread.",
launch_info.GetExecutableFile().GetPath());

Expand All @@ -149,7 +149,7 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadAttachRoutine(
// until after the thread routine has exited.
std::shared_ptr<DebuggerThread> this_ref(shared_from_this());

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "preparing to attach to process '{0}' on background thread.",
pid);

Expand All @@ -172,7 +172,7 @@ Status DebuggerThread::StopDebugging(bool terminate) {

lldb::pid_t pid = m_process.GetProcessId();

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "terminate = {0}, inferior={1}.", terminate, pid);

// Set m_is_shutting_down to true if it was false. Return if it was already
Expand Down Expand Up @@ -246,8 +246,7 @@ void DebuggerThread::ContinueAsyncException(ExceptionResult result) {
if (!m_active_exception.get())
return;

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS |
WINDOWS_LOG_EXCEPTION);
Log *log = GetLog(WindowsLog::Process | WindowsLog::Exception);
LLDB_LOG(log, "broadcasting for inferior process {0}.",
m_process.GetProcessId());

Expand All @@ -265,7 +264,7 @@ void DebuggerThread::FreeProcessHandles() {
}

void DebuggerThread::DebugLoop() {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
Log *log = GetLog(WindowsLog::Event);
DEBUG_EVENT dbe = {};
bool should_debug = true;
LLDB_LOGV(log, "Entering WaitForDebugEvent loop");
Expand Down Expand Up @@ -346,8 +345,7 @@ void DebuggerThread::DebugLoop() {
ExceptionResult
DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
DWORD thread_id) {
Log *log =
ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION);
Log *log = GetLog(WindowsLog::Event | WindowsLog::Exception);
if (m_is_shutting_down) {
// A breakpoint that occurs while `m_pid_to_detach` is non-zero is a magic
// exception that
Expand Down Expand Up @@ -390,8 +388,7 @@ DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
DWORD
DebuggerThread::HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
DWORD thread_id) {
Log *log =
ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD);
Log *log = GetLog(WindowsLog::Event | WindowsLog::Thread);
LLDB_LOG(log, "Thread {0} spawned in process {1}", thread_id,
m_process.GetProcessId());
HostThread thread(info.hThread);
Expand All @@ -403,8 +400,7 @@ DebuggerThread::HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
DWORD
DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
DWORD thread_id) {
Log *log =
ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Event | WindowsLog::Process);
uint32_t process_id = ::GetProcessId(info.hProcess);

LLDB_LOG(log, "process {0} spawned", process_id);
Expand Down Expand Up @@ -432,8 +428,7 @@ DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
DWORD
DebuggerThread::HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
DWORD thread_id) {
Log *log =
ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD);
Log *log = GetLog(WindowsLog::Event | WindowsLog::Thread);
LLDB_LOG(log, "Thread {0} exited with code {1} in process {2}", thread_id,
info.dwExitCode, m_process.GetProcessId());
m_debug_delegate->OnExitThread(thread_id, info.dwExitCode);
Expand All @@ -443,8 +438,7 @@ DebuggerThread::HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
DWORD
DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
DWORD thread_id) {
Log *log =
ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD);
Log *log = GetLog(WindowsLog::Event | WindowsLog::Thread);
LLDB_LOG(log, "process {0} exited with code {1}", m_process.GetProcessId(),
info.dwExitCode);

Expand All @@ -456,7 +450,7 @@ DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
DWORD
DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info,
DWORD thread_id) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
Log *log = GetLog(WindowsLog::Event);
if (info.hFile == nullptr) {
// Not sure what this is, so just ignore it.
LLDB_LOG(log, "Warning: Inferior {0} has a NULL file handle, returning...",
Expand Down Expand Up @@ -500,7 +494,7 @@ DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info,
DWORD
DebuggerThread::HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,
DWORD thread_id) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
Log *log = GetLog(WindowsLog::Event);
LLDB_LOG(log, "process {0} unloading DLL at addr {1:x}.",
m_process.GetProcessId(), info.lpBaseOfDll);

Expand All @@ -517,7 +511,7 @@ DebuggerThread::HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info,

DWORD
DebuggerThread::HandleRipEvent(const RIP_INFO &info, DWORD thread_id) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
Log *log = GetLog(WindowsLog::Event);
LLDB_LOG(log, "encountered error {0} (type={1}) in process {2} thread {3}",
info.dwError, info.dwType, m_process.GetProcessId(), thread_id);

Expand Down
Expand Up @@ -84,7 +84,7 @@ NativeProcessWindows::NativeProcessWindows(lldb::pid_t pid, int terminal_fd,
}

Status NativeProcessWindows::Resume(const ResumeActionList &resume_actions) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
Status error;
llvm::sys::ScopedLock lock(m_mutex);

Expand Down Expand Up @@ -168,7 +168,7 @@ Status NativeProcessWindows::Halt() {

Status NativeProcessWindows::Detach() {
Status error;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
StateType state = GetState();
if (state != eStateExited && state != eStateDetached) {
error = DetachProcess();
Expand Down Expand Up @@ -403,7 +403,7 @@ NativeProcessWindows::GetFileLoadAddress(const llvm::StringRef &file_name,
}

void NativeProcessWindows::OnExitProcess(uint32_t exit_code) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code);

ProcessDebugger::OnExitProcess(exit_code);
Expand All @@ -417,7 +417,7 @@ void NativeProcessWindows::OnExitProcess(uint32_t exit_code) {
}

void NativeProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "Debugger connected to process {0}. Image base = {1:x}",
GetDebuggedProcessId(), image_base);

Expand Down Expand Up @@ -445,7 +445,7 @@ void NativeProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
ExceptionResult
NativeProcessWindows::OnDebugException(bool first_chance,
const ExceptionRecord &record) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION);
Log *log = GetLog(WindowsLog::Exception);
llvm::sys::ScopedLock lock(m_mutex);

// Let the debugger establish the internal status.
Expand Down
Expand Up @@ -60,7 +60,7 @@ static Status
GetWoW64ThreadContextHelper(lldb::thread_t thread_handle,
PWOW64_CONTEXT context_ptr,
const DWORD control_flag = kWoW64ContextFlags) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;
memset(context_ptr, 0, sizeof(::WOW64_CONTEXT));
context_ptr->ContextFlags = control_flag;
Expand All @@ -75,7 +75,7 @@ GetWoW64ThreadContextHelper(lldb::thread_t thread_handle,

static Status SetWoW64ThreadContextHelper(lldb::thread_t thread_handle,
PWOW64_CONTEXT context_ptr) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;
if (!::Wow64SetThreadContext(thread_handle, context_ptr)) {
error.SetError(GetLastError(), eErrorTypeWin32);
Expand Down
Expand Up @@ -88,7 +88,7 @@ CreateRegisterInfoInterface(const ArchSpec &target_arch) {
static Status GetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr,
const DWORD control_flag) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;

memset(context_ptr, 0, sizeof(::CONTEXT));
Expand All @@ -104,7 +104,7 @@ static Status GetThreadContextHelper(lldb::thread_t thread_handle,

static Status SetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;
// It's assumed that the thread has stopped.
if (!::SetThreadContext(thread_handle, context_ptr)) {
Expand Down
Expand Up @@ -105,7 +105,7 @@ CreateRegisterInfoInterface(const ArchSpec &target_arch) {
static Status GetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr,
const DWORD control_flag) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;

memset(context_ptr, 0, sizeof(::CONTEXT));
Expand All @@ -121,7 +121,7 @@ static Status GetThreadContextHelper(lldb::thread_t thread_handle,

static Status SetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;
// It's assumed that the thread has stopped.
if (!::SetThreadContext(thread_handle, context_ptr)) {
Expand Down
Expand Up @@ -55,7 +55,7 @@ CreateRegisterInfoInterface(const ArchSpec &target_arch) {
static Status GetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr,
const DWORD control_flag) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;

memset(context_ptr, 0, sizeof(::CONTEXT));
Expand All @@ -71,7 +71,7 @@ static Status GetThreadContextHelper(lldb::thread_t thread_handle,

static Status SetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;

if (!::SetThreadContext(thread_handle, context_ptr)) {
Expand Down
Expand Up @@ -67,7 +67,7 @@ CreateRegisterInfoInterface(const ArchSpec &target_arch) {
static Status GetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr,
const DWORD control_flag) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;

memset(context_ptr, 0, sizeof(::CONTEXT));
Expand All @@ -83,7 +83,7 @@ static Status GetThreadContextHelper(lldb::thread_t thread_handle,

static Status SetThreadContextHelper(lldb::thread_t thread_handle,
PCONTEXT context_ptr) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
Status error;
// It's assumed that the thread has stopped.
if (!::SetThreadContext(thread_handle, context_ptr)) {
Expand Down
27 changes: 13 additions & 14 deletions lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
Expand Up @@ -72,7 +72,7 @@ lldb::pid_t ProcessDebugger::GetDebuggedProcessId() const {
}

Status ProcessDebugger::DetachProcess() {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
DebuggerThreadSP debugger_thread;
{
// Acquire the lock only long enough to get the DebuggerThread.
Expand Down Expand Up @@ -108,7 +108,7 @@ Status ProcessDebugger::LaunchProcess(ProcessLaunchInfo &launch_info,
// thread has been kicked off. So there's no race conditions, and it
// shouldn't be necessary to acquire the mutex.

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
Status result;

FileSpec working_dir = launch_info.GetWorkingDirectory();
Expand Down Expand Up @@ -171,7 +171,7 @@ Status ProcessDebugger::LaunchProcess(ProcessLaunchInfo &launch_info,
Status ProcessDebugger::AttachProcess(lldb::pid_t pid,
const ProcessAttachInfo &attach_info,
DebugDelegateSP delegate) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
m_session_data.reset(
new ProcessWindowsData(!attach_info.GetContinueOnceAttached()));
DebuggerThreadSP debugger(new DebuggerThread(delegate));
Expand Down Expand Up @@ -209,7 +209,7 @@ Status ProcessDebugger::AttachProcess(lldb::pid_t pid,
}

Status ProcessDebugger::DestroyProcess(const lldb::StateType state) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
DebuggerThreadSP debugger_thread;
{
// Acquire this lock inside an inner scope, only long enough to get the
Expand Down Expand Up @@ -245,7 +245,7 @@ Status ProcessDebugger::DestroyProcess(const lldb::StateType state) {
}

Status ProcessDebugger::HaltProcess(bool &caused_stop) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
Status error;
llvm::sys::ScopedLock lock(m_mutex);
caused_stop = ::DebugBreakProcess(m_session_data->m_debugger->GetProcess()
Expand All @@ -263,7 +263,7 @@ Status ProcessDebugger::ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
size_t &bytes_read) {
Status error;
bytes_read = 0;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);

if (!m_session_data) {
Expand Down Expand Up @@ -297,7 +297,7 @@ Status ProcessDebugger::WriteMemory(lldb::addr_t vm_addr, const void *buf,
size_t size, size_t &bytes_written) {
Status error;
bytes_written = 0;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);
LLDB_LOG(log, "attempting to write {0} bytes into address {1:x}", size,
vm_addr);
Expand Down Expand Up @@ -327,7 +327,7 @@ Status ProcessDebugger::AllocateMemory(size_t size, uint32_t permissions,
lldb::addr_t &addr) {
Status error;
addr = LLDB_INVALID_ADDRESS;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);
LLDB_LOG(log, "attempting to allocate {0} bytes with permissions {1}", size,
permissions);
Expand Down Expand Up @@ -355,7 +355,7 @@ Status ProcessDebugger::AllocateMemory(size_t size, uint32_t permissions,
Status ProcessDebugger::DeallocateMemory(lldb::addr_t vm_addr) {
Status result;

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);
LLDB_LOG(log, "attempting to deallocate bytes at address {0}", vm_addr);

Expand All @@ -379,7 +379,7 @@ Status ProcessDebugger::DeallocateMemory(lldb::addr_t vm_addr) {

Status ProcessDebugger::GetMemoryRegionInfo(lldb::addr_t vm_addr,
MemoryRegionInfo &info) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
Status error;
llvm::sys::ScopedLock lock(m_mutex);
info.Clear();
Expand Down Expand Up @@ -484,7 +484,7 @@ void ProcessDebugger::OnDebuggerConnected(lldb::addr_t image_base) {}
ExceptionResult
ProcessDebugger::OnDebugException(bool first_chance,
const ExceptionRecord &record) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION);
Log *log = GetLog(WindowsLog::Exception);
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
Expand Down Expand Up @@ -538,7 +538,7 @@ void ProcessDebugger::OnDebugString(const std::string &string) {}

void ProcessDebugger::OnDebuggerError(const Status &error, uint32_t type) {
llvm::sys::ScopedLock lock(m_mutex);
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);

if (m_session_data->m_initial_stop_received) {
// This happened while debugging. Do we shutdown the debugging session,
Expand All @@ -564,8 +564,7 @@ void ProcessDebugger::OnDebuggerError(const Status &error, uint32_t type) {
Status ProcessDebugger::WaitForDebuggerConnection(DebuggerThreadSP debugger,
HostProcess &process) {
Status result;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS |
WINDOWS_LOG_BREAKPOINTS);
Log *log = GetLog(WindowsLog::Process | WindowsLog::Breakpoints);
LLDB_LOG(log, "Waiting for loader breakpoint.");

// Block this function until we receive the initial stop from the process.
Expand Down

0 comments on commit 6730df4

Please sign in to comment.