-# Copyright 1998, 2005, 2007, 2008, 2009, 2010, 2011
-# Free Software Foundation, Inc.
+# Copyright 1998, 2005, 2007-2012 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
set ws "\[\r\n\t \]+"
set cr "\[\r\n\]+"
+if [is_amd64_regs_target] {
+ set fpreg "rbp"
+ set spreg "rsp"
+ set pcreg "rip"
+} elseif [is_x86_like_target] {
+ set fpreg "ebp"
+ set spreg "esp"
+ set pcreg "eip"
+} else {
+ set fpreg "fp"
+ set spreg "sp"
+ set pcreg "pc"
+}
+
#
# Utility procs
#
+proc test_register { reg } {
+ global gdb_prompt
+ global hex
+ global cr
+
+ gdb_test_multiple "print /x $reg" "collected $reg" {
+ -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
+ fail "collected $reg (zero)"
+ }
+ -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" {
+ pass "collected $reg"
+ }
+ -re "\[Ee\]rror.*$gdb_prompt $" {
+ fail "collected $reg (error)"
+ }
+ }
+}
+
+proc test_register_unavailable { reg } {
+ gdb_test "print /x $reg" \
+ "<unavailable>" \
+ "correctly report $reg as unavailable"
+}
+
proc prepare_for_trace_test {} {
global executable
"tfind test frame"
}
+# Test that "display VAR" works as expected, assuming VAR is wholly
+# unavailable.
+
+proc test_maybe_regvar_display { var } {
+ global gdb_prompt
+
+ # Evaluating VAR's location description may throw an internal
+ # "unavailable" exception, if for example, the value of a register
+ # necessary for computing VAR's location is unavailable. Such an
+ # exception is caught, and should not cause automatic disablement
+ # of the current display being printed. (GDB used to disable the
+ # current display whenever any exception was thrown.)
+ set test "display $var"
+ gdb_test_multiple "$test" "$test" {
+ -re "Disabling display ? to avoid infinite recursion.*$gdb_prompt $" {
+ fail "$test"
+ }
+ -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" {
+ pass "$test"
+ }
+ }
+ gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled"
+
+ gdb_test "undisp" \
+ "" \
+ "delete $var display" \
+ ".*Delete all auto-display expressions.*y or n. $" \
+ "y"
+}
+
#
# Test procs
#
-proc gdb_collect_globals_test { } {
+proc gdb_collect_args_test {} { with_test_prefix "unavailable arguments" {
+ global cr
+ global gdb_prompt
+
+ prepare_for_trace_test
+
+ gdb_test "trace args_test_func" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "set tracepoint"
+
+ # Begin the test.
+ run_trace_experiment args_test_func
+
+ # 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 argc" " = <unavailable>"
+ gdb_test "print &argc" \
+ "Can't take address of \"argc\" 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\."
+
+ gdb_test "print argf" " = <unavailable>"
+ gdb_test "print &argf" \
+ "Can't take address of \"argf\" 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\."
+
+ # struct arg as one of several args (near end of list)
+
+ gdb_test "print argstruct" \
+ " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
+
+ 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" " = \\(int \\*\\) <unavailable>"
+
+ gdb_test "print &argarray" \
+ "Can't take address of \"argarray\" which isn't an lvalue\."
+
+ gdb_test "print argarray\[0\]" "value is not available"
+
+ # 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 = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
+ set r "${r}argarray = <unavailable>${cr}"
+ gdb_test "info args" "$r" "info args"
+
+ test_maybe_regvar_display "argc"
+
+ gdb_test "tfind none" \
+ "#0 end .*" \
+ "cease trace debugging"
+}}
+
+proc gdb_collect_locals_test { func msg } { with_test_prefix "unavailable locals: $msg" {
+ global cr
+ global gdb_prompt
+
+ prepare_for_trace_test
+
+ set testline [gdb_get_line_number "set $func tracepoint here"]
+
+ gdb_test "trace $testline" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "set tracepoint"
+
+ # 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 = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
+ set r "${r}locar = {<unavailable>, <unavailable>, <unavailable>, <unavailable>}${cr}"
+ set r "${r}i = <unavailable>${cr}"
+ if { $func == "local_test_func" } {
+ set r "${r}locdefst = {<No data fields>}${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_test "tfind none" \
+ "#0 end .*" \
+ "cease trace debugging"
+}}
+
+proc gdb_unavailable_registers_test { } { with_test_prefix "unavailable registers" {
+ global gdb_prompt
+ global spreg
+ global pcreg
+
+ prepare_for_trace_test
+
+ # We'll simply re-use the globals_test_function for this test
+ gdb_test "trace globals_test_func" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "set tracepoint"
+
+ # Collect nothing.
+
+ # 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" \
+ "\\*value not available\\*.*\\*value not available\\*" \
+ "info registers, multiple registers not available"
+
+ gdb_test "info registers \$$spreg" \
+ "\\*value not available\\*" \
+ "info registers \$$spreg reports not available"
+
+ gdb_test "tfind none" "#0 end .*" "cease trace debugging"
+}}
+
+proc gdb_unavailable_floats { } {
+ global gdb_prompt
+
+ with_test_prefix "unavailable floats" {
+ prepare_for_trace_test
+
+ # We'll simply re-use the globals_test_function for this test
+ gdb_test "trace globals_test_func" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "set tracepoint"
+
+ # Collect nothing.
+
+ # 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_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
- global pf_prefix
-
- set old_pf_prefix $pf_prefix
- set pf_prefix "$pf_prefix collect globals:"
prepare_for_trace_test
"Tracepoint \[0-9\]+ at .*" \
"set tracepoint"
+ # 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 g_string_partial\[2\]" "^$" \
\
"collect g_structref_p" "^$" \
+ \
+ "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
+ "collect derived_whole" "^$" \
+ \
+ "collect virtual_partial.z" "^$"
# Begin the test.
run_trace_experiment globals_test_func
gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
+ # 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 <unavailable> isn't confused with 0 in array element repetitions
gdb_test_no_output "set print repeat 1"
gdb_test_no_output "set print repeat 10"
+ # Check that value repeat handles unavailable-ness.
+ gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
+
# Static fields
gdb_test "print struct_b.static_struct_a" \
"non collected const string is still printable"
gdb_test "print g_string_p" \
- " = $hex \"hello world\"" \
+ " = $hex <g_const_string> \"hello world\"" \
"printing constant string through collected pointer"
gdb_test "print g_string_unavail" \
gdb_test "p \$__" " = <unavailable>" "last examined value was <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"
+
+ # Note, depends on previous test.
+ gdb_test "print \$\[1\]" \
+ " = <unavailable>" \
+ "subscript a non-memory rvalue array, accessing an unvailable element"
+
+ # 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" " = \\{member = <unavailable>\\}"
+ gdb_test "print \$.member" " = <unavailable>"
+
+ # Cast to baseclass, checking the unavailable-ness is propagated.
+ gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
+
+ # Same cast, but starting from a non-lazy, value.
+ gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
+ gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
+
+ gdb_test_no_output "set print object on"
+
+ 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" " = \\(Virtual \\*\\) <unavailable>"
+
+ # no vtable pointer available
+ gdb_test "print derived_unavail" \
+ " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <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>}"
+
+ # 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 off"
+
+ with_test_prefix "print object off" {
+ gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
+
+ # no vtable pointer available
+ gdb_test "print derived_unavail" \
+ " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, 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" \
+ " = {<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 "tfind none" \
"#0 end .*" \
"cease trace debugging"
-
- set pf_prefix $old_pf_prefix
-}
+}}
proc gdb_trace_collection_test {} {
gdb_collect_globals_test
+ gdb_unavailable_registers_test
+ gdb_unavailable_floats
+
+ gdb_collect_args_test
+ gdb_collect_locals_test local_test_func "auto locals"
+ gdb_collect_locals_test reglocal_test_func "register locals"
+ gdb_collect_locals_test statlocal_test_func "static locals"
}
clean_restart $executable
runto_main
-# We generously give ourselves one "pass" if we successfully
-# detect that this test cannot be run on this target!
if { ![gdb_target_supports_trace] } then {
- pass "Current target does not support trace"
+ unsupported "Current target does not support trace"
return 1;
}