Subversion Repositories HelenOS

Rev

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

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