python.
* configure: Regenerate.
* main.c: #include "python/python.h".
(captured_main): Defer loading auto-loaded scripts until after
local_gdbinit has been sourced.
* python/py-auto-load.c (gdbpy_global_auto_load): New global.
(load_auto_scripts_for_objfile): New function.
(auto_load_new_objfile): Call it.
* python/python.h (gdbpy_global_auto_load): Declare.
(load_auto_scripts_for_objfile): Declare.
2010-04-23 Doug Evans <dje@google.com>
+ * configure.ac (CONFIG_SRCS): Add py-auto-load.o even if not using
+ python.
+ * configure: Regenerate.
+ * main.c: #include "python/python.h".
+ (captured_main): Defer loading auto-loaded scripts until after
+ local_gdbinit has been sourced.
+ * python/py-auto-load.c (gdbpy_global_auto_load): New global.
+ (load_auto_scripts_for_objfile): New function.
+ (auto_load_new_objfile): Call it.
+ * python/python.h (gdbpy_global_auto_load): Declare.
+ (load_auto_scripts_for_objfile): Declare.
+
Add support for auto-loading scripts from .debug_gdb_scripts section.
* NEWS: Add entry for .debug_gdb_scripts.
* Makefile.in SUBDIR_PYTHON_OBS): Add py-auto-load.o.
fi
else
# Even if Python support is not compiled in, we need to have these files
- # included in order to recognize the GDB command "python".
- CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o"
- CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c python/py-prettyprint.c"
+ # included.
+ CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o py-auto-load.o"
+ CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c \
+ python/py-prettyprint.c python/py-auto-load.c"
fi
fi
else
# Even if Python support is not compiled in, we need to have these files
- # included in order to recognize the GDB command "python".
- CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o"
- CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c python/py-prettyprint.c"
+ # included.
+ CONFIG_OBS="$CONFIG_OBS python.o py-value.o py-prettyprint.o py-auto-load.o"
+ CONFIG_SRCS="$CONFIG_SRCS python/python.c python/py-value.c \
+ python/py-prettyprint.c python/py-auto-load.c"
fi
AC_SUBST(PYTHON_CFLAGS)
#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. */
char *local_gdbinit;
int i;
+ int save_auto_load;
long time_at_startup = get_run_time ();
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)
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)
#include "progspace.h"
#include "objfiles.h"
#include "python.h"
-#include "python-internal.h"
#include "cli/cli-cmds.h"
+/* Internal-use flag to enable/disable auto-loading.
+ This is true if we should auto-load python code when an objfile is opened,
+ false otherwise.
+
+ Both gdbpy_auto_load && gdbpy_global_auto_load must be true to enable
+ auto-loading.
+
+ This flag exists to facilitate deferring auto-loading during start-up
+ until after ./.gdbinit has been read; it may augment the search directories
+ used to find the scripts. */
+int gdbpy_global_auto_load = 1;
+
+#ifdef HAVE_PYTHON
+
+#include "python-internal.h"
+
/* NOTE: It's trivial to also support auto-loading normal gdb scripts.
There has yet to be a need so it's not implemented. */
const char *full_path;
};
-/* This is true if we should auto-load python code when an objfile is opened,
+/* User-settable option to enable/disable auto-loading:
+ maint set python auto-load on|off
+ This is true if we should auto-load python code when an objfile is opened,
false otherwise. */
static int gdbpy_auto_load = 1;
if (!objfile->name)
return;
- if (gdbpy_auto_load)
+ load_auto_scripts_for_objfile (objfile);
+}
+
+/* Load any auto-loaded scripts for OBJFILE. */
+
+void
+load_auto_scripts_for_objfile (struct objfile *objfile)
+{
+ if (gdbpy_auto_load && gdbpy_global_auto_load)
{
auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
_("Print dump of auto-loaded section scripts matching REGEXP."),
&maintenanceprintlist);
}
+
+#else /* ! HAVE_PYTHON */
+
+void
+load_auto_scripts_for_objfile (struct objfile *objfile)
+{
+}
+
+#endif /* ! HAVE_PYTHON */
#include "value.h"
+extern int gdbpy_global_auto_load;
+
void eval_python_from_control_command (struct command_line *);
void source_python_script (FILE *stream, const char *file);
void preserve_python_values (struct objfile *objfile, htab_t copied_types);
+void load_auto_scripts_for_objfile (struct objfile *objfile);
+
#endif /* GDB_PYTHON_H */