public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
@ 2010-04-16  7:13 Doug Evans
  2010-04-20 19:19 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Doug Evans @ 2010-04-16  7:13 UTC (permalink / raw)
  To: gdb-patches

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);
 }
 \f
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 */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
  2010-04-16  7:13 [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading Doug Evans
@ 2010-04-20 19:19 ` Tom Tromey
  2010-04-20 19:29   ` Doug Evans
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2010-04-20 19:19 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

>>>>> "Doug" == Doug Evans <dje@google.com> writes:

Doug> So this patch defers auto-loading of scripts in the main symfile
Doug> at startup until after ./.gdbinit has been sourced.

This approach means that disabling auto-loading in ./.gdbinit will not
work.  This seems like something that ought to be documented, at least.

Doug> +/* Load any auto-loaded scripts for OBJFILE.  */
Doug> +
Doug> +void
Doug> +load_auto_scripts_for_objfile (struct objfile *objfile)
Doug> +{
Doug> +  auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
Doug> +  auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
Doug>  }

I suspect you need a dummy version of this function so that the
--disable-python case continues to work.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
  2010-04-20 19:19 ` Tom Tromey
@ 2010-04-20 19:29   ` Doug Evans
  2010-04-23 18:15     ` Doug Evans
  0 siblings, 1 reply; 4+ messages in thread
From: Doug Evans @ 2010-04-20 19:29 UTC (permalink / raw)
  To: tromey; +Cc: gdb-patches

On Tue, Apr 20, 2010 at 12:19 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Doug" == Doug Evans <dje@google.com> writes:
>
> Doug> So this patch defers auto-loading of scripts in the main symfile
> Doug> at startup until after ./.gdbinit has been sourced.
>
> This approach means that disabling auto-loading in ./.gdbinit will not
> work.  This seems like something that ought to be documented, at least.

Or it could be done differently, e.g. set some other flag that
disabled auto-loading and not touch the user-visible one.

> Doug> +/* Load any auto-loaded scripts for OBJFILE.  */
> Doug> +
> Doug> +void
> Doug> +load_auto_scripts_for_objfile (struct objfile *objfile)
> Doug> +{
> Doug> +  auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
> Doug> +  auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
> Doug>  }
>
> I suspect you need a dummy version of this function so that the
> --disable-python case continues to work.

Blech, I thought I had one.  Must have been thinking of something else
at the time.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
  2010-04-20 19:29   ` Doug Evans
@ 2010-04-23 18:15     ` Doug Evans
  0 siblings, 0 replies; 4+ messages in thread
From: Doug Evans @ 2010-04-23 18:15 UTC (permalink / raw)
  To: tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1828 bytes --]

On Tue, Apr 20, 2010 at 12:29 PM, Doug Evans <dje@google.com> wrote:
> On Tue, Apr 20, 2010 at 12:19 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>>> "Doug" == Doug Evans <dje@google.com> writes:
>>
>> Doug> So this patch defers auto-loading of scripts in the main symfile
>> Doug> at startup until after ./.gdbinit has been sourced.
>>
>> This approach means that disabling auto-loading in ./.gdbinit will not
>> work.  This seems like something that ought to be documented, at least.
>
> Or it could be done differently, e.g. set some other flag that
> disabled auto-loading and not touch the user-visible one.
>
>> Doug> +/* Load any auto-loaded scripts for OBJFILE.  */
>> Doug> +
>> Doug> +void
>> Doug> +load_auto_scripts_for_objfile (struct objfile *objfile)
>> Doug> +{
>> Doug> +  auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
>> Doug> +  auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
>> Doug>  }
>>
>> I suspect you need a dummy version of this function so that the
>> --disable-python case continues to work.
>
> Blech, I thought I had one.  Must have been thinking of something else
> at the time.
>
> Thanks.
>

Here's what I checked in.

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.

[-- Attachment #2: gdb-100423-defer-auto-load-2.patch.txt --]
[-- Type: text/plain, Size: 6975 bytes --]

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.

Index: configure
===================================================================
RCS file: /cvs/src/src/gdb/configure,v
retrieving revision 1.301
diff -u -p -r1.301 configure
--- configure	15 Mar 2010 17:03:01 -0000	1.301
+++ configure	23 Apr 2010 17:18:24 -0000
@@ -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
 
 
Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.116
diff -u -p -r1.116 configure.ac
--- configure.ac	15 Mar 2010 17:03:00 -0000	1.116
+++ configure.ac	23 Apr 2010 17:18:24 -0000
@@ -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)
 
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.82
diff -u -p -r1.82 main.c
--- main.c	6 Apr 2010 16:51:16 -0000	1.82
+++ main.c	23 Apr 2010 17:18:24 -0000
@@ -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. (
     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 co
   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)
Index: python/py-auto-load.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-auto-load.c,v
retrieving revision 1.1
diff -u -p -r1.1 py-auto-load.c
--- python/py-auto-load.c	23 Apr 2010 16:20:13 -0000	1.1
+++ python/py-auto-load.c	23 Apr 2010 17:18:24 -0000
@@ -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 *o
   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 Pyth
 	   _("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 */
Index: python/python.h
===================================================================
RCS file: /cvs/src/src/gdb/python/python.h,v
retrieving revision 1.8
diff -u -p -r1.8 python.h
--- python/python.h	15 Apr 2010 17:45:56 -0000	1.8
+++ python/python.h	23 Apr 2010 17:18:24 -0000
@@ -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 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 */

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-23 18:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-16  7:13 [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading Doug Evans
2010-04-20 19:19 ` Tom Tromey
2010-04-20 19:29   ` Doug Evans
2010-04-23 18:15     ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).