summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2017-02-22 10:38:02 +0000
committerPavel Labath <labath@google.com>2017-02-22 10:38:02 +0000
commita385d2c1b66726ae7ca8960cb84fe3c146110019 (patch)
tree60c5dc3989a90bb69d5e47696a411d08105825ce /lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
parent048b3ece1db993cd0033d567a9396d372895f37a (diff)
downloadbcm5719-llvm-a385d2c1b66726ae7ca8960cb84fe3c146110019.tar.gz
bcm5719-llvm-a385d2c1b66726ae7ca8960cb84fe3c146110019.zip
Replace WINLOG_*** macros with LLDB_LOG
Summary: The main difference here is that in the WINLOG macros you can specify log categories per call, whereas here you have to go the usual lldb route of getting a Log* variable first. While this means you have to write at least two statements, it usually means that each statement will fit on a single line, whereas fitting the WINLOG invocation on a single line was almost impossible. So the total size of code does not increase even in functions with a single log statement, and functions with more logging get shorter. The downside here is reduced flexibility in specifying the log categories, which a couple of functions used quite heavily (e.g. RefreshStateAfterStop). For these I chose a single category used most prominently and put everything into that, although a solution with multiple log variables is definitely possible. Reviewers: zturner, amccarth Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D30172 llvm-svn: 295822
Diffstat (limited to 'lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp')
-rw-r--r--lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp331
1 files changed, 138 insertions, 193 deletions
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 28068d9a1eb..345b5730061 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -157,35 +157,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;
{
@@ -198,10 +193,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();
}
@@ -210,11 +203,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);
@@ -224,9 +215,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);
}
@@ -242,6 +233,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;
@@ -251,7 +243,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;
}
@@ -266,23 +258,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
@@ -299,6 +289,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()));
@@ -310,27 +301,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
@@ -344,16 +331,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();
@@ -365,8 +351,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>(
@@ -376,16 +361,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;
{
@@ -399,10 +383,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();
}
@@ -411,28 +393,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)
@@ -444,10 +423,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;
@@ -469,12 +445,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;
}
@@ -484,11 +459,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;
}
@@ -504,19 +477,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);
}
@@ -531,37 +500,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.
}
@@ -577,7 +541,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;
}
}
@@ -599,6 +563,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;
@@ -614,15 +579,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;
}
}
@@ -635,15 +595,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();
@@ -667,14 +623,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);
@@ -682,24 +638,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;
}
@@ -711,16 +663,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();
@@ -728,7 +678,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();
@@ -736,12 +686,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 = {};
@@ -762,10 +711,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;
}
}
@@ -807,10 +755,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;
}
@@ -826,8 +774,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) {
@@ -843,10 +791,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) {
@@ -890,6 +837,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
@@ -902,10 +850,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;
}
@@ -921,16 +868,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;
@@ -939,11 +885,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)
@@ -1011,14 +956,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
@@ -1027,10 +972,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;
}
}
@@ -1038,14 +983,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;
OpenPOWER on IntegriCloud