Rev 2922 | Rev 2924 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2922 | Rev 2923 | ||
---|---|---|---|
Line 42... | Line 42... | ||
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 |
Line 219... | Line 220... | ||
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; |
Line 239... | Line 274... | ||
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 |