X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/1a7e3f61d38d679bba59130891c2031b5a0092b6..bd6521f0fc816ab056bc71376f9706a69b3b52c1:/KDBG/MachineProcess.impl.hpp diff --git a/KDBG/MachineProcess.impl.hpp b/KDBG/MachineProcess.impl.hpp new file mode 100644 index 0000000..7aab877 --- /dev/null +++ b/KDBG/MachineProcess.impl.hpp @@ -0,0 +1,57 @@ +// +// MachineProcess.impl.hpp +// KDBG +// +// Created by James McIlree on 10/30/12. +// Copyright (c) 2014 Apple. All rights reserved. +// + +template +MachineProcess::MachineProcess(pid_t pid, const char* name, AbsTime create_timestamp, kMachineProcessFlag flags) : + _pid(pid), + _timespan(create_timestamp, AbsTime(0)), + _flags((uint32_t)flags), + _exit_status(0), + _apptype(-1) +{ + ASSERT(name, "Sanity"); + ASSERT(strlen(name) < sizeof(_name) - 1, "Sanity"); + + // strlcpy guarantees NULL termination + strlcpy(_name, name, sizeof(_name)); +} + +#if !defined(NDEBUG) && !defined(NS_BLOCK_ASSERTIONS) +template +void MachineProcess::validate() const { + ASSERT(strlen(_name), "Must have a non zero length name"); + + if (is_trace_terminated()) { + ASSERT(is_exiting(), "Process is trace terminated without precursor exit event"); + + for (auto thread : _threads_by_time) { + ASSERT(thread->is_trace_terminated(), "process is trace terminated, but has live thread"); + } + } + + for (auto thread : _threads_by_time) { + ASSERT(_timespan.contains(thread->timespan()), "thread outside process timespan"); + thread->validate(); + } + + // Every process should have one and only one primordial (main) thread. + // However, we cannot tell what the main thread is for threadmap processes, + // and processes forwarded from an earlier machine state may have already + // exited their main thread. We can only check exec/fork-exec. + + if ((is_created_by_exec() || is_created_by_fork_exec()) && !is_created_by_previous_machine_state()) { + auto main_threads = 0; + for (auto thread : _threads_by_time) { + if (thread->is_main_thread()) main_threads++; + ASSERT(main_threads <= 1, "More than one main thread in a process"); + } + ASSERT(main_threads == 1, "Incorrect number of main thread in process"); + } + +} +#endif \ No newline at end of file