Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Mark Wielaard <mjw@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Use GCC5/DWARF5 DW_AT_noreturn to mark functions that don't return normally.
Date: Thu, 04 Dec 2014 14:02:00 -0000	[thread overview]
Message-ID: <5480696F.1060308@redhat.com> (raw)
In-Reply-To: <1417099980-31834-1-git-send-email-mjw@redhat.com>

Hi Mark,

Thanks for doing this.

On 11/27/2014 02:53 PM, Mark Wielaard wrote:
> Add a flag field is_noreturn to struct func_type. Make calling_convention
> a small bit field to not increase the size of the struct. Set is_noreturn
> if the new GCC5/DWARF5 DW_AT_noreturn is set on a DW_TAG_subprogram.
> Use this information to warn the user before doing a finish or return from
> a function that does not return normally to its caller.
> 
> (gdb) finish
> Warning. Function endless does not return normally.
> Try to finish anyway? (y or n)
> 
> (gdb) return
> warning: Function does not return normally to caller!
> Make endless return now? (y or n)

I'd suggest making the warnings a bit more consistent.

- "Warning." vs "warning: "

  Prefer the latter, as that's what the "warning" function uses.

- "." vs "!"

  I'd keep it calm and get rid of the "!".  :-)

> 
> gdb/ChangeLog
> 
> 	* dwarf2read.c (read_subroutine_type): Set TYPE_NO_RETURN from
> 	DW_AT_noreturn.
> 	* gdbtypes.h (struct func_type): Add is_noreturn field flag. Make
> 	calling_convention an 8 bit bit field.
> 	(TYPE_NO_RETURN): New macro.
> 	* infcmd.c (finish_command): Query if function does not return
> 	normally.
> 	* stack.c (return_command): Likewise.
> 
> include/ChangeLog
> 
> 	* dwarf2.def (DW_AT_noreturn): New DWARF5 attribute.

I wonder if we could have a test?  Could e.g., make sure we don't
crash when the user confirms a return in a noreturn function.

> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 36cbbd9..56212e5 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -14312,6 +14312,12 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
>    else
>      TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
>  
> +  /* Record whether the function returns normally to its caller or not
> +     if the DWARF producer set that information.  */
> +  attr = dwarf2_attr (die, DW_AT_noreturn, cu);
> +  if (attr && (DW_UNSND (attr) != 0))

 if (attr != NULL && (DW_UNSND (attr) != 0))

> +    TYPE_NO_RETURN (ftype) = 1;
> +
>    /* We need to add the subroutine type to the die immediately so
>       we don't infinitely recurse when dealing with parameters
>       declared as the same subroutine type.  */



> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -1869,7 +1869,14 @@ finish_command (char *arg, int from_tty)
>        if (execution_direction == EXEC_REVERSE)
>  	printf_filtered (_("Run back to call of "));
>        else
> -	printf_filtered (_("Run till exit from "));
> +	{
> +	  if (function != NULL && TYPE_NO_RETURN (function->type)
> +	      && ! query (_("Warning. Function %s does not return normally.\n"
> +			    "Try to finish anyway? "),
> +			  SYMBOL_PRINT_NAME (function)))
> +	    error (_("Not confirmed."));
> +	  printf_filtered (_("Run till exit from "));
> +	}

No space between "!" and query:

	      && !query ...

> --- a/gdb/stack.c
> +++ b/gdb/stack.c
> @@ -2462,8 +2462,12 @@ return_command (char *retval_exp, int from_tty)
>  	confirmed = query (_("%sMake selected stack frame return now? "),
>  			   query_prefix);
>        else
> -	confirmed = query (_("%sMake %s return now? "), query_prefix,
> -			   SYMBOL_PRINT_NAME (thisfun));
> +	{
> +	  if (TYPE_NO_RETURN (thisfun->type))
> +	    warning ("Function does not return normally to caller!");

i18n / _() .

Thanks,
Pedro Alves


  parent reply	other threads:[~2014-12-04 14:02 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 [this message]
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
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=5480696F.1060308@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mjw@redhat.com \
    /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