From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11025 invoked by alias); 21 Nov 2005 04:41:18 -0000 Received: (qmail 10714 invoked by uid 22791); 21 Nov 2005 04:41:17 -0000 X-Spam-Check-By: sourceware.org Received: from ausmtp01.au.ibm.com (HELO ausmtp01.au.ibm.com) (202.81.18.186) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 21 Nov 2005 04:41:16 +0000 Received: from sd0208e0.au.ibm.com (d23rh904.au.ibm.com [202.81.18.202]) by ausmtp01.au.ibm.com (8.12.10/8.12.10) with ESMTP id jAL4iRJQ175784 for ; Mon, 21 Nov 2005 15:44:27 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.250.243]) by sd0208e0.au.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id jAL4iB3R183460 for ; Mon, 21 Nov 2005 15:44:11 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.12.11/8.13.3) with ESMTP id jAL4f6Gp013170 for ; Mon, 21 Nov 2005 15:41:07 +1100 Received: from [9.181.133.252] ([9.181.133.252]) by d23av02.au.ibm.com (8.12.11/8.12.11) with ESMTP id jAL4f4Av013127; Mon, 21 Nov 2005 15:41:05 +1100 Date: Mon, 21 Nov 2005 07:28:00 -0000 From: Wu Zhou To: gcc-patches@gcc.gnu.org, gdb-patches@sourceware.org cc: drow@false.org, pinskia@gcc.gnu.org Subject: [RFC] Use DW_CC_program to indicate Fortran main subroutine Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-11/txt/msg00384.txt.bz2 Hello GCC and GDB maintainers, We ever discussed about how to indicate the main subroutine of fortran and java code with DWARF info (GCC PR 23280, 1427 and 10220; GDB PR 822). My point is that DW_CC_program might be the final solution. Here is what DWARF standard said about this: If the semantics of the language of the compilation unit containing the subroutine entry distinguishes between ordinary subroutines and subroutines that can serve as the main program, that is, subroutines that cannot be called directly according to the ordinary calling conventions, then the debugging information entry for such a subroutine may have a calling convention attribute whose value is the constant DW_CC_program. The DW_CC_program value is intended to support Fortran main programs. It is not intended as a way of finding the entry address for the program. Following this, I am doing some experiment with both gfortran and gdb. And I found it does works. The problems stated in GDB PR 822, GCC 10220 are all gone. So I think this might be the proper way. And I post my patches here for review. Any comments and suggestion are highly appreciated. Below is the patch to gcc-4.0.2. I think this method might also work well with gcj, but I am not sure. 2005-11-21 Wu Zhou * dwarf2out.c (add_calling_convention_attribute): If the function name is MAIN__, add a DW_AT_calling_convention attribute with the value being DW_CC_program. --- dwarf2out.c.orig 2005-11-21 17:37:34.000000000 +0800 +++ dwarf2out.c 2005-11-21 17:37:53.000000000 +0800 @@ -10755,6 +10755,13 @@ add_calling_convention_attribute (dw_die value = targetm.dwarf_calling_convention (type); + /* DWARF standard suggests to use DW_CC_program value to indicate Fortran + main programs. Do this when we find the name is 'MAIN__'. + FIXME: Maybe it is better to do this in other way. But I don't figure + out the better way yet. */ + if (!strncmp (get_AT_string (subr_die, DW_AT_name), "MAIN__", 6)) + add_AT_unsigned (subr_die, DW_AT_calling_convention, DW_CC_program); + /* Only add the attribute if the backend requests it, and is not DW_CC_normal. */ if (value && (value != DW_CC_normal)) This is the patch to gdb mainline source. I ever thought of adding these code into read_subroutine_type, but it seems that is too late for setting main name. So I am now adding them into read_partial_die. Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.184.2.2 diff -u -p -r1.184.2.2 dwarf2read.c --- dwarf2read.c 4 Nov 2005 02:58:31 -0000 1.184.2.2 +++ dwarf2read.c 21 Nov 2005 04:11:35 -0000 @@ -5432,6 +5432,13 @@ read_partial_die (struct partial_die_inf part_die->has_stmt_list = 1; part_die->line_offset = DW_UNSND (&attr); break; + case DW_AT_calling_convention: + /* DWARF standard suggests to use value DW_CC_program of attribute + DW_AT_calling_convention to indicate the Fortran main program. + The following code is to check this. */ + if (DW_UNSND (&attr) == DW_CC_program) + set_main_name (part_die->name); + break; default: break; } Regards - Wu Zhou