From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20546 invoked by alias); 4 Dec 2014 13:26:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 20534 invoked by uid 89); 4 Dec 2014 13:26:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 04 Dec 2014 13:26:33 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sB4DQWTV003723 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 4 Dec 2014 08:26:32 -0500 Received: from bordewijk.wildebeest.org (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sB4DQVsX015822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 4 Dec 2014 08:26:32 -0500 Received: by bordewijk.wildebeest.org (Postfix, from userid 1000) id D9AA48062000; Thu, 4 Dec 2014 14:26:30 +0100 (CET) Message-ID: <1417699590.18974.12.camel@bordewijk.wildebeest.org> Subject: Re: [PATCH] Use GCC5/DWARF5 DW_AT_noreturn to mark functions that don't return normally. From: Mark Wielaard To: gdb-patches@sourceware.org Date: Thu, 04 Dec 2014 13:26:00 -0000 In-Reply-To: <1417099980-31834-1-git-send-email-mjw@redhat.com> References: <1417099980-31834-1-git-send-email-mjw@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 X-SW-Source: 2014-12/txt/msg00087.txt.bz2 On Thu, 2014-11-27 at 15:53 +0100, 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. >=20 > (gdb) finish > Warning. Function endless does not return normally. > Try to finish anyway? (y or n) >=20 > (gdb) return > warning: Function does not return normally to caller! > Make endless return now? (y or n) >=20 > gdb/ChangeLog >=20 > * 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. >=20 > include/ChangeLog >=20 > * dwarf2.def (DW_AT_noreturn): New DWARF5 attribute. >=20 > The dwarf2.h addition and the code to emit the new attribute is already in > the gcc tree. >=20 > OK to commit? Ping. > 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, stru= ct dwarf2_cu *cu) > else > TYPE_CALLING_CONVENTION (ftype) =3D DW_CC_normal; >=20=20 > + /* Record whether the function returns normally to its caller or not > + if the DWARF producer set that information. */ > + attr =3D dwarf2_attr (die, DW_AT_noreturn, cu); > + if (attr && (DW_UNSND (attr) !=3D 0)) > + TYPE_NO_RETURN (ftype) =3D 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. */ > diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h > index 14a1f08..779b728 100644 > --- a/gdb/gdbtypes.h > +++ b/gdb/gdbtypes.h > @@ -1019,9 +1019,16 @@ struct func_type > { > /* * The calling convention for targets supporting multiple ABIs. > Right now this is only fetched from the Dwarf-2 > - DW_AT_calling_convention attribute. */ > + DW_AT_calling_convention attribute. The value is one of the > + DW_CC enum dwarf_calling_convention constants. */ >=20=20 > - unsigned calling_convention; > + unsigned calling_convention : 8; > + > + /* * Whether this function normally returns to its caller. It is > + set from the DW_AT_noreturn attribute if set on the > + DW_TAG_subprogram. */ > + > + unsigned int is_noreturn : 1; >=20=20 > /* * Only those DW_TAG_GNU_call_site's in this function that have > DW_AT_GNU_tail_call set are linked in this list. Function > @@ -1245,6 +1252,7 @@ extern void allocate_gnat_aux_type (struct type *); > #define TYPE_GNAT_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_spec= ific.gnat_stuff > #define TYPE_DESCRIPTIVE_TYPE(thistype) TYPE_GNAT_SPECIFIC(thistype)->de= scriptive_type > #define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type= _specific.func_stuff->calling_convention > +#define TYPE_NO_RETURN(thistype) TYPE_MAIN_TYPE(thistype)->type_specific= .func_stuff->is_noreturn > #define TYPE_TAIL_CALL_LIST(thistype) TYPE_MAIN_TYPE(thistype)->type_spe= cific.func_stuff->tail_call_list > #define TYPE_BASECLASS(thistype,index) TYPE_FIELD_TYPE(thistype, index) > #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_ba= seclasses > diff --git a/gdb/infcmd.c b/gdb/infcmd.c > index 4415b31..8231306 100644 > --- a/gdb/infcmd.c > +++ b/gdb/infcmd.c > @@ -1869,7 +1869,14 @@ finish_command (char *arg, int from_tty) > if (execution_direction =3D=3D EXEC_REVERSE) > printf_filtered (_("Run back to call of ")); > else > - printf_filtered (_("Run till exit from ")); > + { > + if (function !=3D 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 ")); > + } >=20=20 > print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0); > } > diff --git a/gdb/stack.c b/gdb/stack.c > index 2834801..c753005 100644 > --- a/gdb/stack.c > +++ b/gdb/stack.c > @@ -2462,8 +2462,12 @@ return_command (char *retval_exp, int from_tty) > confirmed =3D query (_("%sMake selected stack frame return now? "), > query_prefix); > else > - confirmed =3D 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!"); > + confirmed =3D query (_("%sMake %s return now? "), query_prefix, > + SYMBOL_PRINT_NAME (thisfun)); > + } > if (!confirmed) > error (_("Not confirmed")); > } > diff --git a/include/dwarf2.def b/include/dwarf2.def > index 8ca143c..8533a3e 100644 > --- a/include/dwarf2.def > +++ b/include/dwarf2.def > @@ -308,6 +308,8 @@ DW_AT (DW_AT_data_bit_offset, 0x6b) > DW_AT (DW_AT_const_expr, 0x6c) > DW_AT (DW_AT_enum_class, 0x6d) > DW_AT (DW_AT_linkage_name, 0x6e) > +/* DWARF 5. */ > +DW_AT (DW_AT_noreturn, 0x87) >=20=20 > DW_AT_DUP (DW_AT_lo_user, 0x2000) /* Implementation-defined range start.= */ > DW_AT_DUP (DW_AT_hi_user, 0x3fff) /* Implementation-defined range end. = */ >=20