public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 3/3] gdb: Guard against undefined behaviour in mi-vla-fortran.exp
Date: Fri, 11 Dec 2015 21:38:00 -0000	[thread overview]
Message-ID: <42dced1b257e4c5393abf23e4b14c8f0059813ce.1449869723.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1449869721.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1449869721.git.andrew.burgess@embecosm.com>

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 <not associated>.

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  <andrew.burgess@embecosm.com>
 
+	* 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  <andrew.burgess@embecosm.com>
+
 	* 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=\"<not associated>\"" "evaluate not associated vla"
-
-mi_create_varobj_checked pvla2_not_associated pvla2 "<not associated>" \
-  "create local variable pvla2_not_associated"
-mi_gdb_test "581-var-info-type pvla2_not_associated" \
-  "581\\^done,type=\"<not associated>\"" \
-  "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=\"<not associated>\".*${mi_gdb_prompt}$" {
+	pass $test
+
+	mi_create_varobj_checked pvla2_not_associated pvla2 "<not associated>" \
+	    "create local variable pvla2_not_associated"
+	mi_gdb_test "581-var-info-type pvla2_not_associated" \
+	    "581\\^done,type=\"<not associated>\"" \
+	    "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"
-- 
2.5.1

  reply	other threads:[~2015-12-11 21:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-11 21:38 [PATCH 0/2] Problems with gdb.mi/mi-vla-fortran.exp Andrew Burgess
2015-12-11 21:38 ` Andrew Burgess [this message]
2016-01-01 11:08   ` [PATCH 3/3] gdb: Guard against undefined behaviour in mi-vla-fortran.exp Joel Brobecker
2016-01-05 14:15     ` Andrew Burgess
2015-12-11 21:38 ` [PATCH 1/3] gdb: New set/show max-value-size command Andrew Burgess
2016-01-01  9:43   ` Joel Brobecker
2016-01-05 14:12     ` Andrew Burgess
2016-01-05 15:55       ` Pedro Alves
2016-01-05 16:24       ` Eli Zaretskii
2016-01-06 11:41         ` Andrew Burgess
2016-01-20 10:59           ` PING: " Andrew Burgess
2016-01-20 11:23             ` Eli Zaretskii
2016-01-20 15:23             ` Andrew Burgess
2016-01-28 15:11               ` PING #2: " Andrew Burgess
2016-02-01  3:21                 ` Joel Brobecker
2016-02-13 21:40           ` [testsuite patch] testsuite regression: gdb.fortran/vla-value-sub.exp gdb.fortran/vla-value-sub-finish.exp [Re: [PATCH 1/3] gdb: New set/show max-value-size command.] Jan Kratochvil
2016-02-14  0:51             ` Andrew Burgess
2016-02-14  8:20               ` [commit] " Jan Kratochvil
2016-02-14  4:38             ` Joel Brobecker
2015-12-11 21:38 ` [PATCH 2/3] gdb: Set max-value-size before running tests Andrew Burgess
2016-01-01  9:48   ` Joel Brobecker
2016-01-01  9:53     ` Joel Brobecker
2016-01-05 14:14       ` Andrew Burgess
2016-01-01  7:34 ` [PATCH 0/2] Problems with gdb.mi/mi-vla-fortran.exp Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42dced1b257e4c5393abf23e4b14c8f0059813ce.1449869723.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).