This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Another proposal for frontends and queries.


Hi,

I'm starting a new thread in an attempt to get this issue resolved before 7.0.

Three-line recap of the issue:

For some frontends queries are answered automatically by GDB.
Because of this, some actions that the frontends wants to trigger
are automatically cancelled by GDB.

More details, for those less familiar:

When using Eclipse, our connection through GDB is done so that the method
input_from_terminal_p() returns false.  Because of this, all queries are
answered automatically by GDB.  Queries with no default answer, as well
as queries with a default of 'y' are both automatically answered 'y';
but queries that default to 'n' are automatically answered 'n'.

The problem is that in some cases (specifically for PRecord), an
automatic answer of "no" will prevent an operation that the frontend
wants to do, from being performed.  To my knowledge, there is 
currently no way for a frontend to get around this limitation.

The issue if further complicated in the fact that a specific query
can be triggered by different commands.  Specifically, one of the
PRecord queries gets triggered when we attempt to change memory,
which can be from different MI or CLI commands.

Proposals:

One proposal was to add a way to turn off queries for PRecord.
http://sourceware.org/ml/gdb-patches/2009-09/msg00318.html
This was based on the fact that the only other nquery() was for
pending breakpoints, which has its own option to deal with that query.
This solves the current problem but is not future-proof.

Another proposal that was thrown out there was to disable queries
when having started GDB with the MI interpreter.  The idea is that
it would be frontends that would start GDB like that, and frontends
know what they are doing and don't need queries.
http://sourceware.org/ml/gdb/2009-07/msg00113.html
This seems too drastic to me.

Another solution was that when "set confirm" was "off" all queries
would be answered 'y' instead of using their respective default
answer.
http://sourceware.org/ml/gdb/2009-07/msg00150.html
This did not seem very popular.

My latest idea, based on the reactions to the previous suggestions
is to extend "set confirm" and add a new "force" option.
set confirm on/off would remain as before
set confirm force would automatically answer 'y' to all queries.

The patch below illustrates this latest suggestion.
I did the doc changes and NEWS, to help with making this clear.
I will add a Changelog if this solution is selected for inclusion.
(I'm not very comfortable with the declaration of new variables in
this patch, but the patch does illustrates things.)

Thanks for any help to get this resolved.

Marc

### Eclipse Workspace Patch 1.0
#P src
Index: gdb/top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.19
diff -u -r1.19 top.h
--- gdb/top.h	31 Aug 2009 20:18:45 -0000	1.19
+++ gdb/top.h	14 Sep 2009 02:27:12 -0000
@@ -27,7 +27,11 @@
 extern int linesize;
 extern FILE *instream;
 extern int in_user_command;
-extern int caution;
+extern const char *confirm_mode_string;
+extern const char confirm_on[];
+extern const char confirm_off[];
+extern const char confirm_force[];
+
 extern char gdb_dirbuf[1024];
 extern int inhibit_gdbinit;
 extern int epoch_interface;
Index: gdb/top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.171
diff -u -r1.171 top.c
--- gdb/top.c	10 Sep 2009 18:56:45 -0000	1.171
+++ gdb/top.c	14 Sep 2009 02:27:12 -0000
@@ -96,13 +96,25 @@
 
 /* Flag for whether we want all the "from_tty" gubbish printed.  */
 
-int caution = 1;		/* Default is yes, sigh. */
+const char confirm_on[] = "on";
+const char confirm_off[] = "off";
+const char confirm_force[] = "force";
+
+static const char *confirm_kind_names[] = {
+  confirm_on,
+  confirm_off,
+  confirm_force,
+  NULL 
+};
+
+const char *confirm_mode_string = confirm_on;  /* Default is on, sigh. */
+
 static void
-show_caution (struct ui_file *file, int from_tty,
+show_confirm (struct ui_file *file, int from_tty,
 	      struct cmd_list_element *c, const char *value)
 {
   fprintf_filtered (file, _("\
-Whether to confirm potentially dangerous operations is %s.\n"),
+Whether to confirm potentially dangerous operations is set to %s.\n"),
 		    value);
 }
 
@@ -293,8 +305,8 @@
 /* static */ int
 quit_cover (void *s)
 {
-  caution = 0;			/* Throw caution to the wind -- we're exiting.
-				   This prevents asking the user dumb questions.  */
+  confirm_mode_string = confirm_off; /* Throw caution to the wind -- we're exiting.
+					This prevents asking the user dumb questions.  */
   quit_command ((char *) 0, 0);
   return 0;
 }
@@ -444,13 +456,13 @@
       if (c->class == class_user)
 	execute_user_command (c, arg);
       else if (c->type == set_cmd || c->type == show_cmd)
-	do_setshow_command (arg, from_tty & caution, c);
+	do_setshow_command (arg, from_tty && (confirm_mode_string == confirm_on), c);
       else if (!cmd_func_p (c))
 	error (_("That is not a command, just a help topic."));
       else if (deprecated_call_command_hook)
-	deprecated_call_command_hook (c, arg, from_tty & caution);
+	deprecated_call_command_hook (c, arg, from_tty && (confirm_mode_string == confirm_on));
       else
-	cmd_func (c, arg, from_tty & caution);
+	cmd_func (c, arg, from_tty && (confirm_mode_string == confirm_on));
        
       /* If this command has been post-hooked, run the hook last. */
       execute_cmd_post_hook (c);
@@ -1656,12 +1668,19 @@
 			    show_history_filename,
 			    &sethistlist, &showhistlist);
 
-  add_setshow_boolean_cmd ("confirm", class_support, &caution, _("\
+  add_setshow_enum_cmd ("confirm", class_support,
+			confirm_kind_names,
+			&confirm_mode_string, _("\
 Set whether to confirm potentially dangerous operations."), _("\
-Show whether to confirm potentially dangerous operations."), NULL,
-			   NULL,
-			   show_caution,
-			   &setlist, &showlist);
+Show whether to confirm potentially dangerous operations."), _("\
+confirm can be one of:\n\
+  on    - confirm potentially dangerous operations with a query\n\
+  off   - automatically answer queries with the query's default value\n\
+  force - automatically answer queries in the affirmative, so as to perform the operation\n\
+By default, confirm is on."),
+			NULL,
+			show_confirm,
+			&setlist, &showlist);
 
   add_setshow_zinteger_cmd ("annotate", class_obscure, &annotation_level, _("\
 Set annotation_level."), _("\
Index: gdb/NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.330
diff -u -r1.330 NEWS
--- gdb/NEWS	10 Sep 2009 21:02:46 -0000	1.330
+++ gdb/NEWS	14 Sep 2009 02:27:11 -0000
@@ -416,6 +416,15 @@
   answer.  When set to auto (the default), GDB determines which
   mode to use based on the stdin settings.
 
+set confirm (on|off|force)
+show confirm
+  Controls whether GDB should confirm potentially dangerous operations.
+  The 'on' and 'off' settings remain as for the previous release; the
+  new 'force' option is added which will cause GDB to automatically
+  answer 'y' to all queries.  This differs from the 'off' setting in the
+  fact that in the 'off' setting, queries are answered as per their
+  default answer.
+
 * Removed commands
 
 info forks
Index: gdb/utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.219
diff -u -r1.219 utils.c
--- gdb/utils.c	18 Aug 2009 16:17:16 -0000	1.219
+++ gdb/utils.c	14 Sep 2009 02:27:13 -0000
@@ -932,7 +932,7 @@
       /* Default (yes/batch case) is to quit GDB.  When in batch mode
 	 this lessens the likelihood of GDB going into an infinite
 	 loop.  */
-      if (caution == 0)
+      if (confirm_mode_string != confirm_on)
         {
           /* Emit the message and quit.  */
           fputs_unfiltered (reason, gdb_stderr);
@@ -1440,9 +1440,13 @@
       n_string = "[n]";
     }
 
+  /* Automatically answer 'y' if the confirm option is set to 'force' */
+  if (confirm_mode_string == confirm_force)
+    return 1;
+
   /* Automatically answer the default value if the user did not want
      prompts or the command was issued with the server prefix.  */
-  if (! caution || server_command)
+  if ( (confirm_mode_string == confirm_off) || server_command)
     return def_value;
 
   /* If input isn't coming from the user directly, just say what
Index: gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.622
diff -u -r1.622 gdb.texinfo
--- gdb/doc/gdb.texinfo	10 Sep 2009 21:03:07 -0000	1.622
+++ gdb/doc/gdb.texinfo	14 Sep 2009 02:27:30 -0000
@@ -3805,7 +3805,8 @@
 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
 ranges specified as arguments.  If no argument is specified, delete all
 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
-confirm off}).  You can abbreviate this command as @code{d}.
+confirm off} or @code{set confirm force}).  You can abbreviate this 
+command as @code{d}.
 @end table
 
 @node Disabling
@@ -18062,11 +18063,14 @@
 @cindex confirmation
 @cindex stupid questions
 @item set confirm off
-Disables confirmation requests.
+Disables confirmation requests and answers with the default answer for that confirmation.
 
 @item set confirm on
 Enables confirmation requests (the default).
 
+@item set confirm force
+Disables confirmation requests and always answers with the affirmative.
+
 @kindex show confirm
 @item show confirm
 Displays state of confirmation requests.
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]