*** empty log message ***
[binutils-gdb.git] / gdb / main.c
index 170a5b412d12192d126fa3252fcf32cc3fa0953b..c5c712acff8c67608286ec29188e76b2c2e4da3a 100644 (file)
@@ -39,8 +39,9 @@
 
 #include "interps.h"
 #include "main.h"
-
 #include "source.h"
+#include "cli/cli-cmds.h"
+#include "python/python.h"
 
 /* If nonzero, display time usage both at startup and for each command.  */
 
@@ -67,6 +68,10 @@ char *gdb_sysroot = 0;
 /* GDB datadir, used to store data files.  */
 char *gdb_datadir = 0;
 
+/* If gdb was configured with --with-python=/path,
+   the possibly relocated path to python's lib directory.  */
+char *python_libdir = 0;
+
 struct ui_file *gdb_stdout;
 struct ui_file *gdb_stderr;
 struct ui_file *gdb_stdlog;
@@ -142,6 +147,7 @@ relocate_directory (const char *progname, const char *initial, int flag)
   if (*dir)
     {
       char *canon_sysroot = lrealpath (dir);
+
       if (canon_sysroot)
        {
          xfree (dir);
@@ -291,6 +297,7 @@ captured_main (void *data)
   char *local_gdbinit;
 
   int i;
+  int save_auto_load;
 
   long time_at_startup = get_run_time ();
 
@@ -348,6 +355,14 @@ captured_main (void *data)
   gdb_datadir = relocate_directory (argv[0], GDB_DATADIR,
                                    GDB_DATADIR_RELOCATABLE);
 
+#ifdef WITH_PYTHON_PATH
+  /* For later use in helping Python find itself.  */
+  python_libdir = relocate_directory (argv[0],
+                                     concat (WITH_PYTHON_PATH,
+                                             SLASH_STRING, "lib", NULL),
+                                     PYTHON_PATH_RELOCATABLE);
+#endif
+
 #ifdef RELOC_SRCDIR
   add_substitute_path_rule (RELOC_SRCDIR,
                            make_relative_prefix (argv[0], BINDIR,
@@ -740,6 +755,7 @@ Excess command line arguments ignored. (%s%s)\n"),
   {
     /* Find it.  */
     struct interp *interp = interp_lookup (interpreter_p);
+
     if (interp == NULL)
       error (_("Interpreter `%s' unrecognized"), interpreter_p);
     /* Install it.  */
@@ -798,6 +814,11 @@ Excess command line arguments ignored. (%s%s)\n"),
     catch_command_errors (directory_switch, dirarg[i], 0, RETURN_MASK_ALL);
   xfree (dirarg);
 
+  /* Skip auto-loading section-specified scripts until we've sourced
+     local_gdbinit (which is often used to augment the source search path).  */
+  save_auto_load = gdbpy_global_auto_load;
+  gdbpy_global_auto_load = 0;
+
   if (execarg != NULL
       && symarg != NULL
       && strcmp (execarg, symarg) == 0)
@@ -857,6 +878,14 @@ Can't attach to process and specify a core file at the same time."));
   if (local_gdbinit && !inhibit_gdbinit)
     catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
 
+  /* Now that all .gdbinit's have been read and all -d options have been
+     processed, we can read any scripts mentioned in SYMARG.
+     We wait until now because it is common to add to the source search
+     path in local_gdbinit.  */
+  gdbpy_global_auto_load = save_auto_load;
+  if (symfile_objfile != NULL)
+    load_auto_scripts_for_objfile (symfile_objfile);
+
   for (i = 0; i < ncmd; i++)
     {
       if (cmdarg[i].type == CMDARG_FILE)