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