Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Top level stuff for GDB, the GNU debugger. |
085dd6e6 | 2 | Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 1999 |
c906108c SS |
3 | Free Software Foundation, Inc. |
4 | ||
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
c906108c SS |
23 | #include "top.h" |
24 | #include "target.h" | |
25 | #include "inferior.h" | |
26 | #include "call-cmds.h" | |
27 | ||
28 | #include "getopt.h" | |
29 | ||
30 | #include <sys/types.h> | |
31 | #include "gdb_stat.h" | |
32 | #include <ctype.h> | |
33 | ||
34 | #include "gdb_string.h" | |
9e0b60a8 | 35 | #include "event-loop.h" |
c906108c | 36 | |
c906108c SS |
37 | /* If nonzero, display time usage both at startup and for each command. */ |
38 | ||
39 | int display_time; | |
40 | ||
41 | /* If nonzero, display space usage both at startup and for each command. */ | |
42 | ||
43 | int display_space; | |
44 | ||
cd0fc7c3 | 45 | /* Whether this is the async version or not. The async version is |
c5aa993b JM |
46 | invoked on the command line with the -nw --async options. In this |
47 | version, the usual command_loop is substituted by and event loop which | |
48 | processes UI events asynchronously. */ | |
6426a772 | 49 | int event_loop_p = 1; |
cd0fc7c3 | 50 | |
c906108c SS |
51 | /* Whether this is the command line version or not */ |
52 | int tui_version = 0; | |
53 | ||
54 | /* Whether xdb commands will be handled */ | |
55 | int xdb_commands = 0; | |
56 | ||
57 | /* Whether dbx commands will be handled */ | |
58 | int dbx_commands = 0; | |
59 | ||
60 | GDB_FILE *gdb_stdout; | |
61 | GDB_FILE *gdb_stderr; | |
0f71a2f6 | 62 | GDB_FILE *gdb_stdlog; |
43ff13b4 | 63 | GDB_FILE *gdb_stdtarg; |
c906108c | 64 | |
2acceee2 JM |
65 | /* Used to initialize error() - defined in utils.c */ |
66 | ||
67 | extern void error_init (void); | |
68 | ||
c906108c SS |
69 | /* Whether to enable writing into executable and core files */ |
70 | extern int write_files; | |
71 | ||
72 | static void print_gdb_help PARAMS ((GDB_FILE *)); | |
c906108c SS |
73 | |
74 | /* These two are used to set the external editor commands when gdb is farming | |
75 | out files to be edited by another program. */ | |
76 | ||
77 | extern int enable_external_editor; | |
c5aa993b | 78 | extern char *external_editor_command; |
c906108c SS |
79 | |
80 | #ifdef __CYGWIN__ | |
c5aa993b JM |
81 | #include <windows.h> /* for MAX_PATH */ |
82 | #include <sys/cygwin.h> /* for cygwin32_conv_to_posix_path */ | |
c906108c SS |
83 | #endif |
84 | ||
85 | int | |
86 | main (argc, argv) | |
87 | int argc; | |
88 | char **argv; | |
89 | { | |
90 | int count; | |
91 | static int quiet = 0; | |
92 | static int batch = 0; | |
93 | ||
94 | /* Pointers to various arguments from command line. */ | |
95 | char *symarg = NULL; | |
96 | char *execarg = NULL; | |
97 | char *corearg = NULL; | |
98 | char *cdarg = NULL; | |
99 | char *ttyarg = NULL; | |
100 | ||
101 | /* These are static so that we can take their address in an initializer. */ | |
102 | static int print_help; | |
103 | static int print_version; | |
104 | ||
105 | /* Pointers to all arguments of --command option. */ | |
106 | char **cmdarg; | |
107 | /* Allocated size of cmdarg. */ | |
108 | int cmdsize; | |
109 | /* Number of elements of cmdarg used. */ | |
110 | int ncmd; | |
111 | ||
112 | /* Indices of all arguments of --directory option. */ | |
113 | char **dirarg; | |
114 | /* Allocated size. */ | |
115 | int dirsize; | |
116 | /* Number of elements used. */ | |
117 | int ndir; | |
c5aa993b | 118 | |
c906108c SS |
119 | struct stat homebuf, cwdbuf; |
120 | char *homedir, *homeinit; | |
121 | ||
122 | register int i; | |
123 | ||
124 | long time_at_startup = get_run_time (); | |
125 | ||
c906108c SS |
126 | START_PROGRESS (argv[0], 0); |
127 | ||
128 | #ifdef MPW | |
129 | /* Do all Mac-specific setup. */ | |
130 | mac_init (); | |
131 | #endif /* MPW */ | |
132 | ||
133 | /* This needs to happen before the first use of malloc. */ | |
134 | init_malloc ((PTR) NULL); | |
135 | ||
136 | #if defined (ALIGN_STACK_ON_STARTUP) | |
137 | i = (int) &count & 0x3; | |
138 | if (i != 0) | |
139 | alloca (4 - i); | |
140 | #endif | |
141 | ||
142 | /* If error() is called from initialization code, just exit */ | |
c5aa993b JM |
143 | if (SET_TOP_LEVEL ()) |
144 | { | |
145 | exit (1); | |
146 | } | |
c906108c SS |
147 | |
148 | cmdsize = 1; | |
149 | cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg)); | |
150 | ncmd = 0; | |
151 | dirsize = 1; | |
152 | dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg)); | |
153 | ndir = 0; | |
154 | ||
155 | quit_flag = 0; | |
156 | line = (char *) xmalloc (linesize); | |
157 | line[0] = '\0'; /* Terminate saved (now empty) cmd line */ | |
158 | instream = stdin; | |
159 | ||
160 | getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); | |
161 | current_directory = gdb_dirbuf; | |
162 | ||
ac9a91a7 JM |
163 | #if 0 |
164 | /* not yet */ | |
165 | gdb_stdout = stdio_fileopen (stdout); | |
166 | gdb_stderr = stdio_fileopen (stderr); | |
c5aa993b JM |
167 | gdb_stdlog = gdb_stderr; /* for moment */ |
168 | gdb_stdtarg = gdb_stderr; /* for moment */ | |
ac9a91a7 JM |
169 | #else |
170 | gdb_stdout = tui_fileopen (stdout); | |
171 | gdb_stderr = tui_fileopen (stderr); | |
c5aa993b JM |
172 | gdb_stdlog = gdb_stdout; /* for moment */ |
173 | gdb_stdtarg = gdb_stderr; /* for moment */ | |
ac9a91a7 | 174 | #endif |
c906108c | 175 | |
2acceee2 JM |
176 | /* initialize error() */ |
177 | error_init (); | |
178 | ||
c906108c SS |
179 | /* Parse arguments and options. */ |
180 | { | |
181 | int c; | |
182 | /* When var field is 0, use flag field to record the equivalent | |
183 | short option (or arbitrary numbers starting at 10 for those | |
184 | with no equivalent). */ | |
185 | static struct option long_options[] = | |
c5aa993b | 186 | { |
6426a772 JM |
187 | {"async", no_argument, &event_loop_p, 1}, |
188 | {"noasync", no_argument, &event_loop_p, 0}, | |
c906108c | 189 | #if defined(TUI) |
c5aa993b | 190 | {"tui", no_argument, &tui_version, 1}, |
c906108c | 191 | #endif |
c5aa993b JM |
192 | {"xdb", no_argument, &xdb_commands, 1}, |
193 | {"dbx", no_argument, &dbx_commands, 1}, | |
194 | {"readnow", no_argument, &readnow_symbol_files, 1}, | |
195 | {"r", no_argument, &readnow_symbol_files, 1}, | |
196 | {"mapped", no_argument, &mapped_symbol_files, 1}, | |
197 | {"m", no_argument, &mapped_symbol_files, 1}, | |
198 | {"quiet", no_argument, &quiet, 1}, | |
199 | {"q", no_argument, &quiet, 1}, | |
200 | {"silent", no_argument, &quiet, 1}, | |
201 | {"nx", no_argument, &inhibit_gdbinit, 1}, | |
202 | {"n", no_argument, &inhibit_gdbinit, 1}, | |
203 | {"batch", no_argument, &batch, 1}, | |
204 | {"epoch", no_argument, &epoch_interface, 1}, | |
205 | ||
206 | /* This is a synonym for "--annotate=1". --annotate is now preferred, | |
207 | but keep this here for a long time because people will be running | |
208 | emacses which use --fullname. */ | |
209 | {"fullname", no_argument, 0, 'f'}, | |
210 | {"f", no_argument, 0, 'f'}, | |
211 | ||
212 | {"annotate", required_argument, 0, 12}, | |
213 | {"help", no_argument, &print_help, 1}, | |
214 | {"se", required_argument, 0, 10}, | |
215 | {"symbols", required_argument, 0, 's'}, | |
216 | {"s", required_argument, 0, 's'}, | |
217 | {"exec", required_argument, 0, 'e'}, | |
218 | {"e", required_argument, 0, 'e'}, | |
219 | {"core", required_argument, 0, 'c'}, | |
220 | {"c", required_argument, 0, 'c'}, | |
221 | {"command", required_argument, 0, 'x'}, | |
222 | {"version", no_argument, &print_version, 1}, | |
223 | {"x", required_argument, 0, 'x'}, | |
224 | {"directory", required_argument, 0, 'd'}, | |
225 | {"cd", required_argument, 0, 11}, | |
226 | {"tty", required_argument, 0, 't'}, | |
227 | {"baud", required_argument, 0, 'b'}, | |
228 | {"b", required_argument, 0, 'b'}, | |
229 | {"nw", no_argument, &use_windows, 0}, | |
230 | {"nowindows", no_argument, &use_windows, 0}, | |
231 | {"w", no_argument, &use_windows, 1}, | |
232 | {"windows", no_argument, &use_windows, 1}, | |
233 | {"statistics", no_argument, 0, 13}, | |
234 | {"write", no_argument, &write_files, 1}, | |
c906108c SS |
235 | /* Allow machine descriptions to add more options... */ |
236 | #ifdef ADDITIONAL_OPTIONS | |
c5aa993b | 237 | ADDITIONAL_OPTIONS |
c906108c | 238 | #endif |
c5aa993b JM |
239 | {0, no_argument, 0, 0} |
240 | }; | |
c906108c SS |
241 | |
242 | while (1) | |
243 | { | |
244 | int option_index; | |
245 | ||
246 | c = getopt_long_only (argc, argv, "", | |
247 | long_options, &option_index); | |
248 | if (c == EOF) | |
249 | break; | |
250 | ||
251 | /* Long option that takes an argument. */ | |
252 | if (c == 0 && long_options[option_index].flag == 0) | |
253 | c = long_options[option_index].val; | |
254 | ||
255 | switch (c) | |
256 | { | |
257 | case 0: | |
258 | /* Long option that just sets a flag. */ | |
259 | break; | |
260 | case 10: | |
261 | symarg = optarg; | |
262 | execarg = optarg; | |
263 | break; | |
264 | case 11: | |
265 | cdarg = optarg; | |
266 | break; | |
267 | case 12: | |
268 | /* FIXME: what if the syntax is wrong (e.g. not digits)? */ | |
269 | annotation_level = atoi (optarg); | |
270 | break; | |
271 | case 13: | |
272 | /* Enable the display of both time and space usage. */ | |
273 | display_time = 1; | |
274 | display_space = 1; | |
275 | break; | |
276 | case 'f': | |
277 | annotation_level = 1; | |
278 | /* We have probably been invoked from emacs. Disable window interface. */ | |
279 | use_windows = 0; | |
280 | break; | |
281 | case 's': | |
282 | symarg = optarg; | |
283 | break; | |
284 | case 'e': | |
285 | execarg = optarg; | |
286 | break; | |
287 | case 'c': | |
288 | corearg = optarg; | |
289 | break; | |
290 | case 'x': | |
291 | cmdarg[ncmd++] = optarg; | |
292 | if (ncmd >= cmdsize) | |
293 | { | |
294 | cmdsize *= 2; | |
c5aa993b | 295 | cmdarg = (char **) xrealloc ((char *) cmdarg, |
c906108c SS |
296 | cmdsize * sizeof (*cmdarg)); |
297 | } | |
298 | break; | |
299 | case 'd': | |
300 | dirarg[ndir++] = optarg; | |
301 | if (ndir >= dirsize) | |
302 | { | |
303 | dirsize *= 2; | |
c5aa993b | 304 | dirarg = (char **) xrealloc ((char *) dirarg, |
c906108c SS |
305 | dirsize * sizeof (*dirarg)); |
306 | } | |
307 | break; | |
308 | case 't': | |
309 | ttyarg = optarg; | |
310 | break; | |
311 | case 'q': | |
312 | quiet = 1; | |
313 | break; | |
314 | case 'b': | |
315 | { | |
316 | int i; | |
317 | char *p; | |
318 | ||
319 | i = strtol (optarg, &p, 0); | |
320 | if (i == 0 && p == optarg) | |
321 | ||
322 | /* Don't use *_filtered or warning() (which relies on | |
c5aa993b | 323 | current_target) until after initialize_all_files(). */ |
c906108c SS |
324 | |
325 | fprintf_unfiltered | |
326 | (gdb_stderr, | |
327 | "warning: could not set baud rate to `%s'.\n", optarg); | |
328 | else | |
329 | baud_rate = i; | |
330 | } | |
331 | case 'l': | |
332 | { | |
333 | int i; | |
334 | char *p; | |
335 | ||
336 | i = strtol (optarg, &p, 0); | |
337 | if (i == 0 && p == optarg) | |
338 | ||
339 | /* Don't use *_filtered or warning() (which relies on | |
c5aa993b | 340 | current_target) until after initialize_all_files(). */ |
c906108c SS |
341 | |
342 | fprintf_unfiltered | |
343 | (gdb_stderr, | |
c5aa993b | 344 | "warning: could not set timeout limit to `%s'.\n", optarg); |
c906108c SS |
345 | else |
346 | remote_timeout = i; | |
347 | } | |
348 | break; | |
349 | ||
350 | #ifdef ADDITIONAL_OPTION_CASES | |
c5aa993b | 351 | ADDITIONAL_OPTION_CASES |
c906108c SS |
352 | #endif |
353 | case '?': | |
354 | fprintf_unfiltered (gdb_stderr, | |
c5aa993b JM |
355 | "Use `%s --help' for a complete list of options.\n", |
356 | argv[0]); | |
c906108c SS |
357 | exit (1); |
358 | } | |
359 | } | |
360 | ||
361 | /* If --help or --version, disable window interface. */ | |
362 | if (print_help || print_version) | |
363 | { | |
364 | use_windows = 0; | |
365 | #ifdef TUI | |
366 | /* Disable the TUI as well. */ | |
367 | tui_version = 0; | |
368 | #endif | |
369 | } | |
370 | ||
371 | #ifdef TUI | |
372 | /* An explicit --tui flag overrides the default UI, which is the | |
373 | window system. */ | |
374 | if (tui_version) | |
375 | use_windows = 0; | |
c5aa993b | 376 | #endif |
c906108c SS |
377 | |
378 | /* OK, that's all the options. The other arguments are filenames. */ | |
379 | count = 0; | |
380 | for (; optind < argc; optind++) | |
381 | switch (++count) | |
382 | { | |
383 | case 1: | |
384 | symarg = argv[optind]; | |
385 | execarg = argv[optind]; | |
386 | break; | |
387 | case 2: | |
388 | corearg = argv[optind]; | |
389 | break; | |
390 | case 3: | |
391 | fprintf_unfiltered (gdb_stderr, | |
c5aa993b JM |
392 | "Excess command line arguments ignored. (%s%s)\n", |
393 | argv[optind], (optind == argc - 1) ? "" : " ..."); | |
c906108c SS |
394 | break; |
395 | } | |
396 | if (batch) | |
397 | quiet = 1; | |
398 | } | |
399 | ||
400 | #if defined(TUI) | |
0f71a2f6 | 401 | /* Should this be moved to tui-top.c:_initialize_tui()? */ |
c906108c SS |
402 | if (tui_version) |
403 | init_ui_hook = tuiInit; | |
404 | #endif | |
0f71a2f6 JM |
405 | |
406 | /* Initialize all files. Give the interpreter a chance to take | |
407 | control of the console via the init_ui_hook()) */ | |
c906108c SS |
408 | gdb_init (argv[0]); |
409 | ||
410 | /* Do these (and anything which might call wrap_here or *_filtered) | |
411 | after initialize_all_files. */ | |
412 | if (print_version) | |
413 | { | |
414 | print_gdb_version (gdb_stdout); | |
415 | wrap_here (""); | |
416 | printf_filtered ("\n"); | |
417 | exit (0); | |
418 | } | |
419 | ||
420 | if (print_help) | |
421 | { | |
422 | print_gdb_help (gdb_stdout); | |
423 | fputs_unfiltered ("\n", gdb_stdout); | |
424 | exit (0); | |
425 | } | |
426 | ||
427 | if (!quiet) | |
428 | { | |
429 | /* Print all the junk at the top, with trailing "..." if we are about | |
c5aa993b | 430 | to read a symbol file (possibly slowly). */ |
c906108c SS |
431 | print_gdb_version (gdb_stdout); |
432 | if (symarg) | |
433 | printf_filtered (".."); | |
c5aa993b JM |
434 | wrap_here (""); |
435 | gdb_flush (gdb_stdout); /* Force to screen during slow operations */ | |
c906108c SS |
436 | } |
437 | ||
438 | error_pre_print = "\n\n"; | |
439 | quit_pre_print = error_pre_print; | |
440 | ||
441 | /* We may get more than one warning, don't double space all of them... */ | |
442 | warning_pre_print = "\nwarning: "; | |
443 | ||
444 | /* Read and execute $HOME/.gdbinit file, if it exists. This is done | |
445 | *before* all the command line arguments are processed; it sets | |
446 | global parameters, which are independent of what file you are | |
447 | debugging or what directory you are in. */ | |
448 | #ifdef __CYGWIN32__ | |
449 | { | |
c5aa993b JM |
450 | char *tmp = getenv ("HOME"); |
451 | ||
c906108c SS |
452 | if (tmp != NULL) |
453 | { | |
c5aa993b JM |
454 | homedir = (char *) alloca (MAX_PATH + 1); |
455 | cygwin32_conv_to_posix_path (tmp, homedir); | |
c906108c SS |
456 | } |
457 | else | |
458 | homedir = NULL; | |
459 | } | |
460 | #else | |
c5aa993b | 461 | homedir = getenv ("HOME"); |
c906108c SS |
462 | #endif |
463 | if (homedir) | |
464 | { | |
465 | homeinit = (char *) alloca (strlen (homedir) + | |
466 | strlen (gdbinit) + 10); | |
467 | strcpy (homeinit, homedir); | |
468 | strcat (homeinit, "/"); | |
469 | strcat (homeinit, gdbinit); | |
470 | ||
471 | if (!inhibit_gdbinit) | |
472 | { | |
473 | if (!SET_TOP_LEVEL ()) | |
474 | source_command (homeinit, 0); | |
475 | } | |
476 | do_cleanups (ALL_CLEANUPS); | |
477 | ||
478 | /* Do stats; no need to do them elsewhere since we'll only | |
c5aa993b JM |
479 | need them if homedir is set. Make sure that they are |
480 | zero in case one of them fails (this guarantees that they | |
481 | won't match if either exists). */ | |
482 | ||
c906108c SS |
483 | memset (&homebuf, 0, sizeof (struct stat)); |
484 | memset (&cwdbuf, 0, sizeof (struct stat)); | |
c5aa993b | 485 | |
c906108c | 486 | stat (homeinit, &homebuf); |
c5aa993b JM |
487 | stat (gdbinit, &cwdbuf); /* We'll only need this if |
488 | homedir was set. */ | |
c906108c SS |
489 | } |
490 | ||
491 | /* Now perform all the actions indicated by the arguments. */ | |
492 | if (cdarg != NULL) | |
493 | { | |
494 | if (!SET_TOP_LEVEL ()) | |
495 | { | |
496 | cd_command (cdarg, 0); | |
497 | } | |
498 | } | |
499 | do_cleanups (ALL_CLEANUPS); | |
500 | ||
501 | for (i = 0; i < ndir; i++) | |
502 | if (!SET_TOP_LEVEL ()) | |
503 | directory_command (dirarg[i], 0); | |
c5aa993b | 504 | free ((PTR) dirarg); |
c906108c SS |
505 | do_cleanups (ALL_CLEANUPS); |
506 | ||
507 | if (execarg != NULL | |
508 | && symarg != NULL | |
509 | && STREQ (execarg, symarg)) | |
510 | { | |
511 | /* The exec file and the symbol-file are the same. If we can't open | |
c5aa993b | 512 | it, better only print one error message. */ |
c906108c SS |
513 | if (!SET_TOP_LEVEL ()) |
514 | { | |
515 | exec_file_command (execarg, !batch); | |
516 | symbol_file_command (symarg, 0); | |
517 | } | |
518 | } | |
519 | else | |
520 | { | |
521 | if (execarg != NULL) | |
522 | if (!SET_TOP_LEVEL ()) | |
523 | exec_file_command (execarg, !batch); | |
524 | if (symarg != NULL) | |
525 | if (!SET_TOP_LEVEL ()) | |
526 | symbol_file_command (symarg, 0); | |
527 | } | |
528 | do_cleanups (ALL_CLEANUPS); | |
529 | ||
530 | /* After the symbol file has been read, print a newline to get us | |
531 | beyond the copyright line... But errors should still set off | |
532 | the error message with a (single) blank line. */ | |
533 | if (!quiet) | |
534 | printf_filtered ("\n"); | |
535 | error_pre_print = "\n"; | |
536 | quit_pre_print = error_pre_print; | |
537 | warning_pre_print = "\nwarning: "; | |
538 | ||
539 | if (corearg != NULL) | |
540 | { | |
541 | if (!SET_TOP_LEVEL ()) | |
542 | core_file_command (corearg, !batch); | |
543 | else if (isdigit (corearg[0]) && !SET_TOP_LEVEL ()) | |
544 | attach_command (corearg, !batch); | |
545 | } | |
546 | do_cleanups (ALL_CLEANUPS); | |
547 | ||
548 | if (ttyarg != NULL) | |
549 | if (!SET_TOP_LEVEL ()) | |
550 | tty_command (ttyarg, !batch); | |
551 | do_cleanups (ALL_CLEANUPS); | |
552 | ||
553 | #ifdef ADDITIONAL_OPTION_HANDLER | |
554 | ADDITIONAL_OPTION_HANDLER; | |
555 | #endif | |
556 | ||
557 | /* Error messages should no longer be distinguished with extra output. */ | |
558 | error_pre_print = NULL; | |
559 | quit_pre_print = NULL; | |
560 | warning_pre_print = "warning: "; | |
561 | ||
562 | /* Read the .gdbinit file in the current directory, *if* it isn't | |
563 | the same as the $HOME/.gdbinit file (it should exist, also). */ | |
c5aa993b | 564 | |
c906108c SS |
565 | if (!homedir |
566 | || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat))) | |
567 | if (!inhibit_gdbinit) | |
568 | { | |
569 | if (!SET_TOP_LEVEL ()) | |
570 | source_command (gdbinit, 0); | |
571 | } | |
572 | do_cleanups (ALL_CLEANUPS); | |
573 | ||
574 | for (i = 0; i < ncmd; i++) | |
575 | { | |
576 | if (!SET_TOP_LEVEL ()) | |
577 | { | |
b83266a0 SS |
578 | /* NOTE: I am commenting this out, because it is not clear |
579 | where this feature is used. It is very old and | |
c5aa993b | 580 | undocumented. ezannoni: 1999-05-04 */ |
b83266a0 | 581 | #if 0 |
c906108c SS |
582 | if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0') |
583 | read_command_file (stdin); | |
584 | else | |
b83266a0 | 585 | #endif |
c906108c SS |
586 | source_command (cmdarg[i], !batch); |
587 | do_cleanups (ALL_CLEANUPS); | |
588 | } | |
589 | } | |
c5aa993b | 590 | free ((PTR) cmdarg); |
c906108c SS |
591 | |
592 | /* Read in the old history after all the command files have been read. */ | |
c5aa993b | 593 | init_history (); |
c906108c SS |
594 | |
595 | if (batch) | |
596 | { | |
597 | /* We have hit the end of the batch file. */ | |
598 | exit (0); | |
599 | } | |
600 | ||
601 | /* Do any host- or target-specific hacks. This is used for i960 targets | |
602 | to force the user to set a nindy target and spec its parameters. */ | |
603 | ||
604 | #ifdef BEFORE_MAIN_LOOP_HOOK | |
605 | BEFORE_MAIN_LOOP_HOOK; | |
606 | #endif | |
607 | ||
608 | END_PROGRESS (argv[0]); | |
609 | ||
610 | /* Show time and/or space usage. */ | |
611 | ||
612 | if (display_time) | |
613 | { | |
614 | long init_time = get_run_time () - time_at_startup; | |
615 | ||
616 | printf_unfiltered ("Startup time: %ld.%06ld\n", | |
617 | init_time / 1000000, init_time % 1000000); | |
618 | } | |
619 | ||
620 | if (display_space) | |
621 | { | |
622 | #ifdef HAVE_SBRK | |
623 | extern char **environ; | |
624 | char *lim = (char *) sbrk (0); | |
625 | ||
626 | printf_unfiltered ("Startup size: data size %ld\n", | |
627 | (long) (lim - (char *) &environ)); | |
628 | #endif | |
629 | } | |
630 | ||
631 | /* The default command loop. | |
632 | The WIN32 Gui calls this main to set up gdb's state, and | |
633 | has its own command loop. */ | |
634 | #if !defined _WIN32 || defined __GNUC__ | |
635 | while (1) | |
636 | { | |
637 | if (!SET_TOP_LEVEL ()) | |
638 | { | |
c5aa993b | 639 | do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */ |
c906108c SS |
640 | /* GUIs generally have their own command loop, mainloop, or whatever. |
641 | This is a good place to gain control because many error | |
642 | conditions will end up here via longjmp(). */ | |
643 | if (command_loop_hook) | |
644 | command_loop_hook (); | |
645 | else | |
646 | command_loop (); | |
c5aa993b | 647 | quit_command ((char *) 0, instream == stdin); |
c906108c SS |
648 | } |
649 | } | |
c906108c SS |
650 | /* No exit -- exit is through quit_command. */ |
651 | #endif | |
652 | ||
653 | } | |
654 | ||
655 | /* Don't use *_filtered for printing help. We don't want to prompt | |
656 | for continue no matter how small the screen or how much we're going | |
657 | to print. */ | |
658 | ||
659 | static void | |
660 | print_gdb_help (stream) | |
c5aa993b | 661 | GDB_FILE *stream; |
c906108c | 662 | { |
c5aa993b | 663 | fputs_unfiltered ("\ |
c906108c SS |
664 | This is the GNU debugger. Usage:\n\n\ |
665 | gdb [options] [executable-file [core-file or process-id]]\n\n\ | |
666 | Options:\n\n\ | |
0f71a2f6 | 667 | ", stream); |
c5aa993b | 668 | fputs_unfiltered ("\ |
0f71a2f6 | 669 | --[no]async Enable (disable) asynchronous version of CLI\n\ |
c906108c | 670 | ", stream); |
c5aa993b | 671 | fputs_unfiltered ("\ |
c906108c SS |
672 | -b BAUDRATE Set serial port baud rate used for remote debugging.\n\ |
673 | --batch Exit after processing options.\n\ | |
674 | --cd=DIR Change current directory to DIR.\n\ | |
675 | --command=FILE Execute GDB commands from FILE.\n\ | |
676 | --core=COREFILE Analyze the core dump COREFILE.\n\ | |
677 | ", stream); | |
c5aa993b | 678 | fputs_unfiltered ("\ |
c906108c SS |
679 | --dbx DBX compatibility mode.\n\ |
680 | --directory=DIR Search for source files in DIR.\n\ | |
681 | --epoch Output information used by epoch emacs-GDB interface.\n\ | |
682 | --exec=EXECFILE Use EXECFILE as the executable.\n\ | |
683 | --fullname Output information used by emacs-GDB interface.\n\ | |
684 | --help Print this message.\n\ | |
685 | ", stream); | |
c5aa993b | 686 | fputs_unfiltered ("\ |
c906108c SS |
687 | --mapped Use mapped symbol files if supported on this system.\n\ |
688 | --nw Do not use a window interface.\n\ | |
96baa820 JM |
689 | --nx Do not read ", stream); |
690 | fputs_unfiltered (gdbinit, stream); | |
691 | fputs_unfiltered (" file.\n\ | |
c906108c SS |
692 | --quiet Do not print version number on startup.\n\ |
693 | --readnow Fully read symbol files on first access.\n\ | |
694 | ", stream); | |
c5aa993b | 695 | fputs_unfiltered ("\ |
c906108c SS |
696 | --se=FILE Use FILE as symbol file and executable file.\n\ |
697 | --symbols=SYMFILE Read symbols from SYMFILE.\n\ | |
698 | --tty=TTY Use TTY for input/output by the program being debugged.\n\ | |
699 | ", stream); | |
700 | #if defined(TUI) | |
c5aa993b | 701 | fputs_unfiltered ("\ |
c906108c SS |
702 | --tui Use a terminal user interface.\n\ |
703 | ", stream); | |
704 | #endif | |
c5aa993b | 705 | fputs_unfiltered ("\ |
c906108c SS |
706 | --version Print version information and then exit.\n\ |
707 | -w Use a window interface.\n\ | |
708 | --write Set writing into executable and core files.\n\ | |
709 | --xdb XDB compatibility mode.\n\ | |
710 | ", stream); | |
711 | #ifdef ADDITIONAL_OPTION_HELP | |
c5aa993b | 712 | fputs_unfiltered (ADDITIONAL_OPTION_HELP, stream); |
c906108c | 713 | #endif |
c5aa993b | 714 | fputs_unfiltered ("\n\ |
c906108c SS |
715 | For more information, type \"help\" from within GDB, or consult the\n\ |
716 | GDB manual (available as on-line info or a printed manual).\n\ | |
717 | Report bugs to \"bug-gdb@prep.ai.mit.edu\".\ | |
718 | ", stream); | |
719 | } |