1*ef5ccd6cSJohn Marino /* varobj support for Ada. 2*ef5ccd6cSJohn Marino 3*ef5ccd6cSJohn Marino Copyright (C) 2012-2013 Free Software Foundation, Inc. 4*ef5ccd6cSJohn Marino 5*ef5ccd6cSJohn Marino This file is part of GDB. 6*ef5ccd6cSJohn Marino 7*ef5ccd6cSJohn Marino This program is free software; you can redistribute it and/or modify 8*ef5ccd6cSJohn Marino it under the terms of the GNU General Public License as published by 9*ef5ccd6cSJohn Marino the Free Software Foundation; either version 3 of the License, or 10*ef5ccd6cSJohn Marino (at your option) any later version. 11*ef5ccd6cSJohn Marino 12*ef5ccd6cSJohn Marino This program is distributed in the hope that it will be useful, 13*ef5ccd6cSJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 14*ef5ccd6cSJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*ef5ccd6cSJohn Marino GNU General Public License for more details. 16*ef5ccd6cSJohn Marino 17*ef5ccd6cSJohn Marino You should have received a copy of the GNU General Public License 18*ef5ccd6cSJohn Marino along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*ef5ccd6cSJohn Marino 20*ef5ccd6cSJohn Marino #include "defs.h" 21*ef5ccd6cSJohn Marino #include "ada-varobj.h" 22*ef5ccd6cSJohn Marino #include "ada-lang.h" 23*ef5ccd6cSJohn Marino #include "language.h" 24*ef5ccd6cSJohn Marino #include "valprint.h" 25*ef5ccd6cSJohn Marino 26*ef5ccd6cSJohn Marino /* Implementation principle used in this unit: 27*ef5ccd6cSJohn Marino 28*ef5ccd6cSJohn Marino For our purposes, the meat of the varobj object is made of two 29*ef5ccd6cSJohn Marino elements: The varobj's (struct) value, and the varobj's (struct) 30*ef5ccd6cSJohn Marino type. In most situations, the varobj has a non-NULL value, and 31*ef5ccd6cSJohn Marino the type becomes redundant, as it can be directly derived from 32*ef5ccd6cSJohn Marino the value. In the initial implementation of this unit, most 33*ef5ccd6cSJohn Marino routines would only take a value, and return a value. 34*ef5ccd6cSJohn Marino 35*ef5ccd6cSJohn Marino But there are many situations where it is possible for a varobj 36*ef5ccd6cSJohn Marino to have a NULL value. For instance, if the varobj becomes out of 37*ef5ccd6cSJohn Marino scope. Or better yet, when the varobj is the child of another 38*ef5ccd6cSJohn Marino NULL pointer varobj. In that situation, we must rely on the type 39*ef5ccd6cSJohn Marino instead of the value to create the child varobj. 40*ef5ccd6cSJohn Marino 41*ef5ccd6cSJohn Marino That's why most functions below work with a (value, type) pair. 42*ef5ccd6cSJohn Marino The value may or may not be NULL. But the type is always expected 43*ef5ccd6cSJohn Marino to be set. When the value is NULL, then we work with the type 44*ef5ccd6cSJohn Marino alone, and keep the value NULL. But when the value is not NULL, 45*ef5ccd6cSJohn Marino then we work using the value, because it provides more information. 46*ef5ccd6cSJohn Marino But we still always set the type as well, even if that type could 47*ef5ccd6cSJohn Marino easily be derived from the value. The reason behind this is that 48*ef5ccd6cSJohn Marino it allows the code to use the type without having to worry about 49*ef5ccd6cSJohn Marino it being set or not. It makes the code clearer. */ 50*ef5ccd6cSJohn Marino 51*ef5ccd6cSJohn Marino /* A convenience function that decodes the VALUE_PTR/TYPE_PTR couple: 52*ef5ccd6cSJohn Marino If there is a value (*VALUE_PTR not NULL), then perform the decoding 53*ef5ccd6cSJohn Marino using it, and compute the associated type from the resulting value. 54*ef5ccd6cSJohn Marino Otherwise, compute a static approximation of *TYPE_PTR, leaving 55*ef5ccd6cSJohn Marino *VALUE_PTR unchanged. 56*ef5ccd6cSJohn Marino 57*ef5ccd6cSJohn Marino The results are written in place. */ 58*ef5ccd6cSJohn Marino 59*ef5ccd6cSJohn Marino static void 60*ef5ccd6cSJohn Marino ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr) 61*ef5ccd6cSJohn Marino { 62*ef5ccd6cSJohn Marino if (*value_ptr) 63*ef5ccd6cSJohn Marino { 64*ef5ccd6cSJohn Marino *value_ptr = ada_get_decoded_value (*value_ptr); 65*ef5ccd6cSJohn Marino *type_ptr = ada_check_typedef (value_type (*value_ptr)); 66*ef5ccd6cSJohn Marino } 67*ef5ccd6cSJohn Marino else 68*ef5ccd6cSJohn Marino *type_ptr = ada_get_decoded_type (*type_ptr); 69*ef5ccd6cSJohn Marino } 70*ef5ccd6cSJohn Marino 71*ef5ccd6cSJohn Marino /* Return a string containing an image of the given scalar value. 72*ef5ccd6cSJohn Marino VAL is the numeric value, while TYPE is the value's type. 73*ef5ccd6cSJohn Marino This is useful for plain integers, of course, but even more 74*ef5ccd6cSJohn Marino so for enumerated types. 75*ef5ccd6cSJohn Marino 76*ef5ccd6cSJohn Marino The result should be deallocated by xfree after use. */ 77*ef5ccd6cSJohn Marino 78*ef5ccd6cSJohn Marino static char * 79*ef5ccd6cSJohn Marino ada_varobj_scalar_image (struct type *type, LONGEST val) 80*ef5ccd6cSJohn Marino { 81*ef5ccd6cSJohn Marino struct ui_file *buf = mem_fileopen (); 82*ef5ccd6cSJohn Marino struct cleanup *cleanups = make_cleanup_ui_file_delete (buf); 83*ef5ccd6cSJohn Marino char *result; 84*ef5ccd6cSJohn Marino 85*ef5ccd6cSJohn Marino ada_print_scalar (type, val, buf); 86*ef5ccd6cSJohn Marino result = ui_file_xstrdup (buf, NULL); 87*ef5ccd6cSJohn Marino do_cleanups (cleanups); 88*ef5ccd6cSJohn Marino 89*ef5ccd6cSJohn Marino return result; 90*ef5ccd6cSJohn Marino } 91*ef5ccd6cSJohn Marino 92*ef5ccd6cSJohn Marino /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair designates 93*ef5ccd6cSJohn Marino a struct or union, compute the (CHILD_VALUE, CHILD_TYPE) couple 94*ef5ccd6cSJohn Marino corresponding to the field number FIELDNO. */ 95*ef5ccd6cSJohn Marino 96*ef5ccd6cSJohn Marino static void 97*ef5ccd6cSJohn Marino ada_varobj_struct_elt (struct value *parent_value, 98*ef5ccd6cSJohn Marino struct type *parent_type, 99*ef5ccd6cSJohn Marino int fieldno, 100*ef5ccd6cSJohn Marino struct value **child_value, 101*ef5ccd6cSJohn Marino struct type **child_type) 102*ef5ccd6cSJohn Marino { 103*ef5ccd6cSJohn Marino struct value *value = NULL; 104*ef5ccd6cSJohn Marino struct type *type = NULL; 105*ef5ccd6cSJohn Marino 106*ef5ccd6cSJohn Marino if (parent_value) 107*ef5ccd6cSJohn Marino { 108*ef5ccd6cSJohn Marino value = value_field (parent_value, fieldno); 109*ef5ccd6cSJohn Marino type = value_type (value); 110*ef5ccd6cSJohn Marino } 111*ef5ccd6cSJohn Marino else 112*ef5ccd6cSJohn Marino type = TYPE_FIELD_TYPE (parent_type, fieldno); 113*ef5ccd6cSJohn Marino 114*ef5ccd6cSJohn Marino if (child_value) 115*ef5ccd6cSJohn Marino *child_value = value; 116*ef5ccd6cSJohn Marino if (child_type) 117*ef5ccd6cSJohn Marino *child_type = type; 118*ef5ccd6cSJohn Marino } 119*ef5ccd6cSJohn Marino 120*ef5ccd6cSJohn Marino /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is a pointer or 121*ef5ccd6cSJohn Marino reference, return a (CHILD_VALUE, CHILD_TYPE) couple corresponding 122*ef5ccd6cSJohn Marino to the dereferenced value. */ 123*ef5ccd6cSJohn Marino 124*ef5ccd6cSJohn Marino static void 125*ef5ccd6cSJohn Marino ada_varobj_ind (struct value *parent_value, 126*ef5ccd6cSJohn Marino struct type *parent_type, 127*ef5ccd6cSJohn Marino struct value **child_value, 128*ef5ccd6cSJohn Marino struct type **child_type) 129*ef5ccd6cSJohn Marino { 130*ef5ccd6cSJohn Marino struct value *value = NULL; 131*ef5ccd6cSJohn Marino struct type *type = NULL; 132*ef5ccd6cSJohn Marino 133*ef5ccd6cSJohn Marino if (ada_is_array_descriptor_type (parent_type)) 134*ef5ccd6cSJohn Marino { 135*ef5ccd6cSJohn Marino /* This can only happen when PARENT_VALUE is NULL. Otherwise, 136*ef5ccd6cSJohn Marino ada_get_decoded_value would have transformed our parent_type 137*ef5ccd6cSJohn Marino into a simple array pointer type. */ 138*ef5ccd6cSJohn Marino gdb_assert (parent_value == NULL); 139*ef5ccd6cSJohn Marino gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF); 140*ef5ccd6cSJohn Marino 141*ef5ccd6cSJohn Marino /* Decode parent_type by the equivalent pointer to (decoded) 142*ef5ccd6cSJohn Marino array. */ 143*ef5ccd6cSJohn Marino while (TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF) 144*ef5ccd6cSJohn Marino parent_type = TYPE_TARGET_TYPE (parent_type); 145*ef5ccd6cSJohn Marino parent_type = ada_coerce_to_simple_array_type (parent_type); 146*ef5ccd6cSJohn Marino parent_type = lookup_pointer_type (parent_type); 147*ef5ccd6cSJohn Marino } 148*ef5ccd6cSJohn Marino 149*ef5ccd6cSJohn Marino /* If parent_value is a null pointer, then only perform static 150*ef5ccd6cSJohn Marino dereferencing. We cannot dereference null pointers. */ 151*ef5ccd6cSJohn Marino if (parent_value && value_as_address (parent_value) == 0) 152*ef5ccd6cSJohn Marino parent_value = NULL; 153*ef5ccd6cSJohn Marino 154*ef5ccd6cSJohn Marino if (parent_value) 155*ef5ccd6cSJohn Marino { 156*ef5ccd6cSJohn Marino value = ada_value_ind (parent_value); 157*ef5ccd6cSJohn Marino type = value_type (value); 158*ef5ccd6cSJohn Marino } 159*ef5ccd6cSJohn Marino else 160*ef5ccd6cSJohn Marino type = TYPE_TARGET_TYPE (parent_type); 161*ef5ccd6cSJohn Marino 162*ef5ccd6cSJohn Marino if (child_value) 163*ef5ccd6cSJohn Marino *child_value = value; 164*ef5ccd6cSJohn Marino if (child_type) 165*ef5ccd6cSJohn Marino *child_type = type; 166*ef5ccd6cSJohn Marino } 167*ef5ccd6cSJohn Marino 168*ef5ccd6cSJohn Marino /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is a simple 169*ef5ccd6cSJohn Marino array (TYPE_CODE_ARRAY), return the (CHILD_VALUE, CHILD_TYPE) 170*ef5ccd6cSJohn Marino pair corresponding to the element at ELT_INDEX. */ 171*ef5ccd6cSJohn Marino 172*ef5ccd6cSJohn Marino static void 173*ef5ccd6cSJohn Marino ada_varobj_simple_array_elt (struct value *parent_value, 174*ef5ccd6cSJohn Marino struct type *parent_type, 175*ef5ccd6cSJohn Marino int elt_index, 176*ef5ccd6cSJohn Marino struct value **child_value, 177*ef5ccd6cSJohn Marino struct type **child_type) 178*ef5ccd6cSJohn Marino { 179*ef5ccd6cSJohn Marino struct value *value = NULL; 180*ef5ccd6cSJohn Marino struct type *type = NULL; 181*ef5ccd6cSJohn Marino 182*ef5ccd6cSJohn Marino if (parent_value) 183*ef5ccd6cSJohn Marino { 184*ef5ccd6cSJohn Marino struct value *index_value = 185*ef5ccd6cSJohn Marino value_from_longest (TYPE_INDEX_TYPE (parent_type), elt_index); 186*ef5ccd6cSJohn Marino 187*ef5ccd6cSJohn Marino value = ada_value_subscript (parent_value, 1, &index_value); 188*ef5ccd6cSJohn Marino type = value_type (value); 189*ef5ccd6cSJohn Marino } 190*ef5ccd6cSJohn Marino else 191*ef5ccd6cSJohn Marino type = TYPE_TARGET_TYPE (parent_type); 192*ef5ccd6cSJohn Marino 193*ef5ccd6cSJohn Marino if (child_value) 194*ef5ccd6cSJohn Marino *child_value = value; 195*ef5ccd6cSJohn Marino if (child_type) 196*ef5ccd6cSJohn Marino *child_type = type; 197*ef5ccd6cSJohn Marino } 198*ef5ccd6cSJohn Marino 199*ef5ccd6cSJohn Marino /* Given the decoded value and decoded type of a variable object, 200*ef5ccd6cSJohn Marino adjust the value and type to those necessary for getting children 201*ef5ccd6cSJohn Marino of the variable object. 202*ef5ccd6cSJohn Marino 203*ef5ccd6cSJohn Marino The replacement is performed in place. */ 204*ef5ccd6cSJohn Marino 205*ef5ccd6cSJohn Marino static void 206*ef5ccd6cSJohn Marino ada_varobj_adjust_for_child_access (struct value **value, 207*ef5ccd6cSJohn Marino struct type **type) 208*ef5ccd6cSJohn Marino { 209*ef5ccd6cSJohn Marino /* Pointers to struct/union types are special: Instead of having 210*ef5ccd6cSJohn Marino one child (the struct), their children are the components of 211*ef5ccd6cSJohn Marino the struct/union type. We handle this situation by dereferencing 212*ef5ccd6cSJohn Marino the (value, type) couple. */ 213*ef5ccd6cSJohn Marino if (TYPE_CODE (*type) == TYPE_CODE_PTR 214*ef5ccd6cSJohn Marino && (TYPE_CODE (TYPE_TARGET_TYPE (*type)) == TYPE_CODE_STRUCT 215*ef5ccd6cSJohn Marino || TYPE_CODE (TYPE_TARGET_TYPE (*type)) == TYPE_CODE_UNION) 216*ef5ccd6cSJohn Marino && !ada_is_array_descriptor_type (TYPE_TARGET_TYPE (*type)) 217*ef5ccd6cSJohn Marino && !ada_is_constrained_packed_array_type (TYPE_TARGET_TYPE (*type))) 218*ef5ccd6cSJohn Marino ada_varobj_ind (*value, *type, value, type); 219*ef5ccd6cSJohn Marino } 220*ef5ccd6cSJohn Marino 221*ef5ccd6cSJohn Marino /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is an array 222*ef5ccd6cSJohn Marino (any type of array, "simple" or not), return the number of children 223*ef5ccd6cSJohn Marino that this array contains. */ 224*ef5ccd6cSJohn Marino 225*ef5ccd6cSJohn Marino static int 226*ef5ccd6cSJohn Marino ada_varobj_get_array_number_of_children (struct value *parent_value, 227*ef5ccd6cSJohn Marino struct type *parent_type) 228*ef5ccd6cSJohn Marino { 229*ef5ccd6cSJohn Marino LONGEST lo, hi; 230*ef5ccd6cSJohn Marino 231*ef5ccd6cSJohn Marino if (!get_array_bounds (parent_type, &lo, &hi)) 232*ef5ccd6cSJohn Marino { 233*ef5ccd6cSJohn Marino /* Could not get the array bounds. Pretend this is an empty array. */ 234*ef5ccd6cSJohn Marino warning (_("unable to get bounds of array, assuming null array")); 235*ef5ccd6cSJohn Marino return 0; 236*ef5ccd6cSJohn Marino } 237*ef5ccd6cSJohn Marino 238*ef5ccd6cSJohn Marino /* Ada allows the upper bound to be less than the lower bound, 239*ef5ccd6cSJohn Marino in order to specify empty arrays... */ 240*ef5ccd6cSJohn Marino if (hi < lo) 241*ef5ccd6cSJohn Marino return 0; 242*ef5ccd6cSJohn Marino 243*ef5ccd6cSJohn Marino return hi - lo + 1; 244*ef5ccd6cSJohn Marino } 245*ef5ccd6cSJohn Marino 246*ef5ccd6cSJohn Marino /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is a struct or 247*ef5ccd6cSJohn Marino union, return the number of children this struct contains. */ 248*ef5ccd6cSJohn Marino 249*ef5ccd6cSJohn Marino static int 250*ef5ccd6cSJohn Marino ada_varobj_get_struct_number_of_children (struct value *parent_value, 251*ef5ccd6cSJohn Marino struct type *parent_type) 252*ef5ccd6cSJohn Marino { 253*ef5ccd6cSJohn Marino int n_children = 0; 254*ef5ccd6cSJohn Marino int i; 255*ef5ccd6cSJohn Marino 256*ef5ccd6cSJohn Marino gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT 257*ef5ccd6cSJohn Marino || TYPE_CODE (parent_type) == TYPE_CODE_UNION); 258*ef5ccd6cSJohn Marino 259*ef5ccd6cSJohn Marino for (i = 0; i < TYPE_NFIELDS (parent_type); i++) 260*ef5ccd6cSJohn Marino { 261*ef5ccd6cSJohn Marino if (ada_is_ignored_field (parent_type, i)) 262*ef5ccd6cSJohn Marino continue; 263*ef5ccd6cSJohn Marino 264*ef5ccd6cSJohn Marino if (ada_is_wrapper_field (parent_type, i)) 265*ef5ccd6cSJohn Marino { 266*ef5ccd6cSJohn Marino struct value *elt_value; 267*ef5ccd6cSJohn Marino struct type *elt_type; 268*ef5ccd6cSJohn Marino 269*ef5ccd6cSJohn Marino ada_varobj_struct_elt (parent_value, parent_type, i, 270*ef5ccd6cSJohn Marino &elt_value, &elt_type); 271*ef5ccd6cSJohn Marino if (ada_is_tagged_type (elt_type, 0)) 272*ef5ccd6cSJohn Marino { 273*ef5ccd6cSJohn Marino /* We must not use ada_varobj_get_number_of_children 274*ef5ccd6cSJohn Marino to determine is element's number of children, because 275*ef5ccd6cSJohn Marino this function first calls ada_varobj_decode_var, 276*ef5ccd6cSJohn Marino which "fixes" the element. For tagged types, this 277*ef5ccd6cSJohn Marino includes reading the object's tag to determine its 278*ef5ccd6cSJohn Marino real type, which happens to be the parent_type, and 279*ef5ccd6cSJohn Marino leads to an infinite loop (because the element gets 280*ef5ccd6cSJohn Marino fixed back into the parent). */ 281*ef5ccd6cSJohn Marino n_children += ada_varobj_get_struct_number_of_children 282*ef5ccd6cSJohn Marino (elt_value, elt_type); 283*ef5ccd6cSJohn Marino } 284*ef5ccd6cSJohn Marino else 285*ef5ccd6cSJohn Marino n_children += ada_varobj_get_number_of_children (elt_value, elt_type); 286*ef5ccd6cSJohn Marino } 287*ef5ccd6cSJohn Marino else if (ada_is_variant_part (parent_type, i)) 288*ef5ccd6cSJohn Marino { 289*ef5ccd6cSJohn Marino /* In normal situations, the variant part of the record should 290*ef5ccd6cSJohn Marino have been "fixed". Or, in other words, it should have been 291*ef5ccd6cSJohn Marino replaced by the branch of the variant part that is relevant 292*ef5ccd6cSJohn Marino for our value. But there are still situations where this 293*ef5ccd6cSJohn Marino can happen, however (Eg. when our parent is a NULL pointer). 294*ef5ccd6cSJohn Marino We do not support showing this part of the record for now, 295*ef5ccd6cSJohn Marino so just pretend this field does not exist. */ 296*ef5ccd6cSJohn Marino } 297*ef5ccd6cSJohn Marino else 298*ef5ccd6cSJohn Marino n_children++; 299*ef5ccd6cSJohn Marino } 300*ef5ccd6cSJohn Marino 301*ef5ccd6cSJohn Marino return n_children; 302*ef5ccd6cSJohn Marino } 303*ef5ccd6cSJohn Marino 304*ef5ccd6cSJohn Marino /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair designates 305*ef5ccd6cSJohn Marino a pointer, return the number of children this pointer has. */ 306*ef5ccd6cSJohn Marino 307*ef5ccd6cSJohn Marino static int 308*ef5ccd6cSJohn Marino ada_varobj_get_ptr_number_of_children (struct value *parent_value, 309*ef5ccd6cSJohn Marino struct type *parent_type) 310*ef5ccd6cSJohn Marino { 311*ef5ccd6cSJohn Marino struct type *child_type = TYPE_TARGET_TYPE (parent_type); 312*ef5ccd6cSJohn Marino 313*ef5ccd6cSJohn Marino /* Pointer to functions and to void do not have a child, since 314*ef5ccd6cSJohn Marino you cannot print what they point to. */ 315*ef5ccd6cSJohn Marino if (TYPE_CODE (child_type) == TYPE_CODE_FUNC 316*ef5ccd6cSJohn Marino || TYPE_CODE (child_type) == TYPE_CODE_VOID) 317*ef5ccd6cSJohn Marino return 0; 318*ef5ccd6cSJohn Marino 319*ef5ccd6cSJohn Marino /* All other types have 1 child. */ 320*ef5ccd6cSJohn Marino return 1; 321*ef5ccd6cSJohn Marino } 322*ef5ccd6cSJohn Marino 323*ef5ccd6cSJohn Marino /* Return the number of children for the (PARENT_VALUE, PARENT_TYPE) 324*ef5ccd6cSJohn Marino pair. */ 325*ef5ccd6cSJohn Marino 326*ef5ccd6cSJohn Marino int 327*ef5ccd6cSJohn Marino ada_varobj_get_number_of_children (struct value *parent_value, 328*ef5ccd6cSJohn Marino struct type *parent_type) 329*ef5ccd6cSJohn Marino { 330*ef5ccd6cSJohn Marino ada_varobj_decode_var (&parent_value, &parent_type); 331*ef5ccd6cSJohn Marino ada_varobj_adjust_for_child_access (&parent_value, &parent_type); 332*ef5ccd6cSJohn Marino 333*ef5ccd6cSJohn Marino /* A typedef to an array descriptor in fact represents a pointer 334*ef5ccd6cSJohn Marino to an unconstrained array. These types always have one child 335*ef5ccd6cSJohn Marino (the unconstrained array). */ 336*ef5ccd6cSJohn Marino if (ada_is_array_descriptor_type (parent_type) 337*ef5ccd6cSJohn Marino && TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF) 338*ef5ccd6cSJohn Marino return 1; 339*ef5ccd6cSJohn Marino 340*ef5ccd6cSJohn Marino if (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY) 341*ef5ccd6cSJohn Marino return ada_varobj_get_array_number_of_children (parent_value, 342*ef5ccd6cSJohn Marino parent_type); 343*ef5ccd6cSJohn Marino 344*ef5ccd6cSJohn Marino if (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT 345*ef5ccd6cSJohn Marino || TYPE_CODE (parent_type) == TYPE_CODE_UNION) 346*ef5ccd6cSJohn Marino return ada_varobj_get_struct_number_of_children (parent_value, 347*ef5ccd6cSJohn Marino parent_type); 348*ef5ccd6cSJohn Marino 349*ef5ccd6cSJohn Marino if (TYPE_CODE (parent_type) == TYPE_CODE_PTR) 350*ef5ccd6cSJohn Marino return ada_varobj_get_ptr_number_of_children (parent_value, 351*ef5ccd6cSJohn Marino parent_type); 352*ef5ccd6cSJohn Marino 353*ef5ccd6cSJohn Marino /* All other types have no child. */ 354*ef5ccd6cSJohn Marino return 0; 355*ef5ccd6cSJohn Marino } 356*ef5ccd6cSJohn Marino 357*ef5ccd6cSJohn Marino /* Describe the child of the (PARENT_VALUE, PARENT_TYPE) pair 358*ef5ccd6cSJohn Marino whose index is CHILD_INDEX: 359*ef5ccd6cSJohn Marino 360*ef5ccd6cSJohn Marino - If CHILD_NAME is not NULL, then a copy of the child's name 361*ef5ccd6cSJohn Marino is saved in *CHILD_NAME. This copy must be deallocated 362*ef5ccd6cSJohn Marino with xfree after use. 363*ef5ccd6cSJohn Marino 364*ef5ccd6cSJohn Marino - If CHILD_VALUE is not NULL, then save the child's value 365*ef5ccd6cSJohn Marino in *CHILD_VALUE. Same thing for the child's type with 366*ef5ccd6cSJohn Marino CHILD_TYPE if not NULL. 367*ef5ccd6cSJohn Marino 368*ef5ccd6cSJohn Marino - If CHILD_PATH_EXPR is not NULL, then compute the child's 369*ef5ccd6cSJohn Marino path expression. The resulting string must be deallocated 370*ef5ccd6cSJohn Marino after use with xfree. 371*ef5ccd6cSJohn Marino 372*ef5ccd6cSJohn Marino Computing the child's path expression requires the PARENT_PATH_EXPR 373*ef5ccd6cSJohn Marino to be non-NULL. Otherwise, PARENT_PATH_EXPR may be null if 374*ef5ccd6cSJohn Marino CHILD_PATH_EXPR is NULL. 375*ef5ccd6cSJohn Marino 376*ef5ccd6cSJohn Marino PARENT_NAME is the name of the parent, and should never be NULL. */ 377*ef5ccd6cSJohn Marino 378*ef5ccd6cSJohn Marino static void ada_varobj_describe_child (struct value *parent_value, 379*ef5ccd6cSJohn Marino struct type *parent_type, 380*ef5ccd6cSJohn Marino const char *parent_name, 381*ef5ccd6cSJohn Marino const char *parent_path_expr, 382*ef5ccd6cSJohn Marino int child_index, 383*ef5ccd6cSJohn Marino char **child_name, 384*ef5ccd6cSJohn Marino struct value **child_value, 385*ef5ccd6cSJohn Marino struct type **child_type, 386*ef5ccd6cSJohn Marino char **child_path_expr); 387*ef5ccd6cSJohn Marino 388*ef5ccd6cSJohn Marino /* Same as ada_varobj_describe_child, but limited to struct/union 389*ef5ccd6cSJohn Marino objects. */ 390*ef5ccd6cSJohn Marino 391*ef5ccd6cSJohn Marino static void 392*ef5ccd6cSJohn Marino ada_varobj_describe_struct_child (struct value *parent_value, 393*ef5ccd6cSJohn Marino struct type *parent_type, 394*ef5ccd6cSJohn Marino const char *parent_name, 395*ef5ccd6cSJohn Marino const char *parent_path_expr, 396*ef5ccd6cSJohn Marino int child_index, 397*ef5ccd6cSJohn Marino char **child_name, 398*ef5ccd6cSJohn Marino struct value **child_value, 399*ef5ccd6cSJohn Marino struct type **child_type, 400*ef5ccd6cSJohn Marino char **child_path_expr) 401*ef5ccd6cSJohn Marino { 402*ef5ccd6cSJohn Marino int fieldno; 403*ef5ccd6cSJohn Marino int childno = 0; 404*ef5ccd6cSJohn Marino 405*ef5ccd6cSJohn Marino gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT); 406*ef5ccd6cSJohn Marino 407*ef5ccd6cSJohn Marino for (fieldno = 0; fieldno < TYPE_NFIELDS (parent_type); fieldno++) 408*ef5ccd6cSJohn Marino { 409*ef5ccd6cSJohn Marino if (ada_is_ignored_field (parent_type, fieldno)) 410*ef5ccd6cSJohn Marino continue; 411*ef5ccd6cSJohn Marino 412*ef5ccd6cSJohn Marino if (ada_is_wrapper_field (parent_type, fieldno)) 413*ef5ccd6cSJohn Marino { 414*ef5ccd6cSJohn Marino struct value *elt_value; 415*ef5ccd6cSJohn Marino struct type *elt_type; 416*ef5ccd6cSJohn Marino int elt_n_children; 417*ef5ccd6cSJohn Marino 418*ef5ccd6cSJohn Marino ada_varobj_struct_elt (parent_value, parent_type, fieldno, 419*ef5ccd6cSJohn Marino &elt_value, &elt_type); 420*ef5ccd6cSJohn Marino if (ada_is_tagged_type (elt_type, 0)) 421*ef5ccd6cSJohn Marino { 422*ef5ccd6cSJohn Marino /* Same as in ada_varobj_get_struct_number_of_children: 423*ef5ccd6cSJohn Marino For tagged types, we must be careful to not call 424*ef5ccd6cSJohn Marino ada_varobj_get_number_of_children, to prevent our 425*ef5ccd6cSJohn Marino element from being fixed back into the parent. */ 426*ef5ccd6cSJohn Marino elt_n_children = ada_varobj_get_struct_number_of_children 427*ef5ccd6cSJohn Marino (elt_value, elt_type); 428*ef5ccd6cSJohn Marino } 429*ef5ccd6cSJohn Marino else 430*ef5ccd6cSJohn Marino elt_n_children = 431*ef5ccd6cSJohn Marino ada_varobj_get_number_of_children (elt_value, elt_type); 432*ef5ccd6cSJohn Marino 433*ef5ccd6cSJohn Marino /* Is the child we're looking for one of the children 434*ef5ccd6cSJohn Marino of this wrapper field? */ 435*ef5ccd6cSJohn Marino if (child_index - childno < elt_n_children) 436*ef5ccd6cSJohn Marino { 437*ef5ccd6cSJohn Marino if (ada_is_tagged_type (elt_type, 0)) 438*ef5ccd6cSJohn Marino { 439*ef5ccd6cSJohn Marino /* Same as in ada_varobj_get_struct_number_of_children: 440*ef5ccd6cSJohn Marino For tagged types, we must be careful to not call 441*ef5ccd6cSJohn Marino ada_varobj_describe_child, to prevent our element 442*ef5ccd6cSJohn Marino from being fixed back into the parent. */ 443*ef5ccd6cSJohn Marino ada_varobj_describe_struct_child 444*ef5ccd6cSJohn Marino (elt_value, elt_type, parent_name, parent_path_expr, 445*ef5ccd6cSJohn Marino child_index - childno, child_name, child_value, 446*ef5ccd6cSJohn Marino child_type, child_path_expr); 447*ef5ccd6cSJohn Marino } 448*ef5ccd6cSJohn Marino else 449*ef5ccd6cSJohn Marino ada_varobj_describe_child (elt_value, elt_type, 450*ef5ccd6cSJohn Marino parent_name, parent_path_expr, 451*ef5ccd6cSJohn Marino child_index - childno, 452*ef5ccd6cSJohn Marino child_name, child_value, 453*ef5ccd6cSJohn Marino child_type, child_path_expr); 454*ef5ccd6cSJohn Marino return; 455*ef5ccd6cSJohn Marino } 456*ef5ccd6cSJohn Marino 457*ef5ccd6cSJohn Marino /* The child we're looking for is beyond this wrapper 458*ef5ccd6cSJohn Marino field, so skip all its children. */ 459*ef5ccd6cSJohn Marino childno += elt_n_children; 460*ef5ccd6cSJohn Marino continue; 461*ef5ccd6cSJohn Marino } 462*ef5ccd6cSJohn Marino else if (ada_is_variant_part (parent_type, fieldno)) 463*ef5ccd6cSJohn Marino { 464*ef5ccd6cSJohn Marino /* In normal situations, the variant part of the record should 465*ef5ccd6cSJohn Marino have been "fixed". Or, in other words, it should have been 466*ef5ccd6cSJohn Marino replaced by the branch of the variant part that is relevant 467*ef5ccd6cSJohn Marino for our value. But there are still situations where this 468*ef5ccd6cSJohn Marino can happen, however (Eg. when our parent is a NULL pointer). 469*ef5ccd6cSJohn Marino We do not support showing this part of the record for now, 470*ef5ccd6cSJohn Marino so just pretend this field does not exist. */ 471*ef5ccd6cSJohn Marino continue; 472*ef5ccd6cSJohn Marino } 473*ef5ccd6cSJohn Marino 474*ef5ccd6cSJohn Marino if (childno == child_index) 475*ef5ccd6cSJohn Marino { 476*ef5ccd6cSJohn Marino if (child_name) 477*ef5ccd6cSJohn Marino { 478*ef5ccd6cSJohn Marino /* The name of the child is none other than the field's 479*ef5ccd6cSJohn Marino name, except that we need to strip suffixes from it. 480*ef5ccd6cSJohn Marino For instance, fields with alignment constraints will 481*ef5ccd6cSJohn Marino have an __XVA suffix added to them. */ 482*ef5ccd6cSJohn Marino const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno); 483*ef5ccd6cSJohn Marino int child_name_len = ada_name_prefix_len (field_name); 484*ef5ccd6cSJohn Marino 485*ef5ccd6cSJohn Marino *child_name = xstrprintf ("%.*s", child_name_len, field_name); 486*ef5ccd6cSJohn Marino } 487*ef5ccd6cSJohn Marino 488*ef5ccd6cSJohn Marino if (child_value && parent_value) 489*ef5ccd6cSJohn Marino ada_varobj_struct_elt (parent_value, parent_type, fieldno, 490*ef5ccd6cSJohn Marino child_value, NULL); 491*ef5ccd6cSJohn Marino 492*ef5ccd6cSJohn Marino if (child_type) 493*ef5ccd6cSJohn Marino ada_varobj_struct_elt (parent_value, parent_type, fieldno, 494*ef5ccd6cSJohn Marino NULL, child_type); 495*ef5ccd6cSJohn Marino 496*ef5ccd6cSJohn Marino if (child_path_expr) 497*ef5ccd6cSJohn Marino { 498*ef5ccd6cSJohn Marino /* The name of the child is none other than the field's 499*ef5ccd6cSJohn Marino name, except that we need to strip suffixes from it. 500*ef5ccd6cSJohn Marino For instance, fields with alignment constraints will 501*ef5ccd6cSJohn Marino have an __XVA suffix added to them. */ 502*ef5ccd6cSJohn Marino const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno); 503*ef5ccd6cSJohn Marino int child_name_len = ada_name_prefix_len (field_name); 504*ef5ccd6cSJohn Marino 505*ef5ccd6cSJohn Marino *child_path_expr = 506*ef5ccd6cSJohn Marino xstrprintf ("(%s).%.*s", parent_path_expr, 507*ef5ccd6cSJohn Marino child_name_len, field_name); 508*ef5ccd6cSJohn Marino } 509*ef5ccd6cSJohn Marino 510*ef5ccd6cSJohn Marino return; 511*ef5ccd6cSJohn Marino } 512*ef5ccd6cSJohn Marino 513*ef5ccd6cSJohn Marino childno++; 514*ef5ccd6cSJohn Marino } 515*ef5ccd6cSJohn Marino 516*ef5ccd6cSJohn Marino /* Something went wrong. Either we miscounted the number of 517*ef5ccd6cSJohn Marino children, or CHILD_INDEX was too high. But we should never 518*ef5ccd6cSJohn Marino reach here. We don't have enough information to recover 519*ef5ccd6cSJohn Marino nicely, so just raise an assertion failure. */ 520*ef5ccd6cSJohn Marino gdb_assert_not_reached ("unexpected code path"); 521*ef5ccd6cSJohn Marino } 522*ef5ccd6cSJohn Marino 523*ef5ccd6cSJohn Marino /* Same as ada_varobj_describe_child, but limited to pointer objects. 524*ef5ccd6cSJohn Marino 525*ef5ccd6cSJohn Marino Note that CHILD_INDEX is unused in this situation, but still provided 526*ef5ccd6cSJohn Marino for consistency of interface with other routines describing an object's 527*ef5ccd6cSJohn Marino child. */ 528*ef5ccd6cSJohn Marino 529*ef5ccd6cSJohn Marino static void 530*ef5ccd6cSJohn Marino ada_varobj_describe_ptr_child (struct value *parent_value, 531*ef5ccd6cSJohn Marino struct type *parent_type, 532*ef5ccd6cSJohn Marino const char *parent_name, 533*ef5ccd6cSJohn Marino const char *parent_path_expr, 534*ef5ccd6cSJohn Marino int child_index, 535*ef5ccd6cSJohn Marino char **child_name, 536*ef5ccd6cSJohn Marino struct value **child_value, 537*ef5ccd6cSJohn Marino struct type **child_type, 538*ef5ccd6cSJohn Marino char **child_path_expr) 539*ef5ccd6cSJohn Marino { 540*ef5ccd6cSJohn Marino if (child_name) 541*ef5ccd6cSJohn Marino *child_name = xstrprintf ("%s.all", parent_name); 542*ef5ccd6cSJohn Marino 543*ef5ccd6cSJohn Marino if (child_value && parent_value) 544*ef5ccd6cSJohn Marino ada_varobj_ind (parent_value, parent_type, child_value, NULL); 545*ef5ccd6cSJohn Marino 546*ef5ccd6cSJohn Marino if (child_type) 547*ef5ccd6cSJohn Marino ada_varobj_ind (parent_value, parent_type, NULL, child_type); 548*ef5ccd6cSJohn Marino 549*ef5ccd6cSJohn Marino if (child_path_expr) 550*ef5ccd6cSJohn Marino *child_path_expr = xstrprintf ("(%s).all", parent_path_expr); 551*ef5ccd6cSJohn Marino } 552*ef5ccd6cSJohn Marino 553*ef5ccd6cSJohn Marino /* Same as ada_varobj_describe_child, limited to simple array objects 554*ef5ccd6cSJohn Marino (TYPE_CODE_ARRAY only). 555*ef5ccd6cSJohn Marino 556*ef5ccd6cSJohn Marino Assumes that the (PARENT_VALUE, PARENT_TYPE) pair is properly decoded. 557*ef5ccd6cSJohn Marino This is done by ada_varobj_describe_child before calling us. */ 558*ef5ccd6cSJohn Marino 559*ef5ccd6cSJohn Marino static void 560*ef5ccd6cSJohn Marino ada_varobj_describe_simple_array_child (struct value *parent_value, 561*ef5ccd6cSJohn Marino struct type *parent_type, 562*ef5ccd6cSJohn Marino const char *parent_name, 563*ef5ccd6cSJohn Marino const char *parent_path_expr, 564*ef5ccd6cSJohn Marino int child_index, 565*ef5ccd6cSJohn Marino char **child_name, 566*ef5ccd6cSJohn Marino struct value **child_value, 567*ef5ccd6cSJohn Marino struct type **child_type, 568*ef5ccd6cSJohn Marino char **child_path_expr) 569*ef5ccd6cSJohn Marino { 570*ef5ccd6cSJohn Marino struct type *index_desc_type; 571*ef5ccd6cSJohn Marino struct type *index_type; 572*ef5ccd6cSJohn Marino int real_index; 573*ef5ccd6cSJohn Marino 574*ef5ccd6cSJohn Marino gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY); 575*ef5ccd6cSJohn Marino 576*ef5ccd6cSJohn Marino index_desc_type = ada_find_parallel_type (parent_type, "___XA"); 577*ef5ccd6cSJohn Marino ada_fixup_array_indexes_type (index_desc_type); 578*ef5ccd6cSJohn Marino if (index_desc_type) 579*ef5ccd6cSJohn Marino index_type = TYPE_FIELD_TYPE (index_desc_type, 0); 580*ef5ccd6cSJohn Marino else 581*ef5ccd6cSJohn Marino index_type = TYPE_INDEX_TYPE (parent_type); 582*ef5ccd6cSJohn Marino real_index = child_index + ada_discrete_type_low_bound (index_type); 583*ef5ccd6cSJohn Marino 584*ef5ccd6cSJohn Marino if (child_name) 585*ef5ccd6cSJohn Marino *child_name = ada_varobj_scalar_image (index_type, real_index); 586*ef5ccd6cSJohn Marino 587*ef5ccd6cSJohn Marino if (child_value && parent_value) 588*ef5ccd6cSJohn Marino ada_varobj_simple_array_elt (parent_value, parent_type, real_index, 589*ef5ccd6cSJohn Marino child_value, NULL); 590*ef5ccd6cSJohn Marino 591*ef5ccd6cSJohn Marino if (child_type) 592*ef5ccd6cSJohn Marino ada_varobj_simple_array_elt (parent_value, parent_type, real_index, 593*ef5ccd6cSJohn Marino NULL, child_type); 594*ef5ccd6cSJohn Marino 595*ef5ccd6cSJohn Marino if (child_path_expr) 596*ef5ccd6cSJohn Marino { 597*ef5ccd6cSJohn Marino char *index_img = ada_varobj_scalar_image (index_type, real_index); 598*ef5ccd6cSJohn Marino struct cleanup *cleanups = make_cleanup (xfree, index_img); 599*ef5ccd6cSJohn Marino 600*ef5ccd6cSJohn Marino /* Enumeration litterals by themselves are potentially ambiguous. 601*ef5ccd6cSJohn Marino For instance, consider the following package spec: 602*ef5ccd6cSJohn Marino 603*ef5ccd6cSJohn Marino package Pck is 604*ef5ccd6cSJohn Marino type Color is (Red, Green, Blue, White); 605*ef5ccd6cSJohn Marino type Blood_Cells is (White, Red); 606*ef5ccd6cSJohn Marino end Pck; 607*ef5ccd6cSJohn Marino 608*ef5ccd6cSJohn Marino In this case, the litteral "red" for instance, or even 609*ef5ccd6cSJohn Marino the fully-qualified litteral "pck.red" cannot be resolved 610*ef5ccd6cSJohn Marino by itself. Type qualification is needed to determine which 611*ef5ccd6cSJohn Marino enumeration litterals should be used. 612*ef5ccd6cSJohn Marino 613*ef5ccd6cSJohn Marino The following variable will be used to contain the name 614*ef5ccd6cSJohn Marino of the array index type when such type qualification is 615*ef5ccd6cSJohn Marino needed. */ 616*ef5ccd6cSJohn Marino const char *index_type_name = NULL; 617*ef5ccd6cSJohn Marino 618*ef5ccd6cSJohn Marino /* If the index type is a range type, find the base type. */ 619*ef5ccd6cSJohn Marino while (TYPE_CODE (index_type) == TYPE_CODE_RANGE) 620*ef5ccd6cSJohn Marino index_type = TYPE_TARGET_TYPE (index_type); 621*ef5ccd6cSJohn Marino 622*ef5ccd6cSJohn Marino if (TYPE_CODE (index_type) == TYPE_CODE_ENUM 623*ef5ccd6cSJohn Marino || TYPE_CODE (index_type) == TYPE_CODE_BOOL) 624*ef5ccd6cSJohn Marino { 625*ef5ccd6cSJohn Marino index_type_name = ada_type_name (index_type); 626*ef5ccd6cSJohn Marino if (index_type_name) 627*ef5ccd6cSJohn Marino index_type_name = ada_decode (index_type_name); 628*ef5ccd6cSJohn Marino } 629*ef5ccd6cSJohn Marino 630*ef5ccd6cSJohn Marino if (index_type_name != NULL) 631*ef5ccd6cSJohn Marino *child_path_expr = 632*ef5ccd6cSJohn Marino xstrprintf ("(%s)(%.*s'(%s))", parent_path_expr, 633*ef5ccd6cSJohn Marino ada_name_prefix_len (index_type_name), 634*ef5ccd6cSJohn Marino index_type_name, index_img); 635*ef5ccd6cSJohn Marino else 636*ef5ccd6cSJohn Marino *child_path_expr = 637*ef5ccd6cSJohn Marino xstrprintf ("(%s)(%s)", parent_path_expr, index_img); 638*ef5ccd6cSJohn Marino do_cleanups (cleanups); 639*ef5ccd6cSJohn Marino } 640*ef5ccd6cSJohn Marino } 641*ef5ccd6cSJohn Marino 642*ef5ccd6cSJohn Marino /* See description at declaration above. */ 643*ef5ccd6cSJohn Marino 644*ef5ccd6cSJohn Marino static void 645*ef5ccd6cSJohn Marino ada_varobj_describe_child (struct value *parent_value, 646*ef5ccd6cSJohn Marino struct type *parent_type, 647*ef5ccd6cSJohn Marino const char *parent_name, 648*ef5ccd6cSJohn Marino const char *parent_path_expr, 649*ef5ccd6cSJohn Marino int child_index, 650*ef5ccd6cSJohn Marino char **child_name, 651*ef5ccd6cSJohn Marino struct value **child_value, 652*ef5ccd6cSJohn Marino struct type **child_type, 653*ef5ccd6cSJohn Marino char **child_path_expr) 654*ef5ccd6cSJohn Marino { 655*ef5ccd6cSJohn Marino /* We cannot compute the child's path expression without 656*ef5ccd6cSJohn Marino the parent's path expression. This is a pre-condition 657*ef5ccd6cSJohn Marino for calling this function. */ 658*ef5ccd6cSJohn Marino if (child_path_expr) 659*ef5ccd6cSJohn Marino gdb_assert (parent_path_expr != NULL); 660*ef5ccd6cSJohn Marino 661*ef5ccd6cSJohn Marino ada_varobj_decode_var (&parent_value, &parent_type); 662*ef5ccd6cSJohn Marino ada_varobj_adjust_for_child_access (&parent_value, &parent_type); 663*ef5ccd6cSJohn Marino 664*ef5ccd6cSJohn Marino if (child_name) 665*ef5ccd6cSJohn Marino *child_name = NULL; 666*ef5ccd6cSJohn Marino if (child_value) 667*ef5ccd6cSJohn Marino *child_value = NULL; 668*ef5ccd6cSJohn Marino if (child_type) 669*ef5ccd6cSJohn Marino *child_type = NULL; 670*ef5ccd6cSJohn Marino if (child_path_expr) 671*ef5ccd6cSJohn Marino *child_path_expr = NULL; 672*ef5ccd6cSJohn Marino 673*ef5ccd6cSJohn Marino if (ada_is_array_descriptor_type (parent_type) 674*ef5ccd6cSJohn Marino && TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF) 675*ef5ccd6cSJohn Marino { 676*ef5ccd6cSJohn Marino ada_varobj_describe_ptr_child (parent_value, parent_type, 677*ef5ccd6cSJohn Marino parent_name, parent_path_expr, 678*ef5ccd6cSJohn Marino child_index, child_name, 679*ef5ccd6cSJohn Marino child_value, child_type, 680*ef5ccd6cSJohn Marino child_path_expr); 681*ef5ccd6cSJohn Marino return; 682*ef5ccd6cSJohn Marino } 683*ef5ccd6cSJohn Marino 684*ef5ccd6cSJohn Marino if (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY) 685*ef5ccd6cSJohn Marino { 686*ef5ccd6cSJohn Marino ada_varobj_describe_simple_array_child 687*ef5ccd6cSJohn Marino (parent_value, parent_type, parent_name, parent_path_expr, 688*ef5ccd6cSJohn Marino child_index, child_name, child_value, child_type, 689*ef5ccd6cSJohn Marino child_path_expr); 690*ef5ccd6cSJohn Marino return; 691*ef5ccd6cSJohn Marino } 692*ef5ccd6cSJohn Marino 693*ef5ccd6cSJohn Marino if (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT) 694*ef5ccd6cSJohn Marino { 695*ef5ccd6cSJohn Marino ada_varobj_describe_struct_child (parent_value, parent_type, 696*ef5ccd6cSJohn Marino parent_name, parent_path_expr, 697*ef5ccd6cSJohn Marino child_index, child_name, 698*ef5ccd6cSJohn Marino child_value, child_type, 699*ef5ccd6cSJohn Marino child_path_expr); 700*ef5ccd6cSJohn Marino return; 701*ef5ccd6cSJohn Marino } 702*ef5ccd6cSJohn Marino 703*ef5ccd6cSJohn Marino if (TYPE_CODE (parent_type) == TYPE_CODE_PTR) 704*ef5ccd6cSJohn Marino { 705*ef5ccd6cSJohn Marino ada_varobj_describe_ptr_child (parent_value, parent_type, 706*ef5ccd6cSJohn Marino parent_name, parent_path_expr, 707*ef5ccd6cSJohn Marino child_index, child_name, 708*ef5ccd6cSJohn Marino child_value, child_type, 709*ef5ccd6cSJohn Marino child_path_expr); 710*ef5ccd6cSJohn Marino return; 711*ef5ccd6cSJohn Marino } 712*ef5ccd6cSJohn Marino 713*ef5ccd6cSJohn Marino /* It should never happen. But rather than crash, report dummy names 714*ef5ccd6cSJohn Marino and return a NULL child_value. */ 715*ef5ccd6cSJohn Marino if (child_name) 716*ef5ccd6cSJohn Marino *child_name = xstrdup ("???"); 717*ef5ccd6cSJohn Marino } 718*ef5ccd6cSJohn Marino 719*ef5ccd6cSJohn Marino /* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE, 720*ef5ccd6cSJohn Marino PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT. 721*ef5ccd6cSJohn Marino 722*ef5ccd6cSJohn Marino The result should be deallocated after use with xfree. */ 723*ef5ccd6cSJohn Marino 724*ef5ccd6cSJohn Marino char * 725*ef5ccd6cSJohn Marino ada_varobj_get_name_of_child (struct value *parent_value, 726*ef5ccd6cSJohn Marino struct type *parent_type, 727*ef5ccd6cSJohn Marino const char *parent_name, int child_index) 728*ef5ccd6cSJohn Marino { 729*ef5ccd6cSJohn Marino char *child_name; 730*ef5ccd6cSJohn Marino 731*ef5ccd6cSJohn Marino ada_varobj_describe_child (parent_value, parent_type, parent_name, 732*ef5ccd6cSJohn Marino NULL, child_index, &child_name, NULL, 733*ef5ccd6cSJohn Marino NULL, NULL); 734*ef5ccd6cSJohn Marino return child_name; 735*ef5ccd6cSJohn Marino } 736*ef5ccd6cSJohn Marino 737*ef5ccd6cSJohn Marino /* Return the path expression of the child number CHILD_INDEX of 738*ef5ccd6cSJohn Marino the (PARENT_VALUE, PARENT_TYPE) pair. PARENT_NAME is the name 739*ef5ccd6cSJohn Marino of the parent, and PARENT_PATH_EXPR is the parent's path expression. 740*ef5ccd6cSJohn Marino Both must be non-NULL. 741*ef5ccd6cSJohn Marino 742*ef5ccd6cSJohn Marino The result must be deallocated after use with xfree. */ 743*ef5ccd6cSJohn Marino 744*ef5ccd6cSJohn Marino char * 745*ef5ccd6cSJohn Marino ada_varobj_get_path_expr_of_child (struct value *parent_value, 746*ef5ccd6cSJohn Marino struct type *parent_type, 747*ef5ccd6cSJohn Marino const char *parent_name, 748*ef5ccd6cSJohn Marino const char *parent_path_expr, 749*ef5ccd6cSJohn Marino int child_index) 750*ef5ccd6cSJohn Marino { 751*ef5ccd6cSJohn Marino char *child_path_expr; 752*ef5ccd6cSJohn Marino 753*ef5ccd6cSJohn Marino ada_varobj_describe_child (parent_value, parent_type, parent_name, 754*ef5ccd6cSJohn Marino parent_path_expr, child_index, NULL, 755*ef5ccd6cSJohn Marino NULL, NULL, &child_path_expr); 756*ef5ccd6cSJohn Marino 757*ef5ccd6cSJohn Marino return child_path_expr; 758*ef5ccd6cSJohn Marino } 759*ef5ccd6cSJohn Marino 760*ef5ccd6cSJohn Marino /* Return the value of child number CHILD_INDEX of the (PARENT_VALUE, 761*ef5ccd6cSJohn Marino PARENT_TYPE) pair. PARENT_NAME is the name of the parent. */ 762*ef5ccd6cSJohn Marino 763*ef5ccd6cSJohn Marino struct value * 764*ef5ccd6cSJohn Marino ada_varobj_get_value_of_child (struct value *parent_value, 765*ef5ccd6cSJohn Marino struct type *parent_type, 766*ef5ccd6cSJohn Marino const char *parent_name, int child_index) 767*ef5ccd6cSJohn Marino { 768*ef5ccd6cSJohn Marino struct value *child_value; 769*ef5ccd6cSJohn Marino 770*ef5ccd6cSJohn Marino ada_varobj_describe_child (parent_value, parent_type, parent_name, 771*ef5ccd6cSJohn Marino NULL, child_index, NULL, &child_value, 772*ef5ccd6cSJohn Marino NULL, NULL); 773*ef5ccd6cSJohn Marino 774*ef5ccd6cSJohn Marino return child_value; 775*ef5ccd6cSJohn Marino } 776*ef5ccd6cSJohn Marino 777*ef5ccd6cSJohn Marino /* Return the type of child number CHILD_INDEX of the (PARENT_VALUE, 778*ef5ccd6cSJohn Marino PARENT_TYPE) pair. */ 779*ef5ccd6cSJohn Marino 780*ef5ccd6cSJohn Marino struct type * 781*ef5ccd6cSJohn Marino ada_varobj_get_type_of_child (struct value *parent_value, 782*ef5ccd6cSJohn Marino struct type *parent_type, 783*ef5ccd6cSJohn Marino int child_index) 784*ef5ccd6cSJohn Marino { 785*ef5ccd6cSJohn Marino struct type *child_type; 786*ef5ccd6cSJohn Marino 787*ef5ccd6cSJohn Marino ada_varobj_describe_child (parent_value, parent_type, NULL, NULL, 788*ef5ccd6cSJohn Marino child_index, NULL, NULL, &child_type, NULL); 789*ef5ccd6cSJohn Marino 790*ef5ccd6cSJohn Marino return child_type; 791*ef5ccd6cSJohn Marino } 792*ef5ccd6cSJohn Marino 793*ef5ccd6cSJohn Marino /* Return a string that contains the image of the given VALUE, using 794*ef5ccd6cSJohn Marino the print options OPTS as the options for formatting the result. 795*ef5ccd6cSJohn Marino 796*ef5ccd6cSJohn Marino The resulting string must be deallocated after use with xfree. */ 797*ef5ccd6cSJohn Marino 798*ef5ccd6cSJohn Marino static char * 799*ef5ccd6cSJohn Marino ada_varobj_get_value_image (struct value *value, 800*ef5ccd6cSJohn Marino struct value_print_options *opts) 801*ef5ccd6cSJohn Marino { 802*ef5ccd6cSJohn Marino char *result; 803*ef5ccd6cSJohn Marino struct ui_file *buffer; 804*ef5ccd6cSJohn Marino struct cleanup *old_chain; 805*ef5ccd6cSJohn Marino 806*ef5ccd6cSJohn Marino buffer = mem_fileopen (); 807*ef5ccd6cSJohn Marino old_chain = make_cleanup_ui_file_delete (buffer); 808*ef5ccd6cSJohn Marino 809*ef5ccd6cSJohn Marino common_val_print (value, buffer, 0, opts, current_language); 810*ef5ccd6cSJohn Marino result = ui_file_xstrdup (buffer, NULL); 811*ef5ccd6cSJohn Marino 812*ef5ccd6cSJohn Marino do_cleanups (old_chain); 813*ef5ccd6cSJohn Marino return result; 814*ef5ccd6cSJohn Marino } 815*ef5ccd6cSJohn Marino 816*ef5ccd6cSJohn Marino /* Assuming that the (VALUE, TYPE) pair designates an array varobj, 817*ef5ccd6cSJohn Marino return a string that is suitable for use in the "value" field of 818*ef5ccd6cSJohn Marino the varobj output. Most of the time, this is the number of elements 819*ef5ccd6cSJohn Marino in the array inside square brackets, but there are situations where 820*ef5ccd6cSJohn Marino it's useful to add more info. 821*ef5ccd6cSJohn Marino 822*ef5ccd6cSJohn Marino OPTS are the print options used when formatting the result. 823*ef5ccd6cSJohn Marino 824*ef5ccd6cSJohn Marino The result should be deallocated after use using xfree. */ 825*ef5ccd6cSJohn Marino 826*ef5ccd6cSJohn Marino static char * 827*ef5ccd6cSJohn Marino ada_varobj_get_value_of_array_variable (struct value *value, 828*ef5ccd6cSJohn Marino struct type *type, 829*ef5ccd6cSJohn Marino struct value_print_options *opts) 830*ef5ccd6cSJohn Marino { 831*ef5ccd6cSJohn Marino char *result; 832*ef5ccd6cSJohn Marino const int numchild = ada_varobj_get_array_number_of_children (value, type); 833*ef5ccd6cSJohn Marino 834*ef5ccd6cSJohn Marino /* If we have a string, provide its contents in the "value" field. 835*ef5ccd6cSJohn Marino Otherwise, the only other way to inspect the contents of the string 836*ef5ccd6cSJohn Marino is by looking at the value of each element, as in any other array, 837*ef5ccd6cSJohn Marino which is not very convenient... */ 838*ef5ccd6cSJohn Marino if (value 839*ef5ccd6cSJohn Marino && ada_is_string_type (type) 840*ef5ccd6cSJohn Marino && (opts->format == 0 || opts->format == 's')) 841*ef5ccd6cSJohn Marino { 842*ef5ccd6cSJohn Marino char *str; 843*ef5ccd6cSJohn Marino struct cleanup *old_chain; 844*ef5ccd6cSJohn Marino 845*ef5ccd6cSJohn Marino str = ada_varobj_get_value_image (value, opts); 846*ef5ccd6cSJohn Marino old_chain = make_cleanup (xfree, str); 847*ef5ccd6cSJohn Marino result = xstrprintf ("[%d] %s", numchild, str); 848*ef5ccd6cSJohn Marino do_cleanups (old_chain); 849*ef5ccd6cSJohn Marino } 850*ef5ccd6cSJohn Marino else 851*ef5ccd6cSJohn Marino result = xstrprintf ("[%d]", numchild); 852*ef5ccd6cSJohn Marino 853*ef5ccd6cSJohn Marino return result; 854*ef5ccd6cSJohn Marino } 855*ef5ccd6cSJohn Marino 856*ef5ccd6cSJohn Marino /* Return a string representation of the (VALUE, TYPE) pair, using 857*ef5ccd6cSJohn Marino the given print options OPTS as our formatting options. */ 858*ef5ccd6cSJohn Marino 859*ef5ccd6cSJohn Marino char * 860*ef5ccd6cSJohn Marino ada_varobj_get_value_of_variable (struct value *value, 861*ef5ccd6cSJohn Marino struct type *type, 862*ef5ccd6cSJohn Marino struct value_print_options *opts) 863*ef5ccd6cSJohn Marino { 864*ef5ccd6cSJohn Marino char *result = NULL; 865*ef5ccd6cSJohn Marino 866*ef5ccd6cSJohn Marino ada_varobj_decode_var (&value, &type); 867*ef5ccd6cSJohn Marino 868*ef5ccd6cSJohn Marino switch (TYPE_CODE (type)) 869*ef5ccd6cSJohn Marino { 870*ef5ccd6cSJohn Marino case TYPE_CODE_STRUCT: 871*ef5ccd6cSJohn Marino case TYPE_CODE_UNION: 872*ef5ccd6cSJohn Marino result = xstrdup ("{...}"); 873*ef5ccd6cSJohn Marino break; 874*ef5ccd6cSJohn Marino case TYPE_CODE_ARRAY: 875*ef5ccd6cSJohn Marino result = ada_varobj_get_value_of_array_variable (value, type, opts); 876*ef5ccd6cSJohn Marino break; 877*ef5ccd6cSJohn Marino default: 878*ef5ccd6cSJohn Marino if (!value) 879*ef5ccd6cSJohn Marino result = xstrdup (""); 880*ef5ccd6cSJohn Marino else 881*ef5ccd6cSJohn Marino result = ada_varobj_get_value_image (value, opts); 882*ef5ccd6cSJohn Marino break; 883*ef5ccd6cSJohn Marino } 884*ef5ccd6cSJohn Marino 885*ef5ccd6cSJohn Marino return result; 886*ef5ccd6cSJohn Marino } 887*ef5ccd6cSJohn Marino 888*ef5ccd6cSJohn Marino 889