-
Notifications
You must be signed in to change notification settings - Fork 0
/
breakpoint.c
74 lines (64 loc) · 1.41 KB
/
breakpoint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "breakpoint.h"
#include "state.h"
#include "logging.h"
// controller of breakpoint list
//////////////
int is_here_breakpoint(blist_t *blist, uint32_t addr){
blist_t *head = blist;
while(head != NULL){
if(head->addr == addr)
return 1;
head = head->next;
}
return 0;
}
void insert_new_breakpoint(blist_t **blist, uint32_t addr){
// prepare an element
blist_t *new_elm = malloc(sizeof(blist_t));
new_elm->addr = addr;
new_elm->next = NULL;
if(1 == is_here_breakpoint(*blist, addr)){
error("Breakpoint for 0x%08x is already set.", addr);
return;
}
blist_t **prev = NULL;
blist_t **seek = blist;
while (*seek != NULL){
if(addr < (*seek)->addr){
break;
} else {
prev = seek;
seek = &((*seek)->next);
}
}
new_elm->next = *seek;
if(prev == NULL){
*seek = new_elm;
} else {
(*prev)->next = new_elm;
}
}
void delete_breakpoint_by_id(blist_t **blist, int id){
blist_t **prev = NULL;
blist_t **seek = blist;
// pre-validate
if (*blist == NULL){
error("There's no breakpoint. Stop.");
return;
}
// search
for(int i=0; i < id; i++){
if((*seek)->next == NULL){
error("No such breakpoint: %d. Stop.", id);
return;
} else {
prev = seek;
seek = &((*seek)->next);
}
}
// delete
if(prev != NULL){
(*prev)->next = (*seek)->next;
}
free(*seek);
}