Subversion Repositories HelenOS

Rev

Rev 3448 | Rev 3535 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3448 Rev 3474
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 trace
29
/** @addtogroup trace
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <stdio.h>
35
#include <stdio.h>
36
#include <stdlib.h>
36
#include <stdlib.h>
37
#include <unistd.h>
37
#include <unistd.h>
38
#include <syscall.h>
38
#include <syscall.h>
39
#include <ipc/ipc.h>
39
#include <ipc/ipc.h>
40
#include <fibril.h>
40
#include <fibril.h>
41
#include <errno.h>
41
#include <errno.h>
42
#include <udebug.h>
42
#include <udebug.h>
43
#include <async.h>
43
#include <async.h>
44
#include <task.h>
44
#include <task.h>
-
 
45
#include <loader/loader.h>
45
 
46
 
46
// Temporary: service and method names
47
// Temporary: service and method names
47
#include "proto.h"
48
#include "proto.h"
48
#include <ipc/services.h>
49
#include <ipc/services.h>
49
#include "../../srv/vfs/vfs.h"
50
#include "../../srv/vfs/vfs.h"
50
#include "../../srv/console/console.h"
51
#include "../../srv/console/console.h"
51
 
52
 
52
#include "syscalls.h"
53
#include "syscalls.h"
53
#include "ipcp.h"
54
#include "ipcp.h"
54
#include "errors.h"
55
#include "errors.h"
55
#include "trace.h"
56
#include "trace.h"
56
 
57
 
57
#define THBUF_SIZE 64
58
#define THBUF_SIZE 64
58
unsigned thread_hash_buf[THBUF_SIZE];
59
uintptr_t thread_hash_buf[THBUF_SIZE];
59
unsigned n_threads;
60
int n_threads;
60
 
61
 
61
int next_thread_id;
62
int next_thread_id;
62
 
63
 
63
int phoneid;
64
int phoneid;
64
int abort_trace;
65
int abort_trace;
65
 
66
 
66
unsigned thash;
67
uintptr_t thash;
67
volatile int paused;
68
volatile int paused;
68
 
69
 
69
void thread_trace_start(unsigned thread_hash);
70
void thread_trace_start(uintptr_t thread_hash);
70
 
71
 
71
static proto_t *proto_console;
72
static proto_t *proto_console;
72
static task_id_t task_id;
73
static task_id_t task_id;
-
 
74
static loader_t *task_ldr;
73
 
75
 
74
/** Combination of events/data to print. */
76
/** Combination of events/data to print. */
75
display_mask_t display_mask;
77
display_mask_t display_mask;
76
 
78
 
-
 
79
static int program_run_fibril(void *arg);
-
 
80
 
-
 
81
static void program_run(void)
-
 
82
{
-
 
83
    fid_t fid;
-
 
84
 
-
 
85
    fid = fibril_create(program_run_fibril, NULL);
-
 
86
    if (fid == 0) {
-
 
87
        printf("Error creating fibril\n");
-
 
88
        exit(1);
-
 
89
    }
-
 
90
 
-
 
91
    fibril_add_ready(fid);
-
 
92
}
-
 
93
 
-
 
94
static int program_run_fibril(void *arg)
-
 
95
{
-
 
96
    int rc;
-
 
97
 
-
 
98
    /*
-
 
99
     * This must be done in background as it will block until
-
 
100
     * we let the task reply to this call.
-
 
101
     */
-
 
102
    rc = loader_run(task_ldr);
-
 
103
    if (rc != 0) {
-
 
104
        printf("Error running program\n");
-
 
105
        exit(1);
-
 
106
    }
-
 
107
 
-
 
108
    free(task_ldr);
-
 
109
    task_ldr = NULL;
-
 
110
 
-
 
111
    printf("program_run_fibril exiting\n");
-
 
112
    return 0;
-
 
113
}
-
 
114
 
-
 
115
 
77
static int task_connect(task_id_t task_id)
116
static int connect_task(task_id_t task_id)
78
{
117
{
79
    int rc;
118
    int rc;
80
 
119
 
81
    rc = ipc_connect_kbox(task_id);
120
    rc = ipc_connect_kbox(task_id);
82
 
121
 
83
    if (rc == ENOTSUP) {
122
    if (rc == ENOTSUP) {
84
        printf("You do not have userspace debugging support "
123
        printf("You do not have userspace debugging support "
85
            "compiled in the kernel.\n");
124
            "compiled in the kernel.\n");
86
        printf("Compile kernel with 'Support for userspace debuggers' "
125
        printf("Compile kernel with 'Support for userspace debuggers' "
87
            "(CONFIG_UDEBUG) enabled.\n");
126
            "(CONFIG_UDEBUG) enabled.\n");
88
        return rc;
127
        return rc;
89
    }
128
    }
90
 
129
 
91
    if (rc < 0) {
130
    if (rc < 0) {
92
        printf("Error connecting\n");
131
        printf("Error connecting\n");
93
        printf("ipc_connect_task(%lld) -> %d ", task_id, rc);
132
        printf("ipc_connect_task(%lld) -> %d ", task_id, rc);
94
        return rc;
133
        return rc;
95
    }
134
    }
96
 
135
 
97
    phoneid = rc;
136
    phoneid = rc;
98
 
137
 
99
    rc = udebug_begin(phoneid);
138
    rc = udebug_begin(phoneid);
100
    if (rc < 0) {
139
    if (rc < 0) {
101
        printf("udebug_begin() -> %d\n", rc);
140
        printf("udebug_begin() -> %d\n", rc);
102
        return rc;
141
        return rc;
103
    }
142
    }
104
 
143
 
105
    rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL);
144
    rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL);
106
    if (rc < 0) {
145
    if (rc < 0) {
107
        printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
146
        printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
108
        return rc;
147
        return rc;
109
    }
148
    }
110
 
149
 
111
    return 0;
150
    return 0;
112
}
151
}
113
 
152
 
114
static int get_thread_list(void)
153
static int get_thread_list(void)
115
{
154
{
116
    int rc;
155
    int rc;
117
    size_t tb_copied;
156
    size_t tb_copied;
118
    size_t tb_needed;
157
    size_t tb_needed;
119
    int i;
158
    int i;
120
 
159
 
121
    rc = udebug_thread_read(phoneid, thread_hash_buf,
160
    rc = udebug_thread_read(phoneid, thread_hash_buf,
122
        THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
161
        THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
123
    if (rc < 0) {
162
    if (rc < 0) {
124
        printf("udebug_thread_read() -> %d\n", rc);
163
        printf("udebug_thread_read() -> %d\n", rc);
125
        return rc;
164
        return rc;
126
    }
165
    }
127
 
166
 
128
    n_threads = tb_copied / sizeof(unsigned);
167
    n_threads = tb_copied / sizeof(uintptr_t);
129
 
168
 
130
    printf("Threads:");
169
    printf("Threads:");
131
    for (i = 0; i < n_threads; i++) {
170
    for (i = 0; i < n_threads; i++) {
132
        printf(" [%d] (hash 0x%x)", 1+i, thread_hash_buf[i]);
171
        printf(" [%d] (hash 0x%lx)", 1+i, thread_hash_buf[i]);
133
    }
172
    }
134
    printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned));
173
    printf("\ntotal of %u threads\n", tb_needed / sizeof(uintptr_t));
135
 
174
 
136
    return 0;
175
    return 0;
137
}
176
}
138
 
177
 
139
static void print_sc_retval(int retval, rv_type_t rv_type)
178
void val_print(sysarg_t val, val_type_t v_type)
140
{
179
{
-
 
180
    switch (v_type) {
-
 
181
    case V_VOID:
141
    printf (" -> ");
182
        printf("<void>");
-
 
183
        break;
-
 
184
 
142
    if (rv_type == RV_INTEGER) {
185
    case V_INTEGER:
143
        printf("%d", retval);
186
        printf("%ld", val);
-
 
187
        break;
-
 
188
 
144
    } else if (rv_type == RV_HASH) {
189
    case V_HASH:
-
 
190
    case V_PTR:
145
        printf("0x%08x", retval);
191
        printf("0x%08lx", val);
-
 
192
        break;
-
 
193
 
-
 
194
    case V_ERRNO:
146
    } else if (rv_type == RV_ERRNO) {
195
        if (val >= -15 && val <= 0) {
-
 
196
            printf("%ld %s (%s)", val,
-
 
197
                err_desc[-val].name,
-
 
198
                err_desc[-val].desc);
-
 
199
        } else {
-
 
200
            printf("%ld", val);
-
 
201
        }
-
 
202
        break;
-
 
203
    case V_INT_ERRNO:
147
        if (retval >= -15 && retval <= 0) {
204
        if (val >= -15 && val < 0) {
148
            printf("%d %s (%s)", retval,
205
            printf("%ld %s (%s)", val,
149
                err_desc[retval].name,
206
                err_desc[-val].name,
150
                err_desc[retval].desc);
207
                err_desc[-val].desc);
151
        } else {
208
        } else {
152
            printf("%d", retval);
209
            printf("%ld", val);
153
        }
210
        }
-
 
211
        break;
-
 
212
 
154
    } else if (rv_type == RV_INT_ERRNO) {
213
    case V_CHAR:
155
        if (retval >= -15 && retval < 0) {
214
        if (val >= 0x20 && val < 0x7f) {
156
            printf("%d %s (%s)", retval,
215
            printf("'%c'", val);
157
                err_desc[retval].name,
-
 
158
                err_desc[retval].desc);
-
 
159
        } else {
216
        } else {
160
            printf("%d", retval);
217
            switch (val) {
-
 
218
            case '\a': printf("'\\a'"); break;
-
 
219
            case '\b': printf("'\\b'"); break;
-
 
220
            case '\n': printf("'\\n'"); break;
-
 
221
            case '\r': printf("'\\r'"); break;
-
 
222
            case '\t': printf("'\\t'"); break;
-
 
223
            case '\\': printf("'\\\\'"); break;
-
 
224
            default: printf("'\\x%02lX'", val); break;
-
 
225
            }
161
        }
226
        }
-
 
227
        break;
162
    }
228
    }
-
 
229
}
-
 
230
 
-
 
231
 
-
 
232
static void print_sc_retval(sysarg_t retval, val_type_t val_type)
-
 
233
{
-
 
234
    printf(" -> ");
-
 
235
    val_print(retval, val_type);
163
    putchar('\n');
236
    putchar('\n');
164
}
237
}
165
 
238
 
166
static void print_sc_args(unsigned *sc_args, int n)
239
static void print_sc_args(sysarg_t *sc_args, int n)
167
{
240
{
168
    int i;
241
    int i;
169
 
242
 
170
    putchar('(');
243
    putchar('(');
171
    if (n > 0) printf("%d", sc_args[0]);
244
    if (n > 0) printf("%ld", sc_args[0]);
172
    for (i=1; i<n; i++) {
245
    for (i = 1; i < n; i++) {
173
        printf(", %d", sc_args[i]);
246
        printf(", %ld", sc_args[i]);
174
    }
247
    }
175
    putchar(')');
248
    putchar(')');
176
}
249
}
177
 
250
 
178
static void sc_ipc_call_async_fast(unsigned *sc_args, int sc_rc)
251
static void sc_ipc_call_async_fast(sysarg_t *sc_args, sysarg_t sc_rc)
179
{
252
{
180
    ipc_call_t call;
253
    ipc_call_t call;
181
    int phoneid;
254
    ipcarg_t phoneid;
182
   
255
   
183
    if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
256
    if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
184
        return;
257
        return;
185
 
258
 
186
    phoneid = sc_args[0];
259
    phoneid = sc_args[0];
187
 
260
 
188
    IPC_SET_METHOD(call, sc_args[1]);
261
    IPC_SET_METHOD(call, sc_args[1]);
189
    IPC_SET_ARG1(call, sc_args[2]);
262
    IPC_SET_ARG1(call, sc_args[2]);
190
    IPC_SET_ARG2(call, sc_args[3]);
263
    IPC_SET_ARG2(call, sc_args[3]);
191
    IPC_SET_ARG3(call, sc_args[4]);
264
    IPC_SET_ARG3(call, sc_args[4]);
192
    IPC_SET_ARG4(call, sc_args[5]);
265
    IPC_SET_ARG4(call, sc_args[5]);
193
    IPC_SET_ARG5(call, 0);
266
    IPC_SET_ARG5(call, 0);
194
 
267
 
195
    ipcp_call_out(phoneid, &call, sc_rc);
268
    ipcp_call_out(phoneid, &call, sc_rc);
196
}
269
}
197
 
270
 
198
static void sc_ipc_call_async_slow(unsigned *sc_args, int sc_rc)
271
static void sc_ipc_call_async_slow(sysarg_t *sc_args, sysarg_t sc_rc)
199
{
272
{
200
    ipc_call_t call;
273
    ipc_call_t call;
201
    int rc;
274
    int rc;
202
 
275
 
203
    if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
276
    if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY)
204
        return;
277
        return;
205
 
278
 
206
    memset(&call, 0, sizeof(call));
279
    memset(&call, 0, sizeof(call));
207
    rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
280
    rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
208
 
281
 
209
    if (rc >= 0) {
282
    if (rc >= 0) {
210
        ipcp_call_out(sc_args[0], &call, sc_rc);
283
        ipcp_call_out(sc_args[0], &call, sc_rc);
211
    }
284
    }
212
}
285
}
213
 
286
 
214
static void sc_ipc_call_sync_fast(unsigned *sc_args)
287
static void sc_ipc_call_sync_fast(sysarg_t *sc_args)
215
{
288
{
216
    ipc_call_t question, reply;
289
    ipc_call_t question, reply;
217
    int rc;
290
    int rc;
218
    int phoneidx;
291
    int phoneidx;
219
 
292
 
220
//  printf("sc_ipc_call_sync_fast()\n");
293
//  printf("sc_ipc_call_sync_fast()\n");
221
    phoneidx = sc_args[0];
294
    phoneidx = sc_args[0];
222
 
295
 
223
    IPC_SET_METHOD(question, sc_args[1]);
296
    IPC_SET_METHOD(question, sc_args[1]);
224
    IPC_SET_ARG1(question, sc_args[2]);
297
    IPC_SET_ARG1(question, sc_args[2]);
225
    IPC_SET_ARG2(question, sc_args[3]);
298
    IPC_SET_ARG2(question, sc_args[3]);
226
    IPC_SET_ARG3(question, sc_args[4]);
299
    IPC_SET_ARG3(question, sc_args[4]);
227
    IPC_SET_ARG4(question, 0);
300
    IPC_SET_ARG4(question, 0);
228
    IPC_SET_ARG5(question, 0);
301
    IPC_SET_ARG5(question, 0);
229
 
302
 
230
//  printf("memset\n");
303
//  printf("memset\n");
231
    memset(&reply, 0, sizeof(reply));
304
    memset(&reply, 0, sizeof(reply));
232
//  printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n",
305
//  printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n",
233
//      phoneid, &reply.args, sc_args[5], sizeof(reply.args));
306
//      phoneid, &reply.args, sc_args[5], sizeof(reply.args));
234
    rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args));
307
    rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args));
235
//  printf("dmr->%d\n", rc);
308
//  printf("dmr->%d\n", rc);
236
    if (rc < 0) return;
309
    if (rc < 0) return;
237
 
310
 
238
//  printf("call ipc_call_sync\n");
311
//  printf("call ipc_call_sync\n");
239
    ipcp_call_sync(phoneidx, &question, &reply);
312
    ipcp_call_sync(phoneidx, &question, &reply);
240
}
313
}
241
 
314
 
242
static void sc_ipc_call_sync_slow(unsigned *sc_args)
315
static void sc_ipc_call_sync_slow(sysarg_t *sc_args)
243
{
316
{
244
    ipc_call_t question, reply;
317
    ipc_call_t question, reply;
245
    int rc;
318
    int rc;
246
 
319
 
247
    memset(&question, 0, sizeof(question));
320
    memset(&question, 0, sizeof(question));
248
    rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args));
321
    rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args));
249
    printf("dmr->%d\n", rc);
322
    printf("dmr->%d\n", rc);
250
    if (rc < 0) return;
323
    if (rc < 0) return;
251
 
324
 
252
    memset(&reply, 0, sizeof(reply));
325
    memset(&reply, 0, sizeof(reply));
253
    rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args));
326
    rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args));
254
    printf("dmr->%d\n", rc);
327
    printf("dmr->%d\n", rc);
255
    if (rc < 0) return;
328
    if (rc < 0) return;
256
 
329
 
257
    ipcp_call_sync(sc_args[0], &question, &reply);
330
    ipcp_call_sync(sc_args[0], &question, &reply);
258
}
331
}
259
 
332
 
260
static void sc_ipc_wait(unsigned *sc_args, int sc_rc)
333
static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc)
261
{
334
{
262
    ipc_call_t call;
335
    ipc_call_t call;
263
    int rc;
336
    int rc;
264
 
337
 
265
    if (sc_rc == 0) return;
338
    if (sc_rc == 0) return;
266
 
339
 
267
    memset(&call, 0, sizeof(call));
340
    memset(&call, 0, sizeof(call));
268
    rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call));
341
    rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call));
269
//  printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n",
342
//  printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n",
270
//      phoneid, (int)&call, sc_args[0], sizeof(call), rc);
343
//      phoneid, (int)&call, sc_args[0], sizeof(call), rc);
271
 
344
 
272
    if (rc >= 0) {
345
    if (rc >= 0) {
273
        ipcp_call_in(&call, sc_rc);
346
        ipcp_call_in(&call, sc_rc);
274
    }
347
    }
275
}
348
}
276
 
349
 
277
static void event_syscall_b(unsigned thread_id, unsigned thread_hash,  unsigned sc_id, int sc_rc)
350
static void event_syscall_b(unsigned thread_id, uintptr_t thread_hash,
-
 
351
    unsigned sc_id, sysarg_t sc_rc)
278
{
352
{
279
    unsigned sc_args[6];
353
    sysarg_t sc_args[6];
280
    int rc;
354
    int rc;
281
 
355
 
282
    /* Read syscall arguments */
356
    /* Read syscall arguments */
283
    rc = udebug_args_read(phoneid, thread_hash, sc_args);
357
    rc = udebug_args_read(phoneid, thread_hash, sc_args);
284
 
358
 
285
    async_serialize_start();
359
    async_serialize_start();
286
 
360
 
287
//  printf("[%d] ", thread_id);
361
//  printf("[%d] ", thread_id);
288
 
362
 
289
    if (rc < 0) {
363
    if (rc < 0) {
290
        printf("error\n");
364
        printf("error\n");
291
        async_serialize_end();
365
        async_serialize_end();
292
        return;
366
        return;
293
    }
367
    }
294
 
368
 
295
    if ((display_mask & DM_SYSCALL) != 0) {
369
    if ((display_mask & DM_SYSCALL) != 0) {
296
        /* Print syscall name and arguments */
370
        /* Print syscall name and arguments */
297
        printf("%s", syscall_desc[sc_id].name);
371
        printf("%s", syscall_desc[sc_id].name);
298
        print_sc_args(sc_args, syscall_desc[sc_id].n_args);
372
        print_sc_args(sc_args, syscall_desc[sc_id].n_args);
299
    }
373
    }
300
 
374
 
301
    async_serialize_end();
375
    async_serialize_end();
302
}
376
}
303
 
377
 
304
static void event_syscall_e(unsigned thread_id, unsigned thread_hash,  unsigned sc_id, int sc_rc)
378
static void event_syscall_e(unsigned thread_id, uintptr_t thread_hash,
-
 
379
    unsigned sc_id, sysarg_t sc_rc)
305
{
380
{
306
    unsigned sc_args[6];
381
    sysarg_t sc_args[6];
307
    int rv_type;
382
    int rv_type;
308
    int rc;
383
    int rc;
309
 
384
 
310
    /* Read syscall arguments */
385
    /* Read syscall arguments */
311
    rc = udebug_args_read(phoneid, thread_hash, sc_args);
386
    rc = udebug_args_read(phoneid, thread_hash, sc_args);
312
 
387
 
313
    async_serialize_start();
388
    async_serialize_start();
314
 
389
 
315
//  printf("[%d] ", thread_id);
390
//  printf("[%d] ", thread_id);
316
 
391
 
317
    if (rc < 0) {
392
    if (rc < 0) {
318
        printf("error\n");
393
        printf("error\n");
319
        async_serialize_end();
394
        async_serialize_end();
320
        return;
395
        return;
321
    }
396
    }
322
 
397
 
323
    if ((display_mask & DM_SYSCALL) != 0) {
398
    if ((display_mask & DM_SYSCALL) != 0) {
324
        /* Print syscall return value */
399
        /* Print syscall return value */
325
        rv_type = syscall_desc[sc_id].rv_type;
400
        rv_type = syscall_desc[sc_id].rv_type;
326
        print_sc_retval(sc_rc, rv_type);
401
        print_sc_retval(sc_rc, rv_type);
327
    }
402
    }
328
 
403
 
329
    switch (sc_id) {
404
    switch (sc_id) {
330
    case SYS_IPC_CALL_ASYNC_FAST:
405
    case SYS_IPC_CALL_ASYNC_FAST:
331
        sc_ipc_call_async_fast(sc_args, sc_rc);
406
        sc_ipc_call_async_fast(sc_args, sc_rc);
332
        break;
407
        break;
333
    case SYS_IPC_CALL_ASYNC_SLOW:
408
    case SYS_IPC_CALL_ASYNC_SLOW:
334
        sc_ipc_call_async_slow(sc_args, sc_rc);
409
        sc_ipc_call_async_slow(sc_args, sc_rc);
335
        break;
410
        break;
336
    case SYS_IPC_CALL_SYNC_FAST:
411
    case SYS_IPC_CALL_SYNC_FAST:
337
        sc_ipc_call_sync_fast(sc_args);
412
        sc_ipc_call_sync_fast(sc_args);
338
        break;
413
        break;
339
    case SYS_IPC_CALL_SYNC_SLOW:
414
    case SYS_IPC_CALL_SYNC_SLOW:
340
        sc_ipc_call_sync_slow(sc_args);
415
        sc_ipc_call_sync_slow(sc_args);
341
        break;
416
        break;
342
    case SYS_IPC_WAIT:
417
    case SYS_IPC_WAIT:
343
        sc_ipc_wait(sc_args, sc_rc);
418
        sc_ipc_wait(sc_args, sc_rc);
344
        break;
419
        break;
345
    default:
420
    default:
346
        break;
421
        break;
347
    }
422
    }
348
 
423
 
349
    async_serialize_end();
424
    async_serialize_end();
350
}
425
}
351
 
426
 
352
static void event_thread_b(unsigned hash)
427
static void event_thread_b(uintptr_t hash)
353
{
428
{
354
    async_serialize_start();
429
    async_serialize_start();
355
    printf("New thread, hash 0x%x\n", hash);
430
    printf("New thread, hash 0x%lx\n", hash);
356
    async_serialize_end();
431
    async_serialize_end();
357
 
432
 
358
    thread_trace_start(hash);
433
    thread_trace_start(hash);
359
}
434
}
360
 
435
 
361
static int trace_loop(void *thread_hash_arg)
436
static int trace_loop(void *thread_hash_arg)
362
{
437
{
363
    int rc;
438
    int rc;
364
    unsigned ev_type;
439
    unsigned ev_type;
365
    unsigned thread_hash;
440
    uintptr_t thread_hash;
366
    unsigned thread_id;
441
    unsigned thread_id;
367
    unsigned val0, val1;
442
    sysarg_t val0, val1;
368
 
443
 
369
    thread_hash = (unsigned)thread_hash_arg;
444
    thread_hash = (uintptr_t)thread_hash_arg;
370
    thread_id = next_thread_id++;
445
    thread_id = next_thread_id++;
371
 
446
 
372
    printf("Start tracing thread [%d] (hash 0x%x)\n", thread_id, thread_hash);
447
    printf("Start tracing thread [%d] (hash 0x%lx)\n", thread_id, thread_hash);
373
 
448
 
374
    while (!abort_trace) {
449
    while (!abort_trace) {
375
 
450
 
376
        /* Run thread until an event occurs */
451
        /* Run thread until an event occurs */
377
        rc = udebug_go(phoneid, thread_hash,
452
        rc = udebug_go(phoneid, thread_hash,
378
            &ev_type, &val0, &val1);
453
            &ev_type, &val0, &val1);
379
 
454
 
380
//      printf("rc = %d, ev_type=%d\n", rc, ev_type);
455
//      printf("rc = %d, ev_type=%d\n", rc, ev_type);
381
        if (ev_type == UDEBUG_EVENT_FINISHED) {
456
        if (ev_type == UDEBUG_EVENT_FINISHED) {
382
            /* Done tracing this thread */
457
            /* Done tracing this thread */
383
            break;
458
            break;
384
        }
459
        }
385
 
460
 
386
        if (rc >= 0) {
461
        if (rc >= 0) {
387
            switch (ev_type) {
462
            switch (ev_type) {
388
            case UDEBUG_EVENT_SYSCALL_B:
463
            case UDEBUG_EVENT_SYSCALL_B:
389
                event_syscall_b(thread_id, thread_hash, val0, (int)val1);
464
                event_syscall_b(thread_id, thread_hash, val0, (int)val1);
390
                break;
465
                break;
391
            case UDEBUG_EVENT_SYSCALL_E:
466
            case UDEBUG_EVENT_SYSCALL_E:
392
                event_syscall_e(thread_id, thread_hash, val0, (int)val1);
467
                event_syscall_e(thread_id, thread_hash, val0, (int)val1);
393
                break;
468
                break;
394
            case UDEBUG_EVENT_STOP:
469
            case UDEBUG_EVENT_STOP:
395
                printf("Stop event\n");
470
                printf("Stop event\n");
396
                printf("Waiting for resume\n");
471
                printf("Waiting for resume\n");
397
                while (paused) {
472
                while (paused) {
398
                    usleep(1000000);
473
                    usleep(1000000);
399
                    fibril_yield();
474
                    fibril_yield();
400
                    printf(".");
475
                    printf(".");
401
                }
476
                }
402
                printf("Resumed\n");
477
                printf("Resumed\n");
403
                break;
478
                break;
404
            case UDEBUG_EVENT_THREAD_B:
479
            case UDEBUG_EVENT_THREAD_B:
405
                event_thread_b(val0);
480
                event_thread_b(val0);
406
                break;
481
                break;
407
            case UDEBUG_EVENT_THREAD_E:
482
            case UDEBUG_EVENT_THREAD_E:
408
                printf("Thread 0x%x exited\n", val0);
483
                printf("Thread 0x%lx exited\n", val0);
409
                abort_trace = 1;
484
                abort_trace = 1;
410
                break;
485
                break;
411
            default:
486
            default:
412
                printf("Unknown event type %d\n", ev_type);
487
                printf("Unknown event type %d\n", ev_type);
413
                break;
488
                break;
414
            }
489
            }
415
        }
490
        }
416
 
491
 
417
    }
492
    }
418
 
493
 
419
    printf("Finished tracing thread [%d]\n", thread_id);
494
    printf("Finished tracing thread [%d]\n", thread_id);
420
    return 0;
495
    return 0;
421
}
496
}
422
 
497
 
423
void thread_trace_start(unsigned thread_hash)
498
void thread_trace_start(uintptr_t thread_hash)
424
{
499
{
425
    fid_t fid;
500
    fid_t fid;
426
 
501
 
427
    thash = thread_hash;
502
    thash = thread_hash;
428
 
503
 
429
    fid = fibril_create(trace_loop, (void *)thread_hash);
504
    fid = fibril_create(trace_loop, (void *)thread_hash);
430
    if (fid == 0) {
505
    if (fid == 0) {
431
        printf("Warning: Failed creating fibril\n");
506
        printf("Warning: Failed creating fibril\n");
432
    }
507
    }
433
    fibril_add_ready(fid);
508
    fibril_add_ready(fid);
434
}
509
}
435
 
510
 
-
 
511
static loader_t *preload_task(const char *path, char *const argv[],
436
static void trace_active_task(task_id_t task_id)
512
    task_id_t *task_id)
437
{
513
{
438
    int i;
514
    loader_t *ldr;
439
    int rc;
515
    int rc;
440
    int c;
-
 
441
 
516
 
-
 
517
    /* Spawn a program loader */   
-
 
518
    ldr = loader_spawn();
-
 
519
    if (ldr == NULL)
-
 
520
        return 0;
-
 
521
 
-
 
522
    /* Get task ID. */
442
    rc = task_connect(task_id);
523
    rc = loader_get_task_id(ldr, task_id);
443
    if (rc < 0) {
524
    if (rc != EOK)
-
 
525
        goto error;
-
 
526
 
-
 
527
    /* Send program pathname */
444
        printf("Failed to connect to task %lld\n", task_id);
528
    rc = loader_set_pathname(ldr, path);
-
 
529
    if (rc != EOK)
-
 
530
        goto error;
-
 
531
 
-
 
532
    /* Send arguments */
-
 
533
    rc = loader_set_args(ldr, argv);
-
 
534
    if (rc != EOK)
-
 
535
        goto error;
-
 
536
 
-
 
537
    /* Load the program. */
-
 
538
    rc = loader_load_program(ldr);
-
 
539
    if (rc != EOK)
-
 
540
        goto error;
-
 
541
 
-
 
542
    /* Success */
445
        return;
543
    return ldr;
-
 
544
 
-
 
545
    /* Error exit */
-
 
546
error:
-
 
547
    loader_abort(ldr);
-
 
548
    free(ldr);
-
 
549
    return NULL;
446
    }
550
}
447
 
551
 
448
    printf("Connected to task %lld\n", task_id);
552
static void trace_task(task_id_t task_id)
-
 
553
{
-
 
554
    int i;
-
 
555
    int rc;
-
 
556
    int c;
449
 
557
 
450
    ipcp_init();
558
    ipcp_init();
451
 
559
 
452
    /*
560
    /*
453
     * User apps now typically have console on phone 3.
561
     * User apps now typically have console on phone 3.
454
     * (Phones 1 and 2 are used by the loader).
562
     * (Phones 1 and 2 are used by the loader).
455
     */
563
     */
456
    ipcp_connection_set(3, 0, proto_console);
564
    ipcp_connection_set(3, 0, proto_console);
457
 
565
 
458
    rc = get_thread_list();
566
    rc = get_thread_list();
459
    if (rc < 0) {
567
    if (rc < 0) {
460
        printf("Failed to get thread list (error %d)\n", rc);
568
        printf("Failed to get thread list (error %d)\n", rc);
461
        return;
569
        return;
462
    }
570
    }
463
 
571
 
464
    abort_trace = 0;
572
    abort_trace = 0;
465
 
573
 
466
    for (i = 0; i < n_threads; i++) {
574
    for (i = 0; i < n_threads; i++) {
467
        thread_trace_start(thread_hash_buf[i]);
575
        thread_trace_start(thread_hash_buf[i]);
468
    }
576
    }
469
 
577
 
470
    while(1) {
578
    while(1) {
471
        c = getchar();
579
        c = getchar();
472
        if (c == 'q') break;
580
        if (c == 'q') break;
473
        if (c == 'p') {
581
        if (c == 'p') {
474
            paused = 1;
582
            paused = 1;
475
            rc = udebug_stop(phoneid, thash);
583
            rc = udebug_stop(phoneid, thash);
476
            printf("stop -> %d\n", rc);
584
            printf("stop -> %d\n", rc);
477
        }
585
        }
478
        if (c == 'r') {
586
        if (c == 'r') {
479
            paused = 0;
587
            paused = 0;
480
        }
588
        }
481
    }
589
    }
482
 
590
 
483
    printf("\nTerminate debugging session...\n");
591
    printf("\nTerminate debugging session...\n");
484
    abort_trace = 1;
592
    abort_trace = 1;
485
    udebug_end(phoneid);
593
    udebug_end(phoneid);
486
    ipc_hangup(phoneid);
594
    ipc_hangup(phoneid);
487
 
595
 
488
    ipcp_cleanup();
596
    ipcp_cleanup();
489
 
597
 
490
    printf("Done\n");
598
    printf("Done\n");
491
    return;
599
    return;
492
}
600
}
493
 
601
 
494
static void main_init(void)
602
static void main_init(void)
495
{
603
{
496
    proto_t *p;
604
    proto_t *p;
497
    oper_t *o;
605
    oper_t *o;
498
 
606
 
-
 
607
    val_type_t arg_def[OPER_MAX_ARGS] = {
-
 
608
        V_INTEGER,
-
 
609
        V_INTEGER,
-
 
610
        V_INTEGER,
-
 
611
        V_INTEGER,
-
 
612
        V_INTEGER      
-
 
613
    };
-
 
614
 
-
 
615
    val_type_t resp_def[OPER_MAX_ARGS] = {
-
 
616
        V_INTEGER,
-
 
617
        V_INTEGER,
-
 
618
        V_INTEGER,
-
 
619
        V_INTEGER,
-
 
620
        V_INTEGER      
-
 
621
    };
-
 
622
 
499
    next_thread_id = 1;
623
    next_thread_id = 1;
500
    paused = 0;
624
    paused = 0;
501
 
625
 
502
    proto_init();
626
    proto_init();
503
 
627
 
504
    p = proto_new("vfs");
628
    p = proto_new("vfs");
505
    o = oper_new("read");
629
    o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
506
    proto_add_oper(p, VFS_READ, o);
630
    proto_add_oper(p, VFS_READ, o);
507
    o = oper_new("write");
631
    o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
508
    proto_add_oper(p, VFS_WRITE, o);
632
    proto_add_oper(p, VFS_WRITE, o);
509
    o = oper_new("truncate");
633
    o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
510
    proto_add_oper(p, VFS_TRUNCATE, o);
634
    proto_add_oper(p, VFS_TRUNCATE, o);
511
    o = oper_new("mount");
635
    o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def);
512
    proto_add_oper(p, VFS_MOUNT, o);
636
    proto_add_oper(p, VFS_MOUNT, o);
513
    o = oper_new("unmount");
637
/*  o = oper_new("unmount", 0, arg_def);
514
    proto_add_oper(p, VFS_UNMOUNT, o);
638
    proto_add_oper(p, VFS_UNMOUNT, o);*/
515
 
639
 
516
    proto_register(SERVICE_VFS, p);
640
    proto_register(SERVICE_VFS, p);
517
 
641
 
518
    p = proto_new("console");
642
    p = proto_new("console");
-
 
643
    resp_def[0] = V_CHAR;
519
    o = oper_new("getchar");
644
    o = oper_new("getchar", 0, arg_def, V_INTEGER, 2, resp_def);
520
    proto_add_oper(p, CONSOLE_GETCHAR, o);
645
    proto_add_oper(p, CONSOLE_GETCHAR, o);
-
 
646
 
-
 
647
    arg_def[0] = V_CHAR;
521
    o = oper_new("putchar");
648
    o = oper_new("putchar", 1, arg_def, V_VOID, 0, resp_def);
522
    proto_add_oper(p, CONSOLE_PUTCHAR, o);
649
    proto_add_oper(p, CONSOLE_PUTCHAR, o);
523
    o = oper_new("clear");
650
    o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def);
524
    proto_add_oper(p, CONSOLE_CLEAR, o);
651
    proto_add_oper(p, CONSOLE_CLEAR, o);
-
 
652
 
-
 
653
    arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
525
    o = oper_new("goto");
654
    o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def);
526
    proto_add_oper(p, CONSOLE_GOTO, o);
655
    proto_add_oper(p, CONSOLE_GOTO, o);
-
 
656
 
-
 
657
    resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;
527
    o = oper_new("getsize");
658
    o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def);
528
    proto_add_oper(p, CONSOLE_GETSIZE, o);
659
    proto_add_oper(p, CONSOLE_GETSIZE, o);
529
    o = oper_new("flush");
660
    o = oper_new("flush", 0, arg_def, V_VOID, 0, resp_def);
530
    proto_add_oper(p, CONSOLE_FLUSH, o);
661
    proto_add_oper(p, CONSOLE_FLUSH, o);
-
 
662
 
-
 
663
    arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;
531
    o = oper_new("set_style");
664
    o = oper_new("set_style", 2, arg_def, V_INTEGER, 0, resp_def);
532
    proto_add_oper(p, CONSOLE_SET_STYLE, o);
665
    proto_add_oper(p, CONSOLE_SET_STYLE, o);
533
    o = oper_new("cursor_visibility");
666
    o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def);
534
    proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o);
667
    proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o);
535
    o = oper_new("flush");
-
 
536
    proto_add_oper(p, CONSOLE_FLUSH, o);
-
 
537
 
668
 
538
    proto_console = p;
669
    proto_console = p;
539
    proto_register(SERVICE_CONSOLE, p);
670
    proto_register(SERVICE_CONSOLE, p);
540
}
671
}
541
 
672
 
542
static void print_syntax()
673
static void print_syntax()
543
{
674
{
544
    printf("Syntax:\n");
675
    printf("Syntax:\n");
545
    printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n");
676
    printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n");
546
    printf("or\ttrace [+<events>] -t <task_id>\n");
677
    printf("or\ttrace [+<events>] -t <task_id>\n");
547
    printf("Events: (default is +tp)\n");
678
    printf("Events: (default is +tp)\n");
548
    printf("\n");
679
    printf("\n");
549
    printf("\tt ... Thread creation and termination\n");
680
    printf("\tt ... Thread creation and termination\n");
550
    printf("\ts ... System calls\n");
681
    printf("\ts ... System calls\n");
551
    printf("\ti ... Low-level IPC\n");
682
    printf("\ti ... Low-level IPC\n");
552
    printf("\tp ... Protocol level\n");
683
    printf("\tp ... Protocol level\n");
553
    printf("\n");
684
    printf("\n");
554
    printf("Examples:\n");
685
    printf("Examples:\n");
555
    printf("\ttrace +s /app/tetris\n");
686
    printf("\ttrace +s /app/tetris\n");
556
    printf("\ttrace +tsip -t 12\n");
687
    printf("\ttrace +tsip -t 12\n");
557
}
688
}
558
 
689
 
559
static display_mask_t parse_display_mask(char *text)
690
static display_mask_t parse_display_mask(char *text)
560
{
691
{
561
    display_mask_t dm;
692
    display_mask_t dm;
562
    char *c;
693
    char *c;
563
 
694
 
564
    c = text;
695
    c = text;
565
 
696
 
566
    while (*c) {
697
    while (*c) {
567
        switch (*c) {
698
        switch (*c) {
568
        case 't': dm = dm | DM_THREAD; break;
699
        case 't': dm = dm | DM_THREAD; break;
569
        case 's': dm = dm | DM_SYSCALL; break;
700
        case 's': dm = dm | DM_SYSCALL; break;
570
        case 'i': dm = dm | DM_IPC; break;
701
        case 'i': dm = dm | DM_IPC; break;
571
        case 'p': dm = dm | DM_SYSTEM | DM_USER; break;
702
        case 'p': dm = dm | DM_SYSTEM | DM_USER; break;
572
        default:
703
        default:
573
            printf("Unexpected event type '%c'\n", *c);
704
            printf("Unexpected event type '%c'\n", *c);
574
            exit(1);
705
            exit(1);
575
        }
706
        }
576
 
707
 
577
        ++c;
708
        ++c;
578
    }
709
    }
579
 
710
 
580
    return dm;
711
    return dm;
581
}
712
}
582
 
713
 
583
static int parse_args(int argc, char *argv[])
714
static int parse_args(int argc, char *argv[])
584
{
715
{
585
    char *arg;
716
    char *arg;
586
    char *err_p;
717
    char *err_p;
587
 
718
 
588
    task_id = 0;
719
    task_id = 0;
589
 
720
 
590
    --argc; ++argv;
721
    --argc; ++argv;
591
 
722
 
592
    while (argc > 0) {
723
    while (argc > 0) {
593
        arg = *argv;
724
        arg = *argv;
594
        if (arg[0] == '+') {
725
        if (arg[0] == '+') {
595
            display_mask = parse_display_mask(&arg[1]);
726
            display_mask = parse_display_mask(&arg[1]);
596
        } else if (arg[0] == '-') {
727
        } else if (arg[0] == '-') {
597
            if (arg[1] == 't') {
728
            if (arg[1] == 't') {
598
                /* Trace an already running task */
729
                /* Trace an already running task */
599
                --argc; ++argv;
730
                --argc; ++argv;
600
                task_id = strtol(*argv, &err_p, 10);
731
                task_id = strtol(*argv, &err_p, 10);
-
 
732
                task_ldr = NULL;
601
                if (*err_p) {
733
                if (*err_p) {
602
                    printf("Task ID syntax error\n");
734
                    printf("Task ID syntax error\n");
603
                    print_syntax();
735
                    print_syntax();
604
                    return -1;
736
                    return -1;
605
                }
737
                }
606
            } else {
738
            } else {
607
                printf("Uknown option '%s'\n", arg[0]);
739
                printf("Uknown option '%s'\n", arg[0]);
608
                print_syntax();
740
                print_syntax();
609
                return -1;
741
                return -1;
610
            }
742
            }
611
        } else {
743
        } else {
612
            break;
744
            break;
613
        }
745
        }
614
 
746
 
615
        --argc; ++argv;
747
        --argc; ++argv;
616
    }
748
    }
617
 
749
 
618
    if (task_id != 0) {
750
    if (task_id != 0) {
619
        if (argc == 0) return;
751
        if (argc == 0) return 0;
620
        printf("Extra arguments\n");
752
        printf("Extra arguments\n");
621
        print_syntax();
753
        print_syntax();
622
        return -1;
754
        return -1;
623
    }
755
    }
624
 
756
 
625
    if (argc < 1) {
757
    if (argc < 1) {
626
        printf("Missing argument\n");
758
        printf("Missing argument\n");
627
        print_syntax();
759
        print_syntax();
628
        return -1;
760
        return -1;
629
    }
761
    }
630
 
762
 
631
    /* Execute the specified command and trace the new task. */
763
    /* Preload the specified program file. */
632
    printf("Spawning '%s' with arguments:\n", *argv);
764
    printf("Spawning '%s' with arguments:\n", *argv);
633
    {
765
    {
634
        char **cp = argv;
766
        char **cp = argv;
635
        while (*cp) printf("'%s'\n", *cp++);
767
        while (*cp) printf("'%s'\n", *cp++);
636
    }
768
    }
637
    task_id = task_spawn(*argv, argv);
769
    task_ldr = preload_task(*argv, argv, &task_id);
638
 
770
 
639
    return 0;
771
    return 0;
640
}
772
}
641
 
773
 
642
int main(int argc, char *argv[])
774
int main(int argc, char *argv[])
643
{
775
{
-
 
776
    int rc;
-
 
777
 
644
    printf("System Call / IPC Tracer\n");
778
    printf("System Call / IPC Tracer\n");
645
 
779
 
646
    display_mask = DM_THREAD | DM_SYSTEM | DM_USER;
780
    display_mask = DM_THREAD | DM_SYSTEM | DM_USER;
647
 
781
 
648
    if (parse_args(argc, argv) < 0)
782
    if (parse_args(argc, argv) < 0)
649
        return 1;
783
        return 1;
650
 
784
 
651
    main_init();
785
    main_init();
-
 
786
 
-
 
787
    rc = connect_task(task_id);
-
 
788
    if (rc < 0) {
-
 
789
        printf("Failed connecting to task %lld\n", task_id);
-
 
790
        return 1;
-
 
791
    }
-
 
792
 
-
 
793
    printf("Connected to task %lld\n", task_id);
-
 
794
 
-
 
795
    if (task_ldr != NULL) {
-
 
796
        program_run();
-
 
797
    }
-
 
798
 
652
    trace_active_task(task_id);
799
    trace_task(task_id);
653
 
800
 
654
    return 0;
801
    return 0;
655
}
802
}
656
 
803
 
657
/** @}
804
/** @}
658
 */
805
 */
659
 
806