gdb-2.5.1
[deliverable/binutils-gdb.git] / gdb / main.c
1 /* Top level for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
3
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
9
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
16
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
19 */
20
21 #include <sys/file.h>
22 #include <stdio.h>
23 #include <setjmp.h>
24 #include <signal.h>
25 #include <sys/param.h>
26 #include "defs.h"
27 #include "command.h"
28 #include "param.h"
29
30 #ifdef SET_STACK_LIMIT_HUGE
31 #include <sys/time.h>
32 #include <sys/resource.h>
33 #endif
34
35 /* Version number of GDB, as a string. */
36
37 extern char *version;
38
39 /* Chain containing all defined commands. */
40
41 struct cmd_list_element *cmdlist;
42
43 /* Chain containing all defined info subcommands. */
44
45 struct cmd_list_element *infolist;
46
47 /* stdio stream that command input is being read from. */
48
49 FILE *instream;
50
51 /* Current working directory. */
52
53 char *current_directory;
54
55 /* The directory name is actually stored here. */
56 static char dirbuf[MAXPATHLEN];
57
58 /* Nonzero if we should refrain from using an X window. */
59
60 int inhibit_windows = 0;
61
62 /* Function to call before reading a command, if nonzero.
63 The function receives two args: an input stream,
64 and a prompt string. */
65
66 void (*window_hook) ();
67
68 extern int frame_file_full_name;
69
70 void free_command_lines ();
71 char *read_line ();
72 static void initialize_main ();
73 void command_loop ();
74 static void source_command ();
75 void print_gdb_version ();
76
77 /* gdb prints this when reading a command interactively */
78 static char *prompt;
79
80 /* Buffer used for reading command lines, and the size
81 allocated for it so far. */
82
83 char *line;
84 int linesize;
85
86 /* This is how `error' returns to command level. */
87
88 jmp_buf to_top_level;
89
90 return_to_top_level ()
91 {
92 quit_flag = 0;
93 immediate_quit = 0;
94 clear_breakpoint_commands ();
95 clear_momentary_breakpoints ();
96 do_cleanups (0);
97 longjmp (to_top_level, 1);
98 }
99 \f
100 main (argc, argv, envp)
101 int argc;
102 char **argv;
103 char **envp;
104 {
105 extern void request_quit ();
106 int count;
107 int inhibit_gdbinit = 0;
108 int quiet = 0;
109 int batch = 0;
110 register int i;
111
112 quit_flag = 0;
113 linesize = 100;
114 line = (char *) xmalloc (linesize);
115 instream = stdin;
116
117 getwd (dirbuf);
118 current_directory = dirbuf;
119
120 #ifdef SET_STACK_LIMIT_HUGE
121 {
122 struct rlimit rlim;
123
124 /* Set the stack limit huge so that alloca (particularly stringtab
125 * in dbxread.c) does not fail. */
126 getrlimit (RLIMIT_STACK, &rlim);
127 rlim.rlim_cur = rlim.rlim_max;
128 setrlimit (RLIMIT_STACK, &rlim);
129 }
130 #endif /* SET_STACK_LIMIT_HUGE */
131
132 /* Run the init function of each source file */
133
134 /* Look for flag arguments. */
135
136 for (i = 1; i < argc; i++)
137 {
138 if (!strcmp (argv[i], "-q") || !strcmp (argv[i], "-quiet"))
139 quiet = 1;
140 else if (!strcmp (argv[i], "-nx"))
141 inhibit_gdbinit = 1;
142 else if (!strcmp (argv[i], "-nw"))
143 inhibit_windows = 1;
144 else if (!strcmp (argv[i], "-fullname"))
145 frame_file_full_name = 1;
146 else if (!strcmp (argv[i], "-batch"))
147 batch = 1, quiet = 1;
148 else if (argv[i][0] == '-')
149 i++;
150 }
151
152 /* Run the init function of each source file */
153
154 initialize_all_files ();
155 initialize_main (); /* But that omits this file! Do it now */
156
157 signal (SIGINT, request_quit);
158 signal (SIGQUIT, SIG_IGN);
159
160 if (!quiet)
161 print_gdb_version ();
162
163 /* Process the command line arguments. */
164
165 count = 0;
166 for (i = 1; i < argc; i++)
167 {
168 register char *arg = argv[i];
169 /* Args starting with - say what to do with the following arg
170 as a filename. */
171 if (arg[0] == '-')
172 {
173 extern void exec_file_command (), symbol_file_command ();
174 extern void core_file_command (), directory_command ();
175 extern void tty_command ();
176
177 if (!strcmp (arg, "-q") || !strcmp (arg, "-nx")
178 || !strcmp (arg, "-quiet") || !strcmp (arg, "-batch")
179 || !strcmp (arg, "-fullname"))
180 /* Already processed above */
181 continue;
182
183 if (++i == argc)
184 fprintf (stderr, "No argument follows \"%s\".\n", arg);
185 if (!setjmp (to_top_level))
186 {
187 /* -s foo: get syms from foo. -e foo: execute foo.
188 -se foo: do both with foo. -c foo: use foo as core dump. */
189 if (!strcmp (arg, "-se"))
190 {
191 exec_file_command (argv[i], !batch);
192 symbol_file_command (argv[i], !batch);
193 }
194 else if (!strcmp (arg, "-s") || !strcmp (arg, "-symbols"))
195 symbol_file_command (argv[i], !batch);
196 else if (!strcmp (arg, "-e") || !strcmp (arg, "-exec"))
197 exec_file_command (argv[i], !batch);
198 else if (!strcmp (arg, "-c") || !strcmp (arg, "-core"))
199 core_file_command (argv[i], !batch);
200 /* -x foo: execute commands from foo. */
201 else if (!strcmp (arg, "-x") || !strcmp (arg, "-command")
202 || !strcmp (arg, "-commands"))
203 source_command (argv[i]);
204 /* -d foo: add directory `foo' to source-file directory
205 search-list */
206 else if (!strcmp (arg, "-d") || !strcmp (arg, "-dir")
207 || !strcmp (arg, "-directory"))
208 directory_command (argv[i], 0);
209 /* -t /def/ttyp1: use /dev/ttyp1 for inferior I/O. */
210 else if (!strcmp (arg, "-t") || !strcmp (arg, "-tty"))
211 tty_command (argv[i], 0);
212 else
213 error ("Unknown command-line switch: \"%s\"\n", arg);
214 }
215 }
216 else
217 {
218 /* Args not thus accounted for
219 are treated as, first, the symbol/executable file
220 and, second, the core dump file. */
221 count++;
222 if (!setjmp (to_top_level))
223 switch (count)
224 {
225 case 1:
226 exec_file_command (arg, !batch);
227 symbol_file_command (arg, !batch);
228 break;
229
230 case 2:
231 core_file_command (arg, !batch);
232 break;
233
234 case 3:
235 fprintf (stderr, "Excess command line args ignored. (%s%s)\n",
236 arg, (i == argc - 1) ? "" : " ...");
237 }
238 }
239 }
240
241 /* Read init file, if it exists in home directory */
242 if (getenv ("HOME"))
243 {
244 char *s;
245 s = (char *) xmalloc (strlen (getenv ("HOME")) + 10);
246 strcpy (s, getenv ("HOME"));
247 strcat (s, "/.gdbinit");
248 if (!inhibit_gdbinit && access (s, R_OK) == 0)
249 if (!setjmp (to_top_level))
250 source_command (s);
251 }
252
253 /* Read init file, if it exists in current directory. */
254 if (!inhibit_gdbinit && access (".gdbinit", R_OK) == 0)
255 if (!setjmp (to_top_level))
256 source_command (".gdbinit");
257
258 if (batch)
259 fatal ("Attempt to read commands from stdin in batch mode.");
260
261 if (!quiet)
262 printf ("Type \"help\" for a list of commands.\n");
263
264 /* The command loop. */
265
266 while (1)
267 {
268 if (!setjmp (to_top_level))
269 command_loop ();
270 clearerr (stdin); /* Don't get hung if C-d is typed. */
271 }
272 }
273
274 /* Execute the line P as a command.
275 Pass FROM_TTY as second argument to the defining function. */
276
277 void
278 execute_command (p, from_tty)
279 char *p;
280 int from_tty;
281 {
282 register struct cmd_list_element *c;
283 register struct command_line *cmdlines;
284
285 free_all_values ();
286 while (*p == ' ' || *p == '\t') p++;
287 if (*p)
288 {
289 c = lookup_cmd (&p, cmdlist, "", 0);
290 if (c->function == 0)
291 error ("That is not a command, just a help topic.");
292 else if (c->class == (int) class_user)
293 {
294 if (*p)
295 error ("User-defined commands cannot take command-line arguments: \"%s\"",
296 p);
297 cmdlines = (struct command_line *) c->function;
298 if (cmdlines == (struct command_line *) 0)
299 /* Null command */
300 return;
301 while (cmdlines)
302 {
303 execute_command (cmdlines->line, 0);
304 cmdlines = cmdlines->next;
305 }
306 }
307 else
308 /* Pass null arg rather than an empty one. */
309 (*c->function) (*p ? p : 0, from_tty);
310 }
311 }
312
313 static void
314 do_nothing ()
315 {
316 }
317
318 /* Read commands from `instream' and execute them
319 until end of file. */
320 void
321 command_loop ()
322 {
323 struct cleanup *old_chain;
324 while (!feof (instream))
325 {
326 if (instream == stdin)
327 printf ("%s", prompt);
328 fflush (stdout);
329
330 if (window_hook && instream == stdin)
331 (*window_hook) (instream, prompt);
332
333 quit_flag = 0;
334 old_chain = make_cleanup (do_nothing, 0);
335 execute_command (read_line (instream == stdin), instream == stdin);
336 /* Do any commands attached to breakpoint we stopped at. */
337 do_breakpoint_commands ();
338 do_cleanups (old_chain);
339 }
340 }
341 \f
342 static void
343 stop_sig ()
344 {
345 signal (SIGTSTP, SIG_DFL);
346 sigsetmask (0);
347 kill (getpid (), SIGTSTP);
348 signal (SIGTSTP, stop_sig);
349 printf ("%s", prompt);
350 fflush (stdout);
351
352 /* Forget about any previous command -- null line now will do nothing. */
353 *line = 0;
354 }
355
356 /* Commands call this if they do not want to be repeated by null lines. */
357
358 void
359 dont_repeat ()
360 {
361 *line = 0;
362 }
363
364 /* Read one line from the command input stream `instream'
365 into the buffer `line' (whose current length is `linesize').
366 The buffer is made bigger as necessary.
367 Returns the address of the start of the line. */
368
369 char *
370 read_line (repeat)
371 int repeat;
372 {
373 register char *p = line;
374 register char *p1;
375 register int c;
376 char *nline;
377
378 /* Control-C quits instantly if typed while in this loop
379 since it should not wait until the user types a newline. */
380 immediate_quit++;
381 signal (SIGTSTP, stop_sig);
382
383 while (1)
384 {
385 c = fgetc (instream);
386 if (c == -1 || c == '\n')
387 break;
388 else if (c == '\\')
389 if ((c = fgetc (instream)) == '\n')
390 continue;
391 else ungetc (c, instream);
392 if (p - line == linesize - 1)
393 {
394 linesize *= 2;
395 nline = (char *) xrealloc (line, linesize);
396 p += nline - line;
397 line = nline;
398 }
399 *p++ = c;
400 }
401 signal (SIGTSTP, SIG_DFL);
402 immediate_quit--;
403
404 /* If we just got an empty line, and that is supposed
405 to repeat the previous command, leave the last input unchanged. */
406 if (p == line && repeat)
407 return line;
408
409 /* If line is a comment, clear it out. */
410 p1 = line;
411 while ((c = *p1) == ' ' || c == '\t') p1++;
412 if (c == '#')
413 p = line;
414
415 *p = 0;
416
417 return line;
418 }
419 \f
420 /* Read lines from the input stream
421 and accumulate them in a chain of struct command_line's
422 which is then returned. */
423
424 struct command_line *
425 read_command_lines ()
426 {
427 struct command_line *first = 0;
428 register struct command_line *next, *tail = 0;
429 register char *p, *p1;
430 struct cleanup *old_chain = 0;
431
432 while (1)
433 {
434 dont_repeat ();
435 p = read_line (1);
436 /* Remove leading and trailing blanks. */
437 while (*p == ' ' || *p == '\t') p++;
438 p1 = p + strlen (p);
439 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--;
440
441 /* Is this "end"? */
442 if (p1 - p == 3 && !strncmp (p, "end", 3))
443 break;
444
445 /* No => add this line to the chain of command lines. */
446 next = (struct command_line *) xmalloc (sizeof (struct command_line));
447 next->line = savestring (p, p1 - p);
448 next->next = 0;
449 if (tail)
450 {
451 tail->next = next;
452 }
453 else
454 {
455 /* We just read the first line.
456 From now on, arrange to throw away the lines we have
457 if we quit or get an error while inside this function. */
458 first = next;
459 old_chain = make_cleanup (free_command_lines, &first);
460 }
461 tail = next;
462 }
463
464 dont_repeat ();
465
466 /* Now we are about to return the chain to our caller,
467 so freeing it becomes his responsibility. */
468 if (first)
469 discard_cleanups (old_chain);
470 return first;
471 }
472
473 /* Free a chain of struct command_line's. */
474
475 void
476 free_command_lines (lptr)
477 struct command_line **lptr;
478 {
479 register struct command_line *l = *lptr;
480 register struct command_line *next;
481
482 while (l)
483 {
484 next = l->next;
485 free (l->line);
486 free (l);
487 l = next;
488 }
489 }
490 \f
491 /* Add an element to the list of info subcommands. */
492
493 void
494 add_info (name, fun, doc)
495 char *name;
496 void (*fun) ();
497 char *doc;
498 {
499 add_cmd (name, 0, fun, doc, &infolist);
500 }
501
502 /* Add an alias to the list of info subcommands. */
503
504 void
505 add_info_alias (name, oldname, abbrev_flag)
506 char *name;
507 char *oldname;
508 int abbrev_flag;
509 {
510 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
511 }
512
513 /* The "info" command is defined as a prefix, with allow_unknown = 0.
514 Therefore, its own definition is called only for "info" with no args. */
515
516 static void
517 info_command ()
518 {
519 printf ("\"info\" must be followed by the name of an info command.\n");
520 help_cmd (0, infolist, "info ", -1, stdout);
521 }
522 \f
523 /* Add an element to the list of commands. */
524
525 void
526 add_com (name, class, fun, doc)
527 char *name;
528 int class;
529 void (*fun) ();
530 char *doc;
531 {
532 add_cmd (name, class, fun, doc, &cmdlist);
533 }
534
535 /* Add an alias or abbreviation command to the list of commands. */
536
537 void
538 add_com_alias (name, oldname, class, abbrev_flag)
539 char *name;
540 char *oldname;
541 int class;
542 int abbrev_flag;
543 {
544 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
545 }
546
547 void
548 error_no_arg (why)
549 char *why;
550 {
551 error ("Argument required (%s).", why);
552 }
553
554 static void
555 help_command (command, from_tty)
556 char *command;
557 int from_tty; /* Ignored */
558 {
559 help_cmd (command, cmdlist, "", -2, stdout);
560 }
561 \f
562 static void
563 validate_comname (comname)
564 char *comname;
565 {
566 register char *p;
567
568 if (comname == 0)
569 error_no_arg ("name of command to define");
570
571 p = comname;
572 while (*p)
573 {
574 if (!(*p >= 'A' && *p <= 'Z')
575 && !(*p >= 'a' && *p <= 'z')
576 && !(*p >= '1' && *p <= '9')
577 && *p != '-')
578 error ("Junk in argument list: \"%s\"", p);
579 p++;
580 }
581 }
582
583 static void
584 define_command (comname, from_tty)
585 char *comname;
586 int from_tty;
587 {
588 register struct command_line *cmds;
589 register struct cmd_list_element *c;
590 char *tem = comname;
591
592 validate_comname (comname);
593
594 c = lookup_cmd (&tem, cmdlist, "", -1);
595 if (c)
596 {
597 if (c->class == (int) class_user || c->class == (int) class_alias)
598 tem = "Redefine command \"%s\"? ";
599 else
600 tem = "Really redefine built-in command \"%s\"? ";
601 if (!query (tem, comname))
602 error ("Command \"%s\" not redefined.", comname);
603 }
604
605 if (from_tty)
606 printf ("Type commands for definition of \"%s\".\n\
607 End with a line saying just \"end\".\n", comname);
608
609 comname = savestring (comname, strlen (comname));
610
611 cmds = read_command_lines ();
612
613 if (c && c->class == (int) class_user)
614 free_command_lines (&c->function);
615
616 add_com (comname, class_user, cmds,
617 (c && c->class == (int) class_user)
618 ? c->doc : savestring ("User-defined.", 13));
619 }
620
621 static void
622 document_command (comname, from_tty)
623 char *comname;
624 int from_tty;
625 {
626 struct command_line *doclines;
627 register struct cmd_list_element *c;
628 char *tem = comname;
629
630 validate_comname (comname);
631
632 c = lookup_cmd (&tem, cmdlist, "", 0);
633
634 if (c->class != (int) class_user)
635 error ("Command \"%s\" is built-in.", comname);
636
637 if (from_tty)
638 printf ("Type documentation for \"%s\".\n\
639 End with a line saying just \"end\".\n", comname);
640
641 doclines = read_command_lines ();
642
643 if (c->doc) free (c->doc);
644
645 {
646 register struct command_line *cl1;
647 register int len = 0;
648
649 for (cl1 = doclines; cl1; cl1 = cl1->next)
650 len += strlen (cl1->line) + 1;
651
652 c->doc = (char *) xmalloc (len + 1);
653 *c->doc = 0;
654
655 for (cl1 = doclines; cl1; cl1 = cl1->next)
656 {
657 strcat (c->doc, cl1->line);
658 if (cl1->next)
659 strcat (c->doc, "\n");
660 }
661 }
662
663 free_command_lines (&doclines);
664 }
665 \f
666 static void
667 copying_info ()
668 {
669 immediate_quit++;
670 printf (" GDB GENERAL PUBLIC LICENSE\n\
671 \n (Clarified 11 Feb 1988)\
672 \n\
673 Copyright (C) 1988 Richard M. Stallman\n\
674 Everyone is permitted to copy and distribute verbatim copies\n\
675 of this license, but changing it is not allowed.\n\
676 You can also use this wording to make the terms for other programs.\n\
677 \n\
678 The license agreements of most software companies keep you at the\n\
679 mercy of those companies. By contrast, our general public license is\n\
680 intended to give everyone the right to share GDB. To make sure that\n\
681 you get the rights we want you to have, we need to make restrictions\n\
682 that forbid anyone to deny you these rights or to ask you to surrender\n\
683 the rights. Hence this license agreement.\n\
684 \n\
685 Specifically, we want to make sure that you have the right to give\n\
686 away copies of GDB, that you receive source code or else can get it\n\
687 if you want it, that you can change GDB or use pieces of it in new\n\
688 free programs, and that you know you can do these things.\n\
689 --Type Return to print more--");
690 fflush (stdout);
691 read_line ();
692
693 printf ("\
694 To make sure that everyone has such rights, we have to forbid you to\n\
695 deprive anyone else of these rights. For example, if you distribute\n\
696 copies of GDB, you must give the recipients all the rights that you\n\
697 have. You must make sure that they, too, receive or can get the\n\
698 source code. And you must tell them their rights.\n\
699 \n\
700 Also, for our own protection, we must make certain that everyone\n\
701 finds out that there is no warranty for GDB. If GDB is modified by\n\
702 someone else and passed on, we want its recipients to know that what\n\
703 they have is not what we distributed, so that any problems introduced\n\
704 by others will not reflect on our reputation.\n\
705 \n\
706 Therefore we (Richard Stallman and the Free Software Foundation,\n\
707 Inc.) make the following terms which say what you must do to be\n\
708 allowed to distribute or change GDB.\n\
709 --Type Return to print more--");
710 fflush (stdout);
711 read_line ();
712
713 printf ("\
714 COPYING POLICIES\n\
715 \n\
716 1. You may copy and distribute verbatim copies of GDB source code as\n\
717 you receive it, in any medium, provided that you conspicuously and\n\
718 appropriately publish on each copy a valid copyright notice \"Copyright\n\
719 \(C) 1988 Free Software Foundation, Inc.\" (or with whatever year is\n\
720 appropriate); keep intact the notices on all files that refer\n\
721 to this License Agreement and to the absence of any warranty; and give\n\
722 any other recipients of the GDB program a copy of this License\n\
723 Agreement along with the program. You may charge a distribution fee\n\
724 for the physical act of transferring a copy.\n\
725 \n\
726 2. You may modify your copy or copies of GDB or any portion of it,\n\
727 and copy and distribute such modifications under the terms of\n\
728 Paragraph 1 above, provided that you also do the following:\n\
729 \n\
730 a) cause the modified files to carry prominent notices stating\n\
731 that you changed the files and the date of any change; and\n\
732 --Type Return to print more--");
733 fflush (stdout);
734 read_line ();
735
736 printf ("\
737 b) cause the whole of any work that you distribute or publish,\n\
738 that in whole or in part contains or is a derivative of GDB\n\
739 or any part thereof, to be licensed to all third parties on terms\n\
740 identical to those contained in this License Agreement (except that\n\
741 you may choose to grant more extensive warranty protection to some\n\
742 or all third parties, at your option).\n\
743 \n");
744 printf ("\
745 c) if the modified program serves as a debugger, cause it\n\
746 when started running in the simplest and usual way, to print\n\
747 an announcement including a valid copyright notice\n\
748 \"Copyright (C) 1988 Free Software Foundation, Inc.\" (or with\n\
749 the year that is appropriate), saying that there is no warranty\n\
750 (or else, saying that you provide a warranty) and that users may\n\
751 redistribute the program under these conditions, and telling the user\n\
752 how to view a copy of this License Agreement.\n\
753 \n\
754 d) You may charge a distribution fee for the physical act of\n\
755 transferring a copy, and you may at your option offer warranty\n\
756 protection in exchange for a fee.\n\
757 \n\
758 Mere aggregation of another unrelated program with this program (or its\n\
759 derivative) on a volume of a storage or distribution medium does not bring\n\
760 the other program under the scope of these terms.\n\
761 --Type Return to print more--");
762 fflush (stdout);
763 read_line ();
764
765 printf ("\
766 3. You may copy and distribute GDB (or a portion or derivative of it,\n\
767 under Paragraph 2) in object code or executable form under the terms of\n\
768 Paragraphs 1 and 2 above provided that you also do one of the following:\n\
769 \n\
770 a) accompany it with the complete corresponding machine-readable\n\
771 source code, which must be distributed under the terms of\n\
772 Paragraphs 1 and 2 above; or,\n\
773 \n\
774 b) accompany it with a written offer, valid for at least three\n\
775 years, to give any third party free (except for a nominal\n\
776 shipping charge) a complete machine-readable copy of the\n\
777 corresponding source code, to be distributed under the terms of\n\
778 Paragraphs 1 and 2 above; or,\n\n");
779
780 printf ("\
781 c) accompany it with the information you received as to where the\n\
782 corresponding source code may be obtained. (This alternative is\n\
783 allowed only for noncommercial distribution and only if you\n\
784 received the program in object code or executable form alone.)\n\
785 \n\
786 For an executable file, complete source code means all the source code for\n\
787 all modules it contains; but, as a special exception, it need not include\n\
788 source code for modules which are standard libraries that accompany the\n\
789 operating system on which the executable file runs.\n\
790 --Type Return to print more--");
791 fflush (stdout);
792 read_line ();
793
794 printf ("\
795 4. You may not copy, sublicense, distribute or transfer GDB\n\
796 except as expressly provided under this License Agreement. Any attempt\n\
797 otherwise to copy, sublicense, distribute or transfer GDB is void and\n\
798 your rights to use the program under this License agreement shall be\n\
799 automatically terminated. However, parties who have received computer\n\
800 software programs from you with this License Agreement will not have\n\
801 their licenses terminated so long as such parties remain in full compliance.\n\
802 \n\
803 5. If you wish to incorporate parts of GDB into other free\n\
804 programs whose distribution conditions are different, write to the Free\n\
805 Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet\n\
806 worked out a simple rule that can be stated here, but we will often permit\n\
807 this. We will be guided by the two goals of preserving the free status of\n\
808 all derivatives of our free software and of promoting the sharing and reuse\n\
809 of software.\n\
810 \n\
811 In other words, go ahead and share GDB, but don't try to stop\n\
812 anyone else from sharing it farther. Help stamp out software hoarding!\n\
813 ");
814 immediate_quit--;
815 }
816
817 static void
818 warranty_info ()
819 {
820 immediate_quit++;
821 printf (" NO WARRANTY\n\
822 \n\
823 BECAUSE GDB IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO\n\
824 WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT\n\
825 WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,\n\
826 RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE GDB \"AS IS\" WITHOUT\n\
827 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT\n\
828 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n\
829 A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND\n\
830 PERFORMANCE OF GDB IS WITH YOU. SHOULD GDB PROVE DEFECTIVE, YOU\n\
831 ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n");
832
833 printf ("\
834 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.\n\
835 STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY\n\
836 WHO MAY MODIFY AND REDISTRIBUTE GDB, BE LIABLE TO\n\
837 YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER\n\
838 SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR\n\
839 INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA\n\
840 BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A\n\
841 FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GDB, EVEN\n\
842 IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR\n\
843 ANY CLAIM BY ANY OTHER PARTY.\n");
844 immediate_quit--;
845 }
846 \f
847 static void
848 print_gdb_version ()
849 {
850 printf ("GDB %s, Copyright (C) 1988 Free Software Foundation, Inc.\n\
851 There is ABSOLUTELY NO WARRANTY for GDB; type \"info warranty\" for details.\n\
852 GDB is free software and you are welcome to distribute copies of it\n\
853 under certain conditions; type \"info copying\" to see the conditions.\n",
854 version);
855 }
856
857 static void
858 version_info ()
859 {
860 immediate_quit++;
861 print_gdb_version ();
862 immediate_quit--;
863 }
864 \f
865 static void
866 set_prompt_command (text)
867 char *text;
868 {
869 char *p, *q;
870 register int c;
871 char *new;
872
873 if (text == 0)
874 error_no_arg ("string to which to set prompt");
875
876 new = (char *) xmalloc (strlen (text) + 2);
877 p = text; q = new;
878 while (c = *p++)
879 {
880 if (c == '\\')
881 {
882 /* \ at end of argument is used after spaces
883 so they won't be lost. */
884 if (*p == 0)
885 break;
886 c = parse_escape (&p);
887 if (c == 0)
888 break; /* C loses */
889 else if (c > 0)
890 *q++ = c;
891 }
892 else
893 *q++ = c;
894 }
895 if (*(p - 1) != '\\')
896 *q++ = ' ';
897 *q++ = '\0';
898 new = (char *) xrealloc (new, q - new);
899 free (prompt);
900 prompt = new;
901 }
902 \f
903 static void
904 quit_command ()
905 {
906 if (have_inferior_p ())
907 {
908 if (query ("The program is running. Quit anyway? "))
909 {
910 /* Prevent any warning message from reopen_exec_file, in case
911 we have a core file that's inconsistent with the exec file. */
912 exec_file_command (0, 0);
913 kill_inferior ();
914 }
915 else
916 error ("Not confirmed.");
917 }
918 exit (0);
919 }
920
921 int
922 input_from_terminal_p ()
923 {
924 return instream == stdin;
925 }
926 \f
927 static void
928 pwd_command (arg, from_tty)
929 char *arg;
930 int from_tty;
931 {
932 if (arg) error ("The \"pwd\" command does not take an argument: %s", arg);
933 printf ("Working directory %s.\n", dirbuf);
934 }
935
936 static void
937 cd_command (dir, from_tty)
938 char *dir;
939 int from_tty;
940 {
941 if (dir == 0)
942 error_no_arg ("new working directory");
943
944 if (chdir (dir) < 0)
945 perror_with_name (dir);
946 getwd (dirbuf);
947 if (from_tty)
948 pwd_command ((char *) 0, 1);
949 }
950
951 \f
952 /* Clean up on error during a "source" command.
953 Close the file opened by the command
954 and restore the previous input stream. */
955
956 static void
957 source_cleanup (stream)
958 FILE *stream;
959 {
960 fclose (instream);
961 instream = stream;
962 }
963
964 static void
965 source_command (file)
966 char *file;
967 {
968 FILE *stream;
969 struct cleanup *cleanups;
970
971 if (file == 0)
972 error_no_arg ("file to read commands from");
973
974 stream = fopen (file, "r");
975 if (stream == 0)
976 perror_with_name (file);
977
978 cleanups = make_cleanup (source_cleanup, instream);
979
980 instream = stream;
981
982 command_loop ();
983
984 do_cleanups (cleanups);
985 }
986
987 static void
988 echo_command (text)
989 char *text;
990 {
991 char *p = text;
992 register int c;
993
994 if (text)
995 while (c = *p++)
996 {
997 if (c == '\\')
998 {
999 /* \ at end of argument is used after spaces
1000 so they won't be lost. */
1001 if (*p == 0)
1002 return;
1003
1004 c = parse_escape (&p);
1005 if (c >= 0)
1006 fputc (c, stdout);
1007 }
1008 else
1009 fputc (c, stdout);
1010 }
1011 }
1012
1013 static void
1014 dump_me_command ()
1015 {
1016 if (query ("Should GDB dump core? "))
1017 {
1018 signal (SIGQUIT, SIG_DFL);
1019 kill (getpid (), SIGQUIT);
1020 }
1021 }
1022
1023 \f
1024 static void
1025 initialize_main ()
1026 {
1027 prompt = savestring ("(gdb+) ", 7);
1028
1029 /* Define the classes of commands.
1030 They will appear in the help list in the reverse of this order. */
1031
1032 add_cmd ("obscure", class_obscure, 0, "Obscure features.", &cmdlist);
1033 add_cmd ("alias", class_alias, 0, "Aliases of other commands.", &cmdlist);
1034 add_cmd ("user", class_user, 0, "User-defined commands.\n\
1035 The commands in this class are those defined by the user.\n\
1036 Use the \"define\" command to define a command.", &cmdlist);
1037 add_cmd ("support", class_support, 0, "Support facilities.", &cmdlist);
1038 add_cmd ("status", class_info, 0, "Status inquiries.", &cmdlist);
1039 add_cmd ("files", class_files, 0, "Specifying and examining files.", &cmdlist);
1040 add_cmd ("breakpoints", class_breakpoint, 0, "Making program stop at certain points.", &cmdlist);
1041 add_cmd ("data", class_vars, 0, "Examining data.", &cmdlist);
1042 add_cmd ("stack", class_stack, 0, "Examining the stack.\n\
1043 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
1044 counting from zero for the innermost (currently executing) frame.\n\n\
1045 At any time gdb identifies one frame as the \"selected\" frame.\n\
1046 Variable lookups are done with respect to the selected frame.\n\
1047 When the program being debugged stops, gdb selects the innermost frame.\n\
1048 The commands below can be used to select other frames by number or address.",
1049 &cmdlist);
1050 add_cmd ("running", class_run, 0, "Running the program.", &cmdlist);
1051
1052 add_com ("pwd", class_files, pwd_command,
1053 "Print working directory. This is used for your program as well.");
1054 add_com ("cd", class_files, cd_command,
1055 "Set working directory to DIR for debugger and program being debugged.\n\
1056 The change does not take effect for the program being debugged\n\
1057 until the next time it is started.");
1058
1059 add_com ("set-prompt", class_support, set_prompt_command,
1060 "Change gdb's prompt from the default of \"(gdb)\"");
1061 add_com ("echo", class_support, echo_command,
1062 "Print a constant string. Give string as argument.\n\
1063 C escape sequences may be used in the argument.\n\
1064 No newline is added at the end of the argument;\n\
1065 use \"\\n\" if you want a newline to be printed.\n\
1066 Since leading and trailing whitespace are ignored in command arguments,\n\
1067 if you want to print some you must use \"\\\" before leading whitespace\n\
1068 to be printed or after trailing whitespace.");
1069 add_com ("document", class_support, document_command,
1070 "Document a user-defined command.\n\
1071 Give command name as argument. Give documentation on following lines.\n\
1072 End with a line of just \"end\".");
1073 add_com ("define", class_support, define_command,
1074 "Define a new command name. Command name is argument.\n\
1075 Definition appears on following lines, one command per line.\n\
1076 End with a line of just \"end\".\n\
1077 Use the \"document\" command to give documentation for the new command.\n\
1078 Commands defined in this way do not take arguments.");
1079
1080 add_com ("source", class_support, source_command,
1081 "Read commands from a file named FILE.\n\
1082 Note that the file \".gdbinit\" is read automatically in this way\n\
1083 when gdb is started.");
1084 add_com ("quit", class_support, quit_command, "Exit gdb.");
1085 add_com ("help", class_support, help_command, "Print list of commands.");
1086 add_com_alias ("q", "quit", class_support, 1);
1087 add_com_alias ("h", "help", class_support, 1);
1088
1089 add_com ("dump-me", class_obscure, dump_me_command,
1090 "Get fatal error; make debugger dump its core.");
1091
1092 add_prefix_cmd ("info", class_info, info_command,
1093 "Generic command for printing status.",
1094 &infolist, "info ", 0, &cmdlist);
1095 add_com_alias ("i", "info", class_info, 1);
1096
1097 add_info ("copying", copying_info, "Conditions for redistributing copies of GDB.");
1098 add_info ("warranty", warranty_info, "Various kinds of warranty you do not have.");
1099 add_info ("version", version_info, "Report what version of GDB this is.");
1100 }
This page took 0.051334 seconds and 5 git commands to generate.