[patch, doc RFA] New command-line option -na.

Doug Evans dje@google.com
Sat Dec 11 00:47:00 GMT 2010


Hi.

It is useful to be able to disable the auto-loading of scripts
provided by the program.  E.g., because there's a bug in one,
or because you don't trust them.

The capability exists today with "maint set python auto-load on|off",
but that can't be used to disable scripts from a program provided on
the command line.
In order to use that, one has to start gdb without a program,
disable auto-loading, and *then* use the "file" command.  Bleah.

This patch adds a new command-line option, -na, to disable auto-loading.
Since auto-loading is less of a maintenance issue,
and since there's no reason why this has to be python-specific,
I'm renaming "maint set python auto-load on|off" to
"set auto-load-scripts on|off".

I will check this in in two days if there are no objections.
[and pending doc RFA]

2010-12-10  Doug Evans  <dje@google.com>

	New command-line option -na, new command "set auto-load-scripts".
	* NEWS: Mention them.
	main.c (captured_main): Recognize -na.
	(print_gdb_help): Print -na.
	* top.c (auto_load_scripts): New global.
	(init_main): New command "set auto-load-scripts on|off".
	* top.h (auto_load_scripts): Declare.
	* python/py-auto-load.c (gdbpy_auto_load): Delete.
	(load_auto_scripts_for_objfile): Test auto_load_scripts instead of
	gdbpy_auto_load.
	(gdbpy_initialize_auto_load): Delete command
	"maint set python auto-load on|off".

	doc/
	* gdb.texinfo (Mode Options): Document -na.
	(Startup): Document auto-loading of scripts during startup.
	(Auto-loading): Delete "maint set python auto-load on|off".
	Add "set auto-load-scripts on|off".

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.414
diff -u -p -r1.414 NEWS
--- NEWS	10 Dec 2010 20:33:44 -0000	1.414
+++ NEWS	11 Dec 2010 00:23:22 -0000
@@ -8,6 +8,11 @@
 -data-directory DIR	Specify DIR as the "data-directory".
 			This is mostly for testing purposes.
 
+-na			Disable the loading of auto-loaded scripts.
+
+* The "maint set python auto-load on|off" command has been renamed to
+  "set auto-load-scripts on|off".
+
 * GDB has a new command: "set directories".
   It is like the "dir" command except that it replaces the
   source path list instead of augmenting it.
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.88
diff -u -p -r1.88 main.c
--- main.c	7 Dec 2010 17:26:03 -0000	1.88
+++ main.c	11 Dec 2010 00:23:22 -0000
@@ -396,6 +396,7 @@ captured_main (void *data)
       {"silent", no_argument, &quiet, 1},
       {"nx", no_argument, &inhibit_gdbinit, 1},
       {"n", no_argument, &inhibit_gdbinit, 1},
+      {"na", no_argument, &auto_load_scripts, 0},
       {"batch-silent", no_argument, 0, 'B'},
       {"batch", no_argument, &batch_flag, 1},
       {"epoch", no_argument, &epoch_interface, 1},
@@ -985,6 +986,7 @@ Options:\n\n\
   --nx               Do not read "), stream);
   fputs_unfiltered (gdbinit, stream);
   fputs_unfiltered (_(" file.\n\
+  --na		     Do not auto-load scripts provided by the program.\n\
   --quiet            Do not print version number on startup.\n\
   --readnow          Fully read symbol files on first access.\n\
 "), stream);
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.185
diff -u -p -r1.185 top.c
--- top.c	2 Nov 2010 16:48:41 -0000	1.185
+++ top.c	11 Dec 2010 00:23:22 -0000
@@ -88,6 +88,13 @@ char gdbinit[PATH_MAX + 1] = GDBINIT_FIL
 
 int inhibit_gdbinit = 0;
 
+/* User-settable option to enable/disable auto-loading of scripts
+   provided by the program:
+   set auto-load-scripts on|off
+   If zero, then "auto-load" scripts are not loaded,
+   otherwise they are loaded.  */
+int auto_load_scripts = 1;
+
 /* If nonzero, and GDB has been configured to be able to use windows,
    attempt to open them upon startup.  */
 
@@ -1507,6 +1514,7 @@ show_exec_done_display_p (struct ui_file
 Notification of completion for asynchronous execution commands is %s.\n"),
 		    value);
 }
+
 static void
 init_main (void)
 {
@@ -1639,6 +1647,15 @@ When set, GDB uses the specified path to
                            NULL, NULL,
                            &setlist,
                            &showlist);
+
+  add_setshow_boolean_cmd ("auto-load-scripts", class_support,
+			   &auto_load_scripts, _("\
+Enable or disable auto-loading of scripts when an object is opened."), _("\
+Show whether scripts will be auto-loaded when an object is opened."), _("\
+Enables or disables auto-loading of scripts when an object is opened."),
+			   NULL, NULL,
+			   &setlist,
+			   &showlist);
 }
 
 void
Index: top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.22
diff -u -p -r1.22 top.h
--- top.h	7 Apr 2010 16:54:39 -0000	1.22
+++ top.h	11 Dec 2010 00:23:22 -0000
@@ -30,6 +30,7 @@ extern int in_user_command;
 extern int caution;
 extern char gdb_dirbuf[1024];
 extern int inhibit_gdbinit;
+extern int auto_load_scripts;
 extern int epoch_interface;
 extern char gdbinit[];
 
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.779
diff -u -p -r1.779 gdb.texinfo
--- doc/gdb.texinfo	7 Dec 2010 17:26:03 -0000	1.779
+++ doc/gdb.texinfo	11 Dec 2010 00:23:23 -0000
@@ -1025,6 +1025,11 @@ Do not execute commands found in any ini
 options and arguments have been processed.  @xref{Command Files,,Command
 Files}.
 
+@item -na
+@cindex @code{--na}
+Do not auto-load scripts provided by the program.
+@xref{Auto-loading}.
+
 @item -quiet
 @itemx -silent
 @itemx -q
@@ -1263,6 +1268,12 @@ to the program you are debugging, in the
 @value{GDBN}.
 
 @item
+Loads any auto-loaded scripts provided by the program being debugged.
+@xref{Auto-loading}.
+This can be disabled with the @samp{-na} option.
+@xref{Mode Options, -na}.
+
+@item
 Reads command files specified by the @samp{-x} option.  @xref{Command
 Files}, for more details about @value{GDBN} command files.
 
@@ -23114,15 +23125,18 @@ debugging commands and scripts.
 Auto-loading can be enabled or disabled.
 
 @table @code
-@kindex maint set python auto-load
-@item maint set python auto-load [yes|no]
-Enable or disable the Python auto-loading feature.
-
-@kindex maint show python auto-load
-@item maint show python auto-load
-Show whether Python auto-loading is enabled or disabled.
+@kindex set auto-load
+@item set auto-load [yes|no]
+Enable or disable the auto-loading of scripts.
+
+@kindex show auto-load
+@item show auto-load
+Show whether auto-loading is enabled or disabled.
 @end table
 
+Auto-loading can also be disabled with the @samp{-na} command-line option.
+@xref{Mode Options, -na}.
+
 When reading an auto-loaded file, @value{GDBN} sets the
 @dfn{current objfile}.  This is available via the @code{gdb.current_objfile}
 function (@pxref{Objfiles In Python}).  This can be useful for
Index: python/py-auto-load.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-auto-load.c,v
retrieving revision 1.5
diff -u -p -r1.5 py-auto-load.c
--- python/py-auto-load.c	22 Sep 2010 20:00:53 -0000	1.5
+++ python/py-auto-load.c	11 Dec 2010 00:23:23 -0000
@@ -34,7 +34,7 @@
    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
+   Both auto_load_scripts && gdbpy_global_auto_load must be true to enable
    auto-loading.
 
    This flag exists to facilitate deferring auto-loading during start-up
@@ -81,12 +81,6 @@ struct loaded_script_entry
   const char *full_path;
 };
 
-/* 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;
-
 /* Per-program-space data key.  */
 static const struct program_space_data *auto_load_pspace_data;
 
@@ -404,7 +398,7 @@ auto_load_new_objfile (struct objfile *o
 void
 load_auto_scripts_for_objfile (struct objfile *objfile)
 {
-  if (gdbpy_auto_load && gdbpy_global_auto_load)
+  if (auto_load_scripts && gdbpy_global_auto_load)
     {
       auto_load_objfile_script (objfile, GDBPY_AUTO_FILE_NAME);
       auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
@@ -471,15 +465,6 @@ gdbpy_initialize_auto_load (void)
 
   observer_attach_new_objfile (auto_load_new_objfile);
 
-  add_setshow_boolean_cmd ("auto-load", class_maintenance,
-			   &gdbpy_auto_load, _("\
-Enable or disable auto-loading of Python code when an object is opened."), _("\
-Show whether Python code will be auto-loaded when an object is opened."), _("\
-Enables or disables auto-loading of Python code when an object is opened."),
-			   NULL, NULL,
-			   &set_python_list,
-			   &show_python_list);
-
   add_cmd ("section-scripts", class_maintenance, maintenance_print_section_scripts,
 	   _("Print dump of auto-loaded section scripts matching REGEXP."),
 	   &maintenanceprintlist);



More information about the Gdb-patches mailing list