diff options
Diffstat (limited to 'src/debug.c')
-rw-r--r-- | src/debug.c | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/src/debug.c b/src/debug.c index 00f568c..08957ed 100644 --- a/src/debug.c +++ b/src/debug.c | |||
@@ -136,140 +136,3 @@ gdbm_debug_datum (datum dat, char const *pfx) | |||
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | |||
140 | struct hook_list | ||
141 | { | ||
142 | struct hook_list *next; | ||
143 | struct hook_list *prev; | ||
144 | char *id; | ||
145 | gdbm_debug_hook hook; | ||
146 | void *data; | ||
147 | int retval; | ||
148 | }; | ||
149 | |||
150 | static struct hook_list *hook_head, *hook_tail; | ||
151 | static struct hook_list *hook_recent; | ||
152 | |||
153 | static struct hook_list * | ||
154 | hook_lookup_or_install (char const *id, int install) | ||
155 | { | ||
156 | struct hook_list *p; | ||
157 | |||
158 | for (p = hook_head; p; p = p->next) | ||
159 | { | ||
160 | int res = strcmp (p->id, id); | ||
161 | if (res == 0) | ||
162 | return p; | ||
163 | if (res > 0) | ||
164 | break; | ||
165 | } | ||
166 | |||
167 | if (install) | ||
168 | { | ||
169 | struct hook_list *elt = malloc (sizeof *elt); | ||
170 | if (!elt) | ||
171 | return NULL; | ||
172 | elt->id = strdup (id); | ||
173 | if (!elt->id) | ||
174 | { | ||
175 | SAVE_ERRNO (free (elt)); | ||
176 | return NULL; | ||
177 | } | ||
178 | elt->hook = NULL; | ||
179 | elt->next = p; | ||
180 | if (p) | ||
181 | { | ||
182 | if (p->prev) | ||
183 | p->prev->next = elt; | ||
184 | else | ||
185 | hook_head = elt; | ||
186 | elt->prev = p->prev; | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | elt->prev = hook_tail; | ||
191 | if (hook_tail) | ||
192 | hook_tail->next = elt; | ||
193 | else | ||
194 | hook_head = elt; | ||
195 | hook_tail = elt; | ||
196 | } | ||
197 | return elt; | ||
198 | } | ||
199 | |||
200 | return NULL; | ||
201 | } | ||
202 | |||
203 | static struct hook_list * | ||
204 | hook_lookup (char const *id) | ||
205 | { | ||
206 | if (!(hook_recent && strcmp (hook_recent->id, id) == 0)) | ||
207 | hook_recent = hook_lookup_or_install (id, FALSE); | ||
208 | return hook_recent; | ||
209 | } | ||
210 | |||
211 | static void | ||
212 | hook_remove (char const *id) | ||
213 | { | ||
214 | struct hook_list *p; | ||
215 | |||
216 | p = hook_lookup (id); | ||
217 | if (!p) | ||
218 | return; | ||
219 | |||
220 | hook_recent = NULL; | ||
221 | |||
222 | if (p->prev) | ||
223 | p->prev->next = p->next; | ||
224 | else | ||
225 | hook_head = p->next; | ||
226 | |||
227 | if (p->next) | ||
228 | p->next->prev = p->prev; | ||
229 | else | ||
230 | hook_tail = p->prev; | ||
231 | |||
232 | free (p->id); | ||
233 | free (p); | ||
234 | } | ||
235 | |||
236 | static int | ||
237 | default_hook (char const *file, int line, char const *id, void *data) | ||
238 | { | ||
239 | fprintf (stderr, "%s:%d: hit debug hook %s\n", file, line, id); | ||
240 | return 1; | ||
241 | } | ||
242 | |||
243 | void | ||
244 | _gdbm_debug_hook_install (char const *id, gdbm_debug_hook hook, void *data) | ||
245 | { | ||
246 | struct hook_list *p; | ||
247 | |||
248 | p = hook_lookup_or_install (id, TRUE); | ||
249 | p->hook = hook ? hook : default_hook; | ||
250 | p->data = data; | ||
251 | } | ||
252 | |||
253 | void | ||
254 | _gdbm_debug_hook_remove (char const *id) | ||
255 | { | ||
256 | hook_remove (id); | ||
257 | } | ||
258 | |||
259 | int | ||
260 | _gdbm_debug_hook_check (char const *file, int line, char const *id) | ||
261 | { | ||
262 | struct hook_list *p = hook_lookup (id); | ||
263 | if (p) | ||
264 | return p->retval = p->hook (file, line, id, p->data); | ||
265 | return 0; | ||
266 | } | ||
267 | |||
268 | int | ||
269 | _gdbm_debug_hook_val (char const *id) | ||
270 | { | ||
271 | struct hook_list *p = hook_lookup (id); | ||
272 | if (p) | ||
273 | return p->retval; | ||
274 | return 0; | ||
275 | } | ||