[patch/rfc] Add `interpreter-exec command'

Andrew Cagney
2003-02-04T20:35:13Z

[-- Attachment #1: Type: text/plain, Size: 235 bytes --]

Hello,

This, is the final (?) patch to add the interpreter-exec command to GDB
(read GDB's console from MI).

I'll look to commit it tomorrow, I think everything that needs to be
discussed has already been discussed.

enjoy,
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 29700 bytes --]

2003-02-04 Jim Ingham <jingham@apple.com>
Keith Seitz <keiths@redhat.com>
Elena Zannoni <ezannoni@redhat.com>
Andrew Cagney <ac131313@redhat.com>

* Makefile.in (SUBDIR_CLI_OBS): Add "cli-interp.o".
(SUBDIR_CLI_SRCS): Add "cli/cli-interp.c".
(SUBDIR_MI_OBS): Add "mi-interp.o".
(SUBDIR_MI_SRCS): Add "mi/mi-interp.c".
(SFILES): Add "interps.c".
(COMMON_OBS): Add "interps.o".
(interps_h, mi_main_h): Define.
(interps.o, cli-interp.o, mi-interp.o): Add dependencies.
(mi-main.o, main.o, event-top.o): Update dependencies.
* cli/cli-interp.c: New file.
* interps.h, interps.c: New files.
* top.c: (gdb_init): Don't install the default interpreter, handed
by captured_main.
* main.c: Include "interps.h".
(interpreter_p): Note that it should malloc'ed.
(captured_command_loop): Call current_interp_command_loop.
(captured_main): Initialize interpreter_p to INTERP_CONSOLE. Use
xfree and xstrdup when updating interpreter_p. Install the
default interpreter. Add hack to stop mi1's copyright notice
being encoded.
* event-top.h (gdb_setup_readline): Declare.
(gdb_disable_readline): Declare.
* event-top.c: Include "interps.h".
(display_gdb_prompt): Call current_interp_display_prompt_p.
(gdb_setup_readline): Initialize gdb_stdout, gdb_stderr,
gdb_stdlog, and gdb_stdtarg.
(_initialize_event_loop): Don't call gdb_setup_readline.
* cli-out.c (cli_out_set_stream): New function.
* cli-out.h (cli_out_set_stream): Declare.

Index: mi/ChangeLog
2003-02-04 Jim Ingham <jingham@apple.com>
Keith Seitz <keiths@redhat.com>
Elena Zannoni <ezannoni@redhat.com>
Andrew Cagney <ac131313@redhat.com>

* mi-main.h: New file.
* mi-interp.c: New file.
* mi-main.c: Include "interps.h".
(mi_error_message): Make global.
(mi_input): Delete static function, moved to "mi-interp.c".
(mi_execute_command, mi_execute_command_wrapper): Ditto.
(mi_command_loop, mi1_command_loop, mi2_command_loop): Ditto.
(mi_load_progress): Make non-static.
(mi_error_last_message): New function.
(captured_mi_execute_command): If the interpreter changed, don't
print anything.
(mi_load_progress): Use current_interp_named_p.
(mi_init_ui): Delete function.
(_initialize_mi_main): Don't install the mi interpreter, handled
by "mi-interp.c".
(mi_exec_async_cli_cmd_continuation): Make static.
* mi-console.h (mi_console_file_new): Add `quote' parameter.
* mi-console.c (struct mi_console_file): Add `quote'.
(mi_console_file_new): Add `quote' parameter. Initialize `quote'.
(mi_console_raw_packet): Only quote the output when `quote'.
* mi-cmds.h (mi_cmd_interpreter_exec): Declare.
(mi_error_message, mi_error_last_message): Declare.
(mi_execute_command): Declare.
* mi-cmds.c: Add `interpreter-exec' command.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.323
diff -u -r1.323 Makefile.in
--- Makefile.in 31 Jan 2003 20:43:53 -0000 1.323
+++ Makefile.in 4 Feb 2003 20:27:49 -0000
@@ -146,9 +146,11 @@
SUBDIR_CLI_OBS = \
cli-dump.o \
cli-decode.o cli-script.o cli-cmds.o cli-setshow.o cli-utils.o
+ cli-interp.o
SUBDIR_CLI_SRCS = \
cli/cli-dump.c \
cli/cli-decode.c cli/cli-script.c cli/cli-cmds.c cli/cli-setshow.c \
+ cli/cli-interp.c \
cli/cli-utils.c
SUBDIR_CLI_DEPS =
SUBDIR_CLI_INITS = \
@@ -167,12 +169,14 @@
mi-out.o mi-console.o \
mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
mi-cmd-disas.o \
+ mi-interp.o \
mi-main.o mi-parse.o mi-getopt.o
SUBDIR_MI_SRCS = \
mi/mi-out.c mi/mi-console.c \
mi/mi-cmds.c mi/mi-cmd-env.c \
mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \
mi/mi-cmd-disas.c \
+ mi/mi-interp.c \
mi/mi-main.c mi/mi-parse.c mi/mi-getopt.c
SUBDIR_MI_DEPS =
SUBDIR_MI_INITS = \
@@ -517,6 +521,7 @@
gdbarch.c arch-utils.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \
hpacc-abi.c \
inf-loop.c infcmd.c inflow.c infrun.c \
+ interps.c \
jv-exp.y jv-lang.c jv-valprint.c jv-typeprint.c \
kod.c kod-cisco.c \
language.c linespec.c \
@@ -655,6 +660,7 @@
i387_tdep_h = i387-tdep.h
inf_loop_h = inf-loop.h
inferior_h = inferior.h $(breakpoint_h) $(target_h) $(frame_h)
+interps_h = interps.h
jv_lang_h = jv-lang.h
kod_h = kod.h
language_h = language.h
@@ -740,6 +746,7 @@
mi_cmds_h = $(srcdir)/mi/mi-cmds.h
mi_console_h = $(srcdir)/mi/mi-console.h
mi_getopt_h = $(srcdir)/mi/mi-getopt.h
+mi_main_h = $(srcdir)/mi/mi-main.h
mi_out_h = $(srcdir)/mi/mi-out.h
mi_parse_h = $(srcdir)/mi/mi-parse.h

@@ -816,6 +823,7 @@
source.o values.o eval.o valops.o valarith.o valprint.o printcmd.o \
symtab.o symfile.o symmisc.o linespec.o infcmd.o infrun.o \
expprint.o environ.o stack.o thread.o \
+ interps.o \
macrotab.o macrocmd.o macroexp.o macroscope.o \
event-loop.o event-top.o inf-loop.o completer.o \
gdbarch.o arch-utils.o gdbtypes.o osabi.o copying.o $(DEPFILES) \
@@ -1636,7 +1644,8 @@
event-loop.o: event-loop.c $(defs_h) $(event_loop_h) $(event_top_h) \
$(gdb_string_h)
event-top.o: event-top.c $(defs_h) $(top_h) $(inferior_h) $(target_h) \
- $(terminal_h) $(event_loop_h) $(event_top_h) $(gdbcmd_h) $(readline_h)
+ $(terminal_h) $(event_loop_h) $(event_top_h) $(interps_h) \
+ $(gdbcmd_h)
exec.o: exec.c $(defs_h) $(frame_h) $(inferior_h) $(target_h) $(gdbcmd_h) \
$(language_h) $(symfile_h) $(objfiles_h) $(completer_h) $(value_h) \
$(gdb_string_h) $(gdbcore_h) $(gdb_stat_h) $(xcoffsolib_h) \
@@ -1793,6 +1802,9 @@
$(gdbcore_h) $(command_h) $(gdb_stat_h) $(gdb_wait_h)
infttrace.o: infttrace.c $(defs_h) $(frame_h) $(inferior_h) $(target_h) \
$(gdb_string_h) $(gdb_wait_h) $(command_h) $(gdbcore_h)
+interps.o: interps.c $(defs_h) $(gdbcmd_h) $(ui_out_h) $(event_loop_h) \
+ $(event_top_h) $(interps_h) $(completer_h) $(gdb_string_h) \
+ $(gdb_events_h) $(gdb_assert_h) $(top_h)
irix4-nat.o: irix4-nat.c $(defs_h) $(inferior_h) $(gdbcore_h) $(regcache_h) \
$(gregset_h)
irix5-nat.o: irix5-nat.c $(defs_h) $(inferior_h) $(gdbcore_h) $(target_h) \
@@ -1868,7 +1880,7 @@
$(bcache_h) $(complaints_h)
main.o: main.c $(defs_h) $(top_h) $(target_h) $(inferior_h) $(symfile_h) \
$(gdbcore_h) $(getopt_h) $(gdb_stat_h) $(gdb_string_h) \
- $(event_loop_h) $(ui_out_h) $(main_h)
+ $(event_loop_h) $(ui_out_h) $(interps_h) $(main_h)
maint.o: maint.c $(defs_h) $(command_h) $(gdbcmd_h) $(symtab_h) \
$(gdbtypes_h) $(demangle_h) $(gdbcore_h) $(expression_h) \
$(language_h) $(symfile_h) $(objfiles_h) $(value_h) $(cli_decode_h)
@@ -2311,6 +2323,9 @@
$(cli_decode_h) $(cli_cmds_h) $(value_h) $(completer_h) \
$(cli_dump_h) $(gdb_assert_h) $(target_h) $(readline_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-dump.c
+cli-interp.o: $(srcdir)/cli/cli-interp.c $(defs_h) $(interps_h) $(wrapper_h) \
+ $(event_top_h) $(ui_out_h) $(cli_out_h) $(top_h) $(gdb_string_h)
+ $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-interp.c
cli-script.o: $(srcdir)/cli/cli-script.c $(defs_h) $(value_h) $(language_h) \
$(ui_out_h) $(gdb_string_h) $(top_h) $(cli_cmds_h) $(cli_decode_h) \
$(cli_script_h)
@@ -2495,9 +2510,13 @@
mi-getopt.o: $(srcdir)/mi/mi-getopt.c $(defs_h) $(mi_getopt_h) \
$(gdb_string_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-getopt.c
+mi-interp.o: $(srcdir)/mi/mi-interp.c $(defs_h) $(gdb_string_h) $(interps_h) \
+ $(event_top_h) $(event_loop_h) $(inferior_h) $(ui_out_h) $(top_h) \
+ $(mi_main_h) $(mi_cmds_h) $(mi_out_h) $(mi_console_h)
+ $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-interp.c
mi-main.o: $(srcdir)/mi/mi-main.c $(defs_h) $(target_h) $(inferior_h) \
$(gdb_string_h) $(top_h) $(gdbthread_h) $(mi_cmds_h) $(mi_parse_h) \
- $(mi_getopt_h) $(mi_console_h) $(ui_out_h) $(mi_out_h) \
+ $(mi_getopt_h) $(mi_console_h) $(ui_out_h) $(mi_out_h) $(interps_h) \
$(event_loop_h) $(event_top_h) $(gdbcore_h) $(value_h) $(regcache_h) \
$(gdb_h) $(frame_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-main.c
Index: cli-out.c
===================================================================
RCS file: /cvs/src/src/gdb/cli-out.c,v
retrieving revision 1.14
diff -u -r1.14 cli-out.c
--- cli-out.c 19 Mar 2002 02:51:04 -0000 1.14
+++ cli-out.c 4 Feb 2003 20:27:49 -0000
@@ -365,6 +365,15 @@
return ui_out_new (&cli_ui_out_impl, data, flags);
}

+struct ui_file *
+cli_out_set_stream (struct ui_out *uiout, struct ui_file *stream)
+{
+ struct ui_out_data *data = ui_out_data (uiout);
+ struct ui_file *old = data->stream;
+ data->stream = stream;
+ return old;
+}
+
/* standard gdb initialization hook */
void
_initialize_cli_out (void)
Index: cli-out.h
===================================================================
RCS file: /cvs/src/src/gdb/cli-out.h,v
retrieving revision 1.2
diff -u -r1.2 cli-out.h
--- cli-out.h 6 Mar 2001 08:21:06 -0000 1.2
+++ cli-out.h 4 Feb 2003 20:27:49 -0000
@@ -24,4 +24,7 @@

extern struct ui_out *cli_out_new (struct ui_file *stream);

+extern struct ui_file *cli_out_set_stream (struct ui_out *uiout,
+ struct ui_file *stream);
+
#endif
Index: event-top.c
===================================================================
RCS file: /cvs/src/src/gdb/event-top.c,v
retrieving revision 1.24
diff -u -r1.24 event-top.c
--- event-top.c 5 Nov 2002 22:38:11 -0000 1.24
+++ event-top.c 4 Feb 2003 20:27:49 -0000
@@ -26,6 +26,7 @@
#include "terminal.h" /* for job_control */
#include "event-loop.h"
#include "event-top.h"
+#include "interps.h"
#include <signal.h>

/* For dont_repeat() */
@@ -250,9 +251,9 @@
int prompt_length = 0;
char *gdb_prompt = get_prompt ();

- /* When an alternative interpreter has been installed, do not
- display the comand prompt. */
- if (interpreter_p)
+ /* Each interpreter has its own rules on displaying the command
+ prompt. */
+ if (!current_interp_display_prompt_p ())
return;

if (target_executing && sync_execution)
@@ -1125,6 +1126,11 @@

if (event_loop_p)
{
+ gdb_stdout = stdio_fileopen (stdout);
+ gdb_stderr = stdio_fileopen (stderr);
+ gdb_stdlog = gdb_stderr; /* for moment */
+ gdb_stdtarg = gdb_stderr; /* for moment */
+
/* If the input stream is connected to a terminal, turn on
editing. */
if (ISATTY (instream))
@@ -1197,8 +1203,6 @@
void
_initialize_event_loop (void)
{
- gdb_setup_readline ();
-
/* Tell gdb to use the cli_command_loop as the main loop. */
if (event_loop_p && command_loop_hook == NULL)
command_loop_hook = cli_command_loop;
Index: event-top.h
===================================================================
RCS file: /cvs/src/src/gdb/event-top.h,v
retrieving revision 1.4
diff -u -r1.4 event-top.h
--- event-top.h 27 Nov 2001 04:15:09 -0000 1.4
+++ event-top.h 4 Feb 2003 20:27:49 -0000
@@ -71,6 +71,8 @@
FIXME: these should really go into top.h. */

extern void display_gdb_prompt (char *new_prompt);
+void gdb_setup_readline (void);
+void gdb_disable_readline (void);
extern void async_init_signals (void);
extern void set_async_editing_command (char *args, int from_tty,
struct cmd_list_element *c);
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.24
diff -u -r1.24 main.c
--- main.c 1 Feb 2003 20:51:05 -0000 1.24
+++ main.c 4 Feb 2003 20:27:49 -0000
@@ -1,7 +1,8 @@
/* Top level stuff for GDB, the GNU debugger.
- Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
- 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- Free Software Foundation, Inc.
+
+ Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
+ 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
+ Foundation, Inc.

This file is part of GDB.

@@ -37,6 +38,7 @@
#include "event-loop.h"
#include "ui-out.h"

+#include "interps.h"
#include "main.h"

/* If nonzero, display time usage both at startup and for each command. */
@@ -53,7 +55,9 @@
processes UI events asynchronously. */
int event_loop_p = 1;

-/* Has an interpreter been specified and if so, which. */
+/* The selected interpreter. This will be used as a set command
+ variable, so it should always be malloc'ed - since
+ do_setshow_command will free it. */
char *interpreter_p;

/* Whether this is the command line version or not */
@@ -93,10 +97,7 @@
static int
captured_command_loop (void *data)
{
- if (command_loop_hook == NULL)
- command_loop ();
- else
- command_loop_hook ();
+ current_interp_command_loop ();
/* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
would clean things up (restoring the cleanup chain) to the state
they were just prior to the call. Technically, this means that
@@ -232,6 +233,12 @@
#endif
#endif

+ /* There will always be an interpreter. Either the one passed into
+ this captured main (not yet implemented), or one specified by the
+ user at start up, or the console. Make life easier by always
+ initializing the interpreter to something. */
+ interpreter_p = xstrdup (INTERP_CONSOLE);
+
/* Parse arguments and options. */
{
int c;
@@ -386,7 +393,8 @@
}
#endif /* GDBTK */
case 'i':
- interpreter_p = optarg;
+ xfree (interpreter_p);
+ interpreter_p = xstrdup (optarg);
break;
case 'd':
dirarg[ndir++] = optarg;
@@ -514,7 +522,10 @@
gdb_init (argv[0]);

/* Do these (and anything which might call wrap_here or *_filtered)
- after initialize_all_files. */
+ after initialize_all_files() but before the interpreter has been
+ installed. Otherwize the help/version messages will be eaten by
+ the interpreter's output handler. */
+
if (print_version)
{
print_gdb_version (gdb_stdout);
@@ -530,7 +541,49 @@
exit (0);
}

- if (!quiet)
+ /* FIXME: cagney/2003-02-03: The big hack (part 1 of 2) that lets
+ GDB retain the old MI1 interpreter startup behavior. Output the
+ copyright message before the interpreter is installed. That way
+ it isn't encapsulated in MI output. */
+ if (!quiet && strcmp (interpreter_p, INTERP_MI1) == 0)
+ {
+ /* Print all the junk at the top, with trailing "..." if we are about
+ to read a symbol file (possibly slowly). */
+ print_gdb_version (gdb_stdout);
+ if (symarg)
+ printf_filtered ("..");
+ wrap_here ("");
+ gdb_flush (gdb_stdout); /* Force to screen during slow operations */
+ }
+
+
+ /* Install the default UI. All the interpreters should have had a
+ look at things by now. Initialize the default interpreter. */
+
+ {
+ /* Find it. */
+ struct interp *interp = interp_lookup (interpreter_p);
+ if (interp == NULL)
+ {
+ fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",
+ interpreter_p);
+ exit (1);
+ }
+ /* Install it. */
+ if (!interp_set (interp))
+ {
+ fprintf_unfiltered (gdb_stderr,
+ "Interpreter `%s' failed to initialize.\n",
+ interpreter_p);
+ exit (1);
+ }
+ }
+
+ /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets
+ GDB retain the old MI1 interpreter startup behavior. Output the
+ copyright message after the interpreter is installed when it is
+ any sane interpreter. */
+ if (!quiet && !current_interp_named_p (INTERP_MI1))
{
/* Print all the junk at the top, with trailing "..." if we are about
to read a symbol file (possibly slowly). */
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.70
diff -u -r1.70 top.c
--- top.c 12 Jan 2003 21:38:16 -0000 1.70
+++ top.c 4 Feb 2003 20:27:49 -0000
@@ -2124,19 +2124,4 @@
it wants GDB to revert to the CLI, it should clear init_ui_hook. */
if (init_ui_hook)
init_ui_hook (argv0);
-
- /* Install the default UI */
- if (!init_ui_hook)
- {
- uiout = cli_out_new (gdb_stdout);
-
- /* All the interpreters should have had a look at things by now.
- Initialize the selected interpreter. */
- if (interpreter_p)
- {
- fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",
- interpreter_p);
- exit (1);
- }
- }
}
Index: wrapper.h
===================================================================
RCS file: /cvs/src/src/gdb/wrapper.h,v
retrieving revision 1.12
diff -u -r1.12 wrapper.h
--- wrapper.h 31 Oct 2001 03:16:04 -0000 1.12
+++ wrapper.h 4 Feb 2003 20:27:49 -0000
@@ -21,6 +21,8 @@
#include "gdb.h"

struct value;
+struct expression;
+struct block;

/* Use this struct to pass arguments to wrapper routines. */
struct gdb_wrapper_arguments;
Index: mi/mi-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
retrieving revision 1.9
diff -u -r1.9 mi-cmds.c
--- mi/mi-cmds.c 13 Dec 2002 17:00:22 -0000 1.9
+++ mi/mi-cmds.c 4 Feb 2003 20:27:50 -0000
@@ -1,5 +1,7 @@
-/* MI Command Set.
- Copyright 2000, 2001 Free Software Foundation, Inc.
+/* MI Command Set for GDB, the GNU debugger.
+
+ Copyright 2000, 2001, 2003 Free Software Foundation, Inc.
+
Contributed by Cygnus Solutions (a Red Hat company).

This file is part of GDB.
@@ -88,6 +90,7 @@
{"gdb-show", "show %s", 0},
{"gdb-source", 0, 0},
{"gdb-version", "show version", 0},
+ {"interpreter-exec", 0, 0, mi_cmd_interpreter_exec},
{"kod-info", 0, 0},
{"kod-list", 0, 0},
{"kod-list-object-types", 0, 0},
Index: mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.6
diff -u -r1.6 mi-cmds.h
--- mi/mi-cmds.h 13 Dec 2002 17:00:22 -0000 1.6
+++ mi/mi-cmds.h 4 Feb 2003 20:27:50 -0000
@@ -1,5 +1,7 @@
-/* MI Command Set.
- Copyright 2000 Free Software Foundation, Inc.
+/* MI Command Set for GDB, the GNU debugger.
+
+ Copyright 2000, 2003 Free Software Foundation, Inc.
+
Contributed by Cygnus Solutions (a Red Hat company).

This file is part of GDB.
@@ -79,6 +81,7 @@
extern mi_cmd_args_ftype mi_cmd_exec_until;
extern mi_cmd_args_ftype mi_cmd_exec_interrupt;
extern mi_cmd_argv_ftype mi_cmd_gdb_exit;
+extern mi_cmd_argv_ftype mi_cmd_interpreter_exec;
extern mi_cmd_argv_ftype mi_cmd_stack_info_depth;
extern mi_cmd_argv_ftype mi_cmd_stack_list_args;
extern mi_cmd_argv_ftype mi_cmd_stack_list_frames;
@@ -125,5 +128,9 @@

/* Raw console output - FIXME: should this be a parameter? */
extern struct ui_file *raw_stdout;
+
+extern char *mi_error_message;
+extern void mi_error_last_message (void);
+extern void mi_execute_command (char *cmd, int from_tty);

#endif
Index: mi/mi-console.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-console.c,v
retrieving revision 1.8
diff -u -r1.8 mi-console.c
--- mi/mi-console.c 19 Mar 2002 02:51:08 -0000 1.8
+++ mi/mi-console.c 4 Feb 2003 20:27:50 -0000
@@ -37,13 +37,14 @@
struct ui_file *raw;
struct ui_file *buffer;
const char *prefix;
+ char quote;
};

int mi_console_file_magic;

struct ui_file *
mi_console_file_new (struct ui_file *raw,
- const char *prefix)
+ const char *prefix, char quote)
{
struct ui_file *ui_file = ui_file_new ();
struct mi_console_file *mi_console = XMALLOC (struct mi_console_file);
@@ -51,6 +52,7 @@
mi_console->raw = raw;
mi_console->buffer = mem_fileopen ();
mi_console->prefix = prefix;
+ mi_console->quote = quote;
set_ui_file_fputs (ui_file, mi_console_file_fputs);
set_ui_file_flush (ui_file, mi_console_file_flush);
set_ui_file_data (ui_file, mi_console, mi_console_file_delete);
@@ -96,9 +98,17 @@
if (length_buf > 0)
{
fputs_unfiltered (mi_console->prefix, mi_console->raw);
- fputs_unfiltered ("\"", mi_console->raw);
- fputstrn_unfiltered (buf, length_buf, '"', mi_console->raw);
- fputs_unfiltered ("\"\n", mi_console->raw);
+ if (mi_console->quote)
+ {
+ fputs_unfiltered ("\"", mi_console->raw);
+ fputstrn_unfiltered (buf, length_buf, mi_console->quote, mi_console->raw);
+ fputs_unfiltered ("\"\n", mi_console->raw);
+ }
+ else
+ {
+ fputstrn_unfiltered (buf, length_buf, 0, mi_console->raw);
+ fputs_unfiltered ("\n", mi_console->raw);
+ }
gdb_flush (mi_console->raw);
}
}
Index: mi/mi-console.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-console.h,v
retrieving revision 1.4
diff -u -r1.4 mi-console.h
--- mi/mi-console.h 6 Mar 2001 08:21:45 -0000 1.4
+++ mi/mi-console.h 4 Feb 2003 20:27:50 -0000
@@ -22,6 +22,8 @@
#ifndef MI_CONSOLE_H
#define MI_CONSOLE_H

-extern struct ui_file *mi_console_file_new (struct ui_file *raw, const char *prefix);
+extern struct ui_file *mi_console_file_new (struct ui_file *raw,
+ const char *prefix,
+ char quote);

#endif
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.39
diff -u -r1.39 mi-main.c
--- mi/mi-main.c 14 Jan 2003 00:07:43 -0000 1.39
+++ mi/mi-main.c 4 Feb 2003 20:27:50 -0000
@@ -33,6 +33,7 @@
#include "mi-console.h"
#include "ui-out.h"
#include "mi-out.h"
+#include "interps.h"
#include "event-loop.h"
#include "event-top.h"
#include "gdbcore.h" /* for write_memory() */
@@ -79,27 +80,29 @@
/* The token of the last asynchronous command */
static char *last_async_command;
static char *previous_async_command;
-static char *mi_error_message;
+char *mi_error_message;
static char *old_regs;

extern void _initialize_mi_main (void);
-static char *mi_input (char *);
-static void mi_execute_command (char *cmd, int from_tty);
static enum mi_cmd_result mi_cmd_execute (struct mi_parse *parse);

static void mi_execute_cli_command (const char *cli, char *args);
static enum mi_cmd_result mi_execute_async_cli_command (char *mi, char *args, int from_tty);
-static void mi_execute_command_wrapper (char *cmd);

-void mi_exec_async_cli_cmd_continuation (struct continuation_arg *arg);
+static void mi_exec_async_cli_cmd_continuation (struct continuation_arg *arg);

static int register_changed_p (int regnum);
static int get_register (int regnum, int format);
-static void mi_load_progress (const char *section_name,
- unsigned long sent_so_far,
- unsigned long total_section,
- unsigned long total_sent,
- unsigned long grand_total);
+
+/* A helper function which will set mi_error_message to
+ error_last_message. */
+void
+mi_error_last_message (void)
+{
+ char *s = error_last_message ();
+ xasprintf (&mi_error_message, s);
+ xfree (s);
+}

/* Command implementations. FIXME: Is this libgdb? No. This is the MI
layer that calls libgdb. Any operation used in the below should be
@@ -1098,7 +1101,12 @@

if (!target_can_async_p () || !target_executing)
{
- /* print the result if there were no errors */
+ /* print the result if there were no errors
+
+ Remember that on the way out of executing a command, you have
+ to directly use the mi_interp's uiout, since the command could
+ have reset the interpreter, in which case the current uiout
+ will most likely crash in the mi_out_* routines. */
if (args->rc == MI_CMD_DONE)
{
fputs_unfiltered (context->token, raw_stdout);
@@ -1146,15 +1154,21 @@
/* FIXME: If the command string has something that looks like
a format spec (e.g. %s) we will get a core dump */
mi_execute_cli_command ("%s", context->command);
- /* print the result */
- /* FIXME: Check for errors here. */
- fputs_unfiltered (context->token, raw_stdout);
- fputs_unfiltered ("^done", raw_stdout);
- mi_out_put (uiout, raw_stdout);
- mi_out_rewind (uiout);
- fputs_unfiltered ("\n", raw_stdout);
- args->action = EXECUTE_COMMAND_DISPLAY_PROMPT;
- args->rc = MI_CMD_DONE;
+
+ /* If we changed interpreters, DON'T print out anything. */
+ if (current_interp_named_p (INTERP_MI)
+ || current_interp_named_p (INTERP_MI1))
+ {
+ /* print the result */
+ /* FIXME: Check for errors here. */
+ fputs_unfiltered (context->token, raw_stdout);
+ fputs_unfiltered ("^done", raw_stdout);
+ mi_out_put (uiout, raw_stdout);
+ mi_out_rewind (uiout);
+ fputs_unfiltered ("\n", raw_stdout);
+ args->action = EXECUTE_COMMAND_DISPLAY_PROMPT;
+ args->rc = MI_CMD_DONE;
+ }
break;

}
@@ -1169,7 +1183,7 @@
struct mi_parse *command;
struct captured_mi_execute_command_args args;
struct ui_out *saved_uiout = uiout;
- int result, rc;
+ int result;

/* This is to handle EOF (^D). We just quit gdb. */
/* FIXME: we should call some API function here. */
@@ -1277,12 +1291,6 @@
}
}

-static void
-mi_execute_command_wrapper (char *cmd)
-{
- mi_execute_command (cmd, stdin == instream);
-}
-
/* FIXME: This is just a hack so we can get some extra commands going.
We don't want to channel things through the CLI, but call libgdb directly */
/* Use only for synchronous commands */
@@ -1385,13 +1393,7 @@
do_exec_cleanups (ALL_CLEANUPS);
}

-static char *
-mi_input (char *buf)
-{
- return gdb_readline (NULL);
-}
-
-static void
+void
mi_load_progress (const char *section_name,
unsigned long sent_so_far,
unsigned long total_section,
@@ -1403,7 +1405,8 @@
static char *previous_sect_name = NULL;
int new_section;

- if (!interpreter_p || strncmp (interpreter_p, "mi", 2) != 0)
+ if (!current_interp_named_p (INTERP_MI)
+ && !current_interp_named_p (INTERP_MI1))
return;

update_threshold.tv_sec = 0;
@@ -1462,131 +1465,17 @@
}
}

-static void
-mi_command_loop (int mi_version)
-{
- if (mi_version <= 1)
- {
- /* HACK: Force stdout/stderr to point at the console. This avoids
- any potential side effects caused by legacy code that is still
- using the TUI / fputs_unfiltered_hook */
- raw_stdout = stdio_fileopen (stdout);
- /* Route normal output through the MIx */
- gdb_stdout = mi_console_file_new (raw_stdout, "~");
- }
-
- /* Route error and log output through the MI */
- gdb_stderr = mi_console_file_new (raw_stdout, "&");
- gdb_stdlog = gdb_stderr;
- /* Route target output through the MI. */
- gdb_stdtarg = mi_console_file_new (raw_stdout, "@");
-
- /* HACK: Poke the ui_out table directly. Should we be creating a
- mi_out object wired up to the above gdb_stdout / gdb_stderr? */
- uiout = mi_out_new (mi_version);
-
- /* HACK: Override any other interpreter hooks. We need to create a
- real event table and pass in that. */
- init_ui_hook = 0;
- /* command_loop_hook = 0; */
- print_frame_info_listing_hook = 0;
- query_hook = 0;
- warning_hook = 0;
- create_breakpoint_hook = 0;
- delete_breakpoint_hook = 0;
- modify_breakpoint_hook = 0;
- interactive_hook = 0;
- registers_changed_hook = 0;
- readline_begin_hook = 0;
- readline_hook = 0;
- readline_end_hook = 0;
- register_changed_hook = 0;
- memory_changed_hook = 0;
- context_hook = 0;
- target_wait_hook = 0;
- call_command_hook = 0;
- error_hook = 0;
- error_begin_hook = 0;
- show_load_progress = mi_load_progress;
-
- /* Turn off 8 bit strings in quoted output. Any character with the
- high bit set is printed using C's octal format. */
- sevenbit_strings = 1;
-
- /* Tell the world that we're alive */
- fputs_unfiltered ("(gdb) \n", raw_stdout);
- gdb_flush (raw_stdout);
-
- if (!event_loop_p)
- simplified_command_loop (mi_input, mi_execute_command);
- else
- start_event_loop ();
-}
-
-static void
-mi1_command_loop (void)
-{
- mi_command_loop (1);
-}
-
-static void
-mi2_command_loop (void)
-{
- mi_command_loop (2);
-}
-
-static void
-setup_architecture_data (void)
+void
+mi_setup_architecture_data (void)
{
/* don't trust REGISTER_BYTES to be zero. */
old_regs = xmalloc (REGISTER_BYTES + 1);
memset (old_regs, 0, REGISTER_BYTES + 1);
}

-static void
-mi_init_ui (char *arg0)
-{
- if (strlen (interpreter_p) <= 2 ||
- interpreter_p[2] > '1')
- {
- /* HACK: Force stdout/stderr to point at the console. This avoids
- any potential side effects caused by legacy code that is still
- using the TUI / fputs_unfiltered_hook */
- raw_stdout = stdio_fileopen (stdout);
- /* Route normal output through the MIx */
- gdb_stdout = mi_console_file_new (raw_stdout, "~");
- }
-}
-
void
_initialize_mi_main (void)
{
- if (interpreter_p == NULL)
- return;
-
- /* If we're _the_ interpreter, take control. */
- if (strcmp (interpreter_p, "mi") == 0)
- command_loop_hook = mi2_command_loop;
- else if (strcmp (interpreter_p, "mi1") == 0)
- command_loop_hook = mi1_command_loop;
- else if (strcmp (interpreter_p, "mi2") == 0)
- command_loop_hook = mi2_command_loop;
- else
- return;
-
- init_ui_hook = mi_init_ui;
- setup_architecture_data ();
register_gdbarch_swap (&old_regs, sizeof (old_regs), NULL);
- register_gdbarch_swap (NULL, 0, setup_architecture_data);
- if (event_loop_p)
- {
- /* These overwrite some of the initialization done in
- _intialize_event_loop. */
- call_readline = gdb_readline2;
- input_handler = mi_execute_command_wrapper;
- add_file_handler (input_fd, stdin_event_handler, 0);
- async_command_editing_p = 0;
- }
- /* FIXME: Should we notify main that we are here as a possible
- interpreter? */
+ register_gdbarch_swap (NULL, 0, mi_setup_architecture_data);
}