1 /* Top level for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
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.
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.
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!
25 #include <sys/param.h>
30 #ifdef SET_STACK_LIMIT_HUGE
32 #include <sys/resource.h>
35 /* Version number of GDB, as a string. */
39 /* Chain containing all defined commands. */
41 struct cmd_list_element
*cmdlist
;
43 /* Chain containing all defined info subcommands. */
45 struct cmd_list_element
*infolist
;
47 /* stdio stream that command input is being read from. */
51 /* Current working directory. */
53 char *current_directory
;
55 /* The directory name is actually stored here (usually). */
56 static char dirbuf
[MAXPATHLEN
];
58 /* Nonzero if we should refrain from using an X window. */
60 int inhibit_windows
= 0;
62 /* Hook for window manager argument parsing. */
68 /* Function to call before reading a command, if nonzero.
69 The function receives two args: an input stream,
70 and a prompt string. */
72 void (*window_hook
) ();
74 extern int frame_file_full_name
;
76 void free_command_lines ();
78 static void initialize_main ();
80 static void source_command ();
81 void print_gdb_version ();
83 /* gdb prints this when reading a command interactively */
86 /* Buffer used for reading command lines, and the size
87 allocated for it so far. */
92 /* This is how `error' returns to command level. */
96 return_to_top_level ()
100 clear_breakpoint_commands ();
101 clear_momentary_breakpoints ();
102 delete_current_display ();
104 longjmp (to_top_level
, 1);
107 /* Call FUNC with arg ARG, catching any errors.
108 If there is no error, return the value returned by FUNC.
109 If there is an error, return zero after printing ERRSTRING
110 (which is in addition to the specific error message already printed). */
113 catch_errors (func
, arg
, errstring
)
121 bcopy (to_top_level
, saved
, sizeof (jmp_buf));
123 if (setjmp (to_top_level
) == 0)
127 fprintf (stderr
, "%s\n", errstring
);
131 bcopy (saved
, to_top_level
, sizeof (jmp_buf));
135 /* Handler for SIGHUP. */
140 kill_inferior_fast ();
141 signal (SIGHUP
, SIG_DFL
);
142 kill (getpid (), SIGHUP
);
145 main (argc
, argv
, envp
)
150 extern void request_quit ();
152 int inhibit_gdbinit
= 0;
159 line
= (char *) xmalloc (linesize
);
163 current_directory
= dirbuf
;
169 #ifdef SET_STACK_LIMIT_HUGE
173 /* Set the stack limit huge so that alloca (particularly stringtab
174 * in dbxread.c) does not fail. */
175 getrlimit (RLIMIT_STACK
, &rlim
);
176 rlim
.rlim_cur
= rlim
.rlim_max
;
177 setrlimit (RLIMIT_STACK
, &rlim
);
179 #endif /* SET_STACK_LIMIT_HUGE */
181 /* Look for flag arguments. */
183 for (i
= 1; i
< argc
; i
++)
185 if (!strcmp (argv
[i
], "-q") || !strcmp (argv
[i
], "-quiet"))
187 else if (!strcmp (argv
[i
], "-nx"))
189 else if (!strcmp (argv
[i
], "-nw"))
191 else if (!strcmp (argv
[i
], "-batch"))
192 batch
= 1, quiet
= 1;
193 else if (!strcmp (argv
[i
], "-fullname"))
194 frame_file_full_name
= 1;
195 else if (argv
[i
][0] == '-')
199 /* Run the init function of each source file */
201 initialize_all_files ();
202 initialize_main (); /* But that omits this file! Do it now */
204 signal (SIGINT
, request_quit
);
205 signal (SIGQUIT
, SIG_IGN
);
206 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
207 signal (SIGHUP
, disconnect
);
210 print_gdb_version ();
212 /* Process the command line arguments. */
215 for (i
= 1; i
< argc
; i
++)
217 register char *arg
= argv
[i
];
218 /* Args starting with - say what to do with the following arg
222 extern void exec_file_command (), symbol_file_command ();
223 extern void core_file_command (), directory_command ();
224 extern void tty_command ();
226 if (!strcmp (arg
, "-q") || !strcmp (arg
, "-nx")
227 || !strcmp (arg
, "-quiet") || !strcmp (arg
, "-batch")
228 || !strcmp (arg
, "-fullname"))
229 /* Already processed above */
233 fprintf (stderr
, "No argument follows \"%s\".\n", arg
);
234 if (!setjmp (to_top_level
))
236 /* -s foo: get syms from foo. -e foo: execute foo.
237 -se foo: do both with foo. -c foo: use foo as core dump. */
238 if (!strcmp (arg
, "-se"))
240 exec_file_command (argv
[i
], !batch
);
241 symbol_file_command (argv
[i
], !batch
);
243 else if (!strcmp (arg
, "-s") || !strcmp (arg
, "-symbols"))
244 symbol_file_command (argv
[i
], !batch
);
245 else if (!strcmp (arg
, "-e") || !strcmp (arg
, "-exec"))
246 exec_file_command (argv
[i
], !batch
);
247 else if (!strcmp (arg
, "-c") || !strcmp (arg
, "-core"))
248 core_file_command (argv
[i
], !batch
);
249 /* -x foo: execute commands from foo. */
250 else if (!strcmp (arg
, "-x") || !strcmp (arg
, "-command")
251 || !strcmp (arg
, "-commands"))
252 source_command (argv
[i
]);
253 /* -d foo: add directory `foo' to source-file directory
255 else if (!strcmp (arg
, "-d") || !strcmp (arg
, "-dir")
256 || !strcmp (arg
, "-directory"))
257 directory_command (argv
[i
], 0);
258 /* -cd FOO: specify current directory as FOO.
259 GDB remembers the precise string FOO as the dirname. */
260 else if (!strcmp (arg
, "-cd"))
262 int len
= strlen (argv
[i
]);
263 current_directory
= argv
[i
];
264 if (len
> 1 && current_directory
[len
- 1] == '/')
265 current_directory
= savestring (current_directory
, len
-1);
266 chdir (current_directory
);
269 /* -t /def/ttyp1: use /dev/ttyp1 for inferior I/O. */
270 else if (!strcmp (arg
, "-t") || !strcmp (arg
, "-tty"))
271 tty_command (argv
[i
], 0);
273 error ("Unknown command-line switch: \"%s\"\n", arg
);
278 /* Args not thus accounted for
279 are treated as, first, the symbol/executable file
280 and, second, the core dump file. */
282 if (!setjmp (to_top_level
))
286 exec_file_command (arg
, !batch
);
287 symbol_file_command (arg
, !batch
);
291 core_file_command (arg
, !batch
);
295 fprintf (stderr
, "Excess command line args ignored. (%s%s)\n",
296 arg
, (i
== argc
- 1) ? "" : " ...");
301 /* Read init file, if it exists in home directory */
305 s
= (char *) xmalloc (strlen (getenv ("HOME")) + 10);
306 strcpy (s
, getenv ("HOME"));
307 strcat (s
, "/.gdbinit");
308 if (!inhibit_gdbinit
&& access (s
, R_OK
) == 0)
309 if (!setjmp (to_top_level
))
313 /* Read init file, if it exists in current directory. */
314 if (!inhibit_gdbinit
&& access (".gdbinit", R_OK
) == 0)
315 if (!setjmp (to_top_level
))
316 source_command (".gdbinit");
319 fatal ("Attempt to read commands from stdin in batch mode.");
322 printf ("Type \"help\" for a list of commands.\n");
324 /* The command loop. */
328 if (!setjmp (to_top_level
))
330 clearerr (stdin
); /* Don't get hung if C-d is typed. */
334 /* Execute the line P as a command.
335 Pass FROM_TTY as second argument to the defining function. */
338 execute_command (p
, from_tty
)
342 register struct cmd_list_element
*c
;
343 register struct command_line
*cmdlines
;
346 while (*p
== ' ' || *p
== '\t') p
++;
349 c
= lookup_cmd (&p
, cmdlist
, "", 0);
350 if (c
->function
== 0)
351 error ("That is not a command, just a help topic.");
352 else if (c
->class == (int) class_user
)
355 error ("User-defined commands cannot take arguments.");
356 cmdlines
= (struct command_line
*) c
->function
;
357 if (cmdlines
== (struct command_line
*) 0)
362 execute_command (cmdlines
->line
, 0);
363 cmdlines
= cmdlines
->next
;
367 /* Pass null arg rather than an empty one. */
368 (*c
->function
) (*p
? p
: 0, from_tty
);
377 /* Read commands from `instream' and execute them
378 until end of file. */
382 struct cleanup
*old_chain
;
383 while (!feof (instream
))
385 if (instream
== stdin
)
386 printf ("%s", prompt
);
389 if (window_hook
&& instream
== stdin
)
390 (*window_hook
) (instream
, prompt
);
393 old_chain
= make_cleanup (do_nothing
, 0);
394 execute_command (read_line (instream
== stdin
), instream
== stdin
);
395 /* Do any commands attached to breakpoint we stopped at. */
396 do_breakpoint_commands ();
397 do_cleanups (old_chain
);
405 signal (SIGTSTP
, SIG_DFL
);
407 kill (getpid (), SIGTSTP
);
408 signal (SIGTSTP
, stop_sig
);
409 printf ("%s", prompt
);
412 /* Forget about any previous command -- null line now will do nothing. */
417 /* Commands call this if they do not want to be repeated by null lines. */
425 /* Read one line from the command input stream `instream'
426 into the buffer `line' (whose current length is `linesize').
427 The buffer is made bigger as necessary.
428 Returns the address of the start of the line. */
434 register char *p
= line
;
439 /* Control-C quits instantly if typed while in this loop
440 since it should not wait until the user types a newline. */
443 signal (SIGTSTP
, stop_sig
);
448 c
= fgetc (instream
);
449 if (c
== -1 || c
== '\n')
451 /* Ignore backslash-newline; keep adding to the same line. */
454 int c1
= fgetc (instream
);
458 ungetc (c1
, instream
);
461 if (p
- line
== linesize
- 1)
464 nline
= (char *) xrealloc (line
, linesize
);
472 signal (SIGTSTP
, SIG_DFL
);
476 /* If we just got an empty line, and that is supposed
477 to repeat the previous command, leave the last input unchanged. */
478 if (p
== line
&& repeat
)
481 /* If line is a comment, clear it out. */
483 while ((c
= *p1
) == ' ' || c
== '\t') p1
++;
492 /* Read lines from the input stream
493 and accumulate them in a chain of struct command_line's
494 which is then returned. */
496 struct command_line
*
497 read_command_lines ()
499 struct command_line
*first
= 0;
500 register struct command_line
*next
, *tail
= 0;
501 register char *p
, *p1
;
502 struct cleanup
*old_chain
= 0;
508 /* Remove leading and trailing blanks. */
509 while (*p
== ' ' || *p
== '\t') p
++;
511 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t')) p1
--;
514 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
517 /* No => add this line to the chain of command lines. */
518 next
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
519 next
->line
= savestring (p
, p1
- p
);
527 /* We just read the first line.
528 From now on, arrange to throw away the lines we have
529 if we quit or get an error while inside this function. */
531 old_chain
= make_cleanup (free_command_lines
, &first
);
538 /* Now we are about to return the chain to our caller,
539 so freeing it becomes his responsibility. */
541 discard_cleanups (old_chain
);
545 /* Free a chain of struct command_line's. */
548 free_command_lines (lptr
)
549 struct command_line
**lptr
;
551 register struct command_line
*l
= *lptr
;
552 register struct command_line
*next
;
563 /* Add an element to the list of info subcommands. */
566 add_info (name
, fun
, doc
)
571 add_cmd (name
, 0, fun
, doc
, &infolist
);
574 /* Add an alias to the list of info subcommands. */
577 add_info_alias (name
, oldname
, abbrev_flag
)
582 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
585 /* The "info" command is defined as a prefix, with allow_unknown = 0.
586 Therefore, its own definition is called only for "info" with no args. */
591 printf ("\"info\" must be followed by the name of an info command.\n");
592 help_cmd (0, infolist
, "info ", -1, stdout
);
595 /* Add an element to the list of commands. */
598 add_com (name
, class, fun
, doc
)
604 add_cmd (name
, class, fun
, doc
, &cmdlist
);
607 /* Add an alias or abbreviation command to the list of commands. */
610 add_com_alias (name
, oldname
, class, abbrev_flag
)
616 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
623 error ("Argument required (%s).", why
);
627 help_command (command
, from_tty
)
629 int from_tty
; /* Ignored */
631 help_cmd (command
, cmdlist
, "", -2, stdout
);
635 validate_comname (comname
)
641 error_no_arg ("name of command to define");
646 if (!(*p
>= 'A' && *p
<= 'Z')
647 && !(*p
>= 'a' && *p
<= 'z')
648 && !(*p
>= '0' && *p
<= '9')
650 error ("Junk in argument list: \"%s\"", p
);
656 define_command (comname
, from_tty
)
660 register struct command_line
*cmds
;
661 register struct cmd_list_element
*c
;
664 validate_comname (comname
);
666 c
= lookup_cmd (&tem
, cmdlist
, "", -1);
669 if (c
->class == (int) class_user
|| c
->class == (int) class_alias
)
670 tem
= "Redefine command \"%s\"? ";
672 tem
= "Really redefine built-in command \"%s\"? ";
673 if (!query (tem
, comname
))
674 error ("Command \"%s\" not redefined.", comname
);
678 printf ("Type commands for definition of \"%s\".\n\
679 End with a line saying just \"end\".\n", comname
);
681 comname
= savestring (comname
, strlen (comname
));
683 cmds
= read_command_lines ();
685 if (c
&& c
->class == (int) class_user
)
686 free_command_lines (&c
->function
);
688 add_com (comname
, class_user
, cmds
,
689 (c
&& c
->class == (int) class_user
)
690 ? c
->doc
: savestring ("User-defined.", 13));
694 document_command (comname
, from_tty
)
698 struct command_line
*doclines
;
699 register struct cmd_list_element
*c
;
702 validate_comname (comname
);
704 c
= lookup_cmd (&tem
, cmdlist
, "", 0);
706 if (c
->class != (int) class_user
)
707 error ("Command \"%s\" is built-in.", comname
);
710 printf ("Type documentation for \"%s\".\n\
711 End with a line saying just \"end\".\n", comname
);
713 doclines
= read_command_lines ();
715 if (c
->doc
) free (c
->doc
);
718 register struct command_line
*cl1
;
719 register int len
= 0;
721 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
722 len
+= strlen (cl1
->line
) + 1;
724 c
->doc
= (char *) xmalloc (len
+ 1);
727 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
729 strcat (c
->doc
, cl1
->line
);
731 strcat (c
->doc
, "\n");
735 free_command_lines (&doclines
);
742 printf (" GDB GENERAL PUBLIC LICENSE\n\
743 (Clarified 11 Feb 1988)\n\
745 Copyright (C) 1988 Richard M. Stallman\n\
746 Everyone is permitted to copy and distribute verbatim copies\n\
747 of this license, but changing it is not allowed.\n\
748 You can also use this wording to make the terms for other programs.\n\
750 The license agreements of most software companies keep you at the\n\
751 mercy of those companies. By contrast, our general public license is\n\
752 intended to give everyone the right to share GDB. To make sure that\n\
753 you get the rights we want you to have, we need to make restrictions\n\
754 that forbid anyone to deny you these rights or to ask you to surrender\n\
755 the rights. Hence this license agreement.\n\
757 Specifically, we want to make sure that you have the right to give\n\
758 away copies of GDB, that you receive source code or else can get it\n\
759 if you want it, that you can change GDB or use pieces of it in new\n\
760 free programs, and that you know you can do these things.\n\
761 --Type Return to print more--");
766 To make sure that everyone has such rights, we have to forbid you to\n\
767 deprive anyone else of these rights. For example, if you distribute\n\
768 copies of GDB, you must give the recipients all the rights that you\n\
769 have. You must make sure that they, too, receive or can get the\n\
770 source code. And you must tell them their rights.\n\
772 Also, for our own protection, we must make certain that everyone\n\
773 finds out that there is no warranty for GDB. If GDB is modified by\n\
774 someone else and passed on, we want its recipients to know that what\n\
775 they have is not what we distributed, so that any problems introduced\n\
776 by others will not reflect on our reputation.\n\
778 Therefore we (Richard Stallman and the Free Software Foundation,\n\
779 Inc.) make the following terms which say what you must do to be\n\
780 allowed to distribute or change GDB.\n\
781 --Type Return to print more--");
788 1. You may copy and distribute verbatim copies of GDB source code as\n\
789 you receive it, in any medium, provided that you conspicuously and\n\
790 appropriately publish on each copy a valid copyright notice \"Copyright\n\
791 \(C) 1988 Free Software Foundation, Inc.\" (or with whatever year is\n\
792 appropriate); keep intact the notices on all files that refer\n\
793 to this License Agreement and to the absence of any warranty; and give\n\
794 any other recipients of the GDB program a copy of this License\n\
795 Agreement along with the program. You may charge a distribution fee\n\
796 for the physical act of transferring a copy.\n\
798 2. You may modify your copy or copies of GDB or any portion of it,\n\
799 and copy and distribute such modifications under the terms of\n\
800 Paragraph 1 above, provided that you also do the following:\n\
802 a) cause the modified files to carry prominent notices stating\n\
803 that you changed the files and the date of any change; and\n\
804 --Type Return to print more--");
809 b) cause the whole of any work that you distribute or publish,\n\
810 that in whole or in part contains or is a derivative of GDB\n\
811 or any part thereof, to be licensed to all third parties on terms\n\
812 identical to those contained in this License Agreement (except that\n\
813 you may choose to grant more extensive warranty protection to some\n\
814 or all third parties, at your option).\n\
817 c) if the modified program serves as a debugger, cause it\n\
818 when started running in the simplest and usual way, to print\n\
819 an announcement including a valid copyright notice\n\
820 \"Copyright (C) 1988 Free Software Foundation, Inc.\" (or with\n\
821 the year that is appropriate), saying that there is no warranty\n\
822 (or else, saying that you provide a warranty) and that users may\n\
823 redistribute the program under these conditions, and telling the user\n\
824 how to view a copy of this License Agreement.\n\
826 d) You may charge a distribution fee for the physical act of\n\
827 transferring a copy, and you may at your option offer warranty\n\
828 protection in exchange for a fee.\n\
830 Mere aggregation of another unrelated program with this program (or its\n\
831 derivative) on a volume of a storage or distribution medium does not bring\n\
832 the other program under the scope of these terms.\n\
833 --Type Return to print more--");
838 3. You may copy and distribute GDB (or a portion or derivative of it,\n\
839 under Paragraph 2) in object code or executable form under the terms of\n\
840 Paragraphs 1 and 2 above provided that you also do one of the following:\n\
842 a) accompany it with the complete corresponding machine-readable\n\
843 source code, which must be distributed under the terms of\n\
844 Paragraphs 1 and 2 above; or,\n\
846 b) accompany it with a written offer, valid for at least three\n\
847 years, to give any third party free (except for a nominal\n\
848 shipping charge) a complete machine-readable copy of the\n\
849 corresponding source code, to be distributed under the terms of\n\
850 Paragraphs 1 and 2 above; or,\n\n");
853 c) accompany it with the information you received as to where the\n\
854 corresponding source code may be obtained. (This alternative is\n\
855 allowed only for noncommercial distribution and only if you\n\
856 received the program in object code or executable form alone.)\n\
858 For an executable file, complete source code means all the source code for\n\
859 all modules it contains; but, as a special exception, it need not include\n\
860 source code for modules which are standard libraries that accompany the\n\
861 operating system on which the executable file runs.\n\
862 --Type Return to print more--");
867 4. You may not copy, sublicense, distribute or transfer GDB\n\
868 except as expressly provided under this License Agreement. Any attempt\n\
869 otherwise to copy, sublicense, distribute or transfer GDB is void and\n\
870 your rights to use the program under this License agreement shall be\n\
871 automatically terminated. However, parties who have received computer\n\
872 software programs from you with this License Agreement will not have\n\
873 their licenses terminated so long as such parties remain in full compliance.\n\
875 5. If you wish to incorporate parts of GDB into other free\n\
876 programs whose distribution conditions are different, write to the Free\n\
877 Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet\n\
878 worked out a simple rule that can be stated here, but we will often permit\n\
879 this. We will be guided by the two goals of preserving the free status of\n\
880 all derivatives of our free software and of promoting the sharing and reuse\n\
883 In other words, go ahead and share GDB, but don't try to stop\n\
884 anyone else from sharing it farther. Help stamp out software hoarding!\n\
893 printf (" NO WARRANTY\n\
895 BECAUSE GDB IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO\n\
896 WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT\n\
897 WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,\n\
898 RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE GDB \"AS IS\" WITHOUT\n\
899 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT\n\
900 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n\
901 A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND\n\
902 PERFORMANCE OF GDB IS WITH YOU. SHOULD GDB PROVE DEFECTIVE, YOU\n\
903 ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n");
906 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.\n\
907 STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY\n\
908 WHO MAY MODIFY AND REDISTRIBUTE GDB, BE LIABLE TO\n\
909 YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER\n\
910 SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR\n\
911 INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA\n\
912 BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A\n\
913 FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GDB, EVEN\n\
914 IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR\n\
915 ANY CLAIM BY ANY OTHER PARTY.\n");
922 printf ("GDB %s, Copyright (C) 1988 Free Software Foundation, Inc.\n\
923 There is ABSOLUTELY NO WARRANTY for GDB; type \"info warranty\" for details.\n\
924 GDB is free software and you are welcome to distribute copies of it\n\
925 under certain conditions; type \"info copying\" to see the conditions.\n",
933 print_gdb_version ();
937 /* xgdb calls this to reprint the usual GDB prompt. */
942 printf ("%s", prompt
);
946 /* Command to specify a prompt string instead of "(gdb) ". */
949 set_prompt_command (text
)
957 error_no_arg ("string to which to set prompt");
959 new = (char *) xmalloc (strlen (text
) + 2);
965 /* \ at end of argument is used after spaces
966 so they won't be lost. */
969 c
= parse_escape (&p
);
978 if (*(p
- 1) != '\\')
981 new = (char *) xrealloc (new, q
- new);
989 if (have_inferior_p ())
991 if (query ("The program is running. Quit anyway? "))
993 /* Prevent any warning message from reopen_exec_file, in case
994 we have a core file that's inconsistent with the exec file. */
995 exec_file_command (0, 0);
999 error ("Not confirmed.");
1005 input_from_terminal_p ()
1007 return instream
== stdin
;
1011 pwd_command (arg
, from_tty
)
1015 if (arg
) error ("The \"pwd\" command does not take an argument: %s", arg
);
1018 if (strcmp (dirbuf
, current_directory
))
1019 printf ("Working directory %s\n (canonically %s).\n",
1020 current_directory
, dirbuf
);
1022 printf ("Working directory %s.\n", current_directory
);
1026 cd_command (dir
, from_tty
)
1034 error_no_arg ("new working directory");
1037 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
1039 current_directory
= dir
;
1042 current_directory
= concat (current_directory
, "/", dir
);
1046 /* Now simplify any occurrences of `.' and `..' in the pathname. */
1054 for (p
= current_directory
; *p
;)
1056 if (!strncmp (p
, "/./", 2)
1057 && (p
[2] == 0 || p
[2] == '/'))
1059 else if (!strncmp (p
, "/..", 3)
1060 && (p
[3] == 0 || p
[3] == '/')
1061 && p
!= current_directory
)
1064 while (q
!= current_directory
&& q
[-1] != '/') q
--;
1065 if (q
!= current_directory
)
1075 if (chdir (dir
) < 0)
1076 perror_with_name (dir
);
1079 pwd_command ((char *) 0, 1);
1082 /* Clean up on error during a "source" command.
1083 Close the file opened by the command
1084 and restore the previous input stream. */
1087 source_cleanup (stream
)
1095 source_command (file
)
1099 struct cleanup
*cleanups
;
1102 error_no_arg ("file to read commands from");
1104 stream
= fopen (file
, "r");
1106 perror_with_name (file
);
1108 cleanups
= make_cleanup (source_cleanup
, instream
);
1114 do_cleanups (cleanups
);
1129 /* \ at end of argument is used after spaces
1130 so they won't be lost. */
1134 c
= parse_escape (&p
);
1146 if (query ("Should GDB dump core? "))
1148 signal (SIGQUIT
, SIG_DFL
);
1149 kill (getpid (), SIGQUIT
);
1156 prompt
= savestring ("(gdb) ", 6);
1158 /* Define the classes of commands.
1159 They will appear in the help list in the reverse of this order. */
1161 add_cmd ("obscure", class_obscure
, 0, "Obscure features.", &cmdlist
);
1162 add_cmd ("alias", class_alias
, 0, "Aliases of other commands.", &cmdlist
);
1163 add_cmd ("user", class_user
, 0, "User-defined commands.\n\
1164 The commands in this class are those defined by the user.\n\
1165 Use the \"define\" command to define a command.", &cmdlist
);
1166 add_cmd ("support", class_support
, 0, "Support facilities.", &cmdlist
);
1167 add_cmd ("status", class_info
, 0, "Status inquiries.", &cmdlist
);
1168 add_cmd ("files", class_files
, 0, "Specifying and examining files.", &cmdlist
);
1169 add_cmd ("breakpoints", class_breakpoint
, 0, "Making program stop at certain points.", &cmdlist
);
1170 add_cmd ("data", class_vars
, 0, "Examining data.", &cmdlist
);
1171 add_cmd ("stack", class_stack
, 0, "Examining the stack.\n\
1172 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
1173 counting from zero for the innermost (currently executing) frame.\n\n\
1174 At any time gdb identifies one frame as the \"selected\" frame.\n\
1175 Variable lookups are done with respect to the selected frame.\n\
1176 When the program being debugged stops, gdb selects the innermost frame.\n\
1177 The commands below can be used to select other frames by number or address.",
1179 add_cmd ("running", class_run
, 0, "Running the program.", &cmdlist
);
1181 add_com ("pwd", class_files
, pwd_command
,
1182 "Print working directory. This is used for your program as well.");
1183 add_com ("cd", class_files
, cd_command
,
1184 "Set working directory to DIR for debugger and program being debugged.\n\
1185 The change does not take effect for the program being debugged\n\
1186 until the next time it is started.");
1188 add_com ("set-prompt", class_support
, set_prompt_command
,
1189 "Change gdb's prompt from the default of \"(gdb)\"");
1190 add_com ("echo", class_support
, echo_command
,
1191 "Print a constant string. Give string as argument.\n\
1192 C escape sequences may be used in the argument.\n\
1193 No newline is added at the end of the argument;\n\
1194 use \"\\n\" if you want a newline to be printed.\n\
1195 Since leading and trailing whitespace are ignored in command arguments,\n\
1196 if you want to print some you must use \"\\\" before leading whitespace\n\
1197 to be printed or after trailing whitespace.");
1198 add_com ("document", class_support
, document_command
,
1199 "Document a user-defined command.\n\
1200 Give command name as argument. Give documentation on following lines.\n\
1201 End with a line of just \"end\".");
1202 add_com ("define", class_support
, define_command
,
1203 "Define a new command name. Command name is argument.\n\
1204 Definition appears on following lines, one command per line.\n\
1205 End with a line of just \"end\".\n\
1206 Use the \"document\" command to give documentation for the new command.\n\
1207 Commands defined in this way do not take arguments.");
1209 add_com ("source", class_support
, source_command
,
1210 "Read commands from a file named FILE.\n\
1211 Note that the file \".gdbinit\" is read automatically in this way\n\
1212 when gdb is started.");
1213 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
1214 add_com ("help", class_support
, help_command
, "Print list of commands.");
1215 add_com_alias ("q", "quit", class_support
, 1);
1216 add_com_alias ("h", "help", class_support
, 1);
1218 add_com ("dump-me", class_obscure
, dump_me_command
,
1219 "Get fatal error; make debugger dump its core.");
1221 add_prefix_cmd ("info", class_info
, info_command
,
1222 "Generic command for printing status.",
1223 &infolist
, "info ", 0, &cmdlist
);
1224 add_com_alias ("i", "info", class_info
, 1);
1226 add_info ("copying", copying_info
, "Conditions for redistributing copies of GDB.");
1227 add_info ("warranty", warranty_info
, "Various kinds of warranty you do not have.");
1228 add_info ("version", version_info
, "Report what version of GDB this is.");
This page took 0.108244 seconds and 5 git commands to generate.