public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Move traceframe checking out of traceframe generation
  2014-04-28  6:15 [PATCH 0/4 V2] Partially available/unavailable data in requested range Yao Qi
  2014-04-28  6:15 ` [PATCH 3/4] Save traceframes in trace file and read data out from trace file Yao Qi
  2014-04-28  6:15 ` [PATCH 2/4] Show new created display Yao Qi
@ 2014-04-28  6:15 ` Yao Qi
  2014-04-30 16:15   ` Pedro Alves
  2014-04-28  6:15 ` [PATCH 4/4] Partially available/unavailable data in requested range Yao Qi
  3 siblings, 1 reply; 10+ messages in thread
From: Yao Qi @ 2014-04-28  6:15 UTC (permalink / raw)
  To: gdb-patches

This patch moves traceframe checking code out of traceframe generation,
so that we can generation traceframe once, and do the checking in multiple
times (with target remote, tfile and ctf respectively).  This is a
pure refactor, not functional changes in unavailable.exp.

gdb/testsuite:

2014-04-26  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/unavailable.exp (gdb_collect_args_test): Move some
	code to ...
	(gdb_collect_args_test_1): ... it.  New proc.
	(gdb_collect_locals_test): Move some code to ...
	(gdb_collect_locals_test_1): ... it.  New proc.
	(gdb_unavailable_registers_test): Move some code to ...
	(gdb_unavailable_registers_test_1): ... it.  New proc.
	(gdb_unavailable_floats): Move some code to ...
	(gdb_unavailable_floats_1): ... it.  New proc.
---
 gdb/testsuite/gdb.trace/unavailable.exp | 618 +++++++++++++++++---------------
 1 file changed, 320 insertions(+), 298 deletions(-)

diff --git a/gdb/testsuite/gdb.trace/unavailable.exp b/gdb/testsuite/gdb.trace/unavailable.exp
index 589cd77..d76b54d 100644
--- a/gdb/testsuite/gdb.trace/unavailable.exp
+++ b/gdb/testsuite/gdb.trace/unavailable.exp
@@ -133,67 +133,72 @@ proc test_maybe_regvar_display { var } {
 # Test procs
 #
 
-proc gdb_collect_args_test {} {
-    with_test_prefix "unavailable arguments" {
-	global cr
-	global gdb_prompt
+proc gdb_collect_args_test_1 {} {
+    global cr
 
-	prepare_for_trace_test
+    # Test printing the variables, and also their addresses.  We
+    # haven't collected any stack, so there's no way GDB can figure
+    # out the latter.
 
-	gdb_test "trace args_test_func" \
-	    "Tracepoint \[0-9\]+ at .*" \
-	    "set tracepoint"
+    gdb_test "print argc" " = <unavailable>"
+    gdb_test "print &argc" \
+	"Can't take address of \"argc\" which isn't an lvalue\."
 
-	# Begin the test.
-	run_trace_experiment args_test_func
+    gdb_test "print argi" " = <unavailable>"
+    gdb_test "print &argi" \
+	"Can't take address of \"argi\" which isn't an lvalue\."
 
-	# Test printing the variables, and also their addresses.  We
-	# haven't collected any stack, so there's no way GDB can figure
-	# out the latter.
+    gdb_test "print argf" " = <unavailable>"
+    gdb_test "print &argf" \
+	"Can't take address of \"argf\" which isn't an lvalue\."
 
-	gdb_test "print argc" " = <unavailable>"
-	gdb_test "print &argc" \
-	    "Can't take address of \"argc\" which isn't an lvalue\."
+    gdb_test "print argd" " = <unavailable>"
+    gdb_test "print &argd" \
+	"Can't take address of \"argd\" which isn't an lvalue\."
 
-	gdb_test "print argi" " = <unavailable>"
-	gdb_test "print &argi" \
-	    "Can't take address of \"argi\" which isn't an lvalue\."
+    # struct arg as one of several args (near end of list)
 
-	gdb_test "print argf" " = <unavailable>"
-	gdb_test "print &argf" \
-	    "Can't take address of \"argf\" which isn't an lvalue\."
+    gdb_test "print argstruct" " = <unavailable>"
 
-	gdb_test "print argd" " = <unavailable>"
-	gdb_test "print &argd" \
-	    "Can't take address of \"argd\" which isn't an lvalue\."
+    gdb_test "print argstruct.memberc" " = <unavailable>"
+    gdb_test "print argstruct.memberi" " = <unavailable>"
+    gdb_test "print argstruct.memberf" " = <unavailable>"
+    gdb_test "print argstruct.memberd" " = <unavailable>"
 
-	# struct arg as one of several args (near end of list)
+    gdb_test "print argarray" " = <unavailable>"
 
-	gdb_test "print argstruct" " = <unavailable>"
+    gdb_test "print &argarray" \
+	"Can't take address of \"argarray\" which isn't an lvalue\."
 
-	gdb_test "print argstruct.memberc" " = <unavailable>"
-	gdb_test "print argstruct.memberi" " = <unavailable>"
-	gdb_test "print argstruct.memberf" " = <unavailable>"
-	gdb_test "print argstruct.memberd" " = <unavailable>"
+    gdb_test "print argarray\[0\]" "value is not available"
 
-	gdb_test "print argarray" " = <unavailable>"
+    # Test "info args"
+    set r ""
+    set r "${r}argc = <unavailable>${cr}"
+    set r "${r}argi = <unavailable>${cr}"
+    set r "${r}argf = <unavailable>${cr}"
+    set r "${r}argd = <unavailable>${cr}"
+    set r "${r}argstruct = <unavailable>${cr}"
+    set r "${r}argarray = <unavailable>${cr}"
+    gdb_test "info args" "$r" "info args"
 
-	gdb_test "print &argarray" \
-	    "Can't take address of \"argarray\" which isn't an lvalue\."
+    test_maybe_regvar_display "argc"
+}
 
-	gdb_test "print argarray\[0\]" "value is not available"
+proc gdb_collect_args_test {} {
+    with_test_prefix "unavailable arguments" {
+	global gdb_prompt
 
-	# Test "info args"
-	set r ""
-	set r "${r}argc = <unavailable>${cr}"
-	set r "${r}argi = <unavailable>${cr}"
-	set r "${r}argf = <unavailable>${cr}"
-	set r "${r}argd = <unavailable>${cr}"
-	set r "${r}argstruct = <unavailable>${cr}"
-	set r "${r}argarray = <unavailable>${cr}"
-	gdb_test "info args" "$r" "info args"
+	prepare_for_trace_test
 
-	test_maybe_regvar_display "argc"
+	gdb_test "trace args_test_func" \
+	    "Tracepoint \[0-9\]+ at .*" \
+	    "set tracepoint"
+
+	# Begin the test.
+	run_trace_experiment args_test_func
+
+	gdb_collect_args_test_1
 
 	gdb_test "tfind none" \
 	    "#0  end .*" \
@@ -201,9 +206,43 @@ proc gdb_collect_args_test {} {
     }
 }
 
+proc gdb_collect_locals_test_1 { func } {
+    global cr
+
+    gdb_test "print locc" " = <unavailable>"
+    gdb_test "print loci" " = <unavailable>"
+    gdb_test "print locf" " = <unavailable>"
+    gdb_test "print locd" " = <unavailable>"
+
+    gdb_test "print locst.memberc" " = <unavailable>"
+    gdb_test "print locst.memberi" " = <unavailable>"
+    gdb_test "print locst.memberf" " = <unavailable>"
+    gdb_test "print locst.memberd" " = <unavailable>"
+
+    gdb_test "print locar\[0\]" " = <unavailable>"
+    gdb_test "print locar\[1\]" " = <unavailable>"
+    gdb_test "print locar\[2\]" " = <unavailable>"
+    gdb_test "print locar\[3\]" " = <unavailable>"
+
+    # Test "info locals"
+    set r ""
+    set r "${r}locf = <unavailable>${cr}"
+    set r "${r}locd = <unavailable>${cr}"
+    set r "${r}locst = <unavailable>${cr}"
+    set r "${r}locar = <unavailable>${cr}"
+    set r "${r}i = <unavailable>${cr}"
+    if { $func == "local_test_func" } {
+	set r "${r}locdefst = <unavailable>${cr}"
+    }
+    set r "${r}locc = <unavailable>${cr}"
+    set r "${r}loci = <unavailable>${cr}"
+    gdb_test "info locals" "$r" "info locals"
+
+    test_maybe_regvar_display "loci"
+}
+
 proc gdb_collect_locals_test { func msg } {
     with_test_prefix "unavailable locals: $msg" {
-	global cr
 	global gdb_prompt
 
 	prepare_for_trace_test
@@ -217,36 +256,7 @@ proc gdb_collect_locals_test { func msg } {
 	# Begin the test.
 	run_trace_experiment $func
 
-	gdb_test "print locc" " = <unavailable>"
-	gdb_test "print loci" " = <unavailable>"
-	gdb_test "print locf" " = <unavailable>"
-	gdb_test "print locd" " = <unavailable>"
-
-	gdb_test "print locst.memberc" " = <unavailable>"
-	gdb_test "print locst.memberi" " = <unavailable>"
-	gdb_test "print locst.memberf" " = <unavailable>"
-	gdb_test "print locst.memberd" " = <unavailable>"
-
-	gdb_test "print locar\[0\]" " = <unavailable>"
-	gdb_test "print locar\[1\]" " = <unavailable>"
-	gdb_test "print locar\[2\]" " = <unavailable>"
-	gdb_test "print locar\[3\]" " = <unavailable>"
-
-	# Test "info locals"
-	set r ""
-	set r "${r}locf = <unavailable>${cr}"
-	set r "${r}locd = <unavailable>${cr}"
-	set r "${r}locst = <unavailable>${cr}"
-	set r "${r}locar = <unavailable>${cr}"
-	set r "${r}i = <unavailable>${cr}"
-	if { $func == "local_test_func" } {
-	    set r "${r}locdefst = <unavailable>${cr}"
-	}
-	set r "${r}locc = <unavailable>${cr}"
-	set r "${r}loci = <unavailable>${cr}"
-	gdb_test "info locals" "$r" "info locals"
-
-	test_maybe_regvar_display "loci"
+	gdb_collect_locals_test_1 $func
 
 	gdb_test "tfind none" \
 	    "#0  end .*" \
@@ -254,11 +264,44 @@ proc gdb_collect_locals_test { func msg } {
     }
 }
 
+proc gdb_unavailable_registers_test_1 { } {
+    global spreg
+    global pcreg
+
+    # On some archs, the $sp/$pc are a real raw registers.  On others,
+    # like x86, they're user registers.  Test both variants.
+    test_register_unavailable "\$$spreg"
+    test_register_unavailable "\$sp"
+
+    # Test reading uncollected pseudo-registers.  The set of which
+    # depends on target.
+    if [is_amd64_regs_target] {
+	# Check the raw register first.
+	test_register_unavailable "\$rax"
+	test_register_unavailable "\$eax"
+	test_register_unavailable "\$ax"
+    } elseif [is_x86_like_target] {
+	# Check the raw register first.
+	test_register_unavailable "\$eax"
+	test_register_unavailable "\$ax"
+    }
+
+    # GDBserver always provides the PC value of regular tracepoint
+    # hits, since it's the same as the tracepoint's address.
+    test_register "\$$pcreg"
+    test_register "\$pc"
+
+    gdb_test "info registers" \
+	"<unavailable>.*<unavailable>" \
+	"info registers, multiple registers not available"
+
+    gdb_test "info registers \$$spreg" \
+	"<unavailable>" \
+	"info registers \$$spreg reports not available"
+}
+
 proc gdb_unavailable_registers_test { } {
     with_test_prefix "unavailable registers" {
-	global gdb_prompt
-	global spreg
-	global pcreg
 
 	prepare_for_trace_test
 
@@ -272,44 +315,30 @@ proc gdb_unavailable_registers_test { } {
 	# Begin the test.
 	run_trace_experiment globals_test_func
 
-	# On some archs, the $sp/$pc are a real raw registers.  On others,
-	# like x86, they're user registers.  Test both variants.
-	test_register_unavailable "\$$spreg"
-	test_register_unavailable "\$sp"
-
-	# Test reading uncollected pseudo-registers.  The set of which
-	# depends on target.
-	if [is_amd64_regs_target] {
-	    # Check the raw register first.
-	    test_register_unavailable "\$rax"
-	    test_register_unavailable "\$eax"
-	    test_register_unavailable "\$ax"
-	} elseif [is_x86_like_target] {
-	    # Check the raw register first.
-	    test_register_unavailable "\$eax"
-	    test_register_unavailable "\$ax"
-	}
-
-	# GDBserver always provides the PC value of regular tracepoint
-	# hits, since it's the same as the tracepoint's address.
-	test_register "\$$pcreg"
-	test_register "\$pc"
-
-	gdb_test "info registers" \
-	    "<unavailable>.*<unavailable>" \
-	    "info registers, multiple registers not available"
-
-	gdb_test "info registers \$$spreg" \
-	    "<unavailable>" \
-	    "info registers \$$spreg reports not available"
+	gdb_unavailable_registers_test_1
 
 	gdb_test "tfind none" "#0  end .*" "cease trace debugging"
     }
 }
 
-proc gdb_unavailable_floats { } {
+proc gdb_unavailable_floats_1 { } {
     global gdb_prompt
 
+    # Necessarily target specific.
+    if {[istarget "x86_64-*-*"] || [istarget i?86-*]} {
+	send_gdb "info float\n"
+	gdb_expect_list "info float" ".*$gdb_prompt $" {
+	    "Status Word:         <unavailable>"
+	    "Control Word:        <unavailable>"
+	    "Tag Word:            <unavailable>"
+	    "Instruction Pointer: <unavailable>:<unavailable>"
+	    "Operand Pointer:     <unavailable>:<unavailable>"
+	    "Opcode:              <unavailable>"
+	}
+    }
+}
+
+proc gdb_unavailable_floats { } {
     with_test_prefix "unavailable floats" {
 	prepare_for_trace_test
 
@@ -323,253 +352,246 @@ proc gdb_unavailable_floats { } {
 	# Begin the test.
 	run_trace_experiment globals_test_func
 
-	# Necessarily target specific.
-	if {[istarget "x86_64-*-*"] || [istarget i?86-*]} {
-	    send_gdb "info float\n"
-	    gdb_expect_list "info float" ".*$gdb_prompt $" {
-		"Status Word:         <unavailable>"
-		"Control Word:        <unavailable>"
-		"Tag Word:            <unavailable>"
-		"Instruction Pointer: <unavailable>:<unavailable>"
-		"Operand Pointer:     <unavailable>:<unavailable>"
-		"Opcode:              <unavailable>"
-	    }
-	}
+	gdb_unavailable_floats_1
 
 	gdb_test "tfind none" "#0  end .*" "cease trace debugging"
     }
 }
 
-proc gdb_collect_globals_test { } {
-    with_test_prefix "collect globals" {
-	global ws
-	global cr
-	global gdb_prompt
-	global hex
+proc gdb_collect_globals_test_1 { } {
+    global ws
+    global cr
+    global gdb_prompt
+    global hex
 
-	prepare_for_trace_test
+    gdb_test "print globalc" " = <unavailable>"
+    gdb_test "print globali" " = <unavailable>"
+    gdb_test "print globalf" " = <unavailable>"
+    gdb_test "print globald" " = <unavailable>"
 
-	set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
+    gdb_test "print globalstruct.memberc" " = <unavailable>"
+    gdb_test "print globalstruct.memberi" " = <unavailable>"
+    gdb_test "print globalstruct.memberf" " = <unavailable>"
+    gdb_test "print globalstruct.memberd" " = <unavailable>"
 
-	gdb_test "trace $testline" \
-	    "Tracepoint \[0-9\]+ at .*" \
-	    "set tracepoint"
+    gdb_test "print globalstruct" " = <unavailable>"
 
-	# We collect the initial sizeof(pointer) bytes of derived_partial
-	# in an attempt of collecting the vptr.  Not portable, but should
-	# work everywhere we need to care.
-	gdb_trace_setactions "define actions" \
-	    "" \
-	    "collect struct_b.struct_a.array\[2\]" "^$" \
-	    "collect struct_b.struct_a.array\[100\]" "^$" \
-	    \
-	    "collect a" "^$" \
-	    "collect c" "^$" \
-	    \
-	    "collect tarray\[0\].a" "^$" \
-	    "collect tarray\[1\].a" "^$" \
-	    "collect tarray\[3\].a" "^$" \
-	    "collect tarray\[3\].b" "^$" \
-	    "collect tarray\[4\].b" "^$" \
-	    "collect tarray\[5\].b" "^$" \
-	    \
-	    "collect g_string_p" "^$" \
-	    "collect g_string_partial\[1\]" "^$" \
-	    "collect g_string_partial\[2\]" "^$" \
-	    \
-	    "collect g_structref_p" "^$" \
-	    \
-	    "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
-	    "collect derived_whole" "^$" \
-	    \
-	    "collect virtual_partial.z" "^$"
+    gdb_test "print globalp == &globalstruct" \
+	"value is not available" \
+	"can't compare using non collected global pointer"
 
-	# Begin the test.
-	run_trace_experiment globals_test_func
+    gdb_test "print globalarr\[1\]" " = <unavailable>"
+    gdb_test "print globalarr\[2\]" " = <unavailable>"
+    gdb_test "print globalarr\[3\]" " = <unavailable>"
 
-	gdb_test "print globalc" " = <unavailable>"
-	gdb_test "print globali" " = <unavailable>"
-	gdb_test "print globalf" " = <unavailable>"
-	gdb_test "print globald" " = <unavailable>"
+    gdb_test "print struct_b" \
+	" = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}, string = <unavailable>}"
 
-	gdb_test "print globalstruct.memberc" " = <unavailable>"
-	gdb_test "print globalstruct.memberi" " = <unavailable>"
-	gdb_test "print globalstruct.memberf" " = <unavailable>"
-	gdb_test "print globalstruct.memberd" " = <unavailable>"
+    gdb_test "print /x struct_b" \
+	" = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}, string = <unavailable>}"
 
-	gdb_test "print globalstruct" " = <unavailable>"
+    gdb_test "print /x struct_b.struct_a" \
+	" = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
 
-	gdb_test "print globalp == &globalstruct" \
-	    "value is not available" \
-	    "can't compare using non collected global pointer"
+    gdb_test "print /x struct_b.struct_a.array" \
+	" = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
 
-	gdb_test "print globalarr\[1\]" " = <unavailable>"
-	gdb_test "print globalarr\[2\]" " = <unavailable>"
-	gdb_test "print globalarr\[3\]" " = <unavailable>"
+    gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
 
-	gdb_test "print struct_b" \
-	    " = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}, string = <unavailable>}"
+    gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
 
-	gdb_test "print /x struct_b" \
-	    " = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}, string = <unavailable>}"
+    # Check the target doesn't overcollect.  GDB used to merge memory
+    # ranges to collect if they were close enough (collecting the hole
+    # as well), but does not do that anymore.  It's plausible that a
+    # target may do this on its end, but as of this writing, no known
+    # target does it.
+    gdb_test "print {a, b, c}" \
+	" = \\{1, <unavailable>, 3\\}" \
+	"No overcollect of almost but not quite adjacent memory ranges"
 
-	gdb_test "print /x struct_b.struct_a" \
-	    " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
+    # Check <unavailable> isn't confused with 0 in array element repetitions
 
-	gdb_test "print /x struct_b.struct_a.array" \
-	    " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
+    gdb_test_no_output "set print repeat 1"
 
-	gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
+    gdb_test "print /x tarray" \
+	" = \{\{a = 0x0, b = <unavailable>\} <repeats 2 times>, \{a = <unavailable>, b = <unavailable>\}, \{a = 0x0, b = 0x0\}, \{a = <unavailable>, b = 0x0\} <repeats 2 times>, \{a = <unavailable>, b = <unavailable>\} <repeats 2 times>\}" \
+	"<unavailable> is not the same as 0 in array element repetitions"
 
-	gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
+    gdb_test_no_output "set print repeat 10"
 
-	# Check the target doesn't overcollect.  GDB used to merge memory
-	# ranges to collect if they were close enough (collecting the hole
-	# as well), but does not do that anymore.  It's plausible that a
-	# target may do this on its end, but as of this writing, no known
-	# target does it.
-	gdb_test "print {a, b, c}" \
-	    " = \\{1, <unavailable>, 3\\}" \
-	    "No overcollect of almost but not quite adjacent memory ranges"
+    # Check that value repeat handles unavailable-ness.
+    gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
 
-	# Check <unavailable> isn't confused with 0 in array element repetitions
+    # Static fields
 
-	gdb_test_no_output "set print repeat 1"
+    gdb_test "print struct_b.static_struct_a" " = <unavailable>"
 
-	gdb_test "print /x tarray" \
-	    " = \{\{a = 0x0, b = <unavailable>\} <repeats 2 times>, \{a = <unavailable>, b = <unavailable>\}, \{a = 0x0, b = 0x0\}, \{a = <unavailable>, b = 0x0\} <repeats 2 times>, \{a = <unavailable>, b = <unavailable>\} <repeats 2 times>\}" \
-	    "<unavailable> is not the same as 0 in array element repetitions"
+    # Bitfields
 
-	gdb_test_no_output "set print repeat 10"
+    gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
 
-	# Check that value repeat handles unavailable-ness.
-	gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
+    # References
 
-	# Static fields
+    gdb_test "print g_int" " = <unavailable>"
 
-	gdb_test "print struct_b.static_struct_a" " = <unavailable>"
+    gdb_test "print g_ref" \
+	"\\(int &\\) @$hex: <unavailable>" \
+	"global reference shows address but not value"
 
-	# Bitfields
+    gdb_test "print *&g_ref" \
+	"\\$\[0-9\]+ = <unavailable>$cr" \
+	"referenced integer was not collected (taking address of reference)"
 
-	gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
+    gdb_test "print *g_structref_p" " = <unavailable>"
 
-	# References
+    # Strings
 
-	gdb_test "print g_int" " = <unavailable>"
+    # Const string is always available, even when not collected.
+    gdb_test "print g_const_string" \
+	" = \"hello world\"$cr" \
+	"non collected const string is still printable"
 
-	gdb_test "print g_ref" \
-	    "\\(int &\\) @$hex: <unavailable>" \
-	    "global reference shows address but not value"
+    gdb_test "print g_string_p" \
+	" = $hex <g_const_string> \"hello world\"" \
+	"printing constant string through collected pointer"
 
-	gdb_test "print *&g_ref" \
-	    "\\$\[0-9\]+ = <unavailable>$cr" \
-	    "referenced integer was not collected (taking address of reference)"
+    gdb_test "print g_string_unavail" \
+	" = <unavailable>" \
+	"printing non collected string"
 
-	gdb_test "print *g_structref_p" " = <unavailable>"
+    # Incomplete strings print as an array.
+    gdb_test "print g_string_partial" \
+	"\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
+	"printing partially collected string"
 
-	# Strings
+    # It is important for this test that the last examined value is
+    # <unavailable>, to exercise the case of the $__ convenience
+    # variable being set to <unavailable> without error.
+    set msg "examining partially collected object"
+    gdb_test_multiple "x /10x &struct_b" "$msg" {
+	-re "$hex <struct_b>:${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>$cr$hex <struct_b\\+16>:${ws}<unavailable>${ws}<unavailable>${ws}0xaaaaaaaa${ws}<unavailable>$cr$hex <struct_b\\+32>:${ws}<unavailable>${ws}<unavailable>$cr$gdb_prompt $" {
+	    pass "$msg"
+	}
+	-re "value is not available" {
+	    fail "$msg"
+	}
+    }
 
-	# Const string is always available, even when not collected.
-	gdb_test "print g_const_string" \
-	    " = \"hello world\"$cr" \
-	    "non collected const string is still printable"
+    gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
 
-	gdb_test "print g_string_p" \
-	    " = $hex <g_const_string> \"hello world\"" \
-	    "printing constant string through collected pointer"
+    # This tests that building the array does not require accessing
+    # g_int's contents.
+    gdb_test "print { 1, g_int, 3 }" \
+	" = \\{1, <unavailable>, 3\\}" \
+	"build array from unavailable value"
 
-	gdb_test "print g_string_unavail" \
-	    " = <unavailable>" \
-	    "printing non collected string"
+    # Note, depends on previous test.
+    gdb_test "print \$\[1\]" \
+	" = <unavailable>" \
+	"subscript a non-memory rvalue array, accessing an unvailable element"
 
-	# Incomplete strings print as an array.
-	gdb_test "print g_string_partial" \
-	    "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
-	    "printing partially collected string"
+    # Access a field of a non-lazy value, making sure the
+    # unavailable-ness is propagated.  History values are easy
+    # non-lazy values, so use those.  The first test just sets up for
+    # the second.
+    gdb_test "print g_smallstruct" " = <unavailable>"
+    gdb_test "print \$.member" " = <unavailable>"
 
-	# It is important for this test that the last examined value is
-	# <unavailable>, to exercise the case of the $__ convenience
-	# variable being set to <unavailable> without error.
-	set msg "examining partially collected object"
-	gdb_test_multiple "x /10x &struct_b" "$msg" {
-	    -re "$hex <struct_b>:${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>$cr$hex <struct_b\\+16>:${ws}<unavailable>${ws}<unavailable>${ws}0xaaaaaaaa${ws}<unavailable>$cr$hex <struct_b\\+32>:${ws}<unavailable>${ws}<unavailable>$cr$gdb_prompt $" {
-		pass "$msg"
-	    }
-	    -re "value is not available" {
-		fail "$msg"
-	    }
-	}
+    # Cast to baseclass, checking the unavailable-ness is propagated.
+    gdb_test "print (small_struct) g_smallstruct_b" " = <unavailable>"
 
-	gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
+    # Same cast, but starting from a non-lazy, value.
+    gdb_test "print g_smallstruct_b" " = <unavailable>"
+    gdb_test "print (small_struct) \$" " = <unavailable>"
 
-	# This tests that building the array does not require accessing
-	# g_int's contents.
-	gdb_test "print { 1, g_int, 3 }" \
-	    " = \\{1, <unavailable>, 3\\}" \
-	    "build array from unavailable value"
+    gdb_test_no_output "set print object on"
 
-	# Note, depends on previous test.
-	gdb_test "print \$\[1\]" \
-	    " = <unavailable>" \
-	    "subscript a non-memory rvalue array, accessing an unvailable element"
+    with_test_prefix "print object on" {
+	# With print object on, printing a pointer may need to fetch
+	# the pointed-to object, to check its run-time type.  Make
+	# sure that fails gracefully and transparently when the
+	# pointer itself is unavailable.
+	gdb_test "print virtualp" " = <unavailable>"
 
-	# Access a field of a non-lazy value, making sure the
-	# unavailable-ness is propagated.  History values are easy
-	# non-lazy values, so use those.  The first test just sets up for
-	# the second.
-	gdb_test "print g_smallstruct" " = <unavailable>"
-	gdb_test "print \$.member" " = <unavailable>"
+	# no vtable pointer available
+	gdb_test "print derived_unavail" " = <unavailable>"
 
-	# Cast to baseclass, checking the unavailable-ness is propagated.
-	gdb_test "print (small_struct) g_smallstruct_b" " = <unavailable>"
+	# vtable pointer available, but nothing else
+	gdb_test "print derived_partial" \
+	    " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
 
-	# Same cast, but starting from a non-lazy, value.
-	gdb_test "print g_smallstruct_b" " = <unavailable>"
-	gdb_test "print (small_struct) \$" " = <unavailable>"
+	# whole object available
+	gdb_test "print derived_whole" \
+	    " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
+    }
 
-	gdb_test_no_output "set print object on"
+    gdb_test_no_output "set print object off"
 
-	with_test_prefix "print object on" {
-	    # With print object on, printing a pointer may need to fetch
-	    # the pointed-to object, to check its run-time type.  Make
-	    # sure that fails gracefully and transparently when the
-	    # pointer itself is unavailable.
-	    gdb_test "print virtualp" " = <unavailable>"
+    with_test_prefix "print object off" {
+	gdb_test "print virtualp" " = <unavailable>"
 
-	    # no vtable pointer available
-	    gdb_test "print derived_unavail" " = <unavailable>"
+	# no vtable pointer available
+	gdb_test "print derived_unavail" \
+	    " = <unavailable>"
 
-	    # vtable pointer available, but nothing else
-	    gdb_test "print derived_partial" \
-		" = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
+	# vtable pointer available, but nothing else
+	gdb_test "print derived_partial" \
+	    " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
 
-	    # whole object available
-	    gdb_test "print derived_whole" \
-		" = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
-	}
+	# whole object available
+	gdb_test "print derived_whole" \
+	    " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
+    }
+
+    # An instance of a virtual class where we collected everything but
+    # the vptr.
+    gdb_test "print virtual_partial" \
+	" = {_vptr.Virtual = <unavailable>, z = 0}"
+}
 
-	gdb_test_no_output "set print object off"
+proc gdb_collect_globals_test { } {
+    with_test_prefix "collect globals" {
+	prepare_for_trace_test
 
-	with_test_prefix "print object off" {
-	    gdb_test "print virtualp" " = <unavailable>"
+	set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
 
-	    # no vtable pointer available
-	    gdb_test "print derived_unavail" \
-		" = <unavailable>"
+	gdb_test "trace $testline" \
+	    "Tracepoint \[0-9\]+ at .*" \
+	    "set tracepoint"
 
-	    # vtable pointer available, but nothing else
-	    gdb_test "print derived_partial" \
-		" = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
+	# We collect the initial sizeof(pointer) bytes of derived_partial
+	# in an attempt of collecting the vptr.  Not portable, but should
+	# work everywhere we need to care.
+	gdb_trace_setactions "define actions" \
+	    "" \
+	    "collect struct_b.struct_a.array\[2\]" "^$" \
+	    "collect struct_b.struct_a.array\[100\]" "^$" \
+	    \
+	    "collect a" "^$" \
+	    "collect c" "^$" \
+	    \
+	    "collect tarray\[0\].a" "^$" \
+	    "collect tarray\[1\].a" "^$" \
+	    "collect tarray\[3\].a" "^$" \
+	    "collect tarray\[3\].b" "^$" \
+	    "collect tarray\[4\].b" "^$" \
+	    "collect tarray\[5\].b" "^$" \
+	    \
+	    "collect g_string_p" "^$" \
+	    "collect g_string_partial\[1\]" "^$" \
+	    "collect g_string_partial\[2\]" "^$" \
+	    \
+	    "collect g_structref_p" "^$" \
+	    \
+	    "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
+	    "collect derived_whole" "^$" \
+	    \
+	    "collect virtual_partial.z" "^$"
 
-	    # whole object available
-	    gdb_test "print derived_whole" \
-		" = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
-	}
+	# Begin the test.
+	run_trace_experiment globals_test_func
 
-	# An instance of a virtual class where we collected everything but
-	# the vptr.
-	gdb_test "print virtual_partial" \
-	    " = {_vptr.Virtual = <unavailable>, z = 0}"
+	gdb_collect_globals_test_1
 
 	gdb_test "tfind none" \
 	    "#0  end .*" \
-- 
1.9.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/4] Partially available/unavailable data in requested range
  2014-04-28  6:15 [PATCH 0/4 V2] Partially available/unavailable data in requested range Yao Qi
                   ` (2 preceding siblings ...)
  2014-04-28  6:15 ` [PATCH 1/4] Move traceframe checking out of traceframe generation Yao Qi
@ 2014-04-28  6:15 ` Yao Qi
  2014-04-30 16:29   ` Pedro Alves
  3 siblings, 1 reply; 10+ messages in thread
From: Yao Qi @ 2014-04-28  6:15 UTC (permalink / raw)
  To: gdb-patches

In gdb.trace/unavailable.exp, an action is defined to collect
struct_b.struct_a.array[2] and struct_b.struct_a.array[100],

struct StructB
{
  int d, ef;
  StructA struct_a;
  int s:1;
  static StructA static_struct_a;
  const char *string;
};

and the other fields are not collected.

When GDB examine traceframe collected by the action, "struct_b" is
unavailable completely, which is wrong.

(gdb) p struct_b
$1 = <unavailable>

When GDB reads 'struct_b', it will request to read memory at struct_b's address
of length LEN.  Since struct_b.d is not collected, no 'M' block
includes the first part of the desired range, so tfile_xfer_partial returns
TARGET_XFER_UNAVAILABLE and GDB thinks the whole requested range is unavailable.

In order to fix this problem, in the iteration to 'M' blocks, we record the
lowest address of blocks within the request range.  If it has, the requested
range isn't unavailable completely.  This applies to ctf too.  With this patch
applied, the result looks good and fails in unavailable.exp is fixed.

(gdb) p struct_b
$1 = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>,
<unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>,   static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>,
bitfield = <unavailable>}, string = <unavailable>}

gdb:

2014-04-26  Yao Qi  <yao@codesourcery.com>
	    Pedro Alves  <palves@redhat.com>

	* tracefile-tfile.c (tfile_xfer_partial): Record the lowest
	address of blocks that intersects the requested range.  Trim
	LEN up to LOW_ADDR_AVAILABLE if read from executable read-only
	sections.
	* ctf.c (ctf_xfer_partial): Likewise.
---
 gdb/ctf.c             | 11 ++++++++++-
 gdb/tracefile-tfile.c | 11 ++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/gdb/ctf.c b/gdb/ctf.c
index bac7c28..84d0a48 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -1328,6 +1328,9 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
       struct bt_iter_pos *pos;
       int i = 0;
       enum target_xfer_status res;
+      /* Records the lowest available address of all blocks that
+	 intersects the requested range.  */
+      ULONGEST low_addr_available = 0;
 
       gdb_assert (ctf_iter != NULL);
       /* Save the current position.  */
@@ -1410,6 +1413,10 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
 		}
 	    }
 
+	  if (offset < maddr && maddr < (offset + len))
+	    if (low_addr_available == 0 || low_addr_available > maddr)
+	      low_addr_available = maddr;
+
 	  if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
 	    break;
 	}
@@ -1419,7 +1426,9 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
 
       /* Requested memory is unavailable in the context of traceframes,
 	 and this address falls within a read-only section, fallback
-	 to reading from executable.  */
+	 to reading from executable, up to LOW_ADDR_AVAILABLE  */
+      if (offset < low_addr_available)
+	len = min (len, low_addr_available - offset);
       res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);
 
       if (res == TARGET_XFER_OK)
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index efa69b2..37dc691 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -853,6 +853,9 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
     {
       int pos = 0;
       enum target_xfer_status res;
+      /* Records the lowest available address of all blocks that
+	 intersects the requested range.  */
+      ULONGEST low_addr_available = 0;
 
       /* Iterate through the traceframe's blocks, looking for
 	 memory.  */
@@ -886,13 +889,19 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
 	      return TARGET_XFER_OK;
 	    }
 
+	  if (offset < maddr && maddr < (offset + len))
+	    if (low_addr_available == 0 || low_addr_available > maddr)
+	      low_addr_available = maddr;
+
 	  /* Skip over this block.  */
 	  pos += (8 + 2 + mlen);
 	}
 
       /* Requested memory is unavailable in the context of traceframes,
 	 and this address falls within a read-only section, fallback
-	 to reading from executable.  */
+	 to reading from executable, up to LOW_ADDR_AVAILABLE.  */
+      if (offset < low_addr_available)
+	len = min (len, low_addr_available - offset);
       res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);
 
       if (res == TARGET_XFER_OK)
-- 
1.9.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/4] Show new created display
  2014-04-28  6:15 [PATCH 0/4 V2] Partially available/unavailable data in requested range Yao Qi
  2014-04-28  6:15 ` [PATCH 3/4] Save traceframes in trace file and read data out from trace file Yao Qi
@ 2014-04-28  6:15 ` Yao Qi
  2014-04-30 16:26   ` Pedro Alves
  2014-04-28  6:15 ` [PATCH 1/4] Move traceframe checking out of traceframe generation Yao Qi
  2014-04-28  6:15 ` [PATCH 4/4] Partially available/unavailable data in requested range Yao Qi
  3 siblings, 1 reply; 10+ messages in thread
From: Yao Qi @ 2014-04-28  6:15 UTC (permalink / raw)
  To: gdb-patches

When I run refactored unavailable.exp, I find
command display behaves a little different on live inferior and on
examining traceframes.  In live inferior, when command "display argc"
is typed, the value of "argc" is shown.

(gdb) display argc
1: argc = 1 '\001'

however, on tfile target, when command "display argc" is typed, the
value of "argc" is not shown.

(gdb) tfind
Found trace frame 0, tracepoint 1
    at ../../../../git/gdb/testsuite/gdb.trace/unavailable.cc:198
198       i =  (int) argc + argi + argf + argd + argstruct.memberi + argarray[1];
(gdb) display argc

I also notice that on "core" target, the value of "argc" isn't shown
either.  This difference is caused by the code below in printcmd.c:display_command,

      if (from_tty && target_has_execution)
        do_one_display (new);

Looks the value of each display is shown if the target has execution.
Source code archaeology doesn't tell much about this requirement.
However, if we type command "display" then on "core" or "tfile"
target, the value of "argc" is still displayed,

for "core" target,
(gdb) display argc
(gdb) display
1: argc = 1 '\001'

for "tfile" target,
(gdb) display argc
(gdb) display
1: argc = <unavailable>

I feel that it is not necessary to have such "target has execution"
requirement to show the value of new created display.  Auto-display is
a feature to show the value of expression frequently, has nothing to
do with whether target has execution or not.  On the other hand, GDB
has the requirement for new created display, but command "display" can
still show them, this is an inconsistency, which should be fixed.

This patch is to remove the checking to target_has_execution from the
condition.

gdb:

2014-04-26  Yao Qi  <yao@codesourcery.com>

	* printcmd.c (display_command): Remove the check to
	target_has_execution.
---
 gdb/printcmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 87b1448..228d4ad 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1547,7 +1547,7 @@ display_command (char *arg, int from_tty)
       new->enabled_p = 1;
       display_chain = new;
 
-      if (from_tty && target_has_execution)
+      if (from_tty)
 	do_one_display (new);
 
       dont_repeat ();
-- 
1.9.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/4] Save traceframes in trace file and read data out from trace file.
  2014-04-28  6:15 [PATCH 0/4 V2] Partially available/unavailable data in requested range Yao Qi
@ 2014-04-28  6:15 ` Yao Qi
  2014-04-30 16:26   ` Pedro Alves
  2014-04-28  6:15 ` [PATCH 2/4] Show new created display Yao Qi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Yao Qi @ 2014-04-28  6:15 UTC (permalink / raw)
  To: gdb-patches

This patch is to make GDB read data from trace file, tfile and ctf,
and test the output of collected data should be the same as read
data from remote target.

After the change, there are some fails below, and the next patch is to
fix them.

FAIL: gdb.trace/unavailable.exp: collect globals: tfile: print struct_b
FAIL: gdb.trace/unavailable.exp: collect globals: tfile: print /x struct_b
FAIL: gdb.trace/unavailable.exp: collect globals: tfile: print /x struct_b.struct_a
FAIL: gdb.trace/unavailable.exp: collect globals: tfile: print /x struct_b.struct_a.array
FAIL: gdb.trace/unavailable.exp: collect globals: tfile: <unavailable> is not the same as 0 in array element repetitions
FAIL: gdb.trace/unavailable.exp: collect globals: tfile: print *tarray@3
FAIL: gdb.trace/unavailable.exp: collect globals: tfile: printing partially collected string
FAIL: gdb.trace/unavailable.exp: collect globals: tfile: print virtual_partial
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: print struct_b
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: print /x struct_b
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: print /x struct_b.struct_a
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: print /x struct_b.struct_a.array
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: <unavailable> is not the same as 0 in array element repetitions
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: print *tarray@3
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: printing partially collected string
FAIL: gdb.trace/unavailable.exp: collect globals: ctf: print virtual_partial

gdb/testsuite:

2014-04-26  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/unavailable.exp (gdb_collect_args_test): Save
	traceframes into tfile and ctf trace files.  Read data from
	trace file and test collected data.
	(gdb_collect_locals_test): Likewise.
	(gdb_unavailable_registers_test): Likewise.
	(gdb_unavailable_floats): Likewise.
	(gdb_collect_globals_test): Likewise.
	(top-level): Append "ctf" to trace_file_targets if GDB
	supports.
---
 gdb/testsuite/gdb.trace/unavailable.exp | 142 ++++++++++++++++++++++++++++++++
 1 file changed, 142 insertions(+)

diff --git a/gdb/testsuite/gdb.trace/unavailable.exp b/gdb/testsuite/gdb.trace/unavailable.exp
index d76b54d..ec5ed26 100644
--- a/gdb/testsuite/gdb.trace/unavailable.exp
+++ b/gdb/testsuite/gdb.trace/unavailable.exp
@@ -188,6 +188,8 @@ proc gdb_collect_args_test_1 {} {
 proc gdb_collect_args_test {} {
     with_test_prefix "unavailable arguments" {
 	global gdb_prompt
+	global testfile srcdir subdir binfile
+	global trace_file_targets
 
 	prepare_for_trace_test
 
@@ -203,6 +205,30 @@ proc gdb_collect_args_test {} {
 	gdb_test "tfind none" \
 	    "#0  end .*" \
 	    "cease trace debugging"
+
+	set tracefile [standard_output_file ${testfile}]
+	gdb_test "tsave ${tracefile}.args.tfile" \
+	    "Trace data saved to file '${tracefile}.args.tfile'\.\\r" \
+	    "tsave ${testfile}.args.tfile"
+	gdb_test "tsave -ctf ${tracefile}.args.ctf" \
+	    "Trace data saved to directory '${tracefile}.args.ctf'\.\\r" \
+	    "save ctf trace file"
+
+	foreach target_name ${trace_file_targets} {
+	    # Restart GDB and read the trace data in ${TARGET_NAME} target.
+	    gdb_exit
+	    gdb_start
+	    gdb_reinitialize_dir $srcdir/$subdir
+	    gdb_file_cmd $binfile
+	    gdb_test "target ${target_name} ${tracefile}.args.${target_name}" ".*" \
+		"change to ${target_name} target"
+
+	    with_test_prefix "${target_name}" {
+		gdb_test "tfind start" "#0  args_test_func .*" \
+		    "tfind test frame"
+		gdb_collect_args_test_1
+	    }
+	}
     }
 }
 
@@ -244,6 +270,8 @@ proc gdb_collect_locals_test_1 { func } {
 proc gdb_collect_locals_test { func msg } {
     with_test_prefix "unavailable locals: $msg" {
 	global gdb_prompt
+	global testfile srcdir subdir binfile
+	global trace_file_targets
 
 	prepare_for_trace_test
 
@@ -261,6 +289,30 @@ proc gdb_collect_locals_test { func msg } {
 	gdb_test "tfind none" \
 	    "#0  end .*" \
 	    "cease trace debugging"
+
+	set tracefile [standard_output_file ${testfile}]
+	gdb_test "tsave ${tracefile}.locals.tfile" \
+	    "Trace data saved to file '${tracefile}.locals.tfile'\.\\r" \
+	    "tsave ${testfile}.locals.tfile"
+	gdb_test "tsave -ctf ${tracefile}.locals.ctf" \
+	    "Trace data saved to directory '${tracefile}.locals.ctf'\.\\r" \
+	    "save ctf trace file"
+
+	foreach target_name ${trace_file_targets} {
+	    # Restart GDB and read the trace data in ${TARGET_NAME} target.
+	    gdb_exit
+	    gdb_start
+	    gdb_reinitialize_dir $srcdir/$subdir
+	    gdb_file_cmd $binfile
+	    gdb_test "target ${target_name} ${tracefile}.locals.${target_name}" ".*" \
+		"change to ${target_name} target"
+
+	    with_test_prefix "${target_name}" {
+		gdb_test "tfind start" "#0  $func .*" \
+		    "tfind test frame"
+		gdb_collect_locals_test_1 $func
+	    }
+	}
     }
 }
 
@@ -302,6 +354,8 @@ proc gdb_unavailable_registers_test_1 { } {
 
 proc gdb_unavailable_registers_test { } {
     with_test_prefix "unavailable registers" {
+	global testfile srcdir subdir binfile
+	global trace_file_targets
 
 	prepare_for_trace_test
 
@@ -318,6 +372,30 @@ proc gdb_unavailable_registers_test { } {
 	gdb_unavailable_registers_test_1
 
 	gdb_test "tfind none" "#0  end .*" "cease trace debugging"
+
+	set tracefile [standard_output_file ${testfile}]
+	gdb_test "tsave ${tracefile}.registers.tfile" \
+	    "Trace data saved to file '${tracefile}.registers.tfile'\.\\r" \
+	    "tsave ${testfile}.registers.tfile"
+	gdb_test "tsave -ctf ${tracefile}.registers.ctf" \
+	    "Trace data saved to directory '${tracefile}.registers.ctf'\.\\r" \
+	    "save ctf trace file"
+
+	foreach target_name ${trace_file_targets} {
+	    # Restart GDB and read the trace data in ${TARGET_NAME} target.
+	    gdb_exit
+	    gdb_start
+	    gdb_reinitialize_dir $srcdir/$subdir
+	    gdb_file_cmd $binfile
+	    gdb_test "target ${target_name} ${tracefile}.registers.${target_name}" ".*" \
+		"change to ${target_name} target"
+
+	    with_test_prefix "${target_name}" {
+		gdb_test "tfind start" "#0  globals_test_func .*" \
+		    "tfind test frame"
+		gdb_unavailable_registers_test_1
+	    }
+	}
     }
 }
 
@@ -340,6 +418,9 @@ proc gdb_unavailable_floats_1 { } {
 
 proc gdb_unavailable_floats { } {
     with_test_prefix "unavailable floats" {
+	global testfile srcdir subdir binfile
+	global trace_file_targets
+
 	prepare_for_trace_test
 
 	# We'll simply re-use the globals_test_function for this test
@@ -355,6 +436,30 @@ proc gdb_unavailable_floats { } {
 	gdb_unavailable_floats_1
 
 	gdb_test "tfind none" "#0  end .*" "cease trace debugging"
+
+	set tracefile [standard_output_file ${testfile}]
+	gdb_test "tsave ${tracefile}.floats.tfile" \
+	    "Trace data saved to file '${tracefile}.floats.tfile'\.\\r" \
+	    "tsave ${testfile}.floats.tfile"
+	gdb_test "tsave -ctf ${tracefile}.floats.ctf" \
+	    "Trace data saved to directory '${tracefile}.floats.ctf'\.\\r" \
+	    "save ctf trace file"
+
+	foreach target_name ${trace_file_targets} {
+	    # Restart GDB and read the trace data in ${TARGET_NAME} target.
+	    gdb_exit
+	    gdb_start
+	    gdb_reinitialize_dir $srcdir/$subdir
+	    gdb_file_cmd $binfile
+	    gdb_test "target ${target_name} ${tracefile}.floats.${target_name}" ".*" \
+		"change to ${target_name} target"
+
+	    with_test_prefix "${target_name}" {
+		gdb_test "tfind start" "#0  globals_test_func .*" \
+		    "tfind test frame"
+		gdb_unavailable_floats_1
+	    }
+	}
     }
 }
 
@@ -551,6 +656,9 @@ proc gdb_collect_globals_test_1 { } {
 
 proc gdb_collect_globals_test { } {
     with_test_prefix "collect globals" {
+	global testfile binfile srcdir subdir
+	global trace_file_targets
+
 	prepare_for_trace_test
 
 	set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
@@ -596,6 +704,31 @@ proc gdb_collect_globals_test { } {
 	gdb_test "tfind none" \
 	    "#0  end .*" \
 	    "cease trace debugging"
+
+	set tracefile [standard_output_file ${testfile}]
+	gdb_test "tsave ${tracefile}.globals.tfile" \
+	    "Trace data saved to file '${tracefile}.globals.tfile'\.\\r" \
+	    "tsave ${testfile}.globals.tfile"
+	gdb_test "tsave -ctf ${tracefile}.globals.ctf" \
+	    "Trace data saved to directory '${tracefile}.globals.ctf'\.\\r" \
+	    "save ctf trace file"
+
+	foreach target_name ${trace_file_targets} {
+	    # Restart GDB and read the trace data in ${TARGET_NAME} target.
+	    gdb_exit
+	    gdb_start
+	    gdb_reinitialize_dir $srcdir/$subdir
+	    gdb_file_cmd $binfile
+	    gdb_test "target ${target_name} ${tracefile}.globals.${target_name}" ".*" \
+		"change to ${target_name} target"
+
+	    with_test_prefix "${target_name}" {
+		gdb_test "tfind start" "#0  globals_test_func .*" \
+		    "tfind test frame"
+		gdb_collect_globals_test_1
+	    }
+	}
+
     }
 }
 
@@ -617,6 +750,15 @@ if { ![gdb_target_supports_trace] } then {
     return 1
 }
 
+set trace_file_targets [list "tfile"]
+gdb_test_multiple "target ctf" "" {
+    -re "Undefined target command: \"ctf\"\.  Try \"help target\"\.\r\n$gdb_prompt $" {
+    }
+    -re "No CTF directory specified.*\r\n$gdb_prompt $" {
+	lappend trace_file_targets "ctf"
+    }
+}
+
 # Body of test encased in a proc so we can return prematurely.
 gdb_trace_collection_test
 
-- 
1.9.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/4 V2] Partially available/unavailable data in requested range
@ 2014-04-28  6:15 Yao Qi
  2014-04-28  6:15 ` [PATCH 3/4] Save traceframes in trace file and read data out from trace file Yao Qi
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Yao Qi @ 2014-04-28  6:15 UTC (permalink / raw)
  To: gdb-patches

This patch series is V2, to address review comments in V1
https://sourceware.org/ml/gdb-patches/2014-04/msg00395.html

There are some changes in V2:

 - Fall back to read from executable if requested data is unavailable
   in trace frames.
 - Modify gdb.trace/unavailable.exp to cover the scenario this patch
   is to fix.

gdb.trace/unavailable.exp is to test the collected trace data in live
inferior, but this fix is about collected trace data in trace file.
Patch #1 refactors unavailable.exp, so that it can be extended to
cover trace files.  During the refactor, we find automatic display
behaves differently on live inferior and on trace file.  Patch #2
is to get rid of this difference.  Then, patch #3 extends unavailable.exp
by saving traceframes into trace files, read data from them, and test
the output is identical among these targets (remote, tfile and ctf).
After this change, unavailable.exp exposes the problem patch #4 tries
to fix (see more details about the problem in patch #4).  I'll squash
patch #3 and #4 before push them into repository.

The patch series is tested on x86_64-linux with target_board unix and
native-gdbserver respectively.

*** BLURB HERE ***

Yao Qi (4):
  Move traceframe checking out of traceframe generation
  Show new created display
  Save traceframes in trace file and read data out from trace file.
  Partially available/unavailable data in requested range

 gdb/ctf.c                               |  11 +-
 gdb/printcmd.c                          |   2 +-
 gdb/testsuite/gdb.trace/unavailable.exp | 758 +++++++++++++++++++-------------
 gdb/tracefile-tfile.c                   |  11 +-
 4 files changed, 482 insertions(+), 300 deletions(-)

-- 
1.9.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] Move traceframe checking out of traceframe generation
  2014-04-28  6:15 ` [PATCH 1/4] Move traceframe checking out of traceframe generation Yao Qi
@ 2014-04-30 16:15   ` Pedro Alves
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2014-04-30 16:15 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 04/28/2014 07:12 AM, Yao Qi wrote:
> This patch moves traceframe checking code out of traceframe generation,
> so that we can generation traceframe once, and do the checking in multiple
> times (with target remote, tfile and ctf respectively).  This is a
> pure refactor, not functional changes in unavailable.exp.
> 
> gdb/testsuite:
> 
> 2014-04-26  Yao Qi  <yao@codesourcery.com>
> 
> 	* gdb.trace/unavailable.exp (gdb_collect_args_test): Move some
> 	code to ...
> 	(gdb_collect_args_test_1): ... it.  New proc.
> 	(gdb_collect_locals_test): Move some code to ...
> 	(gdb_collect_locals_test_1): ... it.  New proc.
> 	(gdb_unavailable_registers_test): Move some code to ...
> 	(gdb_unavailable_registers_test_1): ... it.  New proc.
> 	(gdb_unavailable_floats): Move some code to ...
> 	(gdb_unavailable_floats_1): ... it.  New proc.

OK.  Thanks.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] Show new created display
  2014-04-28  6:15 ` [PATCH 2/4] Show new created display Yao Qi
@ 2014-04-30 16:26   ` Pedro Alves
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2014-04-30 16:26 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 04/28/2014 07:12 AM, Yao Qi wrote:
> When I run refactored unavailable.exp, I find
> command display behaves a little different on live inferior and on
> examining traceframes.  In live inferior, when command "display argc"
> is typed, the value of "argc" is shown.
> 
> (gdb) display argc
> 1: argc = 1 '\001'
> 
> however, on tfile target, when command "display argc" is typed, the
> value of "argc" is not shown.
> 
> (gdb) tfind
> Found trace frame 0, tracepoint 1
>     at ../../../../git/gdb/testsuite/gdb.trace/unavailable.cc:198
> 198       i =  (int) argc + argi + argf + argd + argstruct.memberi + argarray[1];
> (gdb) display argc
> 
> I also notice that on "core" target, the value of "argc" isn't shown
> either.  This difference is caused by the code below in printcmd.c:display_command,
> 
>       if (from_tty && target_has_execution)
>         do_one_display (new);
> 
> Looks the value of each display is shown if the target has execution.
> Source code archaeology doesn't tell much about this requirement.
> However, if we type command "display" then on "core" or "tfile"
> target, the value of "argc" is still displayed,

Maybe ancient, ancient code that tried to prevent "display $pc"
from erroring out?

Judging from doing that when there's execution, and then
killing the inferior, and getting:

 (gdb) display
 1: $pc = <error: No registers.>

Looks like we handle errors fine here, so I see no issue.

I assume that if there's no target pushed yet, we'll now
see that error -- it's fine with me.

It would be good if display.exp itself was augmented to explicitly
test this.  Say, do "display global" (where global is a variable that
is initialized to something not zero), and also "display $pc" before
there's execution.

> This patch is to remove the checking to target_has_execution from the
> condition.

OK.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] Save traceframes in trace file and read data out from trace file.
  2014-04-28  6:15 ` [PATCH 3/4] Save traceframes in trace file and read data out from trace file Yao Qi
@ 2014-04-30 16:26   ` Pedro Alves
  2014-05-05  3:52     ` Yao Qi
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2014-04-30 16:26 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

OK.

On 04/28/2014 07:12 AM, Yao Qi wrote:
> +	gdb_test "tsave -ctf ${tracefile}.floats.ctf" \

I trust this works even if "target ctf" isn't supported?

Thanks,
-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] Partially available/unavailable data in requested range
  2014-04-28  6:15 ` [PATCH 4/4] Partially available/unavailable data in requested range Yao Qi
@ 2014-04-30 16:29   ` Pedro Alves
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2014-04-30 16:29 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 04/28/2014 07:12 AM, Yao Qi wrote:

> gdb:
> 
> 2014-04-26  Yao Qi  <yao@codesourcery.com>
> 	    Pedro Alves  <palves@redhat.com>
> 
> 	* tracefile-tfile.c (tfile_xfer_partial): Record the lowest
> 	address of blocks that intersects the requested range.  Trim
> 	LEN up to LOW_ADDR_AVAILABLE if read from executable read-only
> 	sections.
> 	* ctf.c (ctf_xfer_partial): Likewise.

OK.

Thanks!

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] Save traceframes in trace file and read data out from trace file.
  2014-04-30 16:26   ` Pedro Alves
@ 2014-05-05  3:52     ` Yao Qi
  0 siblings, 0 replies; 10+ messages in thread
From: Yao Qi @ 2014-05-05  3:52 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On 05/01/2014 12:26 AM, Pedro Alves wrote:
>> +	gdb_test "tsave -ctf ${tracefile}.floats.ctf" \
> I trust this works even if "target ctf" isn't supported?

Yes, we use generic file write/seek APIs to write ctf trace file,
but use libbabeltrace to read from ctf trace file.  Even "target
ctf" isn't supported (libbabeltrace isn't used), GDB is still able
to save in ctf format.

Patches are pushed in.  Thanks for the review.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-05-05  3:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-28  6:15 [PATCH 0/4 V2] Partially available/unavailable data in requested range Yao Qi
2014-04-28  6:15 ` [PATCH 3/4] Save traceframes in trace file and read data out from trace file Yao Qi
2014-04-30 16:26   ` Pedro Alves
2014-05-05  3:52     ` Yao Qi
2014-04-28  6:15 ` [PATCH 2/4] Show new created display Yao Qi
2014-04-30 16:26   ` Pedro Alves
2014-04-28  6:15 ` [PATCH 1/4] Move traceframe checking out of traceframe generation Yao Qi
2014-04-30 16:15   ` Pedro Alves
2014-04-28  6:15 ` [PATCH 4/4] Partially available/unavailable data in requested range Yao Qi
2014-04-30 16:29   ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).