Subversion Repositories HelenOS

Rev

Rev 2947 | Rev 3093 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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