Subversion Repositories HelenOS

Rev

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