From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15847 invoked by alias); 19 Oct 2006 08:59:22 -0000 Received: (qmail 15837 invoked by uid 22791); 19 Oct 2006 08:59:21 -0000 X-Spam-Check-By: sourceware.org Received: from viper.snap.net.nz (HELO viper.snap.net.nz) (202.37.101.8) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 19 Oct 2006 08:59:16 +0000 Received: from kahikatea.snap.net.nz (p202-124-124-218.snap.net.nz [202.124.124.218]) by viper.snap.net.nz (Postfix) with ESMTP id 807A27BB420 for ; Thu, 19 Oct 2006 21:59:07 +1300 (NZDT) Received: by kahikatea.snap.net.nz (Postfix, from userid 500) id BCB4CBE444; Thu, 19 Oct 2006 21:56:00 +1300 (NZDT) From: Nick Roberts MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17719.15772.325330.48627@kahikatea.snap.net.nz> Date: Thu, 19 Oct 2006 08:59:00 -0000 To: gdb-patches@sources.redhat.com Subject: [PATCH] PR mi/2077 "set edit off" breaks MI X-Mailer: VM 7.19 under Emacs 22.0.50.27 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-10/txt/msg00239.txt.bz2 This patch is taken out of the async patch. It's probably a good idea to commit the different parts separately anyway. The bug arises because GDB gets confused about the current interpreter when doing "set edit off" (via -interpreter-exec. To see this more clearly, instead of Vladimir's example try: ~"This GDB was configured as \"i686-pc-linux-gnu\"...\n" ~"Using host libthread_db library \"/lib/libthread_db.so.1\".\n" (gdb) start &"start\n" ~"Breakpoint 1 at 0x8048513: file myprog.c, line 67.\n" ~"Starting program: /home/nickrob/myprog \n" ~"main () at myprog.c:67\n" ~"67\t int i, n, m[10] = {0, 1, 2, 3, 4 , 5, 6, 7, 8, 9};\n" ^done (gdb) -exec-next ^running (gdb) *stopped,reason="end-stepping-range",thread-id="0",frame={addr="0x08048574",func="main",args=[],file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"} (gdb) set edit off &"set edit off\n" ^done (gdb) -exec-next &"Undefined command: \"-exec-next\". Try \"help\".\n" and note that the response to the second -exec-next is a CLI one (no ^error). Apple switch interpreters which fixes this bug. Jim Ingham can probably explain more eloquently why it works. I don't know how to give attribution to these changes in the ChangeLog as I can't match them to entries in Apple's. Perhaps Jim can provide the details. Otherwise can I just write?: 2006-10-19 Apple Computer, Inc Or do I need a person/e-mail address? -- Nick http://www.inet.net.nz/~nickrob *** interps.h 18 Dec 2005 11:34:01 +1300 1.10 --- interps.h 19 Oct 2006 11:21:41 +1300 *************** extern struct interp *interp_new (const *** 59,65 **** struct ui_out *uiout, const struct interp_procs *procs); extern void interp_add (struct interp *interp); ! extern int interp_set (struct interp *interp); extern struct interp *interp_lookup (const char *name); extern struct ui_out *interp_ui_out (struct interp *interp); --- 59,66 ---- struct ui_out *uiout, const struct interp_procs *procs); extern void interp_add (struct interp *interp); ! extern struct interp *interp_set (struct interp *interp); ! extern int interp_set_quiet (struct interp *interp, int quiet); extern struct interp *interp_lookup (const char *name); extern struct ui_out *interp_ui_out (struct interp *interp); *** interps.c 18 Sep 2006 16:44:39 +1200 1.18 --- interps.c 19 Oct 2006 11:23:44 +1300 *************** interp_add (struct interp *interp) *** 127,133 **** interpreter back in place and return 0. If we can't restore the old interpreter, then raise an internal error, since we are in pretty bad shape at this point. */ ! int interp_set (struct interp *interp) { struct interp *old_interp = current_interpreter; --- 127,133 ---- interpreter back in place and return 0. If we can't restore the old interpreter, then raise an internal error, since we are in pretty bad shape at this point. */ ! struct interp * interp_set (struct interp *interp) { struct interp *old_interp = current_interpreter; *************** interp_set (struct interp *interp) *** 188,194 **** internal_error (__FILE__, __LINE__, _("Failed to initialize new interp \"%s\" %s"), interp->name, "and could not restore old interp!\n"); ! return 0; } /* Finally, put up the new prompt to show that we are indeed here. --- 188,194 ---- internal_error (__FILE__, __LINE__, _("Failed to initialize new interp \"%s\" %s"), interp->name, "and could not restore old interp!\n"); ! return NULL; } /* Finally, put up the new prompt to show that we are indeed here. *************** interp_set (struct interp *interp) *** 206,212 **** display_gdb_prompt (NULL); } ! return 1; } /* interp_lookup - Looks up the interpreter for NAME. If no such --- 206,218 ---- display_gdb_prompt (NULL); } ! /* If there wasn't any interp before, return the current interp. ! That way if somebody is grabbing the return value and using ! it, it will actually work first time through. */ ! if (old_interp == NULL) ! return current_interpreter; ! else ! return old_interp; } /* interp_lookup - Looks up the interpreter for NAME. If no such *************** interp_quiet_p (struct interp *interp) *** 289,295 **** return current_interpreter->quiet_p; } ! static int interp_set_quiet (struct interp *interp, int quiet) { int old_val = interp->quiet_p; --- 295,301 ---- return current_interpreter->quiet_p; } ! int interp_set_quiet (struct interp *interp, int quiet) { int old_val = interp->quiet_p; *** mi/mi-interp.c 23 Dec 2005 18:57:46 -0000 1.17 --- mi/mi-interp.c 19 Oct 2006 06:40:21 -0000 *************** struct mi_interp *** 48,53 **** --- 48,56 ---- struct interp *mi_interp; }; + /* Points to the current interpreter, used by the mi context callbacks. */ + static struct interp *mi_interp; + /* These are the interpreter setup, etc. functions for the MI interpreter */ static void mi_execute_command_wrapper (char *cmd); static void mi_command_loop (int mi_version); *************** enum mi_cmd_result *** 188,196 **** mi_cmd_interpreter_exec (char *command, char **argv, int argc) { struct interp *interp_to_use; enum mi_cmd_result result = MI_CMD_DONE; int i; ! struct interp_procs *procs; if (argc < 2) { --- 191,200 ---- mi_cmd_interpreter_exec (char *command, char **argv, int argc) { struct interp *interp_to_use; + struct interp *old_interp; enum mi_cmd_result result = MI_CMD_DONE; int i; ! int old_quiet; if (argc < 2) { *************** mi_cmd_interpreter_exec (char *command, *** 211,216 **** --- 215,235 ---- argv[0]); return MI_CMD_ERROR; } + + old_quiet = interp_set_quiet (interp_to_use, 1); + + old_interp = interp_set (interp_to_use); + if (old_interp == NULL) + { + asprintf (&mi_error_message, + "Could not switch to interpreter \"%s\".", argv[0]); + return MI_CMD_ERROR; + } + + /* Set the global mi_interp. We need this so that the hook functions + can leave their results in the mi interpreter, rather than dumping + them to the console. */ + mi_interp = old_interp; /* Insert the MI out hooks, making sure to also call the interpreter's hooks if it has any. */ *************** mi_cmd_interpreter_exec (char *command, *** 254,260 **** --- 273,284 ---- sync_execution = 0; } + /* Now do the switch */ + interp_set (old_interp); + mi_interp = NULL; + mi_remove_notify_hooks (); + interp_set_quiet (interp_to_use, old_quiet); /* Okay, now let's see if the command set the inferior going... Tricky point - have to do this AFTER resetting the interpreter, since