/* Top level stuff for GDB, the GNU debugger.
- Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
+ Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
Free Software Foundation, Inc.
This file is part of GDB.
/* stdio stream that command input is being read from. Set to stdin normally.
Set by source_command to the file we are sourcing. Set to NULL if we are
- executing a user-defined command. */
+ executing a user-defined command or interacting via a GUI. */
FILE *instream;
void (*flush_hook) PARAMS ((FILE *stream));
+/* 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
+ string that might be (for example) a message for the user to type in a
+ sequence of commands to be executed at a breakpoint. If this function
+ calls back to a GUI, it might take this opportunity to pop up a text
+ interaction window with this message. Next, readline_hook is called
+ with a prompt that is emitted prior to collecting the user input.
+ It can be called multiple times. Finally, readline_end_hook is called
+ 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));
+
/* Called as appropriate to notify the interface of the specified breakpoint
conditions. */
/* Keep iterating so long as the expression is true. */
while (loop == 1)
{
+ QUIT;
+
/* Evaluate the expression. */
val = evaluate_expression (expr);
register struct cmd_list_element *c;
register enum language flang;
static int warned = 0;
+ extern FILE *serial_logfp;
free_all_values ();
if (p == NULL)
return;
+ if (serial_logfp != NULL)
+ serial_log_command (p);
+
while (*p == ' ' || *p == '\t') p++;
if (*p)
{
char *command;
int stdin_is_tty = ISATTY (stdin);
long time_at_cmd_start;
+#ifdef HAVE_SBRK
long space_at_cmd_start;
+#endif
extern int display_time;
extern int display_space;
- while (!feof (instream))
+ while (instream && !feof (instream))
{
if (window_hook && instream == stdin)
(*window_hook) (instream, prompt);
if (display_space)
{
+#ifdef HAVE_SBRK
extern char **environ;
char *lim = (char *) sbrk (0);
space_at_cmd_start = (long) (lim - (char *) &environ);
+#endif
}
execute_command (command, instream == stdin);
if (display_space)
{
+#ifdef HAVE_SBRK
extern char **environ;
char *lim = (char *) sbrk (0);
long space_now = lim - (char *) &environ;
space_now,
(space_diff >= 0 ? '+' : '-'),
space_diff);
+#endif
}
}
}
{
signal (SIGINT, request_quit);
+ /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
+ to the inferior and breakpoints will be ignored. */
+#ifdef SIGTRAP
+ signal (SIGTRAP, SIG_DFL);
+#endif
+
/* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
passed to the inferior, which we don't want. It would be
possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
char *p1;
char *rl;
char *local_prompt = prrompt;
- register int c;
char *nline;
char got_eof = 0;
}
/* Don't use fancy stuff if not talking to stdin. */
- if (command_editing_p && instream == stdin
- && ISATTY (instream))
- rl = readline (local_prompt);
+ if (readline_hook && instream == NULL)
+ {
+ rl = (*readline_hook) (local_prompt);
+ }
+ else if (command_editing_p && instream == stdin && ISATTY (instream))
+ {
+ rl = readline (local_prompt);
+ }
else
- rl = gdb_readline (local_prompt);
+ {
+ rl = gdb_readline (local_prompt);
+ }
if (annotation_level > 1 && instream == stdin)
{
error ("Control nesting too deep!\n");
/* Set a prompt based on the nesting of the control commands. */
- if (instream == stdin)
+ if (instream == stdin || (instream == 0 && readline_hook != NULL))
{
for (i = 0; i < control_level; i++)
control_prompt[i] = ' ';
*command = build_command_line (while_control, p + 6);
else if (p1 - p > 2 && !strncmp (p, "if", 2))
*command = build_command_line (if_control, p + 3);
- else if (p1 - p == 5 && !strncmp (p, "loop_break", 5))
+ else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
{
*command = (struct command_line *)
xmalloc (sizeof (struct command_line));
(*command)->body_count = 0;
(*command)->body_list = NULL;
}
- else if (p1 - p == 8 && !strncmp (p, "loop_continue", 8))
+ else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13))
{
*command = (struct command_line *)
xmalloc (sizeof (struct command_line));
}
/* Recursively read in the control structures and create a command_line
- tructure from them.
+ structure from them.
The parent_control parameter is the control structure in which the
following commands are nested. */
return ret;
}
+/* Read lines from the input stream and accumulate them in a chain of
+ struct command_line's, which is then returned. For input from a
+ terminal, the special command "end" is used to mark the end of the
+ input, and is not included in the returned chain of commands. */
-/* Read lines from the input stream
- and accumulate them in a chain of struct command_line's
- which is then returned. */
+#define END_MESSAGE "End with a line saying just \"end\"."
struct command_line *
-read_command_lines ()
+read_command_lines (prompt, from_tty)
+char *prompt;
+int from_tty;
{
struct command_line *head, *tail, *next;
struct cleanup *old_chain;
enum command_control_type ret;
enum misc_command_type val;
+ if (readline_begin_hook)
+ {
+ /* Note - intentional to merge messages with no newline */
+ (*readline_begin_hook) ("%s %s\n", prompt, END_MESSAGE);
+ }
+ else if (from_tty && input_from_terminal_p ())
+ {
+ printf_unfiltered ("%s\n%s\n", prompt, END_MESSAGE);
+ gdb_flush (gdb_stdout);
+ }
+
head = tail = NULL;
old_chain = NULL;
if (ret != invalid_control)
{
discard_cleanups (old_chain);
- return head;
}
else
do_cleanups (old_chain);
}
- return NULL;
+ if (readline_end_hook)
+ {
+ (*readline_end_hook) ();
+ }
+ return (head);
}
/* Free a chain of struct command_line's. */
register struct command_line *cmds;
register struct cmd_list_element *c, *newc, *hookc = 0;
char *tem = comname;
+ char tmpbuf[128];
#define HOOK_STRING "hook-"
#define HOOK_LEN 5
for (tem = comname; *tem; tem++)
if (isupper(*tem)) *tem = tolower(*tem);
- if (from_tty)
- {
- printf_unfiltered ("Type commands for definition of \"%s\".\n\
-End with a line saying just \"end\".\n", comname);
- gdb_flush (gdb_stdout);
- }
-
control_level = 0;
- cmds = read_command_lines ();
+ sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
+ cmds = read_command_lines (tmpbuf, from_tty);
if (c && c->class == class_user)
free_command_lines (&c->user_commands);
struct command_line *doclines;
register struct cmd_list_element *c;
char *tem = comname;
+ char tmpbuf[128];
validate_comname (comname);
if (c->class != class_user)
error ("Command \"%s\" is built-in.", comname);
- if (from_tty)
- printf_unfiltered ("Type documentation for \"%s\".\n\
-End with a line saying just \"end\".\n", comname);
-
- doclines = read_command_lines ();
+ sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
+ doclines = read_command_lines (tmpbuf, from_tty);
if (c->doc) free (c->doc);
fprintf_filtered (stream, "), ");
wrap_here("");
- fprintf_filtered (stream, "Copyright 1995 Free Software Foundation, Inc.");
+ fprintf_filtered (stream, "Copyright 1996 Free Software Foundation, Inc.");
}
/* ARGSUSED */
#ifdef TARGET_BYTE_ORDER_SELECTABLE
int want;
- if (abfd->xvec->byteorder_big_p)
+ if (bfd_big_endian (abfd))
want = BIG_ENDIAN;
else
want = LITTLE_ENDIAN;
#else /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
- if (abfd->xvec->byteorder_big_p
+ if (bfd_big_endian (abfd)
? TARGET_BYTE_ORDER != BIG_ENDIAN
: TARGET_BYTE_ORDER == BIG_ENDIAN)
warning ("%s endian file does not match %s endian target.",
- abfd->xvec->byteorder_big_p ? "big" : "little",
+ bfd_big_endian (abfd) ? "big" : "little",
TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
#endif /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */