This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
- From: dje at google dot com (Doug Evans)
- To: gdb-patches at sourceware dot org
- Date: Fri, 16 Apr 2010 00:13:43 -0700 (PDT)
- Subject: [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
This patch is a follow-up to
http://sourceware.org/ml/gdb-patches/2010-04/msg00500.html
The problem being solved is that we want to read in the main symfile
before reading ./.gdbinit: The latter may make use of symbols
in the main symfile.
However, it is common to add to the source search path in ./.gdbinit,
and this search path is also used for scripts, including scripts
mentioned in .debug_gdb_scripts.
So this patch defers auto-loading of scripts in the main symfile
at startup until after ./.gdbinit has been sourced.
Comments?
2010-04-15 Doug Evans <dje@google.com>
* 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_auto_load): Make externally visible.
(load_auto_scripts_for_objfile): New function.
(auto_load_new_objfile): Call it.
* python/python.h (gdbpy_auto_load): Declare.
(load_auto_scripts_for_objfile): Declare.
diff -pN -U 2 ../../p6/src/gdb/./main.c gdb/./main.c
--- ../../p6/src/gdb/./main.c 2010-04-08 23:28:52.000000000 -0700
+++ gdb/./main.c 2010-04-15 21:40:02.000000000 -0700
@@ -42,4 +42,5 @@
#include "source.h"
#include "cli/cli-cmds.h"
+#include "python/python.h"
/* If nonzero, display time usage both at startup and for each command. */
@@ -292,4 +293,5 @@ captured_main (void *data)
int i;
+ int save_auto_load;
long time_at_startup = get_run_time ();
@@ -799,4 +801,9 @@ Excess command line arguments ignored. (
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_auto_load;
+ gdbpy_auto_load = 0;
+
if (execarg != NULL
&& symarg != NULL
@@ -858,4 +865,12 @@ Can't attach to process and specify a co
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_auto_load = save_auto_load;
+ if (symfile_objfile != NULL)
+ load_auto_scripts_for_objfile (symfile_objfile);
+
for (i = 0; i < ncmd; i++)
{
diff -pN -U 2 ../../p6/src/gdb/./python/py-auto-load.c gdb/./python/py-auto-load.c
--- ../../p6/src/gdb/./python/py-auto-load.c 2010-04-15 22:22:54.000000000 -0700
+++ gdb/./python/py-auto-load.c 2010-04-15 23:18:00.000000000 -0700
@@ -69,5 +69,5 @@ struct loaded_script_entry
/* This is true if we should auto-load python code when an objfile is opened,
false otherwise. */
-static int gdbpy_auto_load = 1;
+int gdbpy_auto_load = 1;
/* Per-program-space data key. */
@@ -379,8 +379,14 @@ auto_load_new_objfile (struct objfile *o
if (gdbpy_auto_load)
- {
- auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
- auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
- }
+ load_auto_scripts_for_objfile (objfile);
+}
+
+/* Load any auto-loaded scripts for OBJFILE. */
+
+void
+load_auto_scripts_for_objfile (struct objfile *objfile)
+{
+ auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
+ auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
}
diff -pN -U 2 ../../p6/src/gdb/./python/python.h gdb/./python/python.h
--- ../../p6/src/gdb/./python/python.h 2010-04-15 10:55:05.000000000 -0700
+++ gdb/./python/python.h 2010-04-15 21:39:38.000000000 -0700
@@ -23,4 +23,6 @@
#include "value.h"
+extern int gdbpy_auto_load;
+
void eval_python_from_control_command (struct command_line *);
@@ -35,3 +37,5 @@ int apply_val_pretty_printer (struct typ
void preserve_python_values (struct objfile *objfile, htab_t copied_types);
+void load_auto_scripts_for_objfile (struct objfile *objfile);
+
#endif /* GDB_PYTHON_H */