Subversion Repositories HelenOS

Rev

Rev 3623 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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