diff options
Diffstat (limited to 'lldb/source/Plugins/Process')
35 files changed, 1383 insertions, 1481 deletions
diff --git a/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp b/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp index 3ec410fe7d7..f70ef97a2bc 100644 --- a/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp +++ b/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp @@ -254,9 +254,8 @@ CreatePosixSpawnFileAction(const FileAction &action, case FileAction::eFileActionNone: default: - if (log) - log->Printf("%s(): unsupported file action %u", __FUNCTION__, - action.GetAction()); + LLDB_LOGF(log, "%s(): unsupported file action %u", __FUNCTION__, + action.GetAction()); break; } @@ -288,8 +287,7 @@ static Status PosixSpawnChildForPTraceDebugging(const char *path, int error_code; if ((error_code = ::posix_spawnattr_init(&attr)) != 0) { - if (log) - log->Printf("::posix_spawnattr_init(&attr) failed"); + LLDB_LOGF(log, "::posix_spawnattr_init(&attr) failed"); error.SetError(error_code, eErrorTypePOSIX); return error; } @@ -378,10 +376,10 @@ static Status PosixSpawnChildForPTraceDebugging(const char *path, error = CreatePosixSpawnFileAction(*action, &file_actions); if (!error.Success()) { - if (log) - log->Printf("%s(): error converting FileAction to posix_spawn " - "file action: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "%s(): error converting FileAction to posix_spawn " + "file action: %s", + __FUNCTION__, error.AsCString()); return error; } } @@ -416,10 +414,10 @@ static Status PosixSpawnChildForPTraceDebugging(const char *path, if (actual_cpu_type) { *actual_cpu_type = GetCPUTypeForLocalProcess(*pid); - if (log) - log->Printf("%s(): cpu type for launched process pid=%i: " - "cpu_type=0x%8.8x", - __FUNCTION__, *pid, *actual_cpu_type); + LLDB_LOGF(log, + "%s(): cpu type for launched process pid=%i: " + "cpu_type=0x%8.8x", + __FUNCTION__, *pid, *actual_cpu_type); } return error; @@ -477,23 +475,21 @@ Status LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd, char resolved_path[PATH_MAX]; resolved_path[0] = '\0'; - if (log) - log->Printf("%s(): attempting to resolve given binary path: \"%s\"", - __FUNCTION__, given_path); + LLDB_LOGF(log, "%s(): attempting to resolve given binary path: \"%s\"", + __FUNCTION__, given_path); // If we fail to resolve the path to our executable, then just use what we // were given and hope for the best if (!ResolveExecutablePath(given_path, resolved_path, sizeof(resolved_path))) { - if (log) - log->Printf("%s(): failed to resolve binary path, using " - "what was given verbatim and hoping for the best", - __FUNCTION__); + LLDB_LOGF(log, + "%s(): failed to resolve binary path, using " + "what was given verbatim and hoping for the best", + __FUNCTION__); ::strncpy(resolved_path, given_path, sizeof(resolved_path)); } else { - if (log) - log->Printf("%s(): resolved given binary path to: \"%s\"", __FUNCTION__, - resolved_path); + LLDB_LOGF(log, "%s(): resolved given binary path to: \"%s\"", __FUNCTION__, + resolved_path); } char launch_err_str[PATH_MAX]; diff --git a/lldb/source/Plugins/Process/Darwin/MachException.cpp b/lldb/source/Plugins/Process/Darwin/MachException.cpp index 70ad6736a74..073ad64b300 100644 --- a/lldb/source/Plugins/Process/Darwin/MachException.cpp +++ b/lldb/source/Plugins/Process/Darwin/MachException.cpp @@ -67,10 +67,11 @@ extern "C" kern_return_t catch_mach_exception_raise_state( // TODO change to LIBLLDB_LOG_EXCEPTION Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); if (log) { - log->Printf("::%s(exc_port = 0x%4.4x, exc_type = %d (%s), " - "exc_data = 0x%llx, exc_data_count = %d)", - __FUNCTION__, exc_port, exc_type, MachException::Name(exc_type), - (uint64_t)exc_data, exc_data_count); + LLDB_LOGF(log, + "::%s(exc_port = 0x%4.4x, exc_type = %d (%s), " + "exc_data = 0x%llx, exc_data_count = %d)", + __FUNCTION__, exc_port, exc_type, MachException::Name(exc_type), + (uint64_t)exc_data, exc_data_count); } return KERN_FAILURE; } @@ -83,13 +84,14 @@ extern "C" kern_return_t catch_mach_exception_raise_state_identity( thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); if (log) { - log->Printf("::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, " - "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] = " - "{ 0x%llx, 0x%llx })", - __FUNCTION__, exc_port, thread_port, task_port, exc_type, - MachException::Name(exc_type), exc_data_count, - (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD), - (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD)); + LLDB_LOGF(log, + "::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, " + "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] = " + "{ 0x%llx, 0x%llx })", + __FUNCTION__, exc_port, thread_port, task_port, exc_type, + MachException::Name(exc_type), exc_data_count, + (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD), + (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD)); } return KERN_FAILURE; @@ -102,13 +104,14 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port, mach_msg_type_number_t exc_data_count) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); if (log) { - log->Printf("::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, " - "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] " - "= { 0x%llx, 0x%llx })", - __FUNCTION__, exc_port, thread_port, task_port, exc_type, - MachException::Name(exc_type), exc_data_count, - (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD), - (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD)); + LLDB_LOGF(log, + "::%s(exc_port = 0x%4.4x, thd_port = 0x%4.4x, " + "tsk_port = 0x%4.4x, exc_type = %d (%s), exc_data[%d] " + "= { 0x%llx, 0x%llx })", + __FUNCTION__, exc_port, thread_port, task_port, exc_type, + MachException::Name(exc_type), exc_data_count, + (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD), + (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD)); } if (task_port == g_message->task_port) { @@ -187,15 +190,16 @@ Status MachException::Message::Receive(mach_port_t port, options & MACH_RCV_TIMEOUT ? timeout : 0; if (log && ((options & MACH_RCV_TIMEOUT) == 0)) { // Dump this log message if we have no timeout in case it never returns - log->Printf("::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, " - "local_port = %#x, reserved = 0x%x, id = 0x%x}, " - "option = %#x, send_size = 0, rcv_size = %llu, " - "rcv_name = %#x, timeout = %u, notify = %#x)", - exc_msg.hdr.msgh_bits, exc_msg.hdr.msgh_size, - exc_msg.hdr.msgh_remote_port, exc_msg.hdr.msgh_local_port, - exc_msg.hdr.msgh_reserved, exc_msg.hdr.msgh_id, options, - (uint64_t)sizeof(exc_msg.data), port, mach_msg_timeout, - notify_port); + LLDB_LOGF(log, + "::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, " + "local_port = %#x, reserved = 0x%x, id = 0x%x}, " + "option = %#x, send_size = 0, rcv_size = %llu, " + "rcv_name = %#x, timeout = %u, notify = %#x)", + exc_msg.hdr.msgh_bits, exc_msg.hdr.msgh_size, + exc_msg.hdr.msgh_remote_port, exc_msg.hdr.msgh_local_port, + exc_msg.hdr.msgh_reserved, exc_msg.hdr.msgh_id, options, + (uint64_t)sizeof(exc_msg.data), port, mach_msg_timeout, + notify_port); } mach_msg_return_t mach_err = @@ -213,15 +217,16 @@ Status MachException::Message::Receive(mach_port_t port, // Dump any errors we get if (error.Fail() && log) { - log->Printf("::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, " - "local_port = %#x, reserved = 0x%x, id = 0x%x}, " - "option = %#x, send_size = %u, rcv_size = %lu, rcv_name " - "= %#x, timeout = %u, notify = %#x) failed: %s", - exc_msg.hdr.msgh_bits, exc_msg.hdr.msgh_size, - exc_msg.hdr.msgh_remote_port, exc_msg.hdr.msgh_local_port, - exc_msg.hdr.msgh_reserved, exc_msg.hdr.msgh_id, options, 0, - sizeof(exc_msg.data), port, mach_msg_timeout, notify_port, - error.AsCString()); + LLDB_LOGF(log, + "::mach_msg(msg->{bits = %#x, size = %u remote_port = %#x, " + "local_port = %#x, reserved = 0x%x, id = 0x%x}, " + "option = %#x, send_size = %u, rcv_size = %lu, rcv_name " + "= %#x, timeout = %u, notify = %#x) failed: %s", + exc_msg.hdr.msgh_bits, exc_msg.hdr.msgh_size, + exc_msg.hdr.msgh_remote_port, exc_msg.hdr.msgh_local_port, + exc_msg.hdr.msgh_reserved, exc_msg.hdr.msgh_id, options, 0, + sizeof(exc_msg.data), port, mach_msg_timeout, notify_port, + error.AsCString()); } return error; } @@ -264,10 +269,10 @@ bool MachException::Message::CatchExceptionRaise(task_t task) { } else { Log *log( GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf("MachException::Message::%s(): mach_exc_server " - "returned zero...", - __FUNCTION__); + LLDB_LOGF(log, + "MachException::Message::%s(): mach_exc_server " + "returned zero...", + __FUNCTION__); } g_message = NULL; return success; @@ -293,10 +298,10 @@ Status MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task, auto mach_err = ::pid_for_task(state.task_port, &state_pid); if (mach_err) { error.SetError(mach_err, eErrorTypeMachKernel); - if (log) - log->Printf("MachException::Message::%s(): pid_for_task() " - "failed: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "MachException::Message::%s(): pid_for_task() " + "failed: %s", + __FUNCTION__, error.AsCString()); return error; } } @@ -309,25 +314,25 @@ Status MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task, error.SetError(errno, eErrorTypePOSIX); if (!error.Success()) { - if (log) - log->Printf("::ptrace(request = PT_THUPDATE, pid = " - "0x%4.4x, tid = 0x%4.4x, signal = %i)", - state_pid, state.thread_port, soft_signal); + LLDB_LOGF(log, + "::ptrace(request = PT_THUPDATE, pid = " + "0x%4.4x, tid = 0x%4.4x, signal = %i)", + state_pid, state.thread_port, soft_signal); return error; } } } - if (log) - log->Printf("::mach_msg ( msg->{bits = %#x, size = %u, remote_port " - "= %#x, local_port = %#x, reserved = 0x%x, id = 0x%x}, " - "option = %#x, send_size = %u, rcv_size = %u, rcv_name " - "= %#x, timeout = %u, notify = %#x)", - reply_msg.hdr.msgh_bits, reply_msg.hdr.msgh_size, - reply_msg.hdr.msgh_remote_port, reply_msg.hdr.msgh_local_port, - reply_msg.hdr.msgh_reserved, reply_msg.hdr.msgh_id, - MACH_SEND_MSG | MACH_SEND_INTERRUPT, reply_msg.hdr.msgh_size, 0, - MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + LLDB_LOGF(log, + "::mach_msg ( msg->{bits = %#x, size = %u, remote_port " + "= %#x, local_port = %#x, reserved = 0x%x, id = 0x%x}, " + "option = %#x, send_size = %u, rcv_size = %u, rcv_name " + "= %#x, timeout = %u, notify = %#x)", + reply_msg.hdr.msgh_bits, reply_msg.hdr.msgh_size, + reply_msg.hdr.msgh_remote_port, reply_msg.hdr.msgh_local_port, + reply_msg.hdr.msgh_reserved, reply_msg.hdr.msgh_id, + MACH_SEND_MSG | MACH_SEND_INTERRUPT, reply_msg.hdr.msgh_size, 0, + MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); auto mach_err = ::mach_msg(&reply_msg.hdr, MACH_SEND_MSG | MACH_SEND_INTERRUPT, @@ -342,12 +347,13 @@ Status MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task, log->PutCString("::mach_msg() - send interrupted"); // TODO: keep retrying to reply??? } else if (state.task_port == inferior_task) { - log->Printf("mach_msg(): returned an error when replying " - "to a mach exception: error = %u (%s)", - error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "mach_msg(): returned an error when replying " + "to a mach exception: error = %u (%s)", + error.GetError(), error.AsCString()); } else { - log->Printf("::mach_msg() - failed (child of task): %u (%s)", - error.GetError(), error.AsCString()); + LLDB_LOGF(log, "::mach_msg() - failed (child of task): %u (%s)", + error.GetError(), error.AsCString()); } } @@ -377,9 +383,8 @@ Status MachException::PortInfo::Save(task_t task) { Status error; Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf("MachException::PortInfo::%s(task = 0x%4.4x)", __FUNCTION__, - task); + LLDB_LOGF(log, "MachException::PortInfo::%s(task = 0x%4.4x)", __FUNCTION__, + task); // Be careful to be able to have debugserver built on a newer OS than what it // is currently running on by being able to start with all exceptions and @@ -394,13 +399,15 @@ Status MachException::PortInfo::Save(task_t task) { if (log) { if (error.Success()) { - log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = " - "0x%x, maskCnt => %u, ports, behaviors, flavors)", - task, mask, count); + LLDB_LOGF(log, + "::task_get_exception_ports(task = 0x%4.4x, mask = " + "0x%x, maskCnt => %u, ports, behaviors, flavors)", + task, mask, count); } else { - log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = 0x%x, " - "maskCnt => %u, ports, behaviors, flavors) error: %u (%s)", - task, mask, count, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "::task_get_exception_ports(task = 0x%4.4x, mask = 0x%x, " + "maskCnt => %u, ports, behaviors, flavors) error: %u (%s)", + task, mask, count, error.GetError(), error.AsCString()); } } @@ -413,15 +420,17 @@ Status MachException::PortInfo::Save(task_t task) { error.SetError(mach_err, eErrorTypeMachKernel); if (log) { if (error.Success()) { - log->Printf("::task_get_exception_ports(task = 0x%4.4x, " - "mask = 0x%x, maskCnt => %u, ports, behaviors, " - "flavors)", - task, mask, count); + LLDB_LOGF(log, + "::task_get_exception_ports(task = 0x%4.4x, " + "mask = 0x%x, maskCnt => %u, ports, behaviors, " + "flavors)", + task, mask, count); } else { - log->Printf("::task_get_exception_ports(task = 0x%4.4x, mask = " - "0x%x, maskCnt => %u, ports, behaviors, flavors) " - "error: %u (%s)", - task, mask, count, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "::task_get_exception_ports(task = 0x%4.4x, mask = " + "0x%x, maskCnt => %u, ports, behaviors, flavors) " + "error: %u (%s)", + task, mask, count, error.GetError(), error.AsCString()); } } } @@ -437,8 +446,7 @@ Status MachException::PortInfo::Restore(task_t task) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf("MachException::PortInfo::Restore(task = 0x%4.4x)", task); + LLDB_LOGF(log, "MachException::PortInfo::Restore(task = 0x%4.4x)", task); uint32_t i = 0; if (count > 0) { @@ -449,17 +457,19 @@ Status MachException::PortInfo::Restore(task_t task) { error.SetError(mach_err, eErrorTypeMachKernel); if (log) { if (error.Success()) { - log->Printf("::task_set_exception_ports(task = 0x%4.4x, " - "exception_mask = 0x%8.8x, new_port = 0x%4.4x, " - "behavior = 0x%8.8x, new_flavor = 0x%8.8x)", - task, masks[i], ports[i], behaviors[i], flavors[i]); + LLDB_LOGF(log, + "::task_set_exception_ports(task = 0x%4.4x, " + "exception_mask = 0x%8.8x, new_port = 0x%4.4x, " + "behavior = 0x%8.8x, new_flavor = 0x%8.8x)", + task, masks[i], ports[i], behaviors[i], flavors[i]); } else { - log->Printf("::task_set_exception_ports(task = 0x%4.4x, " - "exception_mask = 0x%8.8x, new_port = 0x%4.4x, " - "behavior = 0x%8.8x, new_flavor = 0x%8.8x): " - "error %u (%s)", - task, masks[i], ports[i], behaviors[i], flavors[i], - error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "::task_set_exception_ports(task = 0x%4.4x, " + "exception_mask = 0x%8.8x, new_port = 0x%4.4x, " + "behavior = 0x%8.8x, new_flavor = 0x%8.8x): " + "error %u (%s)", + task, masks[i], ports[i], behaviors[i], flavors[i], + error.GetError(), error.AsCString()); } } diff --git a/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp b/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp index fe7de27e0ee..50baa9c9397 100644 --- a/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp +++ b/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp @@ -75,19 +75,19 @@ Status NativeProcessProtocol::Launch( // Handle launch failure. if (!error.Success()) { - if (log) - log->Printf("NativeProcessDarwin::%s() failed to launch process: " - "%s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() failed to launch process: " + "%s", + __FUNCTION__, error.AsCString()); return error; } // Handle failure to return a pid. if (launch_info.GetProcessID() == LLDB_INVALID_PROCESS_ID) { - if (log) - log->Printf("NativeProcessDarwin::%s() launch succeeded but no " - "pid was returned! Aborting.", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() launch succeeded but no " + "pid was returned! Aborting.", + __FUNCTION__); return error; } @@ -104,10 +104,10 @@ Status NativeProcessProtocol::Launch( // NativeProcessDarwin instance. error = np_darwin_sp->FinalizeLaunch(launch_flavor, mainloop); if (!error.Success()) { - if (log) - log->Printf("NativeProcessDarwin::%s() aborting, failed to finalize" - " the launching of the process: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() aborting, failed to finalize" + " the launching of the process: %s", + __FUNCTION__, error.AsCString()); return error; } @@ -120,9 +120,8 @@ Status NativeProcessProtocol::Attach( lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate, MainLoop &mainloop, NativeProcessProtocolSP &native_process_sp) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("NativeProcessDarwin::%s(pid = %" PRIi64 ")", __FUNCTION__, - pid); + LLDB_LOGF(log, "NativeProcessDarwin::%s(pid = %" PRIi64 ")", __FUNCTION__, + pid); // Retrieve the architecture for the running process. ArchSpec process_arch; @@ -173,10 +172,10 @@ Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor, error = StartExceptionThread(); if (!error.Success()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): failure starting the " - "mach exception port monitor thread: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failure starting the " + "mach exception port monitor thread: %s", + __FUNCTION__, error.AsCString()); // Terminate the inferior process. There's nothing meaningful we can do if // we can't receive signals and exceptions. Since we launched the process, @@ -195,33 +194,31 @@ Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor, int err = ::ptrace(PT_ATTACHEXC, m_pid, 0, 0); if (err == 0) { // m_flags |= eMachProcessFlagsAttached; - if (log) - log->Printf("NativeProcessDarwin::%s(): successfully spawned " - "process with pid %" PRIu64, - __FUNCTION__, m_pid); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): successfully spawned " + "process with pid %" PRIu64, + __FUNCTION__, m_pid); } else { error.SetErrorToErrno(); SetState(eStateExited); - if (log) - log->Printf("NativeProcessDarwin::%s(): error: failed to " - "attach to spawned pid %" PRIu64 " (error=%d (%s))", - __FUNCTION__, m_pid, (int)error.GetError(), - error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): error: failed to " + "attach to spawned pid %" PRIu64 " (error=%d (%s))", + __FUNCTION__, m_pid, (int)error.GetError(), error.AsCString()); return error; } } - if (log) - log->Printf("NativeProcessDarwin::%s(): new pid is %" PRIu64 "...", - __FUNCTION__, m_pid); + LLDB_LOGF(log, "NativeProcessDarwin::%s(): new pid is %" PRIu64 "...", + __FUNCTION__, m_pid); // Spawn a thread to reap our child inferior process... error = StartWaitpidThread(main_loop); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): failed to start waitpid() " - "thread: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failed to start waitpid() " + "thread: %s", + __FUNCTION__, error.AsCString()); kill(SIGKILL, static_cast<::pid_t>(m_pid)); return error; } @@ -230,10 +227,10 @@ Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor, // We failed to get the task for our process ID which is bad. Kill our // process; otherwise, it will be stopped at the entry point and get // reparented to someone else and never go away. - if (log) - log->Printf("NativeProcessDarwin::%s(): could not get task port " - "for process, sending SIGKILL and exiting: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): could not get task port " + "for process, sending SIGKILL and exiting: %s", + __FUNCTION__, error.AsCString()); kill(SIGKILL, static_cast<::pid_t>(m_pid)); return error; } @@ -278,18 +275,17 @@ void NativeProcessDarwin::ExceptionMessageReceived( // the exception to our internal exception stack m_exception_messages.push_back(message); - if (log) - log->Printf("NativeProcessDarwin::%s(): new queued message count: %lu", - __FUNCTION__, m_exception_messages.size()); + LLDB_LOGF(log, "NativeProcessDarwin::%s(): new queued message count: %lu", + __FUNCTION__, m_exception_messages.size()); } void *NativeProcessDarwin::ExceptionThread(void *arg) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); if (!arg) { - if (log) - log->Printf("NativeProcessDarwin::%s(): cannot run mach exception " - "thread, mandatory process arg was null", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): cannot run mach exception " + "thread, mandatory process arg was null", + __FUNCTION__); return nullptr; } @@ -299,9 +295,8 @@ void *NativeProcessDarwin::ExceptionThread(void *arg) { void *NativeProcessDarwin::DoExceptionThread() { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf("NativeProcessDarwin::%s(arg=%p) starting thread...", - __FUNCTION__, this); + LLDB_LOGF(log, "NativeProcessDarwin::%s(arg=%p) starting thread...", + __FUNCTION__, this); pthread_setname_np("exception monitoring thread"); @@ -344,20 +339,20 @@ void *NativeProcessDarwin::DoExceptionThread() { if (process->ProcessUsingSpringBoard()) { // Request a renewal for every 60 seconds if we attached using SpringBoard. watchdog.reset(::SBSWatchdogAssertionCreateForPID(nullptr, pid, 60)); - if (log) - log->Printf("::SBSWatchdogAssertionCreateForPID(NULL, %4.4x, 60) " - "=> %p", - pid, watchdog.get()); + LLDB_LOGF(log, + "::SBSWatchdogAssertionCreateForPID(NULL, %4.4x, 60) " + "=> %p", + pid, watchdog.get()); if (watchdog.get()) { ::SBSWatchdogAssertionRenew(watchdog.get()); CFTimeInterval watchdogRenewalInterval = ::SBSWatchdogAssertionGetRenewalInterval(watchdog.get()); - if (log) - log->Printf("::SBSWatchdogAssertionGetRenewalInterval(%p) => " - "%g seconds", - watchdog.get(), watchdogRenewalInterval); + LLDB_LOGF(log, + "::SBSWatchdogAssertionGetRenewalInterval(%p) => " + "%g seconds", + watchdog.get(), watchdogRenewalInterval); if (watchdogRenewalInterval > 0.0) { watchdog_timeout = (mach_msg_timeout_t)watchdogRenewalInterval * 1000; if (watchdog_timeout > 3000) { @@ -425,11 +420,11 @@ void *NativeProcessDarwin::DoExceptionThread() { // If we have no task port we should exit this thread, as it implies // the inferior went down. if (!IsExceptionPortValid()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): the inferior " - "exception port is no longer valid, " - "canceling exception thread...", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): the inferior " + "exception port is no longer valid, " + "canceling exception thread...", + __FUNCTION__); // Should we be setting a process state here? break; } @@ -437,19 +432,19 @@ void *NativeProcessDarwin::DoExceptionThread() { // Make sure the inferior task is still valid. if (IsTaskValid()) { // Task is still ok. - if (log) - log->Printf("NativeProcessDarwin::%s(): interrupted, but " - "the inferior task iss till valid, " - "continuing...", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): interrupted, but " + "the inferior task iss till valid, " + "continuing...", + __FUNCTION__); continue; } else { // The inferior task is no longer valid. Time to exit as the process // has gone away. - if (log) - log->Printf("NativeProcessDarwin::%s(): the inferior task " - "has exited, and so will we...", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): the inferior task " + "has exited, and so will we...", + __FUNCTION__); // Does this race at all with our waitpid()? SetState(eStateExited); break; @@ -471,18 +466,18 @@ void *NativeProcessDarwin::DoExceptionThread() { // our task is still valid. if (IsTaskValid(task)) { // Task is still ok. - if (log) - log->Printf("NativeProcessDarwin::%s(): got a timeout, " - "continuing...", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): got a timeout, " + "continuing...", + __FUNCTION__); continue; } else { // The inferior task is no longer valid. Time to exit as the // process has gone away. - if (log) - log->Printf("NativeProcessDarwin::%s(): the inferior " - "task has exited, and so will we...", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): the inferior " + "task has exited, and so will we...", + __FUNCTION__); // Does this race at all with our waitpid()? SetState(eStateExited); break; @@ -493,18 +488,17 @@ void *NativeProcessDarwin::DoExceptionThread() { if (watchdog.get()) { watchdog_elapsed += periodic_timeout; if (watchdog_elapsed >= watchdog_timeout) { - if (log) - log->Printf("SBSWatchdogAssertionRenew(%p)", watchdog.get()); + LLDB_LOGF(log, "SBSWatchdogAssertionRenew(%p)", watchdog.get()); ::SBSWatchdogAssertionRenew(watchdog.get()); watchdog_elapsed = 0; } } #endif } else { - if (log) - log->Printf("NativeProcessDarwin::%s(): continuing after " - "receiving an unexpected error: %u (%s)", - __FUNCTION__, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): continuing after " + "receiving an unexpected error: %u (%s)", + __FUNCTION__, error.GetError(), error.AsCString()); // TODO: notify of error? } } @@ -523,17 +517,15 @@ void *NativeProcessDarwin::DoExceptionThread() { } #endif // #if defined (WITH_SPRINGBOARD) && !defined (WITH_BKS) - if (log) - log->Printf("NativeProcessDarwin::%s(%p): thread exiting...", __FUNCTION__, - this); + LLDB_LOGF(log, "NativeProcessDarwin::%s(%p): thread exiting...", __FUNCTION__, + this); return nullptr; } Status NativeProcessDarwin::StartExceptionThread() { Status error; Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("NativeProcessDarwin::%s() called", __FUNCTION__); + LLDB_LOGF(log, "NativeProcessDarwin::%s() called", __FUNCTION__); // Make sure we've looked up the inferior port. TaskPortForProcessID(error); @@ -554,11 +546,11 @@ Status NativeProcessDarwin::StartExceptionThread() { &m_exception_port); error.SetError(mach_err, eErrorTypeMachKernel); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): mach_port_allocate(" - "task_self=0x%4.4x, MACH_PORT_RIGHT_RECEIVE, " - "&m_exception_port) failed: %u (%s)", - __FUNCTION__, task_self, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): mach_port_allocate(" + "task_self=0x%4.4x, MACH_PORT_RIGHT_RECEIVE, " + "&m_exception_port) failed: %u (%s)", + __FUNCTION__, task_self, error.GetError(), error.AsCString()); return error; } @@ -567,23 +559,23 @@ Status NativeProcessDarwin::StartExceptionThread() { task_self, m_exception_port, m_exception_port, MACH_MSG_TYPE_MAKE_SEND); error.SetError(mach_err, eErrorTypeMachKernel); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): mach_port_insert_right(" - "task_self=0x%4.4x, m_exception_port=0x%4.4x, " - "m_exception_port=0x%4.4x, MACH_MSG_TYPE_MAKE_SEND) " - "failed: %u (%s)", - __FUNCTION__, task_self, m_exception_port, m_exception_port, - error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): mach_port_insert_right(" + "task_self=0x%4.4x, m_exception_port=0x%4.4x, " + "m_exception_port=0x%4.4x, MACH_MSG_TYPE_MAKE_SEND) " + "failed: %u (%s)", + __FUNCTION__, task_self, m_exception_port, m_exception_port, + error.GetError(), error.AsCString()); return error; } // Save the original state of the exception ports for our child process. error = SaveExceptionPortInfo(); if (error.Fail() || (m_exc_port_info.mask == 0)) { - if (log) - log->Printf("NativeProcessDarwin::%s(): SaveExceptionPortInfo() " - "failed, cannot install exception handler: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): SaveExceptionPortInfo() " + "failed, cannot install exception handler: %s", + __FUNCTION__, error.AsCString()); return error; } @@ -593,14 +585,14 @@ Status NativeProcessDarwin::StartExceptionThread() { EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE); error.SetError(mach_err, eErrorTypeMachKernel); if (error.Fail()) { - if (log) - log->Printf("::task_set_exception_ports (task = 0x%4.4x, " - "exception_mask = 0x%8.8x, new_port = 0x%4.4x, " - "behavior = 0x%8.8x, new_flavor = 0x%8.8x) failed: " - "%u (%s)", - m_task, m_exc_port_info.mask, m_exception_port, - (EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES), THREAD_STATE_NONE, - error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "::task_set_exception_ports (task = 0x%4.4x, " + "exception_mask = 0x%8.8x, new_port = 0x%4.4x, " + "behavior = 0x%8.8x, new_flavor = 0x%8.8x) failed: " + "%u (%s)", + m_task, m_exc_port_info.mask, m_exception_port, + (EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES), THREAD_STATE_NONE, + error.GetError(), error.AsCString()); return error; } @@ -609,10 +601,10 @@ Status NativeProcessDarwin::StartExceptionThread() { ::pthread_create(&m_exception_thread, nullptr, ExceptionThread, this); error.SetError(pthread_err, eErrorTypePOSIX); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): failed to create Mach " - "exception-handling thread: %u (%s)", - __FUNCTION__, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failed to create Mach " + "exception-handling thread: %u (%s)", + __FUNCTION__, error.GetError(), error.AsCString()); } return error; @@ -677,10 +669,10 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex); - if (log) - log->Printf("NativeProcessDarwin::%s(): processing %lu exception " - "messages.", - __FUNCTION__, m_exception_messages.size()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): processing %lu exception " + "messages.", + __FUNCTION__, m_exception_messages.size()); if (m_exception_messages.empty()) { // Not particularly useful... @@ -733,18 +725,18 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { const bool force_update = true; const task_t new_task = TaskPortForProcessID(error, force_update); if (old_task != new_task) { - if (log) - log->Printf("exec: inferior task port changed " - "from 0x%4.4x to 0x%4.4x", - old_task, new_task); + LLDB_LOGF(log, + "exec: inferior task port changed " + "from 0x%4.4x to 0x%4.4x", + old_task, new_task); } } } else { - if (log) - log->Printf("NativeProcessDarwin::%s() warning: " - "failed to read all_image_infos." - "infoArrayCount from 0x%8.8llx", - __FUNCTION__, info_array_count_addr); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() warning: " + "failed to read all_image_infos." + "infoArrayCount from 0x%8.8llx", + __FUNCTION__, info_array_count_addr); } } else if ((m_sent_interrupt_signo != 0) && (signo == m_sent_interrupt_signo)) { @@ -756,10 +748,10 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { if (m_did_exec) { cpu_type_t process_cpu_type = GetCPUTypeForLocalProcess(m_pid); if (m_cpu_type != process_cpu_type) { - if (log) - log->Printf("NativeProcessDarwin::%s(): arch changed from " - "0x%8.8x to 0x%8.8x", - __FUNCTION__, m_cpu_type, process_cpu_type); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): arch changed from " + "0x%8.8x to 0x%8.8x", + __FUNCTION__, m_cpu_type, process_cpu_type); m_cpu_type = process_cpu_type; // TODO figure out if we need to do something here. // DNBArchProtocol::SetArchitecture (process_cpu_type); @@ -772,10 +764,10 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { if (m_sent_interrupt_signo != 0) { if (received_interrupt) { - if (log) - log->Printf("NativeProcessDarwin::%s(): process " - "successfully interrupted with signal %i", - __FUNCTION__, m_sent_interrupt_signo); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): process " + "successfully interrupted with signal %i", + __FUNCTION__, m_sent_interrupt_signo); // Mark that we received the interrupt signal m_sent_interrupt_signo = 0; @@ -792,19 +784,19 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { // Only auto_resume if we stopped with _only_ the interrupt signal. if (num_task_exceptions == 1) { auto_resume = true; - if (log) - log->Printf("NativeProcessDarwin::%s(): auto " - "resuming due to unhandled interrupt " - "signal %i", - __FUNCTION__, m_auto_resume_signo); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): auto " + "resuming due to unhandled interrupt " + "signal %i", + __FUNCTION__, m_auto_resume_signo); } m_auto_resume_signo = 0; } } else { - if (log) - log->Printf("NativeProcessDarwin::%s(): didn't get signal " - "%i after MachProcess::Interrupt()", - __FUNCTION__, m_sent_interrupt_signo); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): didn't get signal " + "%i after MachProcess::Interrupt()", + __FUNCTION__, m_sent_interrupt_signo); } } } @@ -878,10 +870,10 @@ Status NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) { const bool child_inherits = false; error = m_waitpid_pipe.CreateNew(child_inherits); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): failed to create waitpid " - "communication pipe: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failed to create waitpid " + "communication pipe: %s", + __FUNCTION__, error.AsCString()); return error; } @@ -899,10 +891,10 @@ Status NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) { ::pthread_create(&m_waitpid_thread, nullptr, WaitpidThread, this); error.SetError(pthread_err, eErrorTypePOSIX); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): failed to create waitpid " - "handling thread: %u (%s)", - __FUNCTION__, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failed to create waitpid " + "handling thread: %u (%s)", + __FUNCTION__, error.GetError(), error.AsCString()); return error; } @@ -912,10 +904,10 @@ Status NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) { void *NativeProcessDarwin::WaitpidThread(void *arg) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (!arg) { - if (log) - log->Printf("NativeProcessDarwin::%s(): cannot run waitpid " - "thread, mandatory process arg was null", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): cannot run waitpid " + "thread, mandatory process arg was null", + __FUNCTION__); return nullptr; } @@ -938,10 +930,10 @@ void *NativeProcessDarwin::DoWaitpidThread() { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (m_pid == LLDB_INVALID_PROCESS_ID) { - if (log) - log->Printf("NativeProcessDarwin::%s(): inferior process ID is " - "not set, cannot waitpid on it", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): inferior process ID is " + "not set, cannot waitpid on it", + __FUNCTION__); return nullptr; } @@ -962,41 +954,41 @@ void *NativeProcessDarwin::DoWaitpidThread() { if (error.Fail()) { if (error.GetError() == EINTR) { // This is okay, we can keep going. - if (log) - log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 - ", &status, 0) interrupted, continuing", - __FUNCTION__, m_pid); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 + ", &status, 0) interrupted, continuing", + __FUNCTION__, m_pid); continue; } // This error is not okay, abort. - if (log) - log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 - ", &status, 0) aborting due to error: %u (%s)", - __FUNCTION__, m_pid, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 + ", &status, 0) aborting due to error: %u (%s)", + __FUNCTION__, m_pid, error.GetError(), error.AsCString()); break; } // Log the successful result. - if (log) - log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 - ", &status, 0) => %i, status = %i", - __FUNCTION__, m_pid, child_pid, status); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 + ", &status, 0) => %i, status = %i", + __FUNCTION__, m_pid, child_pid, status); // Handle the result. if (WIFSTOPPED(status)) { - if (log) - log->Printf("NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 - ") received a stop, continuing waitpid() loop", - __FUNCTION__, m_pid); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): waitpid(pid = %" PRIu64 + ") received a stop, continuing waitpid() loop", + __FUNCTION__, m_pid); continue; } else // if (WIFEXITED(status) || WIFSIGNALED(status)) { - if (log) - log->Printf("NativeProcessDarwin::%s(pid = %" PRIu64 "): " - "waitpid thread is setting exit status for pid = " - "%i to %i", - __FUNCTION__, m_pid, child_pid, status); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(pid = %" PRIu64 "): " + "waitpid thread is setting exit status for pid = " + "%i to %i", + __FUNCTION__, m_pid, child_pid, status); error = SendInferiorExitStatusToMainLoop(child_pid, status); return nullptr; @@ -1005,12 +997,11 @@ void *NativeProcessDarwin::DoWaitpidThread() { // We should never exit as long as our child process is alive. If we get // here, something completely unexpected went wrong and we should exit. - if (log) - log->Printf( - "NativeProcessDarwin::%s(): internal error: waitpid thread " - "exited out of its main loop in an unexpected way. pid = %" PRIu64 - ". Sending exit status of -1.", - __FUNCTION__, m_pid); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): internal error: waitpid thread " + "exited out of its main loop in an unexpected way. pid = %" PRIu64 + ". Sending exit status of -1.", + __FUNCTION__, m_pid); error = SendInferiorExitStatusToMainLoop((::pid_t)m_pid, -1); return nullptr; @@ -1026,11 +1017,11 @@ Status NativeProcessDarwin::SendInferiorExitStatusToMainLoop(::pid_t pid, // Send the pid. error = m_waitpid_pipe.Write(&pid, sizeof(pid), bytes_written); if (error.Fail() || (bytes_written < sizeof(pid))) { - if (log) - log->Printf("NativeProcessDarwin::%s() - failed to write " - "waitpid exiting pid to the pipe. Client will not " - "hear about inferior exit status!", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() - failed to write " + "waitpid exiting pid to the pipe. Client will not " + "hear about inferior exit status!", + __FUNCTION__); return error; } @@ -1038,11 +1029,11 @@ Status NativeProcessDarwin::SendInferiorExitStatusToMainLoop(::pid_t pid, bytes_written = 0; error = m_waitpid_pipe.Write(&status, sizeof(status), bytes_written); if (error.Fail() || (bytes_written < sizeof(status))) { - if (log) - log->Printf("NativeProcessDarwin::%s() - failed to write " - "waitpid exit result to the pipe. Client will not " - "hear about inferior exit status!", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() - failed to write " + "waitpid exit result to the pipe. Client will not " + "hear about inferior exit status!", + __FUNCTION__); } return error; } @@ -1058,11 +1049,11 @@ Status NativeProcessDarwin::HandleWaitpidResult() { size_t bytes_read = 0; error = m_waitpid_pipe.Read(&pid, sizeof(pid), bytes_read); if (error.Fail() || (bytes_read < sizeof(pid))) { - if (log) - log->Printf("NativeProcessDarwin::%s() - failed to read " - "waitpid exiting pid from the pipe. Will notify " - "as if parent process died with exit status -1.", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() - failed to read " + "waitpid exiting pid from the pipe. Will notify " + "as if parent process died with exit status -1.", + __FUNCTION__); SetExitStatus(WaitStatus(WaitStatus::Exit, -1), notify_status); return error; } @@ -1071,21 +1062,21 @@ Status NativeProcessDarwin::HandleWaitpidResult() { int status = -1; error = m_waitpid_pipe.Read(&status, sizeof(status), bytes_read); if (error.Fail() || (bytes_read < sizeof(status))) { - if (log) - log->Printf("NativeProcessDarwin::%s() - failed to read " - "waitpid exit status from the pipe. Will notify " - "as if parent process died with exit status -1.", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s() - failed to read " + "waitpid exit status from the pipe. Will notify " + "as if parent process died with exit status -1.", + __FUNCTION__); SetExitStatus(WaitStatus(WaitStatus::Exit, -1), notify_status); return error; } // Notify the monitor that our state has changed. - if (log) - log->Printf("NativeProcessDarwin::%s(): main loop received waitpid " - "exit status info: pid=%i (%s), status=%i", - __FUNCTION__, pid, - (pid == m_pid) ? "the inferior" : "not the inferior", status); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): main loop received waitpid " + "exit status info: pid=%i (%s), status=%i", + __FUNCTION__, pid, + (pid == m_pid) ? "the inferior" : "not the inferior", status); SetExitStatus(WaitStatus::Decode(status), notify_status); return error; @@ -1096,10 +1087,10 @@ task_t NativeProcessDarwin::TaskPortForProcessID(Status &error, if ((m_task == TASK_NULL) || force) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (m_pid == LLDB_INVALID_PROCESS_ID) { - if (log) - log->Printf("NativeProcessDarwin::%s(): cannot get task due " - "to invalid pid", - __FUNCTION__); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): cannot get task due " + "to invalid pid", + __FUNCTION__); return TASK_NULL; } @@ -1115,19 +1106,21 @@ task_t NativeProcessDarwin::TaskPortForProcessID(Status &error, // Succeeded. Save and return it. error.Clear(); m_task = task; - log->Printf("NativeProcessDarwin::%s(): ::task_for_pid(" - "stub_port = 0x%4.4x, pid = %llu, &task) " - "succeeded: inferior task port = 0x%4.4x", - __FUNCTION__, task_self, m_pid, m_task); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): ::task_for_pid(" + "stub_port = 0x%4.4x, pid = %llu, &task) " + "succeeded: inferior task port = 0x%4.4x", + __FUNCTION__, task_self, m_pid, m_task); return m_task; } else { // Failed to get the task for the inferior process. error.SetError(err, eErrorTypeMachKernel); if (log) { - log->Printf("NativeProcessDarwin::%s(): ::task_for_pid(" - "stub_port = 0x%4.4x, pid = %llu, &task) " - "failed, err = 0x%8.8x (%s)", - __FUNCTION__, task_self, m_pid, err, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): ::task_for_pid(" + "stub_port = 0x%4.4x, pid = %llu, &task) " + "failed, err = 0x%8.8x (%s)", + __FUNCTION__, task_self, m_pid, err, error.AsCString()); } } @@ -1156,20 +1149,21 @@ Status NativeProcessDarwin::PrivateResume() { if (log) { if (m_auto_resume_signo) - log->Printf("NativeProcessDarwin::%s(): task 0x%x resuming (with " - "unhandled interrupt signal %i)...", - __FUNCTION__, m_task, m_auto_resume_signo); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): task 0x%x resuming (with " + "unhandled interrupt signal %i)...", + __FUNCTION__, m_task, m_auto_resume_signo); else - log->Printf("NativeProcessDarwin::%s(): task 0x%x resuming...", - __FUNCTION__, m_task); + LLDB_LOGF(log, "NativeProcessDarwin::%s(): task 0x%x resuming...", + __FUNCTION__, m_task); } error = ReplyToAllExceptions(); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): aborting, failed to " - "reply to exceptions: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): aborting, failed to " + "reply to exceptions: %s", + __FUNCTION__, error.AsCString()); return error; } // bool stepOverBreakInstruction = step; @@ -1196,9 +1190,8 @@ Status NativeProcessDarwin::ReplyToAllExceptions() { TaskPortForProcessID(error); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): no task port, aborting", - __FUNCTION__); + LLDB_LOGF(log, "NativeProcessDarwin::%s(): no task port, aborting", + __FUNCTION__); return error; } @@ -1211,9 +1204,10 @@ Status NativeProcessDarwin::ReplyToAllExceptions() { size_t index = 0; for (auto &message : m_exception_messages) { if (log) { - log->Printf("NativeProcessDarwin::%s(): replying to exception " - "%zu...", - __FUNCTION__, index++); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): replying to exception " + "%zu...", + __FUNCTION__, index++); } int thread_reply_signal = 0; @@ -1234,9 +1228,10 @@ Status NativeProcessDarwin::ReplyToAllExceptions() { if (error.Fail() && log) { // We log any error here, but we don't stop the exception response // handling. - log->Printf("NativeProcessDarwin::%s(): failed to reply to " - "exception: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failed to reply to " + "exception: %s", + __FUNCTION__, error.AsCString()); error.Clear(); } } @@ -1253,10 +1248,10 @@ Status NativeProcessDarwin::ResumeTask() { TaskPortForProcessID(error); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): failed to get task port " - "for process when attempting to resume: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failed to get task port " + "for process when attempting to resume: %s", + __FUNCTION__, error.AsCString()); return error; } if (m_task == TASK_NULL) { @@ -1265,20 +1260,20 @@ Status NativeProcessDarwin::ResumeTask() { return error; } - if (log) - log->Printf("NativeProcessDarwin::%s(): requesting resume of task " - "0x%4.4x", - __FUNCTION__, m_task); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): requesting resume of task " + "0x%4.4x", + __FUNCTION__, m_task); // Get the BasicInfo struct to verify that we're suspended before we try to // resume the task. struct task_basic_info task_info; error = GetTaskBasicInfo(m_task, &task_info); if (error.Fail()) { - if (log) - log->Printf("NativeProcessDarwin::%s(): failed to get task " - "BasicInfo when attempting to resume: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): failed to get task " + "BasicInfo when attempting to resume: %s", + __FUNCTION__, error.AsCString()); return error; } @@ -1289,16 +1284,16 @@ Status NativeProcessDarwin::ResumeTask() { error.SetError(mach_err, eErrorTypeMachKernel); if (log) { if (error.Success()) - log->Printf("::task_resume(target_task = 0x%4.4x): success", m_task); + LLDB_LOGF(log, "::task_resume(target_task = 0x%4.4x): success", m_task); else - log->Printf("::task_resume(target_task = 0x%4.4x) error: %s", m_task, - error.AsCString()); + LLDB_LOGF(log, "::task_resume(target_task = 0x%4.4x) error: %s", m_task, + error.AsCString()); } } else { - if (log) - log->Printf("::task_resume(target_task = 0x%4.4x): ignored, " - "already running", - m_task); + LLDB_LOGF(log, + "::task_resume(target_task = 0x%4.4x): ignored, " + "already running", + m_task); } return error; @@ -1353,11 +1348,11 @@ NativeProcessDarwin::GetTaskBasicInfo(task_t task, auto err = ::task_info(m_task, TASK_BASIC_INFO, (task_info_t)info, &count); error.SetError(err, eErrorTypeMachKernel); if (error.Fail()) { - if (log) - log->Printf("::task_info(target_task = 0x%4.4x, " - "flavor = TASK_BASIC_INFO, task_info_out => %p, " - "task_info_outCnt => %u) failed: %u (%s)", - m_task, info, count, error.GetError(), error.AsCString()); + LLDB_LOGF(log, + "::task_info(target_task = 0x%4.4x, " + "flavor = TASK_BASIC_INFO, task_info_out => %p, " + "task_info_outCnt => %u) failed: %u (%s)", + m_task, info, count, error.GetError(), error.AsCString()); return error; } @@ -1368,11 +1363,12 @@ NativeProcessDarwin::GetTaskBasicInfo(task_t task, (float)info->user_time.microseconds / 1000000.0f; float system = (float)info->user_time.seconds + (float)info->user_time.microseconds / 1000000.0f; - verbose_log->Printf("task_basic_info = { suspend_count = %i, " - "virtual_size = 0x%8.8llx, resident_size = " - "0x%8.8llx, user_time = %f, system_time = %f }", - info->suspend_count, (uint64_t)info->virtual_size, - (uint64_t)info->resident_size, user, system); + verbose_LLDB_LOGF(log, + "task_basic_info = { suspend_count = %i, " + "virtual_size = 0x%8.8llx, resident_size = " + "0x%8.8llx, user_time = %f, system_time = %f }", + info->suspend_count, (uint64_t)info->virtual_size, + (uint64_t)info->resident_size, user, system); } return error; } @@ -1383,16 +1379,15 @@ Status NativeProcessDarwin::SuspendTask() { if (m_task == TASK_NULL) { error.SetErrorString("task port is null, cannot suspend task"); - if (log) - log->Printf("NativeProcessDarwin::%s() failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOGF(log, "NativeProcessDarwin::%s() failed: %s", __FUNCTION__, + error.AsCString()); return error; } auto mach_err = ::task_suspend(m_task); error.SetError(mach_err, eErrorTypeMachKernel); if (error.Fail() && log) - log->Printf("::task_suspend(target_task = 0x%4.4x)", m_task); + LLDB_LOGF(log, "::task_suspend(target_task = 0x%4.4x)", m_task); return error; } @@ -1401,8 +1396,7 @@ Status NativeProcessDarwin::Resume(const ResumeActionList &resume_actions) { Status error; Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("NativeProcessDarwin::%s() called", __FUNCTION__); + LLDB_LOGF(log, "NativeProcessDarwin::%s() called", __FUNCTION__); if (CanResume()) { m_thread_actions = resume_actions; @@ -1412,10 +1406,10 @@ Status NativeProcessDarwin::Resume(const ResumeActionList &resume_actions) { auto state = GetState(); if (state == eStateRunning) { - if (log) - log->Printf("NativeProcessDarwin::%s(): task 0x%x is already " - "running, ignoring...", - __FUNCTION__, TaskPortForProcessID(error)); + LLDB_LOGF(log, + "NativeProcessDarwin::%s(): task 0x%x is already " + "running, ignoring...", + __FUNCTION__, TaskPortForProcessID(error)); return error; } diff --git a/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp b/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp index 89de92a6df4..1faa5b219cb 100644 --- a/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp +++ b/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp @@ -301,10 +301,10 @@ uint32_t NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process, Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); std::lock_guard<std::recursive_mutex> locker(m_threads_mutex); - if (log) - log->Printf("NativeThreadListDarwin::%s() (pid = %" PRIu64 ", update = " - "%u) process stop count = %u", - __FUNCTION__, process.GetID(), update, process.GetStopID()); + LLDB_LOGF(log, + "NativeThreadListDarwin::%s() (pid = %" PRIu64 ", update = " + "%u) process stop count = %u", + __FUNCTION__, process.GetID(), update, process.GetStopID()); if (process.GetStopID() == 0) { // On our first stop, we'll record details like 32/64 bitness and select @@ -346,11 +346,11 @@ uint32_t NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process, auto mach_err = ::task_threads(task, &thread_list, &thread_list_count); error.SetError(mach_err, eErrorTypeMachKernel); if (error.Fail()) { - if (log) - log->Printf("::task_threads(task = 0x%4.4x, thread_list => %p, " - "thread_list_count => %u) failed: %u (%s)", - task, thread_list, thread_list_count, error.GetError(), - error.AsCString()); + LLDB_LOGF(log, + "::task_threads(task = 0x%4.4x, thread_list => %p, " + "thread_list_count => %u) failed: %u (%s)", + task, thread_list, thread_list_count, error.GetError(), + error.AsCString()); return 0; } diff --git a/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp b/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp index 74983553127..0a49f96f54a 100644 --- a/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp @@ -288,9 +288,8 @@ void FreeBSDThread::DidStop() { void FreeBSDThread::WillResume(lldb::StateType resume_state) { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); - if (log) - log->Printf("tid %lu resume_state = %s", GetID(), - lldb_private::StateAsCString(resume_state)); + LLDB_LOGF(log, "tid %lu resume_state = %s", GetID(), + lldb_private::StateAsCString(resume_state)); ProcessSP process_sp(GetProcess()); ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(process_sp.get()); int signo = GetResumeSignal(); @@ -322,9 +321,8 @@ bool FreeBSDThread::Resume() { bool status; Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); - if (log) - log->Printf("FreeBSDThread::%s (), resume_state = %s", __FUNCTION__, - StateAsCString(resume_state)); + LLDB_LOGF(log, "FreeBSDThread::%s (), resume_state = %s", __FUNCTION__, + StateAsCString(resume_state)); switch (resume_state) { default: @@ -352,9 +350,8 @@ bool FreeBSDThread::Resume() { void FreeBSDThread::Notify(const ProcessMessage &message) { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); - if (log) - log->Printf("FreeBSDThread::%s () message kind = '%s' for tid %" PRIu64, - __FUNCTION__, message.PrintKind(), GetID()); + LLDB_LOGF(log, "FreeBSDThread::%s () message kind = '%s' for tid %" PRIu64, + __FUNCTION__, message.PrintKind(), GetID()); switch (message.GetKind()) { default: @@ -457,8 +454,7 @@ void FreeBSDThread::BreakNotify(const ProcessMessage &message) { // corresponding to our current PC. assert(GetRegisterContext()); lldb::addr_t pc = GetRegisterContext()->GetPC(); - if (log) - log->Printf("FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc); + LLDB_LOGF(log, "FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc); lldb::BreakpointSiteSP bp_site( GetProcess()->GetBreakpointSiteList().FindByAddress(pc)); @@ -490,10 +486,9 @@ void FreeBSDThread::WatchNotify(const ProcessMessage &message) { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); lldb::addr_t halt_addr = message.GetHWAddress(); - if (log) - log->Printf( - "FreeBSDThread::%s () Hardware Watchpoint Address = 0x%8.8" PRIx64, - __FUNCTION__, halt_addr); + LLDB_LOGF(log, + "FreeBSDThread::%s () Hardware Watchpoint Address = 0x%8.8" PRIx64, + __FUNCTION__, halt_addr); POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol(); if (reg_ctx) { @@ -527,8 +522,7 @@ void FreeBSDThread::TraceNotify(const ProcessMessage &message) { // Try to resolve the breakpoint object corresponding to the current PC. assert(GetRegisterContext()); lldb::addr_t pc = GetRegisterContext()->GetPC(); - if (log) - log->Printf("FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc); + LLDB_LOGF(log, "FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc); lldb::BreakpointSiteSP bp_site( GetProcess()->GetBreakpointSiteList().FindByAddress(pc)); diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp index 770794569f7..6186e1fb83f 100644 --- a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp @@ -154,9 +154,8 @@ Status ProcessFreeBSD::DoResume() { do_step = true; } - if (log) - log->Printf("process %" PRIu64 " resuming (%s)", GetID(), - do_step ? "step" : "continue"); + LLDB_LOGF(log, "process %" PRIu64 " resuming (%s)", GetID(), + do_step ? "step" : "continue"); if (do_step && !software_single_step) m_monitor->SingleStep(GetID(), m_resume_signo); else @@ -168,9 +167,8 @@ Status ProcessFreeBSD::DoResume() { bool ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS)); - if (log) - log->Printf("ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__, - GetID()); + LLDB_LOGF(log, "ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__, + GetID()); std::vector<lldb::pid_t> tds; if (!GetMonitor().GetCurrentThreadIDs(tds)) { @@ -183,20 +181,18 @@ bool ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadSP thread_sp(old_thread_list_copy.RemoveThreadByID(tid, false)); if (!thread_sp) { thread_sp.reset(new FreeBSDThread(*this, tid)); - if (log) - log->Printf("ProcessFreeBSD::%s new tid = %" PRIu64, __FUNCTION__, tid); + LLDB_LOGF(log, "ProcessFreeBSD::%s new tid = %" PRIu64, __FUNCTION__, + tid); } else { - if (log) - log->Printf("ProcessFreeBSD::%s existing tid = %" PRIu64, __FUNCTION__, - tid); + LLDB_LOGF(log, "ProcessFreeBSD::%s existing tid = %" PRIu64, __FUNCTION__, + tid); } new_thread_list.AddThread(thread_sp); } for (size_t i = 0; i < old_thread_list_copy.GetSize(false); ++i) { ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex(i, false)); if (old_thread_sp) { - if (log) - log->Printf("ProcessFreeBSD::%s remove tid", __FUNCTION__); + LLDB_LOGF(log, "ProcessFreeBSD::%s remove tid", __FUNCTION__); } } @@ -698,14 +694,13 @@ Status ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify) { user_id_t watchID = wp->GetID(); addr_t addr = wp->GetLoadAddress(); Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS)); - if (log) - log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 ")", - watchID); + LLDB_LOGF(log, "ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 ")", + watchID); if (wp->IsEnabled()) { - if (log) - log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 - ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.", - watchID, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 + ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.", + watchID, (uint64_t)addr); return error; } @@ -753,14 +748,13 @@ Status ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify) { user_id_t watchID = wp->GetID(); addr_t addr = wp->GetLoadAddress(); Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS)); - if (log) - log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 ")", - watchID); + LLDB_LOGF(log, "ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 ")", + watchID); if (!wp->IsEnabled()) { - if (log) - log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 - ") addr = 0x%8.8" PRIx64 ": watchpoint already disabled.", - watchID, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 + ") addr = 0x%8.8" PRIx64 ": watchpoint already disabled.", + watchID, (uint64_t)addr); // This is needed (for now) to keep watchpoints disabled correctly wp->SetEnabled(false, notify); return error; @@ -970,8 +964,9 @@ Status ProcessFreeBSD::SetSoftwareSingleStepBreakpoint(lldb::tid_t tid, Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS)); if (log) { - log->Printf("ProcessFreeBSD::%s addr = 0x%" PRIx64, __FUNCTION__, addr); - log->Printf("SoftwareBreakpoint::%s addr = 0x%" PRIx64, __FUNCTION__, addr); + LLDB_LOGF(log, "ProcessFreeBSD::%s addr = 0x%" PRIx64, __FUNCTION__, addr); + LLDB_LOGF(log, "SoftwareBreakpoint::%s addr = 0x%" PRIx64, __FUNCTION__, + addr); } // Validate the address. @@ -984,9 +979,8 @@ Status ProcessFreeBSD::SetSoftwareSingleStepBreakpoint(lldb::tid_t tid, sw_step_break->SetCallback(SingleStepBreakpointHit, this, true); sw_step_break->SetBreakpointKind("software-signle-step"); - if (log) - log->Printf("ProcessFreeBSD::%s addr = 0x%" PRIx64 " -- SUCCESS", - __FUNCTION__, addr); + LLDB_LOGF(log, "ProcessFreeBSD::%s addr = 0x%" PRIx64 " -- SUCCESS", + __FUNCTION__, addr); m_threads_stepping_with_breakpoint.insert({tid, sw_step_break->GetID()}); return Status(); diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp index 4b9225db5e3..2866ebf479b 100644 --- a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp @@ -66,13 +66,14 @@ extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data, Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PTRACE)); if (log) { - log->Printf("ptrace(%s, %" PRIu64 ", %p, %x) called from file %s line %d", - reqName, pid, addr, data, file, line); + LLDB_LOGF(log, + "ptrace(%s, %" PRIu64 ", %p, %x) called from file %s line %d", + reqName, pid, addr, data, file, line); if (req == PT_IO) { struct ptrace_io_desc *pi = (struct ptrace_io_desc *)addr; - log->Printf("PT_IO: op=%s offs=%zx size=%zu", Get_PT_IO_OP(pi->piod_op), - (size_t)pi->piod_offs, pi->piod_len); + LLDB_LOGF(log, "PT_IO: op=%s offs=%zx size=%zu", + Get_PT_IO_OP(pi->piod_op), (size_t)pi->piod_offs, pi->piod_len); } } @@ -101,7 +102,7 @@ extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data, default: str = "<unknown>"; } - log->Printf("ptrace() failed; errno=%d (%s)", errno, str); + LLDB_LOGF(log, "ptrace() failed; errno=%d (%s)", errno, str); } if (log) { @@ -109,15 +110,15 @@ extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data, if (req == PT_GETREGS) { struct reg *r = (struct reg *)addr; - log->Printf("PT_GETREGS: rip=0x%lx rsp=0x%lx rbp=0x%lx rax=0x%lx", - r->r_rip, r->r_rsp, r->r_rbp, r->r_rax); + LLDB_LOGF(log, "PT_GETREGS: rip=0x%lx rsp=0x%lx rbp=0x%lx rax=0x%lx", + r->r_rip, r->r_rsp, r->r_rbp, r->r_rax); } if (req == PT_GETDBREGS || req == PT_SETDBREGS) { struct dbreg *r = (struct dbreg *)addr; char setget = (req == PT_GETDBREGS) ? 'G' : 'S'; for (int i = 0; i <= 7; i++) - log->Printf("PT_%cETDBREGS: dr[%d]=0x%lx", setget, i, r->dr[i]); + LLDB_LOGF(log, "PT_%cETDBREGS: dr[%d]=0x%lx", setget, i, r->dr[i]); } #endif } @@ -1037,9 +1038,8 @@ bool ProcessMonitor::MonitorCallback(ProcessMonitor *monitor, lldb::pid_t pid, Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS)); if (exited) { - if (log) - log->Printf("ProcessMonitor::%s() got exit signal, tid = %" PRIu64, - __FUNCTION__, pid); + LLDB_LOGF(log, "ProcessMonitor::%s() got exit signal, tid = %" PRIu64, + __FUNCTION__, pid); message = ProcessMessage::Exit(pid, status); process->SendMessage(message); return pid == process->GetID(); @@ -1087,10 +1087,10 @@ ProcessMessage ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor, unsigned long data = 0; if (!monitor->GetEventMessage(tid, &data)) data = -1; - if (log) - log->Printf("ProcessMonitor::%s() received exit? event, data = %lx, tid " - "= %" PRIu64, - __FUNCTION__, data, tid); + LLDB_LOGF(log, + "ProcessMonitor::%s() received exit? event, data = %lx, tid " + "= %" PRIu64, + __FUNCTION__, data, tid); message = ProcessMessage::Limbo(tid, (data >> 8)); break; } @@ -1101,26 +1101,25 @@ ProcessMessage ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor, // Map TRAP_CAP to a trace trap in the absense of a more specific handler. case TRAP_CAP: #endif - if (log) - log->Printf("ProcessMonitor::%s() received trace event, tid = %" PRIu64 - " : si_code = %d", - __FUNCTION__, tid, info->si_code); + LLDB_LOGF(log, + "ProcessMonitor::%s() received trace event, tid = %" PRIu64 + " : si_code = %d", + __FUNCTION__, tid, info->si_code); message = ProcessMessage::Trace(tid); break; case SI_KERNEL: case TRAP_BRKPT: if (monitor->m_process->IsSoftwareStepBreakpoint(tid)) { - if (log) - log->Printf("ProcessMonitor::%s() received sw single step breakpoint " - "event, tid = %" PRIu64, - __FUNCTION__, tid); + LLDB_LOGF(log, + "ProcessMonitor::%s() received sw single step breakpoint " + "event, tid = %" PRIu64, + __FUNCTION__, tid); message = ProcessMessage::Trace(tid); } else { - if (log) - log->Printf( - "ProcessMonitor::%s() received breakpoint event, tid = %" PRIu64, - __FUNCTION__, tid); + LLDB_LOGF( + log, "ProcessMonitor::%s() received breakpoint event, tid = %" PRIu64, + __FUNCTION__, tid); message = ProcessMessage::Break(tid); } break; @@ -1146,22 +1145,19 @@ ProcessMessage ProcessMonitor::MonitorSignal(ProcessMonitor *monitor, // // Similarly, ACK signals generated by this monitor. if (info->si_code == SI_USER) { - if (log) - log->Printf( - "ProcessMonitor::%s() received signal %s with code %s, pid = %d", - __FUNCTION__, - monitor->m_process->GetUnixSignals()->GetSignalAsCString(signo), - "SI_USER", info->si_pid); + LLDB_LOGF(log, + "ProcessMonitor::%s() received signal %s with code %s, pid = %d", + __FUNCTION__, + monitor->m_process->GetUnixSignals()->GetSignalAsCString(signo), + "SI_USER", info->si_pid); if (info->si_pid == getpid()) return ProcessMessage::SignalDelivered(tid, signo); else return ProcessMessage::Signal(tid, signo); } - if (log) - log->Printf( - "ProcessMonitor::%s() received signal %s", __FUNCTION__, - monitor->m_process->GetUnixSignals()->GetSignalAsCString(signo)); + LLDB_LOGF(log, "ProcessMonitor::%s() received signal %s", __FUNCTION__, + monitor->m_process->GetUnixSignals()->GetSignalAsCString(signo)); switch (signo) { case SIGSEGV: @@ -1313,14 +1309,14 @@ bool ProcessMonitor::Resume(lldb::tid_t unused, uint32_t signo) { m_process->GetUnixSignals()->GetSignalAsCString(signo); if (signame == nullptr) signame = "<none>"; - log->Printf("ProcessMonitor::%s() resuming pid %" PRIu64 " with signal %s", - __FUNCTION__, GetPID(), signame); + LLDB_LOGF(log, + "ProcessMonitor::%s() resuming pid %" PRIu64 " with signal %s", + __FUNCTION__, GetPID(), signame); } ResumeOperation op(signo, result); DoOperation(&op); - if (log) - log->Printf("ProcessMonitor::%s() resuming result = %s", __FUNCTION__, - result ? "true" : "false"); + LLDB_LOGF(log, "ProcessMonitor::%s() resuming result = %s", __FUNCTION__, + result ? "true" : "false"); return result; } diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp index d7206195acb..27eaefd7590 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp @@ -346,8 +346,7 @@ bool NativeRegisterContextLinux_arm::IsFPR(unsigned reg) const { uint32_t NativeRegisterContextLinux_arm::NumSupportedHardwareBreakpoints() { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_BREAKPOINTS)); - if (log) - log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__); + LLDB_LOGF(log, "NativeRegisterContextLinux_arm::%s()", __FUNCTION__); Status error; @@ -458,8 +457,7 @@ Status NativeRegisterContextLinux_arm::GetHardwareBreakHitIndex( uint32_t &bp_index, lldb::addr_t trap_addr) { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_BREAKPOINTS)); - if (log) - log->Printf("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + LLDB_LOGF(log, "NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); lldb::addr_t break_addr; @@ -479,8 +477,7 @@ Status NativeRegisterContextLinux_arm::GetHardwareBreakHitIndex( Status NativeRegisterContextLinux_arm::ClearAllHardwareBreakpoints() { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_BREAKPOINTS)); - if (log) - log->Printf("NativeRegisterContextLinux_arm::%s()", __FUNCTION__); + LLDB_LOGF(log, "NativeRegisterContextLinux_arm::%s()", __FUNCTION__); Status error; diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp index 9bb9e6b77ec..e65b768ff14 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp @@ -347,8 +347,7 @@ bool NativeRegisterContextLinux_arm64::IsFPR(unsigned reg) const { uint32_t NativeRegisterContextLinux_arm64::NumSupportedHardwareBreakpoints() { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_BREAKPOINTS)); - if (log) - log->Printf("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + LLDB_LOGF(log, "NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); Status error; @@ -458,8 +457,7 @@ Status NativeRegisterContextLinux_arm64::GetHardwareBreakHitIndex( uint32_t &bp_index, lldb::addr_t trap_addr) { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_BREAKPOINTS)); - if (log) - log->Printf("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + LLDB_LOGF(log, "NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); lldb::addr_t break_addr; @@ -479,8 +477,7 @@ Status NativeRegisterContextLinux_arm64::GetHardwareBreakHitIndex( Status NativeRegisterContextLinux_arm64::ClearAllHardwareBreakpoints() { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_BREAKPOINTS)); - if (log) - log->Printf("NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); + LLDB_LOGF(log, "NativeRegisterContextLinux_arm64::%s()", __FUNCTION__); Status error; diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp index 3c5326898b0..49f1d44b39d 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp @@ -1191,8 +1191,8 @@ uint32_t NativeRegisterContextLinux_x86_64::SetHardwareWatchpoint( return wp_index; } if (error.Fail() && log) { - log->Printf("NativeRegisterContextLinux_x86_64::%s Error: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, "NativeRegisterContextLinux_x86_64::%s Error: %s", + __FUNCTION__, error.AsCString()); } } return LLDB_INVALID_INDEX32; diff --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp index 287a271689a..677aee34a18 100644 --- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp @@ -133,9 +133,10 @@ bool NativeThreadLinux::GetStopReason(ThreadStopInfo &stop_info, case eStateStepping: case eStateDetached: if (log) { - log->Printf("NativeThreadLinux::%s tid %" PRIu64 - " in state %s cannot answer stop reason", - __FUNCTION__, GetID(), StateAsCString(m_state)); + LLDB_LOGF(log, + "NativeThreadLinux::%s tid %" PRIu64 + " in state %s cannot answer stop reason", + __FUNCTION__, GetID(), StateAsCString(m_state)); } return false; } @@ -273,9 +274,8 @@ Status NativeThreadLinux::SingleStep(uint32_t signo) { void NativeThreadLinux::SetStoppedBySignal(uint32_t signo, const siginfo_t *info) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); - if (log) - log->Printf("NativeThreadLinux::%s called with signal 0x%02" PRIx32, - __FUNCTION__, signo); + LLDB_LOGF(log, "NativeThreadLinux::%s called with signal 0x%02" PRIx32, + __FUNCTION__, signo); SetStopped(); @@ -327,8 +327,7 @@ void NativeThreadLinux::SetStopped() { void NativeThreadLinux::SetStoppedByExec() { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); - if (log) - log->Printf("NativeThreadLinux::%s()", __FUNCTION__); + LLDB_LOGF(log, "NativeThreadLinux::%s()", __FUNCTION__); SetStopped(); @@ -412,19 +411,19 @@ Status NativeThreadLinux::RequestStop() { lldb::pid_t pid = process.GetID(); lldb::tid_t tid = GetID(); - if (log) - log->Printf("NativeThreadLinux::%s requesting thread stop(pid: %" PRIu64 - ", tid: %" PRIu64 ")", - __FUNCTION__, pid, tid); + LLDB_LOGF(log, + "NativeThreadLinux::%s requesting thread stop(pid: %" PRIu64 + ", tid: %" PRIu64 ")", + __FUNCTION__, pid, tid); Status err; errno = 0; if (::tgkill(pid, tid, SIGSTOP) != 0) { err.SetErrorToErrno(); - if (log) - log->Printf("NativeThreadLinux::%s tgkill(%" PRIu64 ", %" PRIu64 - ", SIGSTOP) failed: %s", - __FUNCTION__, pid, tid, err.AsCString()); + LLDB_LOGF(log, + "NativeThreadLinux::%s tgkill(%" PRIu64 ", %" PRIu64 + ", SIGSTOP) failed: %s", + __FUNCTION__, pid, tid, err.AsCString()); } return err; diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp index 1a75326f3b2..5737efd1d6e 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp @@ -70,8 +70,8 @@ bool CommunicationKDP::SendRequestAndGetReply( if (log) { PacketStreamType log_strm; DumpPacket(log_strm, request_packet.GetData(), request_packet.GetSize()); - log->Printf("error: kdp running, not sending packet: %.*s", - (uint32_t)log_strm.GetSize(), log_strm.GetData()); + LLDB_LOGF(log, "error: kdp running, not sending packet: %.*s", + (uint32_t)log_strm.GetSize(), log_strm.GetData()); } return false; } @@ -140,7 +140,7 @@ bool CommunicationKDP::SendRequestPacketNoLock( if (log) { PacketStreamType log_strm; DumpPacket(log_strm, packet_data, packet_size); - log->Printf("%.*s", (uint32_t)log_strm.GetSize(), log_strm.GetData()); + LLDB_LOGF(log, "%.*s", (uint32_t)log_strm.GetSize(), log_strm.GetData()); } ConnectionStatus status = eConnectionStatusSuccess; @@ -149,10 +149,10 @@ bool CommunicationKDP::SendRequestPacketNoLock( if (bytes_written == packet_size) return true; - if (log) - log->Printf("error: failed to send packet entire packet %" PRIu64 - " of %" PRIu64 " bytes sent", - (uint64_t)bytes_written, (uint64_t)packet_size); + LLDB_LOGF(log, + "error: failed to send packet entire packet %" PRIu64 + " of %" PRIu64 " bytes sent", + (uint64_t)bytes_written, (uint64_t)packet_size); } return false; } @@ -241,8 +241,8 @@ bool CommunicationKDP::CheckForPacket(const uint8_t *src, size_t src_len, if (log && log->GetVerbose()) { PacketStreamType log_strm; DumpHexBytes(&log_strm, src, src_len, UINT32_MAX, LLDB_INVALID_ADDRESS); - log->Printf("CommunicationKDP::%s adding %u bytes: %s", __FUNCTION__, - (uint32_t)src_len, log_strm.GetData()); + LLDB_LOGF(log, "CommunicationKDP::%s adding %u bytes: %s", __FUNCTION__, + (uint32_t)src_len, log_strm.GetData()); } m_bytes.append((const char *)src, src_len); } @@ -314,7 +314,8 @@ bool CommunicationKDP::CheckForPacket(const uint8_t *src, size_t src_len, PacketStreamType log_strm; DumpPacket(log_strm, packet); - log->Printf("%.*s", (uint32_t)log_strm.GetSize(), log_strm.GetData()); + LLDB_LOGF(log, "%.*s", (uint32_t)log_strm.GetSize(), + log_strm.GetData()); } return true; } @@ -323,9 +324,8 @@ bool CommunicationKDP::CheckForPacket(const uint8_t *src, size_t src_len, default: // Unrecognized reply command byte, erase this byte and try to get back // on track - if (log) - log->Printf("CommunicationKDP::%s: tossing junk byte: 0x%2.2x", - __FUNCTION__, (uint8_t)m_bytes[0]); + LLDB_LOGF(log, "CommunicationKDP::%s: tossing junk byte: 0x%2.2x", + __FUNCTION__, (uint8_t)m_bytes[0]); m_bytes.erase(0, 1); break; } diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp index 6f1bb4b6476..52c494db6be 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp @@ -394,8 +394,7 @@ void ProcessKDP::DidAttach(ArchSpec &process_arch) { Process::DidAttach(process_arch); Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); - if (log) - log->Printf("ProcessKDP::DidAttach()"); + LLDB_LOGF(log, "ProcessKDP::DidAttach()"); if (GetID() != LLDB_INVALID_PROCESS_ID) { GetHostArchitecture(process_arch); } @@ -429,15 +428,13 @@ Status ProcessKDP::DoResume() { const StateType thread_resume_state = kernel_thread_sp->GetTemporaryResumeState(); - if (log) - log->Printf("ProcessKDP::DoResume() thread_resume_state = %s", - StateAsCString(thread_resume_state)); + LLDB_LOGF(log, "ProcessKDP::DoResume() thread_resume_state = %s", + StateAsCString(thread_resume_state)); switch (thread_resume_state) { case eStateSuspended: // Nothing to do here when a thread will stay suspended we just leave the // CPU mask bit set to zero for the thread - if (log) - log->Printf("ProcessKDP::DoResume() = suspended???"); + LLDB_LOGF(log, "ProcessKDP::DoResume() = suspended???"); break; case eStateStepping: { @@ -445,9 +442,9 @@ Status ProcessKDP::DoResume() { kernel_thread_sp->GetRegisterContext()); if (reg_ctx_sp) { - if (log) - log->Printf( - "ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep (true);"); + LLDB_LOGF( + log, + "ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep (true);"); reg_ctx_sp->HardwareSingleStep(true); resume = true; } else { @@ -462,9 +459,8 @@ Status ProcessKDP::DoResume() { kernel_thread_sp->GetRegisterContext()); if (reg_ctx_sp) { - if (log) - log->Printf("ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep " - "(false);"); + LLDB_LOGF(log, "ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep " + "(false);"); reg_ctx_sp->HardwareSingleStep(false); resume = true; } else { @@ -481,8 +477,7 @@ Status ProcessKDP::DoResume() { } if (resume) { - if (log) - log->Printf("ProcessKDP::DoResume () sending resume"); + LLDB_LOGF(log, "ProcessKDP::DoResume () sending resume"); if (m_comm.SendRequestResume()) { m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue); @@ -550,8 +545,7 @@ Status ProcessKDP::DoHalt(bool &caused_stop) { Status ProcessKDP::DoDetach(bool keep_stopped) { Status error; Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); - if (log) - log->Printf("ProcessKDP::DoDetach(keep_stopped = %i)", keep_stopped); + LLDB_LOGF(log, "ProcessKDP::DoDetach(keep_stopped = %i)", keep_stopped); if (m_comm.IsRunning()) { // We are running and we can't interrupt a running kernel, so we need to @@ -734,8 +728,7 @@ void ProcessKDP::DebuggerInitialize(lldb_private::Debugger &debugger) { bool ProcessKDP::StartAsyncThread() { Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); - if (log) - log->Printf("ProcessKDP::StartAsyncThread ()"); + LLDB_LOGF(log, "ProcessKDP::StartAsyncThread ()"); if (m_async_thread.IsJoinable()) return true; @@ -755,8 +748,7 @@ bool ProcessKDP::StartAsyncThread() { void ProcessKDP::StopAsyncThread() { Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); - if (log) - log->Printf("ProcessKDP::StopAsyncThread ()"); + LLDB_LOGF(log, "ProcessKDP::StopAsyncThread ()"); m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncThreadShouldExit); @@ -771,10 +763,10 @@ void *ProcessKDP::AsyncThread(void *arg) { const lldb::pid_t pid = process->GetID(); Log *log(ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); - if (log) - log->Printf("ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64 - ") thread starting...", - arg, pid); + LLDB_LOGF(log, + "ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64 + ") thread starting...", + arg, pid); ListenerSP listener_sp(Listener::MakeListener("ProcessKDP::AsyncThread")); EventSP event_sp; @@ -786,16 +778,16 @@ void *ProcessKDP::AsyncThread(void *arg) { desired_event_mask) { bool done = false; while (!done) { - if (log) - log->Printf("ProcessKDP::AsyncThread (pid = %" PRIu64 - ") listener.WaitForEvent (NULL, event_sp)...", - pid); + LLDB_LOGF(log, + "ProcessKDP::AsyncThread (pid = %" PRIu64 + ") listener.WaitForEvent (NULL, event_sp)...", + pid); if (listener_sp->GetEvent(event_sp, llvm::None)) { uint32_t event_type = event_sp->GetType(); - if (log) - log->Printf("ProcessKDP::AsyncThread (pid = %" PRIu64 - ") Got an event of type: %d...", - pid, event_type); + LLDB_LOGF(log, + "ProcessKDP::AsyncThread (pid = %" PRIu64 + ") Got an event of type: %d...", + pid, event_type); // When we are running, poll for 1 second to try and get an exception // to indicate the process has stopped. If we don't get one, check to @@ -834,38 +826,38 @@ void *ProcessKDP::AsyncThread(void *arg) { } break; case eBroadcastBitAsyncThreadShouldExit: - if (log) - log->Printf("ProcessKDP::AsyncThread (pid = %" PRIu64 - ") got eBroadcastBitAsyncThreadShouldExit...", - pid); + LLDB_LOGF(log, + "ProcessKDP::AsyncThread (pid = %" PRIu64 + ") got eBroadcastBitAsyncThreadShouldExit...", + pid); done = true; is_running = false; break; default: - if (log) - log->Printf("ProcessKDP::AsyncThread (pid = %" PRIu64 - ") got unknown event 0x%8.8x", - pid, event_type); + LLDB_LOGF(log, + "ProcessKDP::AsyncThread (pid = %" PRIu64 + ") got unknown event 0x%8.8x", + pid, event_type); done = true; is_running = false; break; } } while (is_running); } else { - if (log) - log->Printf("ProcessKDP::AsyncThread (pid = %" PRIu64 - ") listener.WaitForEvent (NULL, event_sp) => false", - pid); + LLDB_LOGF(log, + "ProcessKDP::AsyncThread (pid = %" PRIu64 + ") listener.WaitForEvent (NULL, event_sp) => false", + pid); done = true; } } } - if (log) - log->Printf("ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64 - ") thread exiting...", - arg, pid); + LLDB_LOGF(log, + "ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64 + ") thread exiting...", + arg, pid); process->m_async_thread.Reset(); return NULL; diff --git a/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp b/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp index a7cd637bf82..6cc2810fa23 100644 --- a/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp +++ b/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp @@ -906,8 +906,8 @@ uint32_t NativeRegisterContextNetBSD_x86_64::SetHardwareWatchpoint( return wp_index; } if (error.Fail() && log) { - log->Printf("NativeRegisterContextNetBSD_x86_64::%s Error: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, "NativeRegisterContextNetBSD_x86_64::%s Error: %s", + __FUNCTION__, error.AsCString()); } } return LLDB_INVALID_INDEX32; diff --git a/lldb/source/Plugins/Process/Utility/AuxVector.cpp b/lldb/source/Plugins/Process/Utility/AuxVector.cpp index aab164ff93a..25a1d0b5af0 100644 --- a/lldb/source/Plugins/Process/Utility/AuxVector.cpp +++ b/lldb/source/Plugins/Process/Utility/AuxVector.cpp @@ -43,9 +43,9 @@ void AuxVector::DumpToLog(lldb_private::Log *log) const { log->PutCString("AuxVector: "); for (auto entry : m_auxv_entries) { - log->Printf(" %s [%" PRIu64 "]: %" PRIx64, - GetEntryName(static_cast<EntryType>(entry.first)), entry.first, - entry.second); + LLDB_LOGF(log, " %s [%" PRIu64 "]: %" PRIx64, + GetEntryName(static_cast<EntryType>(entry.first)), entry.first, + entry.second); } } diff --git a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp index 3cb58317262..295c17e474f 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp +++ b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp @@ -32,17 +32,15 @@ HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid, m_queue_id(LLDB_INVALID_QUEUE_ID) { m_unwinder_up.reset(new HistoryUnwind(*this, pcs)); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); - if (log) - log->Printf("%p HistoryThread::HistoryThread", static_cast<void *>(this)); + LLDB_LOGF(log, "%p HistoryThread::HistoryThread", static_cast<void *>(this)); } // Destructor HistoryThread::~HistoryThread() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); - if (log) - log->Printf("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")", - static_cast<void *>(this), GetID()); + LLDB_LOGF(log, "%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")", + static_cast<void *>(this), GetID()); DestroyThread(); } diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp index e804a4d251f..4ca33c248c6 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp @@ -1111,9 +1111,10 @@ int RegisterContextDarwin_arm::WriteRegisterSet(uint32_t set) { void RegisterContextDarwin_arm::LogDBGRegisters(Log *log, const DBG &dbg) { if (log) { for (uint32_t i = 0; i < 16; i++) - log->Printf("BVR%-2u/BCR%-2u = { 0x%8.8x, 0x%8.8x } WVR%-2u/WCR%-2u = { " - "0x%8.8x, 0x%8.8x }", - i, i, dbg.bvr[i], dbg.bcr[i], i, i, dbg.wvr[i], dbg.wcr[i]); + LLDB_LOGF(log, + "BVR%-2u/BCR%-2u = { 0x%8.8x, 0x%8.8x } WVR%-2u/WCR%-2u = { " + "0x%8.8x, 0x%8.8x }", + i, i, dbg.bvr[i], dbg.bcr[i], i, i, dbg.wvr[i], dbg.wcr[i]); } } @@ -1514,8 +1515,6 @@ uint32_t RegisterContextDarwin_arm::NumSupportedHardwareBreakpoints() { // Zero is reserved for the BRP count, so don't increment it if it is zero if (g_num_supported_hw_breakpoints > 0) g_num_supported_hw_breakpoints++; - // if (log) log->Printf ("DBGDIDR=0x%8.8x (number BRP pairs = %u)", - // register_DBGDIDR, g_num_supported_hw_breakpoints); } return g_num_supported_hw_breakpoints; #else @@ -1642,8 +1641,6 @@ uint32_t RegisterContextDarwin_arm::NumSupportedHardwareWatchpoints() { uint32_t register_DBGDIDR; asm("mrc p14, 0, %0, c0, c0, 0" : "=r"(register_DBGDIDR)); g_num_supported_hw_watchpoints = Bits32(register_DBGDIDR, 31, 28) + 1; - // if (log) log->Printf ("DBGDIDR=0x%8.8x (number WRP pairs = %u)", - // register_DBGDIDR, g_num_supported_hw_watchpoints); } return g_num_supported_hw_watchpoints; #else @@ -1656,10 +1653,6 @@ uint32_t RegisterContextDarwin_arm::SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write) { - // if (log) log->Printf - // ("RegisterContextDarwin_arm::EnableHardwareWatchpoint(addr = %8.8p, size - // = %u, read = %u, write = %u)", addr, size, read, write); - const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints(); // Can't watch zero bytes diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp index 85d518a487b..331acddb975 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp @@ -285,10 +285,11 @@ int RegisterContextDarwin_arm64::WriteRegisterSet(uint32_t set) { void RegisterContextDarwin_arm64::LogDBGRegisters(Log *log, const DBG &dbg) { if (log) { for (uint32_t i = 0; i < 16; i++) - log->Printf("BVR%-2u/BCR%-2u = { 0x%8.8" PRIu64 ", 0x%8.8" PRIu64 - " } WVR%-2u/WCR%-2u " - "= { 0x%8.8" PRIu64 ", 0x%8.8" PRIu64 " }", - i, i, dbg.bvr[i], dbg.bcr[i], i, i, dbg.wvr[i], dbg.wcr[i]); + LLDB_LOGF(log, + "BVR%-2u/BCR%-2u = { 0x%8.8" PRIu64 ", 0x%8.8" PRIu64 + " } WVR%-2u/WCR%-2u " + "= { 0x%8.8" PRIu64 ", 0x%8.8" PRIu64 " }", + i, i, dbg.bvr[i], dbg.bcr[i], i, i, dbg.wvr[i], dbg.wcr[i]); } } diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp index 820d280c37f..873713fd837 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp @@ -496,11 +496,11 @@ int RegisterContextDarwin_i386::GetSetForNativeRegNum(int reg_num) { void RegisterContextDarwin_i386::LogGPR(Log *log, const char *title) { if (log) { if (title) - log->Printf("%s", title); + LLDB_LOGF(log, "%s", title); for (uint32_t i = 0; i < k_num_gpr_registers; i++) { uint32_t reg = gpr_eax + i; - log->Printf("%12s = 0x%8.8x", g_register_infos[reg].name, - (&gpr.eax)[reg]); + LLDB_LOGF(log, "%12s = 0x%8.8x", g_register_infos[reg].name, + (&gpr.eax)[reg]); } } } diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp index 786c4a5df49..62f38dcd85a 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp @@ -2087,8 +2087,9 @@ void RegisterContextLLDB::UnwindLogMsg(const char *fmt, ...) { } va_end(args); - log->Printf("%*sth%d/fr%u %s", m_frame_number < 100 ? m_frame_number : 100, - "", m_thread.GetIndexID(), m_frame_number, logmsg); + LLDB_LOGF(log, "%*sth%d/fr%u %s", + m_frame_number < 100 ? m_frame_number : 100, "", + m_thread.GetIndexID(), m_frame_number, logmsg); free(logmsg); } } @@ -2108,8 +2109,9 @@ void RegisterContextLLDB::UnwindLogMsgVerbose(const char *fmt, ...) { } va_end(args); - log->Printf("%*sth%d/fr%u %s", m_frame_number < 100 ? m_frame_number : 100, - "", m_thread.GetIndexID(), m_frame_number, logmsg); + LLDB_LOGF(log, "%*sth%d/fr%u %s", + m_frame_number < 100 ? m_frame_number : 100, "", + m_thread.GetIndexID(), m_frame_number, logmsg); free(logmsg); } } diff --git a/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp b/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp index 38209fb2494..4b135351593 100644 --- a/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp +++ b/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp @@ -104,8 +104,8 @@ bool UnwindLLDB::AddFirstFrame() { unwind_done: Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND)); if (log) { - log->Printf("th%d Unwind of this thread is complete.", - m_thread.GetIndexID()); + LLDB_LOGF(log, "th%d Unwind of this thread is complete.", + m_thread.GetIndexID()); } m_unwind_complete = true; return false; @@ -140,10 +140,10 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) { // is going to blow out the stack space. If we're still unwinding at that // point, we're probably never going to finish. if (cur_idx >= max_stack_depth) { - if (log) - log->Printf("%*sFrame %d unwound too many frames, assuming unwind has " - "gone astray, stopping.", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, + "%*sFrame %d unwound too many frames, assuming unwind has " + "gone astray, stopping.", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); return nullptr; } @@ -161,9 +161,8 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) { return GetOneMoreFrame(abi); } - if (log) - log->Printf("%*sFrame %d did not get a RegisterContext, stopping.", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, "%*sFrame %d did not get a RegisterContext, stopping.", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); return nullptr; } @@ -181,10 +180,10 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) { return GetOneMoreFrame(abi); } - if (log) - log->Printf("%*sFrame %d invalid RegisterContext for this frame, " - "stopping stack walk", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, + "%*sFrame %d invalid RegisterContext for this frame, " + "stopping stack walk", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); return nullptr; } if (!reg_ctx_sp->GetCFA(cursor_sp->cfa)) { @@ -201,10 +200,9 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) { return GetOneMoreFrame(abi); } - if (log) - log->Printf( - "%*sFrame %d did not get CFA for this frame, stopping stack walk", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, + "%*sFrame %d did not get CFA for this frame, stopping stack walk", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); return nullptr; } if (abi && !abi->CallFrameAddressIsValid(cursor_sp->cfa)) { @@ -230,17 +228,17 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) { return GetOneMoreFrame(abi); } - if (log) - log->Printf("%*sFrame %d did not get a valid CFA for this frame, " - "stopping stack walk", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, + "%*sFrame %d did not get a valid CFA for this frame, " + "stopping stack walk", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); return nullptr; } else { - if (log) - log->Printf("%*sFrame %d had a bad CFA value but we switched the " - "UnwindPlan being used and got one that looks more " - "realistic.", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, + "%*sFrame %d had a bad CFA value but we switched the " + "UnwindPlan being used and got one that looks more " + "realistic.", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); } } } @@ -258,10 +256,9 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) { return GetOneMoreFrame(abi); } - if (log) - log->Printf( - "%*sFrame %d did not get PC for this frame, stopping stack walk", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, + "%*sFrame %d did not get PC for this frame, stopping stack walk", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); return nullptr; } if (abi && !abi->CodeAddressIsValid(cursor_sp->start_pc)) { @@ -278,18 +275,17 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) { return GetOneMoreFrame(abi); } - if (log) - log->Printf("%*sFrame %d did not get a valid PC, stopping stack walk", - cur_idx < 100 ? cur_idx : 100, "", cur_idx); + LLDB_LOGF(log, "%*sFrame %d did not get a valid PC, stopping stack walk", + cur_idx < 100 ? cur_idx : 100, "", cur_idx); return nullptr; } // Infinite loop where the current cursor is the same as the previous one... if (prev_frame->start_pc == cursor_sp->start_pc && prev_frame->cfa == cursor_sp->cfa) { - if (log) - log->Printf("th%d pc of this frame is the same as the previous frame and " - "CFAs for both frames are identical -- stopping unwind", - m_thread.GetIndexID()); + LLDB_LOGF(log, + "th%d pc of this frame is the same as the previous frame and " + "CFAs for both frames are identical -- stopping unwind", + m_thread.GetIndexID()); return nullptr; } @@ -337,9 +333,8 @@ bool UnwindLLDB::AddOneMoreFrame(ABI *abi) { new_frame = GetOneMoreFrame(abi); if (new_frame == nullptr) { - if (log) - log->Printf("th%d Unwind of this thread is complete.", - m_thread.GetIndexID()); + LLDB_LOGF(log, "th%d Unwind of this thread is complete.", + m_thread.GetIndexID()); m_unwind_complete = true; return false; } diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp index 980169e16c5..d92c20ef8a9 100644 --- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp +++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp @@ -417,7 +417,7 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data, Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) { if (pr_version > 1) - log->Printf("FreeBSD PRSTATUS unexpected version %d", pr_version); + LLDB_LOGF(log, "FreeBSD PRSTATUS unexpected version %d", pr_version); } // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp index a5d1fc4a7bf..508c8a3108a 100644 --- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp +++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp @@ -181,9 +181,8 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) { } if (!reg_interface) { - if (log) - log->Printf("elf-core::%s:: Architecture(%d) or OS(%d) not supported", - __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS()); + LLDB_LOGF(log, "elf-core::%s:: Architecture(%d) or OS(%d) not supported", + __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS()); assert(false && "Architecture or OS not supported"); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp index fe7ef6b3ace..140e2433023 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp @@ -63,18 +63,16 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( case PacketResult::Success: break; default: - if (log) - log->Printf("GDBRemoteClientBase::%s () ReadPacket(...) => false", - __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteClientBase::%s () ReadPacket(...) => false", + __FUNCTION__); return eStateInvalid; } if (response.Empty()) return eStateInvalid; const char stop_type = response.GetChar(); - if (log) - log->Printf("GDBRemoteClientBase::%s () got packet: %s", __FUNCTION__, - response.GetStringRef().c_str()); + LLDB_LOGF(log, "GDBRemoteClientBase::%s () got packet: %s", __FUNCTION__, + response.GetStringRef().c_str()); switch (stop_type) { case 'W': @@ -84,9 +82,8 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( // ERROR return eStateInvalid; default: - if (log) - log->Printf("GDBRemoteClientBase::%s () unrecognized async packet", - __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteClientBase::%s () unrecognized async packet", + __FUNCTION__); return eStateInvalid; case 'O': { std::string inferior_stdout; @@ -162,10 +159,10 @@ GDBRemoteClientBase::SendPacketAndWaitForResponse( if (!lock) { if (Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)) - log->Printf("GDBRemoteClientBase::%s failed to get mutex, not sending " - "packet '%.*s' (send_async=%d)", - __FUNCTION__, int(payload.size()), payload.data(), - send_async); + LLDB_LOGF(log, + "GDBRemoteClientBase::%s failed to get mutex, not sending " + "packet '%.*s' (send_async=%d)", + __FUNCTION__, int(payload.size()), payload.data(), send_async); return PacketResult::ErrorSendFailed; } @@ -181,10 +178,10 @@ GDBRemoteClientBase::SendPacketAndReceiveResponseWithOutputSupport( if (!lock) { if (Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)) - log->Printf("GDBRemoteClientBase::%s failed to get mutex, not sending " - "packet '%.*s' (send_async=%d)", - __FUNCTION__, int(payload.size()), payload.data(), - send_async); + LLDB_LOGF(log, + "GDBRemoteClientBase::%s failed to get mutex, not sending " + "packet '%.*s' (send_async=%d)", + __FUNCTION__, int(payload.size()), payload.data(), send_async); return PacketResult::ErrorSendFailed; } @@ -214,13 +211,13 @@ GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock( return packet_result; // Response says it wasn't valid Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS); - if (log) - log->Printf( - "error: packet with payload \"%.*s\" got invalid response \"%s\": %s", - int(payload.size()), payload.data(), response.GetStringRef().c_str(), - (i == (max_response_retries - 1)) - ? "using invalid response and giving up" - : "ignoring response and waiting for another"); + LLDB_LOGF( + log, + "error: packet with payload \"%.*s\" got invalid response \"%s\": %s", + int(payload.size()), payload.data(), response.GetStringRef().c_str(), + (i == (max_response_retries - 1)) + ? "using invalid response and giving up" + : "ignoring response and waiting for another"); } return packet_result; } @@ -228,16 +225,14 @@ GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock( bool GDBRemoteClientBase::SendvContPacket(llvm::StringRef payload, StringExtractorGDBRemote &response) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationClient::%s ()", __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationClient::%s ()", __FUNCTION__); // we want to lock down packet sending while we continue Lock lock(*this, true); - if (log) - log->Printf( - "GDBRemoteCommunicationClient::%s () sending vCont packet: %.*s", - __FUNCTION__, int(payload.size()), payload.data()); + LLDB_LOGF(log, + "GDBRemoteCommunicationClient::%s () sending vCont packet: %.*s", + __FUNCTION__, int(payload.size()), payload.data()); if (SendPacketNoLock(payload) != PacketResult::Success) return false; @@ -315,18 +310,16 @@ void GDBRemoteClientBase::ContinueLock::unlock() { GDBRemoteClientBase::ContinueLock::LockResult GDBRemoteClientBase::ContinueLock::lock() { Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS); - if (log) - log->Printf("GDBRemoteClientBase::ContinueLock::%s() resuming with %s", - __FUNCTION__, m_comm.m_continue_packet.c_str()); + LLDB_LOGF(log, "GDBRemoteClientBase::ContinueLock::%s() resuming with %s", + __FUNCTION__, m_comm.m_continue_packet.c_str()); lldbassert(!m_acquired); std::unique_lock<std::mutex> lock(m_comm.m_mutex); m_comm.m_cv.wait(lock, [this] { return m_comm.m_async_count == 0; }); if (m_comm.m_should_stop) { m_comm.m_should_stop = false; - if (log) - log->Printf("GDBRemoteClientBase::ContinueLock::%s() cancelled", - __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteClientBase::ContinueLock::%s() cancelled", + __FUNCTION__); return LockResult::Cancelled; } if (m_comm.SendPacketNoLock(m_comm.m_continue_packet) != @@ -368,9 +361,8 @@ void GDBRemoteClientBase::Lock::SyncWithContinueThread(bool interrupt) { size_t bytes_written = m_comm.Write(&ctrl_c, 1, status, nullptr); if (bytes_written == 0) { --m_comm.m_async_count; - if (log) - log->Printf("GDBRemoteClientBase::Lock::Lock failed to send " - "interrupt packet"); + LLDB_LOGF(log, "GDBRemoteClientBase::Lock::Lock failed to send " + "interrupt packet"); return; } if (log) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 11052eff948..23a069d8223 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -99,8 +99,7 @@ size_t GDBRemoteCommunication::SendAck() { ConnectionStatus status = eConnectionStatusSuccess; char ch = '+'; const size_t bytes_written = Write(&ch, 1, status, nullptr); - if (log) - log->Printf("<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch); + LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch); m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend, bytes_written); return bytes_written; @@ -111,8 +110,7 @@ size_t GDBRemoteCommunication::SendNack() { ConnectionStatus status = eConnectionStatusSuccess; char ch = '-'; const size_t bytes_written = Write(&ch, 1, status, nullptr); - if (log) - log->Printf("<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch); + LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch); m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend, bytes_written); return bytes_written; @@ -172,8 +170,8 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet, strm.Printf("%*s", (int)3, p); log->PutString(strm.GetString()); } else - log->Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written, - (int)packet_length, packet_data); + LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %.*s", + (uint64_t)bytes_written, (int)packet_length, packet_data); } m_history.AddPacket(packet.str(), packet_length, @@ -186,9 +184,8 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet, else return PacketResult::Success; } else { - if (log) - log->Printf("error: failed to send packet: %.*s", (int)packet_length, - packet_data); + LLDB_LOGF(log, "error: failed to send packet: %.*s", (int)packet_length, + packet_data); } } return PacketResult::ErrorSendFailed; @@ -489,11 +486,10 @@ bool GDBRemoteCommunication::DecompressPacket() { llvm::StringRef(m_bytes).substr(1, hash_mark_idx - 1)); bool success = packet_checksum == actual_checksum; if (!success) { - if (log) - log->Printf( - "error: checksum mismatch: %.*s expected 0x%2.2x, got 0x%2.2x", - (int)(pkt_size), m_bytes.c_str(), (uint8_t)packet_checksum, - (uint8_t)actual_checksum); + LLDB_LOGF(log, + "error: checksum mismatch: %.*s expected 0x%2.2x, got 0x%2.2x", + (int)(pkt_size), m_bytes.c_str(), (uint8_t)packet_checksum, + (uint8_t)actual_checksum); } // Send the ack or nack if needed if (!success) { @@ -651,8 +647,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, if (src && src_len > 0) { if (log && log->GetVerbose()) { StreamString s; - log->Printf("GDBRemoteCommunication::%s adding %u bytes: %.*s", - __FUNCTION__, (uint32_t)src_len, (uint32_t)src_len, src); + LLDB_LOGF(log, "GDBRemoteCommunication::%s adding %u bytes: %.*s", + __FUNCTION__, (uint32_t)src_len, (uint32_t)src_len, src); } m_bytes.append((const char *)src, src_len); } @@ -733,9 +729,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, break; } } - if (log) - log->Printf("GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'", - __FUNCTION__, idx - 1, idx - 1, m_bytes.c_str()); + LLDB_LOGF(log, "GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'", + __FUNCTION__, idx - 1, idx - 1, m_bytes.c_str()); m_bytes.erase(0, idx - 1); } break; } @@ -800,13 +795,13 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, log->PutString(strm.GetString()); } else { if (CompressionIsEnabled()) - log->Printf("<%4" PRIu64 ":%" PRIu64 "> read packet: %.*s", - (uint64_t)original_packet_size, (uint64_t)total_length, - (int)(total_length), m_bytes.c_str()); + LLDB_LOGF(log, "<%4" PRIu64 ":%" PRIu64 "> read packet: %.*s", + (uint64_t)original_packet_size, (uint64_t)total_length, + (int)(total_length), m_bytes.c_str()); else - log->Printf("<%4" PRIu64 "> read packet: %.*s", - (uint64_t)total_length, (int)(total_length), - m_bytes.c_str()); + LLDB_LOGF(log, "<%4" PRIu64 "> read packet: %.*s", + (uint64_t)total_length, (int)(total_length), + m_bytes.c_str()); } } @@ -853,11 +848,11 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, llvm::StringRef(m_bytes).slice(content_start, content_end)); success = packet_checksum == actual_checksum; if (!success) { - if (log) - log->Printf("error: checksum mismatch: %.*s expected 0x%2.2x, " - "got 0x%2.2x", - (int)(total_length), m_bytes.c_str(), - (uint8_t)packet_checksum, (uint8_t)actual_checksum); + LLDB_LOGF(log, + "error: checksum mismatch: %.*s expected 0x%2.2x, " + "got 0x%2.2x", + (int)(total_length), m_bytes.c_str(), + (uint8_t)packet_checksum, (uint8_t)actual_checksum); } // Send the ack or nack if needed if (!success) @@ -867,9 +862,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, } } else { success = false; - if (log) - log->Printf("error: invalid checksum in packet: '%s'\n", - m_bytes.c_str()); + LLDB_LOGF(log, "error: invalid checksum in packet: '%s'\n", + m_bytes.c_str()); } } @@ -933,10 +927,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess( const char *url, Platform *platform, ProcessLaunchInfo &launch_info, uint16_t *port, const Args *inferior_args, int pass_comm_fd) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunication::%s(url=%s, port=%" PRIu16 ")", - __FUNCTION__, url ? url : "<empty>", - port ? *port : uint16_t(0)); + LLDB_LOGF(log, "GDBRemoteCommunication::%s(url=%s, port=%" PRIu16 ")", + __FUNCTION__, url ? url : "<empty>", port ? *port : uint16_t(0)); Status error; // If we locate debugserver, keep that located version around @@ -953,10 +945,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess( if (!env_debugserver_path.empty()) { debugserver_file_spec.SetFile(env_debugserver_path, FileSpec::Style::native); - if (log) - log->Printf("GDBRemoteCommunication::%s() gdb-remote stub exe path set " - "from environment variable: %s", - __FUNCTION__, env_debugserver_path.c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() gdb-remote stub exe path set " + "from environment variable: %s", + __FUNCTION__, env_debugserver_path.c_str()); } else debugserver_file_spec = g_debugserver_file_spec; bool debugserver_exists = @@ -968,10 +960,9 @@ Status GDBRemoteCommunication::StartDebugserverProcess( debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME); debugserver_exists = FileSystem::Instance().Exists(debugserver_file_spec); if (debugserver_exists) { - if (log) - log->Printf( - "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'", - __FUNCTION__, debugserver_file_spec.GetPath().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'", + __FUNCTION__, debugserver_file_spec.GetPath().c_str()); g_debugserver_file_spec = debugserver_file_spec; } else { @@ -985,10 +976,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess( // exist debugserver_exists = true; } else { - if (log) - log->Printf("GDBRemoteCommunication::%s() could not find " - "gdb-remote stub exe '%s'", - __FUNCTION__, debugserver_file_spec.GetPath().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() could not find " + "gdb-remote stub exe '%s'", + __FUNCTION__, debugserver_file_spec.GetPath().c_str()); } // Don't cache the platform specific GDB server binary as it could // change from platform to platform @@ -1052,10 +1043,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess( error = socket_pipe.CreateWithUniqueName("debugserver-named-pipe", false, named_pipe_path); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunication::%s() " - "named pipe creation failed: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() " + "named pipe creation failed: %s", + __FUNCTION__, error.AsCString()); return error; } debugserver_args.AppendArgument(llvm::StringRef("--named-pipe")); @@ -1065,10 +1056,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess( // using using an unnamed pipe... error = socket_pipe.CreateNew(true); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunication::%s() " - "unnamed pipe creation failed: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() " + "unnamed pipe creation failed: %s", + __FUNCTION__, error.AsCString()); return error; } pipe_t write = socket_pipe.GetWritePipe(); @@ -1081,10 +1072,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess( // debugserver connect to us.. error = StartListenThread("127.0.0.1", 0); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunication::%s() unable to start listen " - "thread: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() unable to start listen " + "thread: %s", + __FUNCTION__, error.AsCString()); return error; } @@ -1104,9 +1095,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess( *port = port_; } else { error.SetErrorString("failed to bind to port 0 on 127.0.0.1"); - if (log) - log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOGF(log, "GDBRemoteCommunication::%s() failed: %s", + __FUNCTION__, error.AsCString()); return error; } } @@ -1148,10 +1138,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess( if (has_env_var) { debugserver_args.AppendArgument(llvm::StringRef(extra_arg)); - if (log) - log->Printf("GDBRemoteCommunication::%s adding env var %s contents " - "to stub command line (%s)", - __FUNCTION__, env_var_name, extra_arg.c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s adding env var %s contents " + "to stub command line (%s)", + __FUNCTION__, env_var_name, extra_arg.c_str()); } } while (has_env_var); @@ -1177,8 +1167,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess( StreamString string_stream; Platform *const platform = nullptr; launch_info.Dump(string_stream, platform); - log->Printf("launch info for gdb-remote stub:\n%s", - string_stream.GetData()); + LLDB_LOGF(log, "launch info for gdb-remote stub:\n%s", + string_stream.GetData()); } error = Host::LaunchProcess(launch_info); @@ -1188,11 +1178,10 @@ Status GDBRemoteCommunication::StartDebugserverProcess( if (named_pipe_path.size() > 0) { error = socket_pipe.OpenAsReader(named_pipe_path, false); if (error.Fail()) - if (log) - log->Printf("GDBRemoteCommunication::%s() " - "failed to open named pipe %s for reading: %s", - __FUNCTION__, named_pipe_path.c_str(), - error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() " + "failed to open named pipe %s for reading: %s", + __FUNCTION__, named_pipe_path.c_str(), error.AsCString()); } if (socket_pipe.CanWrite()) @@ -1209,24 +1198,22 @@ Status GDBRemoteCommunication::StartDebugserverProcess( uint16_t child_port = StringConvert::ToUInt32(port_cstr, 0); if (*port == 0 || *port == child_port) { *port = child_port; - if (log) - log->Printf("GDBRemoteCommunication::%s() " - "debugserver listens %u port", - __FUNCTION__, *port); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() " + "debugserver listens %u port", + __FUNCTION__, *port); } else { - if (log) - log->Printf("GDBRemoteCommunication::%s() " - "debugserver listening on port " - "%d but requested port was %d", - __FUNCTION__, (uint32_t)child_port, - (uint32_t)(*port)); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() " + "debugserver listening on port " + "%d but requested port was %d", + __FUNCTION__, (uint32_t)child_port, (uint32_t)(*port)); } } else { - if (log) - log->Printf("GDBRemoteCommunication::%s() " - "failed to read a port value from pipe %s: %s", - __FUNCTION__, named_pipe_path.c_str(), - error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s() " + "failed to read a port value from pipe %s: %s", + __FUNCTION__, named_pipe_path.c_str(), error.AsCString()); } socket_pipe.Close(); } @@ -1234,10 +1221,9 @@ Status GDBRemoteCommunication::StartDebugserverProcess( if (named_pipe_path.size() > 0) { const auto err = socket_pipe.Delete(named_pipe_path); if (err.Fail()) { - if (log) - log->Printf( - "GDBRemoteCommunication::%s failed to delete pipe %s: %s", - __FUNCTION__, named_pipe_path.c_str(), err.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunication::%s failed to delete pipe %s: %s", + __FUNCTION__, named_pipe_path.c_str(), err.AsCString()); } } @@ -1249,9 +1235,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess( } if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOGF(log, "GDBRemoteCommunication::%s() failed: %s", __FUNCTION__, + error.AsCString()); } return error; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 9797184026e..8ebeaf03be9 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -439,8 +439,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() { m_max_packet_size = UINT64_MAX; // Must have been a garbled response Log *log( ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("Garbled PacketSize spec in qSupported response"); + LLDB_LOGF(log, "Garbled PacketSize spec in qSupported response"); } } } @@ -525,9 +524,10 @@ GDBRemoteCommunicationClient::SendThreadSpecificPacketAndWaitForResponse( if (!lock) { if (Log *log = ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet( GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)) - log->Printf("GDBRemoteCommunicationClient::%s: Didn't get sequence mutex " - "for %s packet.", - __FUNCTION__, payload.GetData()); + LLDB_LOGF(log, + "GDBRemoteCommunicationClient::%s: Didn't get sequence mutex " + "for %s packet.", + __FUNCTION__, payload.GetData()); return PacketResult::ErrorNoSequenceLock; } @@ -660,10 +660,10 @@ GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses( if (!lock) { Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); - if (log) - log->Printf("error: failed to get packet sequence mutex, not sending " - "packets with prefix '%s'", - payload_prefix); + LLDB_LOGF(log, + "error: failed to get packet sequence mutex, not sending " + "packets with prefix '%s'", + payload_prefix); return PacketResult::ErrorNoSequenceLock; } @@ -1284,14 +1284,15 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) { assert(byte_order == m_host_arch.GetByteOrder()); } - if (log) - log->Printf("GDBRemoteCommunicationClient::%s parsed host " - "architecture as %s, triple as %s from triple text %s", - __FUNCTION__, m_host_arch.GetArchitectureName() - ? m_host_arch.GetArchitectureName() - : "<null-arch-name>", - m_host_arch.GetTriple().getTriple().c_str(), - triple.c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunicationClient::%s parsed host " + "architecture as %s, triple as %s from triple text %s", + __FUNCTION__, + m_host_arch.GetArchitectureName() + ? m_host_arch.GetArchitectureName() + : "<null-arch-name>", + m_host_arch.GetTriple().getTriple().c_str(), + triple.c_str()); } if (!distribution_id.empty()) m_host_arch.SetDistributionId(distribution_id.c_str()); @@ -2064,12 +2065,10 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) { break; case llvm::Triple::Wasm: case llvm::Triple::XCOFF: - if (log) - log->Printf("error: not supported target architecture"); + LLDB_LOGF(log, "error: not supported target architecture"); return false; case llvm::Triple::UnknownObjectFormat: - if (log) - log->Printf("error: failed to determine target architecture"); + LLDB_LOGF(log, "error: failed to determine target architecture"); return false; } @@ -2641,9 +2640,8 @@ bool GDBRemoteCommunicationClient::GetThreadStopInfo( uint8_t GDBRemoteCommunicationClient::SendGDBStoppointTypePacket( GDBStoppointType type, bool insert, addr_t addr, uint32_t length) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); - if (log) - log->Printf("GDBRemoteCommunicationClient::%s() %s at addr = 0x%" PRIx64, - __FUNCTION__, insert ? "add" : "remove", addr); + LLDB_LOGF(log, "GDBRemoteCommunicationClient::%s() %s at addr = 0x%" PRIx64, + __FUNCTION__, insert ? "add" : "remove", addr); // Check if the stub is known not to support this breakpoint type if (!SupportsGDBStoppointPacket(type)) @@ -2745,9 +2743,8 @@ size_t GDBRemoteCommunicationClient::GetCurrentThreadIDs( #if !defined(LLDB_CONFIGURATION_DEBUG) Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); - if (log) - log->Printf("error: failed to get packet sequence mutex, not sending " - "packet 'qfThreadInfo'"); + LLDB_LOGF(log, "error: failed to get packet sequence mutex, not sending " + "packet 'qfThreadInfo'"); #endif sequence_mutex_unavailable = true; } @@ -3873,9 +3870,9 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups( } else if (Log *log = ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet( GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)) { - log->Printf( - "GDBRemoteCommunicationClient::%s: Didn't get sequence mutex.", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationClient::%s: Didn't get sequence mutex.", + __FUNCTION__); } } } @@ -3899,26 +3896,27 @@ GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() { !m_supported_async_json_packets_sp->GetAsArray()) { // We were returned something other than a JSON array. This is // invalid. Clear it out. - if (log) - log->Printf("GDBRemoteCommunicationClient::%s(): " - "QSupportedAsyncJSONPackets returned invalid " - "result: %s", - __FUNCTION__, response.GetStringRef().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunicationClient::%s(): " + "QSupportedAsyncJSONPackets returned invalid " + "result: %s", + __FUNCTION__, response.GetStringRef().c_str()); m_supported_async_json_packets_sp.reset(); } } else { - if (log) - log->Printf("GDBRemoteCommunicationClient::%s(): " - "QSupportedAsyncJSONPackets unsupported", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationClient::%s(): " + "QSupportedAsyncJSONPackets unsupported", + __FUNCTION__); } if (log && m_supported_async_json_packets_sp) { StreamString stream; m_supported_async_json_packets_sp->Dump(stream); - log->Printf("GDBRemoteCommunicationClient::%s(): supported async " - "JSON packets: %s", - __FUNCTION__, stream.GetData()); + LLDB_LOGF(log, + "GDBRemoteCommunicationClient::%s(): supported async " + "JSON packets: %s", + __FUNCTION__, stream.GetData()); } } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp index bcddb4faf86..f9f67fcbcaa 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp @@ -95,10 +95,10 @@ void GDBRemoteCommunicationHistory::Dump(Log *log) const { const Entry &entry = m_packets[idx]; if (entry.type == ePacketTypeInvalid || entry.packet.data.empty()) break; - log->Printf("history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s", - entry.packet_idx, entry.tid, entry.bytes_transmitted, - (entry.type == ePacketTypeSend) ? "send" : "read", - entry.packet.data.c_str()); + LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s", + entry.packet_idx, entry.tid, entry.bytes_transmitted, + (entry.type == ePacketTypeSend) ? "send" : "read", + entry.packet.data.c_str()); } } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp index 49cbeb023fd..d137c4c39ec 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp @@ -139,10 +139,9 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServer::SendIllFormedResponse( const StringExtractorGDBRemote &failed_packet, const char *message) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS)); - if (log) - log->Printf("GDBRemoteCommunicationServer::%s: ILLFORMED: '%s' (%s)", - __FUNCTION__, failed_packet.GetStringRef().c_str(), - message ? message : ""); + LLDB_LOGF(log, "GDBRemoteCommunicationServer::%s: ILLFORMED: '%s' (%s)", + __FUNCTION__, failed_packet.GetStringRef().c_str(), + message ? message : ""); return SendErrorResponse(0x03); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index 9767d3e8b98..c1eaa1dc2ed 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -421,8 +421,7 @@ GDBRemoteCommunicationServerCommon::Handle_qUserName( StringExtractorGDBRemote &packet) { #if !defined(LLDB_DISABLE_POSIX) Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__); // Packet format: "qUserName:%i" where %i is the uid packet.SetFilePos(::strlen("qUserName:")); @@ -435,8 +434,7 @@ GDBRemoteCommunicationServerCommon::Handle_qUserName( return SendPacketNoLock(response.GetString()); } } - if (log) - log->Printf("GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__); #endif return SendErrorResponse(5); } @@ -1017,9 +1015,8 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) { m_process_launch_info.GetExecutableFile().SetFile( arg, FileSpec::Style::native); m_process_launch_info.GetArguments().AppendArgument(arg); - if (log) - log->Printf("LLGSPacketHandler::%s added arg %d: \"%s\"", - __FUNCTION__, actual_arg_index, arg.c_str()); + LLDB_LOGF(log, "LLGSPacketHandler::%s added arg %d: \"%s\"", + __FUNCTION__, actual_arg_index, arg.c_str()); ++actual_arg_index; } } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 190db341ae0..6bdbbd24fdb 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -249,18 +249,18 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() { // Setup stdout/stderr mapping from inferior to $O auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor(); if (terminal_fd >= 0) { - if (log) - log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting " - "inferior STDIO fd to %d", - __FUNCTION__, terminal_fd); + LLDB_LOGF(log, + "ProcessGDBRemoteCommunicationServerLLGS::%s setting " + "inferior STDIO fd to %d", + __FUNCTION__, terminal_fd); Status status = SetSTDIOFileDescriptor(terminal_fd); if (status.Fail()) return status; } else { - if (log) - log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s ignoring " - "inferior STDIO since terminal fd reported as %d", - __FUNCTION__, terminal_fd); + LLDB_LOGF(log, + "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring " + "inferior STDIO since terminal fd reported as %d", + __FUNCTION__, terminal_fd); } } else { LLDB_LOG(log, @@ -278,9 +278,8 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() { Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64, - __FUNCTION__, pid); + LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64, + __FUNCTION__, pid); // Before we try to attach, make sure we aren't already monitoring something // else. @@ -304,18 +303,18 @@ Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) { // Setup stdout/stderr mapping from inferior. auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor(); if (terminal_fd >= 0) { - if (log) - log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting " - "inferior STDIO fd to %d", - __FUNCTION__, terminal_fd); + LLDB_LOGF(log, + "ProcessGDBRemoteCommunicationServerLLGS::%s setting " + "inferior STDIO fd to %d", + __FUNCTION__, terminal_fd); Status status = SetSTDIOFileDescriptor(terminal_fd); if (status.Fail()) return status; } else { - if (log) - log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s ignoring " - "inferior STDIO since terminal fd reported as %d", - __FUNCTION__, terminal_fd); + LLDB_LOGF(log, + "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring " + "inferior STDIO since terminal fd reported as %d", + __FUNCTION__, terminal_fd); } printf("Attached to process %" PRIu64 "...\n", pid); @@ -327,10 +326,11 @@ void GDBRemoteCommunicationServerLLGS::InitializeDelegate( assert(process && "process cannot be NULL"); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) { - log->Printf("GDBRemoteCommunicationServerLLGS::%s called with " - "NativeProcessProtocol pid %" PRIu64 ", current state: %s", - __FUNCTION__, process->GetID(), - StateAsCString(process->GetState())); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s called with " + "NativeProcessProtocol pid %" PRIu64 ", current state: %s", + __FUNCTION__, process->GetID(), + StateAsCString(process->GetState())); } } @@ -431,10 +431,9 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) { const RegisterInfo *const reg_info_p = reg_ctx.GetRegisterInfoAtIndex(reg_num); if (reg_info_p == nullptr) { - if (log) - log->Printf( - "%s failed to get register info for register index %" PRIu32, - __FUNCTION__, reg_num); + LLDB_LOGF(log, + "%s failed to get register info for register index %" PRIu32, + __FUNCTION__, reg_num); continue; } @@ -445,11 +444,10 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) { RegisterValue reg_value; Status error = reg_ctx.ReadRegister(reg_info_p, reg_value); if (error.Fail()) { - if (log) - log->Printf("%s failed to read register '%s' index %" PRIu32 ": %s", - __FUNCTION__, - reg_info_p->name ? reg_info_p->name : "<unnamed-register>", - reg_num, error.AsCString()); + LLDB_LOGF(log, "%s failed to read register '%s' index %" PRIu32 ": %s", + __FUNCTION__, + reg_info_p->name ? reg_info_p->name : "<unnamed-register>", + reg_num, error.AsCString()); continue; } @@ -511,11 +509,12 @@ static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process, const int signum = tid_stop_info.details.signal.signo; if (log) { - log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 - " tid %" PRIu64 - " got signal signo = %d, reason = %d, exc_type = %" PRIu64, - __FUNCTION__, process.GetID(), tid, signum, - tid_stop_info.reason, tid_stop_info.details.exception.type); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 + " tid %" PRIu64 + " got signal signo = %d, reason = %d, exc_type = %" PRIu64, + __FUNCTION__, process.GetID(), tid, signum, + tid_stop_info.reason, tid_stop_info.details.exception.type); } JSONObject::SP thread_obj_sp = std::make_shared<JSONObject>(); @@ -684,12 +683,10 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( RegisterValue reg_value; Status error = reg_ctx.ReadRegister(reg_info_p, reg_value); if (error.Fail()) { - if (log) - log->Printf("%s failed to read register '%s' index %" PRIu32 ": %s", - __FUNCTION__, - reg_info_p->name ? reg_info_p->name - : "<unnamed-register>", - reg_to_read, error.AsCString()); + LLDB_LOGF(log, "%s failed to read register '%s' index %" PRIu32 ": %s", + __FUNCTION__, + reg_info_p->name ? reg_info_p->name : "<unnamed-register>", + reg_to_read, error.AsCString()); continue; } @@ -713,25 +710,24 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( const RegisterSet *reg_set_p; if (reg_ctx.GetRegisterSetCount() > 0 && ((reg_set_p = reg_ctx.GetRegisterSet(0)) != nullptr)) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s expediting registers " - "from set '%s' (registers set count: %zu)", - __FUNCTION__, - reg_set_p->name ? reg_set_p->name : "<unnamed-set>", - reg_set_p->num_registers); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s expediting registers " + "from set '%s' (registers set count: %zu)", + __FUNCTION__, reg_set_p->name ? reg_set_p->name : "<unnamed-set>", + reg_set_p->num_registers); for (const uint32_t *reg_num_p = reg_set_p->registers; *reg_num_p != LLDB_INVALID_REGNUM; ++reg_num_p) { const RegisterInfo *const reg_info_p = reg_ctx.GetRegisterInfoAtIndex(*reg_num_p); if (reg_info_p == nullptr) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to get " - "register info for register set '%s', register index " - "%" PRIu32, - __FUNCTION__, - reg_set_p->name ? reg_set_p->name : "<unnamed-set>", - *reg_num_p); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to get " + "register info for register set '%s', register index " + "%" PRIu32, + __FUNCTION__, + reg_set_p->name ? reg_set_p->name : "<unnamed-set>", + *reg_num_p); } else if (reg_info_p->value_regs == nullptr) { // Only expediate registers that are not contained in other registers. RegisterValue reg_value; @@ -742,13 +738,12 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( ®_value, lldb::eByteOrderBig); response.PutChar(';'); } else { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to read " - "register '%s' index %" PRIu32 ": %s", - __FUNCTION__, - reg_info_p->name ? reg_info_p->name - : "<unnamed-register>", - *reg_num_p, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to read " + "register '%s' index %" PRIu32 ": %s", + __FUNCTION__, + reg_info_p->name ? reg_info_p->name : "<unnamed-register>", + *reg_num_p, error.AsCString()); } } } @@ -787,15 +782,14 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited( assert(process && "process cannot be NULL"); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); PacketResult result = SendStopReasonForState(StateType::eStateExited); if (result != PacketResult::Success) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to send stop " - "notification for PID %" PRIu64 ", state: eStateExited", - __FUNCTION__, process->GetID()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to send stop " + "notification for PID %" PRIu64 ", state: eStateExited", + __FUNCTION__, process->GetID()); } // Close the pipe to the inferior terminal i/o if we launched it and set one @@ -812,8 +806,7 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped( assert(process && "process cannot be NULL"); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); // Send the stop reason unless this is the stop after the launch or attach. switch (m_inferior_prev_state) { @@ -825,10 +818,10 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped( // In all other cases, send the stop reason. PacketResult result = SendStopReasonForState(StateType::eStateStopped); if (result != PacketResult::Success) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to send stop " - "notification for PID %" PRIu64 ", state: eStateExited", - __FUNCTION__, process->GetID()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to send stop " + "notification for PID %" PRIu64 ", state: eStateExited", + __FUNCTION__, process->GetID()); } break; } @@ -839,9 +832,10 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged( assert(process && "process cannot be NULL"); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) { - log->Printf("GDBRemoteCommunicationServerLLGS::%s called with " - "NativeProcessProtocol pid %" PRIu64 ", state: %s", - __FUNCTION__, process->GetID(), StateAsCString(state)); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s called with " + "NativeProcessProtocol pid %" PRIu64 ", state: %s", + __FUNCTION__, process->GetID(), StateAsCString(state)); } switch (state) { @@ -868,9 +862,10 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged( default: if (log) { - log->Printf("GDBRemoteCommunicationServerLLGS::%s didn't handle state " - "change for pid %" PRIu64 ", new state: %s", - __FUNCTION__, process->GetID(), StateAsCString(state)); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s didn't handle state " + "change for pid %" PRIu64 ", new state: %s", + __FUNCTION__, process->GetID(), StateAsCString(state)); } break; } @@ -888,10 +883,10 @@ void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() { if (!m_handshake_completed) { if (!HandshakeWithClient()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s handshake with " - "client failed, exiting", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s handshake with " + "client failed, exiting", + __FUNCTION__); m_mainloop.RequestTermination(); return; } @@ -908,10 +903,10 @@ void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() { break; // No more packets in the queue if ((result != PacketResult::Success)) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s processing a packet " - "failed: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s processing a packet " + "failed: %s", + __FUNCTION__, error.AsCString()); m_mainloop.RequestTermination(); break; } @@ -982,9 +977,10 @@ void GDBRemoteCommunicationServerLLGS::StartSTDIOForwarding() { // Not much we can do about the failure. Log it and continue without // forwarding. if (Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)) - log->Printf("GDBRemoteCommunicationServerLLGS::%s Failed to set up stdio " - "forwarding: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s Failed to set up stdio " + "forwarding: %s", + __FUNCTION__, error.AsCString()); } } @@ -1008,10 +1004,11 @@ void GDBRemoteCommunicationServerLLGS::SendProcessOutput() { case eConnectionStatusError: case eConnectionStatusNoConnection: if (Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)) - log->Printf("GDBRemoteCommunicationServerLLGS::%s Stopping stdio " - "forwarding as communication returned status %d (error: " - "%s)", - __FUNCTION__, status, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s Stopping stdio " + "forwarding as communication returned status %d (error: " + "%s)", + __FUNCTION__, status, error.AsCString()); m_stdio_handle_up.reset(); return; @@ -1349,15 +1346,14 @@ GDBRemoteCommunicationServerLLGS::Handle_qGetWorkingDir( GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD)); - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); // Ensure we have a native process. if (!m_debugged_process_up) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process " - "shared pointer", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s no debugged process " + "shared pointer", + __FUNCTION__); return SendErrorResponse(0x36); } @@ -1430,8 +1426,7 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) { GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote &packet) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD)); - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); packet.SetFilePos(packet.GetFilePos() + ::strlen("c")); @@ -1445,10 +1440,10 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote &packet) { // Ensure we have a native process. if (!m_debugged_process_up) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process " - "shared pointer", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s no debugged process " + "shared pointer", + __FUNCTION__); return SendErrorResponse(0x36); } @@ -1480,17 +1475,16 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_vCont( StringExtractorGDBRemote &packet) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s handling vCont packet", - __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s handling vCont packet", + __FUNCTION__); packet.SetFilePos(::strlen("vCont")); if (packet.GetBytesLeft() == 0) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s missing action from " - "vCont package", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s missing action from " + "vCont package", + __FUNCTION__); return SendIllFormedResponse(packet, "Missing action from vCont package"); } @@ -1958,10 +1952,10 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) { const uint32_t reg_index = packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max()); if (reg_index == std::numeric_limits<uint32_t>::max()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, could not " - "parse register number from request \"%s\"", - __FUNCTION__, packet.GetStringRef().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, could not " + "parse register number from request \"%s\"", + __FUNCTION__, packet.GetStringRef().c_str()); return SendErrorResponse(0x15); } @@ -1978,20 +1972,19 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) { // Return the end of registers response if we've iterated one past the end of // the register set. if (reg_index >= reg_context.GetUserRegisterCount()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested " - "register %" PRIu32 " beyond register count %" PRIu32, - __FUNCTION__, reg_index, - reg_context.GetUserRegisterCount()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, requested " + "register %" PRIu32 " beyond register count %" PRIu32, + __FUNCTION__, reg_index, reg_context.GetUserRegisterCount()); return SendErrorResponse(0x15); } const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index); if (!reg_info) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested " - "register %" PRIu32 " returned NULL", - __FUNCTION__, reg_index); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, requested " + "register %" PRIu32 " returned NULL", + __FUNCTION__, reg_index); return SendErrorResponse(0x15); } @@ -2002,20 +1995,20 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) { RegisterValue reg_value; Status error = reg_context.ReadRegister(reg_info, reg_value); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, read of " - "requested register %" PRIu32 " (%s) failed: %s", - __FUNCTION__, reg_index, reg_info->name, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, read of " + "requested register %" PRIu32 " (%s) failed: %s", + __FUNCTION__, reg_index, reg_info->name, error.AsCString()); return SendErrorResponse(0x15); } const uint8_t *const data = reinterpret_cast<const uint8_t *>(reg_value.GetBytes()); if (!data) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to get data " - "bytes from requested register %" PRIu32, - __FUNCTION__, reg_index); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to get data " + "bytes from requested register %" PRIu32, + __FUNCTION__, reg_index); return SendErrorResponse(0x15); } @@ -2039,10 +2032,10 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) { const uint32_t reg_index = packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max()); if (reg_index == std::numeric_limits<uint32_t>::max()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, could not " - "parse register number from request \"%s\"", - __FUNCTION__, packet.GetStringRef().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, could not " + "parse register number from request \"%s\"", + __FUNCTION__, packet.GetStringRef().c_str()); return SendErrorResponse(0x29); } @@ -2058,10 +2051,10 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) { // Get the thread to use. NativeThreadProtocol *thread = GetThreadFromSuffix(packet); if (!thread) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, no thread " - "available (thread index 0)", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, no thread " + "available (thread index 0)", + __FUNCTION__); return SendErrorResponse(0x28); } @@ -2069,20 +2062,20 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) { NativeRegisterContext ®_context = thread->GetRegisterContext(); const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index); if (!reg_info) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested " - "register %" PRIu32 " returned NULL", - __FUNCTION__, reg_index); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, requested " + "register %" PRIu32 " returned NULL", + __FUNCTION__, reg_index); return SendErrorResponse(0x48); } // Return the end of registers response if we've iterated one past the end of // the register set. if (reg_index >= reg_context.GetUserRegisterCount()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, requested " - "register %" PRIu32 " beyond register count %" PRIu32, - __FUNCTION__, reg_index, reg_context.GetUserRegisterCount()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, requested " + "register %" PRIu32 " beyond register count %" PRIu32, + __FUNCTION__, reg_index, reg_context.GetUserRegisterCount()); return SendErrorResponse(0x47); } @@ -2101,10 +2094,10 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) { m_debugged_process_up->GetArchitecture().GetByteOrder()); Status error = reg_context.WriteRegister(reg_info, reg_value); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, write of " - "requested register %" PRIu32 " (%s) failed: %s", - __FUNCTION__, reg_index, reg_info->name, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, write of " + "requested register %" PRIu32 " (%s) failed: %s", + __FUNCTION__, reg_index, reg_info->name, error.AsCString()); return SendErrorResponse(0x32); } @@ -2118,20 +2111,20 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x15); } // Parse out which variant of $H is requested. packet.SetFilePos(strlen("H")); if (packet.GetBytesLeft() < 1) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, H command " - "missing {g,c} variant", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, H command " + "missing {g,c} variant", + __FUNCTION__); return SendIllFormedResponse(packet, "H command missing {g,c} variant"); } @@ -2144,10 +2137,10 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) { break; default: - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, invalid $H variant %c", - __FUNCTION__, h_variant); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, invalid $H variant %c", + __FUNCTION__, h_variant); return SendIllFormedResponse(packet, "H variant unsupported, should be c or g"); } @@ -2162,10 +2155,10 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) { if (tid != LLDB_INVALID_THREAD_ID && tid != 0) { NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid); if (!thread) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64 - " not found", - __FUNCTION__, tid); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64 + " not found", + __FUNCTION__, tid); return SendErrorResponse(0x15); } } @@ -2196,10 +2189,10 @@ GDBRemoteCommunicationServerLLGS::Handle_I(StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x15); } @@ -2257,10 +2250,10 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read( if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x15); } @@ -2284,10 +2277,10 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read( const uint64_t byte_count = packet.GetHexMaxU64(false, 0); if (byte_count == 0) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s nothing to read: " - "zero-length packet", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s nothing to read: " + "zero-length packet", + __FUNCTION__); return SendOKResponse(); } @@ -2301,20 +2294,20 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read( Status error = m_debugged_process_up->ReadMemoryWithoutTrap( read_addr, &buf[0], byte_count, bytes_read); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 - " mem 0x%" PRIx64 ": failed to read. Error: %s", - __FUNCTION__, m_debugged_process_up->GetID(), read_addr, - error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 + " mem 0x%" PRIx64 ": failed to read. Error: %s", + __FUNCTION__, m_debugged_process_up->GetID(), read_addr, + error.AsCString()); return SendErrorResponse(0x08); } if (bytes_read == 0) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 - " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes", - __FUNCTION__, m_debugged_process_up->GetID(), read_addr, - byte_count); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 + " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes", + __FUNCTION__, m_debugged_process_up->GetID(), read_addr, + byte_count); return SendErrorResponse(0x08); } @@ -2338,10 +2331,10 @@ GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) { if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x15); } @@ -2426,10 +2419,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfoSupported( // since we won't have a NativeProcessProtocol. if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x15); } @@ -2454,10 +2447,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo( // Ensure we have a process. if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x15); } @@ -2703,10 +2696,10 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) { // Ensure we have a process. if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x32); } @@ -2735,11 +2728,11 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) { actions.SetDefaultThreadActionIfNeeded(eStateStopped, 0); Status error = m_debugged_process_up->Resume(actions); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 - " tid %" PRIu64 " Resume() failed with error: %s", - __FUNCTION__, m_debugged_process_up->GetID(), tid, - error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 + " tid %" PRIu64 " Resume() failed with error: %s", + __FUNCTION__, m_debugged_process_up->GetID(), tid, + error.AsCString()); return SendErrorResponse(0x49); } @@ -2986,18 +2979,18 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttach( "vAttach failed to parse the process id"); // Attempt to attach. - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s attempting to attach to " - "pid %" PRIu64, - __FUNCTION__, pid); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s attempting to attach to " + "pid %" PRIu64, + __FUNCTION__, pid); Status error = AttachToProcess(pid); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to attach to " - "pid %" PRIu64 ": %s\n", - __FUNCTION__, pid, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to attach to " + "pid %" PRIu64 ": %s\n", + __FUNCTION__, pid, error.AsCString()); return SendErrorResponse(error); } @@ -3014,10 +3007,10 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) { // Fail if we don't have a current process. if (!m_debugged_process_up || (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) { - if (log) - log->Printf( - "GDBRemoteCommunicationServerLLGS::%s failed, no process available", - __FUNCTION__); + LLDB_LOGF( + log, + "GDBRemoteCommunicationServerLLGS::%s failed, no process available", + __FUNCTION__); return SendErrorResponse(0x15); } @@ -3041,11 +3034,10 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) { const Status error = m_debugged_process_up->Detach(); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to detach from " - "pid %" PRIu64 ": %s\n", - __FUNCTION__, m_debugged_process_up->GetID(), - error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to detach from " + "pid %" PRIu64 ": %s\n", + __FUNCTION__, m_debugged_process_up->GetID(), error.AsCString()); return SendErrorResponse(0x01); } @@ -3060,10 +3052,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qThreadStopInfo( packet.SetFilePos(strlen("qThreadStopInfo")); const lldb::tid_t tid = packet.GetHexMaxU32(false, LLDB_INVALID_THREAD_ID); if (tid == LLDB_INVALID_THREAD_ID) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, could not " - "parse thread id from request \"%s\"", - __FUNCTION__, packet.GetStringRef().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed, could not " + "parse thread id from request \"%s\"", + __FUNCTION__, packet.GetStringRef().c_str()); return SendErrorResponse(0x15); } return SendStopReplyPacketForThread(tid); @@ -3195,15 +3187,15 @@ void GDBRemoteCommunicationServerLLGS::MaybeCloseInferiorTerminalConnection() { connection->Disconnect(&error); if (error.Success()) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s disconnect process " - "terminal stdio - SUCCESS", - __FUNCTION__); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s disconnect process " + "terminal stdio - SUCCESS", + __FUNCTION__); } else { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s disconnect process " - "terminal stdio - FAIL: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s disconnect process " + "terminal stdio - FAIL: %s", + __FUNCTION__, error.AsCString()); } } } @@ -3233,11 +3225,11 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix( // Parse out the ';'. if (packet.GetBytesLeft() < 1 || packet.GetChar() != ';') { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s gdb-remote parse " - "error: expected ';' prior to start of thread suffix: packet " - "contents = '%s'", - __FUNCTION__, packet.GetStringRef().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse " + "error: expected ';' prior to start of thread suffix: packet " + "contents = '%s'", + __FUNCTION__, packet.GetStringRef().c_str()); return nullptr; } @@ -3246,11 +3238,11 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix( // Parse out thread: portion. if (strncmp(packet.Peek(), "thread:", strlen("thread:")) != 0) { - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s gdb-remote parse " - "error: expected 'thread:' but not found, packet contents = " - "'%s'", - __FUNCTION__, packet.GetStringRef().c_str()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse " + "error: expected 'thread:' but not found, packet contents = " + "'%s'", + __FUNCTION__, packet.GetStringRef().c_str()); return nullptr; } packet.SetFilePos(packet.GetFilePos() + strlen("thread:")); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp index 6deb75f2f02..eb6cc6e6b8f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp @@ -104,8 +104,8 @@ Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer( hostname = "127.0.0.1"; Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) - log->Printf("Launching debugserver with: %s:%u...", hostname.c_str(), port); + LLDB_LOGF(log, "Launching debugserver with: %s:%u...", hostname.c_str(), + port); // Do not run in a new session so that it can not linger after the platform // closes. @@ -161,9 +161,8 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer( // process... Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) - log->Printf("GDBRemoteCommunicationServerPlatform::%s() called", - __FUNCTION__); + LLDB_LOGF(log, "GDBRemoteCommunicationServerPlatform::%s() called", + __FUNCTION__); ConnectionFileDescriptor file_conn; std::string hostname; @@ -183,17 +182,17 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer( Status error = LaunchGDBServer(Args(), hostname, debugserver_pid, port, socket_name); if (error.Fail()) { - if (log) - log->Printf("GDBRemoteCommunicationServerPlatform::%s() debugserver " - "launch failed: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerPlatform::%s() debugserver " + "launch failed: %s", + __FUNCTION__, error.AsCString()); return SendErrorResponse(9); } - if (log) - log->Printf("GDBRemoteCommunicationServerPlatform::%s() debugserver " - "launched successfully as pid %" PRIu64, - __FUNCTION__, debugserver_pid); + LLDB_LOGF(log, + "GDBRemoteCommunicationServerPlatform::%s() debugserver " + "launched successfully as pid %" PRIu64, + __FUNCTION__, debugserver_pid); StreamGDBRemote response; response.Printf("pid:%" PRIu64 ";port:%u;", debugserver_pid, diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index a77e659a55f..2bd0234f63e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -206,11 +206,14 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info, } else { Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_THREAD | GDBR_LOG_PACKETS)); - if (log) - log->Printf ("error: GDBRemoteRegisterContext::ReadRegisterBytes tried to read the " - "entire register context at once, expected at least %" PRId64 " bytes " - "but only got %" PRId64 " bytes.", m_reg_data.GetByteSize(), - buffer_sp->GetByteSize()); + LLDB_LOGF( + log, + "error: GDBRemoteRegisterContext::ReadRegisterBytes tried " + "to read the " + "entire register context at once, expected at least %" PRId64 + " bytes " + "but only got %" PRId64 " bytes.", + m_reg_data.GetByteSize(), buffer_sp->GetByteSize()); } } return false; @@ -390,13 +393,15 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info, if (log->GetVerbose()) { StreamString strm; gdb_comm.DumpHistory(strm); - log->Printf("error: failed to get packet sequence mutex, not sending " - "write register for \"%s\":\n%s", - reg_info->name, strm.GetData()); + LLDB_LOGF(log, + "error: failed to get packet sequence mutex, not sending " + "write register for \"%s\":\n%s", + reg_info->name, strm.GetData()); } else - log->Printf("error: failed to get packet sequence mutex, not sending " - "write register for \"%s\"", - reg_info->name); + LLDB_LOGF(log, + "error: failed to get packet sequence mutex, not sending " + "write register for \"%s\"", + reg_info->name); } } } @@ -494,12 +499,14 @@ bool GDBRemoteRegisterContext::ReadAllRegisterValues( if (log->GetVerbose()) { StreamString strm; gdb_comm.DumpHistory(strm); - log->Printf("error: failed to get packet sequence mutex, not sending " - "read all registers:\n%s", - strm.GetData()); + LLDB_LOGF(log, + "error: failed to get packet sequence mutex, not sending " + "read all registers:\n%s", + strm.GetData()); } else - log->Printf("error: failed to get packet sequence mutex, not sending " - "read all registers"); + LLDB_LOGF(log, + "error: failed to get packet sequence mutex, not sending " + "read all registers"); } } @@ -667,12 +674,14 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues( if (log->GetVerbose()) { StreamString strm; gdb_comm.DumpHistory(strm); - log->Printf("error: failed to get packet sequence mutex, not sending " - "write all registers:\n%s", - strm.GetData()); + LLDB_LOGF(log, + "error: failed to get packet sequence mutex, not sending " + "write all registers:\n%s", + strm.GetData()); } else - log->Printf("error: failed to get packet sequence mutex, not sending " - "write all registers"); + LLDB_LOGF(log, + "error: failed to get packet sequence mutex, not sending " + "write all registers"); } } return false; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index a6fdd8dd070..ce2073a91f4 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -354,10 +354,10 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp, if (m_async_listener_sp->StartListeningForEvents( &m_async_broadcaster, async_event_mask) != async_event_mask) { - if (log) - log->Printf("ProcessGDBRemote::%s failed to listen for " - "m_async_broadcaster events", - __FUNCTION__); + LLDB_LOGF(log, + "ProcessGDBRemote::%s failed to listen for " + "m_async_broadcaster events", + __FUNCTION__); } const uint32_t gdb_event_mask = @@ -365,9 +365,9 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp, GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify; if (m_async_listener_sp->StartListeningForEvents( &m_gdb_comm, gdb_event_mask) != gdb_event_mask) { - if (log) - log->Printf("ProcessGDBRemote::%s failed to listen for m_gdb_comm events", - __FUNCTION__); + LLDB_LOGF(log, + "ProcessGDBRemote::%s failed to listen for m_gdb_comm events", + __FUNCTION__); } const uint64_t timeout_seconds = @@ -785,15 +785,15 @@ Status ProcessGDBRemote::DoConnectRemote(Stream *strm, pid, remote_url.str().c_str()); } - if (log) - log->Printf("ProcessGDBRemote::%s pid %" PRIu64 - ": normalizing target architecture initial triple: %s " - "(GetTarget().GetArchitecture().IsValid() %s, " - "m_gdb_comm.GetHostArchitecture().IsValid(): %s)", - __FUNCTION__, GetID(), - GetTarget().GetArchitecture().GetTriple().getTriple().c_str(), - GetTarget().GetArchitecture().IsValid() ? "true" : "false", - m_gdb_comm.GetHostArchitecture().IsValid() ? "true" : "false"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s pid %" PRIu64 + ": normalizing target architecture initial triple: %s " + "(GetTarget().GetArchitecture().IsValid() %s, " + "m_gdb_comm.GetHostArchitecture().IsValid(): %s)", + __FUNCTION__, GetID(), + GetTarget().GetArchitecture().GetTriple().getTriple().c_str(), + GetTarget().GetArchitecture().IsValid() ? "true" : "false", + m_gdb_comm.GetHostArchitecture().IsValid() ? "true" : "false"); if (error.Success() && !GetTarget().GetArchitecture().IsValid() && m_gdb_comm.GetHostArchitecture().IsValid()) { @@ -805,11 +805,11 @@ Status ProcessGDBRemote::DoConnectRemote(Stream *strm, GetTarget().SetArchitecture(m_gdb_comm.GetHostArchitecture()); } - if (log) - log->Printf("ProcessGDBRemote::%s pid %" PRIu64 - ": normalized target architecture triple: %s", - __FUNCTION__, GetID(), - GetTarget().GetArchitecture().GetTriple().getTriple().c_str()); + LLDB_LOGF(log, + "ProcessGDBRemote::%s pid %" PRIu64 + ": normalized target architecture triple: %s", + __FUNCTION__, GetID(), + GetTarget().GetArchitecture().GetTriple().getTriple().c_str()); if (error.Success()) { PlatformSP platform_sp = GetTarget().GetPlatform(); @@ -834,8 +834,7 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module, Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); Status error; - if (log) - log->Printf("ProcessGDBRemote::%s() entered", __FUNCTION__); + LLDB_LOGF(log, "ProcessGDBRemote::%s() entered", __FUNCTION__); uint32_t launch_flags = launch_info.GetFlags().Get(); FileSpec stdin_file_spec{}; @@ -862,15 +861,17 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module, if (log) { if (stdin_file_spec || stdout_file_spec || stderr_file_spec) - log->Printf("ProcessGDBRemote::%s provided with STDIO paths via " - "launch_info: stdin=%s, stdout=%s, stderr=%s", - __FUNCTION__, - stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", - stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", - stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s provided with STDIO paths via " + "launch_info: stdin=%s, stdout=%s, stderr=%s", + __FUNCTION__, + stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", + stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", + stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); else - log->Printf("ProcessGDBRemote::%s no STDIO paths given via launch_info", - __FUNCTION__); + LLDB_LOGF(log, + "ProcessGDBRemote::%s no STDIO paths given via launch_info", + __FUNCTION__); } const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0; @@ -925,24 +926,23 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module, if (!stderr_file_spec) stderr_file_spec = slave_name; } - if (log) - log->Printf( - "ProcessGDBRemote::%s adjusted STDIO paths for local platform " - "(IsHost() is true) using slave: stdin=%s, stdout=%s, stderr=%s", - __FUNCTION__, - stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", - stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", - stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); + LLDB_LOGF( + log, + "ProcessGDBRemote::%s adjusted STDIO paths for local platform " + "(IsHost() is true) using slave: stdin=%s, stdout=%s, stderr=%s", + __FUNCTION__, + stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", + stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", + stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); } - if (log) - log->Printf("ProcessGDBRemote::%s final STDIO paths after all " - "adjustments: stdin=%s, stdout=%s, stderr=%s", - __FUNCTION__, - stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", - stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", - stderr_file_spec ? stderr_file_spec.GetCString() - : "<null>"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s final STDIO paths after all " + "adjustments: stdin=%s, stdout=%s, stderr=%s", + __FUNCTION__, + stdin_file_spec ? stdin_file_spec.GetCString() : "<null>", + stdout_file_spec ? stdout_file_spec.GetCString() : "<null>", + stderr_file_spec ? stderr_file_spec.GetCString() : "<null>"); if (stdin_file_spec) m_gdb_comm.SetSTDIN(stdin_file_spec); @@ -988,9 +988,8 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module, } if (GetID() == LLDB_INVALID_PROCESS_ID) { - if (log) - log->Printf("failed to connect to debugserver: %s", - error.AsCString()); + LLDB_LOGF(log, "failed to connect to debugserver: %s", + error.AsCString()); KillDebugserverProcess(); return error; } @@ -1020,8 +1019,7 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module, } } } else { - if (log) - log->Printf("failed to connect to debugserver: %s", error.AsCString()); + LLDB_LOGF(log, "failed to connect to debugserver: %s", error.AsCString()); } } else { // Set our user ID to an invalid process ID. @@ -1040,9 +1038,8 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); if (!connect_url.empty()) { - if (log) - log->Printf("ProcessGDBRemote::%s Connecting to %s", __FUNCTION__, - connect_url.str().c_str()); + LLDB_LOGF(log, "ProcessGDBRemote::%s Connecting to %s", __FUNCTION__, + connect_url.str().c_str()); std::unique_ptr<ConnectionFileDescriptor> conn_up( new ConnectionFileDescriptor()); if (conn_up) { @@ -1116,8 +1113,7 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) { void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::%s()", __FUNCTION__); + LLDB_LOGF(log, "ProcessGDBRemote::%s()", __FUNCTION__); if (GetID() != LLDB_INVALID_PROCESS_ID) { BuildDynamicRegisterInfo(false); @@ -1130,43 +1126,42 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) { const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture(); if (remote_process_arch.IsValid()) { process_arch = remote_process_arch; - if (log) - log->Printf("ProcessGDBRemote::%s gdb-remote had process architecture, " - "using %s %s", - __FUNCTION__, - process_arch.GetArchitectureName() - ? process_arch.GetArchitectureName() - : "<null>", - process_arch.GetTriple().getTriple().c_str() - ? process_arch.GetTriple().getTriple().c_str() - : "<null>"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s gdb-remote had process architecture, " + "using %s %s", + __FUNCTION__, + process_arch.GetArchitectureName() + ? process_arch.GetArchitectureName() + : "<null>", + process_arch.GetTriple().getTriple().c_str() + ? process_arch.GetTriple().getTriple().c_str() + : "<null>"); } else { process_arch = m_gdb_comm.GetHostArchitecture(); - if (log) - log->Printf("ProcessGDBRemote::%s gdb-remote did not have process " - "architecture, using gdb-remote host architecture %s %s", - __FUNCTION__, - process_arch.GetArchitectureName() - ? process_arch.GetArchitectureName() - : "<null>", - process_arch.GetTriple().getTriple().c_str() - ? process_arch.GetTriple().getTriple().c_str() - : "<null>"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s gdb-remote did not have process " + "architecture, using gdb-remote host architecture %s %s", + __FUNCTION__, + process_arch.GetArchitectureName() + ? process_arch.GetArchitectureName() + : "<null>", + process_arch.GetTriple().getTriple().c_str() + ? process_arch.GetTriple().getTriple().c_str() + : "<null>"); } if (process_arch.IsValid()) { const ArchSpec &target_arch = GetTarget().GetArchitecture(); if (target_arch.IsValid()) { - if (log) - log->Printf( - "ProcessGDBRemote::%s analyzing target arch, currently %s %s", - __FUNCTION__, - target_arch.GetArchitectureName() - ? target_arch.GetArchitectureName() - : "<null>", - target_arch.GetTriple().getTriple().c_str() - ? target_arch.GetTriple().getTriple().c_str() - : "<null>"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s analyzing target arch, currently %s %s", + __FUNCTION__, + target_arch.GetArchitectureName() + ? target_arch.GetArchitectureName() + : "<null>", + target_arch.GetTriple().getTriple().c_str() + ? target_arch.GetTriple().getTriple().c_str() + : "<null>"); // If the remote host is ARM and we have apple as the vendor, then // ARM executables and shared libraries can have mixed ARM @@ -1180,16 +1175,16 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) { process_arch.GetMachine() == llvm::Triple::thumb) && process_arch.GetTriple().getVendor() == llvm::Triple::Apple) { GetTarget().SetArchitecture(process_arch); - if (log) - log->Printf("ProcessGDBRemote::%s remote process is ARM/Apple, " - "setting target arch to %s %s", - __FUNCTION__, - process_arch.GetArchitectureName() - ? process_arch.GetArchitectureName() - : "<null>", - process_arch.GetTriple().getTriple().c_str() - ? process_arch.GetTriple().getTriple().c_str() - : "<null>"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s remote process is ARM/Apple, " + "setting target arch to %s %s", + __FUNCTION__, + process_arch.GetArchitectureName() + ? process_arch.GetArchitectureName() + : "<null>", + process_arch.GetTriple().getTriple().c_str() + ? process_arch.GetTriple().getTriple().c_str() + : "<null>"); } else { // Fill in what is missing in the triple const llvm::Triple &remote_triple = process_arch.GetTriple(); @@ -1211,16 +1206,16 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) { } } - if (log) - log->Printf("ProcessGDBRemote::%s final target arch after " - "adjustments for remote architecture: %s %s", - __FUNCTION__, - target_arch.GetArchitectureName() - ? target_arch.GetArchitectureName() - : "<null>", - target_arch.GetTriple().getTriple().c_str() - ? target_arch.GetTriple().getTriple().c_str() - : "<null>"); + LLDB_LOGF(log, + "ProcessGDBRemote::%s final target arch after " + "adjustments for remote architecture: %s %s", + __FUNCTION__, + target_arch.GetArchitectureName() + ? target_arch.GetArchitectureName() + : "<null>", + target_arch.GetTriple().getTriple().c_str() + ? target_arch.GetTriple().getTriple().c_str() + : "<null>"); } else { // The target doesn't have a valid architecture yet, set it from the // architecture we got from the remote GDB server @@ -1247,8 +1242,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithID( Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); Status error; - if (log) - log->Printf("ProcessGDBRemote::%s()", __FUNCTION__); + LLDB_LOGF(log, "ProcessGDBRemote::%s()", __FUNCTION__); // Clear out and clean up from any current state Clear(); @@ -1359,8 +1353,7 @@ Status ProcessGDBRemote::WillResume() { Status ProcessGDBRemote::DoResume() { Status error; Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::Resume()"); + LLDB_LOGF(log, "ProcessGDBRemote::Resume()"); ListenerSP listener_sp( Listener::MakeListener("gdb-remote.resume-packet-sent")); @@ -1547,9 +1540,8 @@ Status ProcessGDBRemote::DoResume() { EventSP event_sp; if (!m_async_thread.IsJoinable()) { error.SetErrorString("Trying to resume but the async thread is dead."); - if (log) - log->Printf("ProcessGDBRemote::DoResume: Trying to resume but the " - "async thread is dead."); + LLDB_LOGF(log, "ProcessGDBRemote::DoResume: Trying to resume but the " + "async thread is dead."); return error; } @@ -1560,14 +1552,13 @@ Status ProcessGDBRemote::DoResume() { if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) { error.SetErrorString("Resume timed out."); - if (log) - log->Printf("ProcessGDBRemote::DoResume: Resume timed out."); + LLDB_LOGF(log, "ProcessGDBRemote::DoResume: Resume timed out."); } else if (event_sp->BroadcasterIs(&m_async_broadcaster)) { error.SetErrorString("Broadcast continue, but the async thread was " "killed before we got an ack back."); - if (log) - log->Printf("ProcessGDBRemote::DoResume: Broadcast continue, but the " - "async thread was killed before we got an ack back."); + LLDB_LOGF(log, + "ProcessGDBRemote::DoResume: Broadcast continue, but the " + "async thread was killed before we got an ack back."); return error; } } @@ -1979,8 +1970,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo( if (watch_id == LLDB_INVALID_WATCH_ID) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet( GDBR_LOG_WATCHPOINTS)); - if (log) - log->Printf("failed to find watchpoint"); + LLDB_LOGF(log, "failed to find watchpoint"); } thread_sp->SetStopInfo(StopInfo::CreateStopReasonWithWatchpointID( *thread_sp, watch_id, wp_hit_addr)); @@ -2501,8 +2491,7 @@ Status ProcessGDBRemote::DoHalt(bool &caused_stop) { Status ProcessGDBRemote::DoDetach(bool keep_stopped) { Status error; Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped); + LLDB_LOGF(log, "ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped); error = m_gdb_comm.Detach(keep_stopped); if (log) { @@ -2510,8 +2499,9 @@ Status ProcessGDBRemote::DoDetach(bool keep_stopped) { log->PutCString( "ProcessGDBRemote::DoDetach() detach packet sent successfully"); else - log->Printf("ProcessGDBRemote::DoDetach() detach packet send failed: %s", - error.AsCString() ? error.AsCString() : "<unknown error>"); + LLDB_LOGF(log, + "ProcessGDBRemote::DoDetach() detach packet send failed: %s", + error.AsCString() ? error.AsCString() : "<unknown error>"); } if (!error.Success()) @@ -2530,8 +2520,7 @@ Status ProcessGDBRemote::DoDetach(bool keep_stopped) { Status ProcessGDBRemote::DoDestroy() { Status error; Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::DoDestroy()"); + LLDB_LOGF(log, "ProcessGDBRemote::DoDestroy()"); // There is a bug in older iOS debugservers where they don't shut down the // process they are debugging properly. If the process is sitting at a @@ -2586,11 +2575,11 @@ Status ProcessGDBRemote::DoDestroy() { reason = stop_info_sp->GetStopReason(); if (reason == eStopReasonBreakpoint || reason == eStopReasonException) { - if (log) - log->Printf( - "ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64 - " stopped with reason: %s.", - thread_sp->GetProtocolID(), stop_info_sp->GetDescription()); + LLDB_LOGF(log, + "ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64 + " stopped with reason: %s.", + thread_sp->GetProtocolID(), + stop_info_sp->GetDescription()); stop_looks_like_crash = true; break; } @@ -2622,10 +2611,10 @@ Status ProcessGDBRemote::DoDestroy() { reason = stop_info_sp->GetStopReason(); if (reason != eStopReasonBreakpoint && reason != eStopReasonException) { - if (log) - log->Printf("ProcessGDBRemote::DoDestroy() - Suspending " - "thread: 0x%4.4" PRIx64 " before running.", - thread_sp->GetProtocolID()); + LLDB_LOGF(log, + "ProcessGDBRemote::DoDestroy() - Suspending " + "thread: 0x%4.4" PRIx64 " before running.", + thread_sp->GetProtocolID()); thread_sp->SetResumeState(eStateSuspended); } } @@ -2669,30 +2658,28 @@ Status ProcessGDBRemote::DoDestroy() { int status; ::pid_t reap_pid; reap_pid = waitpid(GetID(), &status, WNOHANG); - if (log) - log->Printf("Reaped pid: %d, status: %d.\n", reap_pid, status); + LLDB_LOGF(log, "Reaped pid: %d, status: %d.\n", reap_pid, status); } #endif SetLastStopPacket(response); ClearThreadIDList(); exit_status = response.GetHexU8(); } else { - if (log) - log->Printf("ProcessGDBRemote::DoDestroy - got unexpected response " - "to k packet: %s", - response.GetStringRef().c_str()); + LLDB_LOGF(log, + "ProcessGDBRemote::DoDestroy - got unexpected response " + "to k packet: %s", + response.GetStringRef().c_str()); exit_string.assign("got unexpected response to k packet: "); exit_string.append(response.GetStringRef()); } } else { - if (log) - log->Printf("ProcessGDBRemote::DoDestroy - failed to send k packet"); + LLDB_LOGF(log, "ProcessGDBRemote::DoDestroy - failed to send k packet"); exit_string.assign("failed to send the k packet"); } } else { - if (log) - log->Printf("ProcessGDBRemote::DoDestroy - killed or interrupted while " - "attaching"); + LLDB_LOGF(log, + "ProcessGDBRemote::DoDestroy - killed or interrupted while " + "attaching"); exit_string.assign("killed or interrupted while attaching."); } } else { @@ -2715,8 +2702,7 @@ void ProcessGDBRemote::SetLastStopPacket( response.GetStringRef().find(";reason:exec;") != std::string::npos; if (did_exec) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::SetLastStopPacket () - detected exec"); + LLDB_LOGF(log, "ProcessGDBRemote::SetLastStopPacket () - detected exec"); m_thread_list_real.Clear(); m_thread_list.Clear(); @@ -3078,11 +3064,11 @@ lldb::addr_t ProcessGDBRemote::DoAllocateMemory(size_t size, m_addr_to_mmap_size[allocated_addr] = size; else { allocated_addr = LLDB_INVALID_ADDRESS; - if (log) - log->Printf("ProcessGDBRemote::%s no direct stub support for memory " - "allocation, and InferiorCallMmap also failed - is stub " - "missing register context save/restore capability?", - __FUNCTION__); + LLDB_LOGF(log, + "ProcessGDBRemote::%s no direct stub support for memory " + "allocation, and InferiorCallMmap also failed - is stub " + "missing register context save/restore capability?", + __FUNCTION__); } } @@ -3173,17 +3159,17 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) { const addr_t addr = bp_site->GetLoadAddress(); // Log that a breakpoint was requested - if (log) - log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64 - ") address = 0x%" PRIx64, - site_id, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64 + ") address = 0x%" PRIx64, + site_id, (uint64_t)addr); // Breakpoint already exists and is enabled if (bp_site->IsEnabled()) { - if (log) - log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64 - ") address = 0x%" PRIx64 " -- SUCCESS (already enabled)", - site_id, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64 + ") address = 0x%" PRIx64 " -- SUCCESS (already enabled)", + site_id, (uint64_t)addr); return error; } @@ -3231,8 +3217,7 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) { // We reach here when software breakpoints have been found to be // unsupported. For future calls to set a breakpoint, we will not attempt // to set a breakpoint with a type that is known not to be supported. - if (log) - log->Printf("Software breakpoints are unsupported"); + LLDB_LOGF(log, "Software breakpoints are unsupported"); // So we will fall through and try a hardware breakpoint } @@ -3270,8 +3255,7 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) { // We will reach here when the stub gives an unsupported response to a // hardware breakpoint - if (log) - log->Printf("Hardware breakpoints are unsupported"); + LLDB_LOGF(log, "Hardware breakpoints are unsupported"); // Finally we will falling through to a #trap style breakpoint } @@ -3293,10 +3277,10 @@ Status ProcessGDBRemote::DisableBreakpointSite(BreakpointSite *bp_site) { addr_t addr = bp_site->GetLoadAddress(); user_id_t site_id = bp_site->GetID(); Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS)); - if (log) - log->Printf("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64 - ") addr = 0x%8.8" PRIx64, - site_id, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64 + ") addr = 0x%8.8" PRIx64, + site_id, (uint64_t)addr); if (bp_site->IsEnabled()) { const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode(bp_site); @@ -3328,10 +3312,10 @@ Status ProcessGDBRemote::DisableBreakpointSite(BreakpointSite *bp_site) { if (error.Success()) bp_site->SetEnabled(false); } else { - if (log) - log->Printf("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64 - ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)", - site_id, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64 + ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)", + site_id, (uint64_t)addr); return error; } @@ -3363,14 +3347,13 @@ Status ProcessGDBRemote::EnableWatchpoint(Watchpoint *wp, bool notify) { addr_t addr = wp->GetLoadAddress(); Log *log( ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS)); - if (log) - log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")", - watchID); + LLDB_LOGF(log, "ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")", + watchID); if (wp->IsEnabled()) { - if (log) - log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 - ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.", - watchID, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 + ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.", + watchID, (uint64_t)addr); return error; } @@ -3403,16 +3386,16 @@ Status ProcessGDBRemote::DisableWatchpoint(Watchpoint *wp, bool notify) { addr_t addr = wp->GetLoadAddress(); - if (log) - log->Printf("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64 - ") addr = 0x%8.8" PRIx64, - watchID, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64 + ") addr = 0x%8.8" PRIx64, + watchID, (uint64_t)addr); if (!wp->IsEnabled()) { - if (log) - log->Printf("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64 - ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)", - watchID, (uint64_t)addr); + LLDB_LOGF(log, + "ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64 + ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)", + watchID, (uint64_t)addr); // See also 'class WatchpointSentry' within StopInfo.cpp. This disabling // attempt might come from the user-supplied actions, we'll route it in // order for the watchpoint object to intelligently process this action. @@ -3447,8 +3430,7 @@ void ProcessGDBRemote::Clear() { Status ProcessGDBRemote::DoSignal(int signo) { Status error; Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::DoSignal (signal = %d)", signo); + LLDB_LOGF(log, "ProcessGDBRemote::DoSignal (signal = %d)", signo); if (!m_gdb_comm.SendAsyncSignal(signo)) error.SetErrorStringWithFormat("failed to send signal %i", signo); @@ -3586,9 +3568,8 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver( if (error.Fail()) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("failed to start debugserver process: %s", - error.AsCString()); + LLDB_LOGF(log, "failed to start debugserver process: %s", + error.AsCString()); return error; } @@ -3614,15 +3595,14 @@ bool ProcessGDBRemote::MonitorDebugserverProcess( Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); const bool handled = true; - if (log) - log->Printf("ProcessGDBRemote::%s(process_wp, pid=%" PRIu64 - ", signo=%i (0x%x), exit_status=%i)", - __FUNCTION__, debugserver_pid, signo, signo, exit_status); + LLDB_LOGF(log, + "ProcessGDBRemote::%s(process_wp, pid=%" PRIu64 + ", signo=%i (0x%x), exit_status=%i)", + __FUNCTION__, debugserver_pid, signo, signo, exit_status); std::shared_ptr<ProcessGDBRemote> process_sp = process_wp.lock(); - if (log) - log->Printf("ProcessGDBRemote::%s(process = %p)", __FUNCTION__, - static_cast<void *>(process_sp.get())); + LLDB_LOGF(log, "ProcessGDBRemote::%s(process = %p)", __FUNCTION__, + static_cast<void *>(process_sp.get())); if (!process_sp || process_sp->m_debugserver_pid != debugserver_pid) return handled; @@ -3692,8 +3672,7 @@ void ProcessGDBRemote::DebuggerInitialize(Debugger &debugger) { bool ProcessGDBRemote::StartAsyncThread() { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::%s ()", __FUNCTION__); + LLDB_LOGF(log, "ProcessGDBRemote::%s ()", __FUNCTION__); std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex); if (!m_async_thread.IsJoinable()) { @@ -3709,10 +3688,11 @@ bool ProcessGDBRemote::StartAsyncThread() { return false; } m_async_thread = *async_thread; - } else if (log) - log->Printf("ProcessGDBRemote::%s () - Called when Async thread was " - "already running.", - __FUNCTION__); + } else + LLDB_LOGF(log, + "ProcessGDBRemote::%s () - Called when Async thread was " + "already running.", + __FUNCTION__); return m_async_thread.IsJoinable(); } @@ -3720,8 +3700,7 @@ bool ProcessGDBRemote::StartAsyncThread() { void ProcessGDBRemote::StopAsyncThread() { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::%s ()", __FUNCTION__); + LLDB_LOGF(log, "ProcessGDBRemote::%s ()", __FUNCTION__); std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex); if (m_async_thread.IsJoinable()) { @@ -3733,8 +3712,9 @@ void ProcessGDBRemote::StopAsyncThread() { // Stop the stdio thread m_async_thread.Join(nullptr); m_async_thread.Reset(); - } else if (log) - log->Printf( + } else + LLDB_LOGF( + log, "ProcessGDBRemote::%s () - Called when Async thread was not running.", __FUNCTION__); } @@ -3768,25 +3748,25 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) { ProcessGDBRemote *process = (ProcessGDBRemote *)arg; Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") thread starting...", - __FUNCTION__, arg, process->GetID()); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") thread starting...", + __FUNCTION__, arg, process->GetID()); EventSP event_sp; bool done = false; while (!done) { - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") listener.WaitForEvent (NULL, event_sp)...", - __FUNCTION__, arg, process->GetID()); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") listener.WaitForEvent (NULL, event_sp)...", + __FUNCTION__, arg, process->GetID()); if (process->m_async_listener_sp->GetEvent(event_sp, llvm::None)) { const uint32_t event_type = event_sp->GetType(); if (event_sp->BroadcasterIs(&process->m_async_broadcaster)) { - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") Got an event of type: %d...", - __FUNCTION__, arg, process->GetID(), event_type); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") Got an event of type: %d...", + __FUNCTION__, arg, process->GetID(), event_type); switch (event_type) { case eBroadcastBitAsyncContinue: { @@ -3797,10 +3777,10 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) { const char *continue_cstr = (const char *)continue_packet->GetBytes(); const size_t continue_cstr_len = continue_packet->GetByteSize(); - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") got eBroadcastBitAsyncContinue: %s", - __FUNCTION__, arg, process->GetID(), continue_cstr); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") got eBroadcastBitAsyncContinue: %s", + __FUNCTION__, arg, process->GetID(), continue_cstr); if (::strstr(continue_cstr, "vAttach") == nullptr) process->SetPrivateState(eStateRunning); @@ -3891,18 +3871,18 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) { break; case eBroadcastBitAsyncThreadShouldExit: - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") got eBroadcastBitAsyncThreadShouldExit...", - __FUNCTION__, arg, process->GetID()); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") got eBroadcastBitAsyncThreadShouldExit...", + __FUNCTION__, arg, process->GetID()); done = true; break; default: - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") got unknown event 0x%8.8x", - __FUNCTION__, arg, process->GetID(), event_type); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") got unknown event 0x%8.8x", + __FUNCTION__, arg, process->GetID(), event_type); done = true; break; } @@ -3925,27 +3905,27 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) { } default: - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") got unknown event 0x%8.8x", - __FUNCTION__, arg, process->GetID(), event_type); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") got unknown event 0x%8.8x", + __FUNCTION__, arg, process->GetID(), event_type); done = true; break; } } } else { - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") listener.WaitForEvent (NULL, event_sp) => false", - __FUNCTION__, arg, process->GetID()); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") listener.WaitForEvent (NULL, event_sp) => false", + __FUNCTION__, arg, process->GetID()); done = true; } } - if (log) - log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 - ") thread exiting...", - __FUNCTION__, arg, process->GetID()); + LLDB_LOGF(log, + "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 + ") thread exiting...", + __FUNCTION__, arg, process->GetID()); return {}; } @@ -3977,8 +3957,7 @@ bool ProcessGDBRemote::NewThreadNotifyBreakpointHit( // thread when it starts to // run so I can stop it if that's what I want to do. Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); - if (log) - log->Printf("Hit New Thread Notification breakpoint."); + LLDB_LOGF(log, "Hit New Thread Notification breakpoint."); return false; } @@ -4023,7 +4002,7 @@ bool ProcessGDBRemote::StartNoticingNewThreads() { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); if (m_thread_create_bp_sp) { if (log && log->GetVerbose()) - log->Printf("Enabled noticing new thread breakpoint."); + LLDB_LOGF(log, "Enabled noticing new thread breakpoint."); m_thread_create_bp_sp->SetEnabled(true); } else { PlatformSP platform_sp(GetTarget().GetPlatform()); @@ -4032,14 +4011,13 @@ bool ProcessGDBRemote::StartNoticingNewThreads() { platform_sp->SetThreadCreationBreakpoint(GetTarget()); if (m_thread_create_bp_sp) { if (log && log->GetVerbose()) - log->Printf( - "Successfully created new thread notification breakpoint %i", + LLDB_LOGF( + log, "Successfully created new thread notification breakpoint %i", m_thread_create_bp_sp->GetID()); m_thread_create_bp_sp->SetCallback( ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true); } else { - if (log) - log->Printf("Failed to create new thread notification breakpoint."); + LLDB_LOGF(log, "Failed to create new thread notification breakpoint."); } } } @@ -4049,7 +4027,7 @@ bool ProcessGDBRemote::StartNoticingNewThreads() { bool ProcessGDBRemote::StopNoticingNewThreads() { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); if (log && log->GetVerbose()) - log->Printf("Disabling new thread notification breakpoint."); + LLDB_LOGF(log, "Disabling new thread notification breakpoint."); if (m_thread_create_bp_sp) m_thread_create_bp_sp->SetEnabled(false); @@ -4325,19 +4303,18 @@ bool ProcessGDBRemote::GetModuleSpec(const FileSpec &module_file_spec, } if (!m_gdb_comm.GetModuleInfo(module_file_spec, arch, module_spec)) { - if (log) - log->Printf("ProcessGDBRemote::%s - failed to get module info for %s:%s", - __FUNCTION__, module_file_spec.GetPath().c_str(), - arch.GetTriple().getTriple().c_str()); + LLDB_LOGF(log, "ProcessGDBRemote::%s - failed to get module info for %s:%s", + __FUNCTION__, module_file_spec.GetPath().c_str(), + arch.GetTriple().getTriple().c_str()); return false; } if (log) { StreamString stream; module_spec.Dump(stream); - log->Printf("ProcessGDBRemote::%s - got module info for (%s:%s) : %s", - __FUNCTION__, module_file_spec.GetPath().c_str(), - arch.GetTriple().getTriple().c_str(), stream.GetData()); + LLDB_LOGF(log, "ProcessGDBRemote::%s - got module info for (%s:%s) : %s", + __FUNCTION__, module_file_spec.GetPath().c_str(), + arch.GetTriple().getTriple().c_str(), stream.GetData()); } m_cached_module_specs[key] = module_spec; @@ -4711,8 +4688,7 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) { return Status(0, ErrorType::eErrorTypeGeneric); Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS); - if (log) - log->Printf("ProcessGDBRemote::%s", __FUNCTION__); + LLDB_LOGF(log, "ProcessGDBRemote::%s", __FUNCTION__); GDBRemoteCommunicationClient &comm = m_gdb_comm; bool can_use_svr4 = GetGlobalPluginProperties()->GetUseSVR4(); @@ -4730,8 +4706,7 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) { return Status(0, ErrorType::eErrorTypeGeneric); // parse the xml file in memory - if (log) - log->Printf("parsing: %s", raw.c_str()); + LLDB_LOGF(log, "parsing: %s", raw.c_str()); XMLDocument doc; if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml")) @@ -4791,10 +4766,11 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) { module.get_base_is_offset(base_is_offset); module.get_dynamic(ld); - log->Printf("found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64 - "[%s], ld:0x%08" PRIx64 ", name:'%s')", - lm, base, (base_is_offset ? "offset" : "absolute"), ld, - name.c_str()); + LLDB_LOGF(log, + "found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64 + "[%s], ld:0x%08" PRIx64 ", name:'%s')", + lm, base, (base_is_offset ? "offset" : "absolute"), ld, + name.c_str()); } list.add(module); @@ -4802,9 +4778,8 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) { // node }); - if (log) - log->Printf("found %" PRId32 " modules in total", - (int)list.m_list.size()); + LLDB_LOGF(log, "found %" PRId32 " modules in total", + (int)list.m_list.size()); } else if (comm.GetQXferLibrariesReadSupported()) { list.clear(); @@ -4816,8 +4791,7 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) { lldberr)) return Status(0, ErrorType::eErrorTypeGeneric); - if (log) - log->Printf("parsing: %s", raw.c_str()); + LLDB_LOGF(log, "parsing: %s", raw.c_str()); XMLDocument doc; if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml")) @@ -4853,8 +4827,8 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) { module.get_base(base); module.get_base_is_offset(base_is_offset); - log->Printf("found (base:0x%08" PRIx64 "[%s], name:'%s')", base, - (base_is_offset ? "offset" : "absolute"), name.c_str()); + LLDB_LOGF(log, "found (base:0x%08" PRIx64 "[%s], name:'%s')", base, + (base_is_offset ? "offset" : "absolute"), name.c_str()); } list.add(module); @@ -4862,9 +4836,8 @@ Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) { // node }); - if (log) - log->Printf("found %" PRId32 " modules in total", - (int)list.m_list.size()); + LLDB_LOGF(log, "found %" PRId32 " modules in total", + (int)list.m_list.size()); } else { return Status(0, ErrorType::eErrorTypeGeneric); } @@ -5149,7 +5122,8 @@ ParseStructuredDataPacket(llvm::StringRef packet) { if (!packet.consume_front(s_async_json_packet_prefix)) { if (log) { - log->Printf( + LLDB_LOGF( + log, "GDBRemoteCommunicationClientBase::%s() received $J packet " "but was not a StructuredData packet: packet starts with " "%s", @@ -5166,14 +5140,16 @@ ParseStructuredDataPacket(llvm::StringRef packet) { StreamString json_str; json_sp->Dump(json_str); json_str.Flush(); - log->Printf("ProcessGDBRemote::%s() " - "received Async StructuredData packet: %s", - __FUNCTION__, json_str.GetData()); + LLDB_LOGF(log, + "ProcessGDBRemote::%s() " + "received Async StructuredData packet: %s", + __FUNCTION__, json_str.GetData()); } else { - log->Printf("ProcessGDBRemote::%s" - "() received StructuredData packet:" - " parse failure", - __FUNCTION__); + LLDB_LOGF(log, + "ProcessGDBRemote::%s" + "() received StructuredData packet:" + " parse failure", + __FUNCTION__); } } return json_sp; diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp index 6607bce4488..8a6a58c5545 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp @@ -215,8 +215,7 @@ StructuredData::ObjectSP ThreadGDBRemote::FetchThreadExtendedInfo() { StructuredData::ObjectSP object_sp; const lldb::user_id_t tid = GetProtocolID(); Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD)); - if (log) - log->Printf("Fetching extended information for thread %4.4" PRIx64, tid); + LLDB_LOGF(log, "Fetching extended information for thread %4.4" PRIx64, tid); ProcessSP process_sp(GetProcess()); if (process_sp) { ProcessGDBRemote *gdb_process = @@ -230,9 +229,8 @@ void ThreadGDBRemote::WillResume(StateType resume_state) { int signo = GetResumeSignal(); const lldb::user_id_t tid = GetProtocolID(); Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD)); - if (log) - log->Printf("Resuming thread: %4.4" PRIx64 " with state: %s.", tid, - StateAsCString(resume_state)); + LLDB_LOGF(log, "Resuming thread: %4.4" PRIx64 " with state: %s.", tid, + StateAsCString(resume_state)); ProcessSP process_sp(GetProcess()); if (process_sp) { diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp index 53101ab9fe5..888044218a4 100644 --- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp +++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp @@ -160,10 +160,10 @@ bool ProcessMachCore::GetDynamicLoaderAddress(lldb::addr_t addr) { case llvm::MachO::MH_DYLINKER: // printf("0x%16.16" PRIx64 ": file_type = MH_DYLINKER\n", vaddr); // Address of dyld "struct mach_header" in the core file - if (log) - log->Printf("ProcessMachCore::GetDynamicLoaderAddress found a user " - "process dyld binary image at 0x%" PRIx64, - addr); + LLDB_LOGF(log, + "ProcessMachCore::GetDynamicLoaderAddress found a user " + "process dyld binary image at 0x%" PRIx64, + addr); m_dyld_addr = addr; return true; @@ -172,10 +172,10 @@ bool ProcessMachCore::GetDynamicLoaderAddress(lldb::addr_t addr) { // Check MH_EXECUTABLE file types to see if the dynamic link object flag // is NOT set. If it isn't, then we have a mach_kernel. if ((header.flags & llvm::MachO::MH_DYLDLINK) == 0) { - if (log) - log->Printf("ProcessMachCore::GetDynamicLoaderAddress found a mach " - "kernel binary image at 0x%" PRIx64, - addr); + LLDB_LOGF(log, + "ProcessMachCore::GetDynamicLoaderAddress found a mach " + "kernel binary image at 0x%" PRIx64, + addr); // Address of the mach kernel "struct mach_header" in the core file. m_mach_kernel_addr = addr; return true; @@ -286,9 +286,10 @@ Status ProcessMachCore::DoLoadCore() { { m_mach_kernel_addr = objfile_binary_addr; found_main_binary_definitively = true; - if (log) - log->Printf ("ProcessMachCore::DoLoadCore: using kernel address 0x%" PRIx64 - " from LC_NOTE 'main bin spec' load command.", m_mach_kernel_addr); + LLDB_LOGF(log, + "ProcessMachCore::DoLoadCore: using kernel address 0x%" PRIx64 + " from LC_NOTE 'main bin spec' load command.", + m_mach_kernel_addr); } } @@ -317,11 +318,11 @@ Status ProcessMachCore::DoLoadCore() { if (uuid.IsValid() && addr != LLDB_INVALID_ADDRESS) { m_mach_kernel_addr = addr; found_main_binary_definitively = true; - if (log) - log->Printf( - "ProcessMachCore::DoLoadCore: Using the kernel address 0x%" PRIx64 - " from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'", - addr, corefile_identifier.c_str()); + LLDB_LOGF( + log, + "ProcessMachCore::DoLoadCore: Using the kernel address 0x%" PRIx64 + " from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'", + addr, corefile_identifier.c_str()); } } if (found_main_binary_definitively == false @@ -333,10 +334,10 @@ Status ProcessMachCore::DoLoadCore() { uuid.SetFromStringRef(uuid_str); } if (uuid.IsValid()) { - if (log) - log->Printf("ProcessMachCore::DoLoadCore: Using the EFI " - "from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'", - corefile_identifier.c_str()); + LLDB_LOGF(log, + "ProcessMachCore::DoLoadCore: Using the EFI " + "from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'", + corefile_identifier.c_str()); // We're only given a UUID here, not a load address. // But there are python scripts in the EFI binary's dSYM which @@ -432,9 +433,8 @@ Status ProcessMachCore::DoLoadCore() { m_dyld_addr = saved_user_dyld_addr; if (better_kernel_address != LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("ProcessMachCore::DoLoadCore: Using the kernel address " - "from DynamicLoaderDarwinKernel"); + LLDB_LOGF(log, "ProcessMachCore::DoLoadCore: Using the kernel address " + "from DynamicLoaderDarwinKernel"); m_mach_kernel_addr = better_kernel_address; } } @@ -443,30 +443,30 @@ Status ProcessMachCore::DoLoadCore() { // decide which to prefer. if (GetCorefilePreference() == eKernelCorefile) { if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("ProcessMachCore::DoLoadCore: Using kernel corefile image " - "at 0x%" PRIx64, - m_mach_kernel_addr); + LLDB_LOGF(log, + "ProcessMachCore::DoLoadCore: Using kernel corefile image " + "at 0x%" PRIx64, + m_mach_kernel_addr); m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic(); } else if (m_dyld_addr != LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("ProcessMachCore::DoLoadCore: Using user process dyld " - "image at 0x%" PRIx64, - m_dyld_addr); + LLDB_LOGF(log, + "ProcessMachCore::DoLoadCore: Using user process dyld " + "image at 0x%" PRIx64, + m_dyld_addr); m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic(); } } else { if (m_dyld_addr != LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("ProcessMachCore::DoLoadCore: Using user process dyld " - "image at 0x%" PRIx64, - m_dyld_addr); + LLDB_LOGF(log, + "ProcessMachCore::DoLoadCore: Using user process dyld " + "image at 0x%" PRIx64, + m_dyld_addr); m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic(); } else if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("ProcessMachCore::DoLoadCore: Using kernel corefile image " - "at 0x%" PRIx64, - m_mach_kernel_addr); + LLDB_LOGF(log, + "ProcessMachCore::DoLoadCore: Using kernel corefile image " + "at 0x%" PRIx64, + m_mach_kernel_addr); m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic(); } } |