| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include<stdint.h> |
| 19 |
|
| 20 |
volatile uint8_t run_breakpoint_test; |
| 21 |
volatile uint8_t watchpoint_write; |
| 22 |
volatile uint8_t watchpoint_read; |
| 23 |
volatile uint8_t watchpoint_size; |
| 24 |
void * volatile write_address; |
| 25 |
|
| 26 |
volatile uint32_t watchpoint_write_buffer[3]; |
| 27 |
|
| 28 |
|
| 29 |
void function_1() |
| 30 |
{ |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
void function_2() |
| 35 |
{ |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
void function_3() |
| 40 |
{ |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
void breakpoint_test() |
| 45 |
{ |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
void watchpoint_test() |
| 50 |
{ |
| 51 |
if (1 == watchpoint_size) { |
| 52 |
if (watchpoint_read) { |
| 53 |
*(volatile uint8_t*) write_address; |
| 54 |
} |
| 55 |
if (watchpoint_write) { |
| 56 |
*(volatile uint8_t*) write_address = 42; |
| 57 |
} |
| 58 |
} else if (2 == watchpoint_size) { |
| 59 |
if (watchpoint_read) { |
| 60 |
*(volatile uint16_t*) write_address; |
| 61 |
} |
| 62 |
if (watchpoint_write) { |
| 63 |
*(volatile uint16_t*) write_address = 42; |
| 64 |
} |
| 65 |
} else if (4 == watchpoint_size) { |
| 66 |
if (watchpoint_read) { |
| 67 |
*(volatile uint32_t*) write_address; |
| 68 |
} |
| 69 |
if (watchpoint_write) { |
| 70 |
*(volatile uint32_t*) write_address = 42; |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
int main() |
| 76 |
{ |
| 77 |
int i; |
| 78 |
|
| 79 |
|
| 80 |
run_breakpoint_test = 0; |
| 81 |
watchpoint_write = 0; |
| 82 |
watchpoint_read = 0; |
| 83 |
watchpoint_size = 0; |
| 84 |
write_address = 0; |
| 85 |
for (i = 0; i < sizeof(watchpoint_write_buffer) / |
| 86 |
sizeof(watchpoint_write_buffer[0]); i++) { |
| 87 |
watchpoint_write_buffer[i] = 0; |
| 88 |
} |
| 89 |
|
| 90 |
while(1) { |
| 91 |
function_1(); |
| 92 |
function_2(); |
| 93 |
function_3(); |
| 94 |
if (run_breakpoint_test) { |
| 95 |
breakpoint_test(); |
| 96 |
} |
| 97 |
if (watchpoint_size) { |
| 98 |
watchpoint_test(); |
| 99 |
} |
| 100 |
} |
| 101 |
} |