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