diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2014-07-07 19:22:36 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2014-07-09 14:47:47 +0100 |
commit | 9a9a76082919371f4ceb571f6c9892325b80a2e0 (patch) | |
tree | e788e3f67d885134568beab88af41739fe89fe22 /gdb/testsuite/gdb.mi/mi2-var-child.exp | |
parent | e051745c838bf29e564fb2665339f97c8383b9e8 (diff) | |
download | gdb-9a9a76082919371f4ceb571f6c9892325b80a2e0.zip gdb-9a9a76082919371f4ceb571f6c9892325b80a2e0.tar.gz gdb-9a9a76082919371f4ceb571f6c9892325b80a2e0.tar.bz2 |
Improve MI -var-info-path-expression for nested struct/union case.
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.
Diffstat (limited to 'gdb/testsuite/gdb.mi/mi2-var-child.exp')
-rw-r--r-- | gdb/testsuite/gdb.mi/mi2-var-child.exp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.mi/mi2-var-child.exp b/gdb/testsuite/gdb.mi/mi2-var-child.exp index f992a63..fc02066 100644 --- a/gdb/testsuite/gdb.mi/mi2-var-child.exp +++ b/gdb/testsuite/gdb.mi/mi2-var-child.exp @@ -1163,6 +1163,13 @@ mi_create_breakpoint \ "$srcfile:$lineno" "break in do_anonymous_type_tests" \ -disp keep -func do_anonymous_type_tests \ -file ".*var-cmd.c" -line $lineno + +set lineno [gdb_get_line_number "nested struct union tests breakpoint"] +mi_create_breakpoint \ + "$srcfile:$lineno" "break in do_nested_struct_union_tests" \ + -disp keep -func do_nested_struct_union_tests \ + -file ".*var-cmd.c" -line $lineno + mi_execute_to "exec-continue" "breakpoint-hit" "do_anonymous_type_tests" ""\ ".*" ".*" {"" "disp=\"keep\""} \ "continue to do_anonymous_type_tests breakpoint" @@ -1236,5 +1243,74 @@ set tree { mi_walk_varobj_tree c $tree verify_everything +mi_send_resuming_command "exec-continue" \ + "continuing execution to enter do_nested_struct_union_tests" +mi_expect_stop "breakpoint-hit" "do_nested_struct_union_tests" ".*" ".*" ".*" \ + {.* disp="keep"} "Run till MI stops in do_nested_struct_union_tests" + +set struct_ss_tree { + {struct s_a} a1 { + int a {} + } + {struct s_b} b1 { + int b {} + } + {union u_ab} u1 { + {struct s_a} a { + int a {} + } + {struct s_b} b { + int b {} + } + } + anonymous union { + {struct s_a} a2 { + int a {} + } + {struct s_b} b2 { + int b {} + } + } + {union {...}} u2 { + {struct s_a} a3 { + int a {} + } + {struct s_b} b3 { + int b {} + } + } + } + +set tree " + {struct ss} var { + $struct_ss_tree + } +" + +mi_walk_varobj_tree c $tree verify_everything + +set tree { + {struct {...}} var2 { + {td_u_ab} ab { + {td_s_a} a { + int a {} + } + {td_s_b} b { + int b {} + } + } + } +} + +mi_walk_varobj_tree c $tree verify_everything + +set tree " + {struct ss *} ss_ptr { + $struct_ss_tree + } +" + +mi_walk_varobj_tree c $tree verify_everything + mi_gdb_exit return 0 |