Subversion Repositories HelenOS

Rev

Rev 2921 | Rev 3015 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2921 Rev 3014
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>
-
 
39
 
38
typedef enum { /* udebug_method_t */
40
typedef enum { /* udebug_method_t */
39
 
41
 
40
/** Start debugging the recipient.
42
/** Start debugging the recipient.
41
 * Causes all threads in the receiving task to stop. When they
43
 * Causes all threads in the receiving task to stop. When they
42
 * are all stoped, an answer with retval 0 is generated.
44
 * are all stoped, an answer with retval 0 is generated.
43
 */
45
 */
44
UDEBUG_M_BEGIN = 1,
46
UDEBUG_M_BEGIN = 1,
45
 
47
 
46
/** Finish debugging the recipient.
48
/** Finish debugging the recipient.
47
 * Answers all pending GO and GUARD messages.
49
 * Answers all pending GO and GUARD messages.
48
 */
50
 */
49
UDEBUG_M_END,
51
UDEBUG_M_END,
50
 
52
 
51
/** Set which events should be captured.
53
/** Set which events should be captured.
52
 */
54
 */
53
UDEBUG_M_SET_EVMASK,
55
UDEBUG_M_SET_EVMASK,
54
 
56
 
55
/** Make sure the debugged task is still there.
57
/** Make sure the debugged task is still there.
56
 * This message is answered when the debugged task dies
58
 * This message is answered when the debugged task dies
57
 * or the debugging session ends.
59
 * or the debugging session ends.
58
 */
60
 */
59
UDEBUG_M_GUARD,
61
UDEBUG_M_GUARD,
60
 
62
 
61
/** Run a thread until a debugging event occurs.
63
/** Run a thread until a debugging event occurs.
62
 * This message is answered when the thread stops
64
 * This message is answered when the thread stops
63
 * in a debugging event.
65
 * in a debugging event.
64
 *
66
 *
65
 * - ARG2 - id of the thread to run
67
 * - ARG2 - id of the thread to run
66
 */
68
 */
67
UDEBUG_M_GO,
69
UDEBUG_M_GO,
68
 
70
 
69
/** Stop a thread being debugged.
71
/** Stop a thread being debugged.
70
 * Creates a special STOP event in the thread, causing
72
 * Creates a special STOP event in the thread, causing
71
 * it to answer a pending GO message (if any).
73
 * it to answer a pending GO message (if any).
72
 */
74
 */
73
UDEBUG_M_STOP,
75
UDEBUG_M_STOP,
74
 
76
 
75
/** Read arguments of a syscall.
77
/** Read arguments of a syscall.
76
 *
78
 *
77
 * - ARG2 - thread identification
79
 * - ARG2 - thread identification
78
 * - ARG3 - destination address in the caller's address space
80
 * - ARG3 - destination address in the caller's address space
79
 *
81
 *
80
 */
82
 */
81
UDEBUG_M_ARGS_READ,
83
UDEBUG_M_ARGS_READ,
82
 
84
 
83
/** Read thread's userspace register state (istate_t).
85
/** Read thread's userspace register state (istate_t).
84
 *
86
 *
85
 * - ARG2 - thread identification
87
 * - ARG2 - thread identification
86
 * - ARG3 - destination address in the caller's address space
88
 * - ARG3 - destination address in the caller's address space
87
 *
89
 *
88
 * or, on error, retval will be
90
 * or, on error, retval will be
89
 * - ENOENT - thread does not exist
91
 * - ENOENT - thread does not exist
90
 * - EBUSY - register state not available
92
 * - EBUSY - register state not available
91
 */
93
 */
92
UDEBUG_M_REGS_READ,
94
UDEBUG_M_REGS_READ,
93
 
95
 
94
/** Write thread's userspace register state (istate_t).
96
/** Write thread's userspace register state (istate_t).
95
 *
97
 *
96
 * - ARG2 - thread identification
98
 * - ARG2 - thread identification
97
 * - ARG3 - source address in the caller's address space
99
 * - ARG3 - source address in the caller's address space
98
 *
100
 *
99
 * or, on error, retval will be
101
 * or, on error, retval will be
100
 * - ENOENT - thread does not exist
102
 * - ENOENT - thread does not exist
101
 * - EBUSY - register state not available
103
 * - EBUSY - register state not available
102
 */
104
 */
103
UDEBUG_M_REGS_WRITE,
105
UDEBUG_M_REGS_WRITE,
104
 
106
 
105
/** Read the list of the debugged tasks's threads.
107
/** Read the list of the debugged tasks's threads.
106
 *
108
 *
107
 * - ARG2 - destination address in the caller's address space
109
 * - ARG2 - destination address in the caller's address space
108
 * - ARG3 - size of receiving buffer in bytes
110
 * - ARG3 - size of receiving buffer in bytes
109
 *
111
 *
110
 * 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
111
 * (thread ids). On answer, the kernel will set:
113
 * (thread ids). On answer, the kernel will set:
112
 *
114
 *
113
 * - ARG2 - number of bytes that were actually copied
115
 * - ARG2 - number of bytes that were actually copied
114
 * - ARG3 - number of bytes of the complete data
116
 * - ARG3 - number of bytes of the complete data
115
 *
117
 *
116
 */
118
 */
117
UDEBUG_M_THREAD_READ,
119
UDEBUG_M_THREAD_READ,
118
 
120
 
119
/** Read the debugged tasks's memory.
121
/** Read the debugged tasks's memory.
120
 *
122
 *
121
 * - ARG2 - destination address in the caller's address space
123
 * - ARG2 - destination address in the caller's address space
122
 * - ARG3 - source address in the recipient's address space
124
 * - ARG3 - source address in the recipient's address space
123
 * - ARG4 - size of receiving buffer in bytes
125
 * - ARG4 - size of receiving buffer in bytes
124
 *
126
 *
125
 */
127
 */
126
UDEBUG_M_MEM_READ,
128
UDEBUG_M_MEM_READ,
127
 
129
 
128
/** Write the debugged tasks's memory.
130
/** Write the debugged tasks's memory.
129
 *
131
 *
130
 * - ARG2 - source address in the caller's address space
132
 * - ARG2 - source address in the caller's address space
131
 * - ARG3 - destination address in the recipient's address space
133
 * - ARG3 - destination address in the recipient's address space
132
 * - ARG4 - size of receiving buffer in bytes
134
 * - ARG4 - size of receiving buffer in bytes
133
 *
135
 *
134
 */
136
 */
135
UDEBUG_M_MEM_WRITE
137
UDEBUG_M_MEM_WRITE
136
 
138
 
137
 
139
 
138
} udebug_method_t;
140
} udebug_method_t;
139
 
141
 
140
               
142
               
141
typedef enum {
143
typedef enum {
142
    UDEBUG_EVENT_FINISHED = 1/**< Debuging session has finished */
144
    UDEBUG_EVENT_FINISHED = 1/**< Debuging session has finished */
143
    UDEBUG_EVENT_STOP,      /**< Stopped on DEBUG_STOP request */
145
    UDEBUG_EVENT_STOP,      /**< Stopped on DEBUG_STOP request */
144
    UDEBUG_EVENT_SYSCALL_B,     /**< Before beginning syscall execution */
146
    UDEBUG_EVENT_SYSCALL_B,     /**< Before beginning syscall execution */
145
    UDEBUG_EVENT_SYSCALL_E,     /**< After finishing syscall execution */
147
    UDEBUG_EVENT_SYSCALL_E,     /**< After finishing syscall execution */
146
    UDEBUG_EVENT_THREAD_B,      /**< The task created a new thread */
148
    UDEBUG_EVENT_THREAD_B,      /**< The task created a new thread */
147
    UDEBUG_EVENT_THREAD_E,      /**< A thread exited */
149
    UDEBUG_EVENT_THREAD_E,      /**< A thread exited */
148
    UDEBUG_EVENT_BREAKPOINT,    /**< Breakpoint instruction executed */
150
    UDEBUG_EVENT_BREAKPOINT,    /**< Breakpoint instruction executed */
149
    UDEBUG_EVENT_TRAP       /**< Single-step trap */
151
    UDEBUG_EVENT_TRAP       /**< Single-step trap */
150
} udebug_event_t;
152
} udebug_event_t;
151
 
153
 
152
#define UDEBUG_EVMASK(event) (1 << ((event) - 1))
154
#define UDEBUG_EVMASK(event) (1 << ((event) - 1))
153
 
155
 
154
typedef enum {
156
typedef enum {
155
    UDEBUG_EM_FINISHED  = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
157
    UDEBUG_EM_FINISHED  = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
156
    UDEBUG_EM_STOP      = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
158
    UDEBUG_EM_STOP      = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
157
    UDEBUG_EM_SYSCALL_B = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
159
    UDEBUG_EM_SYSCALL_B = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
158
    UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
160
    UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
159
    UDEBUG_EM_THREAD_B  = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
161
    UDEBUG_EM_THREAD_B  = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
160
    UDEBUG_EM_THREAD_E  = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
162
    UDEBUG_EM_THREAD_E  = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
161
    UDEBUG_EM_BREAKPOINT    = UDEBUG_EVMASK(UDEBUG_EVENT_BREAKPOINT),
163
    UDEBUG_EM_BREAKPOINT    = UDEBUG_EVMASK(UDEBUG_EVENT_BREAKPOINT),
162
    UDEBUG_EM_TRAP      = UDEBUG_EVMASK(UDEBUG_EVENT_TRAP),
164
    UDEBUG_EM_TRAP      = UDEBUG_EVMASK(UDEBUG_EVENT_TRAP),
163
    UDEBUG_EM_ALL       =
165
    UDEBUG_EM_ALL       =
164
        UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
166
        UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
165
        UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
167
        UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
166
        UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
168
        UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
167
        UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
169
        UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
168
        UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
170
        UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
169
        UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E) |
171
        UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E) |
170
        UDEBUG_EVMASK(UDEBUG_EVENT_BREAKPOINT) |
172
        UDEBUG_EVMASK(UDEBUG_EVENT_BREAKPOINT) |
171
        UDEBUG_EVMASK(UDEBUG_EVENT_TRAP)
173
        UDEBUG_EVMASK(UDEBUG_EVENT_TRAP)
172
} udebug_evmask_t;
174
} udebug_evmask_t;
173
 
175
 
174
#ifdef KERNEL
176
#ifdef KERNEL
175
 
177
 
176
typedef enum {
178
typedef enum {
177
    /** Task is not being debugged */
179
    /** Task is not being debugged */
178
    UDEBUG_TS_INACTIVE,
180
    UDEBUG_TS_INACTIVE,
179
    /** BEGIN operation in progress (waiting for threads to stop) */
181
    /** BEGIN operation in progress (waiting for threads to stop) */
180
    UDEBUG_TS_BEGINNING,
182
    UDEBUG_TS_BEGINNING,
181
    /** Debugger fully connected */
183
    /** Debugger fully connected */
182
    UDEBUG_TS_ACTIVE,
184
    UDEBUG_TS_ACTIVE,
183
    /** Task is shutting down, no more debug activities allowed */
185
    /** Task is shutting down, no more debug activities allowed */
184
    UDEBUG_TS_SHUTDOWN
186
    UDEBUG_TS_SHUTDOWN
185
} udebug_task_state_t;
187
} udebug_task_state_t;
186
 
188
 
-
 
189
/** Debugging part of task_t structure.
-
 
190
 */
-
 
191
typedef struct {
-
 
192
    udebug_task_state_t dt_state;
-
 
193
    call_t *begin_call;
-
 
194
    int not_stoppable_count;
-
 
195
    struct task *debugger;
-
 
196
    udebug_evmask_t evmask;
-
 
197
} udebug_task_t;
-
 
198
 
187
struct task;
199
struct task;
188
struct thread;
200
struct thread;
189
 
201
 
-
 
202
void udebug_task_init(udebug_task_t *ut);
-
 
203
 
190
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
204
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
191
    unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc,
205
    unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc,
192
    bool end_variant);
206
    bool end_variant);
193
 
207
 
194
void udebug_thread_b_event(struct thread *t);
208
void udebug_thread_b_event(struct thread *t);
195
void udebug_thread_e_event(void);
209
void udebug_thread_e_event(void);
196
 
210
 
197
void udebug_stoppable_begin(void);
211
void udebug_stoppable_begin(void);
198
void udebug_stoppable_end(void);
212
void udebug_stoppable_end(void);
199
 
213
 
200
void udebug_breakpoint_event(uintptr_t addr);
214
void udebug_breakpoint_event(uintptr_t addr);
201
void udebug_trap_event(uintptr_t addr);
215
void udebug_trap_event(uintptr_t addr);
202
 
216
 
203
int udebug_task_cleanup(struct task *ta);
217
int udebug_task_cleanup(struct task *ta);
204
 
218
 
205
#endif
219
#endif
206
 
220
 
207
#endif
221
#endif
208
 
222
 
209
/** @}
223
/** @}
210
 */
224
 */
211
 
225