public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 0/2] Problems with gdb.mi/mi-vla-fortran.exp
Date: Fri, 01 Jan 2016 07:34:00 -0000	[thread overview]
Message-ID: <20160101073449.GB12416@adacore.com> (raw)
In-Reply-To: <cover.1449869721.git.andrew.burgess@embecosm.com>

Hello Andrew,

> Given the above mistake, what follows is just undefined behaviour
> kicking in; gdb reads the uninitialised memory, which happens to be
> non-zero, so it believes pvla2 is associated, it then tries to figure
> out what it's associated with, and reads yet more uninitialised memory.
> 
> In this end it figures that pvla2 is pointing at a huge 3G+ array,
> which in the gdb.mi/mi-vla-fortran.exp test we gdb to print.  This
> causes gdb to allocate the 3G+ of memory to hold the contents of the
> value.
> 
> My question is what to do next from the gdb side of things?
> 
> We could leave the test unchanged, arguing that gdb is asking sensible
> questions, and it's gfortran that's getting things wrong.
> 
> Or we could remove, or comment out, the offending test.
> 
> Leaving the test in place unchanged would be a bit of a shame, I know
> that 3G of memory isn't much on a lot of machines, but it's still
> making my experience running the testsuite pretty painful; I can't be
> the only one.
> 
> I think that this issue has highlighted a bigger issue that effects
> gdb, when dealing with languages that support dynamic types, like
> fortran.  An incorrect program can result in gdb having invalid type
> information, it would be nice if this invalid information did not
> cause gdb to do something so obviously wrong that it brings the
> maching running gdb down.
> 
> The following patches are my attempt to address this issue.  The first
> adds a mechansim to stop gdb allocating overly large arrays for value
> contents, the second enables this mechanism withn the test suite,
> while the third makes additional changes to the mi-vla-fortran.exp
> test to prevent additional errors that are a consequence of the above
> issue.
> 
> Thoughts and comments welcome.

Thanks for the detailed analysis!

I agree with you that we have to protect GDB against this kind of
bad data. As it happens, this used to happen all the time with Ada
programs, where dynamic data is common practice, especially back
in the days of stabs. For that, the Ada support code (in ada-lang.c)
introduced a setting called "varsize-limit", and we used it as
a limit for detecting probable issues in the debugging info.
I was sure that we had contributed that setting, but it turns out
that we contributed only the backbone (the code has access to that
setting), but forgot to contribute the command allowing the user to
change it! Arg... For the record, here is the hunk:

    @@ -14209,6 +14464,15 @@ With an argument, catch only exceptions
                         CATCH_TEMPORARY);

       varsize_limit = 65536;
    +  add_setshow_uinteger_cmd ("varsize-limit", class_support,
    +                           &varsize_limit, _("\
    +Set the maximum number of bytes allowed in a dynamic-sized object."), _("\
    +Show the maximum number of bytes allowed in a dynamic-sized object."), _("\
    +Attempts to access an object whose size is not a compile-time constant\n\
    +and exceeds this limit will cause an error."),
    +                           NULL, NULL, &setlist, &showlist);
    +  /* Add this alias to prevent ambiguity in 'set var ...' command. */
    +  add_alias_cmd ("var", "variable", class_vars, 1, &setlist);

       add_info ("exceptions", info_exceptions_command,
                _("\

So, all in all, I agree with the direction you'd like us to take.
I will followup on the patches you sent.

-- 
Joel

      parent reply	other threads:[~2016-01-01  7:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-11 21:38 Andrew Burgess
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
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 3/3] gdb: Guard against undefined behaviour in mi-vla-fortran.exp Andrew Burgess
2016-01-01 11:08   ` Joel Brobecker
2016-01-05 14:15     ` Andrew Burgess
2016-01-01  7:34 ` Joel Brobecker [this message]

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=20160101073449.GB12416@adacore.com \
    --to=brobecker@adacore.com \
    --cc=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).