Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: gdb/ada-varobj.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/ada-varobj.h ('k') | gdb/addrmap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* varobj support for Ada. 1 /* varobj support for Ada.
2 2
3 Copyright (C) 2012 Free Software Foundation, Inc. 3 Copyright (C) 2012-2013 Free Software Foundation, Inc.
4 4
5 This file is part of GDB. 5 This file is part of GDB.
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or 9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 19
20 #include "defs.h" 20 #include "defs.h"
21 #include "ada-varobj.h"
22 #include "ada-lang.h" 21 #include "ada-lang.h"
22 #include "varobj.h"
23 #include "language.h" 23 #include "language.h"
24 #include "valprint.h" 24 #include "valprint.h"
25 25
26 /* Implementation principle used in this unit: 26 /* Implementation principle used in this unit:
27 27
28 For our purposes, the meat of the varobj object is made of two 28 For our purposes, the meat of the varobj object is made of two
29 elements: The varobj's (struct) value, and the varobj's (struct) 29 elements: The varobj's (struct) value, and the varobj's (struct)
30 type. In most situations, the varobj has a non-NULL value, and 30 type. In most situations, the varobj has a non-NULL value, and
31 the type becomes redundant, as it can be directly derived from 31 the type becomes redundant, as it can be directly derived from
32 the value. In the initial implementation of this unit, most 32 the value. In the initial implementation of this unit, most
33 routines would only take a value, and return a value. 33 routines would only take a value, and return a value.
34 34
35 But there are many situations where it is possible for a varobj 35 But there are many situations where it is possible for a varobj
36 to have a NULL value. For instance, if the varobj becomes out of 36 to have a NULL value. For instance, if the varobj becomes out of
37 scope. Or better yet, when the varobj is the child of another 37 scope. Or better yet, when the varobj is the child of another
38 NULL pointer varobj. In that situation, we must rely on the type 38 NULL pointer varobj. In that situation, we must rely on the type
39 instead of the value to create the child varobj. 39 instead of the value to create the child varobj.
40 40
41 That's why most functions below work with a (value, type) pair. 41 That's why most functions below work with a (value, type) pair.
42 The value may or may not be NULL. But the type is always expected 42 The value may or may not be NULL. But the type is always expected
43 to be set. When the value is NULL, then we work with the type 43 to be set. When the value is NULL, then we work with the type
44 alone, and keep the value NULL. But when the value is not NULL, 44 alone, and keep the value NULL. But when the value is not NULL,
45 then we work using the value, because it provides more information. 45 then we work using the value, because it provides more information.
46 But we still always set the type as well, even if that type could 46 But we still always set the type as well, even if that type could
47 easily be derived from the value. The reason behind this is that 47 easily be derived from the value. The reason behind this is that
48 it allows the code to use the type without having to worry about 48 it allows the code to use the type without having to worry about
49 it being set or not. It makes the code clearer. */ 49 it being set or not. It makes the code clearer. */
50 50
51 static int ada_varobj_get_number_of_children (struct value *parent_value,
52 struct type *parent_type);
53
51 /* A convenience function that decodes the VALUE_PTR/TYPE_PTR couple: 54 /* A convenience function that decodes the VALUE_PTR/TYPE_PTR couple:
52 If there is a value (*VALUE_PTR not NULL), then perform the decoding 55 If there is a value (*VALUE_PTR not NULL), then perform the decoding
53 using it, and compute the associated type from the resulting value. 56 using it, and compute the associated type from the resulting value.
54 Otherwise, compute a static approximation of *TYPE_PTR, leaving 57 Otherwise, compute a static approximation of *TYPE_PTR, leaving
55 *VALUE_PTR unchanged. 58 *VALUE_PTR unchanged.
56 59
57 The results are written in place. */ 60 The results are written in place. */
58 61
59 static void 62 static void
60 ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr) 63 ada_varobj_decode_var (struct value **value_ptr, struct type **type_ptr)
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 || TYPE_CODE (child_type) == TYPE_CODE_VOID) 319 || TYPE_CODE (child_type) == TYPE_CODE_VOID)
317 return 0; 320 return 0;
318 321
319 /* All other types have 1 child. */ 322 /* All other types have 1 child. */
320 return 1; 323 return 1;
321 } 324 }
322 325
323 /* Return the number of children for the (PARENT_VALUE, PARENT_TYPE) 326 /* Return the number of children for the (PARENT_VALUE, PARENT_TYPE)
324 pair. */ 327 pair. */
325 328
326 int 329 static int
327 ada_varobj_get_number_of_children (struct value *parent_value, 330 ada_varobj_get_number_of_children (struct value *parent_value,
328 struct type *parent_type) 331 struct type *parent_type)
329 { 332 {
330 ada_varobj_decode_var (&parent_value, &parent_type); 333 ada_varobj_decode_var (&parent_value, &parent_type);
331 ada_varobj_adjust_for_child_access (&parent_value, &parent_type); 334 ada_varobj_adjust_for_child_access (&parent_value, &parent_type);
332 335
333 /* A typedef to an array descriptor in fact represents a pointer 336 /* A typedef to an array descriptor in fact represents a pointer
334 to an unconstrained array. These types always have one child 337 to an unconstrained array. These types always have one child
335 (the unconstrained array). */ 338 (the unconstrained array). */
336 if (ada_is_array_descriptor_type (parent_type) 339 if (ada_is_array_descriptor_type (parent_type)
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 and return a NULL child_value. */ 717 and return a NULL child_value. */
715 if (child_name) 718 if (child_name)
716 *child_name = xstrdup ("???"); 719 *child_name = xstrdup ("???");
717 } 720 }
718 721
719 /* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE, 722 /* Return the name of the child number CHILD_INDEX of the (PARENT_VALUE,
720 PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT. 723 PARENT_TYPE) pair. PARENT_NAME is the name of the PARENT.
721 724
722 The result should be deallocated after use with xfree. */ 725 The result should be deallocated after use with xfree. */
723 726
724 char * 727 static char *
725 ada_varobj_get_name_of_child (struct value *parent_value, 728 ada_varobj_get_name_of_child (struct value *parent_value,
726 struct type *parent_type, 729 struct type *parent_type,
727 const char *parent_name, int child_index) 730 const char *parent_name, int child_index)
728 { 731 {
729 char *child_name; 732 char *child_name;
730 733
731 ada_varobj_describe_child (parent_value, parent_type, parent_name, 734 ada_varobj_describe_child (parent_value, parent_type, parent_name,
732 NULL, child_index, &child_name, NULL, 735 NULL, child_index, &child_name, NULL,
733 NULL, NULL); 736 NULL, NULL);
734 return child_name; 737 return child_name;
735 } 738 }
736 739
737 /* Return the path expression of the child number CHILD_INDEX of 740 /* Return the path expression of the child number CHILD_INDEX of
738 the (PARENT_VALUE, PARENT_TYPE) pair. PARENT_NAME is the name 741 the (PARENT_VALUE, PARENT_TYPE) pair. PARENT_NAME is the name
739 of the parent, and PARENT_PATH_EXPR is the parent's path expression. 742 of the parent, and PARENT_PATH_EXPR is the parent's path expression.
740 Both must be non-NULL. 743 Both must be non-NULL.
741 744
742 The result must be deallocated after use with xfree. */ 745 The result must be deallocated after use with xfree. */
743 746
744 char * 747 static char *
745 ada_varobj_get_path_expr_of_child (struct value *parent_value, 748 ada_varobj_get_path_expr_of_child (struct value *parent_value,
746 struct type *parent_type, 749 struct type *parent_type,
747 const char *parent_name, 750 const char *parent_name,
748 const char *parent_path_expr, 751 const char *parent_path_expr,
749 int child_index) 752 int child_index)
750 { 753 {
751 char *child_path_expr; 754 char *child_path_expr;
752 755
753 ada_varobj_describe_child (parent_value, parent_type, parent_name, 756 ada_varobj_describe_child (parent_value, parent_type, parent_name,
754 parent_path_expr, child_index, NULL, 757 parent_path_expr, child_index, NULL,
755 NULL, NULL, &child_path_expr); 758 NULL, NULL, &child_path_expr);
756 759
757 return child_path_expr; 760 return child_path_expr;
758 } 761 }
759 762
760 /* Return the value of child number CHILD_INDEX of the (PARENT_VALUE, 763 /* Return the value of child number CHILD_INDEX of the (PARENT_VALUE,
761 PARENT_TYPE) pair. PARENT_NAME is the name of the parent. */ 764 PARENT_TYPE) pair. PARENT_NAME is the name of the parent. */
762 765
763 struct value * 766 static struct value *
764 ada_varobj_get_value_of_child (struct value *parent_value, 767 ada_varobj_get_value_of_child (struct value *parent_value,
765 struct type *parent_type, 768 struct type *parent_type,
766 const char *parent_name, int child_index) 769 const char *parent_name, int child_index)
767 { 770 {
768 struct value *child_value; 771 struct value *child_value;
769 772
770 ada_varobj_describe_child (parent_value, parent_type, parent_name, 773 ada_varobj_describe_child (parent_value, parent_type, parent_name,
771 NULL, child_index, NULL, &child_value, 774 NULL, child_index, NULL, &child_value,
772 NULL, NULL); 775 NULL, NULL);
773 776
774 return child_value; 777 return child_value;
775 } 778 }
776 779
777 /* Return the type of child number CHILD_INDEX of the (PARENT_VALUE, 780 /* Return the type of child number CHILD_INDEX of the (PARENT_VALUE,
778 PARENT_TYPE) pair. */ 781 PARENT_TYPE) pair. */
779 782
780 struct type * 783 static struct type *
781 ada_varobj_get_type_of_child (struct value *parent_value, 784 ada_varobj_get_type_of_child (struct value *parent_value,
782 struct type *parent_type, 785 struct type *parent_type,
783 int child_index) 786 int child_index)
784 { 787 {
785 struct type *child_type; 788 struct type *child_type;
786 789
787 ada_varobj_describe_child (parent_value, parent_type, NULL, NULL, 790 ada_varobj_describe_child (parent_value, parent_type, NULL, NULL,
788 child_index, NULL, NULL, &child_type, NULL); 791 child_index, NULL, NULL, &child_type, NULL);
789 792
790 return child_type; 793 return child_type;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 } 852 }
850 else 853 else
851 result = xstrprintf ("[%d]", numchild); 854 result = xstrprintf ("[%d]", numchild);
852 855
853 return result; 856 return result;
854 } 857 }
855 858
856 /* Return a string representation of the (VALUE, TYPE) pair, using 859 /* Return a string representation of the (VALUE, TYPE) pair, using
857 the given print options OPTS as our formatting options. */ 860 the given print options OPTS as our formatting options. */
858 861
859 char * 862 static char *
860 ada_varobj_get_value_of_variable (struct value *value, 863 ada_varobj_get_value_of_variable (struct value *value,
861 struct type *type, 864 struct type *type,
862 struct value_print_options *opts) 865 struct value_print_options *opts)
863 { 866 {
864 char *result = NULL; 867 char *result = NULL;
865 868
866 ada_varobj_decode_var (&value, &type); 869 ada_varobj_decode_var (&value, &type);
867 870
868 switch (TYPE_CODE (type)) 871 switch (TYPE_CODE (type))
869 { 872 {
870 case TYPE_CODE_STRUCT: 873 case TYPE_CODE_STRUCT:
871 case TYPE_CODE_UNION: 874 case TYPE_CODE_UNION:
872 result = xstrdup ("{...}"); 875 result = xstrdup ("{...}");
873 break; 876 break;
874 case TYPE_CODE_ARRAY: 877 case TYPE_CODE_ARRAY:
875 result = ada_varobj_get_value_of_array_variable (value, type, opts); 878 result = ada_varobj_get_value_of_array_variable (value, type, opts);
876 break; 879 break;
877 default: 880 default:
878 if (!value) 881 if (!value)
879 result = xstrdup (""); 882 result = xstrdup ("");
880 else 883 else
881 result = ada_varobj_get_value_image (value, opts); 884 result = ada_varobj_get_value_image (value, opts);
882 break; 885 break;
883 } 886 }
884 887
885 return result; 888 return result;
886 } 889 }
887 890
891 /* Ada specific callbacks for VAROBJs. */
888 892
893 static int
894 ada_number_of_children (struct varobj *var)
895 {
896 return ada_varobj_get_number_of_children (var->value, var->type);
897 }
898
899 static char *
900 ada_name_of_variable (struct varobj *parent)
901 {
902 return c_varobj_ops.name_of_variable (parent);
903 }
904
905 static char *
906 ada_name_of_child (struct varobj *parent, int index)
907 {
908 return ada_varobj_get_name_of_child (parent->value, parent->type,
909 parent->name, index);
910 }
911
912 static char*
913 ada_path_expr_of_child (struct varobj *child)
914 {
915 struct varobj *parent = child->parent;
916 const char *parent_path_expr = varobj_get_path_expr (parent);
917
918 return ada_varobj_get_path_expr_of_child (parent->value,
919 parent->type,
920 parent->name,
921 parent_path_expr,
922 child->index);
923 }
924
925 static struct value *
926 ada_value_of_child (struct varobj *parent, int index)
927 {
928 return ada_varobj_get_value_of_child (parent->value, parent->type,
929 parent->name, index);
930 }
931
932 static struct type *
933 ada_type_of_child (struct varobj *parent, int index)
934 {
935 return ada_varobj_get_type_of_child (parent->value, parent->type,
936 index);
937 }
938
939 static char *
940 ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
941 {
942 struct value_print_options opts;
943
944 varobj_formatted_print_options (&opts, format);
945
946 return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
947 }
948
949 /* Implement the "value_is_changeable_p" routine for Ada. */
950
951 static int
952 ada_value_is_changeable_p (struct varobj *var)
953 {
954 struct type *type = var->value ? value_type (var->value) : var->type;
955
956 if (ada_is_array_descriptor_type (type)
957 && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
958 {
959 /* This is in reality a pointer to an unconstrained array.
960 its value is changeable. */
961 return 1;
962 }
963
964 if (ada_is_string_type (type))
965 {
966 /* We display the contents of the string in the array's
967 "value" field. The contents can change, so consider
968 that the array is changeable. */
969 return 1;
970 }
971
972 return varobj_default_value_is_changeable_p (var);
973 }
974
975 /* Implement the "value_has_mutated" routine for Ada. */
976
977 static int
978 ada_value_has_mutated (struct varobj *var, struct value *new_val,
979 struct type *new_type)
980 {
981 int i;
982 int from = -1;
983 int to = -1;
984
985 /* If the number of fields have changed, then for sure the type
986 has mutated. */
987 if (ada_varobj_get_number_of_children (new_val, new_type)
988 != var->num_children)
989 return 1;
990
991 /* If the number of fields have remained the same, then we need
992 to check the name of each field. If they remain the same,
993 then chances are the type hasn't mutated. This is technically
994 an incomplete test, as the child's type might have changed
995 despite the fact that the name remains the same. But we'll
996 handle this situation by saying that the child has mutated,
997 not this value.
998
999 If only part (or none!) of the children have been fetched,
1000 then only check the ones we fetched. It does not matter
1001 to the frontend whether a child that it has not fetched yet
1002 has mutated or not. So just assume it hasn't. */
1003
1004 varobj_restrict_range (var->children, &from, &to);
1005 for (i = from; i < to; i++)
1006 if (strcmp (ada_varobj_get_name_of_child (new_val, new_type,
1007 var->name, i),
1008 VEC_index (varobj_p, var->children, i)->name) != 0)
1009 return 1;
1010
1011 return 0;
1012 }
1013
1014 /* varobj operations for ada. */
1015
1016 const struct lang_varobj_ops ada_varobj_ops =
1017 {
1018 ada_number_of_children,
1019 ada_name_of_variable,
1020 ada_name_of_child,
1021 ada_path_expr_of_child,
1022 ada_value_of_child,
1023 ada_type_of_child,
1024 ada_value_of_variable,
1025 ada_value_is_changeable_p,
1026 ada_value_has_mutated
1027 };
OLDNEW
« no previous file with comments | « gdb/ada-varobj.h ('k') | gdb/addrmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698