diff options
author | Doug Evans <dje@google.com> | 2010-04-23 18:09:16 +0000 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2010-04-23 18:09:16 +0000 |
commit | 88a1906b0da33e2905cce61e133b67cdde314847 (patch) | |
tree | 8aad3a1bd84d470955e81b5eb1c79efc3ff1f7dd | |
parent | 66d0954266e5613064244015f3963ea617463ecf (diff) | |
download | gdb-88a1906b0da33e2905cce61e133b67cdde314847.zip gdb-88a1906b0da33e2905cce61e133b67cdde314847.tar.gz gdb-88a1906b0da33e2905cce61e133b67cdde314847.tar.bz2 |
* 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.
-rw-r--r-- | gdb/ChangeLog | 12 | ||||
-rwxr-xr-x | gdb/configure | 7 | ||||
-rw-r--r-- | gdb/configure.ac | 7 | ||||
-rw-r--r-- | gdb/main.c | 15 | ||||
-rw-r--r-- | gdb/python/py-auto-load.c | 40 | ||||
-rw-r--r-- | gdb/python/python.h | 4 |
6 files changed, 76 insertions, 9 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b59013f..013f001 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,17 @@ 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. diff --git a/gdb/configure b/gdb/configure index 0f3d7e6..301394f 100755 --- a/gdb/configure +++ b/gdb/configure @@ -9648,9 +9648,10 @@ $as_echo "${PYTHON_CFLAGS}" >&6; } 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 diff --git a/gdb/configure.ac b/gdb/configure.ac index 434c5b4..4704a53 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -701,9 +701,10 @@ if test "${have_libpython}" = yes; then 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) @@ -41,6 +41,7 @@ #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. */ @@ -291,6 +292,7 @@ captured_main (void *data) char *local_gdbinit; int i; + int save_auto_load; long time_at_startup = get_run_time (); @@ -798,6 +800,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 +864,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) diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c index e3b406c..a06c126 100644 --- a/gdb/python/py-auto-load.c +++ b/gdb/python/py-auto-load.c @@ -28,9 +28,24 @@ #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. */ @@ -66,7 +81,9 @@ struct loaded_script_entry 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; @@ -377,7 +394,15 @@ auto_load_new_objfile (struct objfile *objfile) 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); @@ -457,3 +482,12 @@ Enables or disables auto-loading of Python code when an object is opened."), _("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 */ diff --git a/gdb/python/python.h b/gdb/python/python.h index b2a9631..ae808c0 100644 --- a/gdb/python/python.h +++ b/gdb/python/python.h @@ -22,6 +22,8 @@ #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); @@ -34,4 +36,6 @@ int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr, void preserve_python_values (struct objfile *objfile, htab_t copied_types); +void load_auto_scripts_for_objfile (struct objfile *objfile); + #endif /* GDB_PYTHON_H */ |