Subversion Repositories HelenOS

Rev

Rev 3438 | Rev 3600 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3438 Rev 3441
Line 33... Line 33...
33
/**
33
/**
34
 * @file
34
 * @file
35
 * @brief   Udebug operations.
35
 * @brief   Udebug operations.
36
 */
36
 */
37
 
37
 
38
#include <print.h>
38
#include <debug.h>
39
#include <proc/task.h>
39
#include <proc/task.h>
40
#include <proc/thread.h>
40
#include <proc/thread.h>
41
#include <arch.h>
41
#include <arch.h>
42
#include <errno.h>
42
#include <errno.h>
43
#include <syscall/copy.h>
43
#include <syscall/copy.h>
Line 160... Line 160...
160
    int reply;
160
    int reply;
161
 
161
 
162
    thread_t *t;
162
    thread_t *t;
163
    link_t *cur;
163
    link_t *cur;
164
 
164
 
165
    printf("udebug_begin()\n");
165
    LOG("udebug_begin()\n");
166
 
166
 
167
    mutex_lock(&TASK->udebug.lock);
167
    mutex_lock(&TASK->udebug.lock);
168
    printf("debugging task %llu\n", TASK->taskid);
168
    LOG("debugging task %llu\n", TASK->taskid);
169
 
169
 
170
    if (TASK->udebug.dt_state != UDEBUG_TS_INACTIVE) {
170
    if (TASK->udebug.dt_state != UDEBUG_TS_INACTIVE) {
171
        mutex_unlock(&TASK->udebug.lock);
171
        mutex_unlock(&TASK->udebug.lock);
172
        printf("udebug_begin(): busy error\n");
172
        LOG("udebug_begin(): busy error\n");
173
 
173
 
174
        return EBUSY;
174
        return EBUSY;
175
    }
175
    }
176
 
176
 
177
    TASK->udebug.dt_state = UDEBUG_TS_BEGINNING;
177
    TASK->udebug.dt_state = UDEBUG_TS_BEGINNING;
Line 197... Line 197...
197
        mutex_unlock(&t->udebug.lock);
197
        mutex_unlock(&t->udebug.lock);
198
    }
198
    }
199
 
199
 
200
    mutex_unlock(&TASK->udebug.lock);
200
    mutex_unlock(&TASK->udebug.lock);
201
 
201
 
202
    printf("udebug_begin() done (%s)\n",
202
    LOG("udebug_begin() done (%s)\n",
203
        reply ? "reply" : "stoppability wait");
203
        reply ? "reply" : "stoppability wait");
204
 
204
 
205
    return reply;
205
    return reply;
206
}
206
}
207
 
207
 
208
int udebug_end(void)
208
int udebug_end(void)
209
{
209
{
210
    int rc;
210
    int rc;
211
 
211
 
212
    printf("udebug_end()\n");
212
    LOG("udebug_end()\n");
213
 
213
 
214
    mutex_lock(&TASK->udebug.lock);
214
    mutex_lock(&TASK->udebug.lock);
215
    printf("task %llu\n", TASK->taskid);
215
    LOG("task %" PRIu64 "\n", TASK->taskid);
216
 
216
 
217
    rc = udebug_task_cleanup(TASK);
217
    rc = udebug_task_cleanup(TASK);
218
 
218
 
219
    mutex_unlock(&TASK->udebug.lock);
219
    mutex_unlock(&TASK->udebug.lock);
220
 
220
 
221
    return rc;
221
    return rc;
222
}
222
}
223
 
223
 
224
int udebug_set_evmask(udebug_evmask_t mask)
224
int udebug_set_evmask(udebug_evmask_t mask)
225
{
225
{
226
    printf("udebug_set_mask()\n");
226
    LOG("udebug_set_mask()\n");
227
 
-
 
228
    printf("debugging task %llu\n", TASK->taskid);
-
 
229
 
227
 
230
    mutex_lock(&TASK->udebug.lock);
228
    mutex_lock(&TASK->udebug.lock);
231
 
229
 
232
    if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
230
    if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
233
        mutex_unlock(&TASK->udebug.lock);
231
        mutex_unlock(&TASK->udebug.lock);
234
        printf("udebug_set_mask(): not active debuging session\n");
232
        LOG("udebug_set_mask(): not active debuging session\n");
235
 
233
 
236
        return EINVAL;
234
        return EINVAL;
237
    }
235
    }
238
 
236
 
239
    TASK->udebug.evmask = mask;
237
    TASK->udebug.evmask = mask;
Line 246... Line 244...
246
 
244
 
247
int udebug_go(thread_t *t, call_t *call)
245
int udebug_go(thread_t *t, call_t *call)
248
{
246
{
249
    int rc;
247
    int rc;
250
 
248
 
251
//  printf("udebug_go()\n");
-
 
252
 
-
 
253
    /* On success, this will lock t->udebug.lock */
249
    /* On success, this will lock t->udebug.lock */
254
    rc = _thread_op_begin(t, false);
250
    rc = _thread_op_begin(t, false);
255
    if (rc != EOK) {
251
    if (rc != EOK) {
256
        return rc;
252
        return rc;
257
    }
253
    }
Line 272... Line 268...
272
 
268
 
273
int udebug_stop(thread_t *t, call_t *call)
269
int udebug_stop(thread_t *t, call_t *call)
274
{
270
{
275
    int rc;
271
    int rc;
276
 
272
 
277
    printf("udebug_stop()\n");
273
    LOG("udebug_stop()\n");
278
    mutex_lock(&TASK->udebug.lock);
274
    mutex_lock(&TASK->udebug.lock);
279
 
275
 
280
    /*
276
    /*
281
     * On success, this will lock t->udebug.lock. Note that this makes sure
277
     * On success, this will lock t->udebug.lock. Note that this makes sure
282
     * the thread is not stopped.
278
     * the thread is not stopped.
Line 296... Line 292...
296
    }
292
    }
297
 
293
 
298
    /*
294
    /*
299
     * Answer GO call
295
     * Answer GO call
300
     */
296
     */
301
    printf("udebug_stop - answering go call\n");
297
    LOG("udebug_stop - answering go call\n");
302
 
298
 
303
    /* Make sure nobody takes this call away from us */
299
    /* Make sure nobody takes this call away from us */
304
    call = t->udebug.go_call;
300
    call = t->udebug.go_call;
305
    t->udebug.go_call = NULL;
301
    t->udebug.go_call = NULL;
306
 
302
 
307
    IPC_SET_RETVAL(call->data, 0);
303
    IPC_SET_RETVAL(call->data, 0);
308
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_STOP);
304
    IPC_SET_ARG1(call->data, UDEBUG_EVENT_STOP);
309
    printf("udebug_stop/ipc_answer\n");
305
    LOG("udebug_stop/ipc_answer\n");
310
 
306
 
311
    THREAD->udebug.cur_event = UDEBUG_EVENT_STOP;
307
    THREAD->udebug.cur_event = UDEBUG_EVENT_STOP;
312
 
308
 
313
    _thread_op_end(t);
309
    _thread_op_end(t);
314
 
310
 
315
    ipc_answer(&TASK->answerbox, call);
311
    ipc_answer(&TASK->answerbox, call);
316
    mutex_unlock(&TASK->udebug.lock);
312
    mutex_unlock(&TASK->udebug.lock);
317
 
313
 
318
    printf("udebog_stop/done\n");
314
    LOG("udebog_stop/done\n");
319
    return 0;
315
    return 0;
320
}
316
}
321
 
317
 
322
int udebug_thread_read(void **buffer, size_t buf_size, size_t *n)
318
int udebug_thread_read(void **buffer, size_t buf_size, size_t *n)
323
{
319
{
Line 328... Line 324...
328
    ipl_t ipl;
324
    ipl_t ipl;
329
    unative_t *id_buffer;
325
    unative_t *id_buffer;
330
    int flags;
326
    int flags;
331
    size_t max_ids;
327
    size_t max_ids;
332
 
328
 
333
    printf("udebug_thread_read()\n");
329
    LOG("udebug_thread_read()\n");
334
 
330
 
335
    /* Allocate a buffer to hold thread IDs */
331
    /* Allocate a buffer to hold thread IDs */
336
    id_buffer = malloc(buf_size, 0);
332
    id_buffer = malloc(buf_size, 0);
337
 
333
 
338
    mutex_lock(&TASK->udebug.lock);
334
    mutex_lock(&TASK->udebug.lock);
Line 383... Line 379...
383
int udebug_args_read(thread_t *t, void **buffer)
379
int udebug_args_read(thread_t *t, void **buffer)
384
{
380
{
385
    int rc;
381
    int rc;
386
    unative_t *arg_buffer;
382
    unative_t *arg_buffer;
387
 
383
 
388
//  printf("udebug_args_read()\n");
-
 
389
 
-
 
390
    /* Prepare a buffer to hold the arguments */
384
    /* Prepare a buffer to hold the arguments */
391
    arg_buffer = malloc(6 * sizeof(unative_t), 0);
385
    arg_buffer = malloc(6 * sizeof(unative_t), 0);
392
 
386
 
393
    /* On success, this will lock t->udebug.lock */
387
    /* On success, this will lock t->udebug.lock */
394
    rc = _thread_op_begin(t, false);
388
    rc = _thread_op_begin(t, false);
Line 425... Line 419...
425
        return EBUSY;
419
        return EBUSY;
426
    }
420
    }
427
 
421
 
428
    data_buffer = malloc(n, 0);
422
    data_buffer = malloc(n, 0);
429
 
423
 
430
//  printf("udebug_mem_read: src=%u, size=%u\n", uspace_addr, n);
-
 
431
 
-
 
432
    /* NOTE: this is not strictly from a syscall... but that shouldn't
424
    /* NOTE: this is not strictly from a syscall... but that shouldn't
433
     * be a problem */
425
     * be a problem */
434
    rc = copy_from_uspace(data_buffer, (void *)uspace_addr, n);
426
    rc = copy_from_uspace(data_buffer, (void *)uspace_addr, n);
435
    mutex_unlock(&TASK->udebug.lock);
427
    mutex_unlock(&TASK->udebug.lock);
436
 
428