This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add -g switch to GAS


Hi Guys,

  I am applying the patch below to add a -g switch to GAS.  This
  switch behaves in the same way as GCC's -g switch, ie it enables the
  generation of debugging information in the format preferred by the
  assembler's target.

  The patch also adds a -gdwarf-2 switch as a synonym for -gdwarf2 so
  that GAS now uses the same nomenclature are GCC.

  A new target macro is included: MD_DEBUG_FORMAT_SELECTOR, which if
  defined by a backend will be called to select the preferred debug
  format.  Otherwise DWARF2 will be selected for ELF targets and STABS
  for others.  The patch does not define any implementations of the
  MD_DEBUG_FORMAT_SELECTOR macro, but these can be added later if
  necessary.

  The patch also clears up the behaviour of the md_parse_option
  function.  This function should always return zero if it did not
  handle the option, and it should not print any messages about the
  option being ignored because there might be further, generic
  processing that can be done.

Cheers
    Nick

gas/ChangeLog
2004-08-17  Nick Clifton  <nickc@redhat.com>

	* as.c (MD_DEBUG_FORMAT_SELECTOR): Provide default definition.
	(show_usage): Add -g.
	(std_longopts): Add --gen-debug.  Alpha sort the table.
	(parse_args): Print an error message if a switch is not handled.
	Handle the -g switch, calling md_debug_format_selector() if
	necessary.
	* NEWS: Mention new feature.
	* doc/as.texinfo: Document new switch.
	* doc/internals.texi: Document behaviour of md_parse_option.
	
	* config/tc-arm.c (md_parse_option): Do not issue an error message
	if the switch is not recognised.
	* config/tc-m68k.c (md_parse_option): Likewise.
	* config/tc-pdp11.c (md_parse_option): Likewise.
	* config/tc-v850.c (md_parse_option): Likewise.

Index: gas/NEWS
===================================================================
RCS file: /cvs/src/src/gas/NEWS,v
retrieving revision 1.63
diff -c -3 -p -r1.63 NEWS
*** gas/NEWS	13 Aug 2004 19:53:51 -0000	1.63
--- gas/NEWS	17 Aug 2004 11:56:11 -0000
***************
*** 1,5 ****
--- 1,8 ----
  -*- text -*-
  
+ * Add a -g command line option to generate debug information in the target's
+   preferred debug format.
+ 
  * Support for the crx-elf target added.
  
  * Support for the sh-symbianelf target added.
Index: gas/as.c
===================================================================
RCS file: /cvs/src/src/gas/as.c,v
retrieving revision 1.52
diff -c -3 -p -r1.52 as.c
*** gas/as.c	13 Aug 2004 19:53:51 -0000	1.52
--- gas/as.c	17 Aug 2004 11:56:11 -0000
*************** int listing;
*** 89,94 ****
--- 89,99 ----
  enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
  int use_gnu_debug_info_extensions = 0;
  
+ #ifndef MD_DEBUG_FORMAT_SELECTOR
+ #define MD_DEBUG_FORMAT_SELECTOR NULL
+ #endif
+ static enum debug_info_type (*md_debug_format_selector) (int *) = MD_DEBUG_FORMAT_SELECTOR;
+ 
  /* Maximum level of macro nesting.  */
  int max_macro_nest = 100;
  
*************** Options:\n\
*** 279,289 ****
    fprintf (stream, _("\
    -f                      skip whitespace and comment preprocessing\n"));
    fprintf (stream, _("\
!   --gstabs                generate stabs debugging information\n"));
    fprintf (stream, _("\
!   --gstabs+               generate stabs debug info with GNU extensions\n"));
    fprintf (stream, _("\
!   --gdwarf2               generate DWARF2 debugging information\n"));
    fprintf (stream, _("\
    --help                  show this message and exit\n"));
    fprintf (stream, _("\
--- 284,296 ----
    fprintf (stream, _("\
    -f                      skip whitespace and comment preprocessing\n"));
    fprintf (stream, _("\
!   -g --gen-debug          generate debugging information\n"));
!   fprintf (stream, _("\
!   --gstabs                generate STABS debugging information\n"));
    fprintf (stream, _("\
!   --gstabs+               generate STABS debug info with GNU extensions\n"));
    fprintf (stream, _("\
!   --gdwarf-2              generate DWARF2 debugging information\n"));
    fprintf (stream, _("\
    --help                  show this message and exit\n"));
    fprintf (stream, _("\
*************** parse_args (int * pargc, char *** pargv)
*** 378,384 ****
      /* -K is not meaningful if .word is not being hacked.  */
      'K',
  #endif
!     'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'f', 'I', ':', 'o', ':',
  #ifndef VMS
      /* -v takes an argument on VMS, so we don't make it a generic
         option.  */
--- 385,391 ----
      /* -K is not meaningful if .word is not being hacked.  */
      'K',
  #endif
!     'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'f', 'g', 'I', ':', 'o', ':',
  #ifndef VMS
      /* -v takes an argument on VMS, so we don't make it a generic
         option.  */
*************** parse_args (int * pargc, char *** pargv)
*** 411,471 ****
        OPTION_DEPFILE,
        OPTION_GSTABS,
        OPTION_GSTABS_PLUS,
        OPTION_STRIP_LOCAL_ABSOLUTE,
        OPTION_TRADITIONAL_FORMAT,
-       OPTION_GDWARF2,
        OPTION_WARN,
        OPTION_TARGET_HELP,
        OPTION_EXECSTACK,
        OPTION_NOEXECSTACK,
        OPTION_ALTERNATE,
        OPTION_WARN_FATAL
      };
    
    static const struct option std_longopts[] =
    {
!     {"help", no_argument, NULL, OPTION_HELP},
!     /* getopt allows abbreviations, so we do this to stop it from
!        treating -k as an abbreviation for --keep-locals.  Some
!        ports use -k to enable PIC assembly.  */
!     {"keep-locals", no_argument, NULL, 'L'},
!     {"keep-locals", no_argument, NULL, 'L'},
!     {"mri", no_argument, NULL, 'M'},
!     {"nocpp", no_argument, NULL, OPTION_NOCPP},
!     {"statistics", no_argument, NULL, OPTION_STATISTICS},
!     {"version", no_argument, NULL, OPTION_VERSION},
!     {"dump-config", no_argument, NULL, OPTION_DUMPCONFIG},
!     {"verbose", no_argument, NULL, OPTION_VERBOSE},
!     {"emulation", required_argument, NULL, OPTION_EMULATION},
!     {"defsym", required_argument, NULL, OPTION_DEFSYM},
      /* New option for extending instruction set (see also -t above).
         The "-t file" or "--itbl file" option extends the basic set of
         valid instructions by reading "file", a text file containing a
         list of instruction formats.  The additional opcodes and their
         formats are added to the built-in set of instructions, and
         mnemonics for new registers may also be defined.  */
!     {"itbl", required_argument, NULL, OPTION_INSTTBL},
!     {"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH},
!     {"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2},
!     {"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH},
!     {"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES},
!     {"MD", required_argument, NULL, OPTION_DEPFILE},
!     {"gstabs", no_argument, NULL, OPTION_GSTABS},
!     {"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS},
!     {"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE},
!     {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
!     {"gdwarf2", no_argument, NULL, OPTION_GDWARF2},
!     {"no-warn", no_argument, NULL, 'W'},
!     {"warn", no_argument, NULL, OPTION_WARN},
!     {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
! #if defined BFD_ASSEMBLER && (defined OBJ_ELF || defined OBJ_MAYBE_ELF)
!     {"execstack", no_argument, NULL, OPTION_EXECSTACK},
!     {"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK},
! #endif
!     {"alternate", no_argument, NULL, OPTION_ALTERNATE},
!     {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
!     /* When you add options here, check that they do not collide with
!        OPTION_MD_BASE.  See as.h.  */
    };
  
    /* Construct the option lists from the standard list and the target
--- 418,485 ----
        OPTION_DEPFILE,
        OPTION_GSTABS,
        OPTION_GSTABS_PLUS,
+       OPTION_GDWARF2,
        OPTION_STRIP_LOCAL_ABSOLUTE,
        OPTION_TRADITIONAL_FORMAT,
        OPTION_WARN,
        OPTION_TARGET_HELP,
        OPTION_EXECSTACK,
        OPTION_NOEXECSTACK,
        OPTION_ALTERNATE,
        OPTION_WARN_FATAL
+     /* When you add options here, check that they do
+        not collide with OPTION_MD_BASE.  See as.h.  */
      };
    
    static const struct option std_longopts[] =
    {
!     /* Note: commas are placed at the start of the line rather than
!        the end of the preceeding line so that it is simpler to
!        selectively add and remove lines from this list.  */
!     {"alternate", no_argument, NULL, OPTION_ALTERNATE}
!     ,{"defsym", required_argument, NULL, OPTION_DEFSYM}
!     ,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}
!     ,{"emulation", required_argument, NULL, OPTION_EMULATION}
! #if defined BFD_ASSEMBLER && (defined OBJ_ELF || defined OBJ_MAYBE_ELF)
!     ,{"execstack", no_argument, NULL, OPTION_EXECSTACK}
!     ,{"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK}
! #endif
!     ,{"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
!     ,{"gdwarf-2", no_argument, NULL, OPTION_GDWARF2}
!     /* GCC uses --gdwarf-2 but GAS uses to use --gdwarf2,
!        so we keep it here for backwards compatibility.  */
!     ,{"gdwarf2", no_argument, NULL, OPTION_GDWARF2}
!     ,{"gen-debug", no_argument, NULL, 'g'}
!     ,{"gstabs", no_argument, NULL, OPTION_GSTABS}
!     ,{"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS}
!     ,{"help", no_argument, NULL, OPTION_HELP}
      /* New option for extending instruction set (see also -t above).
         The "-t file" or "--itbl file" option extends the basic set of
         valid instructions by reading "file", a text file containing a
         list of instruction formats.  The additional opcodes and their
         formats are added to the built-in set of instructions, and
         mnemonics for new registers may also be defined.  */
!     ,{"itbl", required_argument, NULL, OPTION_INSTTBL}
!     /* getopt allows abbreviations, so we do this to stop it from
!        treating -k as an abbreviation for --keep-locals.  Some
!        ports use -k to enable PIC assembly.  */
!     ,{"keep-locals", no_argument, NULL, 'L'}
!     ,{"keep-locals", no_argument, NULL, 'L'}
!     ,{"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH}
!     ,{"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2}
!     ,{"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH}
!     ,{"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES}
!     ,{"MD", required_argument, NULL, OPTION_DEPFILE}
!     ,{"mri", no_argument, NULL, 'M'}
!     ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
!     ,{"no-warn", no_argument, NULL, 'W'}
!     ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
!     ,{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE}
!     ,{"version", no_argument, NULL, OPTION_VERSION}
!     ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
!     ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
!     ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
!     ,{"warn", no_argument, NULL, OPTION_WARN}
    };
  
    /* Construct the option lists from the standard list and the target
*************** parse_args (int * pargc, char *** pargv)
*** 526,531 ****
--- 540,547 ----
  		verbose = 1;
  	      break;
  	    }
+ 	  else
+ 	    as_bad (_("unrecognized option -%c%s"), optc, optarg ? optarg : "");
  	  /* Fall through.  */
  
  	case '?':
*************** the GNU General Public License.  This pr
*** 654,659 ****
--- 670,692 ----
  	  start_dependencies (optarg);
  	  break;
  
+ 	case 'g':
+ 	  /* Some backends, eg Alpha, use the -g switch for their own
+ 	     purposes.  So we check here for an explicit -g and allow
+ 	     the backend to decide if it wants to process it.  */
+ 	  if (   old_argv[optind - 1][1] == 'g'
+ 	      && old_argv[optind - 1][2] == 0
+ 	      && md_parse_option (optc, optarg))
+ 	    continue;
+ 
+ 	  if (md_debug_format_selector)
+ 	    debug_type = md_debug_format_selector (& use_gnu_debug_info_extensions);
+ 	  else if (IS_ELF)
+ 	    debug_type = DEBUG_DWARF2;
+ 	  else
+ 	    debug_type = DEBUG_STABS;
+ 	  break;
+ 
  	case OPTION_GSTABS_PLUS:
  	  use_gnu_debug_info_extensions = 1;
  	  /* Fall through.  */
Index: gas/config/tc-arm.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.c,v
retrieving revision 1.171
diff -c -3 -p -r1.171 tc-arm.c
*** gas/config/tc-arm.c	6 Aug 2004 16:18:07 -0000	1.171
--- gas/config/tc-arm.c	17 Aug 2004 11:56:14 -0000
*************** md_parse_option (c, arg)
*** 13699,13705 ****
  	    }
  	}
  
-       as_bad (_("unrecognized option `-%c%s'"), c, arg ? arg : "");
        return 0;
      }
  
--- 13699,13704 ----
Index: gas/config/tc-m68k.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m68k.c,v
retrieving revision 1.56
diff -c -3 -p -r1.56 tc-m68k.c
*** gas/config/tc-m68k.c	11 Jul 2004 15:20:30 -0000	1.56
--- gas/config/tc-m68k.c	17 Aug 2004 11:56:15 -0000
*************** md_parse_option (int c, char *arg)
*** 7095,7112 ****
  	    if (!strcmp (arg, archs[i].name))
  	      break;
  	  if (i == n_archs)
! 	    {
! 	    unknown:
! 	      as_bad (_("unrecognized option `%s'"), oarg);
! 	      return 0;
! 	    }
  	  arch = archs[i].arch;
  	  if (arch == m68881)
  	    no_68881 = 1;
  	  else if (arch == m68851)
  	    no_68851 = 1;
  	  else
! 	    goto unknown;
  	}
        else
  	{
--- 7095,7109 ----
  	    if (!strcmp (arg, archs[i].name))
  	      break;
  	  if (i == n_archs)
! 	    return 0;
! 
  	  arch = archs[i].arch;
  	  if (arch == m68881)
  	    no_68881 = 1;
  	  else if (arch == m68851)
  	    no_68851 = 1;
  	  else
! 	    return 0;
  	}
        else
  	{
Index: gas/config/tc-pdp11.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-pdp11.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 tc-pdp11.c
*** gas/config/tc-pdp11.c	8 Jun 2002 07:37:15 -0000	1.9
--- gas/config/tc-pdp11.c	17 Aug 2004 11:56:15 -0000
*************** md_parse_option (c, arg)
*** 1347,1354 ****
        break;
      }
  
-   as_bad ("unrecognized option `-%c%s'", c, arg ? arg : "");
- 
    return 0;
  }
  
--- 1347,1352 ----
Index: gas/config/tc-v850.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-v850.c,v
retrieving revision 1.38
diff -c -3 -p -r1.38 tc-v850.c
*** gas/config/tc-v850.c	6 May 2004 11:01:48 -0000	1.38
--- gas/config/tc-v850.c	17 Aug 2004 11:56:16 -0000
*************** md_parse_option (c, arg)
*** 1169,1189 ****
       char *arg;
  {
    if (c != 'm')
!     {
!       if (c != 'a')
! 	/* xgettext:c-format  */
! 	fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
!       return 0;
!     }
  
    if (strcmp (arg, "warn-signed-overflow") == 0)
!     {
!       warn_signed_overflows = TRUE;
!     }
    else if (strcmp (arg, "warn-unsigned-overflow") == 0)
!     {
!       warn_unsigned_overflows = TRUE;
!     }
    else if (strcmp (arg, "v850") == 0)
      {
        machine = 0;
--- 1169,1182 ----
       char *arg;
  {
    if (c != 'm')
!     return 0;
  
    if (strcmp (arg, "warn-signed-overflow") == 0)
!     warn_signed_overflows = TRUE;
! 
    else if (strcmp (arg, "warn-unsigned-overflow") == 0)
!     warn_unsigned_overflows = TRUE;
! 
    else if (strcmp (arg, "v850") == 0)
      {
        machine = 0;
*************** md_parse_option (c, arg)
*** 1211,1221 ****
    else if (strcmp (arg, "relax") == 0)
      v850_relax = 1;
    else
!     {
!       /* xgettext:c-format  */
!       fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
!       return 0;
!     }
  
    return 1;
  }
--- 1204,1210 ----
    else if (strcmp (arg, "relax") == 0)
      v850_relax = 1;
    else
!     return 0;
  
    return 1;
  }
Index: gas/doc/as.texinfo
===================================================================
RCS file: /cvs/src/src/gas/doc/as.texinfo,v
retrieving revision 1.103
diff -c -3 -p -r1.103 as.texinfo
*** gas/doc/as.texinfo	13 Aug 2004 19:53:51 -0000	1.103
--- gas/doc/as.texinfo	17 Aug 2004 11:56:18 -0000
*************** gcc(1), ld(1), and the Info entries for 
*** 227,234 ****
  @smallexample
  @c man begin SYNOPSIS
  @value{AS} [@b{-a}[@b{cdhlns}][=@var{file}]] [@b{--alternate}] [@b{-D}]
!  [@b{--defsym} @var{sym}=@var{val}] [@b{-f}] [@b{--gstabs}] [@b{--gstabs+}]
!  [@b{--gdwarf2}] [@b{--help}] [@b{-I} @var{dir}] [@b{-J}] [@b{-K}] [@b{-L}]
   [@b{--listing-lhs-width}=@var{NUM}] [@b{--listing-lhs-width2}=@var{NUM}]
   [@b{--listing-rhs-width}=@var{NUM}] [@b{--listing-cont-lines}=@var{NUM}]
   [@b{--keep-locals}] [@b{-o} @var{objfile}] [@b{-R}] [@b{--statistics}] [@b{-v}]
--- 227,234 ----
  @smallexample
  @c man begin SYNOPSIS
  @value{AS} [@b{-a}[@b{cdhlns}][=@var{file}]] [@b{--alternate}] [@b{-D}]
!  [@b{--defsym} @var{sym}=@var{val}] [@b{-f}] [@b{-g}] [@b{--gstabs}] [@b{--gstabs+}]
!  [@b{--gdwarf-2}] [@b{--help}] [@b{-I} @var{dir}] [@b{-J}] [@b{-K}] [@b{-L}]
   [@b{--listing-lhs-width}=@var{NUM}] [@b{--listing-lhs-width2}=@var{NUM}]
   [@b{--listing-rhs-width}=@var{NUM}] [@b{--listing-cont-lines}=@var{NUM}]
   [@b{--keep-locals}] [@b{-o} @var{objfile}] [@b{-R}] [@b{--statistics}] [@b{-v}]
*************** indicates a hexadecimal value, and a lea
*** 479,484 ****
--- 479,490 ----
  ``fast''---skip whitespace and comment preprocessing (assume source is
  compiler output).
  
+ @item -g
+ @itemx --gen-debug
+ Generate debugging information for each assembler source line using whichever
+ debug format is preferred by the target.  This currently means either STABS,
+ ECOFF or DWARF2.
+ 
  @item --gstabs
  Generate stabs debugging information for each assembler line.  This
  may help debugging assembler code, if the debugger can handle it.
*************** debuggers crash or refuse to read your p
*** 490,496 ****
  may help debugging assembler code.  Currently the only GNU extension is
  the location of the current working directory at assembling time.
  
! @item --gdwarf2
  Generate DWARF2 debugging information for each assembler line.  This
  may help debugging assembler code, if the debugger can handle it.  Note---this
  option is only supported by some targets, not all of them.
--- 496,502 ----
  may help debugging assembler code.  Currently the only GNU extension is
  the location of the current working directory at assembling time.
  
! @item --gdwarf-2
  Generate DWARF2 debugging information for each assembler line.  This
  may help debugging assembler code, if the debugger can handle it.  Note---this
  option is only supported by some targets, not all of them.
Index: gas/doc/internals.texi
===================================================================
RCS file: /cvs/src/src/gas/doc/internals.texi,v
retrieving revision 1.39
diff -c -3 -p -r1.39 internals.texi
*** gas/doc/internals.texi	9 Feb 2004 12:12:42 -0000	1.39
--- gas/doc/internals.texi	17 Aug 2004 11:56:19 -0000
*************** It should return the size of an address,
*** 1520,1525 ****
--- 1520,1539 ----
  debugging info.  If you don't define this macro, the default definition uses
  the number of bits per address, as defined in @var{bfd}, divided by 8.
  
+ @item   MD_DEBUG_FORMAT_SELECTOR
+ @cindex MD_DEBUG_FORMAT_SELECTOR
+ If defined this macro is the name of a function to be called when the
+ @samp{--gen-debug} switch is detected on the assembler's command line.  The
+ prototype for the function looks like this:
+ 
+ @smallexample
+    enum debug_info_type MD_DEBUG_FORMAT_SELECTOR (int * use_gnu_extensions)
+ @end smallexample
+ 
+ The function should return the debug format that is preferred by the CPU
+ backend.  This format will be used when generating assembler specific debug
+ information.
+ 
  @end table
  
  @node Object format backend

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]