Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: tromey@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
Date: Fri, 23 Apr 2010 18:15:00 -0000	[thread overview]
Message-ID: <v2re394668d1004231114ua39ec16ch64378ca692fe464f@mail.gmail.com> (raw)
In-Reply-To: <p2re394668d1004201229hc3fa8d1cp72b98c6be7ad81e8@mail.gmail.com>

[-- 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 */

      reply	other threads:[~2010-04-23 18:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-16  7:13 Doug Evans
2010-04-20 19:19 ` Tom Tromey
2010-04-20 19:29   ` Doug Evans
2010-04-23 18:15     ` Doug Evans [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=v2re394668d1004231114ua39ec16ch64378ca692fe464f@mail.gmail.com \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox