| 1 | #ifndef STATE_H |
| 2 | #define STATE_H |
| 3 | |
| 4 | #include <glib.h> |
| 5 | #include <lttv/processTrace.h> |
| 6 | |
| 7 | /* The operating system state kept during the trace analysis |
| 8 | contains a subset of the real operating system state, |
| 9 | sufficient for the analysis, and possibly organized quite differently. |
| 10 | |
| 11 | The state information is added to LttvTracesetContext, LttvTraceContext |
| 12 | and LttvTracefileContext objects, used by processTrace, through |
| 13 | subtyping. The context objects already reflect the multiple tracefiles |
| 14 | (one per cpu) per trace and multiple traces per trace set. The state |
| 15 | objects defined here simply add fields to the relevant context objects. */ |
| 16 | |
| 17 | typedef struct _LttvTracesetState LttvTracesetState; |
| 18 | typedef struct _LttvTracesetStateClass LttvTracesetStateClass; |
| 19 | |
| 20 | typedef struct _LttvTraceState LttvTraceState; |
| 21 | typedef struct _LttvTraceStateClass LttvTraceStateClass; |
| 22 | |
| 23 | typedef struct _LttvTracefileState LttvTracefileState; |
| 24 | typedef struct _LttvTracefileStateClass LttvTracefileStateClass; |
| 25 | |
| 26 | gboolean lttv_state_add_event_hooks(LttvTracesetState *self); |
| 27 | |
| 28 | gboolean lttv_state_remove_event_hooks(LttvTracesetState *self); |
| 29 | |
| 30 | /* The LttvProcessState structure defines the current state for each process. |
| 31 | A process can make system calls (in some rare cases nested) and receive |
| 32 | interrupts/faults. For instance, a process may issue a system call, |
| 33 | generate a page fault while reading an argument from user space, and |
| 34 | get caught by an interrupt. To represent these nested states, an |
| 35 | execution mode stack is maintained. The stack bottom is normal user mode |
| 36 | and the top of stack is the current execution mode. |
| 37 | |
| 38 | The execution mode stack tells about the process status, execution mode and |
| 39 | submode (interrupt, system call or IRQ number). All these could be |
| 40 | defined as enumerations but may need extensions (e.g. new process state). |
| 41 | GQuark are thus used. They are as easy to manipulate as integers but have |
| 42 | a string associated, just like enumerations. |
| 43 | |
| 44 | The execution mode is one of "user mode", "kernel thread", "system call", |
| 45 | "interrupt request", "fault". */ |
| 46 | |
| 47 | typedef GQuark LttvExecutionMode; |
| 48 | |
| 49 | extern LttvExecutionMode |
| 50 | LTTV_STATE_USER_MODE, |
| 51 | LTTV_STATE_SYSCALL, |
| 52 | LTTV_STATE_TRAP, |
| 53 | LTTV_STATE_IRQ, |
| 54 | LTTV_STATE_MODE_UNKNOWN; |
| 55 | |
| 56 | |
| 57 | /* The submode number depends on the execution mode. For user mode or kernel |
| 58 | thread, which are the normal mode (execution mode stack bottom), |
| 59 | it is set to "none". For interrupt requests, faults and system calls, |
| 60 | it is set respectively to the interrupt name (e.g. "timer"), fault name |
| 61 | (e.g. "page fault"), and system call name (e.g. "select"). */ |
| 62 | |
| 63 | typedef GQuark LttvExecutionSubmode; |
| 64 | |
| 65 | extern LttvExecutionSubmode |
| 66 | LTTV_STATE_SUBMODE_NONE, |
| 67 | LTTV_STATE_SUBMODE_UNKNOWN; |
| 68 | |
| 69 | /* The process status is one of "running", "wait-cpu" (runnable), or "wait-*" |
| 70 | where "*" describes the resource waited for (e.g. timer, process, |
| 71 | disk...). */ |
| 72 | |
| 73 | typedef GQuark LttvProcessStatus; |
| 74 | |
| 75 | extern LttvProcessStatus |
| 76 | LTTV_STATE_UNNAMED, |
| 77 | LTTV_STATE_WAIT_FORK, |
| 78 | LTTV_STATE_WAIT_CPU, |
| 79 | LTTV_STATE_EXIT, |
| 80 | LTTV_STATE_WAIT, |
| 81 | LTTV_STATE_RUN; |
| 82 | |
| 83 | |
| 84 | typedef struct _LttvExecutionState { |
| 85 | LttvExecutionMode t; |
| 86 | LttvExecutionSubmode n; |
| 87 | LttTime entry; |
| 88 | LttTime change; |
| 89 | LttvProcessStatus s; |
| 90 | } LttvExecutionState; |
| 91 | |
| 92 | |
| 93 | typedef struct _LttvProcessState { |
| 94 | guint pid; |
| 95 | guint ppid; |
| 96 | LttTime creation_time; |
| 97 | GQuark name; |
| 98 | GQuark pid_time; |
| 99 | GArray *execution_stack; /* Array of LttvExecutionState */ |
| 100 | LttvExecutionState *state; /* Top of interrupt stack */ |
| 101 | /* opened file descriptors, address map?... */ |
| 102 | } LttvProcessState; |
| 103 | |
| 104 | |
| 105 | LttvProcessState *lttv_state_find_process(LttvTracefileState *tfs, guint pid); |
| 106 | |
| 107 | |
| 108 | /* The LttvTracesetState, LttvTraceState and LttvTracefileState types |
| 109 | inherit from the corresponding Context objects defined in processTrace. */ |
| 110 | |
| 111 | #define LTTV_TRACESET_STATE_TYPE (lttv_traceset_state_get_type ()) |
| 112 | #define LTTV_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATE_TYPE, LttvTracesetState)) |
| 113 | #define LTTV_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass)) |
| 114 | #define LTTV_IS_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATE_TYPE)) |
| 115 | #define LTTV_IS_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATE_TYPE)) |
| 116 | #define LTTV_TRACESET_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass)) |
| 117 | |
| 118 | struct _LttvTracesetState { |
| 119 | LttvTracesetContext parent; |
| 120 | }; |
| 121 | |
| 122 | struct _LttvTracesetStateClass { |
| 123 | LttvTracesetContextClass parent; |
| 124 | }; |
| 125 | |
| 126 | GType lttv_traceset_state_get_type (void); |
| 127 | |
| 128 | |
| 129 | #define LTTV_TRACE_STATE_TYPE (lttv_trace_state_get_type ()) |
| 130 | #define LTTV_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_STATE_TYPE, LttvTraceState)) |
| 131 | #define LTTV_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass)) |
| 132 | #define LTTV_IS_TRACE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_STATE_TYPE)) |
| 133 | #define LTTV_IS_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATE_TYPE)) |
| 134 | #define LTTV_TRACE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass)) |
| 135 | |
| 136 | struct _LttvTraceState { |
| 137 | LttvTraceContext parent; |
| 138 | |
| 139 | GHashTable *processes; /* LttvProcessState objects indexed by pid */ |
| 140 | /* Block/char devices, locks, memory pages... */ |
| 141 | GQuark *eventtype_names; |
| 142 | GQuark *syscall_names; |
| 143 | GQuark *trap_names; |
| 144 | GQuark *irq_names; |
| 145 | }; |
| 146 | |
| 147 | struct _LttvTraceStateClass { |
| 148 | LttvTraceContextClass parent; |
| 149 | }; |
| 150 | |
| 151 | GType lttv_trace_state_get_type (void); |
| 152 | |
| 153 | |
| 154 | #define LTTV_TRACEFILE_STATE_TYPE (lttv_tracefile_state_get_type ()) |
| 155 | #define LTTV_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileState)) |
| 156 | #define LTTV_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass)) |
| 157 | #define LTTV_IS_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_STATE_TYPE)) |
| 158 | #define LTTV_IS_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATE_TYPE)) |
| 159 | #define LTTV_TRACEFILE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass)) |
| 160 | |
| 161 | struct _LttvTracefileState { |
| 162 | LttvTracefileContext parent; |
| 163 | |
| 164 | LttvProcessState *process; |
| 165 | GQuark cpu_name; |
| 166 | }; |
| 167 | |
| 168 | struct _LttvTracefileStateClass { |
| 169 | LttvTracefileContextClass parent; |
| 170 | }; |
| 171 | |
| 172 | GType lttv_tracefile_state_get_type (void); |
| 173 | |
| 174 | |
| 175 | #endif // STATE_H |