public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Mark Wielaard <mjw@redhat.com>
Cc: Stan Shebs <stanshebs@earthlink.net>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Use GCC5/DWARF5 DW_AT_noreturn to mark functions that don't return normally.
Date: Wed, 21 Jan 2015 17:07:00 -0000	[thread overview]
Message-ID: <54BFDCD8.9090709@redhat.com> (raw)
In-Reply-To: <1421366172.26117.29.camel@bordewijk.wildebeest.org>



On 01/15/2015 11:56 PM, Mark Wielaard wrote:

>  create mode 100644 gdb/testsuite/gdb.base/noreturn.c
>  create mode 100644 gdb/testsuite/gdb.base/noreturn.exp

How about "noreturn-return.{c|exp}", to go with noreturn_finish ?

>  create mode 100644 gdb/testsuite/gdb.base/noreturn_finish.c
>  create mode 100644 gdb/testsuite/gdb.base/noreturn_finish.exp

But please use '-' instead of '_':

  gdb/testsuite/gdb.base/noreturn-finish.c
  gdb/testsuite/gdb.base/noreturn-finish.exp

> diff --git a/gdb/testsuite/gdb.base/noreturn.c b/gdb/testsuite/gdb.base/noreturn.c
> new file mode 100644
> index 0000000..e39cf15
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/noreturn.c
> @@ -0,0 +1,13 @@

Please add a copyright header.  Even though some of our old
files don't have it, all new files should, even if the file
is small (so that we don't have to recall adding it back
if the file grows in future).


> +void __attribute__((noreturn))
> +noreturn_func ()

noreturn_func (void)


> +{
> +  while (1)
> +    ;

Please don't make the test loop forever if GDB crashes.
Does e.g., "abort()" like the other test work here too?

> +}
> +
> +int
> +main ()

likewise (void)

> +{
> +  noreturn_func ();
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/noreturn.exp b/gdb/testsuite/gdb.base/noreturn.exp
> new file mode 100644
> index 0000000..885642f
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/noreturn.exp
> @@ -0,0 +1,54 @@
> +# Copyright 2015 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
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +standard_testfile .c

You can drop the ".c", as it's the default.

> +
> +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
> +     untested noreturn.exp
> +     return -1
> +}

Use prepare_for_testing, like:

if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug}] {
    return -1
}


> +
> +proc noreturn_test { } {
> +    global gdb_prompt
> +
> +    if { ! [ runto_main ] } then {
> +	untested noreturn.exp

Use $testfile, like "untested ${testfile}.exp".

> +	return -1
> +    }
> +
> +    gdb_test "break noreturn_func" "Breakpoint \[0123456789\].*" \
> +	    "set break on noreturn_func"
> +    gdb_test "continue" "Breakpoint.* noreturn_func.*" \
> +	    "continue to noreturn_func"

   gdb_breakpoint "noreturn_func"
   gdb_continue_to_breakpoint "noreturn_func"

> +
> +    gdb_test_multiple "return" "return from noreturn_func" {
> +	-re "warning: Function does not return normally to caller" {
> +	    verbose -log "saw warning"
> +	    exp_continue
> +	}
> +	-re "Make noreturn_func return now.*y or n. $" {
> +	    send_gdb "n\n"
> +	    exp_continue
> +	}
> +	-re "Not confirmed.*$gdb_prompt $" {
> +	    pass "noreturn_func return cancelled"
> +	}

Make the test message be the same in all paths, like:

    set test "return from noreturn_func"
    gdb_test_multiple "return" $test {
	-re "warning: Function does not return normally to caller" {
	    verbose -log "saw warning"
	    exp_continue
	}
	-re "Make noreturn_func return now.*y or n. $" {
	    send_gdb "n\n"
	    exp_continue
	}
	-re "Not confirmed.*$gdb_prompt $" {
	    pass $test
	}

> +   }
> +}
> +
> +clean_restart ${binfile}

prepare_for_testing does this for you.

> +
> +set timeout 30

I don't see why this is necessary.  I think this is just a copy/paste?

> +noreturn_test
> diff --git a/gdb/testsuite/gdb.base/noreturn_finish.c b/gdb/testsuite/gdb.base/noreturn_finish.c
> new file mode 100644
> index 0000000..cd52769
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/noreturn_finish.c
> @@ -0,0 +1,14 @@
> +#include <stdlib.h>
> +
> +void __attribute__((noreturn))
> +noreturn_func ()
> +{
> +  abort ();
> +}
> +
> +int
> +main ()
> +{
> +  noreturn_func ();
> +  return 0;
> +}

Same comments apply to noreturn_finish.c|exp.

Otherwise OK.

Thanks,
Pedro Alves

  reply	other threads:[~2015-01-21 17:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-27 14:53 Mark Wielaard
2014-12-04 13:26 ` Mark Wielaard
2014-12-04 14:02 ` Pedro Alves
2014-12-09 10:49   ` Mark Wielaard
2014-12-09 18:57     ` Stan Shebs
2014-12-10 11:25       ` Mark Wielaard
2014-12-12 10:47         ` Pedro Alves
2015-01-15 23:56           ` Mark Wielaard
2015-01-21 17:07             ` Pedro Alves [this message]
2015-01-23 16:42               ` Mark Wielaard
2015-01-24  0:32                 ` Pedro Alves

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=54BFDCD8.9090709@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mjw@redhat.com \
    --cc=stanshebs@earthlink.net \
    /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).