From patchwork Mon Apr 28 06:12:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 694 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id D699F36007A for ; Sun, 27 Apr 2014 23:16:00 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id 824D613A8A76; Sun, 27 Apr 2014 23:16:00 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id 55F4913F6F4A for ; Sun, 27 Apr 2014 23:16:00 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-type; q=dns; s=default; b=If4Ly snQ2wPTaavULJEnVpXjzkp8M9LgwSQOFUHmzdlke6YBAVkllU6xYgmCsbnNedOck tj6accOGKqgE0RNcB3VjtxnWv2dlPvZkqM6/PZXsVZuMVZc9okB5FwipjLFY1AFf EEOUYmbZe9VMTNPF27Kuyg2tf+FA9SPhxq2zTQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-type; s=default; bh=e0Hf3Ad0dc5 J0PRu4bZib3PCtp8=; b=OCfKIZYJwcK1nAsLd62eWA4nH7Uo8muyftoaB9gCQ23 Vzgp1Ugd0gU9SzMIBwvV9G5sYYeU5wFP5QIZ/942NFCoK+jc1Bvl3/+uSjv1grvW x/Eik6IxcNrAvXybWck4oORWW5DOINCQ2rvb51YoSsPjZ+15DMOTRr71n7K5W60c = Received: (qmail 18905 invoked by alias); 28 Apr 2014 06:15:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 18795 invoked by uid 89); 28 Apr 2014 06:15:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Apr 2014 06:15:17 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1WeeqQ-0005tx-5A from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Sun, 27 Apr 2014 23:15:14 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sun, 27 Apr 2014 23:15:13 -0700 Received: from qiyao.dyndns.org.com (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Sun, 27 Apr 2014 23:15:12 -0700 From: Yao Qi To: Subject: [PATCH 1/4] Move traceframe checking out of traceframe generation Date: Mon, 28 Apr 2014 14:12:15 +0800 Message-ID: <1398665538-16580-2-git-send-email-yao@codesourcery.com> In-Reply-To: <1398665538-16580-1-git-send-email-yao@codesourcery.com> References: <1398665538-16580-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in 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 * 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" " = " + 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" " = " + 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" " = " + gdb_test "print &argf" \ + "Can't take address of \"argf\" which isn't an lvalue\." - gdb_test "print argc" " = " - gdb_test "print &argc" \ - "Can't take address of \"argc\" which isn't an lvalue\." + gdb_test "print argd" " = " + gdb_test "print &argd" \ + "Can't take address of \"argd\" which isn't an lvalue\." - gdb_test "print argi" " = " - 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" " = " - gdb_test "print &argf" \ - "Can't take address of \"argf\" which isn't an lvalue\." + gdb_test "print argstruct" " = " - gdb_test "print argd" " = " - gdb_test "print &argd" \ - "Can't take address of \"argd\" which isn't an lvalue\." + gdb_test "print argstruct.memberc" " = " + gdb_test "print argstruct.memberi" " = " + gdb_test "print argstruct.memberf" " = " + gdb_test "print argstruct.memberd" " = " - # struct arg as one of several args (near end of list) + gdb_test "print argarray" " = " - gdb_test "print argstruct" " = " + gdb_test "print &argarray" \ + "Can't take address of \"argarray\" which isn't an lvalue\." - gdb_test "print argstruct.memberc" " = " - gdb_test "print argstruct.memberi" " = " - gdb_test "print argstruct.memberf" " = " - gdb_test "print argstruct.memberd" " = " + gdb_test "print argarray\[0\]" "value is not available" - gdb_test "print argarray" " = " + # Test "info args" + set r "" + set r "${r}argc = ${cr}" + set r "${r}argi = ${cr}" + set r "${r}argf = ${cr}" + set r "${r}argd = ${cr}" + set r "${r}argstruct = ${cr}" + set r "${r}argarray = ${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 = ${cr}" - set r "${r}argi = ${cr}" - set r "${r}argf = ${cr}" - set r "${r}argd = ${cr}" - set r "${r}argstruct = ${cr}" - set r "${r}argarray = ${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" " = " + gdb_test "print loci" " = " + gdb_test "print locf" " = " + gdb_test "print locd" " = " + + gdb_test "print locst.memberc" " = " + gdb_test "print locst.memberi" " = " + gdb_test "print locst.memberf" " = " + gdb_test "print locst.memberd" " = " + + gdb_test "print locar\[0\]" " = " + gdb_test "print locar\[1\]" " = " + gdb_test "print locar\[2\]" " = " + gdb_test "print locar\[3\]" " = " + + # Test "info locals" + set r "" + set r "${r}locf = ${cr}" + set r "${r}locd = ${cr}" + set r "${r}locst = ${cr}" + set r "${r}locar = ${cr}" + set r "${r}i = ${cr}" + if { $func == "local_test_func" } { + set r "${r}locdefst = ${cr}" + } + set r "${r}locc = ${cr}" + set r "${r}loci = ${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" " = " - gdb_test "print loci" " = " - gdb_test "print locf" " = " - gdb_test "print locd" " = " - - gdb_test "print locst.memberc" " = " - gdb_test "print locst.memberi" " = " - gdb_test "print locst.memberf" " = " - gdb_test "print locst.memberd" " = " - - gdb_test "print locar\[0\]" " = " - gdb_test "print locar\[1\]" " = " - gdb_test "print locar\[2\]" " = " - gdb_test "print locar\[3\]" " = " - - # Test "info locals" - set r "" - set r "${r}locf = ${cr}" - set r "${r}locd = ${cr}" - set r "${r}locst = ${cr}" - set r "${r}locar = ${cr}" - set r "${r}i = ${cr}" - if { $func == "local_test_func" } { - set r "${r}locdefst = ${cr}" - } - set r "${r}locc = ${cr}" - set r "${r}loci = ${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" \ + ".*" \ + "info registers, multiple registers not available" + + gdb_test "info registers \$$spreg" \ + "" \ + "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" \ - ".*" \ - "info registers, multiple registers not available" - - gdb_test "info registers \$$spreg" \ - "" \ - "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: " + "Control Word: " + "Tag Word: " + "Instruction Pointer: :" + "Operand Pointer: :" + "Opcode: " + } + } +} + +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: " - "Control Word: " - "Tag Word: " - "Instruction Pointer: :" - "Operand Pointer: :" - "Opcode: " - } - } + 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" " = " + gdb_test "print globali" " = " + gdb_test "print globalf" " = " + gdb_test "print globald" " = " - set testline [gdb_get_line_number "set globals_test_func tracepoint here"] + gdb_test "print globalstruct.memberc" " = " + gdb_test "print globalstruct.memberi" " = " + gdb_test "print globalstruct.memberf" " = " + gdb_test "print globalstruct.memberd" " = " - gdb_test "trace $testline" \ - "Tracepoint \[0-9\]+ at .*" \ - "set tracepoint" + gdb_test "print globalstruct" " = " - # 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\]" " = " + gdb_test "print globalarr\[2\]" " = " + gdb_test "print globalarr\[3\]" " = " - gdb_test "print globalc" " = " - gdb_test "print globali" " = " - gdb_test "print globalf" " = " - gdb_test "print globald" " = " + gdb_test "print struct_b" \ + " = {d = , ef = , struct_a = {a = , b = , array = {, , -1431655766, , -1431655766, }, ptr = , bitfield = }, s = , static static_struct_a = {a = , b = , array = { }, ptr = , bitfield = }, string = }" - gdb_test "print globalstruct.memberc" " = " - gdb_test "print globalstruct.memberi" " = " - gdb_test "print globalstruct.memberf" " = " - gdb_test "print globalstruct.memberd" " = " + gdb_test "print /x struct_b" \ + " = {d = , ef = , struct_a = {a = , b = , array = {, , 0xaaaaaaaa, , 0xaaaaaaaa, }, ptr = , bitfield = }, s = , static static_struct_a = {a = , b = , array = { }, ptr = , bitfield = }, string = }" - gdb_test "print globalstruct" " = " + gdb_test "print /x struct_b.struct_a" \ + " = {a = , b = , array = {, , 0xaaaaaaaa, , 0xaaaaaaaa, }, ptr = , bitfield = }" - 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" \ + " = {, , 0xaaaaaaaa, , 0xaaaaaaaa, }" - gdb_test "print globalarr\[1\]" " = " - gdb_test "print globalarr\[2\]" " = " - gdb_test "print globalarr\[3\]" " = " + gdb_test "print /x struct_b.struct_a.array\[0\]" " = " - gdb_test "print struct_b" \ - " = {d = , ef = , struct_a = {a = , b = , array = {, , -1431655766, , -1431655766, }, ptr = , bitfield = }, s = , static static_struct_a = {a = , b = , array = { }, ptr = , bitfield = }, string = }" + gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa" - gdb_test "print /x struct_b" \ - " = {d = , ef = , struct_a = {a = , b = , array = {, , 0xaaaaaaaa, , 0xaaaaaaaa, }, ptr = , bitfield = }, s = , static static_struct_a = {a = , b = , array = { }, ptr = , bitfield = }, string = }" + # 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, , 3\\}" \ + "No overcollect of almost but not quite adjacent memory ranges" - gdb_test "print /x struct_b.struct_a" \ - " = {a = , b = , array = {, , 0xaaaaaaaa, , 0xaaaaaaaa, }, ptr = , bitfield = }" + # Check isn't confused with 0 in array element repetitions - gdb_test "print /x struct_b.struct_a.array" \ - " = {, , 0xaaaaaaaa, , 0xaaaaaaaa, }" + gdb_test_no_output "set print repeat 1" - gdb_test "print /x struct_b.struct_a.array\[0\]" " = " + gdb_test "print /x tarray" \ + " = \{\{a = 0x0, b = \} , \{a = , b = \}, \{a = 0x0, b = 0x0\}, \{a = , b = 0x0\} , \{a = , b = \} \}" \ + " 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, , 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 = \\}, \\{a = 0, b = \\}, \\{a = , b = \\}\\}" - # Check 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" " = " - gdb_test "print /x tarray" \ - " = \{\{a = 0x0, b = \} , \{a = , b = \}, \{a = 0x0, b = 0x0\}, \{a = , b = 0x0\} , \{a = , b = \} \}" \ - " 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" " = " - # Check that value repeat handles unavailable-ness. - gdb_test "print *tarray@3" " = \\{\\{a = 0, b = \\}, \\{a = 0, b = \\}, \\{a = , b = \\}\\}" + # References - # Static fields + gdb_test "print g_int" " = " - gdb_test "print struct_b.static_struct_a" " = " + gdb_test "print g_ref" \ + "\\(int &\\) @$hex: " \ + "global reference shows address but not value" - # Bitfields + gdb_test "print *&g_ref" \ + "\\$\[0-9\]+ = $cr" \ + "referenced integer was not collected (taking address of reference)" - gdb_test "print struct_b.struct_a.bitfield" " = " + gdb_test "print *g_structref_p" " = " - # References + # Strings - gdb_test "print g_int" " = " + # 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: " \ - "global reference shows address but not value" + gdb_test "print g_string_p" \ + " = $hex \"hello world\"" \ + "printing constant string through collected pointer" - gdb_test "print *&g_ref" \ - "\\$\[0-9\]+ = $cr" \ - "referenced integer was not collected (taking address of reference)" + gdb_test "print g_string_unavail" \ + " = " \ + "printing non collected string" - gdb_test "print *g_structref_p" " = " + # Incomplete strings print as an array. + gdb_test "print g_string_partial" \ + "\\$\[0-9\]+ = \{, 101 'e', 108 'l', , , , , , , , , \}" \ + "printing partially collected string" - # Strings + # It is important for this test that the last examined value is + # , to exercise the case of the $__ convenience + # variable being set to without error. + set msg "examining partially collected object" + gdb_test_multiple "x /10x &struct_b" "$msg" { + -re "$hex :${ws}${ws}${ws}${ws}$cr$hex :${ws}${ws}${ws}0xaaaaaaaa${ws}$cr$hex :${ws}${ws}$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 \$__" " = " "last examined value was " - gdb_test "print g_string_p" \ - " = $hex \"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, , 3\\}" \ + "build array from unavailable value" - gdb_test "print g_string_unavail" \ - " = " \ - "printing non collected string" + # Note, depends on previous test. + gdb_test "print \$\[1\]" \ + " = " \ + "subscript a non-memory rvalue array, accessing an unvailable element" - # Incomplete strings print as an array. - gdb_test "print g_string_partial" \ - "\\$\[0-9\]+ = \{, 101 'e', 108 'l', , , , , , , , , \}" \ - "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" " = " + gdb_test "print \$.member" " = " - # It is important for this test that the last examined value is - # , to exercise the case of the $__ convenience - # variable being set to without error. - set msg "examining partially collected object" - gdb_test_multiple "x /10x &struct_b" "$msg" { - -re "$hex :${ws}${ws}${ws}${ws}$cr$hex :${ws}${ws}${ws}0xaaaaaaaa${ws}$cr$hex :${ws}${ws}$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" " = " - gdb_test "p \$__" " = " "last examined value was " + # Same cast, but starting from a non-lazy, value. + gdb_test "print g_smallstruct_b" " = " + gdb_test "print (small_struct) \$" " = " - # This tests that building the array does not require accessing - # g_int's contents. - gdb_test "print { 1, g_int, 3 }" \ - " = \\{1, , 3\\}" \ - "build array from unavailable value" + gdb_test_no_output "set print object on" - # Note, depends on previous test. - gdb_test "print \$\[1\]" \ - " = " \ - "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" " = " - # 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" " = " - gdb_test "print \$.member" " = " + # no vtable pointer available + gdb_test "print derived_unavail" " = " - # Cast to baseclass, checking the unavailable-ness is propagated. - gdb_test "print (small_struct) g_smallstruct_b" " = " + # vtable pointer available, but nothing else + gdb_test "print derived_partial" \ + " = \\(Derived\\) { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex , z = }" - # Same cast, but starting from a non-lazy, value. - gdb_test "print g_smallstruct_b" " = " - gdb_test "print (small_struct) \$" " = " + # whole object available + gdb_test "print derived_whole" \ + " = \\(Derived\\) { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex , 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" " = " + with_test_prefix "print object off" { + gdb_test "print virtualp" " = " - # no vtable pointer available - gdb_test "print derived_unavail" " = " + # no vtable pointer available + gdb_test "print derived_unavail" \ + " = " - # vtable pointer available, but nothing else - gdb_test "print derived_partial" \ - " = \\(Derived\\) { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex , z = }" + # vtable pointer available, but nothing else + gdb_test "print derived_partial" \ + " = { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex , z = }" - # whole object available - gdb_test "print derived_whole" \ - " = \\(Derived\\) { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex , z = 4}" - } + # whole object available + gdb_test "print derived_whole" \ + " = { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex , z = 4}" + } + + # An instance of a virtual class where we collected everything but + # the vptr. + gdb_test "print virtual_partial" \ + " = {_vptr.Virtual = , 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" " = " + set testline [gdb_get_line_number "set globals_test_func tracepoint here"] - # no vtable pointer available - gdb_test "print derived_unavail" \ - " = " + gdb_test "trace $testline" \ + "Tracepoint \[0-9\]+ at .*" \ + "set tracepoint" - # vtable pointer available, but nothing else - gdb_test "print derived_partial" \ - " = { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex , z = }" + # 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" \ - " = { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex , 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 = , z = 0}" + gdb_collect_globals_test_1 gdb_test "tfind none" \ "#0 end .*" \