Rev 2805 | Rev 2808 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2805 | Rev 2807 | ||
|---|---|---|---|
| Line 303... | Line 303... | ||
| 303 | spinlock_lock(&ta->lock); |
303 | spinlock_lock(&ta->lock); |
| 304 | 304 | ||
| 305 | return ta; |
305 | return ta; |
| 306 | } |
306 | } |
| 307 | 307 | ||
| - | 308 | static thread_t *get_task_thread_by_id(task_t *ta, thread_id_t tid) |
|
| - | 309 | { |
|
| - | 310 | thread_t *t; |
|
| - | 311 | link_t *cur; |
|
| - | 312 | ||
| - | 313 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
|
| - | 314 | t = list_get_instance(cur, thread_t, th_link); |
|
| - | 315 | if (tid == t->tid) return t; |
|
| - | 316 | } |
|
| - | 317 | ||
| - | 318 | return NULL; |
|
| - | 319 | } |
|
| - | 320 | ||
| 308 | #include <console/klog.h> |
321 | #include <console/klog.h> |
| 309 | 322 | ||
| 310 | static int debug_begin(call_t *call, phone_t *phone) |
323 | static int debug_begin(call_t *call, phone_t *phone) |
| 311 | { |
324 | { |
| 312 | task_t *ta; |
325 | task_t *ta; |
| Line 338... | Line 351... | ||
| 338 | 351 | ||
| 339 | klog_printf("debug_begin() done (wait for stoppability)"); |
352 | klog_printf("debug_begin() done (wait for stoppability)"); |
| 340 | return 0; |
353 | return 0; |
| 341 | } |
354 | } |
| 342 | 355 | ||
| 343 | static void debug_go(call_t *call, phone_t *phone) |
356 | static int debug_go(call_t *call, phone_t *phone) |
| 344 | { |
357 | { |
| 345 | thread_t *t; |
358 | thread_t *t; |
| 346 | link_t *l; |
- | |
| 347 | task_t *ta; |
359 | task_t *ta; |
| 348 | 360 | ||
| 349 | klog_printf("debug_go()"); |
361 | klog_printf("debug_go()"); |
| 350 | ta = get_lock_callee_task(phone); |
362 | ta = get_lock_callee_task(phone); |
| 351 | 363 | ||
| 352 | ta->debug_go_call = call; |
364 | ta->debug_go_call = call; |
| 353 | - | ||
| 354 | l = ta->th_head.next; |
365 | t = get_task_thread_by_id(ta, IPC_GET_ARG1(call->data)); |
| 355 | if (l != &TASK->th_head) { |
366 | if (t == NULL) { |
| 356 | t = list_get_instance(l, thread_t, th_link); |
- | |
| 357 | klog_printf("debug_go(): waitq_wakeup"); |
367 | spinlock_unlock(&ta->lock); |
| 358 | waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
368 | return ENOENT; |
| 359 | } |
369 | } |
| 360 | 370 | ||
| - | 371 | klog_printf("debug_go(): waitq_wakeup"); |
|
| - | 372 | waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
|
| - | 373 | ||
| 361 | spinlock_unlock(&ta->lock); |
374 | spinlock_unlock(&ta->lock); |
| - | 375 | ||
| - | 376 | return 0; /* no backsend */ |
|
| 362 | } |
377 | } |
| 363 | 378 | ||
| 364 | static int debug_args_read(call_t *call, phone_t *phone) |
379 | static int debug_args_read(call_t *call, phone_t *phone) |
| 365 | { |
380 | { |
| 366 | thread_t *t; |
381 | thread_t *t; |
| 367 | link_t *l; |
- | |
| 368 | task_t *ta; |
382 | task_t *ta; |
| 369 | void *uspace_buffer; |
383 | void *uspace_buffer; |
| 370 | unative_t to_copy; |
384 | unative_t to_copy; |
| 371 | int rc; |
385 | int rc; |
| 372 | 386 | ||
| 373 | klog_printf("debug_args_read()"); |
387 | klog_printf("debug_args_read()"); |
| 374 | // FIXME: verify task/thread state |
388 | // FIXME: verify task/thread state |
| 375 | 389 | ||
| 376 | ta = get_lock_callee_task(phone); |
390 | ta = get_lock_callee_task(phone); |
| 377 | klog_printf("task %llu", ta->taskid); |
391 | klog_printf("task %llu", ta->taskid); |
| - | 392 | t = get_task_thread_by_id(ta, IPC_GET_ARG1(call->data)); |
|
| - | 393 | if (t == NULL) { |
|
| - | 394 | spinlock_unlock(&ta->lock); |
|
| - | 395 | return ENOENT; |
|
| - | 396 | } |
|
| 378 | 397 | ||
| 379 | l = ta->th_head.next; |
- | |
| 380 | if (l != &TASK->th_head) { |
- | |
| 381 | t = list_get_instance(l, thread_t, th_link); |
- | |
| 382 | /* t = requested thread */ |
- | |
| 383 | uspace_buffer = (void *)IPC_GET_ARG2(call->data); |
398 | uspace_buffer = (void *)IPC_GET_ARG2(call->data); |
| 384 | to_copy = IPC_GET_ARG3(call->data); |
399 | to_copy = IPC_GET_ARG3(call->data); |
| - | 400 | if (to_copy > 6) to_copy = 6; |
|
| - | 401 | ||
| 385 | rc = copy_to_uspace(uspace_buffer, t->syscall_args, to_copy); |
402 | rc = copy_to_uspace(uspace_buffer, t->syscall_args, to_copy); |
| 386 | if (rc != 0) { |
403 | if (rc != 0) { |
| 387 | spinlock_unlock(&ta->lock); |
404 | spinlock_unlock(&ta->lock); |
| 388 | klog_printf("debug_args_read() - copy failed"); |
405 | klog_printf("debug_args_read() - copy failed"); |
| 389 | return rc; |
406 | return rc; |
| 390 | } |
- | |
| 391 | IPC_SET_ARG1(call->data, to_copy); |
- | |
| 392 | } |
407 | } |
| 393 | 408 | ||
| 394 | spinlock_unlock(&ta->lock); |
409 | spinlock_unlock(&ta->lock); |
| 395 | 410 | ||
| - | 411 | IPC_SET_ARG1(call->data, to_copy); |
|
| - | 412 | ||
| 396 | klog_printf("debug_args_read() done"); |
413 | klog_printf("debug_args_read() done"); |
| 397 | return 1; /* actually need becksend with retval 0 */ |
414 | return 1; /* actually need becksend with retval 0 */ |
| 398 | } |
415 | } |
| 399 | 416 | ||
| - | 417 | static int debug_thread_read(call_t *call, phone_t *phone) |
|
| - | 418 | { |
|
| - | 419 | thread_t *t; |
|
| - | 420 | link_t *cur; |
|
| - | 421 | task_t *ta; |
|
| - | 422 | unative_t *uspace_buffer; |
|
| - | 423 | unative_t to_copy; |
|
| - | 424 | int rc; |
|
| - | 425 | unsigned copied, total; |
|
| - | 426 | unsigned buf_size; |
|
| - | 427 | unative_t tid; |
|
| - | 428 | ||
| - | 429 | klog_printf("debug_thread_read()"); |
|
| - | 430 | // FIXME: verify task/thread state |
|
| - | 431 | ||
| - | 432 | ta = get_lock_callee_task(phone); |
|
| - | 433 | klog_printf("task %llu", ta->taskid); |
|
| - | 434 | ||
| - | 435 | uspace_buffer = (void *)IPC_GET_ARG1(call->data); |
|
| - | 436 | buf_size = IPC_GET_ARG2(call->data); |
|
| - | 437 | ||
| - | 438 | copied = total = 0; |
|
| - | 439 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
|
| - | 440 | t = list_get_instance(cur, thread_t, th_link); |
|
| - | 441 | ||
| - | 442 | //FIXME: id cropped!! |
|
| - | 443 | tid = (unative_t) t->tid; |
|
| - | 444 | ||
| - | 445 | to_copy = sizeof(unative_t); |
|
| - | 446 | if (copied + to_copy >= buf_size) |
|
| - | 447 | to_copy = buf_size - copied; |
|
| - | 448 | ||
| - | 449 | if (to_copy > 0) { |
|
| - | 450 | rc = copy_to_uspace(uspace_buffer, &tid, to_copy); |
|
| - | 451 | if (rc != 0) { |
|
| - | 452 | spinlock_unlock(&ta->lock); |
|
| - | 453 | klog_printf("debug_thread_read() - copy failed"); |
|
| - | 454 | return rc; |
|
| - | 455 | } |
|
| - | 456 | } |
|
| - | 457 | ||
| - | 458 | ++uspace_buffer; |
|
| - | 459 | total += sizeof(unative_t); |
|
| - | 460 | copied += to_copy; |
|
| - | 461 | } |
|
| - | 462 | ||
| - | 463 | spinlock_unlock(&ta->lock); |
|
| - | 464 | ||
| - | 465 | IPC_SET_ARG1(call->data, copied); |
|
| - | 466 | IPC_SET_ARG2(call->data, total); |
|
| - | 467 | ||
| - | 468 | klog_printf("debug_thread_read() done"); |
|
| - | 469 | return 1; /* actually need becksend with retval 0 */ |
|
| - | 470 | } |
|
| - | 471 | ||
| 400 | 472 | ||
| 401 | /** Called before the request is sent. |
473 | /** Called before the request is sent. |
| 402 | * |
474 | * |
| 403 | * @param call Call structure with the request. |
475 | * @param call Call structure with the request. |
| 404 | * @param phone Phone that the call will be sent through. |
476 | * @param phone Phone that the call will be sent through. |
| Line 450... | Line 522... | ||
| 450 | case IPC_M_DEBUG_BEGIN: |
522 | case IPC_M_DEBUG_BEGIN: |
| 451 | /* actually need possibility of backsend with 0 result code */ |
523 | /* actually need possibility of backsend with 0 result code */ |
| 452 | rc = debug_begin(call, phone); |
524 | rc = debug_begin(call, phone); |
| 453 | return rc; |
525 | return rc; |
| 454 | case IPC_M_DEBUG_GO: |
526 | case IPC_M_DEBUG_GO: |
| 455 | debug_go(call, phone); |
527 | rc = debug_go(call, phone); |
| 456 | break; |
528 | return rc; |
| 457 | case IPC_M_DEBUG_ARGS_READ: |
529 | case IPC_M_DEBUG_ARGS_READ: |
| 458 | rc = debug_args_read(call, phone); |
530 | rc = debug_args_read(call, phone); |
| 459 | return rc; |
531 | return rc; |
| - | 532 | case IPC_M_DEBUG_THREAD_READ: |
|
| - | 533 | rc = debug_thread_read(call, phone); |
|
| - | 534 | return rc; |
|
| 460 | default: |
535 | default: |
| 461 | break; |
536 | break; |
| 462 | } |
537 | } |
| 463 | return 0; |
538 | return 0; |
| 464 | } |
539 | } |