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]

[PATCH]: Fix PR tui/9584 Seg Fault tui Single key mode


Hi!

I've fixed PR 9584 http://sourceware.org/bugzilla/show_bug.cgi?id=9584

In SingleKey mode, a crash occurred if the command that is executed uses
'prompt_for_continue'. What happened is that readline is somehow called
recursively in this case. The gdb command is executed while we are still
in 'rl_callback_read_char' and the call to 'prompt_for_continue' will
clear the readline 'rl_linefunc' handler. The crash then occurs in the top-most
'rl_callback_read_char' because the 'rl_linefunc' was cleared.

I've changed the implementation to insert the gdb command in readline
buffer instead of calling 'execute_command'. With this, commands executed
in SingleKey mode will also appear in gdb's history.

I've committed the patch.

Stephane

Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.14810
diff -u -p -r1.14810 ChangeLog
--- ChangeLog   9 Nov 2012 19:57:55 -0000       1.14810
+++ ChangeLog   10 Nov 2012 12:24:16 -0000
@@ -1,3 +1,10 @@
+2012-11-10  Stephane Carrez  <Stephane.Carrez@gmail.com>
+
+       PR tui/9584
+
+       * tui/tui.c (tui_rl_command_key): Do not call execute_command
+       but insert the command to execute in readline's buffer.
+
 2012-11-09  Tom Tromey  <tromey@redhat.com>

        * gdbarch.sh (target_gdbarch): Remove macro.
Index: tui/tui.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tui.c,v
retrieving revision 1.70
diff -u -p -r1.70 tui.c
--- tui/tui.c   4 Jan 2012 08:27:59 -0000       1.70
+++ tui/tui.c   10 Nov 2012 12:24:16 -0000
@@ -240,12 +240,13 @@ tui_rl_command_key (int count, int key)
     {
       if (tui_commands[i].key == key)
         {
-          /* Must save the command because it can be modified by
-             execute_command.  */
-          char *cmd = alloca (strlen (tui_commands[i].cmd) + 1);
-
-          strcpy (cmd, tui_commands[i].cmd);
-          execute_command (cmd, TRUE);
+          /* Insert the command in the readline buffer.
+             Avoid calling the gdb command here since it creates
+             a possible recursion on readline if prompt_for_continue
+             is called (See PR 9584).  The command will also appear
+             in the readline history which turns out to be better.  */
+          rl_insert_text (tui_commands[i].cmd);
+          rl_newline (1, '\n');
           return 0;
         }
     }


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