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