old-cross-binutils/gdb/testsuite/gdb.mi
Andrew Burgess 9a9a760829 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.
2014-07-09 14:47:47 +01:00
..
array.f
basics.c
ChangeLog-1999-2003
dw2-ref-missing-frame-func.c
dw2-ref-missing-frame-main.c
dw2-ref-missing-frame.exp
dw2-ref-missing-frame.S
gdb669.exp
gdb680.exp
gdb701.c
gdb701.exp
gdb792.cc
gdb792.exp
gdb2549.exp
Makefile.in
mi-async.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-basics.exp
mi-break.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-breakpoint-changed.exp PR mi/15806: Fix quoting of async events 2014-06-05 17:59:46 -04:00
mi-catch-load-so.c
mi-catch-load.c
mi-catch-load.exp
mi-cli.exp PR gdb/13860 - Make MI sync vs async output (closer to) the same. 2014-05-29 13:09:45 +01:00
mi-cmd-param-changed.exp
mi-condbreak-call-thr-state-mt.c PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-condbreak-call-thr-state-st.c PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-condbreak-call-thr-state.c PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-condbreak-call-thr-state.exp PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-console.c
mi-console.exp
mi-disassemble.exp
mi-dprintf.c
mi-dprintf.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-eval.exp
mi-file-transfer.exp
mi-file.exp Fix mi-file.exp fails on remote host 2014-05-14 20:11:53 +08:00
mi-fill-memory.exp
mi-fullname-deleted.exp
mi-hack-cli.exp
mi-i-cmd.exp
mi-info-os.exp gdb.mi/mi-info-os.exp: Fix cross-debugger testing 2014-01-09 19:57:13 +00:00
mi-inheritance-syntax-error.cc
mi-inheritance-syntax-error.exp
mi-language.exp
mi-logging.exp
mi-memory-changed.exp
mi-nonstop-exit.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nonstop.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-ns-stale-regcache.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nsintrall.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nsmoribund.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nsthrexec.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-pending.c
mi-pending.exp
mi-pendshr.c
mi-pthreads.exp
mi-read-memory.c
mi-read-memory.exp
mi-record-changed.exp
mi-reg-undefined.c
mi-reg-undefined.exp
mi-reg-undefined.S
mi-regs.exp
mi-return.exp
mi-reverse.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-simplerun.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-solib.exp PR gdb/13860: don't lose '-interpreter-exec console EXECUTION_COMMAND''s output in async mode. 2014-05-21 23:17:23 +01:00
mi-stack.c
mi-stack.exp
mi-start.c
mi-start.exp
mi-stepi.exp
mi-stepn.c
mi-stepn.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-syn-frame.c
mi-syn-frame.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-undefined-cmd.exp
mi-until.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-var-block.exp
mi-var-child-f.exp
mi-var-child.c
mi-var-child.exp
mi-var-cmd.exp Fix for PR mi/15863 2014-06-16 11:38:19 -07:00
mi-var-cp.cc
mi-var-cp.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-var-create-rtti.c
mi-var-create-rtti.exp
mi-var-display.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-var-invalidate.exp
mi-var-rtti.cc In a couple functions (type_update_when_use_rtti_test and 2014-06-17 10:42:23 +01:00
mi-var-rtti.exp
mi-vla-c99.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-watch-nonstop.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-watch.exp
mi2-amd64-entry-value.c
mi2-amd64-entry-value.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi2-amd64-entry-value.s
mi2-prompt.exp
mi2-var-child.exp Improve MI -var-info-path-expression for nested struct/union case. 2014-07-09 14:47:47 +01:00
non-stop-exit.c
non-stop.c Add return value for non-void function return statements to fix error in clang build. 2014-04-14 08:34:51 -07:00
ns-stale-regcache.c
nsintrall.c
nsmoribund.c
nsthrexec.c
pending.c
pendshr1.c
pendshr2.c
pr11022.c
pr11022.exp
pthreads.c
solib-lib.c
solib-main.c
testcmds
until.c
var-cmd.c Improve MI -var-info-path-expression for nested struct/union case. 2014-07-09 14:47:47 +01:00
vla.c test: add mi vla test 2014-04-14 09:52:11 -07:00
watch-nonstop.c