Subversion Repositories HelenOS

Rev

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