+# Test that when we've collected all fields of a structure
+# individually, we can print the whole structure in one go.
+proc gdb_collect_global_in_pieces_test { } {
+ global gdb_prompt
+
+ prepare_for_trace_test
+
+ # Find the comment-identified line for setting this tracepoint.
+ set testline 0
+ set msg "collect global in pieces: find tracepoint line"
+ gdb_test_multiple "list globals_test_func, +30" "$msg" {
+ -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
+ set testline $expect_out(1,string)
+ pass "$msg"
+ }
+ }
+
+ if {$testline == 0} {
+ return
+ }
+
+ gdb_test "trace $testline" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "collect global in pieces: set tracepoint"
+ gdb_trace_setactions "collect global in pieces: define actions" \
+ "" \
+ "collect global_pieces.a, global_pieces.b" \
+ "^$"
+
+ # Begin the test.
+ run_trace_experiment "global in pieces" globals_test_func
+
+ gdb_test "print /x global_pieces.a" " = 0x12345678" \
+ "collect global in pieces: print piece a"
+ gdb_test "print /x global_pieces.b" " = 0x87654321" \
+ "collect global in pieces: print piece b"
+
+ gdb_test "print /x global_pieces" " = \{a = 0x12345678, b = 0x87654321\}" \
+ "collect global in pieces: print whole object"
+
+ gdb_test "tfind none" "#0 end .*" \
+ "collect global in pieces: cease trace debugging"
+}
+
+proc gdb_collect_return_test { } {
+ global gdb_prompt
+
+ prepare_for_trace_test
+
+ # We'll simply re-use the args_test_function for this test
+ gdb_test "trace args_test_func" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "collect \$_ret: set tracepoint"
+ gdb_trace_setactions "collect \$_ret: define actions" \
+ "" \
+ "collect \$_ret" "^$"
+
+ # Begin the test.
+ run_trace_experiment \$_ret args_test_func
+
+ # Since we can't guarantee that $_ret will give us the caller,
+ # pass either way, but giving different messages.
+ gdb_test_multiple "backtrace" "" {
+ -re ".*#1 .* in main .*\r\n$gdb_prompt $" {
+ pass "collect \$_ret: backtrace lists main"
+ }
+ -re ".*#1 .* in ?? .*\r\n$gdb_prompt $" {
+ pass "collect \$_ret: backtrace not listing main"
+ }
+ }
+
+ gdb_test "tfind none" \
+ "#0 end .*" \
+ "collect \$_ret: cease trace debugging"
+}
+
+proc gdb_collect_strings_test { func mystr myrslt mylim msg } {
+ global hex
+ global cr
+ global gdb_prompt
+
+ prepare_for_trace_test
+
+ # Find the comment-identified line for setting this tracepoint.
+ set testline 0
+ gdb_test_multiple "list $func, +30" "collect $msg: find tracepoint line" {
+ -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
+ set testline $expect_out(1,string)
+ pass "collect $msg: find tracepoint line"
+ }
+ -re ".*$gdb_prompt " {
+ fail "collect $msg: find tracepoint line (skipping strings test)"
+ return
+ }
+ timeout {
+ fail "collect $msg: find tracepoint line (skipping strings test)"
+ return
+ }
+ }
+
+ gdb_test "trace $testline" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "collect $msg: set tracepoint"
+ gdb_trace_setactions "collect $msg: define actions" \
+ "" \
+ "collect/s$mylim $mystr" "^$"
+
+ # Begin the test.
+ run_trace_experiment $msg $func
+
+ gdb_test "print $mystr" \
+ "\\$\[0-9\]+ = $hex \"$myrslt\".*$cr" \
+ "collect $msg: collected local string"
+
+ gdb_test "tfind none" \
+ "#0 end .*" \
+ "collect $msg: cease trace debugging"
+}
+