[9a1b20c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2008 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[80487bc5] | 29 | /** @addtogroup generic
|
---|
[9a1b20c] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #ifndef KERN_UDEBUG_H_
|
---|
| 36 | #define KERN_UDEBUG_H_
|
---|
| 37 |
|
---|
| 38 | #include <ipc/ipc.h>
|
---|
| 39 |
|
---|
| 40 | typedef enum { /* udebug_method_t */
|
---|
| 41 |
|
---|
| 42 | /** Start debugging the recipient.
|
---|
| 43 | * Causes all threads in the receiving task to stop. When they
|
---|
| 44 | * are all stoped, an answer with retval 0 is generated.
|
---|
| 45 | */
|
---|
| 46 | UDEBUG_M_BEGIN = 1,
|
---|
| 47 |
|
---|
| 48 | /** Finish debugging the recipient.
|
---|
| 49 | * Answers all pending GO and GUARD messages.
|
---|
| 50 | */
|
---|
| 51 | UDEBUG_M_END,
|
---|
| 52 |
|
---|
| 53 | /** Set which events should be captured.
|
---|
| 54 | */
|
---|
| 55 | UDEBUG_M_SET_EVMASK,
|
---|
| 56 |
|
---|
| 57 | /** Make sure the debugged task is still there.
|
---|
| 58 | * This message is answered when the debugged task dies
|
---|
| 59 | * or the debugging session ends.
|
---|
| 60 | */
|
---|
| 61 | UDEBUG_M_GUARD,
|
---|
| 62 |
|
---|
| 63 | /** Run a thread until a debugging event occurs.
|
---|
| 64 | * This message is answered when the thread stops
|
---|
| 65 | * in a debugging event.
|
---|
| 66 | *
|
---|
| 67 | * - ARG2 - id of the thread to run
|
---|
| 68 | */
|
---|
| 69 | UDEBUG_M_GO,
|
---|
| 70 |
|
---|
| 71 | /** Stop a thread being debugged.
|
---|
| 72 | * Creates a special STOP event in the thread, causing
|
---|
| 73 | * it to answer a pending GO message (if any).
|
---|
| 74 | */
|
---|
| 75 | UDEBUG_M_STOP,
|
---|
| 76 |
|
---|
| 77 | /** Read arguments of a syscall.
|
---|
| 78 | *
|
---|
| 79 | * - ARG2 - thread identification
|
---|
| 80 | * - ARG3 - destination address in the caller's address space
|
---|
| 81 | *
|
---|
| 82 | */
|
---|
| 83 | UDEBUG_M_ARGS_READ,
|
---|
| 84 |
|
---|
[80487bc5] | 85 | /** Read thread's userspace register state (istate_t).
|
---|
| 86 | *
|
---|
| 87 | * - ARG2 - thread identification
|
---|
| 88 | * - ARG3 - destination address in the caller's address space
|
---|
| 89 | *
|
---|
| 90 | * or, on error, retval will be
|
---|
| 91 | * - ENOENT - thread does not exist
|
---|
| 92 | * - EBUSY - register state not available
|
---|
| 93 | */
|
---|
| 94 | UDEBUG_M_REGS_READ,
|
---|
| 95 |
|
---|
[9a1b20c] | 96 | /** Read the list of the debugged tasks's threads.
|
---|
| 97 | *
|
---|
| 98 | * - ARG2 - destination address in the caller's address space
|
---|
| 99 | * - ARG3 - size of receiving buffer in bytes
|
---|
| 100 | *
|
---|
| 101 | * The kernel fills the buffer with a series of sysarg_t values
|
---|
| 102 | * (thread ids). On answer, the kernel will set:
|
---|
| 103 | *
|
---|
| 104 | * - ARG2 - number of bytes that were actually copied
|
---|
| 105 | * - ARG3 - number of bytes of the complete data
|
---|
| 106 | *
|
---|
| 107 | */
|
---|
| 108 | UDEBUG_M_THREAD_READ,
|
---|
| 109 |
|
---|
[3698e44] | 110 | /** Read the name of the debugged task.
|
---|
| 111 | *
|
---|
| 112 | * - ARG2 - destination address in the caller's address space
|
---|
| 113 | * - ARG3 - size of receiving buffer in bytes
|
---|
| 114 | *
|
---|
| 115 | * The kernel fills the buffer with a non-terminated string.
|
---|
| 116 | *
|
---|
| 117 | * - ARG2 - number of bytes that were actually copied
|
---|
| 118 | * - ARG3 - number of bytes of the complete data
|
---|
| 119 | *
|
---|
| 120 | */
|
---|
| 121 | UDEBUG_M_NAME_READ,
|
---|
| 122 |
|
---|
[336db295] | 123 | /** Read the list of the debugged task's address space areas.
|
---|
| 124 | *
|
---|
| 125 | * - ARG2 - destination address in the caller's address space
|
---|
| 126 | * - ARG3 - size of receiving buffer in bytes
|
---|
| 127 | *
|
---|
| 128 | * The kernel fills the buffer with a series of as_area_info_t structures.
|
---|
| 129 | * Upon answer, the kernel will set:
|
---|
| 130 | *
|
---|
| 131 | * - ARG2 - number of bytes that were actually copied
|
---|
| 132 | * - ARG3 - number of bytes of the complete data
|
---|
| 133 | *
|
---|
| 134 | */
|
---|
| 135 | UDEBUG_M_AREAS_READ,
|
---|
| 136 |
|
---|
[9a1b20c] | 137 | /** Read the debugged tasks's memory.
|
---|
| 138 | *
|
---|
| 139 | * - ARG2 - destination address in the caller's address space
|
---|
| 140 | * - ARG3 - source address in the recipient's address space
|
---|
| 141 | * - ARG4 - size of receiving buffer in bytes
|
---|
| 142 | *
|
---|
| 143 | */
|
---|
| 144 | UDEBUG_M_MEM_READ,
|
---|
| 145 |
|
---|
| 146 | } udebug_method_t;
|
---|
| 147 |
|
---|
[80487bc5] | 148 |
|
---|
[9a1b20c] | 149 | typedef enum {
|
---|
| 150 | UDEBUG_EVENT_FINISHED = 1, /**< Debuging session has finished */
|
---|
| 151 | UDEBUG_EVENT_STOP, /**< Stopped on DEBUG_STOP request */
|
---|
| 152 | UDEBUG_EVENT_SYSCALL_B, /**< Before beginning syscall execution */
|
---|
| 153 | UDEBUG_EVENT_SYSCALL_E, /**< After finishing syscall execution */
|
---|
| 154 | UDEBUG_EVENT_THREAD_B, /**< The task created a new thread */
|
---|
| 155 | UDEBUG_EVENT_THREAD_E /**< A thread exited */
|
---|
| 156 | } udebug_event_t;
|
---|
| 157 |
|
---|
| 158 | #define UDEBUG_EVMASK(event) (1 << ((event) - 1))
|
---|
| 159 |
|
---|
| 160 | typedef enum {
|
---|
| 161 | UDEBUG_EM_FINISHED = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
|
---|
| 162 | UDEBUG_EM_STOP = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
|
---|
| 163 | UDEBUG_EM_SYSCALL_B = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
|
---|
| 164 | UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
|
---|
| 165 | UDEBUG_EM_THREAD_B = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
|
---|
| 166 | UDEBUG_EM_THREAD_E = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
|
---|
| 167 | UDEBUG_EM_ALL =
|
---|
| 168 | UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
|
---|
| 169 | UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
|
---|
| 170 | UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
|
---|
| 171 | UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
|
---|
| 172 | UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
|
---|
| 173 | UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E)
|
---|
| 174 | } udebug_evmask_t;
|
---|
| 175 |
|
---|
| 176 | #ifdef KERNEL
|
---|
| 177 |
|
---|
| 178 | #include <synch/mutex.h>
|
---|
[a074b4f] | 179 | #include <synch/condvar.h>
|
---|
[9a1b20c] | 180 | #include <arch/interrupt.h>
|
---|
| 181 | #include <atomic.h>
|
---|
| 182 |
|
---|
| 183 | typedef enum {
|
---|
| 184 | /** Task is not being debugged */
|
---|
| 185 | UDEBUG_TS_INACTIVE,
|
---|
| 186 | /** BEGIN operation in progress (waiting for threads to stop) */
|
---|
| 187 | UDEBUG_TS_BEGINNING,
|
---|
| 188 | /** Debugger fully connected */
|
---|
[f714576] | 189 | UDEBUG_TS_ACTIVE
|
---|
[9a1b20c] | 190 | } udebug_task_state_t;
|
---|
| 191 |
|
---|
| 192 | /** Debugging part of task_t structure.
|
---|
| 193 | */
|
---|
| 194 | typedef struct {
|
---|
| 195 | /** Synchronize debug ops on this task / access to this structure */
|
---|
| 196 | mutex_t lock;
|
---|
| 197 | char *lock_owner;
|
---|
| 198 |
|
---|
| 199 | udebug_task_state_t dt_state;
|
---|
| 200 | call_t *begin_call;
|
---|
| 201 | int not_stoppable_count;
|
---|
| 202 | struct task *debugger;
|
---|
| 203 | udebug_evmask_t evmask;
|
---|
| 204 | } udebug_task_t;
|
---|
| 205 |
|
---|
| 206 | /** Debugging part of thread_t structure.
|
---|
| 207 | */
|
---|
| 208 | typedef struct {
|
---|
[1378b2b] | 209 | /** Synchronize debug ops on this thread / access to this structure. */
|
---|
[9a1b20c] | 210 | mutex_t lock;
|
---|
| 211 |
|
---|
| 212 | waitq_t go_wq;
|
---|
| 213 | call_t *go_call;
|
---|
[96b02eb9] | 214 | sysarg_t syscall_args[6];
|
---|
[3ff2b54] | 215 | istate_t *uspace_state;
|
---|
[9a1b20c] | 216 |
|
---|
[1378b2b] | 217 | /** What type of event are we stopped in or 0 if none. */
|
---|
[384c488] | 218 | udebug_event_t cur_event;
|
---|
[8af9950] | 219 | bool go; /**< thread is GO */
|
---|
| 220 | bool stoppable; /**< thread is stoppable */
|
---|
| 221 | bool active; /**< thread is in a debugging session */
|
---|
[a074b4f] | 222 | condvar_t active_cv;
|
---|
[9a1b20c] | 223 | } udebug_thread_t;
|
---|
| 224 |
|
---|
| 225 | struct task;
|
---|
| 226 | struct thread;
|
---|
| 227 |
|
---|
| 228 | void udebug_task_init(udebug_task_t *ut);
|
---|
| 229 | void udebug_thread_initialize(udebug_thread_t *ut);
|
---|
| 230 |
|
---|
[96b02eb9] | 231 | void udebug_syscall_event(sysarg_t a1, sysarg_t a2, sysarg_t a3,
|
---|
| 232 | sysarg_t a4, sysarg_t a5, sysarg_t a6, sysarg_t id, sysarg_t rc,
|
---|
[9a1b20c] | 233 | bool end_variant);
|
---|
| 234 |
|
---|
[13964ef] | 235 | void udebug_thread_b_event_attach(struct thread *t, struct task *ta);
|
---|
[9a1b20c] | 236 | void udebug_thread_e_event(void);
|
---|
| 237 |
|
---|
| 238 | void udebug_stoppable_begin(void);
|
---|
| 239 | void udebug_stoppable_end(void);
|
---|
| 240 |
|
---|
| 241 | void udebug_before_thread_runs(void);
|
---|
| 242 |
|
---|
| 243 | int udebug_task_cleanup(struct task *ta);
|
---|
[0d21b53] | 244 | void udebug_thread_fault(void);
|
---|
[9a1b20c] | 245 |
|
---|
| 246 | #endif
|
---|
| 247 |
|
---|
| 248 | #endif
|
---|
| 249 |
|
---|
| 250 | /** @}
|
---|
| 251 | */
|
---|