diff options
Diffstat (limited to 'src/monkey/alloc.c')
-rw-r--r-- | src/monkey/alloc.c | 308 |
1 files changed, 308 insertions, 0 deletions
diff --git a/src/monkey/alloc.c b/src/monkey/alloc.c new file mode 100644 index 000000000..9e1ffa740 --- /dev/null +++ b/src/monkey/alloc.c | |||
@@ -0,0 +1,308 @@ | |||
1 | /**[txh]******************************************************************** | ||
2 | |||
3 | Copyright (c) 2004 by Salvador E. Tropea. | ||
4 | Covered by the GPL license. | ||
5 | |||
6 | Module: Allocator. | ||
7 | Comments: | ||
8 | Most alloc/free routines are here. Free routines must accept NULL | ||
9 | pointers. Alloc functions must set mi_error.@p | ||
10 | |||
11 | ***************************************************************************/ | ||
12 | |||
13 | #include "mi_gdb.h" | ||
14 | |||
15 | void *mi_calloc(size_t count, size_t sz) | ||
16 | { | ||
17 | void *res=calloc(count,sz); | ||
18 | if (!res) | ||
19 | mi_error=MI_OUT_OF_MEMORY; | ||
20 | return res; | ||
21 | } | ||
22 | |||
23 | void *mi_calloc1(size_t sz) | ||
24 | { | ||
25 | return mi_calloc(1,sz); | ||
26 | } | ||
27 | |||
28 | char *mi_malloc(size_t sz) | ||
29 | { | ||
30 | char *res=malloc(sz); | ||
31 | if (!res) | ||
32 | mi_error=MI_OUT_OF_MEMORY; | ||
33 | return res; | ||
34 | } | ||
35 | |||
36 | mi_results *mi_alloc_results(void) | ||
37 | { | ||
38 | return (mi_results *)mi_calloc1(sizeof(mi_results)); | ||
39 | } | ||
40 | |||
41 | mi_output *mi_alloc_output(void) | ||
42 | { | ||
43 | return (mi_output *)mi_calloc1(sizeof(mi_output)); | ||
44 | } | ||
45 | |||
46 | mi_frames *mi_alloc_frames(void) | ||
47 | { | ||
48 | return (mi_frames *)mi_calloc1(sizeof(mi_frames)); | ||
49 | } | ||
50 | |||
51 | mi_gvar *mi_alloc_gvar(void) | ||
52 | { | ||
53 | return (mi_gvar *)mi_calloc1(sizeof(mi_gvar)); | ||
54 | } | ||
55 | |||
56 | mi_gvar_chg *mi_alloc_gvar_chg(void) | ||
57 | { | ||
58 | return (mi_gvar_chg *)mi_calloc1(sizeof(mi_gvar_chg)); | ||
59 | } | ||
60 | |||
61 | mi_bkpt *mi_alloc_bkpt(void) | ||
62 | { | ||
63 | mi_bkpt *b=(mi_bkpt *)mi_calloc1(sizeof(mi_bkpt)); | ||
64 | if (b) | ||
65 | { | ||
66 | b->thread=-1; | ||
67 | b->ignore=-1; | ||
68 | } | ||
69 | return b; | ||
70 | } | ||
71 | |||
72 | mi_wp *mi_alloc_wp(void) | ||
73 | { | ||
74 | return (mi_wp *)mi_calloc1(sizeof(mi_wp)); | ||
75 | } | ||
76 | |||
77 | mi_stop *mi_alloc_stop(void) | ||
78 | { | ||
79 | return (mi_stop *)mi_calloc1(sizeof(mi_stop)); | ||
80 | } | ||
81 | |||
82 | mi_asm_insns *mi_alloc_asm_insns(void) | ||
83 | { | ||
84 | return (mi_asm_insns *)mi_calloc1(sizeof(mi_asm_insns)); | ||
85 | } | ||
86 | |||
87 | mi_asm_insn *mi_alloc_asm_insn(void) | ||
88 | { | ||
89 | return (mi_asm_insn *)mi_calloc1(sizeof(mi_asm_insn)); | ||
90 | } | ||
91 | |||
92 | mi_chg_reg *mi_alloc_chg_reg(void) | ||
93 | { | ||
94 | return (mi_chg_reg *)mi_calloc1(sizeof(mi_chg_reg)); | ||
95 | } | ||
96 | |||
97 | /***************************************************************************** | ||
98 | Free functions | ||
99 | *****************************************************************************/ | ||
100 | |||
101 | void mi_free_frames(mi_frames *f) | ||
102 | { | ||
103 | mi_frames *aux; | ||
104 | |||
105 | while (f) | ||
106 | { | ||
107 | free(f->func); | ||
108 | free(f->file); | ||
109 | free(f->from); | ||
110 | mi_free_results(f->args); | ||
111 | aux=f->next; | ||
112 | free(f); | ||
113 | f=aux; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | void mi_free_bkpt(mi_bkpt *b) | ||
118 | { | ||
119 | mi_bkpt *aux; | ||
120 | |||
121 | while (b) | ||
122 | { | ||
123 | free(b->func); | ||
124 | free(b->file); | ||
125 | free(b->file_abs); | ||
126 | free(b->cond); | ||
127 | aux=b->next; | ||
128 | free(b); | ||
129 | b=aux; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | void mi_free_gvar(mi_gvar *v) | ||
134 | { | ||
135 | mi_gvar *aux; | ||
136 | |||
137 | while (v) | ||
138 | { | ||
139 | free(v->name); | ||
140 | free(v->type); | ||
141 | free(v->exp); | ||
142 | free(v->value); | ||
143 | if (v->numchild && v->child) | ||
144 | mi_free_gvar(v->child); | ||
145 | aux=v->next; | ||
146 | free(v); | ||
147 | v=aux; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | void mi_free_gvar_chg(mi_gvar_chg *p) | ||
152 | { | ||
153 | mi_gvar_chg *aux; | ||
154 | |||
155 | while (p) | ||
156 | { | ||
157 | free(p->name); | ||
158 | free(p->new_type); | ||
159 | aux=p->next; | ||
160 | free(p); | ||
161 | p=aux; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | void mi_free_results_but(mi_results *r, mi_results *no) | ||
166 | { | ||
167 | mi_results *aux; | ||
168 | |||
169 | while (r) | ||
170 | { | ||
171 | if (r==no) | ||
172 | { | ||
173 | aux=r->next; | ||
174 | r->next=NULL; | ||
175 | r=aux; | ||
176 | } | ||
177 | else | ||
178 | { | ||
179 | free(r->var); | ||
180 | switch (r->type) | ||
181 | { | ||
182 | case t_const: | ||
183 | free(r->v.cstr); | ||
184 | break; | ||
185 | case t_tuple: | ||
186 | case t_list: | ||
187 | mi_free_results_but(r->v.rs,no); | ||
188 | break; | ||
189 | } | ||
190 | aux=r->next; | ||
191 | free(r); | ||
192 | r=aux; | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | |||
197 | void mi_free_results(mi_results *r) | ||
198 | { | ||
199 | mi_free_results_but(r,NULL); | ||
200 | } | ||
201 | |||
202 | void mi_free_output_but(mi_output *r, mi_output *no, mi_results *no_r) | ||
203 | { | ||
204 | mi_output *aux; | ||
205 | |||
206 | while (r) | ||
207 | { | ||
208 | if (r==no) | ||
209 | { | ||
210 | aux=r->next; | ||
211 | r->next=NULL; | ||
212 | r=aux; | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | if (r->c) | ||
217 | mi_free_results_but(r->c,no_r); | ||
218 | aux=r->next; | ||
219 | free(r); | ||
220 | r=aux; | ||
221 | } | ||
222 | } | ||
223 | } | ||
224 | |||
225 | void mi_free_output(mi_output *r) | ||
226 | { | ||
227 | mi_free_output_but(r,NULL,NULL); | ||
228 | } | ||
229 | |||
230 | void mi_free_stop(mi_stop *s) | ||
231 | { | ||
232 | if (!s) | ||
233 | return; | ||
234 | mi_free_frames(s->frame); | ||
235 | mi_free_wp(s->wp); | ||
236 | free(s->wp_old); | ||
237 | free(s->wp_val); | ||
238 | free(s->gdb_result_var); | ||
239 | free(s->return_value); | ||
240 | free(s->signal_name); | ||
241 | free(s->signal_meaning); | ||
242 | free(s); | ||
243 | } | ||
244 | |||
245 | void mi_free_wp(mi_wp *wp) | ||
246 | { | ||
247 | mi_wp *aux; | ||
248 | while (wp) | ||
249 | { | ||
250 | free(wp->exp); | ||
251 | aux=wp->next; | ||
252 | free(wp); | ||
253 | wp=aux; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | void mi_free_asm_insns(mi_asm_insns *i) | ||
258 | { | ||
259 | mi_asm_insns *aux; | ||
260 | |||
261 | while (i) | ||
262 | { | ||
263 | free(i->file); | ||
264 | mi_free_asm_insn(i->ins); | ||
265 | aux=i->next; | ||
266 | free(i); | ||
267 | i=aux; | ||
268 | } | ||
269 | } | ||
270 | |||
271 | void mi_free_asm_insn(mi_asm_insn *i) | ||
272 | { | ||
273 | mi_asm_insn *aux; | ||
274 | |||
275 | while (i) | ||
276 | { | ||
277 | free(i->func); | ||
278 | free(i->inst); | ||
279 | aux=i->next; | ||
280 | free(i); | ||
281 | i=aux; | ||
282 | } | ||
283 | } | ||
284 | |||
285 | /*void mi_free_charp_list(char **l) | ||
286 | { | ||
287 | char **c=l; | ||
288 | while (c) | ||
289 | { | ||
290 | free(*c); | ||
291 | c++; | ||
292 | } | ||
293 | free(l); | ||
294 | }*/ | ||
295 | |||
296 | void mi_free_chg_reg(mi_chg_reg *r) | ||
297 | { | ||
298 | mi_chg_reg *aux; | ||
299 | while (r) | ||
300 | { | ||
301 | free(r->val); | ||
302 | free(r->name); | ||
303 | aux=r->next; | ||
304 | free(r); | ||
305 | r=aux; | ||
306 | } | ||
307 | } | ||
308 | |||