Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: dje@google.com (Doug Evans)
To: gdb-patches@sourceware.org
Subject: [RFA] [2/2] .debug_gdb_scripts: defer main symfile auto-loading
Date: Fri, 16 Apr 2010 07:13:00 -0000	[thread overview]
Message-ID: <20100416071343.DF64E84396@ruffy.mtv.corp.google.com> (raw)

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


             reply	other threads:[~2010-04-16  7:13 UTC|newest]

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

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=20100416071343.DF64E84396@ruffy.mtv.corp.google.com \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    /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