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