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