Rev 2935 | Rev 2941 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2935 | Rev 2936 | ||
|---|---|---|---|
| Line 35... | Line 35... | ||
| 35 | #include <stdio.h> |
35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
36 | #include <stdlib.h> |
| 37 | #include <sys/types.h> |
37 | #include <sys/types.h> |
| 38 | #include <udebug.h> |
38 | #include <udebug.h> |
| 39 | 39 | ||
| - | 40 | #include "../../../cons.h" |
|
| 40 | #include "../../../main.h" |
41 | #include "../../../main.h" |
| 41 | #include "../../../include/arch.h" |
42 | #include "../../../include/arch.h" |
| 42 | 43 | ||
| 43 | #define OPCODE_INT3 0xCC |
44 | #define OPCODE_INT3 0xCC |
| 44 | 45 | ||
| Line 55... | Line 56... | ||
| 55 | brk = NULL; |
56 | brk = NULL; |
| 56 | for (i = 0; i < MAX_BRKPTS; i++) |
57 | for (i = 0; i < MAX_BRKPTS; i++) |
| 57 | if (brk_list[i].set == 0) brk = brk_list+i; |
58 | if (brk_list[i].set == 0) brk = brk_list+i; |
| 58 | 59 | ||
| 59 | if (!brk) { |
60 | if (!brk) { |
| 60 | printf("too many breakpoints\n"); |
61 | cons_printf("too many breakpoints\n"); |
| 61 | return; |
62 | return; |
| 62 | } |
63 | } |
| 63 | 64 | ||
| 64 | rc = udebug_mem_read(app_phone, &brk->arch.back, addr, 1); |
65 | rc = udebug_mem_read(app_phone, &brk->arch.back, addr, 1); |
| 65 | printf("udebug_mem_read() -> %d\n", rc); |
66 | cons_printf("udebug_mem_read() -> %d\n", rc); |
| 66 | brkp[0] = OPCODE_INT3; |
67 | brkp[0] = OPCODE_INT3; |
| 67 | rc = udebug_mem_write(app_phone, brkp, addr, 1); |
68 | rc = udebug_mem_write(app_phone, brkp, addr, 1); |
| 68 | printf("udebug_mem_write() -> %d\n", rc); |
69 | cons_printf("udebug_mem_write() -> %d\n", rc); |
| 69 | 70 | ||
| 70 | brk->addr = addr; |
71 | brk->addr = addr; |
| 71 | brk->set = 1; |
72 | brk->set = 1; |
| 72 | } |
73 | } |
| 73 | 74 | ||
| Line 77... | Line 78... | ||
| 77 | void arch_event_breakpoint(thash_t thread_hash) |
78 | void arch_event_breakpoint(thash_t thread_hash) |
| 78 | { |
79 | { |
| 79 | int rc; |
80 | int rc; |
| 80 | 81 | ||
| 81 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
82 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
| 82 | printf("udebug_regs_read -> %d\n", rc); |
83 | cons_printf("udebug_regs_read -> %d\n", rc); |
| 83 | printf("EIP was 0x%08x\n", buffer[ISTATE_OFF_EIP]); |
84 | cons_printf("EIP was 0x%08x\n", buffer[ISTATE_OFF_EIP]); |
| 84 | int brk_addr = buffer[ISTATE_OFF_EIP] - 1; |
85 | int brk_addr = buffer[ISTATE_OFF_EIP] - 1; |
| 85 | int bi; |
86 | int bi; |
| 86 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
87 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
| 87 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
88 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
| 88 | break; |
89 | break; |
| 89 | } |
90 | } |
| 90 | 91 | ||
| 91 | if (bi < MAX_BRKPTS) { |
92 | if (bi < MAX_BRKPTS) { |
| 92 | printf("breakpoint %d hit\n", bi); |
93 | cons_printf("breakpoint %d hit\n", bi); |
| 93 | breakpoint_hit(); |
94 | breakpoint_hit(); |
| 94 | 95 | ||
| 95 | buffer[ISTATE_OFF_EIP] = brk_addr; |
96 | buffer[ISTATE_OFF_EIP] = brk_addr; |
| 96 | buffer[ISTATE_OFF_EFLAGS] |= 0x0100; /* trap flag */ |
97 | buffer[ISTATE_OFF_EFLAGS] |= 0x0100; /* trap flag */ |
| 97 | printf("setting EIP to 0x%08x\n", buffer[ISTATE_OFF_EIP]); |
98 | cons_printf("setting EIP to 0x%08x\n", buffer[ISTATE_OFF_EIP]); |
| 98 | rc = udebug_regs_write(app_phone, thread_hash, buffer); |
99 | rc = udebug_regs_write(app_phone, thread_hash, buffer); |
| 99 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1); |
100 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1); |
| 100 | printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
101 | cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
| 101 | lifted_brkpt = &brk_list[bi]; |
102 | lifted_brkpt = &brk_list[bi]; |
| 102 | } else { |
103 | } else { |
| 103 | printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
104 | cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
| 104 | } |
105 | } |
| 105 | } |
106 | } |
| 106 | 107 | ||
| 107 | void arch_event_trap(thash_t thread_hash) |
108 | void arch_event_trap(thash_t thread_hash) |
| 108 | { |
109 | { |
| 109 | unsigned char brkinstr[1]; |
110 | unsigned char brkinstr[1]; |
| 110 | int rc; |
111 | int rc; |
| 111 | 112 | ||
| 112 | printf("trap event\n"); |
113 | cons_printf("trap event\n"); |
| 113 | 114 | ||
| 114 | breakpoint_t *lb = lifted_brkpt; |
115 | breakpoint_t *lb = lifted_brkpt; |
| 115 | brkinstr[0] = OPCODE_INT3; |
116 | brkinstr[0] = OPCODE_INT3; |
| 116 | rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1); |
117 | rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1); |
| 117 | printf("restore breakpoint -> %d\n", rc); |
118 | cons_printf("restore breakpoint -> %d\n", rc); |
| 118 | 119 | ||
| 119 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
120 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
| 120 | printf("udebug_regs_read -> %d\n", rc); |
121 | cons_printf("udebug_regs_read -> %d\n", rc); |
| 121 | buffer[ISTATE_OFF_EFLAGS] &= ~0x0100; /* trap flag */ |
122 | buffer[ISTATE_OFF_EFLAGS] &= ~0x0100; /* trap flag */ |
| 122 | rc = udebug_regs_write(app_phone, thread_hash, buffer); |
123 | rc = udebug_regs_write(app_phone, thread_hash, buffer); |
| 123 | } |
124 | } |
| 124 | 125 | ||
| 125 | /** @} |
126 | /** @} |