/* Top level stuff for GDB, the GNU debugger.
- Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
- Free Software Foundation, Inc.
+ Copyright 1986-2000 Free Software Foundation, Inc.
This file is part of GDB.
#include "terminal.h" /* For job_control. */
#include "annotate.h"
#include "top.h"
+#include "version.h"
/* readline include files */
#include <readline/readline.h>
#undef savestring
#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include "event-loop.h"
+#include <setjmp.h>
+
+#include "event-top.h"
#include "gdb_string.h"
#include "gdb_stat.h"
#include <ctype.h>
+#ifdef UI_OUT
+#include "ui-out.h"
+#include "cli-out.h"
+#endif
/* Prototypes for local functions */
-static void dont_repeat_command PARAMS ((char *, int));
+static void dont_repeat_command (char *, int);
-static void source_cleanup_lines PARAMS ((PTR));
+static void source_cleanup_lines (PTR);
-static void user_defined_command PARAMS ((char *, int));
+static void user_defined_command (char *, int);
-static void init_signals PARAMS ((void));
+static void init_signals (void);
#ifdef STOP_SIGNAL
-static void stop_sig PARAMS ((int));
+static void stop_sig (int);
#endif
-static char *line_completion_function PARAMS ((char *, int, char *, int));
+static char *line_completion_function (char *, int, char *, int);
-static char *readline_line_completion_function PARAMS ((char *, int));
+static char *readline_line_completion_function (char *, int);
-/* NOTE 1999-04-29: this function will be static again, after we make the
- event loop be the default command loop for gdb, and we merge
- event-top.c into this file, top.c */
-/* static */ void command_loop_marker PARAMS ((int));
+static void while_command (char *, int);
-static void while_command PARAMS ((char *, int));
+static void if_command (char *, int);
-static void if_command PARAMS ((char *, int));
+static struct command_line *build_command_line (enum command_control_type,
+ char *);
-static struct command_line *
- build_command_line PARAMS ((enum command_control_type, char *));
-
-static struct command_line *
- get_command_line PARAMS ((enum command_control_type, char *));
+static struct command_line *get_command_line (enum command_control_type,
+ char *);
-static void realloc_body_list PARAMS ((struct command_line *, int));
+static void realloc_body_list (struct command_line *, int);
-static enum misc_command_type read_next_line PARAMS ((struct command_line **));
+static enum misc_command_type read_next_line (struct command_line **);
static enum command_control_type
-recurse_read_control_structure PARAMS ((struct command_line *));
+recurse_read_control_structure (struct command_line *);
-static struct cleanup *setup_user_args PARAMS ((char *));
+static struct cleanup *setup_user_args (char *);
-static char *locate_arg PARAMS ((char *));
+static char *locate_arg (char *);
-static char *insert_args PARAMS ((char *));
+static char *insert_args (char *);
-static void arg_cleanup PARAMS ((void));
+static void arg_cleanup (void *);
-static void init_main PARAMS ((void));
+static void init_main (void);
-static void init_cmd_lists PARAMS ((void));
+static void init_cmd_lists (void);
-static void float_handler PARAMS ((int));
+static void float_handler (int);
-static void init_signals PARAMS ((void));
+static void init_signals (void);
-static void set_verbose PARAMS ((char *, int, struct cmd_list_element *));
+static void set_verbose (char *, int, struct cmd_list_element *);
-static void show_history PARAMS ((char *, int));
+static void show_history (char *, int);
-static void set_history PARAMS ((char *, int));
+static void set_history (char *, int);
-static void set_history_size_command PARAMS ((char *, int,
- struct cmd_list_element *));
+static void set_history_size_command (char *, int, struct cmd_list_element *);
-static void show_commands PARAMS ((char *, int));
+static void show_commands (char *, int);
-static void echo_command PARAMS ((char *, int));
+static void echo_command (char *, int);
-static void pwd_command PARAMS ((char *, int));
+static void pwd_command (char *, int);
-static void show_version PARAMS ((char *, int));
+static void show_version (char *, int);
-static void document_command PARAMS ((char *, int));
+static void document_command (char *, int);
-static void define_command PARAMS ((char *, int));
+static void define_command (char *, int);
-static void validate_comname PARAMS ((char *));
+static void validate_comname (char *);
-static void help_command PARAMS ((char *, int));
+static void help_command (char *, int);
-static void show_command PARAMS ((char *, int));
+static void show_command (char *, int);
-static void info_command PARAMS ((char *, int));
+static void info_command (char *, int);
-static void complete_command PARAMS ((char *, int));
+static void complete_command (char *, int);
-static void do_nothing PARAMS ((int));
+static void do_nothing (int);
+
+static void show_debug (char *, int);
+
+static void set_debug (char *, int);
#ifdef SIGHUP
/* NOTE 1999-04-29: This function will be static again, once we modify
gdb to use the event loop as the default command loop and we merge
event-top.c into this file, top.c */
-/* static */ int quit_cover PARAMS ((PTR));
+/* static */ int quit_cover (PTR);
-static void disconnect PARAMS ((int));
+static void disconnect (int);
#endif
-static void source_cleanup PARAMS ((FILE *));
+static void do_restore_instream_cleanup (void *stream);
+
+static struct cleanup *make_cleanup_free_command_lines (struct command_line **);
+
+/* Default command line prompt. This is overriden in some configs. */
-/* If this definition isn't overridden by the header files, assume
- that isatty and fileno exist on this system. */
-#ifndef ISATTY
-#define ISATTY(FP) (isatty (fileno (FP)))
+#ifndef DEFAULT_PROMPT
+#define DEFAULT_PROMPT "(gdb) "
#endif
/* Initialization file name for gdb. This is overridden in some configs. */
int use_windows = 1;
-/* Version number of GDB, as a string. */
-
-extern char *version;
-
-/* Canonical host name as a string. */
-
-extern char *host_name;
-
-/* Canonical target name as a string. */
-
-extern char *target_name;
-
extern char lang_frame_mismatch_warn[]; /* language.c */
/* Flag for whether we want all the "from_tty" gubbish printed. */
struct cmd_list_element *showprintlist;
+struct cmd_list_element *setdebuglist;
+
+struct cmd_list_element *showdebuglist;
+
struct cmd_list_element *setchecklist;
struct cmd_list_element *showchecklist;
The function receives two args: an input stream,
and a prompt string. */
-void (*window_hook) PARAMS ((FILE *, char *));
+void (*window_hook) (FILE *, char *);
int epoch_interface;
int xgdb_verbose;
/* gdb prints this when reading a command interactively */
static char *gdb_prompt_string; /* the global prompt string */
-extern char *get_prompt PARAMS ((void)); /* access function for prompt string */
+extern char *get_prompt (void); /* access function for prompt string */
/* Buffer used for reading command lines, and the size
allocated for it so far. */
int linesize = 100;
/* Nonzero if the current command is modified by "server ". This
- affects things like recording into the command history, comamnds
+ affects things like recording into the command history, commands
repeating on RETURN, etc. This is so a user interface (emacs, GUI,
whatever) can issue its own commands and also send along commands
from the user, and have the user not notice that the user interface
/* Timeout limit for response from target. */
-int remote_timeout = 20; /* Set default to 20 */
+/* The default value has been changed many times over the years. It
+ was originally 5 seconds. But that was thought to be a long time
+ to sit and wait, so it was changed to 2 seconds. That was thought
+ to be plenty unless the connection was going through some terminal
+ server or multiplexer or other form of hairy serial connection.
+
+ In mid-1996, remote_timeout was moved from remote.c to top.c and
+ it began being used in other remote-* targets. It appears that the
+ default was changed to 20 seconds at that time, perhaps because the
+ Hitachi E7000 ICE didn't always respond in a timely manner.
+
+ But if 5 seconds is a long time to sit and wait for retransmissions,
+ 20 seconds is far worse. This demonstrates the difficulty of using
+ a single variable for all protocol timeouts.
+
+ As remote.c is used much more than remote-e7000.c, it was changed
+ back to 2 seconds in 1999. */
+
+int remote_timeout = 2;
/* Non-zero tells remote* modules to output debugging info. */
#ifndef STOP_SIGNAL
#ifdef SIGTSTP
#define STOP_SIGNAL SIGTSTP
-static void stop_sig PARAMS ((int));
+static void stop_sig (int);
#endif
#endif
/* Called after most modules have been initialized, but before taking users
command file. */
-void (*init_ui_hook) PARAMS ((char *argv0));
+void (*init_ui_hook) (char *argv0);
/* This hook is called from within gdb's many mini-event loops which could
steal control from a real user interface's event loop. It returns
non-zero if the user is requesting a detach, zero otherwise. */
-int (*ui_loop_hook) PARAMS ((int));
+int (*ui_loop_hook) (int);
/* Called instead of command_loop at top level. Can be invoked via
return_to_top_level. */
-void (*command_loop_hook) PARAMS ((void));
-
+void (*command_loop_hook) (void);
-/* Called instead of fputs for all output. */
-
-void (*fputs_unfiltered_hook) PARAMS ((const char *linebuffer, GDB_FILE * stream));
/* Called from print_frame_info to list the line we stopped in. */
-void (*print_frame_info_listing_hook) PARAMS ((struct symtab * s, int line,
- int stopline, int noerror));
+void (*print_frame_info_listing_hook) (struct symtab * s, int line,
+ int stopline, int noerror);
/* Replaces most of query. */
-int (*query_hook) PARAMS ((const char *, va_list));
+int (*query_hook) (const char *, va_list);
/* Replaces most of warning. */
-void (*warning_hook) PARAMS ((const char *, va_list));
-
-/* Called from gdb_flush to flush output. */
-
-void (*flush_hook) PARAMS ((GDB_FILE * stream));
+void (*warning_hook) (const char *, va_list);
/* These three functions support getting lines of text from the user. They
are used in sequence. First readline_begin_hook is called with a text
to notify the GUI that we are done with the interaction window and it
can close it. */
-void (*readline_begin_hook) PARAMS ((char *,...));
-char *(*readline_hook) PARAMS ((char *));
-void (*readline_end_hook) PARAMS ((void));
+void (*readline_begin_hook) (char *, ...);
+char *(*readline_hook) (char *);
+void (*readline_end_hook) (void);
/* Called as appropriate to notify the interface of the specified breakpoint
conditions. */
-void (*create_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
-void (*delete_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
-void (*modify_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
+void (*create_breakpoint_hook) (struct breakpoint * bpt);
+void (*delete_breakpoint_hook) (struct breakpoint * bpt);
+void (*modify_breakpoint_hook) (struct breakpoint * bpt);
+
+/* Called as appropriate to notify the interface that we have attached
+ to or detached from an already running process. */
+
+void (*attach_hook) (void);
+void (*detach_hook) (void);
/* Called during long calculations to allow GUI to repair window damage, and to
check for stop buttons, etc... */
-void (*interactive_hook) PARAMS ((void));
+void (*interactive_hook) (void);
/* Called when the registers have changed, as a hint to a GUI
to minimize window update. */
-void (*registers_changed_hook) PARAMS ((void));
+void (*registers_changed_hook) (void);
/* Tell the GUI someone changed the register REGNO. -1 means
that the caller does not know which register changed or
that several registers have changed (see value_assign). */
-void (*register_changed_hook) PARAMS ((int regno));
+void (*register_changed_hook) (int regno);
/* Tell the GUI someone changed LEN bytes of memory at ADDR */
-void (*memory_changed_hook) PARAMS ((CORE_ADDR addr, int len));
+void (*memory_changed_hook) (CORE_ADDR addr, int len);
/* Called when going to wait for the target. Usually allows the GUI to run
while waiting for target events. */
-int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus * status));
+int (*target_wait_hook) (int pid, struct target_waitstatus * status);
/* Used by UI as a wrapper around command execution. May do various things
like enabling/disabling buttons, etc... */
-void (*call_command_hook) PARAMS ((struct cmd_list_element * c, char *cmd,
- int from_tty));
+void (*call_command_hook) (struct cmd_list_element * c, char *cmd,
+ int from_tty);
+
+/* Called after a `set' command has finished. Is only run if the
+ `set' command succeeded. */
+
+void (*set_hook) (struct cmd_list_element * c);
/* Called when the current thread changes. Argument is thread id. */
-void (*context_hook) PARAMS ((int id));
+void (*context_hook) (int id);
/* Takes control from error (). Typically used to prevent longjmps out of the
middle of the GUI. Usually used in conjunction with a catch routine. */
-NORETURN void (*error_hook)
-PARAMS ((void)) ATTR_NORETURN;
+NORETURN void (*error_hook) (void) ATTR_NORETURN;
\f
-/* Where to go for return_to_top_level (RETURN_ERROR). */
- SIGJMP_BUF error_return;
-/* Where to go for return_to_top_level (RETURN_QUIT). */
- SIGJMP_BUF quit_return;
+/* One should use catch_errors rather than manipulating these
+ directly. */
+#if defined(HAVE_SIGSETJMP)
+#define SIGJMP_BUF sigjmp_buf
+#define SIGSETJMP(buf) sigsetjmp(buf, 1)
+#define SIGLONGJMP(buf,val) siglongjmp(buf,val)
+#else
+#define SIGJMP_BUF jmp_buf
+#define SIGSETJMP(buf) setjmp(buf)
+#define SIGLONGJMP(buf,val) longjmp(buf,val)
+#endif
+
+/* Where to go for return_to_top_level. */
+static SIGJMP_BUF *catch_return;
-/* Return for reason REASON. This generally gets back to the command
- loop, but can be caught via catch_errors. */
+/* Return for reason REASON to the nearest containing catch_errors(). */
- NORETURN void
- return_to_top_level (reason)
+NORETURN void
+return_to_top_level (reason)
enum return_reason reason;
{
quit_flag = 0;
disable_current_display ();
do_cleanups (ALL_CLEANUPS);
- if (async_p && target_has_async)
+ if (event_loop_p && target_can_async_p () && !target_executing)
do_exec_cleanups (ALL_CLEANUPS);
+ if (event_loop_p && sync_execution)
+ do_exec_error_cleanups (ALL_CLEANUPS);
if (annotation_level > 1)
switch (reason)
break;
}
- (NORETURN void) SIGLONGJMP
- (reason == RETURN_ERROR ? error_return : quit_return, 1);
+ /* Jump to the containing catch_errors() call, communicating REASON
+ to that call via setjmp's return value. Note that REASON can't
+ be zero, by definition in defs.h. */
+
+ (NORETURN void) SIGLONGJMP (*catch_return, (int) reason);
}
/* Call FUNC with arg ARGS, catching any errors. If there is no
catch_errors. Note that quit should return to the command line
fairly quickly, even if some further processing is being done. */
+/* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
+ error() et.al. could maintain a set of flags that indicate the the
+ current state of each of the longjmp buffers. This would give the
+ longjmp code the chance to detect a longjmp botch (before it gets
+ to longjmperror()). Prior to 1999-11-05 this wasn't possible as
+ code also randomly used a SET_TOP_LEVEL macro that directly
+ initialize the longjmp buffers. */
+
+/* MAYBE: cagney/1999-11-05: Should the catch_erros and cleanups code
+ be consolidated into a single file instead of being distributed
+ between utils.c and top.c? */
+
int
catch_errors (func, args, errstring, mask)
catch_errors_ftype *func;
char *errstring;
return_mask mask;
{
- SIGJMP_BUF saved_error;
- SIGJMP_BUF saved_quit;
- SIGJMP_BUF tmp_jmp;
+ SIGJMP_BUF *saved_catch;
+ SIGJMP_BUF catch;
int val;
struct cleanup *saved_cleanup_chain;
char *saved_error_pre_print;
char *saved_quit_pre_print;
- saved_cleanup_chain = save_cleanups ();
+ /* Return value from SIGSETJMP(): enum return_reason if error or
+ quit caught, 0 otherwise. */
+ int caught;
+
+ /* Override error/quit messages during FUNC. */
+
saved_error_pre_print = error_pre_print;
saved_quit_pre_print = quit_pre_print;
if (mask & RETURN_MASK_ERROR)
- {
- memcpy ((char *) saved_error, (char *) error_return, sizeof (SIGJMP_BUF));
- error_pre_print = errstring;
- }
+ error_pre_print = errstring;
if (mask & RETURN_MASK_QUIT)
- {
- memcpy (saved_quit, quit_return, sizeof (SIGJMP_BUF));
- quit_pre_print = errstring;
- }
+ quit_pre_print = errstring;
- if (SIGSETJMP (tmp_jmp) == 0)
- {
- if (mask & RETURN_MASK_ERROR)
- memcpy (error_return, tmp_jmp, sizeof (SIGJMP_BUF));
- if (mask & RETURN_MASK_QUIT)
- memcpy (quit_return, tmp_jmp, sizeof (SIGJMP_BUF));
- val = (*func) (args);
- }
- else
- val = 0;
+ /* Prevent error/quit during FUNC from calling cleanups established
+ prior to here. */
+
+ saved_cleanup_chain = save_cleanups ();
+
+ /* Call FUNC, catching error/quit events. */
+
+ saved_catch = catch_return;
+ catch_return = &catch;
+ caught = SIGSETJMP (catch);
+ if (!caught)
+ val = (*func) (args);
+ catch_return = saved_catch;
+
+ /* FIXME: cagney/1999-11-05: A correct FUNC implementaton will
+ clean things up (restoring the cleanup chain) to the state they
+ were just prior to the call. Unfortunatly, many FUNC's are not
+ that well behaved. This could be fixed by adding either a
+ do_cleanups call (to cover the problem) or an assertion check to
+ detect bad FUNCs code. */
+
+ /* Restore the cleanup chain and error/quit messages to their
+ original states. */
restore_cleanups (saved_cleanup_chain);
- if (mask & RETURN_MASK_ERROR)
- {
- memcpy (error_return, saved_error, sizeof (SIGJMP_BUF));
- error_pre_print = saved_error_pre_print;
- }
if (mask & RETURN_MASK_QUIT)
- {
- memcpy (quit_return, saved_quit, sizeof (SIGJMP_BUF));
- quit_pre_print = saved_quit_pre_print;
- }
- return val;
+ quit_pre_print = saved_quit_pre_print;
+ if (mask & RETURN_MASK_ERROR)
+ error_pre_print = saved_error_pre_print;
+
+ /* Return normally if no error/quit event occurred. */
+
+ if (!caught)
+ return val;
+
+ /* If the caller didn't request that the event be caught, relay the
+ event to the next containing catch_errors(). */
+
+ if (!(mask & RETURN_MASK (caught)))
+ return_to_top_level (caught);
+
+ /* Tell the caller that an event was caught.
+
+ FIXME: nsd/2000-02-22: When MASK is RETURN_MASK_ALL, the caller
+ can't tell what type of event occurred.
+
+ A possible fix is to add a new interface, catch_event(), that
+ returns enum return_reason after catching an error or a quit.
+
+ When returning normally, i.e. without catching an error or a
+ quit, catch_event() could return RETURN_NORMAL, which would be
+ added to enum return_reason. FUNC would return information
+ exclusively via ARGS.
+
+ Alternatively, normal catch_event() could return FUNC's return
+ value. The caller would need to be aware of potential overlap
+ with enum return_reason, which could be publicly restricted to
+ negative values to simplify return value processing in FUNC and
+ in the caller. */
+
+ return 0;
}
+struct captured_command_args
+ {
+ catch_command_errors_ftype *command;
+ char *arg;
+ int from_tty;
+ };
+
+static int
+do_captured_command (void *data)
+{
+ struct captured_command_args *context = data;
+ context->command (context->arg, context->from_tty);
+ /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
+ isn't needed. Instead an assertion check could be made that
+ simply confirmed that the called function correctly cleaned up
+ after its self. Unfortunatly, old code (prior to 1999-11-04) in
+ main.c was calling SET_TOP_LEVEL(), calling the command function,
+ and then *always* calling do_cleanups(). For the moment we
+ remain ``bug compatible'' with that old code.. */
+ do_cleanups (ALL_CLEANUPS);
+ return 1;
+}
+
+int
+catch_command_errors (catch_command_errors_ftype * command,
+ char *arg, int from_tty, return_mask mask)
+{
+ struct captured_command_args args;
+ args.command = command;
+ args.arg = arg;
+ args.from_tty = from_tty;
+ return catch_errors (do_captured_command, &args, "", mask);
+}
+
+
/* Handler for SIGHUP. */
#ifdef SIGHUP
user-defined command). */
static void
-source_cleanup (stream)
- FILE *stream;
+do_restore_instream_cleanup (void *stream)
{
/* Restore the previous input stream. */
instream = stream;
{
struct cleanup *cleanups;
- cleanups = make_cleanup ((make_cleanup_func) source_cleanup, instream);
+ cleanups = make_cleanup (do_restore_instream_cleanup, instream);
instream = stream;
command_loop ();
do_cleanups (cleanups);
}
\f
-extern void init_proc PARAMS ((void));
+extern void init_proc (void);
-void (*pre_init_ui_hook) PARAMS ((void));
+void (*pre_init_ui_hook) (void);
+
+#ifdef __MSDOS__
+void
+do_chdir_cleanup (void *old_dir)
+{
+ chdir (old_dir);
+ free (old_dir);
+}
+#endif
void
gdb_init (argv0)
#ifdef __MSDOS__
/* Make sure we return to the original directory upon exit, come
what may, since the OS doesn't do that for us. */
- make_final_cleanup ((make_cleanup_func) chdir, strsave (current_directory));
+ make_final_cleanup (do_chdir_cleanup, xstrdup (current_directory));
#endif
init_cmd_lists (); /* This needs to be done first */
initialize_targets (); /* Setup target_terminal macros for utils.c */
initialize_utils (); /* Make errors and warnings possible */
initialize_all_files ();
+ initialize_current_architecture ();
init_main (); /* But that omits this file! Do it now */
/* The signal handling mechanism is different depending whether or
not the async version is run. NOTE: in the future we plan to make
the event loop be the default engine of gdb, and this difference
will disappear. */
- if (async_p)
+ if (event_loop_p)
async_init_signals ();
else
init_signals ();
set_language (language_c);
expected_language = current_language; /* don't warn about the change. */
+#ifdef UI_OUT
+ /* Install the default UI */
+ uiout = cli_out_new (gdb_stdout);
+#endif
+
+#ifdef UI_OUT
/* All the interpreters should have had a look at things by now.
Initialize the selected interpreter. */
+ if (interpreter_p && !init_ui_hook)
+ {
+ fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",
+ interpreter_p);
+ exit (1);
+ }
+#endif
+
if (init_ui_hook)
init_ui_hook (argv0);
}
/* Allocate and build a new command line structure. */
cmd = build_command_line (type, arg);
- old_chain = make_cleanup ((make_cleanup_func) free_command_lines, &cmd);
+ old_chain = make_cleanup_free_command_lines (&cmd);
/* Read in the body of this command. */
if (recurse_read_control_structure (cmd) == invalid_control)
}
/* Recursively print a command (including full control structures). */
+#ifdef UI_OUT
+void
+print_command_lines (uiout, cmd, depth)
+ struct ui_out *uiout;
+ struct command_line *cmd;
+ unsigned int depth;
+{
+ struct command_line *list;
+
+ list = cmd;
+ while (list)
+ {
+
+ if (depth)
+ ui_out_spaces (uiout, 2 * depth);
+
+ /* A simple command, print it and continue. */
+ if (list->control_type == simple_control)
+ {
+ ui_out_field_string (uiout, NULL, list->line);
+ ui_out_text (uiout, "\n");
+ list = list->next;
+ continue;
+ }
+
+ /* loop_continue to jump to the start of a while loop, print it
+ and continue. */
+ if (list->control_type == continue_control)
+ {
+ ui_out_field_string (uiout, NULL, "loop_continue");
+ ui_out_text (uiout, "\n");
+ list = list->next;
+ continue;
+ }
+
+ /* loop_break to break out of a while loop, print it and continue. */
+ if (list->control_type == break_control)
+ {
+ ui_out_field_string (uiout, NULL, "loop_break");
+ ui_out_text (uiout, "\n");
+ list = list->next;
+ continue;
+ }
+
+ /* A while command. Recursively print its subcommands and continue. */
+ if (list->control_type == while_control)
+ {
+ ui_out_text (uiout, "while ");
+ ui_out_field_fmt (uiout, NULL, "while %s", list->line);
+ ui_out_text (uiout, "\n");
+ print_command_lines (uiout, *list->body_list, depth + 1);
+ ui_out_field_string (uiout, NULL, "end");
+ if (depth)
+ ui_out_spaces (uiout, 2 * depth);
+ ui_out_text (uiout, "end\n");
+ list = list->next;
+ continue;
+ }
+
+ /* An if command. Recursively print both arms before continueing. */
+ if (list->control_type == if_control)
+ {
+ ui_out_text (uiout, "if ");
+ ui_out_field_fmt (uiout, NULL, "if %s", list->line);
+ ui_out_text (uiout, "\n");
+ /* The true arm. */
+ print_command_lines (uiout, list->body_list[0], depth + 1);
+
+ /* Show the false arm if it exists. */
+ if (list->body_count == 2)
+ {
+ if (depth)
+ ui_out_spaces (uiout, 2 * depth);
+ ui_out_field_string (uiout, NULL, "else");
+ ui_out_text (uiout, "else\n");
+ print_command_lines (uiout, list->body_list[1], depth + 1);
+ }
+
+ ui_out_field_string (uiout, NULL, "end");
+ if (depth)
+ ui_out_spaces (uiout, 2 * depth);
+ ui_out_text (uiout, "end\n");
+ list = list->next;
+ continue;
+ }
+
+ /* ignore illegal command type and try next */
+ list = list->next;
+ } /* while (list) */
+}
+#else
void
print_command_line (cmd, depth, stream)
struct command_line *cmd;
unsigned int depth;
- GDB_FILE *stream;
+ struct ui_file *stream;
{
unsigned int i;
fputs_filtered ("end\n", stream);
}
}
+#endif
/* Execute the command in CMD. */
new_line = insert_args (cmd->line);
if (!new_line)
return invalid_control;
- old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
- &new_line);
+ old_chain = make_cleanup (free_current_contents, &new_line);
execute_command (new_line, 0);
ret = cmd->control_type;
break;
new_line = insert_args (cmd->line);
if (!new_line)
return invalid_control;
- old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
- &new_line);
+ old_chain = make_cleanup (free_current_contents, &new_line);
expr = parse_expression (new_line);
- make_cleanup ((make_cleanup_func) free_current_contents, &expr);
+ make_cleanup (free_current_contents, &expr);
ret = simple_control;
loop = 1;
new_line = insert_args (cmd->line);
if (!new_line)
return invalid_control;
- old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
- &new_line);
+ old_chain = make_cleanup (free_current_contents, &new_line);
/* Parse the conditional for the if statement. */
expr = parse_expression (new_line);
- make_cleanup ((make_cleanup_func) free_current_contents, &expr);
+ make_cleanup (free_current_contents, &expr);
current = NULL;
ret = simple_control;
/* Cleanup */
static void
-arg_cleanup ()
+arg_cleanup (void *ignore)
{
struct user_args *oargs = user_args;
if (!user_args)
- fatal ("Internal error, arg_cleanup called with no user args.\n");
+ internal_error ("Internal error, arg_cleanup called with no user args.\n");
user_args = user_args->next;
free (oargs);
args->next = user_args;
user_args = args;
- old_chain = make_cleanup ((make_cleanup_func) arg_cleanup, 0);
+ old_chain = make_cleanup (arg_cleanup, 0/*ignored*/);
if (p == NULL)
return old_chain;
/* Set the instream to 0, indicating execution of a
user-defined function. */
- old_chain = make_cleanup ((make_cleanup_func) source_cleanup, instream);
+ old_chain = make_cleanup (do_restore_instream_cleanup, instream);
instream = (FILE *) 0;
while (cmdlines)
{
register struct cmd_list_element *c;
register enum language flang;
static int warned = 0;
+ char *line;
/* FIXME: These should really be in an appropriate header file */
- extern void serial_log_command PARAMS ((const char *));
+extern void serial_log_command (const char *);
free_all_values ();
if (*p)
{
char *arg;
+ line = p;
c = lookup_cmd (&p, cmdlist, "", 0, 1);
/* If the target is running, we allow only a limited set of
commands. */
- if (async_p && target_has_async && target_executing)
+ if (event_loop_p && target_can_async_p () && target_executing)
if (!strcmp (c->name, "help")
&& !strcmp (c->name, "pwd")
&& !strcmp (c->name, "show")
if (c->hook)
execute_user_command (c->hook, (char *) 0);
+ if (c->flags & DEPRECATED_WARN_USER)
+ deprecated_cmd_warning (&line);
+
if (c->class == class_user)
execute_user_command (c, arg);
else if (c->type == set_cmd || c->type == show_cmd)
}
}
-/* ARGSUSED */
-/* NOTE 1999-04-29: This function will be static again, once we modify
- gdb to use the event loop as the default command loop and we merge
- event-top.c into this file, top.c */
-/* static */ void
-command_loop_marker (foo)
- int foo;
-{
-}
-
/* Read commands from `instream' and execute them
until end of file or error reading instream. */
quit_flag = 0;
if (instream == stdin && stdin_is_tty)
reinitialize_more_filter ();
- old_chain = make_cleanup ((make_cleanup_func) command_loop_marker, 0);
+ old_chain = make_cleanup (null_cleanup, 0);
#if defined(TUI)
/* A bit of paranoia: I want to make sure the "insert_mode" global
}
}
+/* Read commands from `instream' and execute them until end of file or
+ error reading instream. This command loop doesnt care about any
+ such things as displaying time and space usage. If the user asks
+ for those, they won't work. */
+void
+simplified_command_loop (read_input_func, execute_command_func)
+ char *(*read_input_func) (char *);
+ void (*execute_command_func) (char *, int);
+{
+ struct cleanup *old_chain;
+ char *command;
+ int stdin_is_tty = ISATTY (stdin);
+
+ while (instream && !feof (instream))
+ {
+ quit_flag = 0;
+ if (instream == stdin && stdin_is_tty)
+ reinitialize_more_filter ();
+ old_chain = make_cleanup (null_cleanup, 0);
+
+ /* Get a command-line. */
+ command = (*read_input_func) (instream == stdin ?
+ get_prompt () : (char *) NULL);
+
+ if (command == 0)
+ return;
+
+ (*execute_command_func) (command, instream == stdin);
+
+ /* Do any commands attached to breakpoint we stopped at. */
+ bpstat_do_actions (&stop_bpstat);
+
+ do_cleanups (old_chain);
+ }
+}
\f
/* Commands call this if they do not want to be repeated by null lines. */
char *gdb_completer_command_word_break_characters =
" \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
+/* When completing on file names, we remove from the list of word
+ break characters any characters that are commonly used in file
+ names, such as '-', '+', '~', etc. Otherwise, readline displays
+ incorrect completion candidates. */
+char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?/><";
+
/* Characters that can be used to quote completion strings. Note that we
can't include '"' because the gdb C parser treats such quoted sequences
as strings. */
char *word;
{
/* From readline. */
- extern char *filename_completion_function PARAMS ((char *, int));
+extern char *filename_completion_function (char *, int);
int subsequent_name;
char **return_val;
int return_val_used;
return_val[return_val_used++] = p;
break;
}
+ /* We need to set subsequent_name to a non-zero value before the
+ continue line below, because otherwise, if the first file seen
+ by GDB is a backup file whose name ends in a `~', we will loop
+ indefinitely. */
+ subsequent_name = 1;
/* Like emacs, don't complete on old versions. Especially useful
in the "source" command. */
if (p[strlen (p) - 1] == '~')
free (p);
}
}
- subsequent_name = 1;
}
#if 0
/* There is no way to do this just long enough to affect quote inserting
/* It is a normal command; what comes after it is
completed by the command's completer function. */
list = (*c->completer) (p, word);
+ if (c->completer == filename_completer)
+ rl_completer_word_break_characters =
+ gdb_completer_file_name_break_characters;
}
}
else
{
/* It is a normal command. */
list = (*c->completer) (p, word);
+ if (c->completer == filename_completer)
+ rl_completer_word_break_characters =
+ gdb_completer_file_name_break_characters;
}
}
}
#ifdef STOP_SIGNAL
if (job_control)
{
- if (async_p)
+ if (event_loop_p)
signal (STOP_SIGNAL, handle_stop_sig);
else
signal (STOP_SIGNAL, stop_sig);
else
{
head = next;
- old_chain = make_cleanup ((make_cleanup_func) free_command_lines,
- &head);
+ old_chain = make_cleanup_free_command_lines (&head);
}
tail = next;
}
l = next;
}
}
+
+static void
+do_free_command_lines_cleanup (void *arg)
+{
+ free_command_lines (arg);
+}
+
+static struct cleanup *
+make_cleanup_free_command_lines (struct command_line **arg)
+{
+ return make_cleanup (do_free_command_lines_cleanup, arg);
+}
\f
/* Add an element to the list of info subcommands. */
-void
+struct cmd_list_element *
add_info (name, fun, doc)
char *name;
- void (*fun) PARAMS ((char *, int));
+ void (*fun) (char *, int);
char *doc;
{
- add_cmd (name, no_class, fun, doc, &infolist);
+ return add_cmd (name, no_class, fun, doc, &infolist);
}
/* Add an alias to the list of info subcommands. */
-void
+struct cmd_list_element *
add_info_alias (name, oldname, abbrev_flag)
char *name;
char *oldname;
int abbrev_flag;
{
- add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
+ return add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
}
/* The "info" command is defined as a prefix, with allow_unknown = 0.
\f
/* Add an element to the list of commands. */
-void
+struct cmd_list_element *
add_com (name, class, fun, doc)
char *name;
enum command_class class;
- void (*fun) PARAMS ((char *, int));
+ void (*fun) (char *, int);
char *doc;
{
- add_cmd (name, class, fun, doc, &cmdlist);
+ return add_cmd (name, class, fun, doc, &cmdlist);
}
/* Add an alias or abbreviation command to the list of commands. */
-void
+struct cmd_list_element *
add_com_alias (name, oldname, class, abbrev_flag)
char *name;
char *oldname;
enum command_class class;
int abbrev_flag;
{
- add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
+ return add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
}
void
/* Print the GDB banner. */
void
print_gdb_version (stream)
- GDB_FILE *stream;
+ struct ui_file *stream;
{
/* From GNU coding standards, first line is meant to be easy for a
program to parse, and is just canonical program name and version
number, which starts after last space. */
+#ifdef UI_OUT
+ /* Print it console style until a format is defined */
+ fprintf_filtered (stream, "GNU gdb %s (UI_OUT)\n", version);
+#else
fprintf_filtered (stream, "GNU gdb %s\n", version);
+#endif
/* Second line is a copyright notice. */
- fprintf_filtered (stream, "Copyright 1998 Free Software Foundation, Inc.\n");
+ fprintf_filtered (stream, "Copyright 2000 Free Software Foundation, Inc.\n");
/* Following the copyright is a brief statement that the program is
free software, that users are free to copy and change it on
{
char *local_prompt;
- if (async_p)
+ if (event_loop_p)
local_prompt = PROMPT (0);
else
local_prompt = gdb_prompt_string;
else
{
if (available >= 16 /*? */ ) /* overflow protect */
- sprintf (outp, "%d", (long) longval);
+ sprintf (outp, "%ld", (long) longval);
}
break;
}
else
{
/* Prompt could not be formatted. */
- if (async_p)
+ if (event_loop_p)
return PROMPT (0);
else
return gdb_prompt_string;
if (prompt != NULL)
free (prompt);
*/
- if (async_p)
+ if (event_loop_p)
PROMPT (0) = savestring (s, strlen (s));
else
gdb_prompt_string = savestring (s, strlen (s));
#endif
len = strlen (dir);
- if (SLASH_P (dir[len-1]))
+ if (SLASH_P (dir[len - 1]))
{
/* Remove the trailing slash unless this is a root directory
- (including a drive letter on non-Unix systems). */
- if (!(len == 1) /* "/" */
+ (including a drive letter on non-Unix systems). */
+ if (!(len == 1) /* "/" */
#if defined(_WIN32) || defined(__MSDOS__)
- && !(!SLASH_P (*dir) && ROOTED_P (dir) && len <= 3) /* "d:/" */
+ && !(!SLASH_P (*dir) && ROOTED_P (dir) && len <= 3) /* "d:/" */
#endif
)
len--;
}
/* ARGSUSED */
+static void
+do_fclose_cleanup (void *stream)
+{
+ fclose (stream);
+}
+
void
source_command (args, from_tty)
char *args;
return;
}
- make_cleanup ((make_cleanup_func) fclose, stream);
+ make_cleanup (do_fclose_cleanup, stream);
old_lines.old_line = source_line_number;
old_lines.old_file = source_file_name;
than the number of the last command). Relative to history_base. */
int hist_len;
- extern HIST_ENTRY *history_get PARAMS ((int));
+extern HIST_ENTRY *history_get (int);
/* Print out some of the commands from the command history. */
/* First determine the length of the history list. */
signal (SIGFPE, float_handler);
error ("Erroneous arithmetic operation.");
}
-\f
+
+static void
+set_debug (arg, from_tty)
+ char *arg;
+ int from_tty;
+{
+ printf_unfiltered ("\"set debug\" must be followed by the name of a print subcommand.\n");
+ help_list (setdebuglist, "set debug ", -1, gdb_stdout);
+}
+
+static void
+show_debug (args, from_tty)
+ char *args;
+ int from_tty;
+{
+ cmd_show_list (showdebuglist, from_tty, "");
+}
static void
init_cmd_lists ()
directories the file written will be the same as the one
that was read. */
#ifdef __MSDOS__
- /* No leading dots in file names are allowed on MSDOS. */
- history_filename = concat (current_directory, "/_gdb_history", NULL);
+ /* No leading dots in file names are allowed on MSDOS. */
+ history_filename = concat (current_directory, "/_gdb_history", NULL);
#else
history_filename = concat (current_directory, "/.gdb_history", NULL);
#endif
/* If we are running the asynchronous version,
we initialize the prompts differently. */
- if (!async_p)
+ if (!event_loop_p)
{
-#ifdef DEFAULT_PROMPT
gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
-#else
- gdb_prompt_string = savestring ("(gdb) ", 6);
-#endif
}
else
{
/* initialize the prompt stack to a simple "(gdb) " prompt or to
- whatever the DEFULAT_PROMPT is. */
+ whatever the DEFAULT_PROMPT is. */
the_prompts.top = 0;
PREFIX (0) = "";
-#ifdef DEFAULT_PROMPT
PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
-#else
- PROMPT (0) = savestring ("(gdb) ", 6);
-#endif
SUFFIX (0) = "";
/* Set things up for annotation_level > 1, if the user ever decides
to use it. */
async version is run. NOTE: this difference is going to
disappear as we make the event loop be the default engine of
gdb. */
- if (!async_p)
+ if (!event_loop_p)
{
add_show_from_set
(add_set_cmd ("prompt", class_support, var_string,
/* The set editing command is different depending whether or not the
async version is run. NOTE: this difference is going to disappear
as we make the event loop be the default engine of gdb. */
- if (!async_p)
+ if (!event_loop_p)
{
add_show_from_set
(add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p,
using remote targets.", &setlist),
&showlist);
- add_show_from_set (
- add_set_cmd ("remotedebug", no_class, var_zinteger, (char *) &remote_debug,
- "Set debugging of remote protocol.\n\
+ c = add_set_cmd ("remotedebug", no_class, var_zinteger,
+ (char *) &remote_debug,
+ "Set debugging of remote protocol.\n\
When enabled, each packet sent or received with the remote target\n\
-is displayed.", &setlist),
- &showlist);
+is displayed.", &setlist);
+ deprecate_cmd (c, "set debug remote");
+ deprecate_cmd (add_show_from_set (c, &showlist), "show debug remote");
+
+ add_show_from_set (add_set_cmd ("remote", no_class, var_zinteger,
+ (char *) &remote_debug,
+ "Set debugging of remote protocol.\n\
+When enabled, each packet sent or received with the remote target\n\
+is displayed.", &setdebuglist),
+ &showdebuglist);
add_show_from_set (
add_set_cmd ("remotetimeout", no_class, var_integer, (char *) &remote_timeout,
the async version is run. NOTE: this difference is going to
disappear as we make the event loop be the default engine of
gdb. */
- if (!async_p)
+ if (!event_loop_p)
{
c = add_set_cmd ("annotate", class_obscure, var_zinteger,
(char *) &annotation_level, "Set annotation_level.\n\
add_show_from_set (c, &showlist);
c->function.sfunc = set_async_annotation_level;
}
+ if (event_loop_p)
+ {
+ add_show_from_set
+ (add_set_cmd ("exec-done-display", class_support, var_boolean, (char *) &exec_done_display_p,
+ "Set notification of completion for asynchronous execution commands.\n\
+Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist),
+ &showlist);
+ }
+ add_prefix_cmd ("debug", no_class, set_debug,
+ "Generic command for setting gdb debugging flags",
+ &setdebuglist, "set debug ", 0, &setlist);
+
+ add_prefix_cmd ("debug", no_class, show_debug,
+ "Generic command for showing gdb debugging flags",
+ &showdebuglist, "show debug ", 0, &showlist);
}