To make it clear that some functions should not modify the variable
object, this patch adds the const qualifier where it makes sense to some
struct varobj * parameters. Most getters should take a const pointer to
guarantee they don't modify the object.
Unfortunately, I couldn't add it to some callbacks (such as name_of_child).
In the C implementation, they call c_describe_child, which calls
varobj_get_path_expr. varobj_get_path_expr needs to modify the object in
order to cache the computed value. It therefore can't take a const
pointer, and it affects the whole call chain. I suppose that's where you
would use a "mutable" in C++.
I did that to make sure there was no other cases like the one fixed in
the previous patch. I don't think it can hurt.
gdb/ChangeLog:
* ada-varobj.c (ada_number_of_children): Constify struct varobj *
parameter.
(ada_name_of_variable): Same.
(ada_path_expr_of_child): Same.
(ada_value_of_variable): Same.
(ada_value_is_changeable_p): Same.
(ada_value_has_mutated): Same.
* c-varobj.c (varobj_is_anonymous_child): Same.
(c_is_path_expr_parent): Same.
(c_number_of_children): Same.
(c_name_of_variable): Same.
(c_path_expr_of_child): Same.
(get_type): Same.
(c_value_of_variable): Same.
(cplus_number_of_children): Same.
(cplus_name_of_variable): Same.
(cplus_path_expr_of_child): Same.
(cplus_value_of_variable): Same.
* jv-varobj.c (java_number_of_children): Same.
(java_name_of_variable): Same.
(java_path_expr_of_child): Same.
(java_value_of_variable): Same.
* varobj.c (number_of_children): Same.
(name_of_variable): Same.
(is_root_p): Same.
(varobj_ensure_python_env): Same.
(varobj_get_objname): Same.
(varobj_get_expression): Same.
(varobj_get_display_format): Same.
(varobj_get_display_hint): Same.
(varobj_has_more): Same.
(varobj_get_thread_id): Same.
(varobj_get_frozen): Same.
(dynamic_varobj_has_child_method): Same.
(varobj_get_gdb_type): Same.
(is_path_expr_parent): Same.
(varobj_default_is_path_expr_parent): Same.
(varobj_get_language): Same.
(varobj_get_attributes): Same.
(varobj_is_dynamic_p): Same.
(varobj_get_child_range): Same.
(varobj_value_has_mutated): Same.
(varobj_get_value_type): Same.
(number_of_children): Same.
(name_of_variable): Same.
(check_scope): Same.
(varobj_editable_p): Same.
(varobj_value_is_changeable_p): Same.
(varobj_floating_p): Same.
(varobj_default_value_is_changeable_p): Same.
* varobj.h (struct lang_varobj_ops): Consitfy some struct varobj *
parameters.
(varobj_get_objname): Constify struct varobj * parameter.
(varobj_get_expression): Same.
(varobj_get_thread_id): Same.
(varobj_get_frozen): Same.
(varobj_get_child_range): Same.
(varobj_get_display_hint): Same.
(varobj_get_gdb_type): Same.
(varobj_get_language): Same.
(varobj_get_attributes): Same.
(varobj_editable_p): Same.
(varobj_floating_p): Same.
(varobj_has_more): Same.
(varobj_is_dynamic_p): Same.
(varobj_ensure_python_env): Same.
(varobj_default_value_is_changeable_p): Same.
(varobj_value_is_changeable_p): Same.
(varobj_get_value_type): Same.
(varobj_is_anonymous_child): Same.
(varobj_value_get_print_value): Same.
(varobj_default_is_path_expr_parent): Same.
This is preparation work to avoid a regression in the Ada/varobj.
An upcoming patch is going to add support for types in DWARF
which have dynamic properties whose value is a reference to another
DIE.
Consider for instance the following declaration:
type Variant_Type (N : Int := 0) is record
F : String(1 .. N) := (others => 'x');
end record;
type Variant_Type_Access is access all Variant_Type;
VTA : Variant_Type_Access := null;
This declares a variable "VTA" which is an access (=pointer)
to a variant record Variant_Type. This record contains two
components, the first being "N" (the discriminant), and the
second being "F", an array whose lower bound is 1, and whose
upper bound depends on the value of "N" (the discriminant).
Of interest to us, here, is that second component ("F"), and
in particular its bounds. The debugging info, and in particular
the info for the array looks like the following...
.uleb128 0x9 # (DIE (0x91) DW_TAG_array_type)
.long .LASF16 # DW_AT_name: "bar__variant_type__T2b"
.long 0xac # DW_AT_GNAT_descriptive_type
.long 0x2cb # DW_AT_type
.long 0xac # DW_AT_sibling
.uleb128 0xa # (DIE (0xa2) DW_TAG_subrange_type)
.long 0xc4 # DW_AT_type
.long 0x87 # DW_AT_upper_bound
.byte 0 # end of children of DIE 0x91
... where the upper bound of the array's subrange type is a reference
to "n"'s DIE (0x87):
.uleb128 0x8 # (DIE (0x87) DW_TAG_member)
.ascii "n\0" # DW_AT_name
[...]
Once the patch to handle this dynamic property gets applied,
this is what happens when creating a varobj for variable "VTA"
(whose value is null), and then trying to list its children:
(gdb)
-var-create vta * vta
^done,name="vta",numchild="2",value="0x0",
type="bar.variant_type_access",has_more="0"
(gdb)
-var-list-children 1 vta
^done,numchild="2",
children=[child={name="vta.n",[...]},
child={name="vta.f",exp="f",
numchild="43877616", <<<<-----
value="[43877616]", <<<<-----
type="array (1 .. n) of character"}],
has_more="0"
It has an odd number of children.
In this case, we cannot really determine the number of children,
since that number depends on the value of a field in a record
for which we do not have a value. Up to now, the value we've been
displaying is zero - meaning we have an empty array.
What happens in this case, is that, because the VTA is a null pointer,
we're not able to resolve the pointer's target type, and therefore
end up asking ada_varobj_get_array_number_of_children to return
the number of elements in that array; for that, it relies blindly
on get_array_bounds, which assumes the type is no longer dynamic,
and therefore the reads the bound without seeing that it's value
is actually a reference rather than a resolved constant.
This patch prevents the issue by explicitly handling the case of
dynamic arrays, and returning zero child in that case.
gdb/ChangeLog:
* ada-varobj.c (ada_varobj_get_array_number_of_children):
Return zero if PARENT_VALUE is NULL and parent_type's
range type is dynamic.
gdb/testsuite/ChangeLog:
* gdb.ada/mi_var_array: New testcase.
Tested on x86_64-linux.
https://sourceware.org/ml/gdb-patches/2014-05/msg00383.html
The MI command -var-info-path-expression currently does not handle
non-anonymous structs / unions nested within other structs / unions,
it will skip parts of the expression. Consider this example:
## START EXAMPLE ##
$ cat ex.c
#include <string.h>
int
main ()
{
struct s1
{
int a;
};
struct ss
{
struct s1 x;
};
struct ss an_ss;
memset (&an_ss, 0, sizeof (an_ss));
return 0;
}
$ gcc -g -o ex.x ex.c
$ gdb ex.x
(gdb) break 18
Breakpoint 1 at 0x80483ba: file ex.c, line 18.
(gdb) run
Starting program: /home/user/ex.x
Breakpoint 1, main () at ex.c:18
18 return 0;
(gdb) interpreter-exec mi "-var-create an_ss * an_ss"
(gdb) interpreter-exec mi "-var-list-children an_ss"
^done,numchild="1",children=[child={name="an_ss.x",exp="x",numchild="1",type="struct s1",thread-id="1"}],has_more="0"
(gdb) interpreter-exec mi "-var-list-children an_ss.x"
^done,numchild="1",children=[child={name="an_ss.x.a",exp="a",numchild="0",type="int",thread-id="1"}],has_more="0"
(gdb) interpreter-exec mi "-var-list-children an_ss.x.a"
^done,numchild="0",has_more="0"
(gdb) interpreter-exec mi "-var-info-path-expression an_ss.x.a"
^done,path_expr="(an_ss).a"
(gdb) print (an_ss).a
There is no member named a.
## END EXAMPLE ##
Notice that the path expression returned is wrong, and as a result
the print command fails.
This patch adds a new method to the varobj_ops structure called
is_path_expr_parent, to allow language specific control over finding
the parent varobj, the current logic becomes the C/C++ version and is
extended to handle the nested cases. No other language currently uses
this code, so all other languages just get a default method.
With this patch, the above example now finishes like this:
## START EXAMPLE ##
$ gdb ex.x
(gdb) break 18
Breakpoint 1 at 0x80483ba: file ex.c, line 18.
(gdb) run
Starting program: /home/user/ex.x
Breakpoint 1, main () at ex.c:18
18 return 0;
(gdb) interpreter-exec mi "-var-list-children an_ss"
^done,numchild="1",children=[child={name="an_ss.x",exp="x",numchild="1",type="struct s1",thread-id="1"}],has_more="0"
(gdb) interpreter-exec mi "-var-list-children an_ss.x"
^done,numchild="1",children=[child={name="an_ss.x.a",exp="a",numchild="0",type="int",thread-id="1"}],has_more="0"
(gdb) interpreter-exec mi "-var-list-children an_ss.x.a"
^done,numchild="0",has_more="0"
(gdb) interpreter-exec mi "-var-info-path-expression an_ss.x.a"
^done,path_expr="((an_ss).x).a"
(gdb) print ((an_ss).x).a
$1 = 0
## END EXAMPLE ##
Notice that the path expression is now correct, and the print is a
success.
gdb/ChangeLog:
* ada-varobj.c (ada_varobj_ops): Fill in is_path_expr_parent
field.
* c-varobj.c (c_is_path_expr_parent): New function, moved core
from varobj.c, with additional checks.
(c_varobj_ops): Fill in is_path_expr_parent field.
(cplus_varobj_ops): Fill in is_path_expr_parent field.
* jv-varobj.c (java_varobj_ops): Fill in is_path_expr_parent
field.
* varobj.c (is_path_expr_parent): Call is_path_expr_parent varobj
ops method.
(varobj_default_is_path_expr_parent): New function.
* varobj.h (lang_varobj_ops): Add is_path_expr_parent field.
(varobj_default_is_path_expr_parent): Declare new function.
gdb/testsuite/ChangeLog:
* gdb.mi/var-cmd.c (do_nested_struct_union_tests): New function
setting up test structures.
(main): Call new test function.
* gdb.mi/mi2-var-child.exp: Create additional breakpoint in new
test function, continue into test function and walk test
structures.
ada-varobj.c::ada_varobj_describe_simple_array_child only ever gets
called after all GNAT encodings have been applied to (parent_value,
parent_type). So there is no point in redoing it partially by
checking for parallel XA types again.
gdb/ChangeLog:
* ada-varobj.c (ada_varobj_describe_simple_array_child): Remove
handling of parallel ___XA types.
Consider the following code:
type Element is abstract tagged null record;
type GADataType is interface;
type Data_Type is new Element and GADataType with record
I : Integer := 42;
end record;
Result1 : Data_Type;
GGG1 : GADataType'Class := GADataType'Class (Result1);
When trying to create a varobj for variable ggg1, GDB currently
returns an object which has no child:
-var-create ggg1 * ggg1
^done,name="ggg1",numchild="0",[...]
This is incorrect, it should return an object which has one child
(field "i"). This is because tagged-type objects are dynamic, and
we need to apply a small transformation in order to get their actual
type. This is already done on the GDB/CLI side in ada-valprint,
and it needs to be done on the ada-varobj side as well.
gdb/ChangeLog:
* ada-varobj.c (ada_varobj_adjust_for_child_access): Convert
tagged type objects to their actual type.
gdb/testsuite/ChangeLog:
* gdb.ada/mi_interface: New testcase.
As a result of previous patch, extern functions in ada-varobj.c can be
made static, and ada-varobj.h can be removed too.
gdb:
2013-10-17 Yao Qi <yao@codesourcery.com>
* Makefile.in (HFILES_NO_SRCDIR): Remove ada-varobj.h.
* ada-varobj.c: Remove the include of ada-varobj.h.
(ada_varobj_get_number_of_children): Declare.
(ada_varobj_get_name_of_child): Make it static.
(ada_varobj_get_path_expr_of_child): Likewise.
(ada_varobj_get_value_of_child): Likewise.
(ada_varobj_get_type_of_child): Likewise.
(ada_varobj_get_value_of_array_variable): Likewise.
* ada-varobj.h: Remove.
Two modifications:
1. The addition of 2013 to the copyright year range for every file;
2. The use of a single year range, instead of potentially multiple
year ranges, as approved by the FSF.
This patch adds varobj support for Ada variables. Most of the code
is implemented in a separate Ada-specific file called ada-varobj.c.
The only bits in varobj.c are the functions used as the hooks in
the language-specific varobj's vector.
gdb/ChangeLog:
* ada-varobj.h, ada-varobj.c: New files.
* Makefile.in (SFILES): Add ada-varobj.c.
(HFILES_NO_SRCDIR): Add ada-varobj.h.
(COMMON_OBS): Add ada-varobj.o.