comparison packages/cygmon/current/misc/breakpoints.c @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children 02ea4320376c
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
1 //==========================================================================
2 //
3 // breakpoints.c
4 //
5 // Support aribtrary set of breakpoints.
6 //
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //==========================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s):
35 // Contributors: gthomas
36 // Date: 1999-10-20
37 // Purpose:
38 // Description:
39 //
40 //
41 //####DESCRIPTIONEND####
42 //
43 //=========================================================================
44
45 #include <stdlib.h>
46 #ifdef HAVE_BSP
47 #include <bsp/bsp.h>
48 #include <bsp/cpu.h>
49 #endif
50
51 #include "monitor.h"
52 #include "tservice.h"
53 #include "stub-tservice.h"
54
55 #include "fmt_util.h"
56
57
58 static struct bp *last_bp_ptr;
59 static struct bp *first_bp_ptr;
60
61 #ifdef NO_MALLOC
62 static struct bp *free_bp_list;
63 static struct bp bp_list[MAX_NUM_BP];
64 static int curr_bp_num;
65 #endif
66
67 int
68 add_mon_breakpoint (mem_addr_t location)
69 {
70 struct bp *ptr;
71 struct bp *new_bp_ptr;
72
73 for (ptr = first_bp_ptr; ptr != NULL; ptr = ptr->next)
74 {
75 if (MEM_ADDR_EQ_P (ptr->address, location))
76 return 1;
77 }
78 #ifdef NO_MALLOC
79 if (free_bp_list != NULL)
80 {
81 new_bp_ptr = free_bp_list;
82 free_bp_list = new_bp_ptr->next;
83 }
84 else
85 {
86 if (curr_bp_num < MAX_NUM_BP)
87 {
88 new_bp_ptr = &bp_list[curr_bp_num++];
89 }
90 else
91 {
92 xprintf ("No more breakpoints\n");
93 return 1;
94 }
95 }
96 #else
97 new_bp_ptr = (struct bp *)malloc (sizeof (struct bp));
98 #endif
99
100 if (first_bp_ptr == NULL)
101 {
102 first_bp_ptr = new_bp_ptr;
103 }
104 else
105 {
106 last_bp_ptr->next = new_bp_ptr;
107 }
108 last_bp_ptr = new_bp_ptr;
109
110 last_bp_ptr->next = NULL;
111 last_bp_ptr->address = location;
112 last_bp_ptr->in_memory = 0;
113 return 0;
114 }
115
116
117 void
118 install_breakpoints (void)
119 {
120 struct bp *ptr = first_bp_ptr;
121 while (ptr != NULL)
122 {
123 set_breakpoint (ptr);
124 ptr = ptr->next;
125 }
126 }
127
128
129 void
130 clear_breakpoints (void)
131 {
132 struct bp *ptr = first_bp_ptr;
133
134 while (ptr != NULL)
135 {
136 clear_breakpoint (ptr);
137 ptr = ptr->next;
138 }
139 }
140
141 int
142 show_breakpoints (void)
143 {
144 struct bp *ptr;
145
146 for (ptr = first_bp_ptr; ptr != NULL; ptr = ptr->next)
147 {
148 char buf[20];
149
150 addr2str (&ptr->address, buf);
151 xprintf ("%s\n", buf);
152 }
153
154 return 0;
155 }
156
157
158
159 int
160 clear_mon_breakpoint (mem_addr_t location)
161 {
162 int error = 0;
163 struct bp *ptr = first_bp_ptr;
164 struct bp *prev_ptr = NULL;
165
166 /* Scan the list looking for the address to clear */
167 while (ptr != NULL && !MEM_ADDR_EQ_P (ptr->address, location))
168 {
169 /* keep a pointer one behind the current position */
170 prev_ptr = ptr;
171 ptr = ptr->next;
172 }
173 if (ptr == NULL)
174 {
175 xprintf ("That address has no breakpoint on it.\n");
176 error = 1;
177 }
178 else
179 {
180 /* Just in case it's still in memory. */
181 clear_breakpoint (ptr);
182
183 /* now we'll point the previous bp->next at the one after the one
184 we're deleting, unless there is no previous bp. */
185 if (prev_ptr != NULL)
186 {
187 prev_ptr->next = ptr->next;
188 }
189
190 if (first_bp_ptr == ptr)
191 first_bp_ptr = ptr->next;
192
193 if (last_bp_ptr == ptr)
194 last_bp_ptr = prev_ptr;
195
196 /* eliminate the offending bp struct */
197 #ifdef NO_MALLOC
198 ptr->next = free_bp_list;
199 free_bp_list = ptr;
200 #else
201 free (ptr);
202 #endif
203 }
204 return error;
205 }
206