* defs.h, infrun.c (wait_for_inferior), top.c: Call
[deliverable/binutils-gdb.git] / gdb / top.c
1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include "defs.h"
22 #include "gdbcmd.h"
23 #include "call-cmds.h"
24 #include "symtab.h"
25 #include "inferior.h"
26 #include "signals.h"
27 #include "target.h"
28 #include "breakpoint.h"
29 #include "gdbtypes.h"
30 #include "expression.h"
31 #include "value.h"
32 #include "language.h"
33 #include "terminal.h" /* For job_control. */
34 #include "annotate.h"
35 #include <setjmp.h>
36 #include "top.h"
37
38 /* readline include files */
39 #include "readline.h"
40 #include "history.h"
41
42 /* readline defines this. */
43 #undef savestring
44
45 #include <sys/types.h>
46 #ifdef USG
47 /* What is this for? X_OK? */
48 #include <unistd.h>
49 #endif
50
51 #include <string.h>
52 #ifndef NO_SYS_FILE
53 #include <sys/file.h>
54 #endif
55 #include <sys/param.h>
56 #include <sys/stat.h>
57 #include <ctype.h>
58
59 /* Prototypes for local functions */
60
61 static char * symbol_completion_function PARAMS ((char *, int));
62
63 static void command_loop_marker PARAMS ((int));
64
65 static void while_command PARAMS ((char *, int));
66
67 static void if_command PARAMS ((char *, int));
68
69 static enum command_control_type
70 execute_control_command PARAMS ((struct command_line *));
71
72 static struct command_line *
73 build_command_line PARAMS ((enum command_control_type, char *));
74
75 static struct command_line *
76 get_command_line PARAMS ((enum command_control_type, char *));
77
78 static void realloc_body_list PARAMS ((struct command_line *, int));
79
80 static enum misc_command_type read_next_line PARAMS ((struct command_line **));
81
82 static enum command_control_type
83 recurse_read_control_structure PARAMS ((struct command_line *));
84
85 static void init_main PARAMS ((void));
86
87 static void init_cmd_lists PARAMS ((void));
88
89 static void float_handler PARAMS ((int));
90
91 static void init_signals PARAMS ((void));
92
93 static void set_verbose PARAMS ((char *, int, struct cmd_list_element *));
94
95 #ifdef TARGET_BYTE_ORDER_SELECTABLE
96
97 static void set_endian PARAMS ((char *, int));
98
99 static void set_endian_big PARAMS ((char *, int));
100
101 static void set_endian_little PARAMS ((char *, int));
102
103 static void set_endian_auto PARAMS ((char *, int));
104
105 static void show_endian PARAMS ((char *, int));
106
107 #endif
108
109 static void show_history PARAMS ((char *, int));
110
111 static void set_history PARAMS ((char *, int));
112
113 static void set_history_size_command PARAMS ((char *, int,
114 struct cmd_list_element *));
115
116 static void show_commands PARAMS ((char *, int));
117
118 static void echo_command PARAMS ((char *, int));
119
120 static void pwd_command PARAMS ((char *, int));
121
122 static void show_version PARAMS ((char *, int));
123
124 static void document_command PARAMS ((char *, int));
125
126 static void define_command PARAMS ((char *, int));
127
128 static void validate_comname PARAMS ((char *));
129
130 static void help_command PARAMS ((char *, int));
131
132 static void show_command PARAMS ((char *, int));
133
134 static void info_command PARAMS ((char *, int));
135
136 static void complete_command PARAMS ((char *, int));
137
138 static void do_nothing PARAMS ((int));
139
140 static int quit_cover PARAMS ((char *));
141
142 static void disconnect PARAMS ((int));
143
144 static void source_cleanup PARAMS ((FILE *));
145
146 /* If this definition isn't overridden by the header files, assume
147 that isatty and fileno exist on this system. */
148 #ifndef ISATTY
149 #define ISATTY(FP) (isatty (fileno (FP)))
150 #endif
151
152 /* Initialization file name for gdb. This is overridden in some configs. */
153
154 #ifndef GDBINIT_FILENAME
155 #define GDBINIT_FILENAME ".gdbinit"
156 #endif
157 char gdbinit[] = GDBINIT_FILENAME;
158 int inhibit_gdbinit = 0;
159
160 /* Disable windows if non-zero */
161
162 int no_windows = 0;
163
164 /* Version number of GDB, as a string. */
165
166 extern char *version;
167
168 /* Canonical host name as a string. */
169
170 extern char *host_name;
171
172 /* Canonical target name as a string. */
173
174 extern char *target_name;
175
176 extern char lang_frame_mismatch_warn[]; /* language.c */
177
178 /* Flag for whether we want all the "from_tty" gubbish printed. */
179
180 int caution = 1; /* Default is yes, sigh. */
181
182 /*
183 * Define all cmd_list_element's
184 */
185
186 /* Chain containing all defined commands. */
187
188 struct cmd_list_element *cmdlist;
189
190 /* Chain containing all defined info subcommands. */
191
192 struct cmd_list_element *infolist;
193
194 /* Chain containing all defined enable subcommands. */
195
196 struct cmd_list_element *enablelist;
197
198 /* Chain containing all defined disable subcommands. */
199
200 struct cmd_list_element *disablelist;
201
202 /* Chain containing all defined delete subcommands. */
203
204 struct cmd_list_element *deletelist;
205
206 /* Chain containing all defined "enable breakpoint" subcommands. */
207
208 struct cmd_list_element *enablebreaklist;
209
210 /* Chain containing all defined set subcommands */
211
212 struct cmd_list_element *setlist;
213
214 /* Chain containing all defined unset subcommands */
215
216 struct cmd_list_element *unsetlist;
217
218 /* Chain containing all defined show subcommands. */
219
220 struct cmd_list_element *showlist;
221
222 #ifdef TARGET_BYTE_ORDER_SELECTABLE
223 /* Chain containing the \"set endian\" commands. */
224
225 struct cmd_list_element *endianlist;
226 #endif
227
228 /* Chain containing all defined \"set history\". */
229
230 struct cmd_list_element *sethistlist;
231
232 /* Chain containing all defined \"show history\". */
233
234 struct cmd_list_element *showhistlist;
235
236 /* Chain containing all defined \"unset history\". */
237
238 struct cmd_list_element *unsethistlist;
239
240 /* Chain containing all defined maintenance subcommands. */
241
242 #if MAINTENANCE_CMDS
243 struct cmd_list_element *maintenancelist;
244 #endif
245
246 /* Chain containing all defined "maintenance info" subcommands. */
247
248 #if MAINTENANCE_CMDS
249 struct cmd_list_element *maintenanceinfolist;
250 #endif
251
252 /* Chain containing all defined "maintenance print" subcommands. */
253
254 #if MAINTENANCE_CMDS
255 struct cmd_list_element *maintenanceprintlist;
256 #endif
257
258 struct cmd_list_element *setprintlist;
259
260 struct cmd_list_element *showprintlist;
261
262 struct cmd_list_element *setchecklist;
263
264 struct cmd_list_element *showchecklist;
265
266 /* stdio stream that command input is being read from. Set to stdin normally.
267 Set by source_command to the file we are sourcing. Set to NULL if we are
268 executing a user-defined command. */
269
270 FILE *instream;
271
272 /* Current working directory. */
273
274 char *current_directory;
275
276 /* The directory name is actually stored here (usually). */
277 char gdb_dirbuf[1024];
278
279 /* Function to call before reading a command, if nonzero.
280 The function receives two args: an input stream,
281 and a prompt string. */
282
283 void (*window_hook) PARAMS ((FILE *, char *));
284
285 int epoch_interface;
286 int xgdb_verbose;
287
288 /* gdb prints this when reading a command interactively */
289 static char *prompt;
290
291 /* Buffer used for reading command lines, and the size
292 allocated for it so far. */
293
294 char *line;
295 int linesize = 100;
296
297 /* Nonzero if the current command is modified by "server ". This
298 affects things like recording into the command history, comamnds
299 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
300 whatever) can issue its own commands and also send along commands
301 from the user, and have the user not notice that the user interface
302 is issuing commands too. */
303 int server_command;
304
305 /* Baud rate specified for talking to serial target systems. Default
306 is left as -1, so targets can choose their own defaults. */
307 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
308 or (unsigned int)-1. This is a Bad User Interface. */
309
310 int baud_rate = -1;
311
312 /* Non-zero tells remote* modules to output debugging info. */
313
314 int remote_debug = 0;
315
316 /* Level of control structure. */
317 static int control_level;
318
319 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
320
321 #ifndef STOP_SIGNAL
322 #ifdef SIGTSTP
323 #define STOP_SIGNAL SIGTSTP
324 static void stop_sig PARAMS ((int));
325 #endif
326 #endif
327
328 /* Some System V have job control but not sigsetmask(). */
329 #if !defined (HAVE_SIGSETMASK)
330 #if !defined (USG)
331 #define HAVE_SIGSETMASK 1
332 #else
333 #define HAVE_SIGSETMASK 0
334 #endif
335 #endif
336
337 #if 0 == (HAVE_SIGSETMASK)
338 #define sigsetmask(n)
339 #endif
340
341 /* Hooks for alternate command interfaces. */
342
343 /* Called after most modules have been initialized, but before taking users
344 command file. */
345
346 void (*init_ui_hook) PARAMS ((void));
347
348 /* Called instead of command_loop at top level. Can be invoked via
349 return_to_top_level. */
350
351 void (*command_loop_hook) PARAMS ((void));
352
353 /* Called instead of fputs for all output. */
354
355 void (*fputs_unfiltered_hook) PARAMS ((const char *linebuffer));
356
357 /* Called from print_frame_info to list the line we stopped in. */
358
359 void (*print_frame_info_listing_hook) PARAMS ((struct symtab *s, int line,
360 int stopline, int noerror));
361 /* Replaces most of query. */
362
363 int (*query_hook) PARAMS (());
364
365 /* Called from gdb_flush to flush output. */
366
367 void (*flush_hook) PARAMS ((FILE *stream));
368
369 /* Called as appropriate to notify the interface of the specified breakpoint
370 conditions. */
371
372 void (*create_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
373 void (*delete_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
374 void (*enable_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
375 void (*disable_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
376
377 /* Called during long calculations to allow GUI to repair window damage, and to
378 check for stop buttons, etc... */
379
380 void (*interactive_hook) PARAMS ((void));
381
382 /* Called when going to wait for the target. Usually allows the GUI to run
383 while waiting for target events. */
384
385 int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus *status));
386
387 /* Used by UI as a wrapper around command execution. May do various things
388 like enabling/disabling buttons, etc... */
389
390 void (*call_command_hook) PARAMS ((struct cmd_list_element *c, char *cmd,
391 int from_tty));
392 \f
393 /* Where to go for return_to_top_level (RETURN_ERROR). */
394 jmp_buf error_return;
395 /* Where to go for return_to_top_level (RETURN_QUIT). */
396 jmp_buf quit_return;
397
398 /* Return for reason REASON. This generally gets back to the command
399 loop, but can be caught via catch_errors. */
400
401 NORETURN void
402 return_to_top_level (reason)
403 enum return_reason reason;
404 {
405 quit_flag = 0;
406 immediate_quit = 0;
407
408 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
409 I can think of a reason why that is vital, though). */
410 bpstat_clear_actions(stop_bpstat); /* Clear queued breakpoint commands */
411
412 disable_current_display ();
413 do_cleanups (ALL_CLEANUPS);
414
415 if (annotation_level > 1)
416 switch (reason)
417 {
418 case RETURN_QUIT:
419 annotate_quit ();
420 break;
421 case RETURN_ERROR:
422 annotate_error ();
423 break;
424 }
425
426 (NORETURN void) longjmp
427 (reason == RETURN_ERROR ? error_return : quit_return, 1);
428 }
429
430 /* Call FUNC with arg ARGS, catching any errors. If there is no
431 error, return the value returned by FUNC. If there is an error,
432 print ERRSTRING, print the specific error message, then return
433 zero.
434
435 Must not be called with immediate_quit in effect (bad things might
436 happen, say we got a signal in the middle of a memcpy to quit_return).
437 This is an OK restriction; with very few exceptions immediate_quit can
438 be replaced by judicious use of QUIT.
439
440 MASK specifies what to catch; it is normally set to
441 RETURN_MASK_ALL, if for no other reason than that the code which
442 calls catch_errors might not be set up to deal with a quit which
443 isn't caught. But if the code can deal with it, it generally
444 should be RETURN_MASK_ERROR, unless for some reason it is more
445 useful to abort only the portion of the operation inside the
446 catch_errors. Note that quit should return to the command line
447 fairly quickly, even if some further processing is being done. */
448
449 int
450 catch_errors (func, args, errstring, mask)
451 int (*func) PARAMS ((char *));
452 PTR args;
453 char *errstring;
454 return_mask mask;
455 {
456 jmp_buf saved_error;
457 jmp_buf saved_quit;
458 jmp_buf tmp_jmp;
459 int val;
460 struct cleanup *saved_cleanup_chain;
461 char *saved_error_pre_print;
462
463 saved_cleanup_chain = save_cleanups ();
464 saved_error_pre_print = error_pre_print;
465
466 if (mask & RETURN_MASK_ERROR)
467 memcpy ((char *)saved_error, (char *)error_return, sizeof (jmp_buf));
468 if (mask & RETURN_MASK_QUIT)
469 memcpy (saved_quit, quit_return, sizeof (jmp_buf));
470 error_pre_print = errstring;
471
472 if (setjmp (tmp_jmp) == 0)
473 {
474 if (mask & RETURN_MASK_ERROR)
475 memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
476 if (mask & RETURN_MASK_QUIT)
477 memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
478 val = (*func) (args);
479 }
480 else
481 val = 0;
482
483 restore_cleanups (saved_cleanup_chain);
484
485 error_pre_print = saved_error_pre_print;
486 if (mask & RETURN_MASK_ERROR)
487 memcpy (error_return, saved_error, sizeof (jmp_buf));
488 if (mask & RETURN_MASK_QUIT)
489 memcpy (quit_return, saved_quit, sizeof (jmp_buf));
490 return val;
491 }
492
493 /* Handler for SIGHUP. */
494
495 static void
496 disconnect (signo)
497 int signo;
498 {
499 catch_errors (quit_cover, NULL,
500 "Could not kill the program being debugged", RETURN_MASK_ALL);
501 signal (SIGHUP, SIG_DFL);
502 kill (getpid (), SIGHUP);
503 }
504
505 /* Just a little helper function for disconnect(). */
506
507 static int
508 quit_cover (s)
509 char *s;
510 {
511 caution = 0; /* Throw caution to the wind -- we're exiting.
512 This prevents asking the user dumb questions. */
513 quit_command((char *)0, 0);
514 return 0;
515 }
516 \f
517 /* Line number we are currently in in a file which is being sourced. */
518 static int source_line_number;
519
520 /* Name of the file we are sourcing. */
521 static char *source_file_name;
522
523 /* Buffer containing the error_pre_print used by the source stuff.
524 Malloc'd. */
525 static char *source_error;
526 static int source_error_allocated;
527
528 /* Something to glom on to the start of error_pre_print if source_file_name
529 is set. */
530 static char *source_pre_error;
531
532 /* Clean up on error during a "source" command (or execution of a
533 user-defined command). */
534
535 static void
536 source_cleanup (stream)
537 FILE *stream;
538 {
539 /* Restore the previous input stream. */
540 instream = stream;
541 }
542
543 /* Read commands from STREAM. */
544 void
545 read_command_file (stream)
546 FILE *stream;
547 {
548 struct cleanup *cleanups;
549
550 cleanups = make_cleanup (source_cleanup, instream);
551 instream = stream;
552 command_loop ();
553 do_cleanups (cleanups);
554 }
555 \f
556 extern void init_proc ();
557
558 void
559 gdb_init ()
560 {
561 /* Run the init function of each source file */
562
563 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
564 current_directory = gdb_dirbuf;
565
566 init_cmd_lists (); /* This needs to be done first */
567 initialize_targets (); /* Setup target_terminal macros for utils.c */
568 initialize_utils (); /* Make errors and warnings possible */
569 initialize_all_files ();
570 init_main (); /* But that omits this file! Do it now */
571 init_signals ();
572
573 init_proc ();
574
575 /* We need a default language for parsing expressions, so simple things like
576 "set width 0" won't fail if no language is explicitly set in a config file
577 or implicitly set by reading an executable during startup. */
578 set_language (language_c);
579 expected_language = current_language; /* don't warn about the change. */
580
581 if (init_ui_hook)
582 init_ui_hook ();
583 }
584
585 /* Allocate, initialize a new command line structure for one of the
586 control commands (if/while). */
587
588 static struct command_line *
589 build_command_line (type, args)
590 enum command_control_type type;
591 char *args;
592 {
593 struct command_line *cmd;
594
595 cmd = (struct command_line *)xmalloc (sizeof (struct command_line));
596 cmd->next = NULL;
597 cmd->control_type = type;
598
599 cmd->body_count = 1;
600 cmd->body_list
601 = (struct command_line **)xmalloc (sizeof (struct command_line *)
602 * cmd->body_count);
603 memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
604 cmd->line = savestring (args, strlen (args));
605 return cmd;
606 }
607
608 /* Build and return a new command structure for the control commands
609 such as "if" and "while". */
610
611 static struct command_line *
612 get_command_line (type, arg)
613 enum command_control_type type;
614 char *arg;
615 {
616 struct command_line *cmd;
617 struct cleanup *old_chain = NULL;
618
619 /* Allocate and build a new command line structure. */
620 cmd = build_command_line (type, arg);
621
622 old_chain = make_cleanup (free_command_lines, &cmd);
623
624 /* Read in the body of this command. */
625 if (recurse_read_control_structure (cmd) == invalid_control)
626 {
627 warning ("error reading in control structure\n");
628 do_cleanups (old_chain);
629 return NULL;
630 }
631
632 discard_cleanups (old_chain);
633 return cmd;
634 }
635
636 /* Execute the command in CMD. */
637
638 static enum command_control_type
639 execute_control_command (cmd)
640 struct command_line *cmd;
641 {
642 struct expression *expr;
643 struct command_line *current;
644 struct cleanup *old_chain = 0;
645 struct cleanup *tmp_chain;
646 value_ptr val;
647 int loop;
648 enum command_control_type ret;
649
650 switch (cmd->control_type)
651 {
652 case simple_control:
653 /* A simple command, execute it and return. */
654 execute_command (cmd->line, 0);
655 return cmd->control_type;
656
657 case continue_control:
658 case break_control:
659 /* Return for "continue", and "break" so we can either
660 continue the loop at the top, or break out. */
661 return cmd->control_type;
662
663 case while_control:
664 {
665 /* Parse the loop control expression for the while statement. */
666 expr = parse_expression (cmd->line);
667 tmp_chain = make_cleanup (free_current_contents, &expr);
668 if (!old_chain)
669 old_chain = tmp_chain;
670
671 ret = simple_control;
672 loop = true;
673
674 /* Keep iterating so long as the expression is true. */
675 while (loop == true)
676 {
677 /* Evaluate the expression. */
678 val = evaluate_expression (expr);
679
680 /* If the value is false, then break out of the loop. */
681 if (!value_true (val))
682 break;
683
684 /* Execute the body of the while statement. */
685 current = *cmd->body_list;
686 while (current)
687 {
688 ret = execute_control_command (current);
689
690 /* If we got an error, or a "break" command, then stop
691 looping. */
692 if (ret == invalid_control || ret == break_control)
693 {
694 loop = false;
695 break;
696 }
697
698 /* If we got a "continue" command, then restart the loop
699 at this point. */
700 if (ret == continue_control)
701 break;
702
703 /* Get the next statement. */
704 current = current->next;
705 }
706 }
707
708 /* Reset RET so that we don't recurse the break all the way down. */
709 if (ret == break_control)
710 ret = simple_control;
711
712 break;
713 }
714
715 case if_control:
716 {
717 /* Parse the conditional for the if statement. */
718 expr = parse_expression (cmd->line);
719 old_chain = make_cleanup (free_current_contents, &expr);
720
721 current = NULL;
722 ret = simple_control;
723
724 /* Evaluate the conditional. */
725 val = evaluate_expression (expr);
726
727 /* Choose which arm to take commands from based on the value of the
728 conditional expression. */
729 if (value_true (val))
730 current = *cmd->body_list;
731 else if (cmd->body_count == 2)
732 current = *(cmd->body_list + 1);
733
734 /* Execute commands in the given arm. */
735 while (current)
736 {
737 ret = execute_control_command (current);
738
739 /* If we got an error, get out. */
740 if (ret != simple_control)
741 break;
742
743 /* Get the next statement in the body. */
744 current = current->next;
745 }
746 break;
747 }
748
749 default:
750 warning ("Invalid control type in command structure.");
751 return invalid_control;
752 }
753
754 if (old_chain)
755 do_cleanups (old_chain);
756
757 return ret;
758 }
759
760 /* "while" command support. Executes a body of statements while the
761 loop condition is nonzero. */
762
763 static void
764 while_command (arg, from_tty)
765 char *arg;
766 int from_tty;
767 {
768 struct command_line *command = NULL;
769
770 control_level = 1;
771 command = get_command_line (while_control, arg);
772
773 if (command == NULL)
774 return;
775
776 execute_control_command (command);
777 free_command_lines (&command);
778 }
779
780 /* "if" command support. Execute either the true or false arm depending
781 on the value of the if conditional. */
782
783 static void
784 if_command (arg, from_tty)
785 char *arg;
786 int from_tty;
787 {
788 struct command_line *command = NULL;
789
790 control_level = 1;
791 command = get_command_line (if_control, arg);
792
793 if (command == NULL)
794 return;
795
796 execute_control_command (command);
797 free_command_lines (&command);
798 }
799
800 void
801 execute_user_command (c, args)
802 struct cmd_list_element *c;
803 char *args;
804 {
805 register struct command_line *cmdlines;
806 struct cleanup *old_chain;
807 enum command_control_type ret;
808
809 if (args)
810 error ("User-defined commands cannot take arguments.");
811
812 cmdlines = c->user_commands;
813 if (cmdlines == 0)
814 /* Null command */
815 return;
816
817 /* Set the instream to 0, indicating execution of a
818 user-defined function. */
819 old_chain = make_cleanup (source_cleanup, instream);
820 instream = (FILE *) 0;
821 while (cmdlines)
822 {
823 ret = execute_control_command (cmdlines);
824 if (ret != simple_control && ret != break_control)
825 {
826 warning ("Error in control structure.\n");
827 break;
828 }
829 cmdlines = cmdlines->next;
830 }
831 do_cleanups (old_chain);
832 }
833
834 /* Execute the line P as a command.
835 Pass FROM_TTY as second argument to the defining function. */
836
837 void
838 execute_command (p, from_tty)
839 char *p;
840 int from_tty;
841 {
842 register struct cmd_list_element *c;
843 register enum language flang;
844 static int warned = 0;
845
846 free_all_values ();
847
848 /* This can happen when command_line_input hits end of file. */
849 if (p == NULL)
850 return;
851
852 while (*p == ' ' || *p == '\t') p++;
853 if (*p)
854 {
855 char *arg;
856
857 c = lookup_cmd (&p, cmdlist, "", 0, 1);
858 /* Pass null arg rather than an empty one. */
859 arg = *p ? p : 0;
860
861 /* If this command has been hooked, run the hook first. */
862 if (c->hook)
863 execute_user_command (c->hook, (char *)0);
864
865 if (c->class == class_user)
866 execute_user_command (c, arg);
867 else if (c->type == set_cmd || c->type == show_cmd)
868 do_setshow_command (arg, from_tty & caution, c);
869 else if (c->function.cfunc == NO_FUNCTION)
870 error ("That is not a command, just a help topic.");
871 else if (call_command_hook)
872 call_command_hook (c, arg, from_tty & caution);
873 else
874 (*c->function.cfunc) (arg, from_tty & caution);
875 }
876
877 /* Tell the user if the language has changed (except first time). */
878 if (current_language != expected_language)
879 {
880 if (language_mode == language_mode_auto) {
881 language_info (1); /* Print what changed. */
882 }
883 warned = 0;
884 }
885
886 /* Warn the user if the working language does not match the
887 language of the current frame. Only warn the user if we are
888 actually running the program, i.e. there is a stack. */
889 /* FIXME: This should be cacheing the frame and only running when
890 the frame changes. */
891 if (target_has_stack)
892 {
893 flang = get_frame_language ();
894 if (!warned
895 && flang != language_unknown
896 && flang != current_language->la_language)
897 {
898 printf_filtered ("%s\n", lang_frame_mismatch_warn);
899 warned = 1;
900 }
901 }
902 }
903
904 /* ARGSUSED */
905 static void
906 command_loop_marker (foo)
907 int foo;
908 {
909 }
910
911 /* Read commands from `instream' and execute them
912 until end of file or error reading instream. */
913 void
914 command_loop ()
915 {
916 struct cleanup *old_chain;
917 char *command;
918 int stdin_is_tty = ISATTY (stdin);
919
920 while (!feof (instream))
921 {
922 if (window_hook && instream == stdin)
923 (*window_hook) (instream, prompt);
924
925 quit_flag = 0;
926 if (instream == stdin && stdin_is_tty)
927 reinitialize_more_filter ();
928 old_chain = make_cleanup (command_loop_marker, 0);
929 command = command_line_input (instream == stdin ? prompt : (char *) NULL,
930 instream == stdin, "prompt");
931 if (command == 0)
932 return;
933 execute_command (command, instream == stdin);
934 /* Do any commands attached to breakpoint we stopped at. */
935 bpstat_do_actions (&stop_bpstat);
936 do_cleanups (old_chain);
937 }
938 }
939 \f
940 /* Commands call this if they do not want to be repeated by null lines. */
941
942 void
943 dont_repeat ()
944 {
945 if (server_command)
946 return;
947
948 /* If we aren't reading from standard input, we are saving the last
949 thing read from stdin in line and don't want to delete it. Null lines
950 won't repeat here in any case. */
951 if (instream == stdin)
952 *line = 0;
953 }
954 \f
955 /* Read a line from the stream "instream" without command line editing.
956
957 It prints PRROMPT once at the start.
958 Action is compatible with "readline", e.g. space for the result is
959 malloc'd and should be freed by the caller.
960
961 A NULL return means end of file. */
962 char *
963 gdb_readline (prrompt)
964 char *prrompt;
965 {
966 int c;
967 char *result;
968 int input_index = 0;
969 int result_size = 80;
970
971 if (prrompt)
972 {
973 /* Don't use a _filtered function here. It causes the assumed
974 character position to be off, since the newline we read from
975 the user is not accounted for. */
976 fputs_unfiltered (prrompt, gdb_stdout);
977 /* start-sanitize-mpw */
978 #ifdef MPW
979 /* Move to a new line so the entered line doesn't have a prompt
980 on the front of it. */
981 fputs_unfiltered ("\n", gdb_stdout);
982 #endif /* MPW */
983 /* end-sanitize-mpw */
984 gdb_flush (gdb_stdout);
985 }
986
987 result = (char *) xmalloc (result_size);
988
989 while (1)
990 {
991 /* Read from stdin if we are executing a user defined command.
992 This is the right thing for prompt_for_continue, at least. */
993 c = fgetc (instream ? instream : stdin);
994
995 if (c == EOF)
996 {
997 if (input_index > 0)
998 /* The last line does not end with a newline. Return it, and
999 if we are called again fgetc will still return EOF and
1000 we'll return NULL then. */
1001 break;
1002 free (result);
1003 return NULL;
1004 }
1005
1006 if (c == '\n')
1007 break;
1008
1009 result[input_index++] = c;
1010 while (input_index >= result_size)
1011 {
1012 result_size *= 2;
1013 result = (char *) xrealloc (result, result_size);
1014 }
1015 }
1016
1017 result[input_index++] = '\0';
1018 return result;
1019 }
1020
1021 /* Variables which control command line editing and history
1022 substitution. These variables are given default values at the end
1023 of this file. */
1024 static int command_editing_p;
1025 static int history_expansion_p;
1026 static int write_history_p;
1027 static int history_size;
1028 static char *history_filename;
1029
1030 /* readline uses the word breaks for two things:
1031 (1) In figuring out where to point the TEXT parameter to the
1032 rl_completion_entry_function. Since we don't use TEXT for much,
1033 it doesn't matter a lot what the word breaks are for this purpose, but
1034 it does affect how much stuff M-? lists.
1035 (2) If one of the matches contains a word break character, readline
1036 will quote it. That's why we switch between
1037 gdb_completer_word_break_characters and
1038 gdb_completer_command_word_break_characters. I'm not sure when
1039 we need this behavior (perhaps for funky characters in C++ symbols?). */
1040
1041 /* Variables which are necessary for fancy command line editing. */
1042 char *gdb_completer_word_break_characters =
1043 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1044
1045 /* When completing on command names, we remove '-' from the list of
1046 word break characters, since we use it in command names. If the
1047 readline library sees one in any of the current completion strings,
1048 it thinks that the string needs to be quoted and automatically supplies
1049 a leading quote. */
1050 char *gdb_completer_command_word_break_characters =
1051 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1052
1053 /* Characters that can be used to quote completion strings. Note that we
1054 can't include '"' because the gdb C parser treats such quoted sequences
1055 as strings. */
1056 char *gdb_completer_quote_characters =
1057 "'";
1058
1059 /* Functions that are used as part of the fancy command line editing. */
1060
1061 /* This can be used for functions which don't want to complete on symbols
1062 but don't want to complete on anything else either. */
1063 /* ARGSUSED */
1064 char **
1065 noop_completer (text, prefix)
1066 char *text;
1067 char *prefix;
1068 {
1069 return NULL;
1070 }
1071
1072 /* Complete on filenames. */
1073 char **
1074 filename_completer (text, word)
1075 char *text;
1076 char *word;
1077 {
1078 /* From readline. */
1079 extern char *filename_completion_function ();
1080 int subsequent_name;
1081 char **return_val;
1082 int return_val_used;
1083 int return_val_alloced;
1084
1085 return_val_used = 0;
1086 /* Small for testing. */
1087 return_val_alloced = 1;
1088 return_val = (char **) xmalloc (return_val_alloced * sizeof (char *));
1089
1090 subsequent_name = 0;
1091 while (1)
1092 {
1093 char *p;
1094 p = filename_completion_function (text, subsequent_name);
1095 if (return_val_used >= return_val_alloced)
1096 {
1097 return_val_alloced *= 2;
1098 return_val =
1099 (char **) xrealloc (return_val,
1100 return_val_alloced * sizeof (char *));
1101 }
1102 if (p == NULL)
1103 {
1104 return_val[return_val_used++] = p;
1105 break;
1106 }
1107 /* Like emacs, don't complete on old versions. Especially useful
1108 in the "source" command. */
1109 if (p[strlen (p) - 1] == '~')
1110 continue;
1111
1112 {
1113 char *q;
1114 if (word == text)
1115 /* Return exactly p. */
1116 return_val[return_val_used++] = p;
1117 else if (word > text)
1118 {
1119 /* Return some portion of p. */
1120 q = xmalloc (strlen (p) + 5);
1121 strcpy (q, p + (word - text));
1122 return_val[return_val_used++] = q;
1123 free (p);
1124 }
1125 else
1126 {
1127 /* Return some of TEXT plus p. */
1128 q = xmalloc (strlen (p) + (text - word) + 5);
1129 strncpy (q, word, text - word);
1130 q[text - word] = '\0';
1131 strcat (q, p);
1132 return_val[return_val_used++] = q;
1133 free (p);
1134 }
1135 }
1136 subsequent_name = 1;
1137 }
1138 #if 0
1139 /* There is no way to do this just long enough to affect quote inserting
1140 without also affecting the next completion. This should be fixed in
1141 readline. FIXME. */
1142 /* Insure that readline does the right thing
1143 with respect to inserting quotes. */
1144 rl_completer_word_break_characters = "";
1145 #endif
1146 return return_val;
1147 }
1148
1149 /* Here are some useful test cases for completion. FIXME: These should
1150 be put in the test suite. They should be tested with both M-? and TAB.
1151
1152 "show output-" "radix"
1153 "show output" "-radix"
1154 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1155 "p " ambiguous (all symbols)
1156 "info t foo" no completions
1157 "info t " no completions
1158 "info t" ambiguous ("info target", "info terminal", etc.)
1159 "info ajksdlfk" no completions
1160 "info ajksdlfk " no completions
1161 "info" " "
1162 "info " ambiguous (all info commands)
1163 "p \"a" no completions (string constant)
1164 "p 'a" ambiguous (all symbols starting with a)
1165 "p b-a" ambiguous (all symbols starting with a)
1166 "p b-" ambiguous (all symbols)
1167 "file Make" "file" (word break hard to screw up here)
1168 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1169 */
1170
1171 /* Generate completions one by one for the completer. Each time we are
1172 called return another potential completion to the caller. The function
1173 is misnamed; it just completes on commands or passes the buck to the
1174 command's completer function; the stuff specific to symbol completion
1175 is in make_symbol_completion_list.
1176
1177 TEXT is readline's idea of the "word" we are looking at; we don't really
1178 like readline's ideas about word breaking so we ignore it.
1179
1180 MATCHES is the number of matches that have currently been collected from
1181 calling this completion function. When zero, then we need to initialize,
1182 otherwise the initialization has already taken place and we can just
1183 return the next potential completion string.
1184
1185 Returns NULL if there are no more completions, else a pointer to a string
1186 which is a possible completion.
1187
1188 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1189 of the line. RL_POINT is the offset in that line of the cursor. You
1190 should pretend that the line ends at RL_POINT. */
1191
1192 static char *
1193 symbol_completion_function (text, matches)
1194 char *text;
1195 int matches;
1196 {
1197 static char **list = (char **)NULL; /* Cache of completions */
1198 static int index; /* Next cached completion */
1199 char *output = NULL;
1200 char *tmp_command, *p;
1201 /* Pointer within tmp_command which corresponds to text. */
1202 char *word;
1203 struct cmd_list_element *c, *result_list;
1204
1205 if (matches == 0)
1206 {
1207 /* The caller is beginning to accumulate a new set of completions, so
1208 we need to find all of them now, and cache them for returning one at
1209 a time on future calls. */
1210
1211 if (list)
1212 {
1213 /* Free the storage used by LIST, but not by the strings inside.
1214 This is because rl_complete_internal () frees the strings. */
1215 free ((PTR)list);
1216 }
1217 list = 0;
1218 index = 0;
1219
1220 /* Choose the default set of word break characters to break completions.
1221 If we later find out that we are doing completions on command strings
1222 (as opposed to strings supplied by the individual command completer
1223 functions, which can be any string) then we will switch to the
1224 special word break set for command strings, which leaves out the
1225 '-' character used in some commands. */
1226
1227 rl_completer_word_break_characters =
1228 gdb_completer_word_break_characters;
1229
1230 /* Decide whether to complete on a list of gdb commands or on symbols. */
1231 tmp_command = (char *) alloca (rl_point + 1);
1232 p = tmp_command;
1233
1234 strncpy (tmp_command, rl_line_buffer, rl_point);
1235 tmp_command[rl_point] = '\0';
1236 /* Since text always contains some number of characters leading up
1237 to rl_point, we can find the equivalent position in tmp_command
1238 by subtracting that many characters from the end of tmp_command. */
1239 word = tmp_command + rl_point - strlen (text);
1240
1241 if (rl_point == 0)
1242 {
1243 /* An empty line we want to consider ambiguous; that is, it
1244 could be any command. */
1245 c = (struct cmd_list_element *) -1;
1246 result_list = 0;
1247 }
1248 else
1249 {
1250 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1251 }
1252
1253 /* Move p up to the next interesting thing. */
1254 while (*p == ' ' || *p == '\t')
1255 {
1256 p++;
1257 }
1258
1259 if (!c)
1260 {
1261 /* It is an unrecognized command. So there are no
1262 possible completions. */
1263 list = NULL;
1264 }
1265 else if (c == (struct cmd_list_element *) -1)
1266 {
1267 char *q;
1268
1269 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1270 doesn't advance over that thing itself. Do so now. */
1271 q = p;
1272 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
1273 ++q;
1274 if (q != tmp_command + rl_point)
1275 {
1276 /* There is something beyond the ambiguous
1277 command, so there are no possible completions. For
1278 example, "info t " or "info t foo" does not complete
1279 to anything, because "info t" can be "info target" or
1280 "info terminal". */
1281 list = NULL;
1282 }
1283 else
1284 {
1285 /* We're trying to complete on the command which was ambiguous.
1286 This we can deal with. */
1287 if (result_list)
1288 {
1289 list = complete_on_cmdlist (*result_list->prefixlist, p,
1290 word);
1291 }
1292 else
1293 {
1294 list = complete_on_cmdlist (cmdlist, p, word);
1295 }
1296 /* Insure that readline does the right thing with respect to
1297 inserting quotes. */
1298 rl_completer_word_break_characters =
1299 gdb_completer_command_word_break_characters;
1300 }
1301 }
1302 else
1303 {
1304 /* We've recognized a full command. */
1305
1306 if (p == tmp_command + rl_point)
1307 {
1308 /* There is no non-whitespace in the line beyond the command. */
1309
1310 if (p[-1] == ' ' || p[-1] == '\t')
1311 {
1312 /* The command is followed by whitespace; we need to complete
1313 on whatever comes after command. */
1314 if (c->prefixlist)
1315 {
1316 /* It is a prefix command; what comes after it is
1317 a subcommand (e.g. "info "). */
1318 list = complete_on_cmdlist (*c->prefixlist, p, word);
1319
1320 /* Insure that readline does the right thing
1321 with respect to inserting quotes. */
1322 rl_completer_word_break_characters =
1323 gdb_completer_command_word_break_characters;
1324 }
1325 else
1326 {
1327 /* It is a normal command; what comes after it is
1328 completed by the command's completer function. */
1329 list = (*c->completer) (p, word);
1330 }
1331 }
1332 else
1333 {
1334 /* The command is not followed by whitespace; we need to
1335 complete on the command itself. e.g. "p" which is a
1336 command itself but also can complete to "print", "ptype"
1337 etc. */
1338 char *q;
1339
1340 /* Find the command we are completing on. */
1341 q = p;
1342 while (q > tmp_command)
1343 {
1344 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
1345 --q;
1346 else
1347 break;
1348 }
1349
1350 list = complete_on_cmdlist (result_list, q, word);
1351
1352 /* Insure that readline does the right thing
1353 with respect to inserting quotes. */
1354 rl_completer_word_break_characters =
1355 gdb_completer_command_word_break_characters;
1356 }
1357 }
1358 else
1359 {
1360 /* There is non-whitespace beyond the command. */
1361
1362 if (c->prefixlist && !c->allow_unknown)
1363 {
1364 /* It is an unrecognized subcommand of a prefix command,
1365 e.g. "info adsfkdj". */
1366 list = NULL;
1367 }
1368 else
1369 {
1370 /* It is a normal command. */
1371 list = (*c->completer) (p, word);
1372 }
1373 }
1374 }
1375 }
1376
1377 /* If we found a list of potential completions during initialization then
1378 dole them out one at a time. The vector of completions is NULL
1379 terminated, so after returning the last one, return NULL (and continue
1380 to do so) each time we are called after that, until a new list is
1381 available. */
1382
1383 if (list)
1384 {
1385 output = list[index];
1386 if (output)
1387 {
1388 index++;
1389 }
1390 }
1391
1392 #if 0
1393 /* Can't do this because readline hasn't yet checked the word breaks
1394 for figuring out whether to insert a quote. */
1395 if (output == NULL)
1396 /* Make sure the word break characters are set back to normal for the
1397 next time that readline tries to complete something. */
1398 rl_completer_word_break_characters =
1399 gdb_completer_word_break_characters;
1400 #endif
1401
1402 return (output);
1403 }
1404
1405 /* Skip over a possibly quoted word (as defined by the quote characters
1406 and word break characters the completer uses). Returns pointer to the
1407 location after the "word". */
1408
1409 char *
1410 skip_quoted (str)
1411 char *str;
1412 {
1413 char quote_char = '\0';
1414 char *scan;
1415
1416 for (scan = str; *scan != '\0'; scan++)
1417 {
1418 if (quote_char != '\0')
1419 {
1420 /* Ignore everything until the matching close quote char */
1421 if (*scan == quote_char)
1422 {
1423 /* Found matching close quote. */
1424 scan++;
1425 break;
1426 }
1427 }
1428 else if (strchr (gdb_completer_quote_characters, *scan))
1429 {
1430 /* Found start of a quoted string. */
1431 quote_char = *scan;
1432 }
1433 else if (strchr (gdb_completer_word_break_characters, *scan))
1434 {
1435 break;
1436 }
1437 }
1438 return (scan);
1439 }
1440
1441 \f
1442 #ifdef STOP_SIGNAL
1443 static void
1444 stop_sig (signo)
1445 int signo;
1446 {
1447 #if STOP_SIGNAL == SIGTSTP
1448 signal (SIGTSTP, SIG_DFL);
1449 sigsetmask (0);
1450 kill (getpid (), SIGTSTP);
1451 signal (SIGTSTP, stop_sig);
1452 #else
1453 signal (STOP_SIGNAL, stop_sig);
1454 #endif
1455 printf_unfiltered ("%s", prompt);
1456 gdb_flush (gdb_stdout);
1457
1458 /* Forget about any previous command -- null line now will do nothing. */
1459 dont_repeat ();
1460 }
1461 #endif /* STOP_SIGNAL */
1462
1463 /* Initialize signal handlers. */
1464 static void
1465 do_nothing (signo)
1466 int signo;
1467 {
1468 }
1469
1470 static void
1471 init_signals ()
1472 {
1473 signal (SIGINT, request_quit);
1474
1475 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1476 passed to the inferior, which we don't want. It would be
1477 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1478 on BSD4.3 systems using vfork, that can affect the
1479 GDB process as well as the inferior (the signal handling tables
1480 might be in memory, shared between the two). Since we establish
1481 a handler for SIGQUIT, when we call exec it will set the signal
1482 to SIG_DFL for us. */
1483 signal (SIGQUIT, do_nothing);
1484 if (signal (SIGHUP, do_nothing) != SIG_IGN)
1485 signal (SIGHUP, disconnect);
1486 signal (SIGFPE, float_handler);
1487
1488 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1489 signal (SIGWINCH, SIGWINCH_HANDLER);
1490 #endif
1491 }
1492 \f
1493 /* Read one line from the command input stream `instream'
1494 into the local static buffer `linebuffer' (whose current length
1495 is `linelength').
1496 The buffer is made bigger as necessary.
1497 Returns the address of the start of the line.
1498
1499 NULL is returned for end of file.
1500
1501 *If* the instream == stdin & stdin is a terminal, the line read
1502 is copied into the file line saver (global var char *line,
1503 length linesize) so that it can be duplicated.
1504
1505 This routine either uses fancy command line editing or
1506 simple input as the user has requested. */
1507
1508 char *
1509 command_line_input (prrompt, repeat, annotation_suffix)
1510 char *prrompt;
1511 int repeat;
1512 char *annotation_suffix;
1513 {
1514 static char *linebuffer = 0;
1515 static unsigned linelength = 0;
1516 register char *p;
1517 char *p1;
1518 char *rl;
1519 char *local_prompt = prrompt;
1520 register int c;
1521 char *nline;
1522 char got_eof = 0;
1523
1524 if (annotation_level > 1 && instream == stdin)
1525 {
1526 local_prompt = alloca ((prrompt == NULL ? 0 : strlen (prrompt))
1527 + strlen (annotation_suffix) + 40);
1528 if (prrompt == NULL)
1529 local_prompt[0] = '\0';
1530 else
1531 strcpy (local_prompt, prrompt);
1532 strcat (local_prompt, "\n\032\032");
1533 strcat (local_prompt, annotation_suffix);
1534 strcat (local_prompt, "\n");
1535 }
1536
1537 if (linebuffer == 0)
1538 {
1539 linelength = 80;
1540 linebuffer = (char *) xmalloc (linelength);
1541 }
1542
1543 p = linebuffer;
1544
1545 /* Control-C quits instantly if typed while in this loop
1546 since it should not wait until the user types a newline. */
1547 immediate_quit++;
1548 #ifdef STOP_SIGNAL
1549 if (job_control)
1550 signal (STOP_SIGNAL, stop_sig);
1551 #endif
1552
1553 while (1)
1554 {
1555 /* Make sure that all output has been output. Some machines may let
1556 you get away with leaving out some of the gdb_flush, but not all. */
1557 wrap_here ("");
1558 gdb_flush (gdb_stdout);
1559 gdb_flush (gdb_stderr);
1560
1561 if (source_file_name != NULL)
1562 {
1563 ++source_line_number;
1564 sprintf (source_error,
1565 "%s%s:%d: Error in sourced command file:\n",
1566 source_pre_error,
1567 source_file_name,
1568 source_line_number);
1569 error_pre_print = source_error;
1570 }
1571
1572 if (annotation_level > 1 && instream == stdin)
1573 {
1574 printf_unfiltered ("\n\032\032pre-");
1575 printf_unfiltered (annotation_suffix);
1576 printf_unfiltered ("\n");
1577 }
1578
1579 /* Don't use fancy stuff if not talking to stdin. */
1580 if (command_editing_p && instream == stdin
1581 && ISATTY (instream))
1582 rl = readline (local_prompt);
1583 else
1584 rl = gdb_readline (local_prompt);
1585
1586 if (annotation_level > 1 && instream == stdin)
1587 {
1588 printf_unfiltered ("\n\032\032post-");
1589 printf_unfiltered (annotation_suffix);
1590 printf_unfiltered ("\n");
1591 }
1592
1593 if (!rl || rl == (char *) EOF)
1594 {
1595 got_eof = 1;
1596 break;
1597 }
1598 if (strlen(rl) + 1 + (p - linebuffer) > linelength)
1599 {
1600 linelength = strlen(rl) + 1 + (p - linebuffer);
1601 nline = (char *) xrealloc (linebuffer, linelength);
1602 p += nline - linebuffer;
1603 linebuffer = nline;
1604 }
1605 p1 = rl;
1606 /* Copy line. Don't copy null at end. (Leaves line alone
1607 if this was just a newline) */
1608 while (*p1)
1609 *p++ = *p1++;
1610
1611 free (rl); /* Allocated in readline. */
1612
1613 if (p == linebuffer || *(p - 1) != '\\')
1614 break;
1615
1616 p--; /* Put on top of '\'. */
1617 local_prompt = (char *) 0;
1618 }
1619
1620 #ifdef STOP_SIGNAL
1621 if (job_control)
1622 signal (STOP_SIGNAL, SIG_DFL);
1623 #endif
1624 immediate_quit--;
1625
1626 if (got_eof)
1627 return NULL;
1628
1629 #define SERVER_COMMAND_LENGTH 7
1630 server_command =
1631 (p - linebuffer > SERVER_COMMAND_LENGTH)
1632 && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
1633 if (server_command)
1634 {
1635 /* Note that we don't set `line'. Between this and the check in
1636 dont_repeat, this insures that repeating will still do the
1637 right thing. */
1638 *p = '\0';
1639 return linebuffer + SERVER_COMMAND_LENGTH;
1640 }
1641
1642 /* Do history expansion if that is wished. */
1643 if (history_expansion_p && instream == stdin
1644 && ISATTY (instream))
1645 {
1646 char *history_value;
1647 int expanded;
1648
1649 *p = '\0'; /* Insert null now. */
1650 expanded = history_expand (linebuffer, &history_value);
1651 if (expanded)
1652 {
1653 /* Print the changes. */
1654 printf_unfiltered ("%s\n", history_value);
1655
1656 /* If there was an error, call this function again. */
1657 if (expanded < 0)
1658 {
1659 free (history_value);
1660 return command_line_input (prrompt, repeat, annotation_suffix);
1661 }
1662 if (strlen (history_value) > linelength)
1663 {
1664 linelength = strlen (history_value) + 1;
1665 linebuffer = (char *) xrealloc (linebuffer, linelength);
1666 }
1667 strcpy (linebuffer, history_value);
1668 p = linebuffer + strlen(linebuffer);
1669 free (history_value);
1670 }
1671 }
1672
1673 /* If we just got an empty line, and that is supposed
1674 to repeat the previous command, return the value in the
1675 global buffer. */
1676 if (repeat)
1677 {
1678 if (p == linebuffer)
1679 return line;
1680 p1 = linebuffer;
1681 while (*p1 == ' ' || *p1 == '\t')
1682 p1++;
1683 if (!*p1)
1684 return line;
1685 }
1686
1687 *p = 0;
1688
1689 /* Add line to history if appropriate. */
1690 if (instream == stdin
1691 && ISATTY (stdin) && *linebuffer)
1692 add_history (linebuffer);
1693
1694 /* Note: lines consisting solely of comments are added to the command
1695 history. This is useful when you type a command, and then
1696 realize you don't want to execute it quite yet. You can comment
1697 out the command and then later fetch it from the value history
1698 and remove the '#'. The kill ring is probably better, but some
1699 people are in the habit of commenting things out. */
1700 p1 = linebuffer;
1701 while ((c = *p1++) != '\0')
1702 {
1703 if (c == '"')
1704 while ((c = *p1++) != '"')
1705 {
1706 /* Make sure an escaped '"' doesn't make us think the string
1707 is ended. */
1708 if (c == '\\')
1709 parse_escape (&p1);
1710 if (c == '\0')
1711 break;
1712 }
1713 else if (c == '\'')
1714 while ((c = *p1++) != '\'')
1715 {
1716 /* Make sure an escaped '\'' doesn't make us think the string
1717 is ended. */
1718 if (c == '\\')
1719 parse_escape (&p1);
1720 if (c == '\0')
1721 break;
1722 }
1723 else if (c == '#')
1724 {
1725 /* Found a comment. */
1726 p1[-1] = '\0';
1727 break;
1728 }
1729 }
1730
1731 /* Save into global buffer if appropriate. */
1732 if (repeat)
1733 {
1734 if (linelength > linesize)
1735 {
1736 line = xrealloc (line, linelength);
1737 linesize = linelength;
1738 }
1739 strcpy (line, linebuffer);
1740 return line;
1741 }
1742
1743 return linebuffer;
1744 }
1745 \f
1746
1747 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
1748 code bodies. This is typically used when we encounter an "else"
1749 clause for an "if" command. */
1750
1751 static void
1752 realloc_body_list (command, new_length)
1753 struct command_line *command;
1754 int new_length;
1755 {
1756 int n;
1757 struct command_line **body_list;
1758
1759 n = command->body_count;
1760
1761 /* Nothing to do? */
1762 if (new_length <= n)
1763 return;
1764
1765 body_list = (struct command_line **)
1766 xmalloc (sizeof (struct command_line *) * new_length);
1767
1768 memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
1769
1770 free (command->body_list);
1771 command->body_list = body_list;
1772 command->body_count = new_length;
1773 }
1774
1775 /* Read one line from the input stream. If the command is an "else" or
1776 "end", return such an indication to the caller. */
1777
1778 static enum misc_command_type
1779 read_next_line (command)
1780 struct command_line **command;
1781 {
1782 char *p, *p1, *prompt_ptr, control_prompt[256];
1783 int i = 0;
1784
1785 if (control_level >= 254)
1786 error ("Control nesting too deep!\n");
1787
1788 /* Set a prompt based on the nesting of the control commands. */
1789 if (instream == stdin)
1790 {
1791 for (i = 0; i < control_level; i++)
1792 control_prompt[i] = ' ';
1793 control_prompt[i] = '>';
1794 control_prompt[i+1] = '\0';
1795 prompt_ptr = (char *)&control_prompt[0];
1796 }
1797 else
1798 prompt_ptr = NULL;
1799
1800 p = command_line_input (prompt_ptr, instream == stdin, NULL);
1801
1802 /* Not sure what to do here. */
1803 if (p == NULL)
1804 return end_command;
1805
1806 /* Strip leading and trailing whitespace. */
1807 while (*p == ' ' || *p == '\t')
1808 p++;
1809
1810 p1 = p + strlen (p);
1811 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
1812 p1--;
1813
1814 /* Blanks and comments don't really do anything, but we need to
1815 distinguish them from else, end and other commands which can be
1816 executed. */
1817 if (p1 == p || p[0] == '#')
1818 return nop_command;
1819
1820 /* Is this the end of a simple, while, or if control structure? */
1821 if (p1 - p == 3 && !strncmp (p, "end", 3))
1822 return end_command;
1823
1824 /* Is the else clause of an if control structure? */
1825 if (p1 - p == 4 && !strncmp (p, "else", 4))
1826 return else_command;
1827
1828 /* Check for while, if, break, continue, etc and build a new command
1829 line structure for them. */
1830 if (p1 - p > 5 && !strncmp (p, "while", 5))
1831 *command = build_command_line (while_control, p + 6);
1832 else if (p1 - p > 2 && !strncmp (p, "if", 2))
1833 *command = build_command_line (if_control, p + 3);
1834 else if (p1 - p == 5 && !strncmp (p, "loop_break", 5))
1835 {
1836 *command = (struct command_line *)
1837 xmalloc (sizeof (struct command_line));
1838 (*command)->next = NULL;
1839 (*command)->line = NULL;
1840 (*command)->control_type = break_control;
1841 (*command)->body_count = 0;
1842 (*command)->body_list = NULL;
1843 }
1844 else if (p1 - p == 8 && !strncmp (p, "loop_continue", 8))
1845 {
1846 *command = (struct command_line *)
1847 xmalloc (sizeof (struct command_line));
1848 (*command)->next = NULL;
1849 (*command)->line = NULL;
1850 (*command)->control_type = continue_control;
1851 (*command)->body_count = 0;
1852 (*command)->body_list = NULL;
1853 }
1854 else
1855 {
1856 /* A normal command. */
1857 *command = (struct command_line *)
1858 xmalloc (sizeof (struct command_line));
1859 (*command)->next = NULL;
1860 (*command)->line = savestring (p, p1 - p);
1861 (*command)->control_type = simple_control;
1862 (*command)->body_count = 0;
1863 (*command)->body_list = NULL;
1864 }
1865
1866 /* Nothing special. */
1867 return ok_command;
1868 }
1869
1870 /* Recursively read in the control structures and create a command_line
1871 tructure from them.
1872
1873 The parent_control parameter is the control structure in which the
1874 following commands are nested. */
1875
1876 static enum command_control_type
1877 recurse_read_control_structure (current_cmd)
1878 struct command_line *current_cmd;
1879 {
1880 int current_body, i;
1881 enum misc_command_type val;
1882 enum command_control_type ret;
1883 struct command_line **body_ptr, *child_tail, *next;
1884 struct cleanup *old_chains, *tmp_chains;
1885
1886 old_chains = NULL;
1887 child_tail = NULL;
1888 current_body = 1;
1889
1890 /* Sanity checks. */
1891 if (current_cmd->control_type == simple_control)
1892 {
1893 error ("Recursed on a simple control type\n");
1894 return invalid_control;
1895 }
1896
1897 if (current_body > current_cmd->body_count)
1898 {
1899 error ("Allocated body is smaller than this command type needs\n");
1900 return invalid_control;
1901 }
1902
1903 /* Read lines from the input stream and build control structures. */
1904 while (1)
1905 {
1906 dont_repeat ();
1907
1908 next = NULL;
1909 val = read_next_line (&next);
1910
1911 /* Just skip blanks and comments. */
1912 if (val == nop_command)
1913 continue;
1914
1915 if (val == end_command)
1916 {
1917 if (current_cmd->control_type == while_control
1918 || current_cmd->control_type == if_control)
1919 {
1920 /* Success reading an entire control structure. */
1921 ret = simple_control;
1922 break;
1923 }
1924 else
1925 {
1926 ret = invalid_control;
1927 break;
1928 }
1929 }
1930
1931 /* Not the end of a control structure. */
1932 if (val == else_command)
1933 {
1934 if (current_cmd->control_type == if_control
1935 && current_body == 1)
1936 {
1937 realloc_body_list (current_cmd, 2);
1938 current_body = 2;
1939 child_tail = NULL;
1940 continue;
1941 }
1942 else
1943 {
1944 ret = invalid_control;
1945 break;
1946 }
1947 }
1948
1949 if (child_tail)
1950 {
1951 child_tail->next = next;
1952 }
1953 else
1954 {
1955 /* We have just read the first line of the child's control
1956 structure. From now on, arrange to throw away the line
1957 we have if we quit or get an error. */
1958 body_ptr = current_cmd->body_list;
1959 for (i = 1; i < current_body; i++)
1960 body_ptr++;
1961
1962 *body_ptr = next;
1963
1964 tmp_chains = make_cleanup (free_command_lines, body_ptr);
1965
1966 if (!old_chains)
1967 old_chains = tmp_chains;
1968 }
1969
1970 child_tail = next;
1971
1972 /* If the latest line is another control structure, then recurse
1973 on it. */
1974 if (next->control_type == while_control
1975 || next->control_type == if_control)
1976 {
1977 control_level++;
1978 ret = recurse_read_control_structure (next);
1979 control_level--;
1980
1981 if (ret != simple_control)
1982 break;
1983 }
1984 }
1985
1986 dont_repeat ();
1987 if (ret == invalid_control && old_chains)
1988 do_cleanups (old_chains);
1989 else if (old_chains)
1990 discard_cleanups (old_chains);
1991
1992 return ret;
1993 }
1994
1995
1996 /* Read lines from the input stream
1997 and accumulate them in a chain of struct command_line's
1998 which is then returned. */
1999
2000 struct command_line *
2001 read_command_lines ()
2002 {
2003 struct command_line *head, *tail, *next;
2004 struct cleanup *old_chain;
2005 enum command_control_type ret;
2006 enum misc_command_type val;
2007
2008 head = tail = NULL;
2009 old_chain = NULL;
2010
2011 while (1)
2012 {
2013 val = read_next_line (&next);
2014
2015 /* Ignore blank lines or comments. */
2016 if (val == nop_command)
2017 continue;
2018
2019 if (val == end_command)
2020 {
2021 ret = simple_control;
2022 break;
2023 }
2024
2025 if (val != ok_command)
2026 {
2027 ret = invalid_control;
2028 break;
2029 }
2030
2031 if (next->control_type == while_control
2032 || next->control_type == if_control)
2033 {
2034 control_level++;
2035 ret = recurse_read_control_structure (next);
2036 control_level--;
2037
2038 if (ret == invalid_control)
2039 break;
2040 }
2041
2042 if (tail)
2043 {
2044 tail->next = next;
2045 }
2046 else
2047 {
2048 head = next;
2049 old_chain = make_cleanup (free_command_lines, &head);
2050 }
2051 tail = next;
2052 }
2053
2054 dont_repeat ();
2055
2056 if (head)
2057 {
2058 if (ret != invalid_control)
2059 {
2060 discard_cleanups (old_chain);
2061 return head;
2062 }
2063 else
2064 do_cleanups (old_chain);
2065 }
2066
2067 return NULL;
2068 }
2069
2070 /* Free a chain of struct command_line's. */
2071
2072 void
2073 free_command_lines (lptr)
2074 struct command_line **lptr;
2075 {
2076 register struct command_line *l = *lptr;
2077 register struct command_line *next;
2078 struct command_line **blist;
2079 int i;
2080
2081 while (l)
2082 {
2083 if (l->body_count > 0)
2084 {
2085 blist = l->body_list;
2086 for (i = 0; i < l->body_count; i++, blist++)
2087 free_command_lines (blist);
2088 }
2089 next = l->next;
2090 free (l->line);
2091 free ((PTR)l);
2092 l = next;
2093 }
2094 }
2095 \f
2096 /* Add an element to the list of info subcommands. */
2097
2098 void
2099 add_info (name, fun, doc)
2100 char *name;
2101 void (*fun) PARAMS ((char *, int));
2102 char *doc;
2103 {
2104 add_cmd (name, no_class, fun, doc, &infolist);
2105 }
2106
2107 /* Add an alias to the list of info subcommands. */
2108
2109 void
2110 add_info_alias (name, oldname, abbrev_flag)
2111 char *name;
2112 char *oldname;
2113 int abbrev_flag;
2114 {
2115 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
2116 }
2117
2118 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2119 Therefore, its own definition is called only for "info" with no args. */
2120
2121 /* ARGSUSED */
2122 static void
2123 info_command (arg, from_tty)
2124 char *arg;
2125 int from_tty;
2126 {
2127 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2128 help_list (infolist, "info ", -1, gdb_stdout);
2129 }
2130
2131 /* The "complete" command is used by Emacs to implement completion. */
2132
2133 /* ARGSUSED */
2134 static void
2135 complete_command (arg, from_tty)
2136 char *arg;
2137 int from_tty;
2138 {
2139 int i;
2140 char *completion;
2141
2142 dont_repeat ();
2143
2144 if (arg == NULL)
2145 {
2146 rl_line_buffer[0] = '\0';
2147 rl_point = 0;
2148 }
2149 else
2150 {
2151 strcpy (rl_line_buffer, arg);
2152 rl_point = strlen (arg);
2153 }
2154
2155 for (completion = symbol_completion_function (rl_line_buffer, i = 0);
2156 completion;
2157 completion = symbol_completion_function (rl_line_buffer, ++i))
2158 printf_unfiltered ("%s\n", completion);
2159 }
2160
2161 /* The "show" command with no arguments shows all the settings. */
2162
2163 /* ARGSUSED */
2164 static void
2165 show_command (arg, from_tty)
2166 char *arg;
2167 int from_tty;
2168 {
2169 cmd_show_list (showlist, from_tty, "");
2170 }
2171 \f
2172 /* Add an element to the list of commands. */
2173
2174 void
2175 add_com (name, class, fun, doc)
2176 char *name;
2177 enum command_class class;
2178 void (*fun) PARAMS ((char *, int));
2179 char *doc;
2180 {
2181 add_cmd (name, class, fun, doc, &cmdlist);
2182 }
2183
2184 /* Add an alias or abbreviation command to the list of commands. */
2185
2186 void
2187 add_com_alias (name, oldname, class, abbrev_flag)
2188 char *name;
2189 char *oldname;
2190 enum command_class class;
2191 int abbrev_flag;
2192 {
2193 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
2194 }
2195
2196 void
2197 error_no_arg (why)
2198 char *why;
2199 {
2200 error ("Argument required (%s).", why);
2201 }
2202
2203 /* ARGSUSED */
2204 static void
2205 help_command (command, from_tty)
2206 char *command;
2207 int from_tty; /* Ignored */
2208 {
2209 help_cmd (command, gdb_stdout);
2210 }
2211 \f
2212 static void
2213 validate_comname (comname)
2214 char *comname;
2215 {
2216 register char *p;
2217
2218 if (comname == 0)
2219 error_no_arg ("name of command to define");
2220
2221 p = comname;
2222 while (*p)
2223 {
2224 if (!isalnum(*p) && *p != '-')
2225 error ("Junk in argument list: \"%s\"", p);
2226 p++;
2227 }
2228 }
2229
2230 /* This is just a placeholder in the command data structures. */
2231 static void
2232 user_defined_command (ignore, from_tty)
2233 char *ignore;
2234 int from_tty;
2235 {
2236 }
2237
2238 static void
2239 define_command (comname, from_tty)
2240 char *comname;
2241 int from_tty;
2242 {
2243 register struct command_line *cmds;
2244 register struct cmd_list_element *c, *newc, *hookc = 0;
2245 char *tem = comname;
2246 #define HOOK_STRING "hook-"
2247 #define HOOK_LEN 5
2248
2249 validate_comname (comname);
2250
2251 /* Look it up, and verify that we got an exact match. */
2252 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
2253 if (c && !STREQ (comname, c->name))
2254 c = 0;
2255
2256 if (c)
2257 {
2258 if (c->class == class_user || c->class == class_alias)
2259 tem = "Redefine command \"%s\"? ";
2260 else
2261 tem = "Really redefine built-in command \"%s\"? ";
2262 if (!query (tem, c->name))
2263 error ("Command \"%s\" not redefined.", c->name);
2264 }
2265
2266 /* If this new command is a hook, then mark the command which it
2267 is hooking. Note that we allow hooking `help' commands, so that
2268 we can hook the `stop' pseudo-command. */
2269
2270 if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
2271 {
2272 /* Look up cmd it hooks, and verify that we got an exact match. */
2273 tem = comname+HOOK_LEN;
2274 hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
2275 if (hookc && !STREQ (comname+HOOK_LEN, hookc->name))
2276 hookc = 0;
2277 if (!hookc)
2278 {
2279 warning ("Your new `%s' command does not hook any existing command.",
2280 comname);
2281 if (!query ("Proceed? ", (char *)0))
2282 error ("Not confirmed.");
2283 }
2284 }
2285
2286 comname = savestring (comname, strlen (comname));
2287
2288 /* If the rest of the commands will be case insensitive, this one
2289 should behave in the same manner. */
2290 for (tem = comname; *tem; tem++)
2291 if (isupper(*tem)) *tem = tolower(*tem);
2292
2293 if (from_tty)
2294 {
2295 printf_unfiltered ("Type commands for definition of \"%s\".\n\
2296 End with a line saying just \"end\".\n", comname);
2297 gdb_flush (gdb_stdout);
2298 }
2299
2300 control_level = 0;
2301 cmds = read_command_lines ();
2302
2303 if (c && c->class == class_user)
2304 free_command_lines (&c->user_commands);
2305
2306 newc = add_cmd (comname, class_user, user_defined_command,
2307 (c && c->class == class_user)
2308 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
2309 newc->user_commands = cmds;
2310
2311 /* If this new command is a hook, then mark both commands as being
2312 tied. */
2313 if (hookc)
2314 {
2315 hookc->hook = newc; /* Target gets hooked. */
2316 newc->hookee = hookc; /* We are marked as hooking target cmd. */
2317 }
2318 }
2319
2320 static void
2321 document_command (comname, from_tty)
2322 char *comname;
2323 int from_tty;
2324 {
2325 struct command_line *doclines;
2326 register struct cmd_list_element *c;
2327 char *tem = comname;
2328
2329 validate_comname (comname);
2330
2331 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
2332
2333 if (c->class != class_user)
2334 error ("Command \"%s\" is built-in.", comname);
2335
2336 if (from_tty)
2337 printf_unfiltered ("Type documentation for \"%s\".\n\
2338 End with a line saying just \"end\".\n", comname);
2339
2340 doclines = read_command_lines ();
2341
2342 if (c->doc) free (c->doc);
2343
2344 {
2345 register struct command_line *cl1;
2346 register int len = 0;
2347
2348 for (cl1 = doclines; cl1; cl1 = cl1->next)
2349 len += strlen (cl1->line) + 1;
2350
2351 c->doc = (char *) xmalloc (len + 1);
2352 *c->doc = 0;
2353
2354 for (cl1 = doclines; cl1; cl1 = cl1->next)
2355 {
2356 strcat (c->doc, cl1->line);
2357 if (cl1->next)
2358 strcat (c->doc, "\n");
2359 }
2360 }
2361
2362 free_command_lines (&doclines);
2363 }
2364 \f
2365 void
2366 print_gnu_advertisement ()
2367 {
2368 printf_unfiltered ("\
2369 GDB is free software and you are welcome to distribute copies of it\n\
2370 under certain conditions; type \"show copying\" to see the conditions.\n\
2371 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
2372 ");
2373 }
2374
2375 void
2376 print_gdb_version (stream)
2377 GDB_FILE *stream;
2378 {
2379 fprintf_filtered (stream, "\
2380 GDB %s (%s", version, host_name);
2381
2382 if (!STREQ (host_name, target_name))
2383 fprintf_filtered (stream, " --target %s", target_name);
2384
2385 fprintf_filtered (stream, "), ");
2386 wrap_here("");
2387 fprintf_filtered (stream, "Copyright 1994 Free Software Foundation, Inc.");
2388 }
2389
2390 /* ARGSUSED */
2391 static void
2392 show_version (args, from_tty)
2393 char *args;
2394 int from_tty;
2395 {
2396 immediate_quit++;
2397 print_gnu_advertisement ();
2398 print_gdb_version (gdb_stdout);
2399 printf_filtered ("\n");
2400 immediate_quit--;
2401 }
2402 \f
2403 /* xgdb calls this to reprint the usual GDB prompt. Obsolete now that xgdb
2404 is obsolete. */
2405
2406 void
2407 print_prompt ()
2408 {
2409 printf_unfiltered ("%s", prompt);
2410 gdb_flush (gdb_stdout);
2411 }
2412 \f
2413 void
2414 quit_command (args, from_tty)
2415 char *args;
2416 int from_tty;
2417 {
2418 if (inferior_pid != 0 && target_has_execution)
2419 {
2420 if (attach_flag)
2421 {
2422 if (query ("The program is running. Quit anyway (and detach it)? "))
2423 target_detach (args, from_tty);
2424 else
2425 error ("Not confirmed.");
2426 }
2427 else
2428 {
2429 if (query ("The program is running. Quit anyway (and kill it)? "))
2430 target_kill ();
2431 else
2432 error ("Not confirmed.");
2433 }
2434 }
2435 /* UDI wants this, to kill the TIP. */
2436 target_close (1);
2437
2438 /* Save the history information if it is appropriate to do so. */
2439 if (write_history_p && history_filename)
2440 write_history (history_filename);
2441
2442 exit (0);
2443 }
2444
2445 /* Returns whether GDB is running on a terminal and whether the user
2446 desires that questions be asked of them on that terminal. */
2447
2448 int
2449 input_from_terminal_p ()
2450 {
2451 return gdb_has_a_terminal () && (instream == stdin) & caution;
2452 }
2453 \f
2454 /* ARGSUSED */
2455 static void
2456 pwd_command (args, from_tty)
2457 char *args;
2458 int from_tty;
2459 {
2460 if (args) error ("The \"pwd\" command does not take an argument: %s", args);
2461 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
2462
2463 if (!STREQ (gdb_dirbuf, current_directory))
2464 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
2465 current_directory, gdb_dirbuf);
2466 else
2467 printf_unfiltered ("Working directory %s.\n", current_directory);
2468 }
2469
2470 void
2471 cd_command (dir, from_tty)
2472 char *dir;
2473 int from_tty;
2474 {
2475 int len;
2476 /* Found something other than leading repetitions of "/..". */
2477 int found_real_path;
2478 char *p;
2479
2480 /* If the new directory is absolute, repeat is a no-op; if relative,
2481 repeat might be useful but is more likely to be a mistake. */
2482 dont_repeat ();
2483
2484 if (dir == 0)
2485 error_no_arg ("new working directory");
2486
2487 dir = tilde_expand (dir);
2488 make_cleanup (free, dir);
2489
2490 if (chdir (dir) < 0)
2491 perror_with_name (dir);
2492
2493 len = strlen (dir);
2494 dir = savestring (dir, len - (len > 1 && dir[len-1] == '/'));
2495 if (dir[0] == '/')
2496 current_directory = dir;
2497 else
2498 {
2499 if (current_directory[0] == '/' && current_directory[1] == '\0')
2500 current_directory = concat (current_directory, dir, NULL);
2501 else
2502 current_directory = concat (current_directory, "/", dir, NULL);
2503 free (dir);
2504 }
2505
2506 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2507
2508 found_real_path = 0;
2509 for (p = current_directory; *p;)
2510 {
2511 if (p[0] == '/' && p[1] == '.' && (p[2] == 0 || p[2] == '/'))
2512 strcpy (p, p + 2);
2513 else if (p[0] == '/' && p[1] == '.' && p[2] == '.'
2514 && (p[3] == 0 || p[3] == '/'))
2515 {
2516 if (found_real_path)
2517 {
2518 /* Search backwards for the directory just before the "/.."
2519 and obliterate it and the "/..". */
2520 char *q = p;
2521 while (q != current_directory && q[-1] != '/')
2522 --q;
2523
2524 if (q == current_directory)
2525 /* current_directory is
2526 a relative pathname ("can't happen"--leave it alone). */
2527 ++p;
2528 else
2529 {
2530 strcpy (q - 1, p + 3);
2531 p = q - 1;
2532 }
2533 }
2534 else
2535 /* We are dealing with leading repetitions of "/..", for example
2536 "/../..", which is the Mach super-root. */
2537 p += 3;
2538 }
2539 else
2540 {
2541 found_real_path = 1;
2542 ++p;
2543 }
2544 }
2545
2546 forget_cached_source_info ();
2547
2548 if (from_tty)
2549 pwd_command ((char *) 0, 1);
2550 }
2551 \f
2552 struct source_cleanup_lines_args {
2553 int old_line;
2554 char *old_file;
2555 char *old_pre_error;
2556 char *old_error_pre_print;
2557 };
2558
2559 static void
2560 source_cleanup_lines (args)
2561 PTR args;
2562 {
2563 struct source_cleanup_lines_args *p =
2564 (struct source_cleanup_lines_args *)args;
2565 source_line_number = p->old_line;
2566 source_file_name = p->old_file;
2567 source_pre_error = p->old_pre_error;
2568 error_pre_print = p->old_error_pre_print;
2569 }
2570
2571 /* ARGSUSED */
2572 void
2573 source_command (args, from_tty)
2574 char *args;
2575 int from_tty;
2576 {
2577 FILE *stream;
2578 struct cleanup *old_cleanups;
2579 char *file = args;
2580 struct source_cleanup_lines_args old_lines;
2581 int needed_length;
2582
2583 if (file == NULL)
2584 {
2585 error ("source command requires pathname of file to source.");
2586 }
2587
2588 file = tilde_expand (file);
2589 old_cleanups = make_cleanup (free, file);
2590
2591 stream = fopen (file, FOPEN_RT);
2592 if (stream == 0)
2593 perror_with_name (file);
2594
2595 make_cleanup (fclose, stream);
2596
2597 old_lines.old_line = source_line_number;
2598 old_lines.old_file = source_file_name;
2599 old_lines.old_pre_error = source_pre_error;
2600 old_lines.old_error_pre_print = error_pre_print;
2601 make_cleanup (source_cleanup_lines, &old_lines);
2602 source_line_number = 0;
2603 source_file_name = file;
2604 source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
2605 source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
2606 make_cleanup (free, source_pre_error);
2607 /* This will get set every time we read a line. So it won't stay "" for
2608 long. */
2609 error_pre_print = "";
2610
2611 needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
2612 if (source_error_allocated < needed_length)
2613 {
2614 source_error_allocated *= 2;
2615 if (source_error_allocated < needed_length)
2616 source_error_allocated = needed_length;
2617 if (source_error == NULL)
2618 source_error = xmalloc (source_error_allocated);
2619 else
2620 source_error = xrealloc (source_error, source_error_allocated);
2621 }
2622
2623 read_command_file (stream);
2624
2625 do_cleanups (old_cleanups);
2626 }
2627
2628 /* ARGSUSED */
2629 static void
2630 echo_command (text, from_tty)
2631 char *text;
2632 int from_tty;
2633 {
2634 char *p = text;
2635 register int c;
2636
2637 if (text)
2638 while ((c = *p++) != '\0')
2639 {
2640 if (c == '\\')
2641 {
2642 /* \ at end of argument is used after spaces
2643 so they won't be lost. */
2644 if (*p == 0)
2645 return;
2646
2647 c = parse_escape (&p);
2648 if (c >= 0)
2649 printf_filtered ("%c", c);
2650 }
2651 else
2652 printf_filtered ("%c", c);
2653 }
2654
2655 /* Force this output to appear now. */
2656 wrap_here ("");
2657 gdb_flush (gdb_stdout);
2658 }
2659
2660 \f
2661 #ifdef TARGET_BYTE_ORDER_SELECTABLE
2662
2663 /* Functions to manipulate the endianness of the target. */
2664
2665 #ifndef TARGET_BYTE_ORDER_DEFAULT
2666 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
2667 #endif
2668
2669 int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
2670
2671 static int target_byte_order_auto = 1;
2672
2673 /* Called if the user enters ``set endian'' without an argument. */
2674 static void
2675 set_endian (args, from_tty)
2676 char *args;
2677 int from_tty;
2678 {
2679 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
2680 show_endian (args, from_tty);
2681 }
2682
2683 /* Called by ``set endian big''. */
2684 static void
2685 set_endian_big (args, from_tty)
2686 char *args;
2687 int from_tty;
2688 {
2689 target_byte_order = BIG_ENDIAN;
2690 target_byte_order_auto = 0;
2691 }
2692
2693 /* Called by ``set endian little''. */
2694 static void
2695 set_endian_little (args, from_tty)
2696 char *args;
2697 int from_tty;
2698 {
2699 target_byte_order = LITTLE_ENDIAN;
2700 target_byte_order_auto = 0;
2701 }
2702
2703 /* Called by ``set endian auto''. */
2704 static void
2705 set_endian_auto (args, from_tty)
2706 char *args;
2707 int from_tty;
2708 {
2709 target_byte_order_auto = 1;
2710 }
2711
2712 /* Called by ``show endian''. */
2713 static void
2714 show_endian (args, from_tty)
2715 char *args;
2716 int from_tty;
2717 {
2718 const char *msg =
2719 (target_byte_order_auto
2720 ? "The target endianness is set automatically (currently %s endian)\n"
2721 : "The target is assumed to be %s endian\n");
2722 printf_unfiltered (msg, TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
2723 }
2724
2725 #endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
2726
2727 /* Set the endianness from a BFD. */
2728 void
2729 set_endian_from_file (abfd)
2730 bfd *abfd;
2731 {
2732 #ifdef TARGET_BYTE_ORDER_SELECTABLE
2733 int want;
2734
2735 if (abfd->xvec->byteorder_big_p)
2736 want = BIG_ENDIAN;
2737 else
2738 want = LITTLE_ENDIAN;
2739 if (target_byte_order_auto)
2740 target_byte_order = want;
2741 else if (target_byte_order != want)
2742 warning ("%s endian file does not match %s endian target.",
2743 want == BIG_ENDIAN ? "big" : "little",
2744 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
2745
2746 #else /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
2747
2748 if (abfd->xvec->byteorder_big_p
2749 ? TARGET_BYTE_ORDER != BIG_ENDIAN
2750 : TARGET_BYTE_ORDER == BIG_ENDIAN)
2751 warning ("%s endian file does not match %s endian target.",
2752 abfd->xvec->byteorder_big_p ? "big" : "little",
2753 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
2754
2755 #endif /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
2756 }
2757 \f
2758 /* Functions to manipulate command line editing control variables. */
2759
2760 /* Number of commands to print in each call to show_commands. */
2761 #define Hist_print 10
2762 static void
2763 show_commands (args, from_tty)
2764 char *args;
2765 int from_tty;
2766 {
2767 /* Index for history commands. Relative to history_base. */
2768 int offset;
2769
2770 /* Number of the history entry which we are planning to display next.
2771 Relative to history_base. */
2772 static int num = 0;
2773
2774 /* The first command in the history which doesn't exist (i.e. one more
2775 than the number of the last command). Relative to history_base. */
2776 int hist_len;
2777
2778 extern HIST_ENTRY *history_get PARAMS ((int));
2779
2780 /* Print out some of the commands from the command history. */
2781 /* First determine the length of the history list. */
2782 hist_len = history_size;
2783 for (offset = 0; offset < history_size; offset++)
2784 {
2785 if (!history_get (history_base + offset))
2786 {
2787 hist_len = offset;
2788 break;
2789 }
2790 }
2791
2792 if (args)
2793 {
2794 if (args[0] == '+' && args[1] == '\0')
2795 /* "info editing +" should print from the stored position. */
2796 ;
2797 else
2798 /* "info editing <exp>" should print around command number <exp>. */
2799 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
2800 }
2801 /* "show commands" means print the last Hist_print commands. */
2802 else
2803 {
2804 num = hist_len - Hist_print;
2805 }
2806
2807 if (num < 0)
2808 num = 0;
2809
2810 /* If there are at least Hist_print commands, we want to display the last
2811 Hist_print rather than, say, the last 6. */
2812 if (hist_len - num < Hist_print)
2813 {
2814 num = hist_len - Hist_print;
2815 if (num < 0)
2816 num = 0;
2817 }
2818
2819 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
2820 {
2821 printf_filtered ("%5d %s\n", history_base + offset,
2822 (history_get (history_base + offset))->line);
2823 }
2824
2825 /* The next command we want to display is the next one that we haven't
2826 displayed yet. */
2827 num += Hist_print;
2828
2829 /* If the user repeats this command with return, it should do what
2830 "show commands +" does. This is unnecessary if arg is null,
2831 because "show commands +" is not useful after "show commands". */
2832 if (from_tty && args)
2833 {
2834 args[0] = '+';
2835 args[1] = '\0';
2836 }
2837 }
2838
2839 /* Called by do_setshow_command. */
2840 /* ARGSUSED */
2841 static void
2842 set_history_size_command (args, from_tty, c)
2843 char *args;
2844 int from_tty;
2845 struct cmd_list_element *c;
2846 {
2847 if (history_size == INT_MAX)
2848 unstifle_history ();
2849 else if (history_size >= 0)
2850 stifle_history (history_size);
2851 else
2852 {
2853 history_size = INT_MAX;
2854 error ("History size must be non-negative");
2855 }
2856 }
2857
2858 /* ARGSUSED */
2859 static void
2860 set_history (args, from_tty)
2861 char *args;
2862 int from_tty;
2863 {
2864 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
2865 help_list (sethistlist, "set history ", -1, gdb_stdout);
2866 }
2867
2868 /* ARGSUSED */
2869 static void
2870 show_history (args, from_tty)
2871 char *args;
2872 int from_tty;
2873 {
2874 cmd_show_list (showhistlist, from_tty, "");
2875 }
2876
2877 int info_verbose = 0; /* Default verbose msgs off */
2878
2879 /* Called by do_setshow_command. An elaborate joke. */
2880 /* ARGSUSED */
2881 static void
2882 set_verbose (args, from_tty, c)
2883 char *args;
2884 int from_tty;
2885 struct cmd_list_element *c;
2886 {
2887 char *cmdname = "verbose";
2888 struct cmd_list_element *showcmd;
2889
2890 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
2891
2892 if (info_verbose)
2893 {
2894 c->doc = "Set verbose printing of informational messages.";
2895 showcmd->doc = "Show verbose printing of informational messages.";
2896 }
2897 else
2898 {
2899 c->doc = "Set verbosity.";
2900 showcmd->doc = "Show verbosity.";
2901 }
2902 }
2903
2904 static void
2905 float_handler (signo)
2906 int signo;
2907 {
2908 /* This message is based on ANSI C, section 4.7. Note that integer
2909 divide by zero causes this, so "float" is a misnomer. */
2910 signal (SIGFPE, float_handler);
2911 error ("Erroneous arithmetic operation.");
2912 }
2913
2914 \f
2915 static void
2916 init_cmd_lists ()
2917 {
2918 cmdlist = NULL;
2919 infolist = NULL;
2920 enablelist = NULL;
2921 disablelist = NULL;
2922 deletelist = NULL;
2923 enablebreaklist = NULL;
2924 setlist = NULL;
2925 unsetlist = NULL;
2926 showlist = NULL;
2927 #ifdef TARGET_BYTE_ORDER_SELECTABLE
2928 endianlist = NULL;
2929 #endif
2930 sethistlist = NULL;
2931 showhistlist = NULL;
2932 unsethistlist = NULL;
2933 #if MAINTENANCE_CMDS
2934 maintenancelist = NULL;
2935 maintenanceinfolist = NULL;
2936 maintenanceprintlist = NULL;
2937 #endif
2938 setprintlist = NULL;
2939 showprintlist = NULL;
2940 setchecklist = NULL;
2941 showchecklist = NULL;
2942 }
2943
2944 /* Init the history buffer. Note that we are called after the init file(s)
2945 * have been read so that the user can change the history file via his
2946 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2947 * overrides all of this.
2948 */
2949
2950 void
2951 init_history()
2952 {
2953 char *tmpenv;
2954
2955 tmpenv = getenv ("HISTSIZE");
2956 if (tmpenv)
2957 history_size = atoi (tmpenv);
2958 else if (!history_size)
2959 history_size = 256;
2960
2961 stifle_history (history_size);
2962
2963 tmpenv = getenv ("GDBHISTFILE");
2964 if (tmpenv)
2965 history_filename = savestring (tmpenv, strlen(tmpenv));
2966 else if (!history_filename) {
2967 /* We include the current directory so that if the user changes
2968 directories the file written will be the same as the one
2969 that was read. */
2970 history_filename = concat (current_directory, "/.gdb_history", NULL);
2971 }
2972 read_history (history_filename);
2973 }
2974
2975 static void
2976 init_main ()
2977 {
2978 struct cmd_list_element *c;
2979
2980 #ifdef TARGET_BYTE_ORDER_SELECTABLE
2981
2982 add_prefix_cmd ("endian", class_support, set_endian,
2983 "Set endianness of target.",
2984 &endianlist, "set endian ", 0, &setlist);
2985 add_cmd ("big", class_support, set_endian_big,
2986 "Set target as being big endian.", &endianlist);
2987 add_cmd ("little", class_support, set_endian_little,
2988 "Set target as being little endian.", &endianlist);
2989 add_cmd ("auto", class_support, set_endian_auto,
2990 "Select target endianness automatically.", &endianlist);
2991 add_cmd ("endian", class_support, show_endian,
2992 "Show endianness of target.", &showlist);
2993
2994 #endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
2995
2996 #ifdef DEFAULT_PROMPT
2997 prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT));
2998 #else
2999 prompt = savestring ("(gdb) ", 6);
3000 #endif
3001
3002 /* Set the important stuff up for command editing. */
3003 command_editing_p = 1;
3004 history_expansion_p = 0;
3005 write_history_p = 0;
3006
3007 /* Setup important stuff for command line editing. */
3008 rl_completion_entry_function = (int (*)()) symbol_completion_function;
3009 rl_completer_word_break_characters = gdb_completer_word_break_characters;
3010 rl_completer_quote_characters = gdb_completer_quote_characters;
3011 rl_readline_name = "gdb";
3012
3013 /* Define the classes of commands.
3014 They will appear in the help list in the reverse of this order. */
3015
3016 add_cmd ("internals", class_maintenance, NO_FUNCTION,
3017 "Maintenance commands.\n\
3018 Some gdb commands are provided just for use by gdb maintainers.\n\
3019 These commands are subject to frequent change, and may not be as\n\
3020 well documented as user commands.",
3021 &cmdlist);
3022 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
3023 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
3024 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
3025 The commands in this class are those defined by the user.\n\
3026 Use the \"define\" command to define a command.", &cmdlist);
3027 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
3028 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
3029 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
3030 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
3031 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
3032 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
3033 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3034 counting from zero for the innermost (currently executing) frame.\n\n\
3035 At any time gdb identifies one frame as the \"selected\" frame.\n\
3036 Variable lookups are done with respect to the selected frame.\n\
3037 When the program being debugged stops, gdb selects the innermost frame.\n\
3038 The commands below can be used to select other frames by number or address.",
3039 &cmdlist);
3040 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
3041
3042 add_com ("pwd", class_files, pwd_command,
3043 "Print working directory. This is used for your program as well.");
3044 c = add_cmd ("cd", class_files, cd_command,
3045 "Set working directory to DIR for debugger and program being debugged.\n\
3046 The change does not take effect for the program being debugged\n\
3047 until the next time it is started.", &cmdlist);
3048 c->completer = filename_completer;
3049
3050 add_show_from_set
3051 (add_set_cmd ("prompt", class_support, var_string, (char *)&prompt,
3052 "Set gdb's prompt",
3053 &setlist),
3054 &showlist);
3055
3056 add_com ("echo", class_support, echo_command,
3057 "Print a constant string. Give string as argument.\n\
3058 C escape sequences may be used in the argument.\n\
3059 No newline is added at the end of the argument;\n\
3060 use \"\\n\" if you want a newline to be printed.\n\
3061 Since leading and trailing whitespace are ignored in command arguments,\n\
3062 if you want to print some you must use \"\\\" before leading whitespace\n\
3063 to be printed or after trailing whitespace.");
3064 add_com ("document", class_support, document_command,
3065 "Document a user-defined command.\n\
3066 Give command name as argument. Give documentation on following lines.\n\
3067 End with a line of just \"end\".");
3068 add_com ("define", class_support, define_command,
3069 "Define a new command name. Command name is argument.\n\
3070 Definition appears on following lines, one command per line.\n\
3071 End with a line of just \"end\".\n\
3072 Use the \"document\" command to give documentation for the new command.\n\
3073 Commands defined in this way do not take arguments.");
3074
3075 #ifdef __STDC__
3076 c = add_cmd ("source", class_support, source_command,
3077 "Read commands from a file named FILE.\n\
3078 Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
3079 when gdb is started.", &cmdlist);
3080 #else
3081 /* Punt file name, we can't help it easily. */
3082 c = add_cmd ("source", class_support, source_command,
3083 "Read commands from a file named FILE.\n\
3084 Note that the file \".gdbinit\" is read automatically in this way\n\
3085 when gdb is started.", &cmdlist);
3086 #endif
3087 c->completer = filename_completer;
3088
3089 add_com ("quit", class_support, quit_command, "Exit gdb.");
3090 add_com ("help", class_support, help_command, "Print list of commands.");
3091 add_com_alias ("q", "quit", class_support, 1);
3092 add_com_alias ("h", "help", class_support, 1);
3093
3094
3095 c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose,
3096 "Set ",
3097 &setlist),
3098 add_show_from_set (c, &showlist);
3099 c->function.sfunc = set_verbose;
3100 set_verbose (NULL, 0, c);
3101
3102 add_show_from_set
3103 (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p,
3104 "Set editing of command lines as they are typed.\n\
3105 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
3106 Without an argument, command line editing is enabled. To edit, use\n\
3107 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
3108 &showlist);
3109
3110 add_prefix_cmd ("history", class_support, set_history,
3111 "Generic command for setting command history parameters.",
3112 &sethistlist, "set history ", 0, &setlist);
3113 add_prefix_cmd ("history", class_support, show_history,
3114 "Generic command for showing command history parameters.",
3115 &showhistlist, "show history ", 0, &showlist);
3116
3117 add_show_from_set
3118 (add_set_cmd ("expansion", no_class, var_boolean, (char *)&history_expansion_p,
3119 "Set history expansion on command input.\n\
3120 Without an argument, history expansion is enabled.", &sethistlist),
3121 &showhistlist);
3122
3123 add_show_from_set
3124 (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p,
3125 "Set saving of the history record on exit.\n\
3126 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
3127 Without an argument, saving is enabled.", &sethistlist),
3128 &showhistlist);
3129
3130 c = add_set_cmd ("size", no_class, var_integer, (char *)&history_size,
3131 "Set the size of the command history, \n\
3132 ie. the number of previous commands to keep a record of.", &sethistlist);
3133 add_show_from_set (c, &showhistlist);
3134 c->function.sfunc = set_history_size_command;
3135
3136 add_show_from_set
3137 (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename,
3138 "Set the filename in which to record the command history\n\
3139 (the list of previous commands of which a record is kept).", &sethistlist),
3140 &showhistlist);
3141
3142 add_show_from_set
3143 (add_set_cmd ("confirm", class_support, var_boolean,
3144 (char *)&caution,
3145 "Set whether to confirm potentially dangerous operations.",
3146 &setlist),
3147 &showlist);
3148
3149 add_prefix_cmd ("info", class_info, info_command,
3150 "Generic command for showing things about the program being debugged.",
3151 &infolist, "info ", 0, &cmdlist);
3152 add_com_alias ("i", "info", class_info, 1);
3153
3154 add_com ("complete", class_obscure, complete_command,
3155 "List the completions for the rest of the line as a command.");
3156
3157 add_prefix_cmd ("show", class_info, show_command,
3158 "Generic command for showing things about the debugger.",
3159 &showlist, "show ", 0, &cmdlist);
3160 /* Another way to get at the same thing. */
3161 add_info ("set", show_command, "Show all GDB settings.");
3162
3163 add_cmd ("commands", no_class, show_commands,
3164 "Show the the history of commands you typed.\n\
3165 You can supply a command number to start with, or a `+' to start after\n\
3166 the previous command number shown.",
3167 &showlist);
3168
3169 add_cmd ("version", no_class, show_version,
3170 "Show what version of GDB this is.", &showlist);
3171
3172 add_com ("while", class_support, while_command,
3173 "Execute nested commands WHILE the conditional expression is non zero.\n\
3174 The conditional expression must follow the word `while' and must in turn be\
3175 followed by a new line. The nested commands must be entered one per line,\
3176 and should be terminated by the word `end'.");
3177
3178 add_com ("if", class_support, if_command,
3179 "Execute nested commands once IF the conditional expression is non zero.\n\
3180 The conditional expression must follow the word `if' and must in turn be\
3181 followed by a new line. The nested commands must be entered one per line,\
3182 and should be terminated by the word 'else' or `end'. If an else clause\
3183 is used, the same rules apply to its nested commands as to the first ones.");
3184
3185 /* If target is open when baud changes, it doesn't take effect until the
3186 next open (I think, not sure). */
3187 add_show_from_set (add_set_cmd ("remotebaud", no_class,
3188 var_zinteger, (char *)&baud_rate,
3189 "Set baud rate for remote serial I/O.\n\
3190 This value is used to set the speed of the serial port when debugging\n\
3191 using remote targets.", &setlist),
3192 &showlist);
3193
3194 add_show_from_set (
3195 add_set_cmd ("remotedebug", no_class, var_zinteger, (char *)&remote_debug,
3196 "Set debugging of remote protocol.\n\
3197 When enabled, each packet sent or received with the remote target\n\
3198 is displayed.", &setlist),
3199 &showlist);
3200 }
This page took 0.152545 seconds and 5 git commands to generate.