[9a1b20c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2008 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 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
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 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
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 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
|
---|
| 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
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup trace
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <stdio.h>
|
---|
| 36 | #include <stdlib.h>
|
---|
| 37 | #include <unistd.h>
|
---|
| 38 | #include <fibril.h>
|
---|
| 39 | #include <errno.h>
|
---|
| 40 | #include <udebug.h>
|
---|
| 41 | #include <async.h>
|
---|
[47e0a05b] | 42 | #include <task.h>
|
---|
[3bf907a] | 43 | #include <mem.h>
|
---|
[19f857a] | 44 | #include <str.h>
|
---|
[3e6a98c5] | 45 | #include <stdbool.h>
|
---|
[4470e26] | 46 | #include <loader/loader.h>
|
---|
[9d8a1ed] | 47 | #include <io/console.h>
|
---|
| 48 | #include <io/keycode.h>
|
---|
[1e4cada] | 49 | #include <fibril_synch.h>
|
---|
[1ccafee] | 50 | #include <sys/types.h>
|
---|
| 51 | #include <sys/typefmt.h>
|
---|
[df02460] | 52 | #include <vfs/vfs.h>
|
---|
[9a1b20c] | 53 |
|
---|
[f2ef7fd] | 54 | #include <libc.h>
|
---|
| 55 |
|
---|
[28a3e74] | 56 | /* Temporary: service and method names */
|
---|
[9a1b20c] | 57 | #include "proto.h"
|
---|
| 58 | #include <ipc/services.h>
|
---|
| 59 | #include "../../srv/vfs/vfs.h"
|
---|
[d3e6935] | 60 | #include <ipc/console.h>
|
---|
[9a1b20c] | 61 |
|
---|
| 62 | #include "syscalls.h"
|
---|
| 63 | #include "ipcp.h"
|
---|
| 64 | #include "errors.h"
|
---|
[1643855] | 65 | #include "trace.h"
|
---|
[9a1b20c] | 66 |
|
---|
| 67 | #define THBUF_SIZE 64
|
---|
[a5c3f73] | 68 | uintptr_t thread_hash_buf[THBUF_SIZE];
|
---|
| 69 | int n_threads;
|
---|
[9a1b20c] | 70 |
|
---|
| 71 | int next_thread_id;
|
---|
| 72 |
|
---|
[c8404d4] | 73 | ipc_call_t thread_ipc_req[THBUF_SIZE];
|
---|
| 74 |
|
---|
[79ae36dd] | 75 | async_sess_t *sess;
|
---|
[9ad5b5cc] | 76 | bool abort_trace;
|
---|
[9a1b20c] | 77 |
|
---|
[a5c3f73] | 78 | uintptr_t thash;
|
---|
[9ad5b5cc] | 79 | static bool paused;
|
---|
| 80 | static fibril_condvar_t state_cv;
|
---|
| 81 | static fibril_mutex_t state_lock;
|
---|
[84683fdc] | 82 |
|
---|
[9ad5b5cc] | 83 | static bool cev_valid;
|
---|
[79ae36dd] | 84 | static kbd_event_t cev;
|
---|
[9a1b20c] | 85 |
|
---|
[a5c3f73] | 86 | void thread_trace_start(uintptr_t thread_hash);
|
---|
[9a1b20c] | 87 |
|
---|
[1643855] | 88 | static task_id_t task_id;
|
---|
[4470e26] | 89 | static loader_t *task_ldr;
|
---|
[9ad5b5cc] | 90 | static bool task_wait_for;
|
---|
[1643855] | 91 |
|
---|
| 92 | /** Combination of events/data to print. */
|
---|
| 93 | display_mask_t display_mask;
|
---|
[9a1b20c] | 94 |
|
---|
[4470e26] | 95 | static int program_run_fibril(void *arg);
|
---|
[84683fdc] | 96 | static int cev_fibril(void *arg);
|
---|
[4470e26] | 97 |
|
---|
| 98 | static void program_run(void)
|
---|
| 99 | {
|
---|
| 100 | fid_t fid;
|
---|
| 101 |
|
---|
| 102 | fid = fibril_create(program_run_fibril, NULL);
|
---|
| 103 | if (fid == 0) {
|
---|
| 104 | printf("Error creating fibril\n");
|
---|
| 105 | exit(1);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | fibril_add_ready(fid);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[84683fdc] | 111 | static void cev_fibril_start(void)
|
---|
| 112 | {
|
---|
| 113 | fid_t fid;
|
---|
| 114 |
|
---|
| 115 | fid = fibril_create(cev_fibril, NULL);
|
---|
| 116 | if (fid == 0) {
|
---|
| 117 | printf("Error creating fibril\n");
|
---|
| 118 | exit(1);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | fibril_add_ready(fid);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[4470e26] | 124 | static int program_run_fibril(void *arg)
|
---|
| 125 | {
|
---|
| 126 | int rc;
|
---|
| 127 |
|
---|
| 128 | /*
|
---|
| 129 | * This must be done in background as it will block until
|
---|
| 130 | * we let the task reply to this call.
|
---|
| 131 | */
|
---|
| 132 | rc = loader_run(task_ldr);
|
---|
| 133 | if (rc != 0) {
|
---|
| 134 | printf("Error running program\n");
|
---|
| 135 | exit(1);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | task_ldr = NULL;
|
---|
| 139 |
|
---|
| 140 | printf("program_run_fibril exiting\n");
|
---|
| 141 | return 0;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | static int connect_task(task_id_t task_id)
|
---|
[9a1b20c] | 146 | {
|
---|
[79ae36dd] | 147 | async_sess_t *ksess = async_connect_kbox(task_id);
|
---|
| 148 |
|
---|
| 149 | if (!ksess) {
|
---|
| 150 | if (errno == ENOTSUP) {
|
---|
| 151 | printf("You do not have userspace debugging support "
|
---|
| 152 | "compiled in the kernel.\n");
|
---|
| 153 | printf("Compile kernel with 'Support for userspace debuggers' "
|
---|
| 154 | "(CONFIG_UDEBUG) enabled.\n");
|
---|
| 155 | return errno;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[c9a29d6] | 158 | printf("Error connecting\n");
|
---|
[79ae36dd] | 159 | printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, errno);
|
---|
| 160 | return errno;
|
---|
[fb9b0b0] | 161 | }
|
---|
[79ae36dd] | 162 |
|
---|
| 163 | int rc = udebug_begin(ksess);
|
---|
[c9a29d6] | 164 | if (rc < 0) {
|
---|
| 165 | printf("udebug_begin() -> %d\n", rc);
|
---|
| 166 | return rc;
|
---|
| 167 | }
|
---|
[79ae36dd] | 168 |
|
---|
| 169 | rc = udebug_set_evmask(ksess, UDEBUG_EM_ALL);
|
---|
[c9a29d6] | 170 | if (rc < 0) {
|
---|
| 171 | printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
|
---|
| 172 | return rc;
|
---|
| 173 | }
|
---|
[79ae36dd] | 174 |
|
---|
| 175 | sess = ksess;
|
---|
[9a1b20c] | 176 | return 0;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | static int get_thread_list(void)
|
---|
| 180 | {
|
---|
| 181 | int rc;
|
---|
| 182 | size_t tb_copied;
|
---|
| 183 | size_t tb_needed;
|
---|
| 184 | int i;
|
---|
| 185 |
|
---|
[79ae36dd] | 186 | rc = udebug_thread_read(sess, thread_hash_buf,
|
---|
[9a1b20c] | 187 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
|
---|
[c9a29d6] | 188 | if (rc < 0) {
|
---|
| 189 | printf("udebug_thread_read() -> %d\n", rc);
|
---|
| 190 | return rc;
|
---|
| 191 | }
|
---|
[9a1b20c] | 192 |
|
---|
[a5c3f73] | 193 | n_threads = tb_copied / sizeof(uintptr_t);
|
---|
[9a1b20c] | 194 |
|
---|
[c9a29d6] | 195 | printf("Threads:");
|
---|
| 196 | for (i = 0; i < n_threads; i++) {
|
---|
[7e752b2] | 197 | printf(" [%d] (hash %p)", 1 + i, (void *) thread_hash_buf[i]);
|
---|
[9a1b20c] | 198 | }
|
---|
[7e752b2] | 199 | printf("\ntotal of %zu threads\n", tb_needed / sizeof(uintptr_t));
|
---|
[9a1b20c] | 200 |
|
---|
| 201 | return 0;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[356acd0] | 204 | void val_print(sysarg_t val, val_type_t v_type)
|
---|
[9a1b20c] | 205 | {
|
---|
[f019cc07] | 206 | long sval;
|
---|
| 207 |
|
---|
| 208 | sval = (long) val;
|
---|
| 209 |
|
---|
[abf3564] | 210 | switch (v_type) {
|
---|
| 211 | case V_VOID:
|
---|
| 212 | printf("<void>");
|
---|
| 213 | break;
|
---|
| 214 |
|
---|
| 215 | case V_INTEGER:
|
---|
[f019cc07] | 216 | printf("%ld", sval);
|
---|
[abf3564] | 217 | break;
|
---|
| 218 |
|
---|
| 219 | case V_HASH:
|
---|
[4470e26] | 220 | case V_PTR:
|
---|
[7e752b2] | 221 | printf("%p", (void *) val);
|
---|
[abf3564] | 222 | break;
|
---|
| 223 |
|
---|
| 224 | case V_ERRNO:
|
---|
[f019cc07] | 225 | if (sval >= -15 && sval <= 0) {
|
---|
| 226 | printf("%ld %s (%s)", sval,
|
---|
| 227 | err_desc[-sval].name,
|
---|
| 228 | err_desc[-sval].desc);
|
---|
[9a1b20c] | 229 | } else {
|
---|
[f019cc07] | 230 | printf("%ld", sval);
|
---|
[9a1b20c] | 231 | }
|
---|
[abf3564] | 232 | break;
|
---|
| 233 | case V_INT_ERRNO:
|
---|
[f019cc07] | 234 | if (sval >= -15 && sval < 0) {
|
---|
| 235 | printf("%ld %s (%s)", sval,
|
---|
| 236 | err_desc[-sval].name,
|
---|
| 237 | err_desc[-sval].desc);
|
---|
[abf3564] | 238 | } else {
|
---|
[f019cc07] | 239 | printf("%ld", sval);
|
---|
[abf3564] | 240 | }
|
---|
| 241 | break;
|
---|
| 242 |
|
---|
| 243 | case V_CHAR:
|
---|
[f019cc07] | 244 | if (sval >= 0x20 && sval < 0x7f) {
|
---|
[7e752b2] | 245 | printf("'%c'", (char) sval);
|
---|
[9a1b20c] | 246 | } else {
|
---|
[f019cc07] | 247 | switch (sval) {
|
---|
[abf3564] | 248 | case '\a': printf("'\\a'"); break;
|
---|
| 249 | case '\b': printf("'\\b'"); break;
|
---|
| 250 | case '\n': printf("'\\n'"); break;
|
---|
| 251 | case '\r': printf("'\\r'"); break;
|
---|
| 252 | case '\t': printf("'\\t'"); break;
|
---|
| 253 | case '\\': printf("'\\\\'"); break;
|
---|
[7e752b2] | 254 | default: printf("'\\x%02" PRIxn "'", val); break;
|
---|
[abf3564] | 255 | }
|
---|
[9a1b20c] | 256 | }
|
---|
[abf3564] | 257 | break;
|
---|
[9a1b20c] | 258 | }
|
---|
[abf3564] | 259 | }
|
---|
| 260 |
|
---|
| 261 |
|
---|
[356acd0] | 262 | static void print_sc_retval(sysarg_t retval, val_type_t val_type)
|
---|
[abf3564] | 263 | {
|
---|
| 264 | printf(" -> ");
|
---|
| 265 | val_print(retval, val_type);
|
---|
[9a1b20c] | 266 | putchar('\n');
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[a5c3f73] | 269 | static void print_sc_args(sysarg_t *sc_args, int n)
|
---|
[9a1b20c] | 270 | {
|
---|
| 271 | int i;
|
---|
| 272 |
|
---|
| 273 | putchar('(');
|
---|
[7e752b2] | 274 | if (n > 0) printf("%" PRIun, sc_args[0]);
|
---|
[abf3564] | 275 | for (i = 1; i < n; i++) {
|
---|
[7e752b2] | 276 | printf(", %" PRIun, sc_args[i]);
|
---|
[9a1b20c] | 277 | }
|
---|
| 278 | putchar(')');
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[a5c3f73] | 281 | static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc)
|
---|
[9a1b20c] | 282 | {
|
---|
| 283 | ipc_call_t call;
|
---|
[96b02eb9] | 284 | sysarg_t phoneid;
|
---|
[9a1b20c] | 285 |
|
---|
[f019cc07] | 286 | if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL ||
|
---|
| 287 | sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY)
|
---|
[9a1b20c] | 288 | return;
|
---|
| 289 |
|
---|
| 290 | phoneid = sc_args[0];
|
---|
| 291 |
|
---|
[228e490] | 292 | IPC_SET_IMETHOD(call, sc_args[1]);
|
---|
[9a1b20c] | 293 | IPC_SET_ARG1(call, sc_args[2]);
|
---|
| 294 | IPC_SET_ARG2(call, sc_args[3]);
|
---|
| 295 | IPC_SET_ARG3(call, sc_args[4]);
|
---|
| 296 | IPC_SET_ARG4(call, sc_args[5]);
|
---|
| 297 | IPC_SET_ARG5(call, 0);
|
---|
| 298 |
|
---|
| 299 | ipcp_call_out(phoneid, &call, sc_rc);
|
---|
| 300 | }
|
---|
| 301 |
|
---|
[a5c3f73] | 302 | static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc)
|
---|
[9a1b20c] | 303 | {
|
---|
| 304 | ipc_call_t call;
|
---|
| 305 | int rc;
|
---|
| 306 |
|
---|
[f019cc07] | 307 | if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL ||
|
---|
| 308 | sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY)
|
---|
[9a1b20c] | 309 | return;
|
---|
| 310 |
|
---|
| 311 | memset(&call, 0, sizeof(call));
|
---|
[79ae36dd] | 312 | rc = udebug_mem_read(sess, &call.args, sc_args[1], sizeof(call.args));
|
---|
[9a1b20c] | 313 |
|
---|
| 314 | if (rc >= 0) {
|
---|
| 315 | ipcp_call_out(sc_args[0], &call, sc_rc);
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[a5c3f73] | 319 | static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc)
|
---|
[9a1b20c] | 320 | {
|
---|
| 321 | ipc_call_t call;
|
---|
| 322 | int rc;
|
---|
| 323 |
|
---|
| 324 | if (sc_rc == 0) return;
|
---|
| 325 |
|
---|
| 326 | memset(&call, 0, sizeof(call));
|
---|
[79ae36dd] | 327 | rc = udebug_mem_read(sess, &call, sc_args[0], sizeof(call));
|
---|
| 328 |
|
---|
| 329 | if (rc >= 0)
|
---|
[9a1b20c] | 330 | ipcp_call_in(&call, sc_rc);
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[a5c3f73] | 333 | static void event_syscall_b(unsigned thread_id, uintptr_t thread_hash,
|
---|
| 334 | unsigned sc_id, sysarg_t sc_rc)
|
---|
[9a1b20c] | 335 | {
|
---|
[a5c3f73] | 336 | sysarg_t sc_args[6];
|
---|
[9a1b20c] | 337 | int rc;
|
---|
| 338 |
|
---|
| 339 | /* Read syscall arguments */
|
---|
[79ae36dd] | 340 | rc = udebug_args_read(sess, thread_hash, sc_args);
|
---|
[9a1b20c] | 341 |
|
---|
| 342 | if (rc < 0) {
|
---|
| 343 | printf("error\n");
|
---|
| 344 | return;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
[1643855] | 347 | if ((display_mask & DM_SYSCALL) != 0) {
|
---|
| 348 | /* Print syscall name and arguments */
|
---|
[a3b339b4] | 349 | if (syscall_desc_defined(sc_id)) {
|
---|
| 350 | printf("%s", syscall_desc[sc_id].name);
|
---|
| 351 | print_sc_args(sc_args, syscall_desc[sc_id].n_args);
|
---|
| 352 | }
|
---|
| 353 | else {
|
---|
| 354 | printf("unknown_syscall<%d>", sc_id);
|
---|
| 355 | print_sc_args(sc_args, 6);
|
---|
| 356 | }
|
---|
[1643855] | 357 | }
|
---|
[9a1b20c] | 358 | }
|
---|
| 359 |
|
---|
[a5c3f73] | 360 | static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash,
|
---|
| 361 | unsigned sc_id, sysarg_t sc_rc)
|
---|
[9a1b20c] | 362 | {
|
---|
[a5c3f73] | 363 | sysarg_t sc_args[6];
|
---|
[9a1b20c] | 364 | int rv_type;
|
---|
| 365 | int rc;
|
---|
| 366 |
|
---|
| 367 | /* Read syscall arguments */
|
---|
[79ae36dd] | 368 | rc = udebug_args_read(sess, thread_hash, sc_args);
|
---|
[9a1b20c] | 369 |
|
---|
| 370 | // printf("[%d] ", thread_id);
|
---|
| 371 |
|
---|
| 372 | if (rc < 0) {
|
---|
| 373 | printf("error\n");
|
---|
| 374 | return;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[1643855] | 377 | if ((display_mask & DM_SYSCALL) != 0) {
|
---|
| 378 | /* Print syscall return value */
|
---|
[a3b339b4] | 379 | if (syscall_desc_defined(sc_id))
|
---|
| 380 | rv_type = syscall_desc[sc_id].rv_type;
|
---|
| 381 | else
|
---|
| 382 | rv_type = V_PTR;
|
---|
[1643855] | 383 | print_sc_retval(sc_rc, rv_type);
|
---|
| 384 | }
|
---|
[9a1b20c] | 385 |
|
---|
| 386 | switch (sc_id) {
|
---|
| 387 | case SYS_IPC_CALL_ASYNC_FAST:
|
---|
| 388 | sc_ipc_call_async_fast(sc_args, sc_rc);
|
---|
| 389 | break;
|
---|
| 390 | case SYS_IPC_CALL_ASYNC_SLOW:
|
---|
| 391 | sc_ipc_call_async_slow(sc_args, sc_rc);
|
---|
| 392 | break;
|
---|
| 393 | case SYS_IPC_WAIT:
|
---|
| 394 | sc_ipc_wait(sc_args, sc_rc);
|
---|
| 395 | break;
|
---|
| 396 | default:
|
---|
| 397 | break;
|
---|
| 398 | }
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[a5c3f73] | 401 | static void event_thread_b(uintptr_t hash)
|
---|
[9a1b20c] | 402 | {
|
---|
[7e752b2] | 403 | printf("New thread, hash %p\n", (void *) hash);
|
---|
[9a1b20c] | 404 | thread_trace_start(hash);
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | static int trace_loop(void *thread_hash_arg)
|
---|
| 408 | {
|
---|
| 409 | int rc;
|
---|
| 410 | unsigned ev_type;
|
---|
[a5c3f73] | 411 | uintptr_t thread_hash;
|
---|
[9a1b20c] | 412 | unsigned thread_id;
|
---|
[a5c3f73] | 413 | sysarg_t val0, val1;
|
---|
[9a1b20c] | 414 |
|
---|
[a5c3f73] | 415 | thread_hash = (uintptr_t)thread_hash_arg;
|
---|
[9a1b20c] | 416 | thread_id = next_thread_id++;
|
---|
[c8404d4] | 417 | if (thread_id >= THBUF_SIZE) {
|
---|
| 418 | printf("Too many threads.\n");
|
---|
| 419 | return ELIMIT;
|
---|
| 420 | }
|
---|
[9a1b20c] | 421 |
|
---|
[7e752b2] | 422 | printf("Start tracing thread [%u] (hash %p).\n",
|
---|
| 423 | thread_id, (void *) thread_hash);
|
---|
[9a1b20c] | 424 |
|
---|
| 425 | while (!abort_trace) {
|
---|
| 426 |
|
---|
[84683fdc] | 427 | fibril_mutex_lock(&state_lock);
|
---|
[741fd16] | 428 | if (paused) {
|
---|
[7e752b2] | 429 | printf("Thread [%u] paused. Press R to resume.\n",
|
---|
[654a30a] | 430 | thread_id);
|
---|
| 431 |
|
---|
| 432 | while (paused)
|
---|
[84683fdc] | 433 | fibril_condvar_wait(&state_cv, &state_lock);
|
---|
[654a30a] | 434 |
|
---|
[7e752b2] | 435 | printf("Thread [%u] resumed.\n", thread_id);
|
---|
[741fd16] | 436 | }
|
---|
[84683fdc] | 437 | fibril_mutex_unlock(&state_lock);
|
---|
[741fd16] | 438 |
|
---|
[9a1b20c] | 439 | /* Run thread until an event occurs */
|
---|
[79ae36dd] | 440 | rc = udebug_go(sess, thread_hash,
|
---|
[9a1b20c] | 441 | &ev_type, &val0, &val1);
|
---|
| 442 |
|
---|
| 443 | // printf("rc = %d, ev_type=%d\n", rc, ev_type);
|
---|
| 444 | if (ev_type == UDEBUG_EVENT_FINISHED) {
|
---|
[c9a29d6] | 445 | /* Done tracing this thread */
|
---|
[9a1b20c] | 446 | break;
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | if (rc >= 0) {
|
---|
| 450 | switch (ev_type) {
|
---|
| 451 | case UDEBUG_EVENT_SYSCALL_B:
|
---|
| 452 | event_syscall_b(thread_id, thread_hash, val0, (int)val1);
|
---|
| 453 | break;
|
---|
| 454 | case UDEBUG_EVENT_SYSCALL_E:
|
---|
| 455 | event_syscall_e(thread_id, thread_hash, val0, (int)val1);
|
---|
| 456 | break;
|
---|
| 457 | case UDEBUG_EVENT_STOP:
|
---|
[c9a29d6] | 458 | printf("Stop event\n");
|
---|
[84683fdc] | 459 | fibril_mutex_lock(&state_lock);
|
---|
[9ad5b5cc] | 460 | paused = true;
|
---|
[84683fdc] | 461 | fibril_mutex_unlock(&state_lock);
|
---|
[9a1b20c] | 462 | break;
|
---|
| 463 | case UDEBUG_EVENT_THREAD_B:
|
---|
| 464 | event_thread_b(val0);
|
---|
| 465 | break;
|
---|
| 466 | case UDEBUG_EVENT_THREAD_E:
|
---|
[7e752b2] | 467 | printf("Thread %" PRIun " exited.\n", val0);
|
---|
[84683fdc] | 468 | fibril_mutex_lock(&state_lock);
|
---|
[9ad5b5cc] | 469 | abort_trace = true;
|
---|
[84683fdc] | 470 | fibril_condvar_broadcast(&state_cv);
|
---|
| 471 | fibril_mutex_unlock(&state_lock);
|
---|
[9a1b20c] | 472 | break;
|
---|
| 473 | default:
|
---|
[ef687799] | 474 | printf("Unknown event type %d.\n", ev_type);
|
---|
[9a1b20c] | 475 | break;
|
---|
| 476 | }
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | }
|
---|
| 480 |
|
---|
[ef687799] | 481 | printf("Finished tracing thread [%d].\n", thread_id);
|
---|
[9a1b20c] | 482 | return 0;
|
---|
| 483 | }
|
---|
| 484 |
|
---|
[a5c3f73] | 485 | void thread_trace_start(uintptr_t thread_hash)
|
---|
[9a1b20c] | 486 | {
|
---|
| 487 | fid_t fid;
|
---|
| 488 |
|
---|
| 489 | thash = thread_hash;
|
---|
| 490 |
|
---|
| 491 | fid = fibril_create(trace_loop, (void *)thread_hash);
|
---|
| 492 | if (fid == 0) {
|
---|
| 493 | printf("Warning: Failed creating fibril\n");
|
---|
| 494 | }
|
---|
| 495 | fibril_add_ready(fid);
|
---|
| 496 | }
|
---|
| 497 |
|
---|
[a000878c] | 498 | static loader_t *preload_task(const char *path, char **argv,
|
---|
[4470e26] | 499 | task_id_t *task_id)
|
---|
[9a1b20c] | 500 | {
|
---|
[4470e26] | 501 | loader_t *ldr;
|
---|
[9a1b20c] | 502 | int rc;
|
---|
| 503 |
|
---|
[a000878c] | 504 | /* Spawn a program loader */
|
---|
[08b777e] | 505 | ldr = loader_connect();
|
---|
[4470e26] | 506 | if (ldr == NULL)
|
---|
[a3b339b4] | 507 | return NULL;
|
---|
[4470e26] | 508 |
|
---|
| 509 | /* Get task ID. */
|
---|
| 510 | rc = loader_get_task_id(ldr, task_id);
|
---|
| 511 | if (rc != EOK)
|
---|
| 512 | goto error;
|
---|
| 513 |
|
---|
| 514 | /* Send program pathname */
|
---|
| 515 | rc = loader_set_pathname(ldr, path);
|
---|
| 516 | if (rc != EOK)
|
---|
| 517 | goto error;
|
---|
| 518 |
|
---|
| 519 | /* Send arguments */
|
---|
[a000878c] | 520 | rc = loader_set_args(ldr, (const char **) argv);
|
---|
[4470e26] | 521 | if (rc != EOK)
|
---|
| 522 | goto error;
|
---|
| 523 |
|
---|
[8e1dc00] | 524 | /* Send default files */
|
---|
[7171760] | 525 | int *files[4];
|
---|
| 526 | int fd_stdin;
|
---|
| 527 | int fd_stdout;
|
---|
| 528 | int fd_stderr;
|
---|
[8e1dc00] | 529 |
|
---|
[7171760] | 530 | if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
|
---|
| 531 | files[0] = &fd_stdin;
|
---|
[8e1dc00] | 532 | else
|
---|
| 533 | files[0] = NULL;
|
---|
| 534 |
|
---|
[7171760] | 535 | if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
|
---|
| 536 | files[1] = &fd_stdout;
|
---|
[8e1dc00] | 537 | else
|
---|
| 538 | files[1] = NULL;
|
---|
| 539 |
|
---|
[7171760] | 540 | if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
|
---|
| 541 | files[2] = &fd_stderr;
|
---|
[8e1dc00] | 542 | else
|
---|
| 543 | files[2] = NULL;
|
---|
| 544 |
|
---|
| 545 | files[3] = NULL;
|
---|
| 546 |
|
---|
| 547 | rc = loader_set_files(ldr, files);
|
---|
| 548 | if (rc != EOK)
|
---|
| 549 | goto error;
|
---|
| 550 |
|
---|
[4470e26] | 551 | /* Load the program. */
|
---|
| 552 | rc = loader_load_program(ldr);
|
---|
| 553 | if (rc != EOK)
|
---|
| 554 | goto error;
|
---|
| 555 |
|
---|
| 556 | /* Success */
|
---|
| 557 | return ldr;
|
---|
| 558 |
|
---|
| 559 | /* Error exit */
|
---|
| 560 | error:
|
---|
| 561 | loader_abort(ldr);
|
---|
| 562 | return NULL;
|
---|
| 563 | }
|
---|
[9a1b20c] | 564 |
|
---|
[84683fdc] | 565 | static int cev_fibril(void *arg)
|
---|
| 566 | {
|
---|
[07b7c48] | 567 | cons_event_t event;
|
---|
| 568 |
|
---|
[84683fdc] | 569 | (void) arg;
|
---|
[79ae36dd] | 570 |
|
---|
| 571 | console_ctrl_t *console = console_init(stdin, stdout);
|
---|
| 572 |
|
---|
[84683fdc] | 573 | while (true) {
|
---|
| 574 | fibril_mutex_lock(&state_lock);
|
---|
| 575 | while (cev_valid)
|
---|
| 576 | fibril_condvar_wait(&state_cv, &state_lock);
|
---|
| 577 | fibril_mutex_unlock(&state_lock);
|
---|
[79ae36dd] | 578 |
|
---|
[07b7c48] | 579 | if (!console_get_event(console, &event))
|
---|
[84683fdc] | 580 | return -1;
|
---|
[79ae36dd] | 581 |
|
---|
[07b7c48] | 582 | if (event.type == CEV_KEY) {
|
---|
| 583 | fibril_mutex_lock(&state_lock);
|
---|
| 584 | cev = event.ev.key;
|
---|
| 585 | cev_valid = true;
|
---|
| 586 | fibril_condvar_broadcast(&state_cv);
|
---|
| 587 | fibril_mutex_unlock(&state_lock);
|
---|
| 588 | }
|
---|
[84683fdc] | 589 | }
|
---|
| 590 | }
|
---|
| 591 |
|
---|
[4470e26] | 592 | static void trace_task(task_id_t task_id)
|
---|
| 593 | {
|
---|
[79ae36dd] | 594 | kbd_event_t ev;
|
---|
[9d8a1ed] | 595 | bool done;
|
---|
[4470e26] | 596 | int i;
|
---|
| 597 | int rc;
|
---|
[9a1b20c] | 598 |
|
---|
| 599 | ipcp_init();
|
---|
[c9a29d6] | 600 |
|
---|
[9a1b20c] | 601 | rc = get_thread_list();
|
---|
| 602 | if (rc < 0) {
|
---|
| 603 | printf("Failed to get thread list (error %d)\n", rc);
|
---|
| 604 | return;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
[9ad5b5cc] | 607 | abort_trace = false;
|
---|
[9a1b20c] | 608 |
|
---|
| 609 | for (i = 0; i < n_threads; i++) {
|
---|
| 610 | thread_trace_start(thread_hash_buf[i]);
|
---|
| 611 | }
|
---|
| 612 |
|
---|
[9d8a1ed] | 613 | done = false;
|
---|
| 614 |
|
---|
| 615 | while (!done) {
|
---|
[84683fdc] | 616 | fibril_mutex_lock(&state_lock);
|
---|
| 617 | while (!cev_valid && !abort_trace)
|
---|
| 618 | fibril_condvar_wait(&state_cv, &state_lock);
|
---|
| 619 | fibril_mutex_unlock(&state_lock);
|
---|
| 620 |
|
---|
| 621 | ev = cev;
|
---|
| 622 |
|
---|
| 623 | fibril_mutex_lock(&state_lock);
|
---|
| 624 | cev_valid = false;
|
---|
| 625 | fibril_condvar_broadcast(&state_cv);
|
---|
| 626 | fibril_mutex_unlock(&state_lock);
|
---|
| 627 |
|
---|
| 628 | if (abort_trace)
|
---|
| 629 | break;
|
---|
[9d8a1ed] | 630 |
|
---|
| 631 | if (ev.type != KEY_PRESS)
|
---|
| 632 | continue;
|
---|
| 633 |
|
---|
| 634 | switch (ev.key) {
|
---|
| 635 | case KC_Q:
|
---|
| 636 | done = true;
|
---|
| 637 | break;
|
---|
| 638 | case KC_P:
|
---|
[741fd16] | 639 | printf("Pause...\n");
|
---|
[79ae36dd] | 640 | rc = udebug_stop(sess, thash);
|
---|
[654a30a] | 641 | if (rc != EOK)
|
---|
| 642 | printf("Error: stop -> %d\n", rc);
|
---|
[9d8a1ed] | 643 | break;
|
---|
| 644 | case KC_R:
|
---|
[84683fdc] | 645 | fibril_mutex_lock(&state_lock);
|
---|
[9ad5b5cc] | 646 | paused = false;
|
---|
[84683fdc] | 647 | fibril_condvar_broadcast(&state_cv);
|
---|
| 648 | fibril_mutex_unlock(&state_lock);
|
---|
[741fd16] | 649 | printf("Resume...\n");
|
---|
[9d8a1ed] | 650 | break;
|
---|
[7c014d1] | 651 | default:
|
---|
| 652 | break;
|
---|
[9a1b20c] | 653 | }
|
---|
| 654 | }
|
---|
| 655 |
|
---|
[c9a29d6] | 656 | printf("\nTerminate debugging session...\n");
|
---|
[9ad5b5cc] | 657 | abort_trace = true;
|
---|
[79ae36dd] | 658 | udebug_end(sess);
|
---|
| 659 | async_hangup(sess);
|
---|
[9a1b20c] | 660 |
|
---|
| 661 | ipcp_cleanup();
|
---|
| 662 |
|
---|
[c9a29d6] | 663 | printf("Done\n");
|
---|
[9a1b20c] | 664 | return;
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 | static void main_init(void)
|
---|
| 668 | {
|
---|
| 669 | proto_t *p;
|
---|
| 670 | oper_t *o;
|
---|
| 671 |
|
---|
[abf3564] | 672 | val_type_t arg_def[OPER_MAX_ARGS] = {
|
---|
| 673 | V_INTEGER,
|
---|
| 674 | V_INTEGER,
|
---|
| 675 | V_INTEGER,
|
---|
| 676 | V_INTEGER,
|
---|
| 677 | V_INTEGER
|
---|
| 678 | };
|
---|
| 679 |
|
---|
| 680 | val_type_t resp_def[OPER_MAX_ARGS] = {
|
---|
| 681 | V_INTEGER,
|
---|
| 682 | V_INTEGER,
|
---|
| 683 | V_INTEGER,
|
---|
| 684 | V_INTEGER,
|
---|
[fa09449] | 685 | V_INTEGER
|
---|
[abf3564] | 686 | };
|
---|
| 687 |
|
---|
[9a1b20c] | 688 | next_thread_id = 1;
|
---|
[9ad5b5cc] | 689 | paused = false;
|
---|
| 690 | cev_valid = false;
|
---|
[84683fdc] | 691 |
|
---|
| 692 | fibril_mutex_initialize(&state_lock);
|
---|
| 693 | fibril_condvar_initialize(&state_cv);
|
---|
[9a1b20c] | 694 |
|
---|
| 695 | proto_init();
|
---|
| 696 |
|
---|
| 697 | p = proto_new("vfs");
|
---|
[abf3564] | 698 | o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
|
---|
[4198f9c3] | 699 | proto_add_oper(p, VFS_IN_READ, o);
|
---|
[abf3564] | 700 | o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
|
---|
[4198f9c3] | 701 | proto_add_oper(p, VFS_IN_WRITE, o);
|
---|
[a5facfb] | 702 | o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def);
|
---|
| 703 | proto_add_oper(p, VFS_IN_SEEK, o);
|
---|
[abf3564] | 704 | o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
|
---|
[4198f9c3] | 705 | proto_add_oper(p, VFS_IN_TRUNCATE, o);
|
---|
[a5facfb] | 706 | o = oper_new("fstat", 1, arg_def, V_ERRNO, 0, resp_def);
|
---|
| 707 | proto_add_oper(p, VFS_IN_FSTAT, o);
|
---|
| 708 | o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def);
|
---|
| 709 | proto_add_oper(p, VFS_IN_CLOSE, o);
|
---|
[abf3564] | 710 | o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def);
|
---|
[4198f9c3] | 711 | proto_add_oper(p, VFS_IN_MOUNT, o);
|
---|
[abf3564] | 712 | /* o = oper_new("unmount", 0, arg_def);
|
---|
[4198f9c3] | 713 | proto_add_oper(p, VFS_IN_UNMOUNT, o);*/
|
---|
[a5facfb] | 714 | o = oper_new("sync", 1, arg_def, V_ERRNO, 0, resp_def);
|
---|
| 715 | proto_add_oper(p, VFS_IN_SYNC, o);
|
---|
[741a7af9] | 716 | o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def);
|
---|
[4198f9c3] | 717 | proto_add_oper(p, VFS_IN_UNLINK, o);
|
---|
[741a7af9] | 718 | o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def);
|
---|
[4198f9c3] | 719 | proto_add_oper(p, VFS_IN_RENAME, o);
|
---|
[ff8c87c] | 720 | o = oper_new("walk", 3, arg_def, V_INT_ERRNO, 0, resp_def);
|
---|
| 721 | proto_add_oper(p, VFS_IN_WALK, o);
|
---|
| 722 | o = oper_new("open2", 2, arg_def, V_ERRNO, 0, resp_def);
|
---|
| 723 | proto_add_oper(p, VFS_IN_OPEN2, o);
|
---|
[9a1b20c] | 724 |
|
---|
| 725 | proto_register(SERVICE_VFS, p);
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | static void print_syntax()
|
---|
| 729 | {
|
---|
[47e0a05b] | 730 | printf("Syntax:\n");
|
---|
| 731 | printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n");
|
---|
| 732 | printf("or\ttrace [+<events>] -t <task_id>\n");
|
---|
[1643855] | 733 | printf("Events: (default is +tp)\n");
|
---|
| 734 | printf("\n");
|
---|
| 735 | printf("\tt ... Thread creation and termination\n");
|
---|
| 736 | printf("\ts ... System calls\n");
|
---|
| 737 | printf("\ti ... Low-level IPC\n");
|
---|
| 738 | printf("\tp ... Protocol level\n");
|
---|
| 739 | printf("\n");
|
---|
[47e0a05b] | 740 | printf("Examples:\n");
|
---|
| 741 | printf("\ttrace +s /app/tetris\n");
|
---|
| 742 | printf("\ttrace +tsip -t 12\n");
|
---|
[9a1b20c] | 743 | }
|
---|
| 744 |
|
---|
[a000878c] | 745 | static display_mask_t parse_display_mask(const char *text)
|
---|
[9a1b20c] | 746 | {
|
---|
[f1cc9db] | 747 | display_mask_t dm = 0;
|
---|
[a000878c] | 748 | const char *c = text;
|
---|
| 749 |
|
---|
[1643855] | 750 | while (*c) {
|
---|
| 751 | switch (*c) {
|
---|
[a000878c] | 752 | case 't':
|
---|
| 753 | dm = dm | DM_THREAD;
|
---|
| 754 | break;
|
---|
| 755 | case 's':
|
---|
| 756 | dm = dm | DM_SYSCALL;
|
---|
| 757 | break;
|
---|
| 758 | case 'i':
|
---|
| 759 | dm = dm | DM_IPC;
|
---|
| 760 | break;
|
---|
| 761 | case 'p':
|
---|
| 762 | dm = dm | DM_SYSTEM | DM_USER;
|
---|
| 763 | break;
|
---|
[1643855] | 764 | default:
|
---|
[ef687799] | 765 | printf("Unexpected event type '%c'.\n", *c);
|
---|
[1643855] | 766 | exit(1);
|
---|
| 767 | }
|
---|
[a000878c] | 768 |
|
---|
[1643855] | 769 | ++c;
|
---|
| 770 | }
|
---|
[a000878c] | 771 |
|
---|
[1643855] | 772 | return dm;
|
---|
| 773 | }
|
---|
| 774 |
|
---|
| 775 | static int parse_args(int argc, char *argv[])
|
---|
| 776 | {
|
---|
[9a1b20c] | 777 | char *err_p;
|
---|
| 778 |
|
---|
[47e0a05b] | 779 | task_id = 0;
|
---|
| 780 |
|
---|
[a000878c] | 781 | --argc;
|
---|
| 782 | ++argv;
|
---|
[1643855] | 783 |
|
---|
[47e0a05b] | 784 | while (argc > 0) {
|
---|
[a000878c] | 785 | char *arg = *argv;
|
---|
[1643855] | 786 | if (arg[0] == '+') {
|
---|
| 787 | display_mask = parse_display_mask(&arg[1]);
|
---|
[47e0a05b] | 788 | } else if (arg[0] == '-') {
|
---|
| 789 | if (arg[1] == 't') {
|
---|
| 790 | /* Trace an already running task */
|
---|
[a000878c] | 791 | --argc;
|
---|
| 792 | ++argv;
|
---|
[47e0a05b] | 793 | task_id = strtol(*argv, &err_p, 10);
|
---|
[4470e26] | 794 | task_ldr = NULL;
|
---|
[9ad5b5cc] | 795 | task_wait_for = false;
|
---|
[47e0a05b] | 796 | if (*err_p) {
|
---|
| 797 | printf("Task ID syntax error\n");
|
---|
| 798 | print_syntax();
|
---|
| 799 | return -1;
|
---|
| 800 | }
|
---|
| 801 | } else {
|
---|
[7e752b2] | 802 | printf("Uknown option '%c'\n", arg[0]);
|
---|
[47e0a05b] | 803 | print_syntax();
|
---|
| 804 | return -1;
|
---|
| 805 | }
|
---|
[1643855] | 806 | } else {
|
---|
[47e0a05b] | 807 | break;
|
---|
[1643855] | 808 | }
|
---|
[a000878c] | 809 |
|
---|
| 810 | --argc;
|
---|
| 811 | ++argv;
|
---|
[1643855] | 812 | }
|
---|
| 813 |
|
---|
[47e0a05b] | 814 | if (task_id != 0) {
|
---|
[a000878c] | 815 | if (argc == 0)
|
---|
| 816 | return 0;
|
---|
[47e0a05b] | 817 | printf("Extra arguments\n");
|
---|
[9a1b20c] | 818 | print_syntax();
|
---|
[47e0a05b] | 819 | return -1;
|
---|
[9a1b20c] | 820 | }
|
---|
| 821 |
|
---|
[47e0a05b] | 822 | if (argc < 1) {
|
---|
| 823 | printf("Missing argument\n");
|
---|
[9a1b20c] | 824 | print_syntax();
|
---|
[1643855] | 825 | return -1;
|
---|
[9a1b20c] | 826 | }
|
---|
| 827 |
|
---|
[4470e26] | 828 | /* Preload the specified program file. */
|
---|
[47e0a05b] | 829 | printf("Spawning '%s' with arguments:\n", *argv);
|
---|
[a000878c] | 830 |
|
---|
| 831 | char **cp = argv;
|
---|
| 832 | while (*cp)
|
---|
| 833 | printf("'%s'\n", *cp++);
|
---|
| 834 |
|
---|
[4470e26] | 835 | task_ldr = preload_task(*argv, argv, &task_id);
|
---|
[9ad5b5cc] | 836 | task_wait_for = true;
|
---|
[47e0a05b] | 837 |
|
---|
[1643855] | 838 | return 0;
|
---|
| 839 | }
|
---|
| 840 |
|
---|
| 841 | int main(int argc, char *argv[])
|
---|
| 842 | {
|
---|
[4470e26] | 843 | int rc;
|
---|
[6e3a44a] | 844 | task_exit_t texit;
|
---|
| 845 | int retval;
|
---|
[4470e26] | 846 |
|
---|
[1643855] | 847 | printf("System Call / IPC Tracer\n");
|
---|
[ef687799] | 848 | printf("Controls: Q - Quit, P - Pause, R - Resume\n");
|
---|
[1643855] | 849 |
|
---|
| 850 | display_mask = DM_THREAD | DM_SYSTEM | DM_USER;
|
---|
| 851 |
|
---|
| 852 | if (parse_args(argc, argv) < 0)
|
---|
| 853 | return 1;
|
---|
| 854 |
|
---|
[9a1b20c] | 855 | main_init();
|
---|
[4470e26] | 856 |
|
---|
| 857 | rc = connect_task(task_id);
|
---|
| 858 | if (rc < 0) {
|
---|
[7e752b2] | 859 | printf("Failed connecting to task %" PRIu64 ".\n", task_id);
|
---|
[4470e26] | 860 | return 1;
|
---|
| 861 | }
|
---|
| 862 |
|
---|
[7e752b2] | 863 | printf("Connected to task %" PRIu64 ".\n", task_id);
|
---|
[4470e26] | 864 |
|
---|
[6e3a44a] | 865 | if (task_ldr != NULL)
|
---|
[4470e26] | 866 | program_run();
|
---|
| 867 |
|
---|
[84683fdc] | 868 | cev_fibril_start();
|
---|
[4470e26] | 869 | trace_task(task_id);
|
---|
[1643855] | 870 |
|
---|
[6e3a44a] | 871 | if (task_wait_for) {
|
---|
| 872 | printf("Waiting for task to exit.\n");
|
---|
| 873 |
|
---|
| 874 | rc = task_wait(task_id, &texit, &retval);
|
---|
| 875 | if (rc != EOK) {
|
---|
| 876 | printf("Failed waiting for task.\n");
|
---|
| 877 | return -1;
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | if (texit == TASK_EXIT_NORMAL) {
|
---|
| 881 | printf("Task exited normally, return value %d.\n",
|
---|
| 882 | retval);
|
---|
| 883 | } else {
|
---|
| 884 | printf("Task exited unexpectedly.\n");
|
---|
| 885 | }
|
---|
| 886 | }
|
---|
| 887 |
|
---|
[1643855] | 888 | return 0;
|
---|
[9a1b20c] | 889 | }
|
---|
| 890 |
|
---|
| 891 | /** @}
|
---|
| 892 | */
|
---|