]> git.saurik.com Git - apple/system_cmds.git/blob - KDBG/KDState.hpp
system_cmds-643.30.1.tar.gz
[apple/system_cmds.git] / KDBG / KDState.hpp
1 //
2 // KDState.hpp
3 // KDBG
4 //
5 // Created by James McIlree on 8/10/12.
6 // Copyright (c) 2014 Apple. All rights reserved.
7 //
8
9 class KDState {
10 protected:
11 kbufinfo_t _state;
12
13 public:
14 uint32_t flags() { return _state.flags; }
15 int capacity() { return _state.nkdbufs; }
16 int thread_map_capacity() { return _state.nkdthreads; }
17
18 bool is_enabled() { return !_state.nolog; }
19 bool is_initialized() { return flags() & KDBG_BUFINIT; }
20 bool is_thread_map_initialized() { return flags() & KDBG_MAPINIT; }
21 bool is_nowrap() { return flags() & KDBG_NOWRAP; }
22 bool is_freerun() { return flags() & KDBG_FREERUN; }
23 bool is_wrapped() { return flags() & KDBG_WRAPPED; }
24
25 bool is_lp64() { return (flags() & KDBG_LP64) > 0; }
26
27 bool is_range_collection_enabled() { return (flags() & KDBG_RANGECHECK) > 0; }
28 bool is_specific_value_collection_enabled() { return (flags() & KDBG_VALCHECK) > 0; }
29 bool is_filter_collection_enabled() { return (flags() & KDBG_TYPEFILTER_CHECK) > 0; }
30 bool is_inclusive_pid_collection_enabled() { return (flags() & KDBG_PIDCHECK) > 0; }
31 bool is_exclusive_pid_collection_enabled() { return (flags() & KDBG_PIDEXCLUDE) > 0; }
32
33 pid_t controlling_pid() { return _state.bufid; }
34
35 void print() {
36 printf("KDebug State\n");
37 printf("\tBuffer is %s\n", this->is_initialized() ? "initialized" : "not initialized");
38 printf("\tCapacity is %d\n", this->capacity());
39 printf("\tRaw flags 0x%08x\n", this->flags());
40 printf("\tLogging is %s\n", this->is_enabled() ? "enabled" : "disabled");
41 printf("\tWrapping is %s\n", this->is_nowrap() ? "disabled" : "enabled");
42 printf("\tBuffer %s wrapped\n", this->is_wrapped() ? "has" : "has not");
43
44 // Two bits, 4 possible states:
45 //
46 // INC EXC
47 // 1 0 ALL_MARKED_PIDS
48 // 0 1 ALL_UNMARKED_PIDS
49 // 0 0 ALL_PIDS
50 // 1 1 ERROR
51
52 const char* style;
53 switch (flags() & (KDBG_PIDEXCLUDE | KDBG_PIDCHECK)) {
54 case 0:
55 style = "all-pids";
56 break;
57 case KDBG_PIDCHECK:
58 style = "includes-marked-pids";
59 break;
60 case KDBG_PIDEXCLUDE:
61 style = "excludes-marked-pids";
62 break;
63 default:
64 style = "ERROR";
65 break;
66 }
67 printf("\tCollection style is %s\n", style);
68 printf("\tCollection by range is %s\n", this->is_range_collection_enabled() ? "enabled" : "disabled");
69 printf("\tCollection by value is %s\n", this->is_specific_value_collection_enabled() ? "enabled" : "disabled");
70 printf("\tCollection by filter is %s\n", this->is_filter_collection_enabled() ? "enabled" : "disabled");
71 printf("\tThread map is %s ", this->is_thread_map_initialized() ? "initialized\n" : "not initialized\n");
72 printf("\tThread map entries %d\n", this->thread_map_capacity());
73 if (this->controlling_pid() == -1)
74 printf("\tNo controlling pid\n");
75 else
76 printf("\tControlled by pid %d\n", this->controlling_pid());
77 }
78 };
79