]> git.saurik.com Git - apple/system_cmds.git/blame - KDBG/MachineProcess.impl.hpp
system_cmds-643.30.1.tar.gz
[apple/system_cmds.git] / KDBG / MachineProcess.impl.hpp
CommitLineData
bd6521f0
A
1//
2// MachineProcess.impl.hpp
3// KDBG
4//
5// Created by James McIlree on 10/30/12.
6// Copyright (c) 2014 Apple. All rights reserved.
7//
8
9template <typename SIZE>
10MachineProcess<SIZE>::MachineProcess(pid_t pid, const char* name, AbsTime create_timestamp, kMachineProcessFlag flags) :
11 _pid(pid),
12 _timespan(create_timestamp, AbsTime(0)),
13 _flags((uint32_t)flags),
14 _exit_status(0),
15 _apptype(-1)
16{
17 ASSERT(name, "Sanity");
18 ASSERT(strlen(name) < sizeof(_name) - 1, "Sanity");
19
20 // strlcpy guarantees NULL termination
21 strlcpy(_name, name, sizeof(_name));
22}
23
24#if !defined(NDEBUG) && !defined(NS_BLOCK_ASSERTIONS)
25template <typename SIZE>
26void MachineProcess<SIZE>::validate() const {
27 ASSERT(strlen(_name), "Must have a non zero length name");
28
29 if (is_trace_terminated()) {
30 ASSERT(is_exiting(), "Process is trace terminated without precursor exit event");
31
32 for (auto thread : _threads_by_time) {
33 ASSERT(thread->is_trace_terminated(), "process is trace terminated, but has live thread");
34 }
35 }
36
37 for (auto thread : _threads_by_time) {
38 ASSERT(_timespan.contains(thread->timespan()), "thread outside process timespan");
39 thread->validate();
40 }
41
42 // Every process should have one and only one primordial (main) thread.
43 // However, we cannot tell what the main thread is for threadmap processes,
44 // and processes forwarded from an earlier machine state may have already
45 // exited their main thread. We can only check exec/fork-exec.
46
47 if ((is_created_by_exec() || is_created_by_fork_exec()) && !is_created_by_previous_machine_state()) {
48 auto main_threads = 0;
49 for (auto thread : _threads_by_time) {
50 if (thread->is_main_thread()) main_threads++;
51 ASSERT(main_threads <= 1, "More than one main thread in a process");
52 }
53 ASSERT(main_threads == 1, "Incorrect number of main thread in process");
54 }
55
56}
57#endif