diff options
author | Safey A.Halim <safey.allah@gmail.com> | 2010-06-29 19:14:37 +0000 |
---|---|---|
committer | Safey A.Halim <safey.allah@gmail.com> | 2010-06-29 19:14:37 +0000 |
commit | 1e2ec555753751d032dbe1f19d5206a2da4de65a (patch) | |
tree | ba5f6d9487ab2f7aea7fa98d1de3d6abef268b33 /src/monkey/var_obj.c | |
parent | c75af8bb6df74bfcba1e7b1a3123babf066a1939 (diff) | |
download | gnunet-1e2ec555753751d032dbe1f19d5206a2da4de65a.tar.gz gnunet-1e2ec555753751d032dbe1f19d5206a2da4de65a.zip |
Adding "Monkey", GNUnet module for automatic debugging. Experimental code so far.
Diffstat (limited to 'src/monkey/var_obj.c')
-rw-r--r-- | src/monkey/var_obj.c | 369 |
1 files changed, 369 insertions, 0 deletions
diff --git a/src/monkey/var_obj.c b/src/monkey/var_obj.c new file mode 100644 index 000000000..a027d6751 --- /dev/null +++ b/src/monkey/var_obj.c | |||
@@ -0,0 +1,369 @@ | |||
1 | /**[txh]******************************************************************** | ||
2 | |||
3 | Copyright (c) 2004 by Salvador E. Tropea. | ||
4 | Covered by the GPL license. | ||
5 | |||
6 | Module: Variable objects. | ||
7 | Comments: | ||
8 | GDB/MI commands for the "Variable Objects" section.@p | ||
9 | |||
10 | @<pre> | ||
11 | gdb command: Imp? Description: | ||
12 | -var-create Yes create a variable object | ||
13 | -var-delete Yes delete the variable object and its children | ||
14 | -var-set-format Yes set the display format of this variable | ||
15 | -var-show-format Yes show the display format of this variable | ||
16 | -var-info-num-children Yes tells how many children this object has | ||
17 | -var-list-children Yes* return a list of the object's children | ||
18 | -var-info-type Yes show the type of this variable object | ||
19 | -var-info-expression Yes print what this variable object represents | ||
20 | -var-show-attributes Yes is this variable editable? | ||
21 | -var-evaluate-expression Yes get the value of this variable | ||
22 | -var-assign Yes set the value of this variable | ||
23 | -var-update Yes* update the variable and its children | ||
24 | @</pre> | ||
25 | |||
26 | Notes:@p | ||
27 | 1) I suggest letting gdb to choose the names for the variables.@* | ||
28 | 2) -var-list-children supports an optional "show values" argument in MI v2. | ||
29 | It isn't implemented.@* | ||
30 | @p | ||
31 | |||
32 | * MI v1 and v2 result formats supported.@p | ||
33 | |||
34 | ***************************************************************************/ | ||
35 | |||
36 | #include "mi_gdb.h" | ||
37 | |||
38 | /* Low level versions. */ | ||
39 | |||
40 | void mi_var_create(mi_h *h, const char *name, int frame, const char *exp) | ||
41 | { | ||
42 | const char *n=name ? name : "-"; | ||
43 | |||
44 | if (frame<0) | ||
45 | mi_send(h,"-var-create %s * %s\n",n,exp); | ||
46 | else | ||
47 | mi_send(h,"-var-create %s %d %s\n",n,frame,exp); | ||
48 | } | ||
49 | |||
50 | void mi_var_delete(mi_h *h, const char *name) | ||
51 | { | ||
52 | mi_send(h,"-var-delete %s\n",name); | ||
53 | } | ||
54 | |||
55 | void mi_var_set_format(mi_h *h, const char *name, const char *format) | ||
56 | { | ||
57 | mi_send(h,"-var-set-format \"%s\" %s\n",name,format); | ||
58 | } | ||
59 | |||
60 | void mi_var_show_format(mi_h *h, const char *name) | ||
61 | { | ||
62 | mi_send(h,"-var-show-format \"%s\"\n",name); | ||
63 | } | ||
64 | |||
65 | void mi_var_info_num_children(mi_h *h, const char *name) | ||
66 | { | ||
67 | mi_send(h,"-var-info-num-children \"%s\"\n",name); | ||
68 | } | ||
69 | |||
70 | void mi_var_info_type(mi_h *h, const char *name) | ||
71 | { | ||
72 | mi_send(h,"-var-info-type \"%s\"\n",name); | ||
73 | } | ||
74 | |||
75 | void mi_var_info_expression(mi_h *h, const char *name) | ||
76 | { | ||
77 | mi_send(h,"-var-info-expression \"%s\"\n",name); | ||
78 | } | ||
79 | |||
80 | void mi_var_show_attributes(mi_h *h, const char *name) | ||
81 | { | ||
82 | mi_send(h,"-var-show-attributes \"%s\"\n",name); | ||
83 | } | ||
84 | |||
85 | void mi_var_update(mi_h *h, const char *name) | ||
86 | { | ||
87 | if (name) | ||
88 | mi_send(h,"-var-update %s\n",name); | ||
89 | else | ||
90 | mi_send(h,"-var-update *\n"); | ||
91 | } | ||
92 | |||
93 | void mi_var_assign(mi_h *h, const char *name, const char *expression) | ||
94 | { | ||
95 | mi_send(h,"-var-assign \"%s\" \"%s\"\n",name,expression); | ||
96 | } | ||
97 | |||
98 | void mi_var_evaluate_expression(mi_h *h, const char *name) | ||
99 | { | ||
100 | mi_send(h,"-var-evaluate-expression \"%s\"\n",name); | ||
101 | } | ||
102 | |||
103 | void mi_var_list_children(mi_h *h, const char *name) | ||
104 | { | ||
105 | if (h->version>=MI_VERSION2U(2,0,0)) | ||
106 | mi_send(h,"-var-list-children --all-values \"%s\"\n",name); | ||
107 | else | ||
108 | mi_send(h,"-var-list-children \"%s\"\n",name); | ||
109 | } | ||
110 | |||
111 | /* High level versions. */ | ||
112 | |||
113 | /**[txh]******************************************************************** | ||
114 | |||
115 | Description: | ||
116 | Create a variable object. I recommend using @x{gmi_var_create} and letting | ||
117 | gdb choose the names. | ||
118 | |||
119 | Command: -var-create | ||
120 | Return: A new mi_gvar strcture or NULL on error. | ||
121 | |||
122 | ***************************************************************************/ | ||
123 | |||
124 | mi_gvar *gmi_var_create_nm(mi_h *h, const char *name, int frame, const char *exp) | ||
125 | { | ||
126 | mi_var_create(h,name,frame,exp); | ||
127 | return mi_res_gvar(h,NULL,exp); | ||
128 | } | ||
129 | |||
130 | /**[txh]******************************************************************** | ||
131 | |||
132 | Description: | ||
133 | Create a variable object. The name is selected by gdb. Alternative: | ||
134 | @x{gmi_full_var_create}. | ||
135 | |||
136 | Command: -var-create [auto name] | ||
137 | Return: A new mi_gvar strcture or NULL on error. | ||
138 | |||
139 | ***************************************************************************/ | ||
140 | |||
141 | mi_gvar *gmi_var_create(mi_h *h, int frame, const char *exp) | ||
142 | { | ||
143 | return gmi_var_create_nm(h,NULL,frame,exp); | ||
144 | } | ||
145 | |||
146 | /**[txh]******************************************************************** | ||
147 | |||
148 | Description: | ||
149 | Delete a variable object. Doesn't free the mi_gvar data. | ||
150 | |||
151 | Command: -var-delete | ||
152 | Return: !=0 OK | ||
153 | |||
154 | ***************************************************************************/ | ||
155 | |||
156 | int gmi_var_delete(mi_h *h, mi_gvar *var) | ||
157 | { | ||
158 | mi_var_delete(h,var->name); | ||
159 | return mi_res_simple_done(h); | ||
160 | } | ||
161 | |||
162 | /**[txh]******************************************************************** | ||
163 | |||
164 | Description: | ||
165 | Set the format used to represent the result. | ||
166 | |||
167 | Command: -var-set-format | ||
168 | Return: !=0 OK | ||
169 | |||
170 | ***************************************************************************/ | ||
171 | |||
172 | int gmi_var_set_format(mi_h *h, mi_gvar *var, enum mi_gvar_fmt format) | ||
173 | { | ||
174 | int ret; | ||
175 | |||
176 | mi_var_set_format(h,var->name,mi_format_enum_to_str(format)); | ||
177 | ret=mi_res_simple_done(h); | ||
178 | if (ret) | ||
179 | var->format=format; | ||
180 | return ret; | ||
181 | } | ||
182 | |||
183 | /**[txh]******************************************************************** | ||
184 | |||
185 | Description: | ||
186 | Fill the format field with info from gdb. | ||
187 | |||
188 | Command: -var-show-format | ||
189 | Return: !=0 OK. | ||
190 | |||
191 | ***************************************************************************/ | ||
192 | |||
193 | int gmi_var_show_format(mi_h *h, mi_gvar *var) | ||
194 | { | ||
195 | mi_var_show_format(h,var->name); | ||
196 | return mi_res_gvar(h,var,NULL)!=NULL; | ||
197 | } | ||
198 | |||
199 | /**[txh]******************************************************************** | ||
200 | |||
201 | Description: | ||
202 | Fill the numchild field with info from gdb. | ||
203 | |||
204 | Command: -var-info-num-children | ||
205 | Return: !=0 OK | ||
206 | |||
207 | ***************************************************************************/ | ||
208 | |||
209 | int gmi_var_info_num_children(mi_h *h, mi_gvar *var) | ||
210 | { | ||
211 | mi_var_info_num_children(h,var->name); | ||
212 | return mi_res_gvar(h,var,NULL)!=NULL; | ||
213 | } | ||
214 | |||
215 | /**[txh]******************************************************************** | ||
216 | |||
217 | Description: | ||
218 | Fill the type field with info from gdb. | ||
219 | |||
220 | Command: -var-info-type | ||
221 | Return: !=0 OK | ||
222 | |||
223 | ***************************************************************************/ | ||
224 | |||
225 | int gmi_var_info_type(mi_h *h, mi_gvar *var) | ||
226 | { | ||
227 | mi_var_info_type(h,var->name); | ||
228 | return mi_res_gvar(h,var,NULL)!=NULL; | ||
229 | } | ||
230 | |||
231 | /**[txh]******************************************************************** | ||
232 | |||
233 | Description: | ||
234 | Fill the expression and lang fields with info from gdb. Note that lang | ||
235 | isn't filled during creation. | ||
236 | |||
237 | Command: -var-info-expression | ||
238 | Return: !=0 OK | ||
239 | |||
240 | ***************************************************************************/ | ||
241 | |||
242 | int gmi_var_info_expression(mi_h *h, mi_gvar *var) | ||
243 | { | ||
244 | mi_var_info_expression(h,var->name); | ||
245 | return mi_res_gvar(h,var,NULL)!=NULL; | ||
246 | } | ||
247 | |||
248 | |||
249 | /**[txh]******************************************************************** | ||
250 | |||
251 | Description: | ||
252 | Fill the attr field with info from gdb. Note that attr isn't filled | ||
253 | during creation. | ||
254 | |||
255 | Command: -var-show-attributes | ||
256 | Return: !=0 OK | ||
257 | |||
258 | ***************************************************************************/ | ||
259 | |||
260 | int gmi_var_show_attributes(mi_h *h, mi_gvar *var) | ||
261 | { | ||
262 | mi_var_show_attributes(h,var->name); | ||
263 | return mi_res_gvar(h,var,NULL)!=NULL; | ||
264 | } | ||
265 | |||
266 | /**[txh]******************************************************************** | ||
267 | |||
268 | Description: | ||
269 | Create the variable and also fill the lang and attr fields. The name is | ||
270 | selected by gdb. | ||
271 | |||
272 | Command: -var-create + -var-info-expression + -var-show-attributes | ||
273 | Return: A new mi_gvar strcture or NULL on error. | ||
274 | |||
275 | ***************************************************************************/ | ||
276 | |||
277 | mi_gvar *gmi_full_var_create(mi_h *h, int frame, const char *exp) | ||
278 | { | ||
279 | mi_gvar *var=gmi_var_create_nm(h,NULL,frame,exp); | ||
280 | if (var) | ||
281 | {/* What if it fails? */ | ||
282 | gmi_var_info_expression(h,var); | ||
283 | gmi_var_show_attributes(h,var); | ||
284 | } | ||
285 | return var; | ||
286 | } | ||
287 | |||
288 | /**[txh]******************************************************************** | ||
289 | |||
290 | Description: | ||
291 | Update variable. Use NULL for all. Note that *changed can be NULL if none | ||
292 | updated. | ||
293 | |||
294 | Command: -var-update | ||
295 | Return: !=0 OK. The @var{changed} list contains the list of changed vars. | ||
296 | |||
297 | ***************************************************************************/ | ||
298 | |||
299 | int gmi_var_update(mi_h *h, mi_gvar *var, mi_gvar_chg **changed) | ||
300 | { | ||
301 | mi_var_update(h,var ? var->name : NULL); | ||
302 | return mi_res_changelist(h,changed); | ||
303 | } | ||
304 | |||
305 | /**[txh]******************************************************************** | ||
306 | |||
307 | Description: | ||
308 | Change variable. The new value replaces the @var{value} field. | ||
309 | |||
310 | Command: -var-assign | ||
311 | Return: !=0 OK | ||
312 | |||
313 | ***************************************************************************/ | ||
314 | |||
315 | int gmi_var_assign(mi_h *h, mi_gvar *var, const char *expression) | ||
316 | { | ||
317 | char *res; | ||
318 | mi_var_assign(h,var->name,expression); | ||
319 | res=mi_res_value(h); | ||
320 | if (res) | ||
321 | { | ||
322 | free(var->value); | ||
323 | var->value=res; | ||
324 | return 1; | ||
325 | } | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | /**[txh]******************************************************************** | ||
330 | |||
331 | Description: | ||
332 | Fill the value field getting the current value for a variable. | ||
333 | |||
334 | Command: -var-evaluate-expression | ||
335 | Return: !=0 OK, value contains the result. | ||
336 | |||
337 | ***************************************************************************/ | ||
338 | |||
339 | int gmi_var_evaluate_expression(mi_h *h, mi_gvar *var) | ||
340 | { | ||
341 | char *s; | ||
342 | |||
343 | mi_var_evaluate_expression(h,var->name); | ||
344 | s=mi_res_value(h); | ||
345 | if (s) | ||
346 | { | ||
347 | free(var->value); | ||
348 | var->value=s; | ||
349 | } | ||
350 | return s!=NULL; | ||
351 | } | ||
352 | |||
353 | /**[txh]******************************************************************** | ||
354 | |||
355 | Description: | ||
356 | List children. It ONLY returns the first level information. :-(@* | ||
357 | On success the child field contains the list of children. | ||
358 | |||
359 | Command: -var-list-children | ||
360 | Return: !=0 OK | ||
361 | |||
362 | ***************************************************************************/ | ||
363 | |||
364 | int gmi_var_list_children(mi_h *h, mi_gvar *var) | ||
365 | { | ||
366 | mi_var_list_children(h,var->name); | ||
367 | return mi_res_children(h,var); | ||
368 | } | ||
369 | |||