Subversion Repositories HelenOS

Rev

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

Rev 2941 Rev 2942
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 debug
29
/** @addtogroup debug
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 <string.h>
37
#include <string.h>
38
#include <bool.h>
38
#include <bool.h>
39
#include <udebug.h>
39
#include <udebug.h>
40
#include <sys/types.h>
40
#include <sys/types.h>
41
 
41
 
42
#include "main.h"
42
#include "main.h"
43
#include "cons.h"
43
#include "cons.h"
44
#include "dthread.h"
44
#include "dthread.h"
45
#include "include/arch.h"
45
#include "include/arch.h"
46
#include "cmd.h"
46
#include "cmd.h"
47
 
47
 
48
static void cmd_break(int argc, char *argv[]);
48
static void cmd_break(int argc, char *argv[]);
49
static void cmd_ct(int argc, char *argv[]);
49
static void cmd_ct(int argc, char *argv[]);
50
static void cmd_go(int argc, char *argv[]);
50
static void cmd_go(int argc, char *argv[]);
51
static void cmd_istep(int argc, char *argv[]);
51
static void cmd_istep(int argc, char *argv[]);
52
void        cmd_help(int argc, char *argv[]);
52
void        cmd_help(int argc, char *argv[]);
53
static void cmd_memr(int argc, char *argv[]);
53
static void cmd_memr(int argc, char *argv[]);
54
static void cmd_pwt(int argc, char *argv[]);
54
static void cmd_pwt(int argc, char *argv[]);
55
static void cmd_regs(int argc, char *argv[]);
55
static void cmd_regs(int argc, char *argv[]);
56
static void cmd_stop(int argc, char *argv[]);
56
static void cmd_stop(int argc, char *argv[]);
57
static void cmd_threads(int argc, char *argv[]);
57
static void cmd_threads(int argc, char *argv[]);
58
static void cmd_quit(int argc, char *argv[]);
58
static void cmd_quit(int argc, char *argv[]);
59
 
59
 
60
volatile bool quit = false;
60
volatile bool quit = false;
61
 
61
 
62
cmd_desc_t cmd_table[] = {
62
cmd_desc_t cmd_table[] = {
63
    { 1,    "break",    cmd_break },
63
    { 1,    "break",    cmd_break },
64
    { 1,    "ct",       cmd_ct },
64
    { 1,    "ct",       cmd_ct },
65
    { 0,    "go",       cmd_go },
65
    { 0,    "go",       cmd_go },
66
    { 0,    "help",     cmd_help },
66
    { 0,    "help",     cmd_help },
67
    { 2,    "memr",     cmd_memr },
67
    { 2,    "memr",     cmd_memr },
68
    { 0,    "pwt",      cmd_pwt },
68
    { 0,    "pwt",      cmd_pwt },
69
    { 0,    "regs",     cmd_regs },
69
    { 0,    "regs",     cmd_regs },
70
    { 0 ,   "stop",     cmd_stop },
70
    { 0 ,   "stop",     cmd_stop },
71
    { 0,    "istep",    cmd_istep },
71
    { 0,    "istep",    cmd_istep },
72
    { 0,    "threads",  cmd_threads },
72
    { 0,    "threads",  cmd_threads },
73
    { 0,    "quit",     cmd_quit },
73
    { 0,    "quit",     cmd_quit },
74
    { -1,   NULL,       NULL }
74
    { -1,   NULL,       NULL }
75
};
75
};
76
 
76
 
77
static void cmd_break(int argc, char *argv[])
77
static void cmd_break(int argc, char *argv[])
78
{
78
{
79
    uintptr_t addr;
79
    uintptr_t addr;
80
 
80
 
81
    (void)argc;
81
    (void)argc;
82
    addr = strtoul(argv[1], NULL, 0);
82
    addr = strtoul(argv[1], NULL, 0);
83
 
83
 
84
    cons_printf("You requested a breakpoint at 0x%x\n", addr);
84
    cons_printf("You requested a breakpoint at 0x%x\n", addr);
85
    arch_breakpoint_add(addr);
85
    arch_breakpoint_add(addr);
86
}
86
}
87
 
87
 
88
static void cmd_ct(int argc, char *argv[])
88
static void cmd_ct(int argc, char *argv[])
89
{
89
{
90
    int tid;
90
    int tid;
91
 
91
 
92
    link_t *cur;
92
    link_t *cur;
93
    dthread_t *dt;
93
    dthread_t *dt;
94
 
94
 
95
    (void)argc;
95
    (void)argc;
96
    tid = strtoul(argv[1], NULL, 0);
96
    tid = strtoul(argv[1], NULL, 0);
97
 
97
 
98
    dt = NULL;
98
    dt = NULL;
99
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
99
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
100
        dt = list_get_instance(cur, dthread_t, link);
100
        dt = list_get_instance(cur, dthread_t, link);
101
        if (dt->id == tid) break;
101
        if (dt->id == tid) break;
102
    }
102
    }
103
   
103
   
104
    if (dt->id == tid) {
104
    if (dt->id == tid) {
105
        cwt = dt;
105
        cwt = dt;
106
        cons_printf("changed working thread to: %d [hash 0x%x]\n",
106
        cons_printf("changed working thread to: %d [hash 0x%x]\n",
107
            cwt->id, cwt->hash);
107
            cwt->id, cwt->hash);
108
    } else {
108
    } else {
109
        cons_printf("no such thread\n");
109
        cons_printf("no such thread\n");
110
    }
110
    }
111
}
111
}
112
 
112
 
113
 
113
 
114
void cmd_go(int argc, char *argv[])
114
void cmd_go(int argc, char *argv[])
115
{
115
{
116
    link_t *cur;
116
    link_t *cur;
117
    dthread_t *dt;
117
    dthread_t *dt;
118
 
118
 
119
    (void)argc; (void)argv;
119
    (void)argc; (void)argv;
120
 
120
 
121
    dt = NULL;
121
    dt = NULL;
122
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
122
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
123
        dt = list_get_instance(cur, dthread_t, link);
123
        dt = list_get_instance(cur, dthread_t, link);
-
 
124
        arch_set_singlestep(dt, 0);
124
        dthread_resume(dt);
125
        dthread_resume(dt);
125
    }  
126
    }  
126
}
127
}
127
 
128
 
128
void cmd_help(int argc, char *argv[])
129
void cmd_help(int argc, char *argv[])
129
{
130
{
130
    int i;
131
    int i;
131
 
132
 
132
    (void)argc; (void)argv;
133
    (void)argc; (void)argv;
133
    i = 0;
134
    i = 0;
134
    while (cmd_table[i].name != NULL) {
135
    while (cmd_table[i].name != NULL) {
135
        cons_printf("%s\n", cmd_table[i].name);
136
        cons_printf("%s\n", cmd_table[i].name);
136
        ++i;
137
        ++i;
137
    }
138
    }
138
}
139
}
139
 
140
 
140
void cmd_istep(int argc, char *argv[])
141
void cmd_istep(int argc, char *argv[])
141
{
142
{
142
    (void)argc; (void)argv;
143
    (void)argc; (void)argv;
-
 
144
 
-
 
145
    arch_set_singlestep(cwt, 1);
143
    /*TODO*/
146
    dthread_resume(cwt);
144
}
147
}
145
 
148
 
146
#define BYTES_PER_LINE 16
149
#define BYTES_PER_LINE 16
147
 
150
 
148
static void cmd_memr(int argc, char *argv[])
151
static void cmd_memr(int argc, char *argv[])
149
{
152
{
150
    uintptr_t addr;
153
    uintptr_t addr;
151
    size_t length;
154
    size_t length;
152
    uint8_t buf[BYTES_PER_LINE];
155
    uint8_t buf[BYTES_PER_LINE];
153
    int to_read, i;
156
    int to_read, i;
154
    int rc;
157
    int rc;
155
 
158
 
156
    (void)argc;
159
    (void)argc;
157
    addr = strtoul(argv[1], NULL, 0);
160
    addr = strtoul(argv[1], NULL, 0);
158
    length = strtoul(argv[2], NULL, 0);
161
    length = strtoul(argv[2], NULL, 0);
159
 
162
 
160
    while (length > 0) {
163
    while (length > 0) {
161
        to_read = length < BYTES_PER_LINE ? length : BYTES_PER_LINE;
164
        to_read = length < BYTES_PER_LINE ? length : BYTES_PER_LINE;
162
 
165
 
163
        rc = udebug_mem_read(app_phone, buf, addr, to_read);
166
        rc = udebug_mem_read(app_phone, buf, addr, to_read);
164
        if (rc < 0) {
167
        if (rc < 0) {
165
            cons_printf("error %d\n", rc);
168
            cons_printf("error %d\n", rc);
166
            return;
169
            return;
167
        }
170
        }
168
 
171
 
169
        cons_printf("0x%x:", addr);
172
        cons_printf("0x%x:", addr);
170
        for (i = 0; i < to_read; ++i) {
173
        for (i = 0; i < to_read; ++i) {
171
            cons_printf(" %02x", buf[i]);
174
            cons_printf(" %02x", buf[i]);
172
        }
175
        }
173
        for (i = to_read; i < BYTES_PER_LINE; ++i) {
176
        for (i = to_read; i < BYTES_PER_LINE; ++i) {
174
            cons_printf("   ");
177
            cons_printf("   ");
175
        }
178
        }
176
 
179
 
177
        putchar ('\t');
180
        putchar ('\t');
178
 
181
 
179
        for (i = 0; i < to_read; ++i) {
182
        for (i = 0; i < to_read; ++i) {
180
            if (buf[i] >= 32 && buf[i] < 127)
183
            if (buf[i] >= 32 && buf[i] < 127)
181
                putchar(buf[i]);
184
                putchar(buf[i]);
182
            else
185
            else
183
                putchar('.');
186
                putchar('.');
184
        }
187
        }
185
        cons_printf("\n");
188
        cons_printf("\n");
186
 
189
 
187
        addr += to_read;
190
        addr += to_read;
188
        length -= to_read;
191
        length -= to_read;
189
    }
192
    }
190
}
193
}
191
 
194
 
192
void cmd_pwt(int argc, char *argv[])
195
void cmd_pwt(int argc, char *argv[])
193
{
196
{
194
    (void)argc; (void)argv;
197
    (void)argc; (void)argv;
195
 
198
 
196
    cons_printf("working thread: %d [hash 0x%x]\n", cwt->id, cwt->hash);
199
    cons_printf("working thread: %d [hash 0x%x]\n", cwt->id, cwt->hash);
197
}
200
}
198
 
201
 
199
void cmd_regs(int argc, char *argv[])
202
void cmd_regs(int argc, char *argv[])
200
{
203
{
201
    (void)argc; (void)argv;
204
    (void)argc; (void)argv;
202
 
205
 
203
    if (cwt) arch_dump_regs(cwt->hash);
206
    if (cwt) arch_dump_regs(cwt->hash);
204
}
207
}
205
 
208
 
206
void cmd_stop(int argc, char *argv[])
209
void cmd_stop(int argc, char *argv[])
207
{
210
{
208
    link_t *cur;
211
    link_t *cur;
209
    dthread_t *dt;
212
    dthread_t *dt;
210
    int rc;
213
    int rc;
211
 
214
 
212
    (void)argc; (void)argv;
215
    (void)argc; (void)argv;
213
 
216
 
214
    dt = NULL;
217
    dt = NULL;
215
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
218
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
216
        dt = list_get_instance(cur, dthread_t, link);
219
        dt = list_get_instance(cur, dthread_t, link);
217
        if (!dt->stopped) {
220
        if (!dt->stopped) {
218
            rc = udebug_stop(app_phone, dt->hash);
221
            rc = udebug_stop(app_phone, dt->hash);
219
            if (rc < 0) {
222
            if (rc < 0) {
220
                printf("failed halting thread %d\n", dt->id);
223
                printf("failed halting thread %d\n", dt->id);
221
            }
224
            }
222
        }
225
        }
223
    }  
226
    }  
224
}
227
}
225
 
228
 
226
 
229
 
227
void cmd_threads(int argc, char *argv[])
230
void cmd_threads(int argc, char *argv[])
228
{
231
{
229
    link_t *cur;
232
    link_t *cur;
230
    dthread_t *dt;
233
    dthread_t *dt;
231
 
234
 
232
    (void)argc;
235
    (void)argc;
233
 
236
 
234
    dt = NULL;
237
    dt = NULL;
235
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
238
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
236
        dt = list_get_instance(cur, dthread_t, link);
239
        dt = list_get_instance(cur, dthread_t, link);
237
        cons_printf("%d [hash 0x%x]\n", dt->id, dt->hash);
240
        cons_printf("%d [hash 0x%x]\n", dt->id, dt->hash);
238
    }  
241
    }  
239
}
242
}
240
 
243
 
241
 
244
 
242
static void cmd_quit(int argc, char *argv[])
245
static void cmd_quit(int argc, char *argv[])
243
{
246
{
244
    (void)argc; (void)argv;
247
    (void)argc; (void)argv;
245
    quit = true;
248
    quit = true;
246
}
249
}
247
 
250
 
248
/** @}
251
/** @}
249
 */
252
 */
250
 
253