Rev 4389 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4389 | Rev 4691 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | #include <fibril.h> |
39 | #include <fibril.h> |
40 | #include <errno.h> |
40 | #include <errno.h> |
41 | #include <udebug.h> |
41 | #include <udebug.h> |
42 | #include <async.h> |
42 | #include <async.h> |
43 | #include <task.h> |
43 | #include <task.h> |
- | 44 | #include <mem.h> |
|
- | 45 | #include <string.h> |
|
- | 46 | #include <bool.h> |
|
44 | #include <loader/loader.h> |
47 | #include <loader/loader.h> |
- | 48 | #include <io/console.h> |
|
- | 49 | #include <io/keycode.h> |
|
- | 50 | #include <fibril_sync.h> |
|
45 | 51 | ||
46 | #include <libc.h> |
52 | #include <libc.h> |
47 | 53 | ||
48 | // Temporary: service and method names |
54 | // Temporary: service and method names |
49 | #include "proto.h" |
55 | #include "proto.h" |
Line 60... | Line 66... | ||
60 | uintptr_t thread_hash_buf[THBUF_SIZE]; |
66 | uintptr_t thread_hash_buf[THBUF_SIZE]; |
61 | int n_threads; |
67 | int n_threads; |
62 | 68 | ||
63 | int next_thread_id; |
69 | int next_thread_id; |
64 | 70 | ||
- | 71 | ipc_call_t thread_ipc_req[THBUF_SIZE]; |
|
- | 72 | ||
65 | int phoneid; |
73 | int phoneid; |
66 | int abort_trace; |
74 | bool abort_trace; |
67 | 75 | ||
68 | uintptr_t thash; |
76 | uintptr_t thash; |
69 | volatile int paused; |
77 | static bool paused; |
- | 78 | static fibril_condvar_t state_cv; |
|
- | 79 | static fibril_mutex_t state_lock; |
|
- | 80 | ||
- | 81 | static bool cev_valid; |
|
- | 82 | static console_event_t cev; |
|
70 | 83 | ||
71 | void thread_trace_start(uintptr_t thread_hash); |
84 | void thread_trace_start(uintptr_t thread_hash); |
72 | 85 | ||
73 | static proto_t *proto_console; |
86 | static proto_t *proto_console; |
74 | static task_id_t task_id; |
87 | static task_id_t task_id; |
75 | static loader_t *task_ldr; |
88 | static loader_t *task_ldr; |
- | 89 | static bool task_wait_for; |
|
76 | 90 | ||
77 | /** Combination of events/data to print. */ |
91 | /** Combination of events/data to print. */ |
78 | display_mask_t display_mask; |
92 | display_mask_t display_mask; |
79 | 93 | ||
80 | static int program_run_fibril(void *arg); |
94 | static int program_run_fibril(void *arg); |
- | 95 | static int cev_fibril(void *arg); |
|
81 | 96 | ||
82 | static void program_run(void) |
97 | static void program_run(void) |
83 | { |
98 | { |
84 | fid_t fid; |
99 | fid_t fid; |
85 | 100 | ||
Line 90... | Line 105... | ||
90 | } |
105 | } |
91 | 106 | ||
92 | fibril_add_ready(fid); |
107 | fibril_add_ready(fid); |
93 | } |
108 | } |
94 | 109 | ||
- | 110 | static void cev_fibril_start(void) |
|
- | 111 | { |
|
- | 112 | fid_t fid; |
|
- | 113 | ||
- | 114 | fid = fibril_create(cev_fibril, NULL); |
|
- | 115 | if (fid == 0) { |
|
- | 116 | printf("Error creating fibril\n"); |
|
- | 117 | exit(1); |
|
- | 118 | } |
|
- | 119 | ||
- | 120 | fibril_add_ready(fid); |
|
- | 121 | } |
|
- | 122 | ||
95 | static int program_run_fibril(void *arg) |
123 | static int program_run_fibril(void *arg) |
96 | { |
124 | { |
97 | int rc; |
125 | int rc; |
98 | 126 | ||
99 | /* |
127 | /* |
Line 176... | Line 204... | ||
176 | return 0; |
204 | return 0; |
177 | } |
205 | } |
178 | 206 | ||
179 | void val_print(sysarg_t val, val_type_t v_type) |
207 | void val_print(sysarg_t val, val_type_t v_type) |
180 | { |
208 | { |
- | 209 | long sval; |
|
- | 210 | ||
- | 211 | sval = (long) val; |
|
- | 212 | ||
181 | switch (v_type) { |
213 | switch (v_type) { |
182 | case V_VOID: |
214 | case V_VOID: |
183 | printf("<void>"); |
215 | printf("<void>"); |
184 | break; |
216 | break; |
185 | 217 | ||
186 | case V_INTEGER: |
218 | case V_INTEGER: |
187 | printf("%ld", val); |
219 | printf("%ld", sval); |
188 | break; |
220 | break; |
189 | 221 | ||
190 | case V_HASH: |
222 | case V_HASH: |
191 | case V_PTR: |
223 | case V_PTR: |
192 | printf("0x%08lx", val); |
224 | printf("0x%08lx", val); |
193 | break; |
225 | break; |
194 | 226 | ||
195 | case V_ERRNO: |
227 | case V_ERRNO: |
196 | if (val >= -15 && val <= 0) { |
228 | if (sval >= -15 && sval <= 0) { |
197 | printf("%ld %s (%s)", val, |
229 | printf("%ld %s (%s)", sval, |
198 | err_desc[-val].name, |
230 | err_desc[-sval].name, |
199 | err_desc[-val].desc); |
231 | err_desc[-sval].desc); |
200 | } else { |
232 | } else { |
201 | printf("%ld", val); |
233 | printf("%ld", sval); |
202 | } |
234 | } |
203 | break; |
235 | break; |
204 | case V_INT_ERRNO: |
236 | case V_INT_ERRNO: |
205 | if (val >= -15 && val < 0) { |
237 | if (sval >= -15 && sval < 0) { |
206 | printf("%ld %s (%s)", val, |
238 | printf("%ld %s (%s)", sval, |
207 | err_desc[-val].name, |
239 | err_desc[-sval].name, |
208 | err_desc[-val].desc); |
240 | err_desc[-sval].desc); |
209 | } else { |
241 | } else { |
210 | printf("%ld", val); |
242 | printf("%ld", sval); |
211 | } |
243 | } |
212 | break; |
244 | break; |
213 | 245 | ||
214 | case V_CHAR: |
246 | case V_CHAR: |
215 | if (val >= 0x20 && val < 0x7f) { |
247 | if (sval >= 0x20 && sval < 0x7f) { |
216 | printf("'%c'", val); |
248 | printf("'%c'", sval); |
217 | } else { |
249 | } else { |
218 | switch (val) { |
250 | switch (sval) { |
219 | case '\a': printf("'\\a'"); break; |
251 | case '\a': printf("'\\a'"); break; |
220 | case '\b': printf("'\\b'"); break; |
252 | case '\b': printf("'\\b'"); break; |
221 | case '\n': printf("'\\n'"); break; |
253 | case '\n': printf("'\\n'"); break; |
222 | case '\r': printf("'\\r'"); break; |
254 | case '\r': printf("'\\r'"); break; |
223 | case '\t': printf("'\\t'"); break; |
255 | case '\t': printf("'\\t'"); break; |
Line 252... | Line 284... | ||
252 | static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc) |
284 | static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc) |
253 | { |
285 | { |
254 | ipc_call_t call; |
286 | ipc_call_t call; |
255 | ipcarg_t phoneid; |
287 | ipcarg_t phoneid; |
256 | 288 | ||
- | 289 | if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL || |
|
257 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
290 | sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY) |
258 | return; |
291 | return; |
259 | 292 | ||
260 | phoneid = sc_args[0]; |
293 | phoneid = sc_args[0]; |
261 | 294 | ||
262 | IPC_SET_METHOD(call, sc_args[1]); |
295 | IPC_SET_METHOD(call, sc_args[1]); |
Line 272... | Line 305... | ||
272 | static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc) |
305 | static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc) |
273 | { |
306 | { |
274 | ipc_call_t call; |
307 | ipc_call_t call; |
275 | int rc; |
308 | int rc; |
276 | 309 | ||
- | 310 | if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL || |
|
277 | if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
311 | sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY) |
278 | return; |
312 | return; |
279 | 313 | ||
280 | memset(&call, 0, sizeof(call)); |
314 | memset(&call, 0, sizeof(call)); |
281 | rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
315 | rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args)); |
282 | 316 | ||
Line 311... | Line 345... | ||
311 | 345 | ||
312 | // printf("call ipc_call_sync\n"); |
346 | // printf("call ipc_call_sync\n"); |
313 | ipcp_call_sync(phoneidx, &question, &reply); |
347 | ipcp_call_sync(phoneidx, &question, &reply); |
314 | } |
348 | } |
315 | 349 | ||
316 | static void sc_ipc_call_sync_slow(sysarg_t *sc_args) |
350 | static void sc_ipc_call_sync_slow_b(unsigned thread_id, sysarg_t *sc_args) |
317 | { |
351 | { |
318 | ipc_call_t question, reply; |
352 | ipc_call_t question; |
319 | int rc; |
353 | int rc; |
320 | 354 | ||
321 | memset(&question, 0, sizeof(question)); |
355 | memset(&question, 0, sizeof(question)); |
322 | rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
356 | rc = udebug_mem_read(phoneid, &question.args, sc_args[1], |
- | 357 | sizeof(question.args)); |
|
- | 358 | ||
- | 359 | if (rc < 0) { |
|
323 | printf("dmr->%d\n", rc); |
360 | printf("Error: mem_read->%d\n", rc); |
- | 361 | return; |
|
- | 362 | } |
|
- | 363 | ||
- | 364 | thread_ipc_req[thread_id] = question; |
|
- | 365 | } |
|
- | 366 | ||
- | 367 | static void sc_ipc_call_sync_slow_e(unsigned thread_id, sysarg_t *sc_args) |
|
- | 368 | { |
|
324 | if (rc < 0) return; |
369 | ipc_call_t reply; |
- | 370 | int rc; |
|
325 | 371 | ||
326 | memset(&reply, 0, sizeof(reply)); |
372 | memset(&reply, 0, sizeof(reply)); |
327 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
373 | rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], |
- | 374 | sizeof(reply.args)); |
|
- | 375 | ||
- | 376 | if (rc < 0) { |
|
328 | printf("dmr->%d\n", rc); |
377 | printf("Error: mem_read->%d\n", rc); |
329 | if (rc < 0) return; |
378 | return; |
- | 379 | } |
|
330 | 380 | ||
331 | ipcp_call_sync(sc_args[0], &question, &reply); |
381 | ipcp_call_sync(sc_args[0], &thread_ipc_req[thread_id], &reply); |
332 | } |
382 | } |
333 | 383 | ||
334 | static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc) |
384 | static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc) |
335 | { |
385 | { |
336 | ipc_call_t call; |
386 | ipc_call_t call; |
Line 371... | Line 421... | ||
371 | /* Print syscall name and arguments */ |
421 | /* Print syscall name and arguments */ |
372 | printf("%s", syscall_desc[sc_id].name); |
422 | printf("%s", syscall_desc[sc_id].name); |
373 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
423 | print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
374 | } |
424 | } |
375 | 425 | ||
- | 426 | switch (sc_id) { |
|
- | 427 | case SYS_IPC_CALL_SYNC_SLOW: |
|
- | 428 | sc_ipc_call_sync_slow_b(thread_id, sc_args); |
|
- | 429 | break; |
|
- | 430 | default: |
|
- | 431 | break; |
|
- | 432 | } |
|
- | 433 | ||
376 | async_serialize_end(); |
434 | async_serialize_end(); |
377 | } |
435 | } |
378 | 436 | ||
379 | static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash, |
437 | static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash, |
380 | unsigned sc_id, sysarg_t sc_rc) |
438 | unsigned sc_id, sysarg_t sc_rc) |
Line 411... | Line 469... | ||
411 | break; |
469 | break; |
412 | case SYS_IPC_CALL_SYNC_FAST: |
470 | case SYS_IPC_CALL_SYNC_FAST: |
413 | sc_ipc_call_sync_fast(sc_args); |
471 | sc_ipc_call_sync_fast(sc_args); |
414 | break; |
472 | break; |
415 | case SYS_IPC_CALL_SYNC_SLOW: |
473 | case SYS_IPC_CALL_SYNC_SLOW: |
416 | sc_ipc_call_sync_slow(sc_args); |
474 | sc_ipc_call_sync_slow_e(thread_id, sc_args); |
417 | break; |
475 | break; |
418 | case SYS_IPC_WAIT: |
476 | case SYS_IPC_WAIT: |
419 | sc_ipc_wait(sc_args, sc_rc); |
477 | sc_ipc_wait(sc_args, sc_rc); |
420 | break; |
478 | break; |
421 | default: |
479 | default: |
Line 442... | Line 500... | ||
442 | unsigned thread_id; |
500 | unsigned thread_id; |
443 | sysarg_t val0, val1; |
501 | sysarg_t val0, val1; |
444 | 502 | ||
445 | thread_hash = (uintptr_t)thread_hash_arg; |
503 | thread_hash = (uintptr_t)thread_hash_arg; |
446 | thread_id = next_thread_id++; |
504 | thread_id = next_thread_id++; |
- | 505 | if (thread_id >= THBUF_SIZE) { |
|
- | 506 | printf("Too many threads.\n"); |
|
- | 507 | return ELIMIT; |
|
- | 508 | } |
|
447 | 509 | ||
448 | printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash); |
510 | printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash); |
449 | 511 | ||
450 | while (!abort_trace) { |
512 | while (!abort_trace) { |
451 | 513 | ||
- | 514 | fibril_mutex_lock(&state_lock); |
|
452 | if (paused) { |
515 | if (paused) { |
453 | printf("Press R to resume (and be patient).\n"); |
516 | printf("Thread [%d] paused. Press R to resume.\n", |
454 | while (paused) { |
517 | thread_id); |
- | 518 | ||
455 | usleep(1000000); |
519 | while (paused) |
456 | fibril_yield(); |
520 | fibril_condvar_wait(&state_cv, &state_lock); |
457 | printf("."); |
- | |
458 | } |
521 | |
459 | printf("Resumed\n"); |
522 | printf("Thread [%d] resumed.\n", thread_id); |
460 | } |
523 | } |
- | 524 | fibril_mutex_unlock(&state_lock); |
|
461 | 525 | ||
462 | /* Run thread until an event occurs */ |
526 | /* Run thread until an event occurs */ |
463 | rc = udebug_go(phoneid, thread_hash, |
527 | rc = udebug_go(phoneid, thread_hash, |
464 | &ev_type, &val0, &val1); |
528 | &ev_type, &val0, &val1); |
465 | 529 | ||
Line 477... | Line 541... | ||
477 | case UDEBUG_EVENT_SYSCALL_E: |
541 | case UDEBUG_EVENT_SYSCALL_E: |
478 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
542 | event_syscall_e(thread_id, thread_hash, val0, (int)val1); |
479 | break; |
543 | break; |
480 | case UDEBUG_EVENT_STOP: |
544 | case UDEBUG_EVENT_STOP: |
481 | printf("Stop event\n"); |
545 | printf("Stop event\n"); |
- | 546 | fibril_mutex_lock(&state_lock); |
|
- | 547 | paused = true; |
|
- | 548 | fibril_mutex_unlock(&state_lock); |
|
482 | break; |
549 | break; |
483 | case UDEBUG_EVENT_THREAD_B: |
550 | case UDEBUG_EVENT_THREAD_B: |
484 | event_thread_b(val0); |
551 | event_thread_b(val0); |
485 | break; |
552 | break; |
486 | case UDEBUG_EVENT_THREAD_E: |
553 | case UDEBUG_EVENT_THREAD_E: |
487 | printf("Thread 0x%lx exited.\n", val0); |
554 | printf("Thread 0x%lx exited.\n", val0); |
- | 555 | fibril_mutex_lock(&state_lock); |
|
488 | abort_trace = 1; |
556 | abort_trace = true; |
- | 557 | fibril_condvar_broadcast(&state_cv); |
|
- | 558 | fibril_mutex_unlock(&state_lock); |
|
489 | break; |
559 | break; |
490 | default: |
560 | default: |
491 | printf("Unknown event type %d.\n", ev_type); |
561 | printf("Unknown event type %d.\n", ev_type); |
492 | break; |
562 | break; |
493 | } |
563 | } |
Line 536... | Line 606... | ||
536 | /* Send arguments */ |
606 | /* Send arguments */ |
537 | rc = loader_set_args(ldr, argv); |
607 | rc = loader_set_args(ldr, argv); |
538 | if (rc != EOK) |
608 | if (rc != EOK) |
539 | goto error; |
609 | goto error; |
540 | 610 | ||
- | 611 | /* Send default files */ |
|
- | 612 | fdi_node_t *files[4]; |
|
- | 613 | fdi_node_t stdin_node; |
|
- | 614 | fdi_node_t stdout_node; |
|
- | 615 | fdi_node_t stderr_node; |
|
- | 616 | ||
- | 617 | if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK)) |
|
- | 618 | files[0] = &stdin_node; |
|
- | 619 | else |
|
- | 620 | files[0] = NULL; |
|
- | 621 | ||
- | 622 | if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK)) |
|
- | 623 | files[1] = &stdout_node; |
|
- | 624 | else |
|
- | 625 | files[1] = NULL; |
|
- | 626 | ||
- | 627 | if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK)) |
|
- | 628 | files[2] = &stderr_node; |
|
- | 629 | else |
|
- | 630 | files[2] = NULL; |
|
- | 631 | ||
- | 632 | files[3] = NULL; |
|
- | 633 | ||
- | 634 | rc = loader_set_files(ldr, files); |
|
- | 635 | if (rc != EOK) |
|
- | 636 | goto error; |
|
- | 637 | ||
541 | /* Load the program. */ |
638 | /* Load the program. */ |
542 | rc = loader_load_program(ldr); |
639 | rc = loader_load_program(ldr); |
543 | if (rc != EOK) |
640 | if (rc != EOK) |
544 | goto error; |
641 | goto error; |
545 | 642 | ||
Line 551... | Line 648... | ||
551 | loader_abort(ldr); |
648 | loader_abort(ldr); |
552 | free(ldr); |
649 | free(ldr); |
553 | return NULL; |
650 | return NULL; |
554 | } |
651 | } |
555 | 652 | ||
- | 653 | static int cev_fibril(void *arg) |
|
- | 654 | { |
|
- | 655 | (void) arg; |
|
- | 656 | ||
- | 657 | while (true) { |
|
- | 658 | fibril_mutex_lock(&state_lock); |
|
- | 659 | while (cev_valid) |
|
- | 660 | fibril_condvar_wait(&state_cv, &state_lock); |
|
- | 661 | fibril_mutex_unlock(&state_lock); |
|
- | 662 | ||
- | 663 | if (!console_get_event(fphone(stdin), &cev)) |
|
- | 664 | return -1; |
|
- | 665 | ||
- | 666 | fibril_mutex_lock(&state_lock); |
|
- | 667 | cev_valid = true; |
|
- | 668 | fibril_condvar_broadcast(&state_cv); |
|
- | 669 | fibril_mutex_unlock(&state_lock); |
|
- | 670 | } |
|
- | 671 | } |
|
- | 672 | ||
556 | static void trace_task(task_id_t task_id) |
673 | static void trace_task(task_id_t task_id) |
557 | { |
674 | { |
- | 675 | console_event_t ev; |
|
- | 676 | bool done; |
|
558 | int i; |
677 | int i; |
559 | int rc; |
678 | int rc; |
560 | int c; |
- | |
561 | 679 | ||
562 | ipcp_init(); |
680 | ipcp_init(); |
563 | 681 | ||
564 | /* |
682 | /* |
565 | * User apps now typically have console on phone 3. |
683 | * User apps now typically have console on phone 3. |
Line 571... | Line 689... | ||
571 | if (rc < 0) { |
689 | if (rc < 0) { |
572 | printf("Failed to get thread list (error %d)\n", rc); |
690 | printf("Failed to get thread list (error %d)\n", rc); |
573 | return; |
691 | return; |
574 | } |
692 | } |
575 | 693 | ||
576 | abort_trace = 0; |
694 | abort_trace = false; |
577 | 695 | ||
578 | for (i = 0; i < n_threads; i++) { |
696 | for (i = 0; i < n_threads; i++) { |
579 | thread_trace_start(thread_hash_buf[i]); |
697 | thread_trace_start(thread_hash_buf[i]); |
580 | } |
698 | } |
581 | 699 | ||
- | 700 | done = false; |
|
- | 701 | ||
582 | while(1) { |
702 | while (!done) { |
- | 703 | fibril_mutex_lock(&state_lock); |
|
- | 704 | while (!cev_valid && !abort_trace) |
|
- | 705 | fibril_condvar_wait(&state_cv, &state_lock); |
|
- | 706 | fibril_mutex_unlock(&state_lock); |
|
- | 707 | ||
583 | c = getchar(); |
708 | ev = cev; |
- | 709 | ||
- | 710 | fibril_mutex_lock(&state_lock); |
|
- | 711 | cev_valid = false; |
|
- | 712 | fibril_condvar_broadcast(&state_cv); |
|
- | 713 | fibril_mutex_unlock(&state_lock); |
|
- | 714 | ||
584 | if (c == 'q') break; |
715 | if (abort_trace) |
- | 716 | break; |
|
- | 717 | ||
- | 718 | if (ev.type != KEY_PRESS) |
|
- | 719 | continue; |
|
- | 720 | ||
585 | if (c == 'p') { |
721 | switch (ev.key) { |
- | 722 | case KC_Q: |
|
- | 723 | done = true; |
|
- | 724 | break; |
|
- | 725 | case KC_P: |
|
586 | printf("Pause...\n"); |
726 | printf("Pause...\n"); |
587 | paused = 1; |
- | |
588 | rc = udebug_stop(phoneid, thash); |
727 | rc = udebug_stop(phoneid, thash); |
- | 728 | if (rc != EOK) |
|
589 | printf("stop -> %d\n", rc); |
729 | printf("Error: stop -> %d\n", rc); |
590 | } |
730 | break; |
591 | if (c == 'r') { |
731 | case KC_R: |
- | 732 | fibril_mutex_lock(&state_lock); |
|
592 | paused = 0; |
733 | paused = false; |
- | 734 | fibril_condvar_broadcast(&state_cv); |
|
- | 735 | fibril_mutex_unlock(&state_lock); |
|
593 | printf("Resume...\n"); |
736 | printf("Resume...\n"); |
- | 737 | break; |
|
594 | } |
738 | } |
595 | } |
739 | } |
596 | 740 | ||
597 | printf("\nTerminate debugging session...\n"); |
741 | printf("\nTerminate debugging session...\n"); |
598 | abort_trace = 1; |
742 | abort_trace = true; |
599 | udebug_end(phoneid); |
743 | udebug_end(phoneid); |
600 | ipc_hangup(phoneid); |
744 | ipc_hangup(phoneid); |
601 | 745 | ||
602 | ipcp_cleanup(); |
746 | ipcp_cleanup(); |
603 | 747 | ||
Line 625... | Line 769... | ||
625 | V_INTEGER, |
769 | V_INTEGER, |
626 | V_INTEGER |
770 | V_INTEGER |
627 | }; |
771 | }; |
628 | 772 | ||
629 | next_thread_id = 1; |
773 | next_thread_id = 1; |
630 | paused = 0; |
774 | paused = false; |
- | 775 | cev_valid = false; |
|
- | 776 | ||
- | 777 | fibril_mutex_initialize(&state_lock); |
|
- | 778 | fibril_condvar_initialize(&state_cv); |
|
631 | 779 | ||
632 | proto_init(); |
780 | proto_init(); |
633 | 781 | ||
634 | p = proto_new("vfs"); |
782 | p = proto_new("vfs"); |
- | 783 | o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def); |
|
- | 784 | proto_add_oper(p, VFS_IN_OPEN, o); |
|
- | 785 | o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def); |
|
- | 786 | proto_add_oper(p, VFS_IN_OPEN_NODE, o); |
|
635 | o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); |
787 | o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); |
636 | proto_add_oper(p, VFS_READ, o); |
788 | proto_add_oper(p, VFS_IN_READ, o); |
637 | o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def); |
789 | o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def); |
638 | proto_add_oper(p, VFS_WRITE, o); |
790 | proto_add_oper(p, VFS_IN_WRITE, o); |
- | 791 | o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def); |
|
- | 792 | proto_add_oper(p, VFS_IN_SEEK, o); |
|
639 | o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def); |
793 | o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def); |
640 | proto_add_oper(p, VFS_TRUNCATE, o); |
794 | proto_add_oper(p, VFS_IN_TRUNCATE, o); |
- | 795 | o = oper_new("fstat", 1, arg_def, V_ERRNO, 0, resp_def); |
|
- | 796 | proto_add_oper(p, VFS_IN_FSTAT, o); |
|
- | 797 | o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def); |
|
- | 798 | proto_add_oper(p, VFS_IN_CLOSE, o); |
|
641 | o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def); |
799 | o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def); |
642 | proto_add_oper(p, VFS_MOUNT, o); |
800 | proto_add_oper(p, VFS_IN_MOUNT, o); |
643 | /* o = oper_new("unmount", 0, arg_def); |
801 | /* o = oper_new("unmount", 0, arg_def); |
644 | proto_add_oper(p, VFS_UNMOUNT, o);*/ |
802 | proto_add_oper(p, VFS_IN_UNMOUNT, o);*/ |
645 | o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def); |
- | |
646 | proto_add_oper(p, VFS_OPEN, o); |
- | |
647 | o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def); |
- | |
648 | proto_add_oper(p, VFS_CLOSE, o); |
- | |
649 | o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def); |
803 | o = oper_new("sync", 1, arg_def, V_ERRNO, 0, resp_def); |
650 | proto_add_oper(p, VFS_SEEK, o); |
804 | proto_add_oper(p, VFS_IN_SYNC, o); |
651 | o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def); |
805 | o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def); |
652 | proto_add_oper(p, VFS_MKDIR, o); |
806 | proto_add_oper(p, VFS_IN_MKDIR, o); |
653 | o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def); |
807 | o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def); |
654 | proto_add_oper(p, VFS_UNLINK, o); |
808 | proto_add_oper(p, VFS_IN_UNLINK, o); |
655 | o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def); |
809 | o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def); |
656 | proto_add_oper(p, VFS_RENAME, o); |
810 | proto_add_oper(p, VFS_IN_RENAME, o); |
- | 811 | o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def); |
|
- | 812 | proto_add_oper(p, VFS_IN_STAT, o); |
|
657 | 813 | ||
658 | proto_register(SERVICE_VFS, p); |
814 | proto_register(SERVICE_VFS, p); |
659 | 815 | ||
660 | p = proto_new("console"); |
816 | p = proto_new("console"); |
- | 817 | ||
- | 818 | o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def); |
|
- | 819 | proto_add_oper(p, VFS_IN_WRITE, o); |
|
- | 820 | ||
661 | resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER; |
821 | resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER; |
662 | resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR; |
822 | resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR; |
663 | o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def); |
823 | o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def); |
664 | proto_add_oper(p, CONSOLE_GETKEY, o); |
- | |
665 | 824 | ||
666 | arg_def[0] = V_CHAR; |
825 | arg_def[0] = V_CHAR; |
667 | o = oper_new("putchar", 1, arg_def, V_VOID, 0, resp_def); |
- | |
668 | proto_add_oper(p, CONSOLE_PUTCHAR, o); |
- | |
669 | o = oper_new("write", 0, arg_def, V_VOID, 0, resp_def); |
- | |
670 | proto_add_oper(p, CONSOLE_WRITE, o); |
- | |
671 | o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def); |
826 | o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def); |
672 | proto_add_oper(p, CONSOLE_CLEAR, o); |
827 | proto_add_oper(p, CONSOLE_CLEAR, o); |
673 | 828 | ||
674 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; |
829 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; |
675 | o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def); |
830 | o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def); |
676 | proto_add_oper(p, CONSOLE_GOTO, o); |
831 | proto_add_oper(p, CONSOLE_GOTO, o); |
677 | 832 | ||
678 | resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER; |
833 | resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER; |
679 | o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def); |
834 | o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def); |
680 | proto_add_oper(p, CONSOLE_GETSIZE, o); |
835 | proto_add_oper(p, CONSOLE_GET_SIZE, o); |
681 | o = oper_new("flush", 0, arg_def, V_VOID, 0, resp_def); |
- | |
682 | proto_add_oper(p, CONSOLE_FLUSH, o); |
- | |
683 | 836 | ||
684 | arg_def[0] = V_INTEGER; |
837 | arg_def[0] = V_INTEGER; |
685 | o = oper_new("set_style", 1, arg_def, V_VOID, 0, resp_def); |
838 | o = oper_new("set_style", 1, arg_def, V_VOID, 0, resp_def); |
686 | proto_add_oper(p, CONSOLE_SET_STYLE, o); |
839 | proto_add_oper(p, CONSOLE_SET_STYLE, o); |
687 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; arg_def[2] = V_INTEGER; |
840 | arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; arg_def[2] = V_INTEGER; |
Line 755... | Line 908... | ||
755 | if (arg[1] == 't') { |
908 | if (arg[1] == 't') { |
756 | /* Trace an already running task */ |
909 | /* Trace an already running task */ |
757 | --argc; ++argv; |
910 | --argc; ++argv; |
758 | task_id = strtol(*argv, &err_p, 10); |
911 | task_id = strtol(*argv, &err_p, 10); |
759 | task_ldr = NULL; |
912 | task_ldr = NULL; |
- | 913 | task_wait_for = false; |
|
760 | if (*err_p) { |
914 | if (*err_p) { |
761 | printf("Task ID syntax error\n"); |
915 | printf("Task ID syntax error\n"); |
762 | print_syntax(); |
916 | print_syntax(); |
763 | return -1; |
917 | return -1; |
764 | } |
918 | } |
Line 792... | Line 946... | ||
792 | { |
946 | { |
793 | char **cp = argv; |
947 | char **cp = argv; |
794 | while (*cp) printf("'%s'\n", *cp++); |
948 | while (*cp) printf("'%s'\n", *cp++); |
795 | } |
949 | } |
796 | task_ldr = preload_task(*argv, argv, &task_id); |
950 | task_ldr = preload_task(*argv, argv, &task_id); |
- | 951 | task_wait_for = true; |
|
797 | 952 | ||
798 | return 0; |
953 | return 0; |
799 | } |
954 | } |
800 | 955 | ||
801 | int main(int argc, char *argv[]) |
956 | int main(int argc, char *argv[]) |
802 | { |
957 | { |
803 | int rc; |
958 | int rc; |
- | 959 | task_exit_t texit; |
|
- | 960 | int retval; |
|
804 | 961 | ||
805 | printf("System Call / IPC Tracer\n"); |
962 | printf("System Call / IPC Tracer\n"); |
806 | printf("Controls: Q - Quit, P - Pause, R - Resume\n"); |
963 | printf("Controls: Q - Quit, P - Pause, R - Resume\n"); |
807 | 964 | ||
808 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER; |
965 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER; |
Line 818... | Line 975... | ||
818 | return 1; |
975 | return 1; |
819 | } |
976 | } |
820 | 977 | ||
821 | printf("Connected to task %lld.\n", task_id); |
978 | printf("Connected to task %lld.\n", task_id); |
822 | 979 | ||
823 | if (task_ldr != NULL) { |
980 | if (task_ldr != NULL) |
824 | program_run(); |
981 | program_run(); |
825 | } |
- | |
826 | 982 | ||
- | 983 | cev_fibril_start(); |
|
827 | trace_task(task_id); |
984 | trace_task(task_id); |
828 | 985 | ||
- | 986 | if (task_wait_for) { |
|
- | 987 | printf("Waiting for task to exit.\n"); |
|
- | 988 | ||
- | 989 | rc = task_wait(task_id, &texit, &retval); |
|
- | 990 | if (rc != EOK) { |
|
- | 991 | printf("Failed waiting for task.\n"); |
|
- | 992 | return -1; |
|
- | 993 | } |
|
- | 994 | ||
- | 995 | if (texit == TASK_EXIT_NORMAL) { |
|
- | 996 | printf("Task exited normally, return value %d.\n", |
|
- | 997 | retval); |
|
- | 998 | } else { |
|
- | 999 | printf("Task exited unexpectedly.\n"); |
|
- | 1000 | } |
|
- | 1001 | } |
|
- | 1002 | ||
829 | return 0; |
1003 | return 0; |
830 | } |
1004 | } |
831 | 1005 | ||
832 | /** @} |
1006 | /** @} |
833 | */ |
1007 | */ |