/* 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.
/* Canonical host name as a string. */
-extern char *host_canonical;
+extern char *host_name;
/* Canonical target name as a string. */
-extern char *target_canonical;
-
-/* Message to be printed before the error message, when an error occurs. */
-
-extern char *error_pre_print;
-
-/* Message to be printed before the warning message, when a warning occurs. */
-
-extern char *warning_pre_print;
+extern char *target_name;
extern char lang_frame_mismatch_warn[]; /* language.c */
/* 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)
return 0;
}
\f
+/* Line number we are currently in in a file which is being sourced. */
+static int source_line_number;
+
+/* Name of the file we are sourcing. */
+static char *source_file_name;
+
+/* Buffer containing the error_pre_print used by the source stuff.
+ Malloc'd. */
+static char *source_error;
+static int source_error_allocated;
+
+/* Something to glom on to the start of error_pre_print if source_file_name
+ is set. */
+static char *source_pre_error;
+
/* Clean up on error during a "source" command (or execution of a
user-defined command). */
gdb_flush (gdb_stdout);
gdb_flush (gdb_stderr);
+ if (source_file_name != NULL)
+ {
+ ++source_line_number;
+ sprintf (source_error,
+ "%s%s:%d: Error in sourced command file:\n",
+ source_pre_error,
+ source_file_name,
+ source_line_number);
+ error_pre_print = source_error;
+ }
+
/* Don't use fancy stuff if not talking to stdin. */
if (command_editing_p && instream == stdin
&& ISATTY (instream))
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 */
pwd_command ((char *) 0, 1);
}
\f
+struct source_cleanup_lines_args {
+ int old_line;
+ char *old_file;
+ char *old_pre_error;
+ char *old_error_pre_print;
+};
+
+static void
+source_cleanup_lines (args)
+ PTR args;
+{
+ struct source_cleanup_lines_args *p =
+ (struct source_cleanup_lines_args *)args;
+ source_line_number = p->old_line;
+ source_file_name = p->old_file;
+ source_pre_error = p->old_pre_error;
+ error_pre_print = p->old_error_pre_print;
+}
+
/* ARGSUSED */
static void
source_command (args, from_tty)
int from_tty;
{
FILE *stream;
- struct cleanup *cleanups;
+ struct cleanup *old_cleanups;
char *file = args;
+ struct source_cleanup_lines_args old_lines;
+ int needed_length;
if (file == NULL)
{
}
file = tilde_expand (file);
- make_cleanup (free, file);
+ old_cleanups = make_cleanup (free, file);
stream = fopen (file, FOPEN_RT);
if (stream == 0)
perror_with_name (file);
- cleanups = make_cleanup (fclose, stream);
+ make_cleanup (fclose, stream);
+
+ old_lines.old_line = source_line_number;
+ old_lines.old_file = source_file_name;
+ old_lines.old_pre_error = source_pre_error;
+ old_lines.old_error_pre_print = error_pre_print;
+ make_cleanup (source_cleanup_lines, &old_lines);
+ source_line_number = 0;
+ source_file_name = file;
+ source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
+ source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
+ make_cleanup (free, source_pre_error);
+ /* This will get set every time we read a line. So it won't stay "" for
+ long. */
+ error_pre_print = "";
+
+ needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
+ if (source_error_allocated < needed_length)
+ {
+ source_error_allocated *= 2;
+ if (source_error_allocated < needed_length)
+ source_error_allocated = needed_length;
+ if (source_error == NULL)
+ source_error = xmalloc (source_error_allocated);
+ else
+ source_error = xrealloc (source_error, source_error_allocated);
+ }
read_command_file (stream);
- do_cleanups (cleanups);
+ do_cleanups (old_cleanups);
}
/* ARGSUSED */
than the number of the last command). Relative to history_base. */
int hist_len;
- extern struct _hist_entry *history_get PARAMS ((int));
+ extern HIST_ENTRY *history_get PARAMS ((int));
extern int history_base;
/* Print out some of the commands from the command history. */
&showlist);
add_show_from_set (
- add_set_cmd ("remotedebug", no_class, var_boolean, (char *)&remote_debug,
+ 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),