diff --git a/gas/ChangeLog b/gas/ChangeLog
index f3203de3d9d..3df006d8945 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,13 @@
+Wed May 13 10:16:37 1998  Doug Evans  <devans@canuck.cygnus.com>
+
+	* read.c (generate_file_debug,generate_lineno_debug): New functions.
+	(read_a_source_file): Call them.
+	* read.h (stabs_generate_asm_file): Declare.
+	* stabs.c (stabs_generate_asm_file): New function.
+	(generate_asm_file): New function.
+	(stabs_generate_asm_lineno): Move file name handling into
+	generate_asm_file.
+
 start-sanitize-m32rx
 Tue May 12 13:34:12 1998  Nick Clifton  <nickc@cygnus.com>
 
diff --git a/gas/read.c b/gas/read.c
index 8e06d85281c..c9e4461b6c5 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -217,6 +217,8 @@ static segT get_segmented_expression PARAMS ((expressionS *expP));
 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
 static void pobegin PARAMS ((void));
 static int get_line_sb PARAMS ((sb *));
+static void generate_file_debug PARAMS ((void));
+static void generate_lineno_debug PARAMS ((void));
 
 
 void
@@ -499,6 +501,11 @@ read_a_source_file (name)
   listing_newline (NULL);
   register_dependency (name);
 
+  /* Generate debugging information before we've read anything in to denote
+     this file as the "main" source file and not a subordinate one
+     (e.g. N_SO vs N_SOL in stabs).  */
+  generate_file_debug ();
+
   while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
     {				/* We have another line to parse. */
       know (buffer_limit[-1] == '\n');	/* Must have a sentinel. */
@@ -825,30 +832,7 @@ read_a_source_file (name)
 		      c = *input_line_pointer;
 		      *input_line_pointer = '\0';
 
-		      if (debug_type == DEBUG_STABS)
-			stabs_generate_asm_lineno ();
-
-#ifdef OBJ_GENERATE_ASM_LINENO
-#ifdef ECOFF_DEBUGGING
-		      /* ECOFF assemblers automatically generate
-                         debugging information.  FIXME: This should
-                         probably be handled elsewhere.  */
-		      if (debug_type == DEBUG_NONE)
-			{
-			  if (ecoff_no_current_file ())
-			    debug_type = DEBUG_ECOFF;
-			}
-
-		      if (debug_type == DEBUG_ECOFF)
-		        {
-			  unsigned int lineno;
-			  char *s;
-
-			  as_where (&s, &lineno);
-			  OBJ_GENERATE_ASM_LINENO (s, lineno);
-			}
-#endif
-#endif
+		      generate_lineno_debug ();
 
 		      if (macro_defined)
 			{
@@ -4117,7 +4101,7 @@ sizeof_uleb128 (value)
   return size;
 }
 
-inline int
+int
 sizeof_leb128 (value, sign)
      valueT value;
      int sign;
@@ -4882,6 +4866,46 @@ add_include_dir (path)
     include_dir_maxlen = i;
 }				/* add_include_dir() */
 
+/* Output debugging information to denote the source file.  */
+
+static void
+generate_file_debug ()
+{
+  if (debug_type == DEBUG_STABS)
+    stabs_generate_asm_file ();
+}
+
+/* Output line number debugging information for the current source line.  */
+
+static void
+generate_lineno_debug ()
+{
+  if (debug_type == DEBUG_STABS)
+    stabs_generate_asm_lineno ();
+
+#ifdef OBJ_GENERATE_ASM_LINENO
+#ifdef ECOFF_DEBUGGING
+  /* ECOFF assemblers automatically generate
+     debugging information.  FIXME: This should
+     probably be handled elsewhere.  */
+  if (debug_type == DEBUG_NONE)
+    {
+      if (ecoff_no_current_file ())
+	debug_type = DEBUG_ECOFF;
+    }
+
+  if (debug_type == DEBUG_ECOFF)
+    {
+      unsigned int lineno;
+      char *s;
+
+      as_where (&s, &lineno);
+      OBJ_GENERATE_ASM_LINENO (s, lineno);
+    }
+#endif
+#endif
+}
+
 void 
 s_ignore (arg)
      int arg;