Rev 2922 | Rev 2924 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2922 | Rev 2923 | ||
---|---|---|---|
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 <unistd.h> |
37 | #include <unistd.h> |
38 | #include <syscall.h> |
38 | #include <syscall.h> |
39 | #include <ipc/ipc.h> |
39 | #include <ipc/ipc.h> |
40 | #include <fibril.h> |
40 | #include <fibril.h> |
41 | #include <errno.h> |
41 | #include <errno.h> |
42 | #include <udebug.h> |
42 | #include <udebug.h> |
43 | #include <async.h> |
43 | #include <async.h> |
44 | #include <string.h> |
44 | #include <string.h> |
45 | 45 | ||
46 | #include "cmd.h" |
46 | #include "cmd.h" |
- | 47 | #include "include/arch.h" |
|
47 | #include "main.h" |
48 | #include "main.h" |
48 | 49 | ||
49 | void thread_debug_start(unsigned thread_hash); |
50 | void thread_debug_start(unsigned thread_hash); |
50 | 51 | ||
51 | #define INBUF_SIZE 64 |
52 | #define INBUF_SIZE 64 |
52 | char in_buf[INBUF_SIZE]; |
53 | char in_buf[INBUF_SIZE]; |
53 | 54 | ||
54 | #define MAX_ARGC 10 |
55 | #define MAX_ARGC 10 |
55 | int cmd_argc; |
56 | int cmd_argc; |
56 | char *cmd_argv[MAX_ARGC + 1]; /* need one spare field for cmd_split() */ |
57 | char *cmd_argv[MAX_ARGC + 1]; /* need one spare field for cmd_split() */ |
57 | 58 | ||
58 | #define THBUF_SIZE 64 |
59 | #define THBUF_SIZE 64 |
59 | thash_t thread_hash_buf[THBUF_SIZE]; |
60 | thash_t thread_hash_buf[THBUF_SIZE]; |
60 | unsigned n_threads; |
61 | unsigned n_threads; |
61 | 62 | ||
62 | int next_thread_id; |
63 | int next_thread_id; |
63 | 64 | ||
64 | int app_phone; |
65 | int app_phone; |
65 | volatile bool abort_debug; |
66 | volatile bool abort_debug; |
66 | 67 | ||
67 | thash_t thash; |
68 | thash_t thash; |
68 | volatile int paused; |
69 | volatile int paused; |
69 | 70 | ||
70 | breakpoint_t brk_list[MAX_BRKPTS]; |
71 | breakpoint_t brk_list[MAX_BRKPTS]; |
71 | int lifted_brkpt; |
72 | int lifted_brkpt; |
72 | 73 | ||
73 | void read_line(char *buffer, int n) |
74 | void read_line(char *buffer, int n) |
74 | { |
75 | { |
75 | char c; |
76 | char c; |
76 | int i; |
77 | int i; |
77 | 78 | ||
78 | i = 0; |
79 | i = 0; |
79 | while (i < n - 1) { |
80 | while (i < n - 1) { |
80 | c = getchar(); |
81 | c = getchar(); |
81 | if (c == '\n') break; |
82 | if (c == '\n') break; |
82 | if (c == '\b') { |
83 | if (c == '\b') { |
83 | if (i > 0) { |
84 | if (i > 0) { |
84 | putchar('\b'); |
85 | putchar('\b'); |
85 | --i; |
86 | --i; |
86 | } |
87 | } |
87 | continue; |
88 | continue; |
88 | } |
89 | } |
89 | 90 | ||
90 | putchar(c); |
91 | putchar(c); |
91 | buffer[i++] = c; |
92 | buffer[i++] = c; |
92 | } |
93 | } |
93 | 94 | ||
94 | putchar('\n'); |
95 | putchar('\n'); |
95 | buffer[i] = '\0'; |
96 | buffer[i] = '\0'; |
96 | } |
97 | } |
97 | 98 | ||
98 | void command_split(char *cmd_str) |
99 | void command_split(char *cmd_str) |
99 | { |
100 | { |
100 | char *p = cmd_str; |
101 | char *p = cmd_str; |
101 | 102 | ||
102 | if (*p == '\0') { |
103 | if (*p == '\0') { |
103 | cmd_argc = 0; |
104 | cmd_argc = 0; |
104 | return; |
105 | return; |
105 | } |
106 | } |
106 | 107 | ||
107 | cmd_argc = 1; |
108 | cmd_argc = 1; |
108 | cmd_argv[0] = p; |
109 | cmd_argv[0] = p; |
109 | 110 | ||
110 | while (*p != '\0') { |
111 | while (*p != '\0') { |
111 | if (*p == ' ') { |
112 | if (*p == ' ') { |
112 | cmd_argv[cmd_argc++] = p + 1; |
113 | cmd_argv[cmd_argc++] = p + 1; |
113 | *p = '\0'; |
114 | *p = '\0'; |
114 | } |
115 | } |
115 | ++p; |
116 | ++p; |
116 | } |
117 | } |
117 | } |
118 | } |
118 | 119 | ||
119 | void command_run(void) |
120 | void command_run(void) |
120 | { |
121 | { |
121 | int i; |
122 | int i; |
122 | int cmp_len; |
123 | int cmp_len; |
123 | int len; |
124 | int len; |
124 | 125 | ||
125 | int idx_found; |
126 | int idx_found; |
126 | int num_found; |
127 | int num_found; |
127 | 128 | ||
128 | len = strlen(cmd_argv[0]); |
129 | len = strlen(cmd_argv[0]); |
129 | cmp_len = 1; |
130 | cmp_len = 1; |
130 | 131 | ||
131 | while (cmp_len <= len + 1) { |
132 | while (cmp_len <= len + 1) { |
132 | 133 | ||
133 | num_found = 0; |
134 | num_found = 0; |
134 | i = 0; |
135 | i = 0; |
135 | while (cmd_table[i].name != NULL) { |
136 | while (cmd_table[i].name != NULL) { |
136 | if (strncmp(cmd_table[i].name, cmd_argv[0], cmp_len) == 0) { |
137 | if (strncmp(cmd_table[i].name, cmd_argv[0], cmp_len) == 0) { |
137 | idx_found = i; |
138 | idx_found = i; |
138 | ++num_found; |
139 | ++num_found; |
139 | } |
140 | } |
140 | ++i; |
141 | ++i; |
141 | } |
142 | } |
142 | 143 | ||
143 | if (num_found < 2) break; |
144 | if (num_found < 2) break; |
144 | 145 | ||
145 | --cmp_len; |
146 | --cmp_len; |
146 | } |
147 | } |
147 | 148 | ||
148 | if (num_found == 0) { |
149 | if (num_found == 0) { |
149 | printf("Unknown command. Try one of:\n"); |
150 | printf("Unknown command. Try one of:\n"); |
150 | cmd_help(0, NULL); |
151 | cmd_help(0, NULL); |
151 | return; |
152 | return; |
152 | } |
153 | } |
153 | 154 | ||
154 | if (cmd_argc - 1 != cmd_table[idx_found].argc) { |
155 | if (cmd_argc - 1 != cmd_table[idx_found].argc) { |
155 | printf("Command '%s' expects %d arguments\n", |
156 | printf("Command '%s' expects %d arguments\n", |
156 | cmd_table[idx_found].name, cmd_table[idx_found].argc); |
157 | cmd_table[idx_found].name, cmd_table[idx_found].argc); |
157 | return; |
158 | return; |
158 | } |
159 | } |
159 | 160 | ||
160 | (*cmd_table[idx_found].proc)(cmd_argc, cmd_argv); |
161 | (*cmd_table[idx_found].proc)(cmd_argc, cmd_argv); |
161 | } |
162 | } |
162 | 163 | ||
163 | 164 | ||
164 | int task_connect(int taskid) |
165 | int task_connect(int taskid) |
165 | { |
166 | { |
166 | int rc; |
167 | int rc; |
167 | unsigned evmask; |
168 | unsigned evmask; |
168 | 169 | ||
169 | printf("ipc_connect_kbox(%d)... ", taskid); |
170 | printf("ipc_connect_kbox(%d)... ", taskid); |
170 | rc = ipc_connect_kbox(taskid); |
171 | rc = ipc_connect_kbox(taskid); |
171 | printf("-> %d\n", rc); |
172 | printf("-> %d\n", rc); |
172 | app_phone = rc; |
173 | app_phone = rc; |
173 | if (rc < 0) return rc; |
174 | if (rc < 0) return rc; |
174 | 175 | ||
175 | printf("udebug_begin()... "); |
176 | printf("udebug_begin()... "); |
176 | rc = udebug_begin(app_phone); |
177 | rc = udebug_begin(app_phone); |
177 | printf("-> %d\n", rc); |
178 | printf("-> %d\n", rc); |
178 | if (rc < 0) return rc; |
179 | if (rc < 0) return rc; |
179 | 180 | ||
180 | evmask = UDEBUG_EM_ALL & ~(UDEBUG_EM_SYSCALL_B | UDEBUG_EM_SYSCALL_E); |
181 | evmask = UDEBUG_EM_ALL & ~(UDEBUG_EM_SYSCALL_B | UDEBUG_EM_SYSCALL_E); |
181 | printf("udebug_set_evmask(0x%x)... ", evmask); |
182 | printf("udebug_set_evmask(0x%x)... ", evmask); |
182 | rc = udebug_set_evmask(app_phone, evmask); |
183 | rc = udebug_set_evmask(app_phone, evmask); |
183 | printf("-> %d\n", rc); |
184 | printf("-> %d\n", rc); |
184 | if (rc < 0) return rc; |
185 | if (rc < 0) return rc; |
185 | 186 | ||
186 | return 0; |
187 | return 0; |
187 | } |
188 | } |
188 | 189 | ||
189 | int get_thread_list(void) |
190 | int get_thread_list(void) |
190 | { |
191 | { |
191 | int rc; |
192 | int rc; |
192 | int tb_copied; |
193 | int tb_copied; |
193 | int tb_needed; |
194 | int tb_needed; |
194 | int i; |
195 | int i; |
195 | 196 | ||
196 | printf("send IPC_M_DEBUG_THREAD_READ message\n"); |
197 | printf("send IPC_M_DEBUG_THREAD_READ message\n"); |
197 | rc = udebug_thread_read(app_phone, (unsigned)thread_hash_buf, |
198 | rc = udebug_thread_read(app_phone, (unsigned)thread_hash_buf, |
198 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
199 | THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); |
199 | printf("-> %d\n", rc); |
200 | printf("-> %d\n", rc); |
200 | if (rc < 0) return rc; |
201 | if (rc < 0) return rc; |
201 | 202 | ||
202 | n_threads = tb_copied / sizeof(unsigned); |
203 | n_threads = tb_copied / sizeof(unsigned); |
203 | 204 | ||
204 | printf("thread IDs:"); |
205 | printf("thread IDs:"); |
205 | for (i=0; i<n_threads; i++) { |
206 | for (i=0; i<n_threads; i++) { |
206 | printf(" %u", thread_hash_buf[i]); |
207 | printf(" %u", thread_hash_buf[i]); |
207 | } |
208 | } |
208 | printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned)); |
209 | printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned)); |
209 | 210 | ||
210 | return 0; |
211 | return 0; |
211 | } |
212 | } |
212 | 213 | ||
213 | void event_thread_b(unsigned hash) |
214 | void event_thread_b(unsigned hash) |
214 | { |
215 | { |
215 | async_serialize_start(); |
216 | async_serialize_start(); |
216 | printf("new thread, hash 0x%x\n", hash); |
217 | printf("new thread, hash 0x%x\n", hash); |
217 | async_serialize_end(); |
218 | async_serialize_end(); |
218 | 219 | ||
219 | thread_debug_start(hash); |
220 | thread_debug_start(hash); |
220 | } |
221 | } |
221 | 222 | ||
222 | static unsigned buffer[1024]; |
223 | static unsigned buffer[1024]; |
223 | 224 | ||
- | 225 | static void debug_event(thash_t thash, udebug_event_t ev_type, sysarg_t val0) |
|
- | 226 | { |
|
- | 227 | switch (ev_type) { |
|
- | 228 | case UDEBUG_EVENT_STOP: |
|
- | 229 | printf("stop event\n"); |
|
- | 230 | printf("waiting for resume\n"); |
|
- | 231 | while (paused) { |
|
- | 232 | usleep(1000000); |
|
- | 233 | fibril_yield(); |
|
- | 234 | printf("."); |
|
- | 235 | } |
|
- | 236 | printf("resumed\n"); |
|
- | 237 | break; |
|
- | 238 | case UDEBUG_EVENT_THREAD_B: |
|
- | 239 | event_thread_b(val0); |
|
- | 240 | break; |
|
- | 241 | case UDEBUG_EVENT_THREAD_E: |
|
- | 242 | printf("thread 0x%x exited\n", val0); |
|
- | 243 | abort_debug = true; |
|
- | 244 | break; |
|
- | 245 | case UDEBUG_EVENT_BREAKPOINT: |
|
- | 246 | printf("breakpoint reached\n"); |
|
- | 247 | arch_event_breakpoint(thash); |
|
- | 248 | break; |
|
- | 249 | case UDEBUG_EVENT_TRAP: |
|
- | 250 | printf("trap event\n"); |
|
- | 251 | arch_event_trap(thash); |
|
- | 252 | break; |
|
- | 253 | default: |
|
- | 254 | printf("unknown event type %d\n", ev_type); |
|
- | 255 | break; |
|
- | 256 | } |
|
- | 257 | } |
|
- | 258 | ||
224 | void debug_loop(void *thread_hash_arg) |
259 | void debug_loop(void *thread_hash_arg) |
225 | { |
260 | { |
226 | int rc; |
261 | int rc; |
227 | unsigned ev_type; |
262 | udebug_event_t ev_type; |
228 | unsigned thread_hash; |
263 | unsigned thread_hash; |
229 | unsigned thread_id; |
264 | unsigned thread_id; |
230 | unsigned val0, val1; |
265 | unsigned val0, val1; |
231 | 266 | ||
232 | thread_hash = (unsigned)thread_hash_arg; |
267 | thread_hash = (unsigned)thread_hash_arg; |
233 | thread_id = next_thread_id++; |
268 | thread_id = next_thread_id++; |
234 | 269 | ||
235 | printf("debug_loop(%d)\n", thread_id); |
270 | printf("debug_loop(%d)\n", thread_id); |
236 | 271 | ||
237 | while (!abort_debug) { |
272 | while (!abort_debug) { |
238 | 273 | ||
239 | printf("go\n"); |
274 | printf("go\n"); |
240 | /* Run thread until an event occurs */ |
275 | /* Run thread until an event occurs */ |
241 | rc = udebug_go(app_phone, thread_hash, |
276 | rc = udebug_go(app_phone, thread_hash, |
242 | &ev_type, &val0, &val1); |
277 | &ev_type, &val0, &val1); |
243 | 278 | ||
244 | printf("..ev type %d\n", ev_type); |
- | |
245 | - | ||
246 | // printf("rc = %d, ev_type=%d\n", rc, ev_type); |
- | |
247 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
279 | if (ev_type == UDEBUG_EVENT_FINISHED) { |
248 | printf("thread %u debugging finished\n", thread_id); |
280 | printf("thread %u debugging finished\n", thread_id); |
249 | break; |
281 | break; |
250 | } |
282 | } |
251 | 283 | ||
252 | if (rc >= 0) { |
- | |
253 | switch (ev_type) { |
- | |
254 | case UDEBUG_EVENT_STOP: |
- | |
255 | printf("stop event\n"); |
- | |
256 | printf("waiting for resume\n"); |
- | |
257 | while (paused) { |
- | |
258 | usleep(1000000); |
- | |
259 | fibril_yield(); |
- | |
260 | printf("."); |
- | |
261 | } |
- | |
262 | printf("resumed\n"); |
- | |
263 | break; |
- | |
264 | case UDEBUG_EVENT_THREAD_B: |
- | |
265 | event_thread_b(val0); |
- | |
266 | break; |
- | |
267 | case UDEBUG_EVENT_THREAD_E: |
- | |
268 | printf("thread 0x%x exited\n", val0); |
- | |
269 | abort_debug = true; |
- | |
270 | break; |
- | |
271 | case UDEBUG_EVENT_BREAKPOINT: |
- | |
272 | printf("breakpoint reached\n"); |
- | |
273 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
- | |
274 | printf("udebug_regs_read -> %d\n", rc); |
- | |
275 | int eip_idx = 12; |
- | |
276 | int efl_idx = 14; |
- | |
277 | printf("EIP was 0x%08x\n", buffer[eip_idx]); |
- | |
278 | int brk_addr = buffer[eip_idx] - 1; |
- | |
279 | int bi; |
- | |
280 | for (bi = 0; bi < MAX_BRKPTS; bi++) |
- | |
281 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
- | |
282 | break; |
- | |
283 | if (bi < MAX_BRKPTS) { |
- | |
284 | buffer[eip_idx] = brk_addr; |
- | |
285 | buffer[efl_idx] |= 0x0100; /* trap flag */ |
- | |
286 | printf("setting EIP to 0x%08x\n", buffer[eip_idx]); |
- | |
287 | rc = udebug_regs_write(app_phone, thread_hash, buffer); |
- | |
288 | rc = udebug_mem_write(app_phone, &brk_list[bi].back, brk_addr, 1); |
- | |
289 | printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].back, rc); |
- | |
290 | lifted_brkpt = bi; |
- | |
291 | } else { |
- | |
292 | printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
- | |
293 | } |
- | |
294 | break; |
- | |
295 | case UDEBUG_EVENT_TRAP: |
- | |
296 | printf("trap event\n"); |
- | |
297 | unsigned char brkinstr[1]; |
- | |
298 | breakpoint_t *lb = &brk_list[lifted_brkpt]; |
- | |
299 | brkinstr[0] = 0xcc; |
- | |
300 | rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1); |
- | |
301 | printf("restore breakpoint -> %d\n", rc); |
- | |
302 | - | ||
303 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
- | |
304 | printf("udebug_regs_read -> %d\n", rc); |
- | |
305 | int efl_idx2 = 14; |
- | |
306 | buffer[efl_idx2] &= ~0x0100; /* trap flag */ |
- | |
307 | rc = udebug_regs_write(app_phone, thread_hash, buffer); |
- | |
308 | break; |
- | |
309 | default: |
- | |
310 | printf("unknown event type %d\n", ev_type); |
284 | if (rc >= 0) debug_event(thread_hash, ev_type, val0); |
311 | usleep(1000*1000); |
- | |
312 | break; |
- | |
313 | } |
- | |
314 | } |
- | |
315 | - | ||
316 | } |
285 | } |
317 | 286 | ||
318 | printf("debug_loop(%d) exiting\n", thread_id); |
287 | printf("debug_loop(%d) exiting\n", thread_id); |
319 | } |
288 | } |
320 | 289 | ||
321 | void thread_debug_start(unsigned thread_hash) |
290 | void thread_debug_start(unsigned thread_hash) |
322 | { |
291 | { |
323 | fid_t fid; |
292 | fid_t fid; |
324 | 293 | ||
325 | thash = thread_hash; |
294 | thash = thread_hash; |
326 | 295 | ||
327 | fid = fibril_create(debug_loop, (void *)thread_hash); |
296 | fid = fibril_create(debug_loop, (void *)thread_hash); |
328 | if (fid == 0) { |
297 | if (fid == 0) { |
329 | printf("Warning: Failed creating fibril\n"); |
298 | printf("Warning: Failed creating fibril\n"); |
330 | } |
299 | } |
331 | fibril_add_ready(fid); |
300 | fibril_add_ready(fid); |
332 | } |
301 | } |
333 | 302 | ||
334 | void debug_active_task(void) |
303 | void debug_active_task(void) |
335 | { |
304 | { |
336 | int taskid; |
305 | int taskid; |
337 | int i; |
306 | int i; |
338 | int rc; |
307 | int rc; |
339 | int c; |
308 | int c; |
340 | 309 | ||
341 | printf("Breakpoint Debugger\n"); |
310 | printf("Breakpoint Debugger\n"); |
342 | printf("Press 'c' to connect\n"); |
311 | printf("Press 'c' to connect\n"); |
343 | while ((i = getchar()) != 'c') |
312 | while ((i = getchar()) != 'c') |
344 | putchar(i); |
313 | putchar(i); |
345 | 314 | ||
346 | taskid = 14; |
315 | taskid = 14; |
347 | rc = task_connect(taskid); |
316 | rc = task_connect(taskid); |
348 | if (rc < 0) { |
317 | if (rc < 0) { |
349 | printf("Failed to connect to task %d\n", taskid); |
318 | printf("Failed to connect to task %d\n", taskid); |
350 | return; |
319 | return; |
351 | } |
320 | } |
352 | 321 | ||
353 | printf("Connected to task %d\n", taskid); |
322 | printf("Connected to task %d\n", taskid); |
354 | 323 | ||
355 | rc = get_thread_list(); |
324 | rc = get_thread_list(); |
356 | if (rc < 0) { |
325 | if (rc < 0) { |
357 | printf("Failed to get thread list (error %d)\n", rc); |
326 | printf("Failed to get thread list (error %d)\n", rc); |
358 | return; |
327 | return; |
359 | } |
328 | } |
360 | 329 | ||
361 | abort_debug = false; |
330 | abort_debug = false; |
362 | 331 | ||
363 | for (i = 0; i < n_threads; i++) { |
332 | for (i = 0; i < n_threads; i++) { |
364 | thread_debug_start(thread_hash_buf[i]); |
333 | thread_debug_start(thread_hash_buf[i]); |
365 | } |
334 | } |
366 | 335 | ||
367 | while (!quit) { |
336 | while (!quit) { |
368 | printf("> "); |
337 | printf("> "); |
369 | read_line(in_buf, INBUF_SIZE); |
338 | read_line(in_buf, INBUF_SIZE); |
370 | command_split(in_buf); |
339 | command_split(in_buf); |
371 | if (cmd_argc == 0) continue; |
340 | if (cmd_argc == 0) continue; |
372 | 341 | ||
373 | command_run(); |
342 | command_run(); |
374 | } |
343 | } |
375 | 344 | ||
376 | printf("terminate debugging session...\n"); |
345 | printf("terminate debugging session...\n"); |
377 | abort_debug = true; |
346 | abort_debug = true; |
378 | udebug_end(app_phone); |
347 | udebug_end(app_phone); |
379 | ipc_hangup(app_phone); |
348 | ipc_hangup(app_phone); |
380 | 349 | ||
381 | printf("done\n"); |
350 | printf("done\n"); |
382 | return; |
351 | return; |
383 | } |
352 | } |
384 | 353 | ||
385 | static void main_init(void) |
354 | static void main_init(void) |
386 | { |
355 | { |
387 | next_thread_id = 1; |
356 | next_thread_id = 1; |
388 | paused = 0; |
357 | paused = 0; |
389 | } |
358 | } |
390 | 359 | ||
391 | int main(void) |
360 | int main(void) |
392 | { |
361 | { |
393 | main_init(); |
362 | main_init(); |
394 | 363 | ||
395 | while (1) { |
364 | while (1) { |
396 | debug_active_task(); |
365 | debug_active_task(); |
397 | } |
366 | } |
398 | } |
367 | } |
399 | 368 | ||
400 | /** @} |
369 | /** @} |
401 | */ |
370 | */ |
402 | 371 |