1 /**[txh]********************************************************************
3 Copyright (c) 2004 by Salvador E. Tropea.
4 Covered by the GPL license.
6 Module: Variable objects.
8 GDB/MI commands for the "Variable Objects" section.@p
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
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.@*
32 * MI v1 and v2 result formats supported.@p
34 ***************************************************************************/
38 /* Low level versions. */
40 void mi_var_create(mi_h *h, const char *name, int frame, const char *exp)
42 const char *n=name ? name : "-";
45 mi_send(h,"-var-create %s * %s\n",n,exp);
47 mi_send(h,"-var-create %s %d %s\n",n,frame,exp);
50 void mi_var_delete(mi_h *h, const char *name)
52 mi_send(h,"-var-delete %s\n",name);
55 void mi_var_set_format(mi_h *h, const char *name, const char *format)
57 mi_send(h,"-var-set-format \"%s\" %s\n",name,format);
60 void mi_var_show_format(mi_h *h, const char *name)
62 mi_send(h,"-var-show-format \"%s\"\n",name);
65 void mi_var_info_num_children(mi_h *h, const char *name)
67 mi_send(h,"-var-info-num-children \"%s\"\n",name);
70 void mi_var_info_type(mi_h *h, const char *name)
72 mi_send(h,"-var-info-type \"%s\"\n",name);
75 void mi_var_info_expression(mi_h *h, const char *name)
77 mi_send(h,"-var-info-expression \"%s\"\n",name);
80 void mi_var_show_attributes(mi_h *h, const char *name)
82 mi_send(h,"-var-show-attributes \"%s\"\n",name);
85 void mi_var_update(mi_h *h, const char *name)
88 mi_send(h,"-var-update %s\n",name);
90 mi_send(h,"-var-update *\n");
93 void mi_var_assign(mi_h *h, const char *name, const char *expression)
95 mi_send(h,"-var-assign \"%s\" \"%s\"\n",name,expression);
98 void mi_var_evaluate_expression(mi_h *h, const char *name)
100 mi_send(h,"-var-evaluate-expression \"%s\"\n",name);
103 void mi_var_list_children(mi_h *h, const char *name)
105 if (h->version>=MI_VERSION2U(2,0,0))
106 mi_send(h,"-var-list-children --all-values \"%s\"\n",name);
108 mi_send(h,"-var-list-children \"%s\"\n",name);
111 /* High level versions. */
113 /**[txh]********************************************************************
116 Create a variable object. I recommend using @x{gmi_var_create} and letting
117 gdb choose the names.
120 Return: A new mi_gvar strcture or NULL on error.
122 ***************************************************************************/
124 mi_gvar *gmi_var_create_nm(mi_h *h, const char *name, int frame, const char *exp)
126 mi_var_create(h,name,frame,exp);
127 return mi_res_gvar(h,NULL,exp);
130 /**[txh]********************************************************************
133 Create a variable object. The name is selected by gdb. Alternative:
134 @x{gmi_full_var_create}.
136 Command: -var-create [auto name]
137 Return: A new mi_gvar strcture or NULL on error.
139 ***************************************************************************/
141 mi_gvar *gmi_var_create(mi_h *h, int frame, const char *exp)
143 return gmi_var_create_nm(h,NULL,frame,exp);
146 /**[txh]********************************************************************
149 Delete a variable object. Doesn't free the mi_gvar data.
154 ***************************************************************************/
156 int gmi_var_delete(mi_h *h, mi_gvar *var)
158 mi_var_delete(h,var->name);
159 return mi_res_simple_done(h);
162 /**[txh]********************************************************************
165 Set the format used to represent the result.
167 Command: -var-set-format
170 ***************************************************************************/
172 int gmi_var_set_format(mi_h *h, mi_gvar *var, enum mi_gvar_fmt format)
176 mi_var_set_format(h,var->name,mi_format_enum_to_str(format));
177 ret=mi_res_simple_done(h);
183 /**[txh]********************************************************************
186 Fill the format field with info from gdb.
188 Command: -var-show-format
191 ***************************************************************************/
193 int gmi_var_show_format(mi_h *h, mi_gvar *var)
195 mi_var_show_format(h,var->name);
196 return mi_res_gvar(h,var,NULL)!=NULL;
199 /**[txh]********************************************************************
202 Fill the numchild field with info from gdb.
204 Command: -var-info-num-children
207 ***************************************************************************/
209 int gmi_var_info_num_children(mi_h *h, mi_gvar *var)
211 mi_var_info_num_children(h,var->name);
212 return mi_res_gvar(h,var,NULL)!=NULL;
215 /**[txh]********************************************************************
218 Fill the type field with info from gdb.
220 Command: -var-info-type
223 ***************************************************************************/
225 int gmi_var_info_type(mi_h *h, mi_gvar *var)
227 mi_var_info_type(h,var->name);
228 return mi_res_gvar(h,var,NULL)!=NULL;
231 /**[txh]********************************************************************
234 Fill the expression and lang fields with info from gdb. Note that lang
235 isn't filled during creation.
237 Command: -var-info-expression
240 ***************************************************************************/
242 int gmi_var_info_expression(mi_h *h, mi_gvar *var)
244 mi_var_info_expression(h,var->name);
245 return mi_res_gvar(h,var,NULL)!=NULL;
249 /**[txh]********************************************************************
252 Fill the attr field with info from gdb. Note that attr isn't filled
255 Command: -var-show-attributes
258 ***************************************************************************/
260 int gmi_var_show_attributes(mi_h *h, mi_gvar *var)
262 mi_var_show_attributes(h,var->name);
263 return mi_res_gvar(h,var,NULL)!=NULL;
266 /**[txh]********************************************************************
269 Create the variable and also fill the lang and attr fields. The name is
272 Command: -var-create + -var-info-expression + -var-show-attributes
273 Return: A new mi_gvar strcture or NULL on error.
275 ***************************************************************************/
277 mi_gvar *gmi_full_var_create(mi_h *h, int frame, const char *exp)
279 mi_gvar *var=gmi_var_create_nm(h,NULL,frame,exp);
281 {/* What if it fails? */
282 gmi_var_info_expression(h,var);
283 gmi_var_show_attributes(h,var);
288 /**[txh]********************************************************************
291 Update variable. Use NULL for all. Note that *changed can be NULL if none
295 Return: !=0 OK. The @var{changed} list contains the list of changed vars.
297 ***************************************************************************/
299 int gmi_var_update(mi_h *h, mi_gvar *var, mi_gvar_chg **changed)
301 mi_var_update(h,var ? var->name : NULL);
302 return mi_res_changelist(h,changed);
305 /**[txh]********************************************************************
308 Change variable. The new value replaces the @var{value} field.
313 ***************************************************************************/
315 int gmi_var_assign(mi_h *h, mi_gvar *var, const char *expression)
318 mi_var_assign(h,var->name,expression);
329 /**[txh]********************************************************************
332 Fill the value field getting the current value for a variable.
334 Command: -var-evaluate-expression
335 Return: !=0 OK, value contains the result.
337 ***************************************************************************/
339 int gmi_var_evaluate_expression(mi_h *h, mi_gvar *var)
343 mi_var_evaluate_expression(h,var->name);
353 /**[txh]********************************************************************
356 List children. It ONLY returns the first level information. :-(@*
357 On success the child field contains the list of children.
359 Command: -var-list-children
362 ***************************************************************************/
364 int gmi_var_list_children(mi_h *h, mi_gvar *var)
366 mi_var_list_children(h,var->name);
367 return mi_res_children(h,var);