GDB (API)
/home/stan/gdb/src/gdb/ada-varobj.c
Go to the documentation of this file.
00001 /* varobj support for Ada.
00002 
00003    Copyright (C) 2012-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "ada-varobj.h"
00022 #include "ada-lang.h"
00023 #include "language.h"
00024 #include "valprint.h"
00025 
00026 /* Implementation principle used in this unit:
00027 
00028    For our purposes, the meat of the varobj object is made of two
00029    elements: The varobj's (struct) value, and the varobj's (struct)
00030    type.  In most situations, the varobj has a non-NULL value, and
00031    the type becomes redundant, as it can be directly derived from
00032    the value.  In the initial implementation of this unit, most
00033    routines would only take a value, and return a value.
00034 
00035    But there are many situations where it is possible for a varobj
00036    to have a NULL value.  For instance, if the varobj becomes out of
00037    scope.  Or better yet, when the varobj is the child of another
00038    NULL pointer varobj.  In that situation, we must rely on the type
00039    instead of the value to create the child varobj.
00040 
00041    That's why most functions below work with a (value, type) pair.
00042    The value may or may not be NULL.  But the type is always expected
00043    to be set.  When the value is NULL, then we work with the type
00044    alone, and keep the value NULL.  But when the value is not NULL,
00045    then we work using the value, because it provides more information.
00046    But we still always set the type as well, even if that type could
00047    easily be derived from the value.  The reason behind this is that
00048    it allows the code to use the type without having to worry about
00049    it being set or not.  It makes the code clearer.  */
00050 
00051 /* A convenience function that decodes the VALUE_PTR/TYPE_PTR couple:
00052    If there is a value (*VALUE_PTR not NULL), then perform the decoding
00053    using it, and compute the associated type from the resulting value.
00054    Otherwise, compute a static approximation of *TYPE_PTR, leaving
00055    *VALUE_PTR unchanged.
00056 
00057    The results are written in place.  */
00058 
00059 static void
00060 ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr)
00061 {
00062   if (*value_ptr)
00063     {
00064       *value_ptr = ada_get_decoded_value (*value_ptr);
00065       *type_ptr = ada_check_typedef (value_type (*value_ptr));
00066     }
00067   else
00068     *type_ptr = ada_get_decoded_type (*type_ptr);
00069 }
00070 
00071 /* Return a string containing an image of the given scalar value.
00072    VAL is the numeric value, while TYPE is the value's type.
00073    This is useful for plain integers, of course, but even more
00074    so for enumerated types.
00075 
00076    The result should be deallocated by xfree after use.  */
00077 
00078 static char *
00079 ada_varobj_scalar_image (struct type *type, LONGEST val)
00080 {
00081   struct ui_file *buf = mem_fileopen ();
00082   struct cleanup *cleanups = make_cleanup_ui_file_delete (buf);
00083   char *result;
00084 
00085   ada_print_scalar (type, val, buf);
00086   result = ui_file_xstrdup (buf, NULL);
00087   do_cleanups (cleanups);
00088 
00089   return result;
00090 }
00091 
00092 /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair designates
00093    a struct or union, compute the (CHILD_VALUE, CHILD_TYPE) couple
00094    corresponding to the field number FIELDNO.  */
00095 
00096 static void
00097 ada_varobj_struct_elt (struct value *parent_value,
00098                        struct type *parent_type,
00099                        int fieldno,
00100                        struct value **child_value,
00101                        struct type **child_type)
00102 {
00103   struct value *value = NULL;
00104   struct type *type = NULL;
00105 
00106   if (parent_value)
00107     {
00108       value = value_field (parent_value, fieldno);
00109       type = value_type (value);
00110     }
00111   else
00112     type = TYPE_FIELD_TYPE (parent_type, fieldno);
00113 
00114   if (child_value)
00115     *child_value = value;
00116   if (child_type)
00117     *child_type = type;
00118 }
00119 
00120 /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is a pointer or
00121    reference, return a (CHILD_VALUE, CHILD_TYPE) couple corresponding
00122    to the dereferenced value.  */
00123 
00124 static void
00125 ada_varobj_ind (struct value *parent_value,
00126                 struct type *parent_type,
00127                 struct value **child_value,
00128                 struct type **child_type)
00129 {
00130   struct value *value = NULL;
00131   struct type *type = NULL;
00132 
00133   if (ada_is_array_descriptor_type (parent_type))
00134     {
00135       /* This can only happen when PARENT_VALUE is NULL.  Otherwise,
00136          ada_get_decoded_value would have transformed our parent_type
00137          into a simple array pointer type.  */
00138       gdb_assert (parent_value == NULL);
00139       gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF);
00140 
00141       /* Decode parent_type by the equivalent pointer to (decoded)
00142          array.  */
00143       while (TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF)
00144         parent_type = TYPE_TARGET_TYPE (parent_type);
00145       parent_type = ada_coerce_to_simple_array_type (parent_type);
00146       parent_type = lookup_pointer_type (parent_type);
00147     }
00148 
00149   /* If parent_value is a null pointer, then only perform static
00150      dereferencing.  We cannot dereference null pointers.  */
00151   if (parent_value && value_as_address (parent_value) == 0)
00152     parent_value = NULL;
00153 
00154   if (parent_value)
00155     {
00156       value = ada_value_ind (parent_value);
00157       type = value_type (value);
00158     }
00159   else
00160     type = TYPE_TARGET_TYPE (parent_type);
00161 
00162   if (child_value)
00163     *child_value = value;
00164   if (child_type)
00165     *child_type = type;
00166 }
00167 
00168 /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is a simple
00169    array (TYPE_CODE_ARRAY), return the (CHILD_VALUE, CHILD_TYPE)
00170    pair corresponding to the element at ELT_INDEX.  */
00171 
00172 static void
00173 ada_varobj_simple_array_elt (struct value *parent_value,
00174                              struct type *parent_type,
00175                              int elt_index,
00176                              struct value **child_value,
00177                              struct type **child_type)
00178 {
00179   struct value *value = NULL;
00180   struct type *type = NULL;
00181 
00182   if (parent_value)
00183     {
00184       struct value *index_value =
00185         value_from_longest (TYPE_INDEX_TYPE (parent_type), elt_index);
00186 
00187       value = ada_value_subscript (parent_value, 1, &index_value);
00188       type = value_type (value);
00189     }
00190   else
00191     type = TYPE_TARGET_TYPE (parent_type);
00192 
00193   if (child_value)
00194     *child_value = value;
00195   if (child_type)
00196     *child_type = type;
00197 }
00198 
00199 /* Given the decoded value and decoded type of a variable object,
00200    adjust the value and type to those necessary for getting children
00201    of the variable object.
00202 
00203    The replacement is performed in place.  */
00204 
00205 static void
00206 ada_varobj_adjust_for_child_access (struct value **value,
00207                                     struct type **type)
00208 {
00209    /* Pointers to struct/union types are special: Instead of having
00210       one child (the struct), their children are the components of
00211       the struct/union type.  We handle this situation by dereferencing
00212       the (value, type) couple.  */
00213   if (TYPE_CODE (*type) == TYPE_CODE_PTR
00214       && (TYPE_CODE (TYPE_TARGET_TYPE (*type)) == TYPE_CODE_STRUCT
00215           || TYPE_CODE (TYPE_TARGET_TYPE (*type)) == TYPE_CODE_UNION)
00216       && !ada_is_array_descriptor_type (TYPE_TARGET_TYPE (*type))
00217       && !ada_is_constrained_packed_array_type (TYPE_TARGET_TYPE (*type)))
00218     ada_varobj_ind (*value, *type, value, type);
00219 }
00220 
00221 /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is an array
00222    (any type of array, "simple" or not), return the number of children
00223    that this array contains.  */
00224 
00225 static int
00226 ada_varobj_get_array_number_of_children (struct value *parent_value,
00227                                          struct type *parent_type)
00228 {
00229   LONGEST lo, hi;
00230 
00231   if (!get_array_bounds (parent_type, &lo, &hi))
00232     {
00233       /* Could not get the array bounds.  Pretend this is an empty array.  */
00234       warning (_("unable to get bounds of array, assuming null array"));
00235       return 0;
00236     }
00237 
00238   /* Ada allows the upper bound to be less than the lower bound,
00239      in order to specify empty arrays...  */
00240   if (hi < lo)
00241     return 0;
00242 
00243   return hi - lo + 1;
00244 }
00245 
00246 /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is a struct or
00247    union, return the number of children this struct contains.  */
00248 
00249 static int
00250 ada_varobj_get_struct_number_of_children (struct value *parent_value,
00251                                           struct type *parent_type)
00252 {
00253   int n_children = 0;
00254   int i;
00255 
00256   gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT
00257               || TYPE_CODE (parent_type) == TYPE_CODE_UNION);
00258 
00259   for (i = 0; i < TYPE_NFIELDS (parent_type); i++)
00260     {
00261       if (ada_is_ignored_field (parent_type, i))
00262         continue;
00263 
00264       if (ada_is_wrapper_field (parent_type, i))
00265         {
00266           struct value *elt_value;
00267           struct type *elt_type;
00268 
00269           ada_varobj_struct_elt (parent_value, parent_type, i,
00270                                  &elt_value, &elt_type);
00271           if (ada_is_tagged_type (elt_type, 0))
00272             {
00273               /* We must not use ada_varobj_get_number_of_children
00274                  to determine is element's number of children, because
00275                  this function first calls ada_varobj_decode_var,
00276                  which "fixes" the element.  For tagged types, this
00277                  includes reading the object's tag to determine its
00278                  real type, which happens to be the parent_type, and
00279                  leads to an infinite loop (because the element gets
00280                  fixed back into the parent).  */
00281               n_children += ada_varobj_get_struct_number_of_children
00282                 (elt_value, elt_type);
00283             }
00284           else
00285             n_children += ada_varobj_get_number_of_children (elt_value, elt_type);
00286         }
00287       else if (ada_is_variant_part (parent_type, i))
00288         {
00289           /* In normal situations, the variant part of the record should
00290              have been "fixed". Or, in other words, it should have been
00291              replaced by the branch of the variant part that is relevant
00292              for our value.  But there are still situations where this
00293              can happen, however (Eg. when our parent is a NULL pointer).
00294              We do not support showing this part of the record for now,
00295              so just pretend this field does not exist.  */
00296         }
00297       else
00298         n_children++;
00299     }
00300 
00301   return n_children;
00302 }
00303 
00304 /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair designates
00305    a pointer, return the number of children this pointer has.  */
00306 
00307 static int
00308 ada_varobj_get_ptr_number_of_children (struct value *parent_value,
00309                                        struct type *parent_type)
00310 {
00311   struct type *child_type = TYPE_TARGET_TYPE (parent_type);
00312 
00313   /* Pointer to functions and to void do not have a child, since
00314      you cannot print what they point to.  */
00315   if (TYPE_CODE (child_type) == TYPE_CODE_FUNC
00316       || TYPE_CODE (child_type) == TYPE_CODE_VOID)
00317     return 0;
00318 
00319   /* All other types have 1 child.  */
00320   return 1;
00321 }
00322 
00323 /* Return the number of children for the (PARENT_VALUE, PARENT_TYPE)
00324    pair.  */
00325 
00326 int
00327 ada_varobj_get_number_of_children (struct value *parent_value,
00328                                    struct type *parent_type)
00329 {
00330   ada_varobj_decode_var (&parent_value, &parent_type);
00331   ada_varobj_adjust_for_child_access (&parent_value, &parent_type);
00332 
00333   /* A typedef to an array descriptor in fact represents a pointer
00334      to an unconstrained array.  These types always have one child
00335      (the unconstrained array).  */
00336   if (ada_is_array_descriptor_type (parent_type)
00337       && TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF)
00338     return 1;
00339 
00340   if (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY)
00341     return ada_varobj_get_array_number_of_children (parent_value,
00342                                                     parent_type);
00343 
00344   if (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT
00345       || TYPE_CODE (parent_type) == TYPE_CODE_UNION)
00346     return ada_varobj_get_struct_number_of_children (parent_value,
00347                                                      parent_type);
00348 
00349   if (TYPE_CODE (parent_type) == TYPE_CODE_PTR)
00350     return ada_varobj_get_ptr_number_of_children (parent_value,
00351                                                   parent_type);
00352 
00353   /* All other types have no child.  */
00354   return 0;
00355 }
00356 
00357 /* Describe the child of the (PARENT_VALUE, PARENT_TYPE) pair
00358    whose index is CHILD_INDEX:
00359 
00360      - If CHILD_NAME is not NULL, then a copy of the child's name
00361        is saved in *CHILD_NAME.  This copy must be deallocated
00362        with xfree after use.
00363 
00364      - If CHILD_VALUE is not NULL, then save the child's value
00365        in *CHILD_VALUE. Same thing for the child's type with
00366        CHILD_TYPE if not NULL.
00367 
00368      - If CHILD_PATH_EXPR is not NULL, then compute the child's
00369        path expression.  The resulting string must be deallocated
00370        after use with xfree.
00371 
00372        Computing the child's path expression requires the PARENT_PATH_EXPR
00373        to be non-NULL.  Otherwise, PARENT_PATH_EXPR may be null if
00374        CHILD_PATH_EXPR is NULL.
00375 
00376   PARENT_NAME is the name of the parent, and should never be NULL.  */
00377 
00378 static void ada_varobj_describe_child (struct value *parent_value,
00379                                        struct type *parent_type,
00380                                        const char *parent_name,
00381                                        const char *parent_path_expr,
00382                                        int child_index,
00383                                        char **child_name,
00384                                        struct value **child_value,
00385                                        struct type **child_type,
00386                                        char **child_path_expr);
00387 
00388 /* Same as ada_varobj_describe_child, but limited to struct/union
00389    objects.  */
00390 
00391 static void
00392 ada_varobj_describe_struct_child (struct value *parent_value,
00393                                   struct type *parent_type,
00394                                   const char *parent_name,
00395                                   const char *parent_path_expr,
00396                                   int child_index,
00397                                   char **child_name,
00398                                   struct value **child_value,
00399                                   struct type **child_type,
00400                                   char **child_path_expr)
00401 {
00402   int fieldno;
00403   int childno = 0;
00404 
00405   gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT);
00406 
00407   for (fieldno = 0; fieldno < TYPE_NFIELDS (parent_type); fieldno++)
00408     {
00409       if (ada_is_ignored_field (parent_type, fieldno))
00410         continue;
00411 
00412       if (ada_is_wrapper_field (parent_type, fieldno))
00413         {
00414           struct value *elt_value;
00415           struct type *elt_type;
00416           int elt_n_children;
00417 
00418           ada_varobj_struct_elt (parent_value, parent_type, fieldno,
00419                                  &elt_value, &elt_type);
00420           if (ada_is_tagged_type (elt_type, 0))
00421             {
00422               /* Same as in ada_varobj_get_struct_number_of_children:
00423                  For tagged types, we must be careful to not call
00424                  ada_varobj_get_number_of_children, to prevent our
00425                  element from being fixed back into the parent.  */
00426               elt_n_children = ada_varobj_get_struct_number_of_children
00427                 (elt_value, elt_type);
00428             }
00429           else
00430             elt_n_children =
00431               ada_varobj_get_number_of_children (elt_value, elt_type);
00432 
00433           /* Is the child we're looking for one of the children
00434              of this wrapper field?  */
00435           if (child_index - childno < elt_n_children)
00436             {
00437               if (ada_is_tagged_type (elt_type, 0))
00438                 {
00439                   /* Same as in ada_varobj_get_struct_number_of_children:
00440                      For tagged types, we must be careful to not call
00441                      ada_varobj_describe_child, to prevent our element
00442                      from being fixed back into the parent.  */
00443                   ada_varobj_describe_struct_child
00444                     (elt_value, elt_type, parent_name, parent_path_expr,
00445                      child_index - childno, child_name, child_value,
00446                      child_type, child_path_expr);
00447                 }
00448               else
00449                 ada_varobj_describe_child (elt_value, elt_type,
00450                                            parent_name, parent_path_expr,
00451                                            child_index - childno,
00452                                            child_name, child_value,
00453                                            child_type, child_path_expr);
00454               return;
00455             }
00456 
00457           /* The child we're looking for is beyond this wrapper
00458              field, so skip all its children.  */
00459           childno += elt_n_children;
00460           continue;
00461         }
00462       else if (ada_is_variant_part (parent_type, fieldno))
00463         {
00464           /* In normal situations, the variant part of the record should
00465              have been "fixed". Or, in other words, it should have been
00466              replaced by the branch of the variant part that is relevant
00467              for our value.  But there are still situations where this
00468              can happen, however (Eg. when our parent is a NULL pointer).
00469              We do not support showing this part of the record for now,
00470              so just pretend this field does not exist.  */
00471           continue;
00472         }
00473 
00474       if (childno == child_index)
00475         {
00476           if (child_name)
00477             {
00478               /* The name of the child is none other than the field's
00479                  name, except that we need to strip suffixes from it.
00480                  For instance, fields with alignment constraints will
00481                  have an __XVA suffix added to them.  */
00482               const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
00483               int child_name_len = ada_name_prefix_len (field_name);
00484 
00485               *child_name = xstrprintf ("%.*s", child_name_len, field_name);
00486             }
00487 
00488           if (child_value && parent_value)
00489             ada_varobj_struct_elt (parent_value, parent_type, fieldno,
00490                                    child_value, NULL);
00491 
00492           if (child_type)
00493             ada_varobj_struct_elt (parent_value, parent_type, fieldno,
00494                                    NULL, child_type);
00495 
00496           if (child_path_expr)
00497             {
00498               /* The name of the child is none other than the field's
00499                  name, except that we need to strip suffixes from it.
00500                  For instance, fields with alignment constraints will
00501                  have an __XVA suffix added to them.  */
00502               const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
00503               int child_name_len = ada_name_prefix_len (field_name);
00504 
00505               *child_path_expr =
00506                 xstrprintf ("(%s).%.*s", parent_path_expr,
00507                             child_name_len, field_name);
00508             }
00509 
00510           return;
00511         }
00512 
00513       childno++;
00514     }
00515 
00516   /* Something went wrong.  Either we miscounted the number of
00517      children, or CHILD_INDEX was too high.  But we should never
00518      reach here.  We don't have enough information to recover
00519      nicely, so just raise an assertion failure.  */
00520   gdb_assert_not_reached ("unexpected code path");
00521 }
00522 
00523 /* Same as ada_varobj_describe_child, but limited to pointer objects.
00524 
00525    Note that CHILD_INDEX is unused in this situation, but still provided
00526    for consistency of interface with other routines describing an object's
00527    child.  */
00528 
00529 static void
00530 ada_varobj_describe_ptr_child (struct value *parent_value,
00531                                struct type *parent_type,
00532                                const char *parent_name,
00533                                const char *parent_path_expr,
00534                                int child_index,
00535                                char **child_name,
00536                                struct value **child_value,
00537                                struct type **child_type,
00538                                char **child_path_expr)
00539 {
00540   if (child_name)
00541     *child_name = xstrprintf ("%s.all", parent_name);
00542 
00543   if (child_value && parent_value)
00544     ada_varobj_ind (parent_value, parent_type, child_value, NULL);
00545 
00546   if (child_type)
00547     ada_varobj_ind (parent_value, parent_type, NULL, child_type);
00548 
00549   if (child_path_expr)
00550     *child_path_expr = xstrprintf ("(%s).all", parent_path_expr);
00551 }
00552 
00553 /* Same as ada_varobj_describe_child, limited to simple array objects
00554    (TYPE_CODE_ARRAY only).
00555 
00556    Assumes that the (PARENT_VALUE, PARENT_TYPE) pair is properly decoded.
00557    This is done by ada_varobj_describe_child before calling us.  */
00558 
00559 static void
00560 ada_varobj_describe_simple_array_child (struct value *parent_value,
00561                                         struct type *parent_type,
00562                                         const char *parent_name,
00563                                         const char *parent_path_expr,
00564                                         int child_index,
00565                                         char **child_name,
00566                                         struct value **child_value,
00567                                         struct type **child_type,
00568                                         char **child_path_expr)
00569 {
00570   struct type *index_desc_type;
00571   struct type *index_type;
00572   int real_index;
00573 
00574   gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY);
00575 
00576   index_desc_type = ada_find_parallel_type (parent_type, "___XA");
00577   ada_fixup_array_indexes_type (index_desc_type);
00578   if (index_desc_type)
00579     index_type = TYPE_FIELD_TYPE (index_desc_type, 0);
00580   else
00581     index_type = TYPE_INDEX_TYPE (parent_type);
00582   real_index = child_index + ada_discrete_type_low_bound (index_type);
00583 
00584   if (child_name)
00585     *child_name = ada_varobj_scalar_image (index_type, real_index);
00586 
00587   if (child_value && parent_value)
00588     ada_varobj_simple_array_elt (parent_value, parent_type, real_index,
00589                                  child_value, NULL);
00590 
00591   if (child_type)
00592     ada_varobj_simple_array_elt (parent_value, parent_type, real_index,
00593                                  NULL, child_type);
00594 
00595   if (child_path_expr)
00596     {
00597       char *index_img = ada_varobj_scalar_image (index_type, real_index);
00598       struct cleanup *cleanups = make_cleanup (xfree, index_img);
00599 
00600       /* Enumeration litterals by themselves are potentially ambiguous.
00601          For instance, consider the following package spec:
00602 
00603             package Pck is
00604                type Color is (Red, Green, Blue, White);
00605                type Blood_Cells is (White, Red);
00606             end Pck;
00607 
00608          In this case, the litteral "red" for instance, or even
00609          the fully-qualified litteral "pck.red" cannot be resolved
00610          by itself.  Type qualification is needed to determine which
00611          enumeration litterals should be used.
00612 
00613          The following variable will be used to contain the name
00614          of the array index type when such type qualification is
00615          needed.  */
00616       const char *index_type_name = NULL;
00617 
00618       /* If the index type is a range type, find the base type.  */
00619       while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
00620         index_type = TYPE_TARGET_TYPE (index_type);
00621 
00622       if (TYPE_CODE (index_type) == TYPE_CODE_ENUM
00623           || TYPE_CODE (index_type) == TYPE_CODE_BOOL)
00624         {
00625           index_type_name = ada_type_name (index_type);
00626           if (index_type_name)
00627             index_type_name = ada_decode (index_type_name);
00628         }
00629 
00630       if (index_type_name != NULL)
00631         *child_path_expr =
00632           xstrprintf ("(%s)(%.*s'(%s))", parent_path_expr,
00633                       ada_name_prefix_len (index_type_name),
00634                       index_type_name, index_img);
00635       else
00636         *child_path_expr =
00637           xstrprintf ("(%s)(%s)", parent_path_expr, index_img);
00638       do_cleanups (cleanups);
00639     }
00640 }
00641 
00642 /* See description at declaration above.  */
00643 
00644 static void
00645 ada_varobj_describe_child (struct value *parent_value,
00646                            struct type *parent_type,
00647                            const char *parent_name,
00648                            const char *parent_path_expr,
00649                            int child_index,
00650                            char **child_name,
00651                            struct value **child_value,
00652                            struct type **child_type,
00653                            char **child_path_expr)
00654 {
00655   /* We cannot compute the child's path expression without
00656      the parent's path expression.  This is a pre-condition
00657      for calling this function.  */
00658   if (child_path_expr)
00659     gdb_assert (parent_path_expr != NULL);
00660 
00661   ada_varobj_decode_var (&parent_value, &parent_type);
00662   ada_varobj_adjust_for_child_access (&parent_value, &parent_type);
00663 
00664   if (child_name)
00665     *child_name = NULL;
00666   if (child_value)
00667     *child_value = NULL;
00668   if (child_type)
00669     *child_type = NULL;
00670   if (child_path_expr)
00671     *child_path_expr = NULL;
00672 
00673   if (ada_is_array_descriptor_type (parent_type)
00674       && TYPE_CODE (parent_type) == TYPE_CODE_TYPEDEF)
00675     {
00676       ada_varobj_describe_ptr_child (parent_value, parent_type,
00677                                      parent_name, parent_path_expr,
00678                                      child_index, child_name,
00679                                      child_value, child_type,
00680                                      child_path_expr);
00681       return;
00682     }
00683 
00684   if (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY)
00685     {
00686       ada_varobj_describe_simple_array_child
00687         (parent_value, parent_type, parent_name, parent_path_expr,
00688          child_index, child_name, child_value, child_type,
00689          child_path_expr);
00690       return;
00691     }
00692 
00693   if (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT)
00694     {
00695       ada_varobj_describe_struct_child (parent_value, parent_type,
00696                                         parent_name, parent_path_expr,
00697                                         child_index, child_name,
00698                                         child_value, child_type,
00699                                         child_path_expr);
00700       return;
00701     }
00702 
00703   if (TYPE_CODE (parent_type) == TYPE_CODE_PTR)
00704     {
00705       ada_varobj_describe_ptr_child (parent_value, parent_type,
00706                                      parent_name, parent_path_expr,
00707                                      child_index, child_name,
00708                                      child_value, child_type,
00709                                      child_path_expr);
00710       return;
00711     }
00712 
00713   /* It should never happen.  But rather than crash, report dummy names
00714      and return a NULL child_value.  */
00715   if (child_name)
00716     *child_name = xstrdup ("???");
00717 }
00718 
00719 /* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE,
00720    PARENT_TYPE) pair.  PARENT_NAME is the name of the PARENT.
00721 
00722    The result should be deallocated after use with xfree.  */
00723 
00724 char *
00725 ada_varobj_get_name_of_child (struct value *parent_value,
00726                               struct type *parent_type,
00727                               const char *parent_name, int child_index)
00728 {
00729   char *child_name;
00730 
00731   ada_varobj_describe_child (parent_value, parent_type, parent_name,
00732                              NULL, child_index, &child_name, NULL,
00733                              NULL, NULL);
00734   return child_name;
00735 }
00736 
00737 /* Return the path expression of the child number CHILD_INDEX of
00738    the (PARENT_VALUE, PARENT_TYPE) pair.  PARENT_NAME is the name
00739    of the parent, and PARENT_PATH_EXPR is the parent's path expression.
00740    Both must be non-NULL.
00741 
00742    The result must be deallocated after use with xfree.  */
00743 
00744 char *
00745 ada_varobj_get_path_expr_of_child (struct value *parent_value,
00746                                    struct type *parent_type,
00747                                    const char *parent_name,
00748                                    const char *parent_path_expr,
00749                                    int child_index)
00750 {
00751   char *child_path_expr;
00752 
00753   ada_varobj_describe_child (parent_value, parent_type, parent_name,
00754                              parent_path_expr, child_index, NULL,
00755                              NULL, NULL, &child_path_expr);
00756 
00757   return child_path_expr;
00758 }
00759 
00760 /* Return the value of child number CHILD_INDEX of the (PARENT_VALUE,
00761    PARENT_TYPE) pair.  PARENT_NAME is the name of the parent.  */
00762 
00763 struct value *
00764 ada_varobj_get_value_of_child (struct value *parent_value,
00765                                struct type *parent_type,
00766                                const char *parent_name, int child_index)
00767 {
00768   struct value *child_value;
00769 
00770   ada_varobj_describe_child (parent_value, parent_type, parent_name,
00771                              NULL, child_index, NULL, &child_value,
00772                              NULL, NULL);
00773 
00774   return child_value;
00775 }
00776 
00777 /* Return the type of child number CHILD_INDEX of the (PARENT_VALUE,
00778    PARENT_TYPE) pair.  */
00779 
00780 struct type *
00781 ada_varobj_get_type_of_child (struct value *parent_value,
00782                               struct type *parent_type,
00783                               int child_index)
00784 {
00785   struct type *child_type;
00786 
00787   ada_varobj_describe_child (parent_value, parent_type, NULL, NULL,
00788                              child_index, NULL, NULL, &child_type, NULL);
00789 
00790   return child_type;
00791 }
00792 
00793 /* Return a string that contains the image of the given VALUE, using
00794    the print options OPTS as the options for formatting the result.
00795 
00796    The resulting string must be deallocated after use with xfree.  */
00797 
00798 static char *
00799 ada_varobj_get_value_image (struct value *value,
00800                             struct value_print_options *opts)
00801 {
00802   char *result;
00803   struct ui_file *buffer;
00804   struct cleanup *old_chain;
00805 
00806   buffer = mem_fileopen ();
00807   old_chain = make_cleanup_ui_file_delete (buffer);
00808 
00809   common_val_print (value, buffer, 0, opts, current_language);
00810   result = ui_file_xstrdup (buffer, NULL);
00811 
00812   do_cleanups (old_chain);
00813   return result;
00814 }
00815 
00816 /* Assuming that the (VALUE, TYPE) pair designates an array varobj,
00817    return a string that is suitable for use in the "value" field of
00818    the varobj output.  Most of the time, this is the number of elements
00819    in the array inside square brackets, but there are situations where
00820    it's useful to add more info.
00821 
00822    OPTS are the print options used when formatting the result.
00823 
00824    The result should be deallocated after use using xfree.  */
00825 
00826 static char *
00827 ada_varobj_get_value_of_array_variable (struct value *value,
00828                                         struct type *type,
00829                                         struct value_print_options *opts)
00830 {
00831   char *result;
00832   const int numchild = ada_varobj_get_array_number_of_children (value, type);
00833 
00834   /* If we have a string, provide its contents in the "value" field.
00835      Otherwise, the only other way to inspect the contents of the string
00836      is by looking at the value of each element, as in any other array,
00837      which is not very convenient...  */
00838   if (value
00839       && ada_is_string_type (type)
00840       && (opts->format == 0 || opts->format == 's'))
00841     {
00842       char *str;
00843       struct cleanup *old_chain;
00844 
00845       str = ada_varobj_get_value_image (value, opts);
00846       old_chain = make_cleanup (xfree, str);
00847       result = xstrprintf ("[%d] %s", numchild, str);
00848       do_cleanups (old_chain);
00849     }
00850   else
00851     result = xstrprintf ("[%d]", numchild);
00852 
00853   return result;
00854 }
00855 
00856 /* Return a string representation of the (VALUE, TYPE) pair, using
00857    the given print options OPTS as our formatting options.  */
00858 
00859 char *
00860 ada_varobj_get_value_of_variable (struct value *value,
00861                                   struct type *type,
00862                                   struct value_print_options *opts)
00863 {
00864   char *result = NULL;
00865 
00866   ada_varobj_decode_var (&value, &type);
00867 
00868   switch (TYPE_CODE (type))
00869     {
00870     case TYPE_CODE_STRUCT:
00871     case TYPE_CODE_UNION:
00872       result = xstrdup ("{...}");
00873       break;
00874     case TYPE_CODE_ARRAY:
00875       result = ada_varobj_get_value_of_array_variable (value, type, opts);
00876       break;
00877     default:
00878       if (!value)
00879         result = xstrdup ("");
00880       else
00881         result = ada_varobj_get_value_image (value, opts);
00882       break;
00883     }
00884 
00885   return result;
00886 }
00887 
00888 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines