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