DWARF Standard


HOME
SPECIFICATIONS
FAQ
ISSUES



070619.1 Chris Quenelle/Michael Eager Identify main function Extension Accepted with modifications Michael Eager


Background:

It may be difficult for a debugger to determine which function
is the logical start of a program.  In Standard C, this is 'main()',
but non-standard C, such as in embedded systems or Windows programs,
may start at different locations, such as 'winmain()'.  Fortran
notably allows the programmer to identify a subroutine with the
keyword 'PROGRAM'.  Some languages like Ada have the starting
function defined outside of the compilation system.

The most common reason to want the main function's name is to set
a breakpoint in it to begin debugging.  But it's also very useful to know
what name was given to that function by the user, so that the name can
be used when printing messages and other output.

There are a variety of implementation specific ways that are mostly
reliable for using the ELF symbol table or other information to figure out
the name (and location) of the main function.  But it's better to record
the information in a portable and reliable way in DWARF.

Proposal:

Define a new attribute, DW_AT_main_subprogram, which may be used
with in a DW_TAG_compilation_unit or DW_TAG_subprogram DIE, to 
identify that the CU contains the starting "main" function of 
a program and the specified subprogram is the "main" function.

In Figure 2, Attribute Names, (page 11), add an entry for 
DW_AT_main_subprogram, with references to "Compilation unit 
contains main subprogram" and "Subroutine is main subprogram".

In Section 3.1.1, Normal and Partial Compilation Unit Entries
(page 41) add the following:

  11. DW_AT_main_subprogram attribute, whose value is a flag, which
  indicates that the compilation unit contains a subprogram which 
  has been identified as the starting function of the program.  If 
  more than one compilation unit contains this flag, any one may be
  the starting function of the program.

  Fortran has a PROGRAM statement which is used to specify and 
  provide a user-supplied name for the main function in a program.

In Section 3.3.1, General Subroutine and Entry Point Information
(page 47) add the following:

  A subprogram entry may have the DW_AT_main_subprogram attribute
  whose value is a flag, which indicates that the subprogram has 
  been identified as the starting function of the program.  If 
  more than one subprogram contains this flag, any one may be 
  the starting function of the program.  

  Fortran has a PROGRAM statement which is used to specify and 
  provide a user-supplied name for the main function in a program.

-------------------------------

Accepted with change to add "may contain" instead of "contains" 
in description of Compilation Unit.


All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2007-2017 by DWARF Standards Committee.