aboutsummaryrefslogtreecommitdiffstats
path: root/source/Plugins/Process/Darwin
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/Process/Darwin')
-rw-r--r--source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp42
-rw-r--r--source/Plugins/Process/Darwin/MachException.cpp194
-rw-r--r--source/Plugins/Process/Darwin/NativeProcessDarwin.cpp568
-rw-r--r--source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp18
4 files changed, 411 insertions, 411 deletions
diff --git a/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp b/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
index 3ec410fe7d76..f70ef97a2bc5 100644
--- a/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
+++ b/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/source/Plugins/Process/Darwin/MachException.cpp b/source/Plugins/Process/Darwin/MachException.cpp
index 70ad6736a748..073ad64b300c 100644
--- a/source/Plugins/Process/Darwin/MachException.cpp
+++ b/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/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp b/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
index fe7de27e0ee6..18dbdda9a33b 100644
--- a/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
+++ b/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;
}
@@ -889,8 +881,8 @@ Status NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) {
// TODO make PipePOSIX derive from IOObject. This is goofy here.
const bool transfer_ownership = false;
- auto io_sp = IOObjectSP(
- new File(m_waitpid_pipe.GetReadFileDescriptor(), transfer_ownership));
+ auto io_sp = IOObjectSP(new NativeFile(m_waitpid_pipe.GetReadFileDescriptor(),
+ transfer_ownership));
m_waitpid_reader_handle = main_loop.RegisterReadObject(
io_sp, [this](MainLoopBase &) { HandleWaitpidResult(); }, 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/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp b/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
index 89de92a6df4d..1faa5b219cbc 100644
--- a/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
+++ b/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;
}