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.
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
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.@*
34 * MI v1 and v2 result formats supported. @<p>
36 ***************************************************************************/
40 /* Low level versions. */
42 void mi_var_create(mi_h *h, const char *name, int frame, const char *exp)
44 const char *n=name ? name : "-";
47 mi_send(h,"-var-create %s * %s\n",n,exp);
49 mi_send(h,"-var-create %s %d %s\n",n,frame,exp);
52 void mi_var_delete(mi_h *h, const char *name)
54 mi_send(h,"-var-delete %s\n",name);
57 void mi_var_set_format(mi_h *h, const char *name, const char *format)
59 mi_send(h,"-var-set-format \"%s\" %s\n",name,format);
62 void mi_var_show_format(mi_h *h, const char *name)
64 mi_send(h,"-var-show-format \"%s\"\n",name);
67 void mi_var_info_num_children(mi_h *h, const char *name)
69 mi_send(h,"-var-info-num-children \"%s\"\n",name);
72 void mi_var_info_type(mi_h *h, const char *name)
74 mi_send(h,"-var-info-type \"%s\"\n",name);
77 void mi_var_info_expression(mi_h *h, const char *name)
79 mi_send(h,"-var-info-expression \"%s\"\n",name);
82 void mi_var_show_attributes(mi_h *h, const char *name)
84 mi_send(h,"-var-show-attributes \"%s\"\n",name);
87 void mi_var_update(mi_h *h, const char *name)
90 mi_send(h,"-var-update %s\n",name);
92 mi_send(h,"-var-update *\n");
95 void mi_var_assign(mi_h *h, const char *name, const char *expression)
97 mi_send(h,"-var-assign \"%s\" \"%s\"\n",name,expression);
100 void mi_var_evaluate_expression(mi_h *h, const char *name)
102 mi_send(h,"-var-evaluate-expression \"%s\"\n",name);
105 void mi_var_list_children(mi_h *h, const char *name)
107 if (h->version>=MI_VERSION2U(2,0,0))
108 mi_send(h,"-var-list-children --all-values \"%s\"\n",name);
110 mi_send(h,"-var-list-children \"%s\"\n",name);
113 /* High level versions. */
115 /**[txh]********************************************************************
118 Create a variable object. I recommend using gmi_var_create and letting
119 gdb choose the names.
122 Return: A new mi_gvar strcture or NULL on error.
124 ***************************************************************************/
126 mi_gvar *gmi_var_create_nm(mi_h *h, const char *name, int frame, const char *exp)
128 mi_var_create(h,name,frame,exp);
129 return mi_res_gvar(h,NULL,exp);
132 /**[txh]********************************************************************
135 Create a variable object. The name is selected by gdb. Alternative:
138 Command: -var-create [auto name]
139 Return: A new mi_gvar strcture or NULL on error.
141 ***************************************************************************/
143 mi_gvar *gmi_var_create(mi_h *h, int frame, const char *exp)
145 return gmi_var_create_nm(h,NULL,frame,exp);
148 /**[txh]********************************************************************
151 Delete a variable object. Doesn't free the mi_gvar data.
156 ***************************************************************************/
158 int gmi_var_delete(mi_h *h, mi_gvar *var)
160 mi_var_delete(h,var->name);
161 return mi_res_simple_done(h);
164 /**[txh]********************************************************************
167 Set the format used to represent the result.
169 Command: -var-set-format
172 ***************************************************************************/
174 int gmi_var_set_format(mi_h *h, mi_gvar *var, enum mi_gvar_fmt format)
178 mi_var_set_format(h,var->name,mi_format_enum_to_str(format));
179 ret=mi_res_simple_done(h);
185 /**[txh]********************************************************************
188 Fill the format field with info from gdb.
190 Command: -var-show-format
193 ***************************************************************************/
195 int gmi_var_show_format(mi_h *h, mi_gvar *var)
197 mi_var_show_format(h,var->name);
198 return mi_res_gvar(h,var,NULL)!=NULL;
201 /**[txh]********************************************************************
204 Fill the numchild field with info from gdb.
206 Command: -var-info-num-children
209 ***************************************************************************/
211 int gmi_var_info_num_children(mi_h *h, mi_gvar *var)
213 mi_var_info_num_children(h,var->name);
214 return mi_res_gvar(h,var,NULL)!=NULL;
217 /**[txh]********************************************************************
220 Fill the type field with info from gdb.
222 Command: -var-info-type
225 ***************************************************************************/
227 int gmi_var_info_type(mi_h *h, mi_gvar *var)
229 mi_var_info_type(h,var->name);
230 return mi_res_gvar(h,var,NULL)!=NULL;
233 /**[txh]********************************************************************
236 Fill the expression and lang fields with info from gdb. Note that lang
237 isn't filled during creation.
239 Command: -var-info-expression
242 ***************************************************************************/
244 int gmi_var_info_expression(mi_h *h, mi_gvar *var)
246 mi_var_info_expression(h,var->name);
247 return mi_res_gvar(h,var,NULL)!=NULL;
251 /**[txh]********************************************************************
254 Fill the attr field with info from gdb. Note that attr isn't filled
257 Command: -var-show-attributes
260 ***************************************************************************/
262 int gmi_var_show_attributes(mi_h *h, mi_gvar *var)
264 mi_var_show_attributes(h,var->name);
265 return mi_res_gvar(h,var,NULL)!=NULL;
268 /**[txh]********************************************************************
271 Create the variable and also fill the lang and attr fields. The name is
274 Command: -var-create + -var-info-expression + -var-show-attributes
275 Return: A new mi_gvar strcture or NULL on error.
277 ***************************************************************************/
279 mi_gvar *gmi_full_var_create(mi_h *h, int frame, const char *exp)
281 mi_gvar *var=gmi_var_create_nm(h,NULL,frame,exp);
283 {/* What if it fails? */
284 gmi_var_info_expression(h,var);
285 gmi_var_show_attributes(h,var);
290 /**[txh]********************************************************************
293 Update variable. Use NULL for all. Note that *changed can be NULL if none
297 Return: !=0 OK. The changed list contains the list of changed vars.
299 ***************************************************************************/
301 int gmi_var_update(mi_h *h, mi_gvar *var, mi_gvar_chg **changed)
303 mi_var_update(h,var ? var->name : NULL);
304 return mi_res_changelist(h,changed);
307 /**[txh]********************************************************************
310 Change variable. The new value replaces the value field.
315 ***************************************************************************/
317 int gmi_var_assign(mi_h *h, mi_gvar *var, const char *expression)
320 mi_var_assign(h,var->name,expression);
331 /**[txh]********************************************************************
334 Fill the value field getting the current value for a variable.
336 Command: -var-evaluate-expression
337 Return: !=0 OK, value contains the result.
339 ***************************************************************************/
341 int gmi_var_evaluate_expression(mi_h *h, mi_gvar *var)
345 mi_var_evaluate_expression(h,var->name);
355 /**[txh]********************************************************************
358 List children. It ONLY returns the first level information. :-(@*
359 On success the child field contains the list of children.
361 Command: -var-list-children
364 ***************************************************************************/
366 int gmi_var_list_children(mi_h *h, mi_gvar *var)
368 mi_var_list_children(h,var->name);
369 return mi_res_children(h,var);