/* Top level `main' program for GDB, the GNU debugger.
- Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
+ Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
Free Software Foundation, Inc.
This file is part of GDB.
#include "expression.h"
#include "language.h"
#include "terminal.h" /* For job_control. */
+#include "annotate.h"
#include "getopt.h"
/* readline defines this. */
#undef savestring
-#ifdef USG
#include <sys/types.h>
+#ifdef USG
+/* What is this for? X_OK? */
#include <unistd.h>
#endif
#include <sys/stat.h>
#include <ctype.h>
-#ifdef SET_STACK_LIMIT_HUGE
-#include <sys/time.h>
-#include <sys/resource.h>
-
-int original_stack_limit;
-#endif
-
/* Prototypes for local functions */
static char *
static void
info_command PARAMS ((char *, int));
+static void
+complete_command PARAMS ((char *, int));
+
static void
do_nothing PARAMS ((int));
/* Canonical host name as a string. */
-extern char *host_canonical;
+extern char *host_name;
/* Canonical target name as a string. */
-extern char *target_canonical;
+extern char *target_name;
extern char lang_frame_mismatch_warn[]; /* language.c */
char *line;
int linesize = 100;
+/* Nonzero if the current command is modified by "server ". This
+ affects things like recording into the command history, comamnds
+ 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
+ is issuing commands too. */
+int server_command;
+
/* Baud rate specified for talking to serial target systems. Default
is left as -1, so targets can choose their own defaults. */
+/* FIXME: This means that "show remotebaud" and gr_files_info can print -1
+ or (unsigned int)-1. This is a Bad User Interface. */
int baud_rate = -1;
/* Some System V have job control but not sigsetmask(). */
#if !defined (HAVE_SIGSETMASK)
-#define HAVE_SIGSETMASK !defined (USG)
+#if !defined (USG)
+#define HAVE_SIGSETMASK 1
+#else
+#define HAVE_SIGSETMASK 0
+#endif
#endif
#if 0 == (HAVE_SIGSETMASK)
disable_current_display ();
do_cleanups (ALL_CLEANUPS);
+
+ if (annotation_level > 1)
+ switch (reason)
+ {
+ case RETURN_QUIT:
+ annotate_quit ();
+ break;
+ case RETURN_ERROR:
+ annotate_error ();
+ break;
+ }
+
(NORETURN void) longjmp
(reason == RETURN_ERROR ? error_return : quit_return, 1);
}
do_cleanups (cleanups);
}
\f
+extern void init_proc ();
+
+void
+gdb_init ()
+{
+ /* Run the init function of each source file */
+
+ init_cmd_lists (); /* This needs to be done first */
+ initialize_all_files ();
+ init_main (); /* But that omits this file! Do it now */
+ init_signals ();
+
+ init_proc ();
+
+ /* We need a default language for parsing expressions, so simple things like
+ "set width 0" won't fail if no language is explicitly set in a config file
+ or implicitly set by reading an executable during startup. */
+ set_language (language_c);
+ expected_language = current_language; /* don't warn about the change. */
+}
+
+#ifndef MAIN_OVERRIDE
int
main (argc, argv)
int argc;
register int i;
+/* start-sanitize-mpw */
+#ifdef MPW
+ /* Drop into MacsBug, but only if the executable is specially named. */
+ if (strcmp(argv[0], "DEBUGGDB") == 0)
+ DebugStr("\pat start of GDB main");
+
+ if (StandAlone)
+ mac_app = mac_init ();
+#endif /* MPW */
+/* end-sanitize-mpw */
/* This needs to happen before the first use of malloc. */
init_malloc ((PTR) NULL);
getcwd (dirbuf, sizeof (dirbuf));
current_directory = dirbuf;
-#ifdef SET_STACK_LIMIT_HUGE
- {
- struct rlimit rlim;
-
- /* Set the stack limit huge so that alloca (particularly stringtab
- * in dbxread.c) does not fail. */
- getrlimit (RLIMIT_STACK, &rlim);
- original_stack_limit = rlim.rlim_cur;
- rlim.rlim_cur = rlim.rlim_max;
- setrlimit (RLIMIT_STACK, &rlim);
- }
-#endif /* SET_STACK_LIMIT_HUGE */
-
/* Parse arguments and options. */
{
int c;
{"n", no_argument, &inhibit_gdbinit, 1},
{"batch", no_argument, &batch, 1},
{"epoch", no_argument, &epoch_interface, 1},
- {"fullname", no_argument, &frame_file_full_name, 1},
- {"f", no_argument, &frame_file_full_name, 1},
+
+ /* This is a synonym for "--annotate=1". --annotate is now preferred,
+ but keep this here for a long time because people will be running
+ emacses which use --fullname. */
+ {"fullname", no_argument, 0, 'f'},
+ {"f", no_argument, 0, 'f'},
+
+ {"annotate", required_argument, 0, 12},
{"help", no_argument, &print_help, 1},
{"se", required_argument, 0, 10},
{"symbols", required_argument, 0, 's'},
case 11:
cdarg = optarg;
break;
+ case 12:
+ /* FIXME: what if the syntax is wrong (e.g. not digits)? */
+ annotation_level = atoi (optarg);
+ break;
+ case 'f':
+ annotation_level = 1;
+ break;
case 's':
symarg = optarg;
break;
i = strtol (optarg, &p, 0);
if (i == 0 && p == optarg)
- warning ("Could not set baud rate to `%s'.\n", optarg);
+
+ /* Don't use *_filtered or warning() (which relies on
+ current_target) until after initialize_all_files(). */
+
+ fprintf_unfiltered
+ (gdb_stderr,
+ "warning: could not set baud rate to `%s'.\n", optarg);
else
baud_rate = i;
}
quiet = 1;
}
- /* Run the init function of each source file */
-
- init_cmd_lists (); /* This needs to be done first */
- initialize_all_files ();
- init_main (); /* But that omits this file! Do it now */
- init_signals ();
+ gdb_init ();
/* Do these (and anything which might call wrap_here or *_filtered)
after initialize_all_files. */
/* But don't use *_filtered here. We don't want to prompt for continue
no matter how small the screen or how much we're going to print. */
+/* start-sanitize-mpw */
+/* For reasons too ugly to describe... */
+#ifdef MPW_C
+ fputs_unfiltered ("This is the GNU debugger.\n", gdb_stdout);
+#else
+/* end-sanitize-mpw */
fputs_unfiltered ("\
This is the GNU debugger. Usage:\n\
gdb [options] [executable-file [core-file or process-id]]\n\
--mapped Use mapped symbol files if supported on this system.\n\
--readnow Fully read symbol files on first access.\n\
", gdb_stdout);
+/* start-sanitize-mpw */
+#endif /* MPW_C */
+/* end-sanitize-mpw */
#ifdef ADDITIONAL_OPTION_HELP
fputs_unfiltered (ADDITIONAL_OPTION_HELP, gdb_stdout);
#endif
/* We may get more than one warning, don't double space all of them... */
warning_pre_print = "\nwarning: ";
- /* We need a default language for parsing expressions, so simple things like
- "set width 0" won't fail if no language is explicitly set in a config file
- or implicitly set by reading an executable during startup. */
- set_language (language_c);
- expected_language = current_language; /* don't warn about the change. */
-
/* Read and execute $HOME/.gdbinit file, if it exists. This is done
*before* all the command line arguments are processed; it sets
global parameters, which are independent of what file you are
if (!SET_TOP_LEVEL ())
{
cd_command (cdarg, 0);
- init_source_path ();
}
}
do_cleanups (ALL_CLEANUPS);
if (!SET_TOP_LEVEL ())
{
do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */
+/* start-sanitize-mpw */
+#ifdef MPW
+ /* If we're being a Mac application, go into a Mac-specific
+ event-handling loop instead. We still want to be inside
+ the outer loop, because that will catch longjmps resulting
+ from some command executions. */
+ if (mac_app)
+ mac_command_loop ();
+ else
+#endif /* MPW */
+/* end-sanitize-mpw */
command_loop ();
quit_command ((char *)0, instream == stdin);
}
}
/* No exit -- exit is through quit_command. */
}
+\f
+void
+init_proc ()
+{
+}
+
+int
+proc_wait (pid, status)
+ int pid;
+ int *status;
+{
+ return wait (status);
+}
+
+void
+proc_remove_foreign (pid)
+ int pid;
+{
+}
+#endif /* MAIN_OVERRIDE */
void
execute_user_command (c, args)
reinitialize_more_filter ();
old_chain = make_cleanup (command_loop_marker, 0);
command = command_line_input (instream == stdin ? prompt : (char *) NULL,
- instream == stdin);
+ instream == stdin, "prompt");
if (command == 0)
return;
execute_command (command, instream == stdin);
void
dont_repeat ()
{
+ if (server_command)
+ return;
+
/* If we aren't reading from standard input, we are saving the last
thing read from stdin in line and don't want to delete it. Null lines
won't repeat here in any case. */
character position to be off, since the newline we read from
the user is not accounted for. */
fputs_unfiltered (prrompt, gdb_stdout);
+/* start-sanitize-mpw */
+#ifdef MPW
+ /* Move to a new line so the entered line doesn't have a prompt
+ on the front of it. */
+ fputs_unfiltered ("\n", gdb_stdout);
+#endif /* MPW */
+/* end-sanitize-mpw */
gdb_flush (gdb_stdout);
}
"p b-a" ambiguous (all symbols starting with a)
"p b-" ambiguous (all symbols)
"file Make" "file" (word break hard to screw up here)
- "file ../gdb.stabs/wi" "erd" (needs to not break word at slash)
+ "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
*/
/* Generate completions one by one for the completer. Each time we are
/* Pointer within tmp_command which corresponds to text. */
char *word;
struct cmd_list_element *c, *result_list;
- extern char *rl_line_buffer;
- extern int rl_point;
if (matches == 0)
{
simple input as the user has requested. */
char *
-command_line_input (prrompt, repeat)
+command_line_input (prrompt, repeat, annotation_suffix)
char *prrompt;
int repeat;
+ char *annotation_suffix;
{
static char *linebuffer = 0;
static unsigned linelength = 0;
char *nline;
char got_eof = 0;
+ if (annotation_level > 1 && instream == stdin)
+ {
+ local_prompt = alloca ((prrompt == NULL ? 0 : strlen (prrompt))
+ + strlen (annotation_suffix) + 40);
+ if (prrompt == NULL)
+ local_prompt[0] = '\0';
+ else
+ strcpy (local_prompt, prrompt);
+ strcat (local_prompt, "\n\032\032");
+ strcat (local_prompt, annotation_suffix);
+ strcat (local_prompt, "\n");
+ }
+
if (linebuffer == 0)
{
linelength = 80;
while (1)
{
- /* Reports are that some Sys V's don't flush gdb_stdout/err on reads
- from stdin, when stdin/out are sockets rather than ttys. So we
- have to do it ourselves, to make emacs-gdb and xxgdb work.
- On other machines, doing this once per input should be a cheap nop. */
+ /* Make sure that all output has been output. Some machines may let
+ you get away with leaving out some of the gdb_flush, but not all. */
+ wrap_here ("");
gdb_flush (gdb_stdout);
gdb_flush (gdb_stderr);
error_pre_print = source_error;
}
+ if (annotation_level > 1 && instream == stdin)
+ {
+ printf_unfiltered ("\n\032\032pre-");
+ printf_unfiltered (annotation_suffix);
+ printf_unfiltered ("\n");
+ }
+
/* Don't use fancy stuff if not talking to stdin. */
if (command_editing_p && instream == stdin
&& ISATTY (instream))
else
rl = gdb_readline (local_prompt);
+ if (annotation_level > 1 && instream == stdin)
+ {
+ printf_unfiltered ("\n\032\032post-");
+ printf_unfiltered (annotation_suffix);
+ printf_unfiltered ("\n");
+ }
+
if (!rl || rl == (char *) EOF)
{
got_eof = 1;
if (got_eof)
return NULL;
+#define SERVER_COMMAND_LENGTH 7
+ server_command =
+ (p - linebuffer > SERVER_COMMAND_LENGTH)
+ && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
+ if (server_command)
+ {
+ /* Note that we don't set `line'. Between this and the check in
+ dont_repeat, this insures that repeating will still do the
+ right thing. */
+ *p = '\0';
+ return linebuffer + SERVER_COMMAND_LENGTH;
+ }
+
/* Do history expansion if that is wished. */
if (history_expansion_p && instream == stdin
&& ISATTY (instream))
if (expanded < 0)
{
free (history_value);
- return command_line_input (prrompt, repeat);
+ return command_line_input (prrompt, repeat, annotation_suffix);
}
if (strlen (history_value) > linelength)
{
&& ISATTY (stdin) && *linebuffer)
add_history (linebuffer);
- /* Note: lines consisting soley of comments are added to the command
+ /* Note: lines consisting solely of comments are added to the command
history. This is useful when you type a command, and then
realize you don't want to execute it quite yet. You can comment
out the command and then later fetch it from the value history
while (1)
{
dont_repeat ();
- p = command_line_input ((char *) NULL, instream == stdin);
+ p = command_line_input ((char *) NULL, instream == stdin, "commands");
if (p == NULL)
/* Treat end of file like "end". */
break;
help_list (infolist, "info ", -1, gdb_stdout);
}
+/* The "complete" command is used by Emacs to implement completion. */
+
+/* ARGSUSED */
+static void
+complete_command (arg, from_tty)
+ char *arg;
+ int from_tty;
+{
+ int i;
+ char *completion;
+
+ dont_repeat ();
+
+ if (arg == NULL)
+ {
+ rl_line_buffer[0] = '\0';
+ rl_point = 0;
+ }
+ else
+ {
+ strcpy (rl_line_buffer, arg);
+ rl_point = strlen (arg);
+ }
+
+ for (completion = symbol_completion_function (rl_line_buffer, i = 0);
+ completion;
+ completion = symbol_completion_function (rl_line_buffer, ++i))
+ printf_unfiltered ("%s\n", completion);
+}
+
/* The "show" command with no arguments shows all the settings. */
/* ARGSUSED */
GDB_FILE *stream;
{
fprintf_filtered (stream, "\
-GDB %s (%s", version, host_canonical);
+GDB %s (%s", version, host_name);
- if (strcmp(host_canonical, target_canonical))
- fprintf_filtered (stream, " --target %s", target_canonical);
+ if (!STREQ (host_name, target_name))
+ fprintf_filtered (stream, " --target %s", target_name);
fprintf_filtered (stream, "), ");
wrap_here("");
- fprintf_filtered (stream, "Copyright 1993 Free Software Foundation, Inc.");
+ fprintf_filtered (stream, "Copyright 1994 Free Software Foundation, Inc.");
}
/* ARGSUSED */
immediate_quit--;
}
\f
-/* xgdb calls this to reprint the usual GDB prompt. */
+/* xgdb calls this to reprint the usual GDB prompt. Obsolete now that xgdb
+ is obsolete. */
void
print_prompt ()
error ("Not confirmed.");
}
}
+ /* UDI wants this, to kill the TIP. */
+ target_close (1);
+
/* Save the history information if it is appropriate to do so. */
if (write_history_p && history_filename)
write_history (history_filename);
+
exit (0);
}
than the number of the last command). Relative to history_base. */
int hist_len;
- extern struct _hist_entry *history_get PARAMS ((int));
- extern int history_base;
+ extern HIST_ENTRY *history_get PARAMS ((int));
/* Print out some of the commands from the command history. */
/* First determine the length of the history list. */
&infolist, "info ", 0, &cmdlist);
add_com_alias ("i", "info", class_info, 1);
+ add_com ("complete", class_obscure, complete_command,
+ "List the completions for the rest of the line as a command.");
+
add_prefix_cmd ("show", class_info, show_command,
"Generic command for showing things about the debugger.",
&showlist, "show ", 0, &cmdlist);