[11/12] Test case

Message ID 53510FB3.1060202@codesourcery.com
State New, archived
Headers

Commit Message

Yao Qi April 18, 2014, 11:42 a.m. UTC
  On 02/14/2014 04:44 PM, Yao Qi wrote:
>  - Remove hard-coded breakpoint number, but it depends on this patch
> 
>   [PATCH] Accept convenience variable in commands -break-passcount and -break-commands
>   https://sourceware.org/ml/gdb-patches/2014-01/msg00936.html

This patch above isn't acceptable as its current shape, so I revert
this patch back to use hard-coded breakpoint number.
  

Comments

Keith Seitz April 24, 2014, 8:53 p.m. UTC | #1
On 04/18/2014 04:42 AM, Yao Qi wrote:
> On 02/14/2014 04:44 PM, Yao Qi wrote:
>>   - Remove hard-coded breakpoint number, but it depends on this patch
>>
>>    [PATCH] Accept convenience variable in commands -break-passcount and -break-commands
>>    https://sourceware.org/ml/gdb-patches/2014-01/msg00936.html
>
> This patch above isn't acceptable as its current shape, so I revert
> this patch back to use hard-coded breakpoint number.
>

Yeah, I apologize for that. Something tells me we should consider 
extending the mi_create_breakpoint API to not only return the breakpoint 
regexp but also the number of the breakpoint that was set. That would 
make things like this quite a bit easier in the future.

I really only have three (related) nits about this patch:

In gdb.trace/mi-available-children-only-cxx.exp:

+mi_gdb_test "-break-insert -a marker" "\\^done.*" \
+    "trace marker"
+

and in gdb.trace/mi-available-children-only.exp:

+mi_gdb_test "-break-insert -a marker1" "\\^done.*" \
+    "trace marker1"

[snip]

+mi_gdb_test "-break-insert -a marker2" "\\^done.*" \
+    "trace marker2"

Please use mi_create_breakpoint unless there is some feature that is not 
supported by that API.

Otherwise, this looks okay. I recommend a maintainer approve with these 
changes.

Keith
  

Patch

diff --git a/gdb/config/djgpp/fnchange.lst b/gdb/config/djgpp/fnchange.lst
index cbf11c6..b94c77e 100644
--- a/gdb/config/djgpp/fnchange.lst
+++ b/gdb/config/djgpp/fnchange.lst
@@ -506,6 +506,10 @@ 
 @V@/gdb/testsuite/gdb.mi/mi2-var-display.exp @V@/gdb/testsuite/gdb.mi/mi2vardisplay.exp
 @V@/gdb/testsuite/gdb.mi/mi-nonstop-exit.exp @V@/gdb/testsuite/gdb.mi/minonstop-exit.exp
 @V@/gdb/testsuite/gdb.mi/non-stop-exit.c @V@/gdb/testsuite/gdb.mi/nonstop-exit.c
+@V@/gdb/testsuite/gdb.trace/available-children-only.c @V@/gdb/testsuite/gdb.trace/availnly.c
+@V@/gdb/testsuite/gdb.trace/mi-available-children-only.exp @V@/gdb/testsuite/gdb.trace/availnly.exp
+@V@/gdb/testsuite/gdb.trace/mi-available-children-only-cxx.exp  @V@/gdb/testsuite/gdb.trace/availcxx.exp
+@V@/gdb/testsuite/gdb.trace/available-children-only.cc @V@/gdb/testsuite/gdb.trace/availcxx.cc
 @V@/gdb/testsuite/gdb.threads/watchthreads2.c @V@/gdb/testsuite/gdb.threads/watchth2.c
 @V@/gdb/testsuite/gdb.threads/watchthreads2.exp @V@/gdb/testsuite/gdb.threads/watchth2.exp
 @V@/gdb/amd64-linux-tdep.c @V@/gdb/amd64-ltdep.c
diff --git a/gdb/testsuite/gdb.trace/available-children-only.c b/gdb/testsuite/gdb.trace/available-children-only.c
new file mode 100644
index 0000000..b13f130
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/available-children-only.c
@@ -0,0 +1,69 @@ 
+/* Copyright 2013-2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Two trace actions are set, and they collect different fields to
+   reproduce the case that children appear in the different orders.  */
+
+struct simple
+{
+  int a; /* Collected by both.  */
+  int b; /* Collected by action 2.  */
+  struct
+  {
+    struct
+    {
+      int g; /* Collected by action 1.  */
+      int h; /* Collected by action 2.  */
+    } s3;
+    int d; /* Collected by action 1.  */
+  } s1;
+
+  struct
+  {
+    int e;
+    int f; /* Collected by action 1.  */
+  } s2;
+};
+
+struct simple s;
+
+static void
+marker1 (void)
+{
+}
+
+static void
+marker2 (void)
+{
+}
+
+static void
+end (void)
+{
+}
+
+int
+main (void)
+{
+  marker1 ();
+
+  marker2 ();
+
+  end ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.trace/available-children-only.cc b/gdb/testsuite/gdb.trace/available-children-only.cc
new file mode 100644
index 0000000..f9f06e7
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/available-children-only.cc
@@ -0,0 +1,45 @@ 
+/* Copyright 2013-2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+class Fake
+{
+ private:
+  int pri1; /* Collected.  */
+
+ public:
+  int pub1;
+
+};
+
+Fake fake;
+
+static void
+marker (void)
+{}
+
+static void
+end (void)
+{}
+
+int
+main (void)
+{
+  marker ();
+
+  end ();
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.trace/mi-available-children-only-cxx.exp b/gdb/testsuite/gdb.trace/mi-available-children-only-cxx.exp
new file mode 100644
index 0000000..cc6b0f2
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/mi-available-children-only-cxx.exp
@@ -0,0 +1,126 @@ 
+# Copyright 2013-2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test for C++ fake children.
+
+load_lib mi-support.exp
+load_lib trace-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile available-children-only.cc
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+	   executable {debug c++}] != "" } {
+    untested "Couldn't compile ${srcfile}"
+    return -1
+}
+
+# Test target supports tracepoints or not.
+
+clean_restart $testfile
+
+if { ![runto_main] } {
+    fail "Can't run to main to check for trace support"
+    return -1
+}
+
+if { ![gdb_target_supports_trace] } {
+    unsupported "Current target does not support trace"
+    return -1
+}
+gdb_exit
+
+if { [mi_gdb_start] } {
+    continue
+}
+
+mi_run_to_main
+
+mi_gdb_test "-break-insert -a marker" "\\^done.*" \
+    "trace marker"
+
+mi_gdb_test "-break-commands 2 \"collect fake.pri1\" \"end\" " \
+    {\^done} "set action on marker"
+
+mi_gdb_test "-trace-start" ".*\\^done.*" "trace start"
+mi_continue_to end
+mi_gdb_test "-trace-stop" "\\^done.*" "trace stop"
+# Save trace frames to trace file.
+set tracefile [standard_output_file ${testfile}]
+mi_gdb_test "-trace-save ${tracefile}.tfile" \
+    ".*" \
+    "save tfile trace"
+
+# In live target, '--available-children-only' shouldn't have any
+# effects.
+
+mi_gdb_test "-trace-find frame-number 0" \
+    ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \
+    "-trace-find frame-number 0"
+
+mi_gdb_test "-var-create --available-children-only fake @ fake" \
+    {\^done,name="fake",numchild="0",value=".*",type="Fake",dynamic="1",has_more="1"} \
+    "-var-create --available-children-only fake"
+
+mi_list_varobj_children { fake --available-children-only } {
+    { fake.public public 0 }
+    { fake.private private 0 }
+} "-var-list-children --available-children-only fake"
+
+mi_gdb_test "-var-info-num-children --available-children-only fake" \
+    "\\^done,numchild=\"2\"" \
+    "-var-info-num-children --available-children-only fake"
+
+mi_gdb_test "-var-delete fake" {\^done,ndeleted="3"} "-var-delete fake"
+
+# Select a traceframe, and '--available-children-only' have some
+# effects.
+
+proc check_with_traceframe { } {
+    global decimal
+
+    with_test_prefix "w/ setting traceframe" {
+	mi_gdb_test "-trace-find frame-number 0" \
+	    ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \
+	    "-trace-find frame-number 0"
+
+	mi_gdb_test "-var-create --available-children-only fake @ fake" \
+	    {\^done,name="fake",numchild="0",value=".*",type="Fake",dynamic="1",has_more="1"} \
+	    "-var-create --available-children-only fake"
+
+	mi_list_varobj_children "fake" {
+	    { fake.public public 1 }
+	    { fake.private private 1 }
+	} "-var-list-children fake"
+
+	mi_gdb_test "-var-info-num-children fake" \
+	    "\\^done,numchild=\"2\"" "-var-info-num-children fake"
+
+	mi_list_varobj_children {"fake" "--available-children-only" } {
+	    { fake.public public 0 }
+	    { fake.private private 0 }
+	} "-var-list-children --available-children-only fake"
+
+	mi_gdb_test "-var-info-num-children --available-children-only fake" \
+	    "\\^done,numchild=\"2\"" \
+	    "-var-info-num-children --available-children-only fake"
+
+	mi_gdb_test "-var-delete fake" {\^done,ndeleted="3"} "-var-delete fake"
+    }
+    mi_gdb_test "-trace-find none" ".*\\^done,found=\"0\".*" \
+	"-trace-find none"
+}
+
+check_with_traceframe
diff --git a/gdb/testsuite/gdb.trace/mi-available-children-only.exp b/gdb/testsuite/gdb.trace/mi-available-children-only.exp
new file mode 100644
index 0000000..247c32c
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/mi-available-children-only.exp
@@ -0,0 +1,198 @@ 
+# Copyright 2013-2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+load_lib mi-support.exp
+load_lib trace-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile available-children-only.c
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    untested mi-available-children-only.exp
+    return -1
+}
+
+# Test target supports tracepoints or not.
+
+clean_restart $testfile
+
+if { ![runto_main] } {
+    fail "Can't run to main to check for trace support"
+    return -1
+}
+
+if { ![gdb_target_supports_trace] } {
+    unsupported "Current target does not support trace"
+    return -1
+}
+gdb_exit
+
+if { [mi_gdb_start] } {
+    continue
+}
+
+mi_run_to_main
+mi_gdb_test "-break-insert -a marker1" "\\^done.*" \
+    "trace marker1"
+
+mi_gdb_test "-break-commands 2 \"collect s.a\" \"collect s.s1.d\" \"collect s.s1.s3.g\" \"collect s.s2.f\" \"end\" " \
+    {\^done} "set action on marker1"
+
+mi_gdb_test "-break-insert -a marker2" "\\^done.*" \
+    "trace marker2"
+
+mi_gdb_test "-break-commands 3 \"collect s.a\" \"collect s.b\" \"collect s.s1.s3.h\" \"end\" " \
+    {\^done} "set action on marker2"
+
+mi_gdb_test "-trace-start" ".*\\^done.*" "trace start"
+mi_continue_to end
+mi_gdb_test "-trace-stop" "\\^done.*" "trace stop"
+
+# Save trace frames to trace file.
+set tracefile [standard_output_file ${testfile}]
+mi_gdb_test "-trace-save ${tracefile}.tfile" \
+    ".*" \
+    "save tfile trace"
+
+# In live target, '--available-children-only' shouldn't have any
+# effects.
+mi_gdb_test "-var-create --available-children-only s1 @ s" \
+    {\^done,name="s1",numchild="0",value=".*",type="struct simple",dynamic="1",has_more="1"} \
+    "-var-create --available-children-only s1"
+
+mi_list_varobj_children  { "s1" "--available-children-only" } {
+    { s1.a a 0 int }
+    { s1.b b 0 int }
+    { s1.s1 s1 0 "struct \\{\\.\\.\\.\\}" }
+    { s1.s2 s2 0 "struct \\{\\.\\.\\.\\}" }
+} "-var-list-children --available-children-only s1"
+
+mi_gdb_test "-var-info-num-children --available-children-only s1" \
+    "\\^done,numchild=\"4\"" \
+    "-var-info-num-children --available-children-only s1"
+
+mi_gdb_test "-var-delete s1" {\^done,ndeleted="5"} "-var-delete s1"
+
+# Select a traceframe, and '--available-children-only' have some
+# effects.
+
+proc check_with_traceframe { } {
+    global decimal
+
+    mi_gdb_test "-trace-find frame-number 0" \
+	".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \
+	"-trace-find frame-number 0"
+
+    with_test_prefix "traceframe 0" {
+	mi_gdb_test "-var-create --available-children-only s2 @ s" \
+	    {\^done,name="s2",numchild="0",value=".*",type="struct simple",dynamic="1",has_more="1"} \
+	    "-var-create --available-children-only s2"
+
+	mi_gdb_test "-var-list-children s2" \
+	    "\\^done,numchild=\"4\",.*,has_more=\"0\"" \
+	    "-var-list-children s2"
+
+	mi_gdb_test "-var-info-num-children s2" \
+	    "\\^done,numchild=\"4\"" \
+	    "-var-info-num-children s2"
+
+	# "s2" should have children "a", "s1" and "s2".
+	mi_list_varobj_children  { "s2" "--available-children-only" } {
+	    { s2.a a 0 int }
+	    { s2.s1 s1 0 "struct \\{\\.\\.\\.\\}" }
+	    { s2.s2 s2 0 "struct \\{\\.\\.\\.\\}" }
+	} "-var-list-children --available-children-only s2"
+
+	mi_gdb_test "-var-info-num-children --available-children-only s2" \
+	    "\\^done,numchild=\"3\"" \
+	    "-var-info-num-children --available-children-only s2"
+
+	mi_list_varobj_children  { "s2.s1" "--available-children-only" } {
+	    { s2.s1.s3 s3 0 "struct \\{\\.\\.\\.\\}" }
+	    { s2.s1.d d 0 int }
+	} "-var-list-children --available-children-only s2.s1"
+
+    }
+
+    mi_gdb_test "-trace-find frame-number 1" \
+	".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"1\",frame=\{.*" \
+	"-trace-find frame-number 1"
+
+    with_test_prefix "traceframe 1" {
+	mi_list_varobj_children  { "s2" "--available-children-only" } {
+	    { s2.a a 0 int }
+	    { s2.b b 0 int }
+	    { s2.s1 s1 0 "struct \\{\\.\\.\\.\\}" }
+	} "-var-list-children --available-children-only s2"
+
+	mi_list_varobj_children  { "s2.s1" "--available-children-only" } {
+	    { s2.s1.s3 s3 0 "struct \\{\\.\\.\\.\\}" }
+	} "-var-list-children --available-children-only s2.s1"
+
+	mi_list_varobj_children  { "s2.s1.s3" "--available-children-only" } {
+	    { s2.s1.s3.h h 0 int }
+	} "-var-list-children --available-children-only s2.s1.s3"
+
+	mi_gdb_test "-var-info-num-children --available-children-only s2" \
+	    "\\^done,numchild=\"3\"" \
+	    "-var-info-num-children --available-children-only s2"
+
+	mi_gdb_test "-var-delete s2" {\^done,ndeleted="6"} "-var-delete s2"
+    }
+
+    mi_gdb_test "-trace-find none" ".*\\^done,found=\"0\".*" \
+	"-trace-find none"
+}
+
+check_with_traceframe
+
+# Test when changing target from remote to ${target}.
+
+proc test_from_remote { target } {
+    global mi_gdb_prompt decimal
+    global tracefile
+
+    with_test_prefix "remote to ${target}" {
+	# Change target to ${target}.
+	mi_gdb_test "-target-select ${target} ${tracefile}.${target}" ".*\\^connected.*" \
+	    "change target to ${target}"
+
+	with_test_prefix "w/ setting traceframe" {
+	    check_with_traceframe
+	}
+    }
+}
+
+test_from_remote "tfile"
+
+proc test_from_exec { target } {
+    global binfile
+    global tracefile
+
+    mi_gdb_exit
+    if [mi_gdb_start] {
+	return
+    }
+    mi_gdb_load ${binfile}
+
+    with_test_prefix "exec to ${target}" {
+	mi_gdb_test "-target-select ${target} ${tracefile}.${target}" ".*\\^connected.*" \
+	    "change target to ${target}"
+
+	check_with_traceframe
+    }
+}
+
+test_from_exec "tfile"