From patchwork Fri Dec 11 21:38:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 9990 Received: (qmail 8930 invoked by alias); 11 Dec 2015 21:38:58 -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 8833 invoked by uid 89); 11 Dec 2015 21:38:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mail-wm0-f42.google.com Received: from mail-wm0-f42.google.com (HELO mail-wm0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 11 Dec 2015 21:38:54 +0000 Received: by wmnn186 with SMTP id n186so49274044wmn.0 for ; Fri, 11 Dec 2015 13:38:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=RAp5ITqKqmV75VSq5ESGNaItG6HkLdwNuv3zFP1pj+U=; b=g4U/QBn4DL/6QvjL0UpnGcvHl74Od4H/wX/WMR7RDffsO/aggaK6MjGXFrG2P2eyjc el+W2uefpTdx28ZQXoROWWNLUz2GkOEu6jbY6aDq4htidD5EGnanSb4WiNZY1x3b/zHJ svqU7y/f2WQk0LPUPvs/kCx/gPfmCIMq+fHKMmW1kaRb1MKIRZQew+xGdtcf7OpkJbbj JGopwJHsfegsK5ttAD0wEZqHzLgUKocDi+qC9ZeQX73kVXmrmQNQLG2B80OrDPP0D/HO iydetBEykuKphtuq92hVHOjxNvV6i7BbKeXKgU2FgZzHIbIKLI+tUGz3H89wZQsTq+2g VyhA== X-Gm-Message-State: ALoCoQlbKG0c8N8OZc3VsKc0HayEOKzmgqfLUKH4TZkEIU740z8cYwXpMswJwkznF1Io/9ElkQdXX1UtFGpHVPF2lOcs6NwBpg== X-Received: by 10.194.58.5 with SMTP id m5mr22463739wjq.31.1449869931325; Fri, 11 Dec 2015 13:38:51 -0800 (PST) Received: from localhost (host86-138-95-213.range86-138.btcentralplus.com. [86.138.95.213]) by smtp.gmail.com with ESMTPSA id c194sm5040775wmd.13.2015.12.11.13.38.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Dec 2015 13:38:50 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdb: Guard against undefined behaviour in mi-vla-fortran.exp Date: Fri, 11 Dec 2015 21:38:37 +0000 Message-Id: <42dced1b257e4c5393abf23e4b14c8f0059813ce.1449869723.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes The test gdb.mi/mi-vla-fortran.exp reveals an issue with the DWARF generated by gfortran. In the test a pointer variable 'pvla2' is created: real, pointer :: pvla2 (:, :) Initially this variable will be unassociated, so something like this: l = associated(pvla2) should return false. In the test gdb stops at a point _before_ pvla2 is associated with anything, and we then try to print pvla2, the expectation is that gdb should reply . The problem is that the data the DWARF directs gdb to read (to identify if the variable is associated or not) is not initialised until the first time pvla2 is accessed. As a result gdb ends up reading uninitialised memory, sometimes this uninitialised memory indicates the variable is associated (when it's not). This first mistake can lead to a cascade of errors, reading uninitialised memory, with the result that gdb builds an invalid type to associate with the variable pvla2. In some cases, this invalid type can be very large, which when we try to print pvla2 causes gdb to allocate a large amount of memory. A recent commit has added 'set max-value-size' to the gdb testsuite start up code, this saves us in some regard, directly trying to print pvla2 will now now error rather than allocate a large amount of memory. However, some of the later tests create a varobj for pvla2, and then ask for the children of that varobj to be displayed. In the case where an invalid type has been computed for pvla2 then the number of children can be wrong, and very big, in which case trying to display all of these children can cause gdb to consume an excessive amount of memory. This commit first detects if printing pvla2 triggers the max-value-size error, if it does then we avoid all the follow on tests relating to the unassociated pvla2, which avoids the second error printing the varobj children. gdb/testsuite/ChangeLog: * gdb.mi/mi-vla-fortran.exp: Add XFAIL for accessing unassociated pointer. Don't perform further tests on the unassociated pointer if the first test fails. --- gdb/testsuite/ChangeLog | 6 +++++ gdb/testsuite/gdb.mi/mi-vla-fortran.exp | 48 ++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0673d01..429e98d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2015-12-11 Andrew Burgess + * gdb.mi/mi-vla-fortran.exp: Add XFAIL for accessing unassociated + pointer. Don't perform further tests on the unassociated pointer + if the first test fails. + +2015-12-11 Andrew Burgess + * lib/gdb.exp (default_gdb_start): Set max-value-size. * lib/mi-support.exp (default_mi_gdb_start): Likewise. * gdb.base/max-value-size.exp: Don't check the initial value. diff --git a/gdb/testsuite/gdb.mi/mi-vla-fortran.exp b/gdb/testsuite/gdb.mi/mi-vla-fortran.exp index 8902ecb..ab697d8 100644 --- a/gdb/testsuite/gdb.mi/mi-vla-fortran.exp +++ b/gdb/testsuite/gdb.mi/mi-vla-fortran.exp @@ -128,24 +128,40 @@ mi_create_breakpoint "-t vla.f90:$bp_lineno" 6 "del" "vla" ".*vla.f90" \ mi_run_cmd mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \ { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno" -mi_gdb_test "580-data-evaluate-expression pvla2" \ - "580\\^done,value=\"\"" "evaluate not associated vla" - -mi_create_varobj_checked pvla2_not_associated pvla2 "" \ - "create local variable pvla2_not_associated" -mi_gdb_test "581-var-info-type pvla2_not_associated" \ - "581\\^done,type=\"\"" \ - "info type variable pvla2_not_associated" -mi_gdb_test "582-var-show-format pvla2_not_associated" \ - "582\\^done,format=\"natural\"" \ - "show format variable pvla2_not_associated" -mi_gdb_test "583-var-evaluate-expression pvla2_not_associated" \ - "583\\^done,value=\"\\\[0\\\]\"" \ - "eval variable pvla2_not_associated" -mi_list_array_varobj_children_with_index "pvla2_not_associated" "0" "1" \ - "real\\\(kind=4\\\)" "get children of pvla2_not_associated" +set test "evaluate not associated vla" +send_gdb "580-data-evaluate-expression pvla2\n" +gdb_expect { + -re "580\\^done,value=\"\".*${mi_gdb_prompt}$" { + pass $test + + mi_create_varobj_checked pvla2_not_associated pvla2 "" \ + "create local variable pvla2_not_associated" + mi_gdb_test "581-var-info-type pvla2_not_associated" \ + "581\\^done,type=\"\"" \ + "info type variable pvla2_not_associated" + mi_gdb_test "582-var-show-format pvla2_not_associated" \ + "582\\^done,format=\"natural\"" \ + "show format variable pvla2_not_associated" + mi_gdb_test "583-var-evaluate-expression pvla2_not_associated" \ + "583\\^done,value=\"\\\[0\\\]\"" \ + "eval variable pvla2_not_associated" + mi_list_array_varobj_children_with_index "pvla2_not_associated" "0" "1" \ + "real\\\(kind=4\\\)" "get children of pvla2_not_associated" + } + -re "580\\^error,msg=\"value contents too large \\(\[0-9\]+ bytes\\).*${mi_gdb_prompt}$" { + # Undefined behaviour in gfortran. + xfail $test + } + -re "${mi_gdb_prompt}$" { + fail $test + } + timeout { + fail "$test (timeout)" + } +} + set bp_lineno [gdb_get_line_number "pvla2-associated"] mi_create_breakpoint "-t vla.f90:$bp_lineno" 7 "del" "vla" ".*vla.f90" \ $bp_lineno $hex "insert breakpoint at line $bp_lineno"