This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Optify -g switches


Only target switches are done the old way now.

Neil.

	* common.opt: Add debug switches.
	* flags.h (use_gnu_debug_info_extensions): Boolify.
	* opts.c (write_symbols, debug_info_level,
	use_gnu_debug_info_extensions): Move from toplev.c.
	(set_debug_level): New.
	(common_handle_options): Handle debug switches.
	(print_help): Display target options directly.
	* toplev.c (debug_hooks): Don't initialize.
	(write_symbols, debug_info_level,
	use_gnu_debug_info_extensions): Move to opts.c.
	(debug_args, display_help, decode_g_option): Remove.
	(process_options): Set no debug if level zero here,
	and no-debug-hooks.  Error here if impossible debug format selected.
	* toplev.h (display_help, decode_g_option): Remove.

Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.14
diff -u -p -r1.14 common.opt
--- common.opt	19 Jul 2003 08:13:55 -0000	1.14
+++ common.opt	7 Aug 2003 21:15:01 -0000
@@ -709,6 +709,47 @@ Put zero initialized data in the bss sec
 
 g
 Common JoinedOrMissing
+Generate debug information in default format
+
+gcoff
+Common JoinedOrMissing
+Generate debug information in COFF format
+
+gdwarf
+Common JoinedOrMissing
+Generate debug information in DWARF v1 format
+
+gdwarf+
+Common JoinedOrMissing
+Generate debug information in extended DWARF v1 format
+
+gdwarf-2
+Common JoinedOrMissing
+Generate debug information in DWARF v2 format
+
+ggdb
+Common JoinedOrMissing
+Generate debug information in default extended format
+
+gstabs
+Common JoinedOrMissing
+Generate debug information in STABS format
+
+gstabs+
+Common JoinedOrMissing
+Generate debug information in extended STABS format
+
+gvms
+Common JoinedOrMissing
+Generate debug information in VMS format
+
+gxcoff
+Common JoinedOrMissing
+Generate debug information in XCOFF format
+
+gxcoff+
+Common JoinedOrMissing
+Generate debug information in extended XCOFF format
 
 m
 Common Joined
Index: flags.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/flags.h,v
retrieving revision 1.118
diff -u -p -r1.118 flags.h
--- flags.h	1 Jul 2003 05:00:16 -0000	1.118
+++ flags.h	7 Aug 2003 21:15:01 -0000
@@ -55,7 +55,7 @@ extern enum debug_info_level debug_info_
 
 /* Nonzero means use GNU-only extensions in the generated symbolic
    debugging information.  */
-extern int use_gnu_debug_info_extensions;
+extern bool use_gnu_debug_info_extensions;
 
 /* Nonzero means emit debugging information only for symbols which are used.  */
 extern int flag_debug_only_used_symbols;
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.34
diff -u -p -r1.34 opts.c
--- opts.c	3 Aug 2003 22:14:47 -0000	1.34
+++ opts.c	7 Aug 2003 21:15:02 -0000
@@ -128,6 +128,20 @@ bool warn_unused_value;
 /* Hack for cooperation between set_Wunused and set_Wextra.  */
 static bool maybe_warn_unused_parameter;
 
+/* Type(s) of debugging information we are producing (if any).  See
+   flags.h for the definitions of the different possible types of
+   debugging information.  */
+enum debug_info_type write_symbols = NO_DEBUG;
+
+/* Level of debugging information we are producing.  See flags.h for
+   the definitions of the different possible levels.  */
+enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
+
+/* Nonzero means use GNU-only extensions in the generated symbolic
+   debugging information.  Currently, this only has an effect when
+   write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG.  */
+bool use_gnu_debug_info_extensions;
+
 /* Columns of --help display.  */
 static unsigned int columns = 80;
 
@@ -152,6 +166,8 @@ static void print_help (void);
 static void print_param_help (void);
 static void print_filtered_help (unsigned int flag);
 static unsigned int print_switch (const char *text, unsigned int indent);
+static void set_debug_level (enum debug_info_type type, int extended,
+			     const char *arg);
 
 /* Perform a binary search to find which option the command-line INPUT
    matches.  Returns its index in the option array, and N_OPTS
@@ -1383,7 +1399,46 @@ common_handle_option (size_t scode, cons
       break;
 
     case OPT_g:
-      decode_g_option (arg);
+      set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
+      break;
+
+    case OPT_gcoff:
+      set_debug_level (SDB_DEBUG, false, arg);
+      break;
+
+    case OPT_gdwarf:
+      if (*arg)
+	{
+	  error ("use -gdwarf -gN for DWARF v1 level N, "
+		 "and -gdwarf-2 for DWARF v2" );
+	  break;
+	}
+
+      /* Fall through.  */
+    case OPT_gdwarf_:
+      set_debug_level (DWARF_DEBUG, code == OPT_gdwarf_, arg);
+      break;
+
+    case OPT_gdwarf_2:
+      set_debug_level (DWARF2_DEBUG, false, arg);
+      break;
+
+    case OPT_ggdb:
+      set_debug_level (NO_DEBUG, 2, arg);
+      break;
+
+    case OPT_gstabs:
+    case OPT_gstabs_:
+      set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
+      break;
+
+    case OPT_gvms:
+      set_debug_level (VMS_DEBUG, false, arg);
+      break;
+
+    case OPT_gxcoff:
+    case OPT_gxcoff_:
+      set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
       break;
 
     case OPT_m:
@@ -1505,6 +1560,60 @@ fast_math_flags_set_p (void)
 	  && !flag_errno_math);
 }
 
+/* Handle a debug output -g switch.  EXTENDED is true or false to support
+   extended output (2 is special and means "-ggdb" was given).  */
+static void
+set_debug_level (enum debug_info_type type, int extended, const char *arg)
+{
+  static bool type_explicit;
+
+  use_gnu_debug_info_extensions = extended;
+
+  if (type == NO_DEBUG)
+    {
+      if (write_symbols == NO_DEBUG)
+	{
+	  write_symbols = PREFERRED_DEBUGGING_TYPE;
+
+	  if (extended == 2)
+	    {
+#ifdef DWARF2_DEBUGGING_INFO
+	      write_symbols = DWARF2_DEBUG;
+#elif defined DBX_DEBUGGING_INFO
+	      write_symbols = DBX_DEBUG;
+#endif
+	    }
+
+	  if (write_symbols == NO_DEBUG)
+	    warning ("target system does not support debug output");
+	}
+    }
+  else
+    {
+      /* Does it conflict with an already selected type?  */
+      if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
+	error ("debug format \"-g%s\" conflicts with prior selection",
+	       debug_type_names[type]);
+      write_symbols = type;
+      type_explicit = true;
+    }
+
+  /* A debug flag without a level defaults to level 2.  */
+  if (*arg == '\0')
+    {
+      if (!debug_info_level)
+	debug_info_level = 2;
+    }
+  else
+    {
+      debug_info_level = integral_argument (arg);
+      if (debug_info_level == (unsigned int) -1)
+	error ("unrecognised debug output level \"%s\"", arg);
+      else if (debug_info_level > 3)
+	error ("debug output level %s is too high", arg);
+    }
+}
+
 /* Output --help text.  */
 static void
 print_help (void)
@@ -1532,7 +1641,7 @@ print_help (void)
       print_filtered_help (1U << i);
     }
 
-  display_help ();
+  display_target_options ();
 }
 
 /* Print the help for --param.  */
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.816
diff -u -p -r1.816 toplev.c
--- toplev.c	5 Aug 2003 21:15:56 -0000	1.816
+++ toplev.c	7 Aug 2003 21:15:03 -0000
@@ -221,7 +221,7 @@ int target_flags_explicit;
 
 /* Debug hooks - dependent upon command line options.  */
 
-const struct gcc_debug_hooks *debug_hooks = &do_nothing_debug_hooks;
+const struct gcc_debug_hooks *debug_hooks;
 
 /* Describes a dump file.  */
 
@@ -355,21 +355,6 @@ enum graph_dump_types graph_dump_format;
 
 const char *asm_file_name;
 
-/* Type(s) of debugging information we are producing (if any).
-   See flags.h for the definitions of the different possible
-   types of debugging information.  */
-enum debug_info_type write_symbols = NO_DEBUG;
-
-/* Level of debugging information we are producing.  See flags.h
-   for the definitions of the different possible levels.  */
-enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
-
-/* Nonzero means use GNU-only extensions in the generated symbolic
-   debugging information.  */
-/* Currently, this only has an effect when write_symbols is set to
-   DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG.  */
-int use_gnu_debug_info_extensions = 0;
-
 /* Nonzero means do optimizations.  -O.
    Particular numeric values stand for particular amounts of optimization;
    thus, -O2 stores 2 here.  However, the optimizations beyond the basic
@@ -984,46 +969,6 @@ int align_functions_log;
    minimum function alignment.  Zero means no alignment is forced.  */
 int force_align_functions_log;
 
-/* Table of supported debugging formats.  */
-static const struct
-{
-  const char *const arg;
-  /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
-     constant expression, we use NO_DEBUG in its place.  */
-  const enum debug_info_type debug_type;
-  const int use_extensions_p;
-  const char *const description;
-} *da,
-debug_args[] =
-{
-  { "",       NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
-    N_("Generate debugging info in default format") },
-  { "gdb",    NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
-#ifdef DBX_DEBUGGING_INFO
-  { "stabs",  DBX_DEBUG, 0, N_("Generate STABS format debug info") },
-  { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
-#endif
-#ifdef DWARF_DEBUGGING_INFO
-  { "dwarf",  DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
-  { "dwarf+", DWARF_DEBUG, 1,
-    N_("Generate extended DWARF-1 format debug info") },
-#endif
-#ifdef DWARF2_DEBUGGING_INFO
-  { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
-#endif
-#ifdef XCOFF_DEBUGGING_INFO
-  { "xcoff",  XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
-  { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
-#endif
-#ifdef SDB_DEBUGGING_INFO
-  { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
-#endif
-#ifdef VMS_DEBUGGING_INFO
-  { "vms", VMS_DEBUG, 0, N_("Generate VMS format debug info") },
-#endif
-  { 0, 0, 0, 0 }
-};
-
 typedef struct
 {
   const char *const string;
@@ -3620,22 +3565,6 @@ rest_of_compilation (tree decl)
   timevar_pop (TV_REST_OF_COMPILATION);
 }
 
-/* Display help for generic options.  */
-void
-display_help (void)
-{
-  unsigned long i;
-
-  for (i = ARRAY_SIZE (debug_args); i--;)
-    {
-      if (debug_args[i].description != NULL)
-	printf ("  -g%-21s %s\n",
-		debug_args[i].arg, _(debug_args[i].description));
-    }
-
-  display_target_options ();
-}
-
 /* Display help for target options.  */
 void 
 display_target_options (void)
@@ -3769,124 +3698,6 @@ const char *const debug_type_names[] =
   "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
 };
 
-/* Parse a -g... command line switch.  ARG is the value after the -g.
-   It is safe to access 'ARG - 2' to generate the full switch name.
-   Return the number of strings consumed.  */
-
-void
-decode_g_option (const char *arg)
-{
-  static unsigned level = 0;
-  /* A lot of code assumes write_symbols == NO_DEBUG if the
-     debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
-     of what debugging type has been selected).  This records the
-     selected type.  It is an error to specify more than one
-     debugging type.  */
-  static enum debug_info_type selected_debug_type = NO_DEBUG;
-  /* Nonzero if debugging format has been explicitly set.
-     -g and -ggdb don't explicitly set the debugging format so
-     -gdwarf -g3 is equivalent to -gdwarf3.  */
-  static int type_explicitly_set_p = 0;
-
-  /* The maximum admissible debug level value.  */
-  static const unsigned max_debug_level = 3;
-
-  /* Look up ARG in the table.  */
-  for (da = debug_args; da->arg; da++)
-    {
-      const int da_len = strlen (da->arg);
-
-      if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
-	{
-	  enum debug_info_type type = da->debug_type;
-	  const char *p = arg + da_len;
-
-	  if (*p && ! ISDIGIT (*p))
-	    continue;
-
-	  /* A debug flag without a level defaults to level 2.
-	     Note we do not want to call read_integral_parameter
-	     for that case since it will call atoi which
-	     will return zero.
-
-	     ??? We may want to generalize the interface to
-	     read_integral_parameter to better handle this case
-	     if this case shows up often.  */
-	  if (*p)
-	    level = read_integral_parameter (p, 0, max_debug_level + 1);
-	  else
-	    level = (level == 0) ? 2 : level;
-
-	  if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
-	    {
-	      error ("use -gdwarf -g%d for DWARF v1, level %d",
-		     level, level);
-	      if (level == 2)
-		error ("use -gdwarf-2   for DWARF v2");
-	    }
-
-	  if (level > max_debug_level)
-	    {
-	      warning ("\
-ignoring option `%s' due to invalid debug level specification",
-		       arg - 2);
-	      level = debug_info_level;
-	    }
-
-	  if (type == NO_DEBUG)
-	    {
-	      type = PREFERRED_DEBUGGING_TYPE;
-
-	      if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
-		{
-#ifdef DWARF2_DEBUGGING_INFO
-		  type = DWARF2_DEBUG;
-#else
-#ifdef DBX_DEBUGGING_INFO
-		  type = DBX_DEBUG;
-#endif
-#endif
-		}
-	    }
-
-	  if (type == NO_DEBUG)
-	    warning ("`%s': unknown or unsupported -g option", arg - 2);
-
-	  /* Does it conflict with an already selected type?  */
-	  if (type_explicitly_set_p
-	      /* -g/-ggdb don't conflict with anything.  */
-	      && da->debug_type != NO_DEBUG
-	      && type != selected_debug_type)
-	    warning ("`%s' ignored, conflicts with `-g%s'",
-		     arg - 2, debug_type_names[(int) selected_debug_type]);
-	  else
-	    {
-	      /* If the format has already been set, -g/-ggdb
-		 only change the debug level.  */
-	      if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
-		/* Don't change debugging type.  */
-		;
-	      else
-		{
-		  selected_debug_type = type;
-		  type_explicitly_set_p = da->debug_type != NO_DEBUG;
-		}
-
-	      write_symbols = (level == 0
-			       ? NO_DEBUG
-			       : selected_debug_type);
-	      use_gnu_debug_info_extensions = da->use_extensions_p;
-	      debug_info_level = (enum debug_info_level) level;
-	    }
-
-	  break;
-	}
-    }
-
-  if (! da->arg)
-    warning ("`-g%s': unknown or unsupported -g option", arg);
-}
-
 /* Decode -m switches.  */
 /* Decode the switch -mNAME.  */
 
@@ -4336,32 +4147,42 @@ process_options (void)
       profile_flag = 0;
     }
 
+  /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
+     level is 0.  */
+  if (debug_info_level == DINFO_LEVEL_NONE)
+    write_symbols = NO_DEBUG;
+
   /* Now we know write_symbols, set up the debug hooks based on it.
      By default we do nothing for debug output.  */
+  if (write_symbols == NO_DEBUG)
+    debug_hooks = &do_nothing_debug_hooks;
 #if defined(DBX_DEBUGGING_INFO)
-  if (write_symbols == DBX_DEBUG)
+  else if (write_symbols == DBX_DEBUG)
     debug_hooks = &dbx_debug_hooks;
 #endif
 #if defined(XCOFF_DEBUGGING_INFO)
-  if (write_symbols == XCOFF_DEBUG)
+  else if (write_symbols == XCOFF_DEBUG)
     debug_hooks = &xcoff_debug_hooks;
 #endif
 #ifdef SDB_DEBUGGING_INFO
-  if (write_symbols == SDB_DEBUG)
+  else if (write_symbols == SDB_DEBUG)
     debug_hooks = &sdb_debug_hooks;
 #endif
 #ifdef DWARF_DEBUGGING_INFO
-  if (write_symbols == DWARF_DEBUG)
+  else if (write_symbols == DWARF_DEBUG)
     debug_hooks = &dwarf_debug_hooks;
 #endif
 #ifdef DWARF2_DEBUGGING_INFO
-  if (write_symbols == DWARF2_DEBUG)
+  else if (write_symbols == DWARF2_DEBUG)
     debug_hooks = &dwarf2_debug_hooks;
 #endif
 #ifdef VMS_DEBUGGING_INFO
-  if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
+  else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
     debug_hooks = &vmsdbg_debug_hooks;
 #endif
+  else
+    error ("target system does not support the \"%s\" debug format",
+	   debug_type_names[write_symbols]);
 
   /* If auxiliary info generation is desired, open the output file.
      This goes in the same directory as the source file--unlike
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.111
diff -u -p -r1.111 toplev.h
--- toplev.h	5 Aug 2003 21:15:56 -0000	1.111
+++ toplev.h	7 Aug 2003 21:15:03 -0000
@@ -123,7 +123,6 @@ extern int flag_ssa_dce;
 extern int time_report;
 extern int flag_new_regalloc;
 
-extern void display_help (void);
 extern void display_target_options (void);
 extern void print_version (FILE *, const char *);
 extern void set_target_switch (const char *);
@@ -138,9 +137,6 @@ extern void set_fast_math_flags         
 
 /* Handle -d switch.  */
 extern void decode_d_option		(const char *);
-
-/* Handle -g switch.  */
-extern void decode_g_option		(const char *);
 
 /* Return true iff flags are set as if -ffast-math.  */
 extern bool fast_math_flags_set_p	(void);


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