* elflink.h (elf_bfd_final_link): Check if dynobj is not NULL
[binutils-gdb.git] / gdb / source.c
index ebc82dc88f3ebdbdda577fe031a040ff366f0fc9..dab794fb731b9140df803d933f21a77c0c6c8efa 100644 (file)
@@ -41,6 +41,7 @@
 #include "gdbtypes.h"
 #include "linespec.h"
 #include "filenames.h"         /* for DOSish file names */
+#include "completer.h"
 #ifdef UI_OUT
 #include "ui-out.h"
 #endif
@@ -153,9 +154,9 @@ select_source_symtab (register struct symtab *s)
 
   /* Make the default place to list be the function `main'
      if one exists.  */
-  if (lookup_symbol ("main", 0, VAR_NAMESPACE, 0, NULL))
+  if (lookup_symbol (main_name (), 0, VAR_NAMESPACE, 0, NULL))
     {
-      sals = decode_line_spec ("main", 1);
+      sals = decode_line_spec (main_name (), 1);
       sal = sals.sals[0];
       xfree (sals.sals);
       current_source_symtab = sal.symtab;
@@ -233,6 +234,7 @@ forget_cached_source_info (void)
 {
   register struct symtab *s;
   register struct objfile *objfile;
+  struct partial_symtab *pst;
 
   for (objfile = object_files; objfile != NULL; objfile = objfile->next)
     {
@@ -240,15 +242,24 @@ forget_cached_source_info (void)
        {
          if (s->line_charpos != NULL)
            {
-             mfree (objfile->md, s->line_charpos);
+             xmfree (objfile->md, s->line_charpos);
              s->line_charpos = NULL;
            }
          if (s->fullname != NULL)
            {
-             mfree (objfile->md, s->fullname);
+             xmfree (objfile->md, s->fullname);
              s->fullname = NULL;
            }
        }
+
+      ALL_OBJFILE_PSYMTABS (objfile, pst)
+      {
+       if (pst->fullname != NULL)
+         {
+           xfree (pst->fullname);
+           pst->fullname = NULL;
+         }
+      }
     }
 }
 
@@ -515,12 +526,14 @@ source_info (char *ignore, int from_tty)
 /*  >>>> This should only allow files of certain types,
    >>>>  eg executable, non-directory */
 int
-openp (char *path, int try_cwd_first, char *string, int mode, int prot,
+openp (const char *path, int try_cwd_first, const char *string,
+       int mode, int prot,
        char **filename_opened)
 {
   register int fd;
   register char *filename;
-  register char *p, *p1;
+  const char *p;
+  const char *p1;
   register int len;
   int alloclen;
 
@@ -534,7 +547,8 @@ openp (char *path, int try_cwd_first, char *string, int mode, int prot,
   if (try_cwd_first || IS_ABSOLUTE_PATH (string))
     {
       int i;
-      filename = string;
+      filename = alloca (strlen (string) + 1);
+      strcpy (filename, string);
       fd = open (filename, mode, prot);
       if (fd >= 0)
        goto done;
@@ -548,11 +562,11 @@ openp (char *path, int try_cwd_first, char *string, int mode, int prot,
     string += 2;
 
   alloclen = strlen (path) + strlen (string) + 2;
-  filename = (char *) alloca (alloclen);
+  filename = alloca (alloclen);
   fd = -1;
   for (p = path; p; p = p1 ? p1 + 1 : 0)
     {
-      p1 = (char *) strchr (p, DIRNAME_SEPARATOR);
+      p1 = strchr (p, DIRNAME_SEPARATOR);
       if (p1)
        len = p1 - p;
       else
@@ -570,7 +584,7 @@ openp (char *path, int try_cwd_first, char *string, int mode, int prot,
          if (newlen > alloclen)
            {
              alloclen = newlen;
-             filename = (char *) alloca (alloclen);
+             filename = alloca (alloclen);
            }
          strcpy (filename, current_directory);
        }
@@ -597,17 +611,19 @@ done:
   if (filename_opened)
     {
       if (fd < 0)
-       *filename_opened = (char *) 0;
+       *filename_opened = NULL;
       else if (IS_ABSOLUTE_PATH (filename))
-       *filename_opened = savestring (filename, strlen (filename));
+       *filename_opened = gdb_realpath (filename);
       else
        {
          /* Beware the // my son, the Emacs barfs, the botch that catch... */
 
-         *filename_opened = concat (current_directory,
+         char *f = concat (current_directory,
            IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
                                     ? "" : SLASH_STRING,
                                     filename, NULL);
+         *filename_opened = gdb_realpath (f);
+         xfree (f);
        }
     }
   /* OBSOLETE #ifdef MPW  */
@@ -667,7 +683,7 @@ int
 open_source_file (struct symtab *s)
 {
   char *path = source_path;
-  char *p;
+  const char *p;
   int result;
   char *fullname;
 
@@ -678,7 +694,7 @@ open_source_file (struct symtab *s)
       if (result >= 0)
        return result;
       /* Didn't work -- free old one, try again. */
-      mfree (s->objfile->md, s->fullname);
+      xmfree (s->objfile->md, s->fullname);
       s->fullname = NULL;
     }
 
@@ -707,7 +723,7 @@ open_source_file (struct symtab *s)
   if (result < 0)
     {
       /* Didn't work.  Try using just the basename. */
-      p = basename (s->filename);
+      p = lbasename (s->filename);
       if (p != s->filename)
        result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname);
     }
@@ -794,8 +810,6 @@ find_source_lines (struct symtab *s, int desc)
 
   if (mtime && mtime < st.st_mtime)
     {
-      if (tui_version)
-       printf_filtered ("\n");
       warning ("Source file is more recent than executable.\n");
     }
 
@@ -1131,31 +1145,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, int noerror)
 void
 print_source_lines (struct symtab *s, int line, int stopline, int noerror)
 {
-#if defined(TUI)
-  if (!tui_version ||
-      m_winPtrIsNull (srcWin) || !srcWin->generic.isVisible)
-    print_source_lines_base (s, line, stopline, noerror);
-  else
-    {
-      TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
-extern void tui_vAddWinToLayout (va_list);
-extern void tui_vUpdateSourceWindowsWithLine (va_list);
-
-      /* Regardless of whether we can open the file,
-         set current_source_symtab. */
-      current_source_symtab = s;
-      current_source_line = line;
-      first_line_listed = line;
-
-      /* make sure that the source window is displayed */
-      tuiDo ((TuiOpaqueFuncPtr) tui_vAddWinToLayout, SRC_WIN);
-
-      tuiDo ((TuiOpaqueFuncPtr) tui_vUpdateSourceWindowsWithLine, s, line);
-      tuiDo ((TuiOpaqueFuncPtr) tui_vUpdateLocatorFilename, s->filename);
-    }
-#else
   print_source_lines_base (s, line, stopline, noerror);
-#endif
 }
 \f
 
@@ -1460,29 +1450,7 @@ forward_search_command (char *regex, int from_tty)
   int line;
   char *msg;
 
-#if defined(TUI)
-  /* 
-     ** If this is the TUI, search from the first line displayed in 
-     ** the source window, otherwise, search from last_line_listed+1 
-     ** in current_source_symtab 
-   */
-  if (!tui_version)
-    line = last_line_listed;
-  else
-    {
-      if (srcWin->generic.isVisible && srcWin->generic.contentSize > 0)
-       line = ((TuiWinContent)
-        srcWin->generic.content)[0]->whichElement.source.lineOrAddr.lineNo;
-      else
-       {
-         printf_filtered ("No source displayed.\nExpression not found.\n");
-         return;
-       }
-    }
-  line++;
-#else
   line = last_line_listed + 1;
-#endif
 
   msg = (char *) re_comp (regex);
   if (msg)
@@ -1554,8 +1522,6 @@ forward_search_command (char *regex, int from_tty)
        {
          /* Match! */
          fclose (stream);
-         if (tui_version)
-           print_source_lines_base (current_source_symtab, line, line + 1, 0);
          print_source_lines (current_source_symtab, line, line + 1, 0);
          set_internalvar (lookup_internalvar ("_"),
                           value_from_longest (builtin_type_int,
@@ -1579,29 +1545,8 @@ reverse_search_command (char *regex, int from_tty)
   register FILE *stream;
   int line;
   char *msg;
-#if defined(TUI)
-  /*
-     ** If this is the TUI, search from the first line displayed in
-     ** the source window, otherwise, search from last_line_listed-1
-     ** in current_source_symtab
-   */
-  if (!tui_version)
-    line = last_line_listed;
-  else
-    {
-      if (srcWin->generic.isVisible && srcWin->generic.contentSize > 0)
-       line = ((TuiWinContent)
-        srcWin->generic.content)[0]->whichElement.source.lineOrAddr.lineNo;
-      else
-       {
-         printf_filtered ("No source displayed.\nExpression not found.\n");
-         return;
-       }
-    }
-  line--;
-#else
+
   line = last_line_listed - 1;
-#endif
 
   msg = (char *) re_comp (regex);
   if (msg)
@@ -1662,8 +1607,6 @@ reverse_search_command (char *regex, int from_tty)
        {
          /* Match! */
          fclose (stream);
-         if (tui_version)
-           print_source_lines_base (current_source_symtab, line, line + 1, 0);
          print_source_lines (current_source_symtab, line, line + 1, 0);
          set_internalvar (lookup_internalvar ("_"),
                           value_from_longest (builtin_type_int,