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