2
* Copyright (c) 2008 Jiri Svoboda
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
29
/** @addtogroup generic
35
#ifndef KERN_UDEBUG_H_
36
#define KERN_UDEBUG_H_
40
typedef enum { /* udebug_method_t */
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.
48
/** Finish debugging the recipient.
49
* Answers all pending GO and GUARD messages.
53
/** Set which events should be captured.
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.
63
/** Run a thread until a debugging event occurs.
64
* This message is answered when the thread stops
65
* in a debugging event.
67
* - ARG2 - id of the thread to run
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).
77
/** Read arguments of a syscall.
79
* - ARG2 - thread identification
80
* - ARG3 - destination address in the caller's address space
85
/** Read the list of the debugged tasks's threads.
87
* - ARG2 - destination address in the caller's address space
88
* - ARG3 - size of receiving buffer in bytes
90
* The kernel fills the buffer with a series of sysarg_t values
91
* (thread ids). On answer, the kernel will set:
93
* - ARG2 - number of bytes that were actually copied
94
* - ARG3 - number of bytes of the complete data
99
/** Read the debugged tasks's memory.
101
* - ARG2 - destination address in the caller's address space
102
* - ARG3 - source address in the recipient's address space
103
* - ARG4 - size of receiving buffer in bytes
112
UDEBUG_EVENT_FINISHED = 1, /**< Debuging session has finished */
113
UDEBUG_EVENT_STOP, /**< Stopped on DEBUG_STOP request */
114
UDEBUG_EVENT_SYSCALL_B, /**< Before beginning syscall execution */
115
UDEBUG_EVENT_SYSCALL_E, /**< After finishing syscall execution */
116
UDEBUG_EVENT_THREAD_B, /**< The task created a new thread */
117
UDEBUG_EVENT_THREAD_E /**< A thread exited */
120
#define UDEBUG_EVMASK(event) (1 << ((event) - 1))
123
UDEBUG_EM_FINISHED = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
124
UDEBUG_EM_STOP = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
125
UDEBUG_EM_SYSCALL_B = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
126
UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
127
UDEBUG_EM_THREAD_B = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
128
UDEBUG_EM_THREAD_E = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
130
UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
131
UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
132
UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
133
UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
134
UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
135
UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E)
140
#include <synch/mutex.h>
141
#include <arch/interrupt.h>
145
/** Task is not being debugged */
147
/** BEGIN operation in progress (waiting for threads to stop) */
149
/** Debugger fully connected */
151
} udebug_task_state_t;
153
/** Debugging part of task_t structure.
156
/** Synchronize debug ops on this task / access to this structure */
160
udebug_task_state_t dt_state;
162
int not_stoppable_count;
163
struct task *debugger;
164
udebug_evmask_t evmask;
167
/** Debugging part of thread_t structure.
170
/** Synchronize debug ops on this thread / access to this structure. */
175
unative_t syscall_args[6];
176
istate_t *uspace_state;
178
/** What type of event are we stopped in or 0 if none. */
179
udebug_event_t cur_event;
180
bool go; /**< thread is GO */
181
bool stoppable; /**< thread is stoppable */
182
bool active; /**< thread is in a debugging session */
188
void udebug_task_init(udebug_task_t *ut);
189
void udebug_thread_initialize(udebug_thread_t *ut);
191
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
192
unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc,
195
void udebug_thread_b_event_attach(struct thread *t, struct task *ta);
196
void udebug_thread_e_event(void);
198
void udebug_stoppable_begin(void);
199
void udebug_stoppable_end(void);
201
void udebug_before_thread_runs(void);
203
int udebug_task_cleanup(struct task *ta);