diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
commit | 74a628f776edb588bff8f8f5cc16eac947c9d631 (patch) | |
tree | dc32e010ac4902621e5a279bfeb48628f7f0e166 /source/Plugins/Process/Windows/Common | |
parent | afed7be32164a598f8172282c249af7266c48b46 (diff) |
Notes
Diffstat (limited to 'source/Plugins/Process/Windows/Common')
10 files changed, 286 insertions, 547 deletions
diff --git a/source/Plugins/Process/Windows/Common/CMakeLists.txt b/source/Plugins/Process/Windows/Common/CMakeLists.txt index 9386ed8a0e4c4..009a289bae399 100644 --- a/source/Plugins/Process/Windows/Common/CMakeLists.txt +++ b/source/Plugins/Process/Windows/Common/CMakeLists.txt @@ -20,6 +20,17 @@ elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) ) endif() -add_lldb_library(lldbPluginProcessWindowsCommon +add_lldb_library(lldbPluginProcessWindowsCommon PLUGIN ${PROC_WINDOWS_COMMON_SOURCES} + + LINK_LIBS + lldbCore + lldbHost + lldbInterpreter + lldbSymbol + lldbTarget + ws2_32 + rpcrt4 + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Process/Windows/Common/DebuggerThread.cpp b/source/Plugins/Process/Windows/Common/DebuggerThread.cpp index be1462aa6602c..b79359ba96676 100644 --- a/source/Plugins/Process/Windows/Common/DebuggerThread.cpp +++ b/source/Plugins/Process/Windows/Common/DebuggerThread.cpp @@ -11,23 +11,23 @@ #include "ExceptionRecord.h" #include "IDebugDelegate.h" -#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" #include "lldb/Host/windows/HostProcessWindows.h" #include "lldb/Host/windows/HostThreadWindows.h" #include "lldb/Host/windows/ProcessLauncherWindows.h" #include "lldb/Target/Process.h" #include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" using namespace lldb; @@ -61,9 +61,8 @@ DebuggerThread::DebuggerThread(DebugDelegateSP debug_delegate) DebuggerThread::~DebuggerThread() { ::CloseHandle(m_debugging_ended_event); } Error DebuggerThread::DebugLaunch(const ProcessLaunchInfo &launch_info) { - WINLOG_IFALL(WINDOWS_LOG_PROCESS, - "DebuggerThread::DebugLaunch launching '%s'", - launch_info.GetExecutableFile().GetPath().c_str()); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); + LLDB_LOG(log, "launching '{0}'", launch_info.GetExecutableFile().GetPath()); Error error; DebugLaunchContext *context = new DebugLaunchContext(this, launch_info); @@ -71,19 +70,16 @@ Error DebuggerThread::DebugLaunch(const ProcessLaunchInfo &launch_info) { "lldb.plugin.process-windows.slave[?]", DebuggerThreadLaunchRoutine, context, &error)); - if (!error.Success()) { - WINERR_IFALL(WINDOWS_LOG_PROCESS, - "DebugLaunch couldn't launch debugger thread. %s", - error.AsCString()); - } + if (!error.Success()) + LLDB_LOG(log, "couldn't launch debugger thread. {0}", error); return error; } Error DebuggerThread::DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info) { - WINLOG_IFALL(WINDOWS_LOG_PROCESS, - "DebuggerThread::DebugAttach attaching to '%llu'", pid); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); + LLDB_LOG(log, "attaching to '{0}'", pid); Error error; DebugAttachContext *context = new DebugAttachContext(this, pid, attach_info); @@ -91,11 +87,8 @@ Error DebuggerThread::DebugAttach(lldb::pid_t pid, "lldb.plugin.process-windows.slave[?]", DebuggerThreadAttachRoutine, context, &error)); - if (!error.Success()) { - WINERR_IFALL(WINDOWS_LOG_PROCESS, - "DebugAttach couldn't attach to process '%llu'. %s", pid, - error.AsCString()); - } + if (!error.Success()) + LLDB_LOG(log, "couldn't attach to process '{0}'. {1}", pid, error); return error; } @@ -123,9 +116,9 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadLaunchRoutine( // thread routine has exited. std::shared_ptr<DebuggerThread> this_ref(shared_from_this()); - WINLOG_IFALL(WINDOWS_LOG_PROCESS, - "DebuggerThread preparing to launch '%s' on background thread.", - launch_info.GetExecutableFile().GetPath().c_str()); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); + LLDB_LOG(log, "preparing to launch '{0}' on background thread.", + launch_info.GetExecutableFile().GetPath()); Error error; ProcessLauncherWindows launcher; @@ -154,9 +147,9 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadAttachRoutine( // thread routine has exited. std::shared_ptr<DebuggerThread> this_ref(shared_from_this()); - WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DebuggerThread preparing to attach to " - "process '%llu' on background thread.", - pid); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); + LLDB_LOG(log, "preparing to attach to process '{0}' on background thread.", + pid); if (!DebugActiveProcess((DWORD)pid)) { Error error(::GetLastError(), eErrorTypeWin32); @@ -179,9 +172,8 @@ Error DebuggerThread::StopDebugging(bool terminate) { lldb::pid_t pid = m_process.GetProcessId(); - WINLOG_IFALL(WINDOWS_LOG_PROCESS, - "StopDebugging('%s') called (inferior=%I64u).", - (terminate ? "true" : "false"), pid); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_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 // true. @@ -200,10 +192,9 @@ Error DebuggerThread::StopDebugging(bool terminate) { // next debug // event we get is the exit process event, and not some other event. BOOL terminate_suceeded = TerminateProcess(handle, 0); - WINLOG_IFALL(WINDOWS_LOG_PROCESS, "StopDebugging called " - "TerminateProcess(0x%p, 0) " - "(inferior=%I64u), success='%s'", - handle, pid, (terminate_suceeded ? "true" : "false")); + LLDB_LOG(log, + "calling TerminateProcess({0}, 0) (inferior={1}), success={2}", + handle, pid, terminate_suceeded); } // If we're stuck waiting for an exception to continue (e.g. the user is at a @@ -213,9 +204,7 @@ Error DebuggerThread::StopDebugging(bool terminate) { // to make sure that the very next call to WaitForDebugEvent is an exit // process event. if (m_active_exception.get()) { - WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_EXCEPTION, - "StopDebugging masking active exception"); - + LLDB_LOG(log, "masking active exception"); ContinueAsyncException(ExceptionResult::MaskException); } @@ -231,26 +220,19 @@ Error DebuggerThread::StopDebugging(bool terminate) { } } - WINLOG_IFALL( - WINDOWS_LOG_PROCESS, - "StopDebugging waiting for detach from process %llu to complete.", pid); + LLDB_LOG(log, "waiting for detach from process {0} to complete.", pid); DWORD wait_result = WaitForSingleObject(m_debugging_ended_event, 5000); if (wait_result != WAIT_OBJECT_0) { error.SetError(GetLastError(), eErrorTypeWin32); - WINERR_IFALL(WINDOWS_LOG_PROCESS, - "StopDebugging WaitForSingleObject(0x%p, 5000) returned %lu", - m_debugging_ended_event, wait_result); - } else { - WINLOG_IFALL( - WINDOWS_LOG_PROCESS, - "StopDebugging detach from process %llu completed successfully.", pid); - } + LLDB_LOG(log, "error: WaitForSingleObject({0}, 5000) returned {1}", + m_debugging_ended_event, wait_result); + } else + LLDB_LOG(log, "detach from process {0} completed successfully.", pid); if (!error.Success()) { - WINERR_IFALL(WINDOWS_LOG_PROCESS, "StopDebugging encountered an error " - "while trying to stop process %llu. %s", - pid, error.AsCString()); + LLDB_LOG(log, "encountered an error while trying to stop process {0}. {1}", + pid, error); } return error; } @@ -259,10 +241,10 @@ void DebuggerThread::ContinueAsyncException(ExceptionResult result) { if (!m_active_exception.get()) return; - WINLOG_IFANY( - WINDOWS_LOG_PROCESS | WINDOWS_LOG_EXCEPTION, - "ContinueAsyncException called for inferior process %I64u, broadcasting.", - m_process.GetProcessId()); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS | + WINDOWS_LOG_EXCEPTION); + LLDB_LOG(log, "broadcasting for inferior process {0}.", + m_process.GetProcessId()); m_active_exception.reset(); m_exception_pred.SetValue(result, eBroadcastAlways); @@ -278,11 +260,12 @@ void DebuggerThread::FreeProcessHandles() { } void DebuggerThread::DebugLoop() { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT); DEBUG_EVENT dbe = {}; bool should_debug = true; - WINLOG_IFALL(WINDOWS_LOG_EVENT, "Entering WaitForDebugEvent loop"); + LLDB_LOGV(log, "Entering WaitForDebugEvent loop"); while (should_debug) { - WINLOGD_IFALL(WINDOWS_LOG_EVENT, "Calling WaitForDebugEvent"); + LLDB_LOGV(log, "Calling WaitForDebugEvent"); BOOL wait_result = WaitForDebugEvent(&dbe, INFINITE); if (wait_result) { DWORD continue_status = DBG_CONTINUE; @@ -331,11 +314,9 @@ void DebuggerThread::DebugLoop() { break; } - WINLOGD_IFALL( - WINDOWS_LOG_EVENT, - "DebugLoop calling ContinueDebugEvent(%lu, %lu, %lu) on thread %lu.", - dbe.dwProcessId, dbe.dwThreadId, continue_status, - ::GetCurrentThreadId()); + LLDB_LOGV(log, "calling ContinueDebugEvent({0}, {1}, {2}) on thread {3}.", + dbe.dwProcessId, dbe.dwThreadId, continue_status, + ::GetCurrentThreadId()); ::ContinueDebugEvent(dbe.dwProcessId, dbe.dwThreadId, continue_status); @@ -343,23 +324,23 @@ void DebuggerThread::DebugLoop() { should_debug = false; } } else { - WINERR_IFALL( - WINDOWS_LOG_EVENT, - "DebugLoop returned FALSE from WaitForDebugEvent. Error = %lu", - ::GetLastError()); + LLDB_LOG(log, "returned FALSE from WaitForDebugEvent. Error = {0}", + ::GetLastError()); should_debug = false; } } FreeProcessHandles(); - WINLOG_IFALL(WINDOWS_LOG_EVENT, "WaitForDebugEvent loop completed, exiting."); + LLDB_LOG(log, "WaitForDebugEvent loop completed, exiting."); SetEvent(m_debugging_ended_event); } ExceptionResult DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id) { + Log *log = + ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION); if (m_is_shutting_down) { // A breakpoint that occurs while `m_pid_to_detach` is non-zero is a magic // exception that @@ -367,10 +348,8 @@ DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, // debug loop. if (m_pid_to_detach != 0 && info.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT) { - WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION | - WINDOWS_LOG_PROCESS, - "Breakpoint exception is cue to detach from process 0x%lx", - m_pid_to_detach.load()); + LLDB_LOG(log, "Breakpoint exception is cue to detach from process {0:x}", + m_pid_to_detach.load()); ::DebugActiveProcessStop(m_pid_to_detach); m_detached = true; } @@ -385,36 +364,29 @@ DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, m_active_exception.reset( new ExceptionRecord(info.ExceptionRecord, thread_id)); - WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION, - "HandleExceptionEvent encountered %s chance exception 0x%lx on " - "thread 0x%lx", - first_chance ? "first" : "second", - info.ExceptionRecord.ExceptionCode, thread_id); + LLDB_LOG(log, "encountered {0} chance exception {1:x} on thread {2:x}", + first_chance ? "first" : "second", + info.ExceptionRecord.ExceptionCode, thread_id); ExceptionResult result = m_debug_delegate->OnDebugException(first_chance, *m_active_exception); m_exception_pred.SetValue(result, eBroadcastNever); - WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION, - "DebuggerThread::HandleExceptionEvent waiting for ExceptionPred " - "!= BreakInDebugger"); - + LLDB_LOG(log, "waiting for ExceptionPred != BreakInDebugger"); m_exception_pred.WaitForValueNotEqualTo(ExceptionResult::BreakInDebugger, result); - WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION, - "DebuggerThread::HandleExceptionEvent got ExceptionPred = %u", - m_exception_pred.GetValue()); - + LLDB_LOG(log, "got ExceptionPred = {0}", (int)m_exception_pred.GetValue()); return result; } DWORD DebuggerThread::HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, DWORD thread_id) { - WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD, - "HandleCreateThreadEvent Thread 0x%lx spawned in process %llu", - thread_id, m_process.GetProcessId()); + Log *log = + ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD); + LLDB_LOG(log, "Thread {0:x} spawned in process {1}", thread_id, + m_process.GetProcessId()); HostThread thread(info.hThread); thread.GetNativeThread().SetOwnsHandle(false); m_debug_delegate->OnCreateThread(thread); @@ -424,16 +396,17 @@ 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); uint32_t process_id = ::GetProcessId(info.hProcess); - WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_PROCESS, - "HandleCreateProcessEvent process %u spawned", process_id); + LLDB_LOG(log, "process {0} spawned", process_id); std::string thread_name; llvm::raw_string_ostream name_stream(thread_name); name_stream << "lldb.plugin.process-windows.slave[" << process_id << "]"; name_stream.flush(); - ThisThread::SetName(thread_name.c_str()); + llvm::set_thread_name(thread_name); // info.hProcess and info.hThread are closed automatically by Windows when // EXIT_PROCESS_DEBUG_EVENT is received. @@ -452,10 +425,10 @@ DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, DWORD DebuggerThread::HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD thread_id) { - WINLOG_IFANY( - WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD, - "HandleExitThreadEvent Thread %lu exited with code %lu in process %llu", - thread_id, info.dwExitCode, m_process.GetProcessId()); + Log *log = + ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_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); return DBG_CONTINUE; } @@ -463,9 +436,10 @@ DebuggerThread::HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWORD thread_id) { - WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD, - "HandleExitProcessEvent process %llu exited with code %lu", - m_process.GetProcessId(), info.dwExitCode); + Log *log = + ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD); + LLDB_LOG(log, "process {0} exited with code {1}", m_process.GetProcessId(), + info.dwExitCode); m_debug_delegate->OnExitProcess(info.dwExitCode); @@ -476,11 +450,11 @@ 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); if (info.hFile == nullptr) { // Not sure what this is, so just ignore it. - WINWARN_IFALL(WINDOWS_LOG_EVENT, "Inferior %llu - HandleLoadDllEvent has " - "a NULL file handle, returning...", - m_process.GetProcessId()); + LLDB_LOG(log, "Warning: Inferior {0} has a NULL file handle, returning...", + m_process.GetProcessId()); return DBG_CONTINUE; } @@ -502,16 +476,15 @@ DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, ModuleSpec module_spec(file_spec); lldb::addr_t load_addr = reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll); - WINLOG_IFALL(WINDOWS_LOG_EVENT, "Inferior %I64u - HandleLoadDllEvent DLL " - "'%s' loaded at address 0x%p...", - m_process.GetProcessId(), path, info.lpBaseOfDll); + LLDB_LOG(log, "Inferior {0} - DLL '{1}' loaded at address {2:x}...", + m_process.GetProcessId(), path, info.lpBaseOfDll); m_debug_delegate->OnLoadDll(module_spec, load_addr); } else { - WINERR_IFALL(WINDOWS_LOG_EVENT, "Inferior %llu - HandleLoadDllEvent Error " - "%lu occurred calling " - "GetFinalPathNameByHandle", - m_process.GetProcessId(), ::GetLastError()); + LLDB_LOG( + log, + "Inferior {0} - Error {1} occurred calling GetFinalPathNameByHandle", + m_process.GetProcessId(), ::GetLastError()); } // Windows does not automatically close info.hFile, so we need to do it. ::CloseHandle(info.hFile); @@ -521,9 +494,9 @@ DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD DebuggerThread::HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, DWORD thread_id) { - WINLOG_IFALL(WINDOWS_LOG_EVENT, - "HandleUnloadDllEvent process %llu unloading DLL at addr 0x%p.", - m_process.GetProcessId(), info.lpBaseOfDll); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT); + LLDB_LOG(log, "process {0} unloading DLL at addr {1:x}.", + m_process.GetProcessId(), info.lpBaseOfDll); m_debug_delegate->OnUnloadDll( reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll)); @@ -538,9 +511,9 @@ DebuggerThread::HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD DebuggerThread::HandleRipEvent(const RIP_INFO &info, DWORD thread_id) { - WINERR_IFALL(WINDOWS_LOG_EVENT, "HandleRipEvent encountered error %lu " - "(type=%lu) in process %llu thread %lu", - info.dwError, info.dwType, m_process.GetProcessId(), thread_id); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT); + LLDB_LOG(log, "encountered error {0} (type={1}) in process {2} thread {3}", + info.dwError, info.dwType, m_process.GetProcessId(), thread_id); Error error(info.dwError, eErrorTypeWin32); m_debug_delegate->OnDebuggerError(error, info.dwType); diff --git a/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/source/Plugins/Process/Windows/Common/ProcessWindows.cpp index 50f787f78495a..56a98a8eef63e 100644 --- a/source/Plugins/Process/Windows/Common/ProcessWindows.cpp +++ b/source/Plugins/Process/Windows/Common/ProcessWindows.cpp @@ -23,6 +23,7 @@ #include "lldb/Host/HostProcess.h" #include "lldb/Host/windows/HostThreadWindows.h" #include "lldb/Host/windows/windows.h" +#include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/Target/StopInfo.h" @@ -30,6 +31,7 @@ #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/Format.h" +#include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" #include "DebuggerThread.h" @@ -102,9 +104,9 @@ ProcessSP ProcessWindows::CreateInstance(lldb::TargetSP target_sp, } void ProcessWindows::Initialize() { - static std::once_flag g_once_flag; + static llvm::once_flag g_once_flag; - std::call_once(g_once_flag, []() { + llvm::call_once(g_once_flag, []() { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance); }); @@ -156,35 +158,30 @@ lldb_private::ConstString ProcessWindows::GetPluginName() { uint32_t ProcessWindows::GetPluginVersion() { return 1; } Error ProcessWindows::EnableBreakpointSite(BreakpointSite *bp_site) { - WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS, - "EnableBreakpointSite called with bp_site 0x%p " - "(id=%d, addr=0x%llx)", - bp_site, bp_site->GetID(), bp_site->GetLoadAddress()); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_BREAKPOINTS); + LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site, + bp_site->GetID(), bp_site->GetLoadAddress()); Error error = EnableSoftwareBreakpoint(bp_site); - if (!error.Success()) { - WINERR_IFALL(WINDOWS_LOG_BREAKPOINTS, "EnableBreakpointSite failed. %s", - error.AsCString()); - } + if (!error.Success()) + LLDB_LOG(log, "error: {0}", error); return error; } Error ProcessWindows::DisableBreakpointSite(BreakpointSite *bp_site) { - WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS, - "DisableBreakpointSite called with bp_site 0x%p " - "(id=%d, addr=0x%llx)", - bp_site, bp_site->GetID(), bp_site->GetLoadAddress()); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_BREAKPOINTS); + LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site, + bp_site->GetID(), bp_site->GetLoadAddress()); Error error = DisableSoftwareBreakpoint(bp_site); - if (!error.Success()) { - WINERR_IFALL(WINDOWS_LOG_BREAKPOINTS, "DisableBreakpointSite failed. %s", - error.AsCString()); - } + if (!error.Success()) + LLDB_LOG(log, "error: {0}", error); return error; } Error ProcessWindows::DoDetach(bool keep_stopped) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); DebuggerThreadSP debugger_thread; StateType private_state; { @@ -197,10 +194,8 @@ Error ProcessWindows::DoDetach(bool keep_stopped) { private_state = GetPrivateState(); if (!m_session_data) { - WINWARN_IFALL( - WINDOWS_LOG_PROCESS, - "DoDetach called while state = %u, but there is no active session.", - private_state); + LLDB_LOG(log, "state = {0}, but there is no active session.", + private_state); return Error(); } @@ -209,11 +204,9 @@ Error ProcessWindows::DoDetach(bool keep_stopped) { Error error; if (private_state != eStateExited && private_state != eStateDetached) { - WINLOG_IFALL( - WINDOWS_LOG_PROCESS, - "DoDetach called for process %p while state = %d. Detaching...", - debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(), - private_state); + LLDB_LOG(log, "detaching from process {0} while state = {1}.", + debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(), + private_state); error = debugger_thread->StopDebugging(false); if (error.Success()) { SetPrivateState(eStateDetached); @@ -223,9 +216,9 @@ Error ProcessWindows::DoDetach(bool keep_stopped) { // we can be assured that no other thread will race for the session data. m_session_data.reset(); } else { - WINERR_IFALL( - WINDOWS_LOG_PROCESS, "DoDetach called for process %p while state = " - "%d, but cannot destroy in this state.", + LLDB_LOG( + log, + "error: process {0} in state = {1}, but cannot destroy in this state.", debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(), private_state); } @@ -241,6 +234,7 @@ Error ProcessWindows::DoLaunch(Module *exe_module, // to acquire // the mutex. + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); Error result; if (!launch_info.GetFlags().Test(eLaunchFlagDebug)) { StreamString stream; @@ -250,7 +244,7 @@ Error ProcessWindows::DoLaunch(Module *exe_module, std::string message = stream.GetString(); result.SetErrorString(message.c_str()); - WINERR_IFALL(WINDOWS_LOG_PROCESS, "%s", message.c_str()); + LLDB_LOG(log, "error: {0}", message); return result; } @@ -265,23 +259,21 @@ Error ProcessWindows::DoLaunch(Module *exe_module, // Kick off the DebugLaunch asynchronously and wait for it to complete. result = debugger->DebugLaunch(launch_info); if (result.Fail()) { - WINERR_IFALL(WINDOWS_LOG_PROCESS, "DoLaunch failed launching '%s'. %s", - launch_info.GetExecutableFile().GetPath().c_str(), - result.AsCString()); + LLDB_LOG(log, "failed launching '{0}'. {1}", + launch_info.GetExecutableFile().GetPath(), result); return result; } HostProcess process; Error error = WaitForDebuggerConnection(debugger, process); if (error.Fail()) { - WINERR_IFALL(WINDOWS_LOG_PROCESS, "DoLaunch failed launching '%s'. %s", - launch_info.GetExecutableFile().GetPath().c_str(), - error.AsCString()); + LLDB_LOG(log, "failed launching '{0}'. {1}", + launch_info.GetExecutableFile().GetPath(), error); return error; } - WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DoLaunch successfully launched '%s'", - launch_info.GetExecutableFile().GetPath().c_str()); + LLDB_LOG(log, "successfully launched '{0}'", + launch_info.GetExecutableFile().GetPath()); // We've hit the initial stop. If eLaunchFlagsStopAtEntry was specified, the // private state @@ -298,6 +290,7 @@ Error ProcessWindows::DoLaunch(Module *exe_module, Error ProcessWindows::DoAttachToProcessWithID( lldb::pid_t pid, const ProcessAttachInfo &attach_info) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); m_session_data.reset( new ProcessWindowsData(!attach_info.GetContinueOnceAttached())); @@ -309,27 +302,23 @@ Error ProcessWindows::DoAttachToProcessWithID( DWORD process_id = static_cast<DWORD>(pid); Error error = debugger->DebugAttach(process_id, attach_info); if (error.Fail()) { - WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DoAttachToProcessWithID encountered an " - "error occurred initiating the " - "asynchronous attach. %s", - error.AsCString()); + LLDB_LOG( + log, + "encountered an error occurred initiating the asynchronous attach. {0}", + error); return error; } HostProcess process; error = WaitForDebuggerConnection(debugger, process); if (error.Fail()) { - WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DoAttachToProcessWithID encountered an " - "error waiting for the debugger to " - "connect. %s", - error.AsCString()); + LLDB_LOG(log, + "encountered an error waiting for the debugger to connect. {0}", + error); return error; } - WINLOG_IFALL( - WINDOWS_LOG_PROCESS, - "DoAttachToProcessWithID successfully attached to process with pid=%lu", - process_id); + LLDB_LOG(log, "successfully attached to process with pid={0}", process_id); // We've hit the initial stop. If eLaunchFlagsStopAtEntry was specified, the // private state @@ -343,16 +332,15 @@ Error ProcessWindows::DoAttachToProcessWithID( } Error ProcessWindows::DoResume() { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); llvm::sys::ScopedLock lock(m_mutex); Error error; StateType private_state = GetPrivateState(); if (private_state == eStateStopped || private_state == eStateCrashed) { - WINLOG_IFALL( - WINDOWS_LOG_PROCESS, - "DoResume called for process %I64u while state is %u. Resuming...", - m_session_data->m_debugger->GetProcess().GetProcessId(), - GetPrivateState()); + LLDB_LOG(log, "process {0} is in state {1}. Resuming...", + m_session_data->m_debugger->GetProcess().GetProcessId(), + GetPrivateState()); ExceptionRecordSP active_exception = m_session_data->m_debugger->GetActiveException().lock(); @@ -364,8 +352,7 @@ Error ProcessWindows::DoResume() { ExceptionResult::MaskException); } - WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_THREAD, - "DoResume resuming %u threads.", m_thread_list.GetSize()); + LLDB_LOG(log, "resuming {0} threads.", m_thread_list.GetSize()); for (uint32_t i = 0; i < m_thread_list.GetSize(); ++i) { auto thread = std::static_pointer_cast<TargetThreadWindows>( @@ -375,16 +362,15 @@ Error ProcessWindows::DoResume() { SetPrivateState(eStateRunning); } else { - WINERR_IFALL( - WINDOWS_LOG_PROCESS, - "DoResume called for process %I64u but state is %u. Returning...", - m_session_data->m_debugger->GetProcess().GetProcessId(), - GetPrivateState()); + LLDB_LOG(log, "error: process %I64u is in state %u. Returning...", + m_session_data->m_debugger->GetProcess().GetProcessId(), + GetPrivateState()); } return error; } Error ProcessWindows::DoDestroy() { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); DebuggerThreadSP debugger_thread; StateType private_state; { @@ -398,10 +384,8 @@ Error ProcessWindows::DoDestroy() { private_state = GetPrivateState(); if (!m_session_data) { - WINWARN_IFALL( - WINDOWS_LOG_PROCESS, - "DoDestroy called while state = %u, but there is no active session.", - private_state); + LLDB_LOG(log, "warning: state = {0}, but there is no active session.", + private_state); return Error(); } @@ -410,28 +394,25 @@ Error ProcessWindows::DoDestroy() { Error error; if (private_state != eStateExited && private_state != eStateDetached) { - WINLOG_IFALL( - WINDOWS_LOG_PROCESS, "DoDestroy called for process %p while state = " - "%u. Shutting down...", - debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(), - private_state); + LLDB_LOG(log, "Shutting down process {0} while state = {1}.", + debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(), + private_state); error = debugger_thread->StopDebugging(true); // By the time StopDebugging returns, there is no more debugger thread, so // we can be assured that no other thread will race for the session data. m_session_data.reset(); } else { - WINERR_IFALL( - WINDOWS_LOG_PROCESS, "DoDestroy called for process %p while state = " - "%d, but cannot destroy in this state.", - debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(), - private_state); + LLDB_LOG(log, "cannot destroy process {0} while state = {1}", + debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(), + private_state); } return error; } Error ProcessWindows::DoHalt(bool &caused_stop) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); Error error; StateType state = GetPrivateState(); if (state == eStateStopped) @@ -443,10 +424,7 @@ Error ProcessWindows::DoHalt(bool &caused_stop) { .GetSystemHandle()); if (!caused_stop) { error.SetError(::GetLastError(), eErrorTypeWin32); - WINERR_IFALL( - WINDOWS_LOG_PROCESS, - "DoHalt called DebugBreakProcess, but it failed with error %u", - error.GetError()); + LLDB_LOG(log, "DebugBreakProcess failed with error {0}", error); } } return error; @@ -468,12 +446,11 @@ void ProcessWindows::DidAttach(ArchSpec &arch_spec) { } void ProcessWindows::RefreshStateAfterStop() { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION); llvm::sys::ScopedLock lock(m_mutex); if (!m_session_data) { - WINWARN_IFALL( - WINDOWS_LOG_PROCESS, - "RefreshStateAfterStop called with no active session. Returning..."); + LLDB_LOG(log, "no active session. Returning..."); return; } @@ -483,11 +460,9 @@ void ProcessWindows::RefreshStateAfterStop() { m_session_data->m_debugger->GetActiveException(); ExceptionRecordSP active_exception = exception_record.lock(); if (!active_exception) { - WINERR_IFALL( - WINDOWS_LOG_PROCESS, - "RefreshStateAfterStop called for process %I64u but there is no " - "active exception. Why is the process stopped?", - m_session_data->m_debugger->GetProcess().GetProcessId()); + LLDB_LOG(log, "there is no active exception in process {0}. Why is the " + "process stopped?", + m_session_data->m_debugger->GetProcess().GetProcessId()); return; } @@ -503,19 +478,15 @@ void ProcessWindows::RefreshStateAfterStop() { const uint64_t pc = register_context->GetPC(); BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc)); if (site && site->ValidForThisThread(stop_thread.get())) { - WINLOG_IFANY(WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION | - WINDOWS_LOG_STEP, - "Single-stepped onto a breakpoint in process %I64u at " - "address 0x%I64x with breakpoint site %d", - m_session_data->m_debugger->GetProcess().GetProcessId(), pc, - site->GetID()); + LLDB_LOG(log, "Single-stepped onto a breakpoint in process {0} at " + "address {1:x} with breakpoint site {2}", + m_session_data->m_debugger->GetProcess().GetProcessId(), pc, + site->GetID()); stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID(*stop_thread, site->GetID()); stop_thread->SetStopInfo(stop_info); } else { - WINLOG_IFANY(WINDOWS_LOG_EXCEPTION | WINDOWS_LOG_STEP, - "RefreshStateAfterStop single stepping thread %llu", - stop_thread->GetID()); + LLDB_LOG(log, "single stepping thread {0}", stop_thread->GetID()); stop_info = StopInfo::CreateStopReasonToTrace(*stop_thread); stop_thread->SetStopInfo(stop_info); } @@ -530,37 +501,32 @@ void ProcessWindows::RefreshStateAfterStop() { BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc)); if (site) { - WINLOG_IFANY( - WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION, - "RefreshStateAfterStop detected breakpoint in process %I64u at " - "address 0x%I64x with breakpoint site %d", - m_session_data->m_debugger->GetProcess().GetProcessId(), pc, - site->GetID()); + LLDB_LOG(log, "detected breakpoint in process {0} at address {1:x} with " + "breakpoint site {2}", + m_session_data->m_debugger->GetProcess().GetProcessId(), pc, + site->GetID()); if (site->ValidForThisThread(stop_thread.get())) { - WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION, - "Breakpoint site %d is valid for this thread (0x%I64x), " - "creating stop info.", - site->GetID(), stop_thread->GetID()); + LLDB_LOG(log, "Breakpoint site {0} is valid for this thread ({1:x}), " + "creating stop info.", + site->GetID(), stop_thread->GetID()); stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID( *stop_thread, site->GetID()); register_context->SetPC(pc); } else { - WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION, - "Breakpoint site %d is not valid for this thread, " - "creating empty stop info.", - site->GetID()); + LLDB_LOG(log, "Breakpoint site {0} is not valid for this thread, " + "creating empty stop info.", + site->GetID()); } stop_thread->SetStopInfo(stop_info); return; } else { // The thread hit a hard-coded breakpoint like an `int 3` or // `__debugbreak()`. - WINLOG_IFALL( - WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION, - "No breakpoint site matches for this thread. __debugbreak()? " - "Creating stop info with the exception."); + LLDB_LOG(log, + "No breakpoint site matches for this thread. __debugbreak()? " + "Creating stop info with the exception."); // FALLTHROUGH: We'll treat this as a generic exception record in the // default case. } @@ -576,7 +542,7 @@ void ProcessWindows::RefreshStateAfterStop() { stop_info = StopInfo::CreateStopReasonWithException( *stop_thread, desc_stream.str().c_str()); stop_thread->SetStopInfo(stop_info); - WINLOG_IFALL(WINDOWS_LOG_EXCEPTION, "%s", desc_stream.str().c_str()); + LLDB_LOG(log, "{0}", desc_stream.str()); return; } } @@ -598,6 +564,7 @@ bool ProcessWindows::CanDebug(lldb::TargetSP target_sp, bool ProcessWindows::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_THREAD); // Add all the threads that were previously running and for which we did not // detect a thread exited event. int new_size = 0; @@ -613,15 +580,10 @@ bool ProcessWindows::UpdateThreadList(ThreadList &old_thread_list, new_thread_list.AddThread(old_thread); ++new_size; ++continued_threads; - WINLOGV_IFALL( - WINDOWS_LOG_THREAD, - "UpdateThreadList - Thread %llu was running and is still running.", - old_thread_id); + LLDB_LOGV(log, "Thread {0} was running and is still running.", + old_thread_id); } else { - WINLOGV_IFALL( - WINDOWS_LOG_THREAD, - "UpdateThreadList - Thread %llu was running and has exited.", - old_thread_id); + LLDB_LOGV(log, "Thread {0} was running and has exited.", old_thread_id); ++exited_threads; } } @@ -634,15 +596,11 @@ bool ProcessWindows::UpdateThreadList(ThreadList &old_thread_list, new_thread_list.AddThread(thread); ++new_size; ++new_threads; - WINLOGV_IFALL(WINDOWS_LOG_THREAD, - "UpdateThreadList - Thread %llu is new since last update.", - thread_info.first); + LLDB_LOGV(log, "Thread {0} is new since last update.", thread_info.first); } - WINLOG_IFALL( - WINDOWS_LOG_THREAD, - "UpdateThreadList - %d new threads, %d old threads, %d exited threads.", - new_threads, continued_threads, exited_threads); + LLDB_LOG(log, "{0} new threads, {1} old threads, {2} exited threads.", + new_threads, continued_threads, exited_threads); m_session_data->m_new_threads.clear(); m_session_data->m_exited_threads.clear(); @@ -666,14 +624,14 @@ bool ProcessWindows::IsAlive() { size_t ProcessWindows::DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Error &error) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY); llvm::sys::ScopedLock lock(m_mutex); if (!m_session_data) return 0; - WINLOG_IFALL(WINDOWS_LOG_MEMORY, - "DoReadMemory attempting to read %u bytes from address 0x%I64x", - size, vm_addr); + LLDB_LOG(log, "attempting to read {0} bytes from address {1:x}", size, + vm_addr); HostProcess process = m_session_data->m_debugger->GetProcess(); void *addr = reinterpret_cast<void *>(vm_addr); @@ -681,24 +639,20 @@ size_t ProcessWindows::DoReadMemory(lldb::addr_t vm_addr, void *buf, if (!ReadProcessMemory(process.GetNativeProcess().GetSystemHandle(), addr, buf, size, &bytes_read)) { error.SetError(GetLastError(), eErrorTypeWin32); - WINERR_IFALL(WINDOWS_LOG_MEMORY, "DoReadMemory failed with error code %u", - error.GetError()); + LLDB_LOG(log, "reading failed with error: {0}", error); } return bytes_read; } size_t ProcessWindows::DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY); llvm::sys::ScopedLock lock(m_mutex); - WINLOG_IFALL( - WINDOWS_LOG_MEMORY, - "DoWriteMemory attempting to write %u bytes into address 0x%I64x", size, - vm_addr); + LLDB_LOG(log, "attempting to write {0} bytes into address {1:x}", size, + vm_addr); if (!m_session_data) { - WINERR_IFANY( - WINDOWS_LOG_MEMORY, - "DoWriteMemory cannot write, there is no active debugger connection."); + LLDB_LOG(log, "cannot write, there is no active debugger connection."); return 0; } @@ -710,16 +664,14 @@ size_t ProcessWindows::DoWriteMemory(lldb::addr_t vm_addr, const void *buf, FlushInstructionCache(handle, addr, bytes_written); else { error.SetError(GetLastError(), eErrorTypeWin32); - WINLOG_IFALL(WINDOWS_LOG_MEMORY, "DoWriteMemory failed with error code %u", - error.GetError()); + LLDB_LOG(log, "writing failed with error: {0}", error); } return bytes_written; } -#define BOOL_STR(b) ((b) ? "true" : "false") - Error ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr, MemoryRegionInfo &info) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY); Error error; llvm::sys::ScopedLock lock(m_mutex); info.Clear(); @@ -727,7 +679,7 @@ Error ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr, if (!m_session_data) { error.SetErrorString( "GetMemoryRegionInfo called with no debugging session."); - WINERR_IFALL(WINDOWS_LOG_MEMORY, "%s", error.AsCString()); + LLDB_LOG(log, "error: {0}", error); return error; } HostProcess process = m_session_data->m_debugger->GetProcess(); @@ -735,12 +687,11 @@ Error ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr, if (handle == nullptr || handle == LLDB_INVALID_PROCESS) { error.SetErrorString( "GetMemoryRegionInfo called with an invalid target process."); - WINERR_IFALL(WINDOWS_LOG_MEMORY, "%s", error.AsCString()); + LLDB_LOG(log, "error: {0}", error); return error; } - WINLOG_IFALL(WINDOWS_LOG_MEMORY, - "GetMemoryRegionInfo getting info for address 0x%I64x", vm_addr); + LLDB_LOG(log, "getting info for address {0:x}", vm_addr); void *addr = reinterpret_cast<void *>(vm_addr); MEMORY_BASIC_INFORMATION mem_info = {}; @@ -761,10 +712,9 @@ Error ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr, return error; } else { error.SetError(::GetLastError(), eErrorTypeWin32); - WINERR_IFALL(WINDOWS_LOG_MEMORY, "VirtualQueryEx returned error %u while " - "getting memory region info for address " - "0x%I64x", - error.GetError(), vm_addr); + LLDB_LOG(log, "VirtualQueryEx returned error {0} while getting memory " + "region info for address {1:x}", + error, vm_addr); return error; } } @@ -806,10 +756,10 @@ Error ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr, } error.SetError(::GetLastError(), eErrorTypeWin32); - WINLOGV_IFALL(WINDOWS_LOG_MEMORY, "Memory region info for address %llu: " - "readable=%s, executable=%s, writable=%s", - vm_addr, BOOL_STR(info.GetReadable()), - BOOL_STR(info.GetExecutable()), BOOL_STR(info.GetWritable())); + LLDB_LOGV(log, "Memory region info for address {0}: readable={1}, " + "executable={2}, writable={3}", + vm_addr, info.GetReadable(), info.GetExecutable(), + info.GetWritable()); return error; } @@ -825,8 +775,8 @@ lldb::addr_t ProcessWindows::GetImageInfoAddress() { void ProcessWindows::OnExitProcess(uint32_t exit_code) { // No need to acquire the lock since m_session_data isn't accessed. - WINLOG_IFALL(WINDOWS_LOG_PROCESS, "Process %llu exited with code %u", GetID(), - exit_code); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); + LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code); TargetSP target = m_target_sp.lock(); if (target) { @@ -842,10 +792,9 @@ void ProcessWindows::OnExitProcess(uint32_t exit_code) { void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) { DebuggerThreadSP debugger = m_session_data->m_debugger; - - WINLOG_IFALL(WINDOWS_LOG_PROCESS, - "Debugger connected to process %I64u. Image base = 0x%I64x", - debugger->GetProcess().GetProcessId(), image_base); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); + LLDB_LOG(log, "Debugger connected to process {0}. Image base = {1:x}", + debugger->GetProcess().GetProcessId(), image_base); ModuleSP module = GetTarget().GetExecutableModule(); if (!module) { @@ -889,6 +838,7 @@ void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) { ExceptionResult ProcessWindows::OnDebugException(bool first_chance, const ExceptionRecord &record) { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION); llvm::sys::ScopedLock lock(m_mutex); // FIXME: Without this check, occasionally when running the test suite there @@ -901,10 +851,9 @@ ProcessWindows::OnDebugException(bool first_chance, // full // lldb logs, and then add logging to the process plugin. if (!m_session_data) { - WINERR_IFANY(WINDOWS_LOG_EXCEPTION, "Debugger thread reported exception " - "0x%lx at address 0x%llu, but there is " - "no session.", - record.GetExceptionCode(), record.GetExceptionAddress()); + LLDB_LOG(log, "Debugger thread reported exception {0:x} at address {1:x}, " + "but there is no session.", + record.GetExceptionCode(), record.GetExceptionAddress()); return ExceptionResult::SendToApplication; } @@ -920,16 +869,15 @@ ProcessWindows::OnDebugException(bool first_chance, result = ExceptionResult::BreakInDebugger; if (!m_session_data->m_initial_stop_received) { - WINLOG_IFANY(WINDOWS_LOG_BREAKPOINTS, "Hit loader breakpoint at address " - "0x%I64x, setting initial stop " - "event.", - record.GetExceptionAddress()); + LLDB_LOG( + log, + "Hit loader breakpoint at address {0:x}, setting initial stop event.", + record.GetExceptionAddress()); m_session_data->m_initial_stop_received = true; ::SetEvent(m_session_data->m_initial_stop_event); } else { - WINLOG_IFANY(WINDOWS_LOG_BREAKPOINTS, - "Hit non-loader breakpoint at address 0x%I64x.", - record.GetExceptionAddress()); + LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.", + record.GetExceptionAddress()); } SetPrivateState(eStateStopped); break; @@ -938,11 +886,10 @@ ProcessWindows::OnDebugException(bool first_chance, SetPrivateState(eStateStopped); break; default: - WINLOG_IFANY(WINDOWS_LOG_EXCEPTION, "Debugger thread reported exception " - "0x%lx at address 0x%llx " - "(first_chance=%s)", - record.GetExceptionCode(), record.GetExceptionAddress(), - BOOL_STR(first_chance)); + LLDB_LOG(log, "Debugger thread reported exception {0:x} at address {1:x} " + "(first_chance={2})", + record.GetExceptionCode(), record.GetExceptionAddress(), + first_chance); // For non-breakpoints, give the application a chance to handle the // exception first. if (first_chance) @@ -1010,14 +957,14 @@ void ProcessWindows::OnDebugString(const std::string &string) {} void ProcessWindows::OnDebuggerError(const Error &error, uint32_t type) { llvm::sys::ScopedLock lock(m_mutex); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS); if (m_session_data->m_initial_stop_received) { // This happened while debugging. Do we shutdown the debugging session, try - // to continue, - // or do something else? - WINERR_IFALL(WINDOWS_LOG_PROCESS, "Error %u occurred during debugging. " - "Unexpected behavior may result. %s", - error.GetError(), error.AsCString()); + // to continue, or do something else? + LLDB_LOG(log, "Error {0} occurred during debugging. Unexpected behavior " + "may result. {1}", + error.GetError(), error); } else { // If we haven't actually launched the process yet, this was an error // launching the @@ -1026,10 +973,10 @@ void ProcessWindows::OnDebuggerError(const Error &error, uint32_t type) { // method wakes up and returns a failure. m_session_data->m_launch_error = error; ::SetEvent(m_session_data->m_initial_stop_event); - WINERR_IFALL( - WINDOWS_LOG_PROCESS, - "Error %u occurred launching the process before the initial stop. %s", - error.GetError(), error.AsCString()); + LLDB_LOG( + log, + "Error {0} occurred launching the process before the initial stop. {1}", + error.GetError(), error); return; } } @@ -1037,14 +984,14 @@ void ProcessWindows::OnDebuggerError(const Error &error, uint32_t type) { Error ProcessWindows::WaitForDebuggerConnection(DebuggerThreadSP debugger, HostProcess &process) { Error result; - WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_BREAKPOINTS, - "WaitForDebuggerConnection Waiting for loader breakpoint."); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS | + WINDOWS_LOG_BREAKPOINTS); + LLDB_LOG(log, "Waiting for loader breakpoint."); // Block this function until we receive the initial stop from the process. if (::WaitForSingleObject(m_session_data->m_initial_stop_event, INFINITE) == WAIT_OBJECT_0) { - WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_BREAKPOINTS, - "WaitForDebuggerConnection hit loader breakpoint, returning."); + LLDB_LOG(log, "hit loader breakpoint, returning."); process = debugger->GetProcess(); return m_session_data->m_launch_error; diff --git a/source/Plugins/Process/Windows/Common/ProcessWindows.h b/source/Plugins/Process/Windows/Common/ProcessWindows.h index fac06c46b2ba8..f2db102299aef 100644 --- a/source/Plugins/Process/Windows/Common/ProcessWindows.h +++ b/source/Plugins/Process/Windows/Common/ProcessWindows.h @@ -11,8 +11,8 @@ #define liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_ // Other libraries and framework includes -#include "lldb/Core/Error.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/Error.h" #include "lldb/lldb-forward.h" #include "llvm/Support/Mutex.h" diff --git a/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp b/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp index 242c1996bdd46..386e9a5816c5f 100644 --- a/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp +++ b/source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp @@ -9,160 +9,33 @@ #include "ProcessWindowsLog.h" -#include <mutex> - -#include "lldb/Core/StreamFile.h" -#include "lldb/Interpreter/Args.h" -#include "llvm/Support/ManagedStatic.h" - -using namespace lldb; using namespace lldb_private; -// We want to avoid global constructors where code needs to be run so here we -// control access to our static g_log_sp by hiding it in a singleton function -// that will construct the static g_log_sp the first time this function is -// called. -static bool g_log_enabled = false; -static Log *g_log = nullptr; +static constexpr Log::Category g_categories[] = { + {{"break"}, {"log breakpoints"}, WINDOWS_LOG_BREAKPOINTS}, + {{"event"}, {"log low level debugger events"}, WINDOWS_LOG_EVENT}, + {{"exception"}, {"log exception information"}, WINDOWS_LOG_EXCEPTION}, + {{"memory"}, {"log memory reads and writes"}, WINDOWS_LOG_MEMORY}, + {{"process"}, {"log process events and activities"}, WINDOWS_LOG_PROCESS}, + {{"registers"}, {"log register read/writes"}, WINDOWS_LOG_REGISTERS}, + {{"step"}, {"log step related activities"}, WINDOWS_LOG_STEP}, + {{"thread"}, {"log thread events and activities"}, WINDOWS_LOG_THREAD}, +}; -static llvm::ManagedStatic<std::once_flag> g_once_flag; +Log::Channel ProcessWindowsLog::g_channel(g_categories, WINDOWS_LOG_PROCESS); void ProcessWindowsLog::Initialize() { - static ConstString g_name("windows"); - - std::call_once(*g_once_flag, []() { - Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories}; - - Log::RegisterLogChannel(g_name, log_callbacks); - RegisterPluginName(g_name); - }); + static llvm::once_flag g_once_flag; + llvm::call_once(g_once_flag, []() { Log::Register("windows", g_channel); }); } void ProcessWindowsLog::Terminate() {} -Log *ProcessWindowsLog::GetLog() { return (g_log_enabled) ? g_log : nullptr; } -bool ProcessWindowsLog::TestLogFlags(uint32_t mask, LogMaskReq req) { - Log *log = GetLog(); - if (!log) - return false; - uint32_t log_mask = log->GetMask().Get(); - if (req == LogMaskReq::All) - return ((log_mask & mask) == mask); - else - return (log_mask & mask); -} - -static uint32_t GetFlagBits(const char *arg) { - if (::strcasecmp(arg, "all") == 0) - return WINDOWS_LOG_ALL; - else if (::strcasecmp(arg, "break") == 0) - return WINDOWS_LOG_BREAKPOINTS; - else if (::strcasecmp(arg, "event") == 0) - return WINDOWS_LOG_EVENT; - else if (::strcasecmp(arg, "exception") == 0) - return WINDOWS_LOG_EXCEPTION; - else if (::strcasecmp(arg, "memory") == 0) - return WINDOWS_LOG_MEMORY; - else if (::strcasecmp(arg, "process") == 0) - return WINDOWS_LOG_PROCESS; - else if (::strcasecmp(arg, "registers") == 0) - return WINDOWS_LOG_REGISTERS; - else if (::strcasecmp(arg, "step") == 0) - return WINDOWS_LOG_STEP; - else if (::strcasecmp(arg, "thread") == 0) - return WINDOWS_LOG_THREAD; - else if (::strcasecmp(arg, "verbose") == 0) - return WINDOWS_LOG_VERBOSE; - return 0; -} -void ProcessWindowsLog::DisableLog(const char **args, Stream *feedback_strm) { - Log *log(GetLog()); - if (log) { - uint32_t flag_bits = 0; - if (args[0] != nullptr) { - flag_bits = log->GetMask().Get(); - for (; args[0]; args++) { - const char *arg = args[0]; - uint32_t bits = GetFlagBits(arg); - if (bits) { - flag_bits &= ~bits; - } else { - feedback_strm->Printf("error: unrecognized log category '%s'\n", arg); - ListLogCategories(feedback_strm); - } - } - } - log->GetMask().Reset(flag_bits); - if (flag_bits == 0) { - g_log_enabled = false; - log->SetStream(lldb::StreamSP()); - } - } - return; -} - -Log *ProcessWindowsLog::EnableLog(StreamSP &log_stream_sp, uint32_t log_options, - const char **args, Stream *feedback_strm) { - // Try see if there already is a log - that way we can reuse its settings. - // We could reuse the log in toto, but we don't know that the stream is the - // same. - uint32_t flag_bits = 0; - if (g_log) - flag_bits = g_log->GetMask().Get(); - - // Now make a new log with this stream if one was provided - if (log_stream_sp) { - if (g_log) - g_log->SetStream(log_stream_sp); - else - g_log = new Log(log_stream_sp); - } - - if (g_log) { - bool got_unknown_category = false; - for (; args[0]; args++) { - const char *arg = args[0]; - uint32_t bits = GetFlagBits(arg); - - if (bits) { - flag_bits |= bits; - } else { - feedback_strm->Printf("error: unrecognized log category '%s'\n", arg); - if (got_unknown_category == false) { - got_unknown_category = true; - ListLogCategories(feedback_strm); - } - } - } - if (flag_bits == 0) - flag_bits = WINDOWS_LOG_ALL; - g_log->GetMask().Reset(flag_bits); - g_log->GetOptions().Reset(log_options); - g_log_enabled = true; - } - return g_log; -} - -void ProcessWindowsLog::ListLogCategories(Stream *strm) { - strm->Printf("Logging categories for '%s':\n" - " all - turn on all available logging categories\n" - " break - log breakpoints\n" - " event - log low level debugger events\n" - " exception - log exception information\n" - " memory - log memory reads and writes\n" - " process - log process events and activities\n" - " registers - log register read/writes\n" - " thread - log thread events and activities\n" - " step - log step related activities\n" - " verbose - enable verbose logging\n", - ProcessWindowsLog::m_pluginname); -} -const char *ProcessWindowsLog::m_pluginname = ""; diff --git a/source/Plugins/Process/Windows/Common/ProcessWindowsLog.h b/source/Plugins/Process/Windows/Common/ProcessWindowsLog.h index cbb99e8d907e9..b7f59c7081431 100644 --- a/source/Plugins/Process/Windows/Common/ProcessWindowsLog.h +++ b/source/Plugins/Process/Windows/Common/ProcessWindowsLog.h @@ -10,9 +10,8 @@ #ifndef liblldb_ProcessWindowsLog_h_ #define liblldb_ProcessWindowsLog_h_ -#include "lldb/Core/Log.h" +#include "lldb/Utility/Log.h" -#define WINDOWS_LOG_VERBOSE (1u << 0) #define WINDOWS_LOG_PROCESS (1u << 1) // Log process operations #define WINDOWS_LOG_EXCEPTION (1u << 1) // Log exceptions #define WINDOWS_LOG_THREAD (1u << 2) // Log thread operations @@ -21,71 +20,17 @@ #define WINDOWS_LOG_STEP (1u << 5) // Log step operations #define WINDOWS_LOG_REGISTERS (1u << 6) // Log register operations #define WINDOWS_LOG_EVENT (1u << 7) // Low level debug events -#define WINDOWS_LOG_ALL (UINT32_MAX) - -enum class LogMaskReq { All, Any }; +namespace lldb_private { class ProcessWindowsLog { - static const char *m_pluginname; + static Log::Channel g_channel; public: - // --------------------------------------------------------------------- - // Public Static Methods - // --------------------------------------------------------------------- static void Initialize(); - static void Terminate(); - static void RegisterPluginName(const char *pluginName) { - m_pluginname = pluginName; - } - - static void RegisterPluginName(lldb_private::ConstString pluginName) { - m_pluginname = pluginName.GetCString(); - } - - static bool TestLogFlags(uint32_t mask, LogMaskReq req); - - static lldb_private::Log *GetLog(); - - static void DisableLog(const char **args, - lldb_private::Stream *feedback_strm); - - static lldb_private::Log *EnableLog(lldb::StreamSP &log_stream_sp, - uint32_t log_options, const char **args, - lldb_private::Stream *feedback_strm); - - static void ListLogCategories(lldb_private::Stream *strm); + static Log *GetLogIfAny(uint32_t mask) { return g_channel.GetLogIfAny(mask); } }; - -#define WINLOGF_IF(Flags, Req, Method, ...) \ - { \ - if (ProcessWindowsLog::TestLogFlags(Flags, Req)) { \ - Log *log = ProcessWindowsLog::GetLog(); \ - if (log) \ - log->Method(__VA_ARGS__); \ - } \ - } - -#define WINLOG_IFANY(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::Any, Printf, __VA_ARGS__) -#define WINLOG_IFALL(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::All, Printf, __VA_ARGS__) -#define WINLOGV_IFANY(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::Any, Verbose, __VA_ARGS__) -#define WINLOGV_IFALL(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::All, Verbose, __VA_ARGS__) -#define WINLOGD_IFANY(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::Any, Debug, __VA_ARGS__) -#define WINLOGD_IFALL(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::All, Debug, __VA_ARGS__) -#define WINERR_IFANY(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::Any, Error, __VA_ARGS__) -#define WINERR_IFALL(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::All, Error, __VA_ARGS__) -#define WINWARN_IFANY(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::Any, Warning, __VA_ARGS__) -#define WINWARN_IFALL(Flags, ...) \ - WINLOGF_IF(Flags, LogMaskReq::All, Warning, __VA_ARGS__) +} #endif // liblldb_ProcessWindowsLog_h_ diff --git a/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp b/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp index 0ef3c77e47c1f..bfed3044910de 100644 --- a/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp +++ b/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" #include "lldb/Host/windows/HostThreadWindows.h" #include "lldb/Host/windows/windows.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Error.h" #include "lldb/lldb-private-types.h" #include "ProcessWindowsLog.h" @@ -113,6 +113,7 @@ bool RegisterContextWindows::ClearHardwareWatchpoint(uint32_t hw_index) { bool RegisterContextWindows::HardwareSingleStep(bool enable) { return false; } bool RegisterContextWindows::CacheAllRegisterValues() { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS); if (!m_context_stale) return true; @@ -122,14 +123,13 @@ bool RegisterContextWindows::CacheAllRegisterValues() { if (!::GetThreadContext( wthread.GetHostThread().GetNativeThread().GetSystemHandle(), &m_context)) { - WINERR_IFALL( - WINDOWS_LOG_REGISTERS, - "GetThreadContext failed with error %lu while caching register values.", + LLDB_LOG( + log, + "GetThreadContext failed with error {0} while caching register values.", ::GetLastError()); return false; } - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, - "GetThreadContext successfully updated the register values."); + LLDB_LOG(log, "successfully updated the register values."); m_context_stale = false; return true; } diff --git a/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp b/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp index 8f2603c3365b7..a4d60303877e0 100644 --- a/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp +++ b/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp @@ -7,14 +7,14 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Core/Log.h" -#include "lldb/Core/Logging.h" #include "lldb/Core/State.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/HostNativeThreadBase.h" #include "lldb/Host/windows/HostThreadWindows.h" #include "lldb/Host/windows/windows.h" #include "lldb/Target/RegisterContext.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Logging.h" #include "ProcessWindows.h" #include "ProcessWindowsLog.h" diff --git a/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp b/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp index 942b4e97c40d5..53fe1d9024945 100644 --- a/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp +++ b/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Core/Error.h" #include "lldb/Core/RegisterValue.h" #include "lldb/Host/windows/HostThreadWindows.h" #include "lldb/Host/windows/windows.h" +#include "lldb/Utility/Error.h" #include "lldb/lldb-private-types.h" #include "RegisterContextWindows_x64.h" diff --git a/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp b/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp index 2938f77f3c2ae..8127606583cdf 100644 --- a/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp +++ b/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Core/Error.h" #include "lldb/Core/RegisterValue.h" #include "lldb/Host/windows/HostThreadWindows.h" #include "lldb/Host/windows/windows.h" +#include "lldb/Utility/Error.h" #include "lldb/lldb-private-types.h" #include "ProcessWindowsLog.h" @@ -203,7 +203,8 @@ bool RegisterContextWindows_x86::ReadRegister(const RegisterInfo *reg_info, return ReadRegisterHelper(CONTEXT_CONTROL, "EFLAGS", m_context.EFlags, reg_value); default: - WINWARN_IFALL(WINDOWS_LOG_REGISTERS, "Requested unknown register %u", reg); + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS); + LLDB_LOG(log, "Requested unknown register {0}", reg); break; } return false; @@ -219,62 +220,52 @@ bool RegisterContextWindows_x86::WriteRegister(const RegisterInfo *reg_info, if (!CacheAllRegisterValues()) return false; + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS); uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; switch (reg) { case lldb_eax_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EAX", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to EAX", reg_value.GetAsUInt32()); m_context.Eax = reg_value.GetAsUInt32(); break; case lldb_ebx_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBX", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to EBX", reg_value.GetAsUInt32()); m_context.Ebx = reg_value.GetAsUInt32(); break; case lldb_ecx_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ECX", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to ECX", reg_value.GetAsUInt32()); m_context.Ecx = reg_value.GetAsUInt32(); break; case lldb_edx_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDX", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to EDX", reg_value.GetAsUInt32()); m_context.Edx = reg_value.GetAsUInt32(); break; case lldb_edi_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDI", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to EDI", reg_value.GetAsUInt32()); m_context.Edi = reg_value.GetAsUInt32(); break; case lldb_esi_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESI", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to ESI", reg_value.GetAsUInt32()); m_context.Esi = reg_value.GetAsUInt32(); break; case lldb_ebp_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBP", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to EBP", reg_value.GetAsUInt32()); m_context.Ebp = reg_value.GetAsUInt32(); break; case lldb_esp_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESP", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to ESP", reg_value.GetAsUInt32()); m_context.Esp = reg_value.GetAsUInt32(); break; case lldb_eip_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EIP", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to EIP", reg_value.GetAsUInt32()); m_context.Eip = reg_value.GetAsUInt32(); break; case lldb_eflags_i386: - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EFLAGS", - reg_value.GetAsUInt32()); + LLDB_LOG(log, "Write value {0:x} to EFLAGS", reg_value.GetAsUInt32()); m_context.EFlags = reg_value.GetAsUInt32(); break; default: - WINWARN_IFALL(WINDOWS_LOG_REGISTERS, - "Write value 0x%x to unknown register %u", - reg_value.GetAsUInt32(), reg); + LLDB_LOG(log, "Write value {0:x} to unknown register {1}", + reg_value.GetAsUInt32(), reg); } // Physically update the registers in the target process. @@ -286,13 +277,12 @@ bool RegisterContextWindows_x86::WriteRegister(const RegisterInfo *reg_info, bool RegisterContextWindows_x86::ReadRegisterHelper( DWORD flags_required, const char *reg_name, DWORD value, RegisterValue ®_value) const { + Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS); if ((m_context.ContextFlags & flags_required) != flags_required) { - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Thread context doesn't have %s", - reg_name); + LLDB_LOG(log, "Thread context doesn't have {0}", reg_name); return false; } - WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Read value 0x%lx from %s", value, - reg_name); + LLDB_LOG(log, "Read value {0:x} from {1}", value, reg_name); reg_value.SetUInt32(value); return true; } |