]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Top level stuff for GDB, the GNU debugger. |
2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 | |
3 | Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "defs.h" | |
c906108c | 22 | #include "top.h" |
392a587b | 23 | #include "event-loop.h" |
c906108c SS |
24 | #include "target.h" |
25 | #include "inferior.h" | |
26 | #include "call-cmds.h" | |
7a292a7a SS |
27 | #ifdef HAVE_UNISTD_H |
28 | #include <unistd.h> | |
29 | #endif | |
c906108c SS |
30 | |
31 | #include "getopt.h" | |
32 | ||
33 | #include <sys/types.h> | |
34 | #include "gdb_stat.h" | |
35 | #include <ctype.h> | |
36 | ||
37 | #include "gdb_string.h" | |
38 | ||
c906108c SS |
39 | /* If nonzero, display time usage both at startup and for each command. */ |
40 | ||
41 | int display_time; | |
42 | ||
43 | /* If nonzero, display space usage both at startup and for each command. */ | |
44 | ||
45 | int display_space; | |
46 | ||
cd0fc7c3 SS |
47 | /* Whether this is the async version or not. The async version is |
48 | invoked on the command line with the -nw --async options. In this | |
49 | version, the usual command_loop is substituted by and event loop which | |
50 | processes UI events asynchronously. */ | |
0f71a2f6 | 51 | int async_p = 0; |
cd0fc7c3 | 52 | |
c906108c SS |
53 | /* Whether this is the command line version or not */ |
54 | int tui_version = 0; | |
55 | ||
56 | /* Whether xdb commands will be handled */ | |
57 | int xdb_commands = 0; | |
58 | ||
59 | /* Whether dbx commands will be handled */ | |
60 | int dbx_commands = 0; | |
61 | ||
62 | GDB_FILE *gdb_stdout; | |
63 | GDB_FILE *gdb_stderr; | |
0f71a2f6 | 64 | GDB_FILE *gdb_stdlog; |
c906108c SS |
65 | |
66 | /* Whether to enable writing into executable and core files */ | |
67 | extern int write_files; | |
68 | ||
69 | static void print_gdb_help PARAMS ((GDB_FILE *)); | |
c906108c SS |
70 | |
71 | /* These two are used to set the external editor commands when gdb is farming | |
72 | out files to be edited by another program. */ | |
73 | ||
74 | extern int enable_external_editor; | |
75 | extern char * external_editor_command; | |
76 | ||
77 | #ifdef __CYGWIN__ | |
78 | #include <windows.h> /* for MAX_PATH */ | |
79 | #include <sys/cygwin.h> /* for cygwin32_conv_to_posix_path */ | |
80 | #endif | |
81 | ||
82 | int | |
83 | main (argc, argv) | |
84 | int argc; | |
85 | char **argv; | |
86 | { | |
87 | int count; | |
88 | static int quiet = 0; | |
89 | static int batch = 0; | |
90 | ||
91 | /* Pointers to various arguments from command line. */ | |
92 | char *symarg = NULL; | |
93 | char *execarg = NULL; | |
94 | char *corearg = NULL; | |
95 | char *cdarg = NULL; | |
96 | char *ttyarg = NULL; | |
97 | ||
98 | /* These are static so that we can take their address in an initializer. */ | |
99 | static int print_help; | |
100 | static int print_version; | |
101 | ||
102 | /* Pointers to all arguments of --command option. */ | |
103 | char **cmdarg; | |
104 | /* Allocated size of cmdarg. */ | |
105 | int cmdsize; | |
106 | /* Number of elements of cmdarg used. */ | |
107 | int ncmd; | |
108 | ||
109 | /* Indices of all arguments of --directory option. */ | |
110 | char **dirarg; | |
111 | /* Allocated size. */ | |
112 | int dirsize; | |
113 | /* Number of elements used. */ | |
114 | int ndir; | |
115 | ||
116 | struct stat homebuf, cwdbuf; | |
117 | char *homedir, *homeinit; | |
118 | ||
119 | register int i; | |
120 | ||
121 | long time_at_startup = get_run_time (); | |
122 | ||
123 | int gdb_file_size; | |
124 | ||
125 | START_PROGRESS (argv[0], 0); | |
126 | ||
127 | #ifdef MPW | |
128 | /* Do all Mac-specific setup. */ | |
129 | mac_init (); | |
130 | #endif /* MPW */ | |
131 | ||
132 | /* This needs to happen before the first use of malloc. */ | |
133 | init_malloc ((PTR) NULL); | |
134 | ||
135 | #if defined (ALIGN_STACK_ON_STARTUP) | |
136 | i = (int) &count & 0x3; | |
137 | if (i != 0) | |
138 | alloca (4 - i); | |
139 | #endif | |
140 | ||
141 | /* If error() is called from initialization code, just exit */ | |
142 | if (SET_TOP_LEVEL ()) { | |
143 | exit(1); | |
144 | } | |
145 | ||
146 | cmdsize = 1; | |
147 | cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg)); | |
148 | ncmd = 0; | |
149 | dirsize = 1; | |
150 | dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg)); | |
151 | ndir = 0; | |
152 | ||
153 | quit_flag = 0; | |
154 | line = (char *) xmalloc (linesize); | |
155 | line[0] = '\0'; /* Terminate saved (now empty) cmd line */ | |
156 | instream = stdin; | |
157 | ||
158 | getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); | |
159 | current_directory = gdb_dirbuf; | |
160 | ||
ac9a91a7 JM |
161 | #if 0 |
162 | /* not yet */ | |
163 | gdb_stdout = stdio_fileopen (stdout); | |
164 | gdb_stderr = stdio_fileopen (stderr); | |
0f71a2f6 | 165 | gdb_stdlog = gdb_stderr; /* for moment */ |
ac9a91a7 JM |
166 | #else |
167 | gdb_stdout = tui_fileopen (stdout); | |
168 | gdb_stderr = tui_fileopen (stderr); | |
0f71a2f6 | 169 | gdb_stdlog = gdb_stdout; /* 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[] = | |
cd0fc7c3 | 179 | { |
0f71a2f6 JM |
180 | {"async", no_argument, &async_p, 1}, |
181 | {"noasync", no_argument, &async_p, 0}, | |
c906108c SS |
182 | #if defined(TUI) |
183 | {"tui", no_argument, &tui_version, 1}, | |
184 | #endif | |
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}, | |
228 | /* Allow machine descriptions to add more options... */ | |
229 | #ifdef ADDITIONAL_OPTIONS | |
230 | ADDITIONAL_OPTIONS | |
231 | #endif | |
232 | {0, no_argument, 0, 0} | |
233 | }; | |
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; | |
288 | cmdarg = (char **) xrealloc ((char *)cmdarg, | |
289 | cmdsize * sizeof (*cmdarg)); | |
290 | } | |
291 | break; | |
292 | case 'd': | |
293 | dirarg[ndir++] = optarg; | |
294 | if (ndir >= dirsize) | |
295 | { | |
296 | dirsize *= 2; | |
297 | dirarg = (char **) xrealloc ((char *)dirarg, | |
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 | |
316 | current_target) until after initialize_all_files(). */ | |
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 | |
333 | current_target) until after initialize_all_files(). */ | |
334 | ||
335 | fprintf_unfiltered | |
336 | (gdb_stderr, | |
337 | "warning: could not set timeout limit to `%s'.\n", optarg); | |
338 | else | |
339 | remote_timeout = i; | |
340 | } | |
341 | break; | |
342 | ||
343 | #ifdef ADDITIONAL_OPTION_CASES | |
344 | ADDITIONAL_OPTION_CASES | |
345 | #endif | |
346 | case '?': | |
347 | fprintf_unfiltered (gdb_stderr, | |
348 | "Use `%s --help' for a complete list of options.\n", | |
349 | argv[0]); | |
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; | |
369 | #endif | |
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, | |
385 | "Excess command line arguments ignored. (%s%s)\n", | |
386 | argv[optind], (optind == argc - 1) ? "" : " ..."); | |
387 | break; | |
388 | } | |
389 | if (batch) | |
390 | quiet = 1; | |
391 | } | |
392 | ||
cd0fc7c3 SS |
393 | /* Get ready to invoke the event loop instead of the |
394 | command_loop. See event-loop.h for more details.*/ | |
0f71a2f6 JM |
395 | if (async_p) |
396 | command_loop_hook = start_event_loop; | |
c906108c | 397 | #if defined(TUI) |
0f71a2f6 | 398 | /* Should this be moved to tui-top.c:_initialize_tui()? */ |
c906108c SS |
399 | if (tui_version) |
400 | init_ui_hook = tuiInit; | |
401 | #endif | |
0f71a2f6 JM |
402 | |
403 | /* Initialize all files. Give the interpreter a chance to take | |
404 | control of the console via the init_ui_hook()) */ | |
c906108c SS |
405 | gdb_init (argv[0]); |
406 | ||
407 | /* Do these (and anything which might call wrap_here or *_filtered) | |
408 | after initialize_all_files. */ | |
409 | if (print_version) | |
410 | { | |
411 | print_gdb_version (gdb_stdout); | |
412 | wrap_here (""); | |
413 | printf_filtered ("\n"); | |
414 | exit (0); | |
415 | } | |
416 | ||
417 | if (print_help) | |
418 | { | |
419 | print_gdb_help (gdb_stdout); | |
420 | fputs_unfiltered ("\n", gdb_stdout); | |
421 | exit (0); | |
422 | } | |
423 | ||
424 | if (!quiet) | |
425 | { | |
426 | /* Print all the junk at the top, with trailing "..." if we are about | |
427 | to read a symbol file (possibly slowly). */ | |
428 | print_gdb_version (gdb_stdout); | |
429 | if (symarg) | |
430 | printf_filtered (".."); | |
431 | wrap_here(""); | |
432 | gdb_flush (gdb_stdout); /* Force to screen during slow operations */ | |
433 | } | |
434 | ||
435 | error_pre_print = "\n\n"; | |
436 | quit_pre_print = error_pre_print; | |
437 | ||
438 | /* We may get more than one warning, don't double space all of them... */ | |
439 | warning_pre_print = "\nwarning: "; | |
440 | ||
441 | /* Read and execute $HOME/.gdbinit file, if it exists. This is done | |
442 | *before* all the command line arguments are processed; it sets | |
443 | global parameters, which are independent of what file you are | |
444 | debugging or what directory you are in. */ | |
445 | #ifdef __CYGWIN32__ | |
446 | { | |
447 | char * tmp = getenv ("HOME"); | |
448 | ||
449 | if (tmp != NULL) | |
450 | { | |
451 | homedir = (char *) alloca (MAX_PATH+1); | |
452 | cygwin32_conv_to_posix_path (tmp, homedir); | |
453 | } | |
454 | else | |
455 | homedir = NULL; | |
456 | } | |
457 | #else | |
458 | homedir = getenv ("HOME"); | |
459 | #endif | |
460 | if (homedir) | |
461 | { | |
462 | homeinit = (char *) alloca (strlen (homedir) + | |
463 | strlen (gdbinit) + 10); | |
464 | strcpy (homeinit, homedir); | |
465 | strcat (homeinit, "/"); | |
466 | strcat (homeinit, gdbinit); | |
467 | ||
468 | if (!inhibit_gdbinit) | |
469 | { | |
470 | if (!SET_TOP_LEVEL ()) | |
471 | source_command (homeinit, 0); | |
472 | } | |
473 | do_cleanups (ALL_CLEANUPS); | |
474 | ||
475 | /* Do stats; no need to do them elsewhere since we'll only | |
476 | need them if homedir is set. Make sure that they are | |
477 | zero in case one of them fails (this guarantees that they | |
478 | won't match if either exists). */ | |
479 | ||
480 | memset (&homebuf, 0, sizeof (struct stat)); | |
481 | memset (&cwdbuf, 0, sizeof (struct stat)); | |
482 | ||
483 | stat (homeinit, &homebuf); | |
484 | stat (gdbinit, &cwdbuf); /* We'll only need this if | |
485 | homedir was set. */ | |
486 | } | |
487 | ||
488 | /* Now perform all the actions indicated by the arguments. */ | |
489 | if (cdarg != NULL) | |
490 | { | |
491 | if (!SET_TOP_LEVEL ()) | |
492 | { | |
493 | cd_command (cdarg, 0); | |
494 | } | |
495 | } | |
496 | do_cleanups (ALL_CLEANUPS); | |
497 | ||
498 | for (i = 0; i < ndir; i++) | |
499 | if (!SET_TOP_LEVEL ()) | |
500 | directory_command (dirarg[i], 0); | |
501 | free ((PTR)dirarg); | |
502 | do_cleanups (ALL_CLEANUPS); | |
503 | ||
504 | if (execarg != NULL | |
505 | && symarg != NULL | |
506 | && STREQ (execarg, symarg)) | |
507 | { | |
508 | /* The exec file and the symbol-file are the same. If we can't open | |
509 | it, better only print one error message. */ | |
510 | if (!SET_TOP_LEVEL ()) | |
511 | { | |
512 | exec_file_command (execarg, !batch); | |
513 | symbol_file_command (symarg, 0); | |
514 | } | |
515 | } | |
516 | else | |
517 | { | |
518 | if (execarg != NULL) | |
519 | if (!SET_TOP_LEVEL ()) | |
520 | exec_file_command (execarg, !batch); | |
521 | if (symarg != NULL) | |
522 | if (!SET_TOP_LEVEL ()) | |
523 | symbol_file_command (symarg, 0); | |
524 | } | |
525 | do_cleanups (ALL_CLEANUPS); | |
526 | ||
527 | /* After the symbol file has been read, print a newline to get us | |
528 | beyond the copyright line... But errors should still set off | |
529 | the error message with a (single) blank line. */ | |
530 | if (!quiet) | |
531 | printf_filtered ("\n"); | |
532 | error_pre_print = "\n"; | |
533 | quit_pre_print = error_pre_print; | |
534 | warning_pre_print = "\nwarning: "; | |
535 | ||
536 | if (corearg != NULL) | |
537 | { | |
538 | if (!SET_TOP_LEVEL ()) | |
539 | core_file_command (corearg, !batch); | |
540 | else if (isdigit (corearg[0]) && !SET_TOP_LEVEL ()) | |
541 | attach_command (corearg, !batch); | |
542 | } | |
543 | do_cleanups (ALL_CLEANUPS); | |
544 | ||
545 | if (ttyarg != NULL) | |
546 | if (!SET_TOP_LEVEL ()) | |
547 | tty_command (ttyarg, !batch); | |
548 | do_cleanups (ALL_CLEANUPS); | |
549 | ||
550 | #ifdef ADDITIONAL_OPTION_HANDLER | |
551 | ADDITIONAL_OPTION_HANDLER; | |
552 | #endif | |
553 | ||
554 | /* Error messages should no longer be distinguished with extra output. */ | |
555 | error_pre_print = NULL; | |
556 | quit_pre_print = NULL; | |
557 | warning_pre_print = "warning: "; | |
558 | ||
559 | /* Read the .gdbinit file in the current directory, *if* it isn't | |
560 | the same as the $HOME/.gdbinit file (it should exist, also). */ | |
561 | ||
562 | if (!homedir | |
563 | || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat))) | |
564 | if (!inhibit_gdbinit) | |
565 | { | |
566 | if (!SET_TOP_LEVEL ()) | |
567 | source_command (gdbinit, 0); | |
568 | } | |
569 | do_cleanups (ALL_CLEANUPS); | |
570 | ||
571 | for (i = 0; i < ncmd; i++) | |
572 | { | |
573 | if (!SET_TOP_LEVEL ()) | |
574 | { | |
b83266a0 SS |
575 | /* NOTE: I am commenting this out, because it is not clear |
576 | where this feature is used. It is very old and | |
392a587b | 577 | undocumented. ezannoni: 1999-05-04*/ |
b83266a0 | 578 | #if 0 |
c906108c SS |
579 | if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0') |
580 | read_command_file (stdin); | |
581 | else | |
b83266a0 | 582 | #endif |
c906108c SS |
583 | source_command (cmdarg[i], !batch); |
584 | do_cleanups (ALL_CLEANUPS); | |
585 | } | |
586 | } | |
587 | free ((PTR)cmdarg); | |
588 | ||
589 | /* Read in the old history after all the command files have been read. */ | |
590 | init_history(); | |
591 | ||
592 | if (batch) | |
593 | { | |
594 | /* We have hit the end of the batch file. */ | |
595 | exit (0); | |
596 | } | |
597 | ||
598 | /* Do any host- or target-specific hacks. This is used for i960 targets | |
599 | to force the user to set a nindy target and spec its parameters. */ | |
600 | ||
601 | #ifdef BEFORE_MAIN_LOOP_HOOK | |
602 | BEFORE_MAIN_LOOP_HOOK; | |
603 | #endif | |
604 | ||
605 | END_PROGRESS (argv[0]); | |
606 | ||
607 | /* Show time and/or space usage. */ | |
608 | ||
609 | if (display_time) | |
610 | { | |
611 | long init_time = get_run_time () - time_at_startup; | |
612 | ||
613 | printf_unfiltered ("Startup time: %ld.%06ld\n", | |
614 | init_time / 1000000, init_time % 1000000); | |
615 | } | |
616 | ||
617 | if (display_space) | |
618 | { | |
619 | #ifdef HAVE_SBRK | |
620 | extern char **environ; | |
621 | char *lim = (char *) sbrk (0); | |
622 | ||
623 | printf_unfiltered ("Startup size: data size %ld\n", | |
624 | (long) (lim - (char *) &environ)); | |
625 | #endif | |
626 | } | |
627 | ||
628 | /* The default command loop. | |
629 | The WIN32 Gui calls this main to set up gdb's state, and | |
630 | has its own command loop. */ | |
631 | #if !defined _WIN32 || defined __GNUC__ | |
632 | while (1) | |
633 | { | |
634 | if (!SET_TOP_LEVEL ()) | |
635 | { | |
636 | do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */ | |
637 | /* GUIs generally have their own command loop, mainloop, or whatever. | |
638 | This is a good place to gain control because many error | |
639 | conditions will end up here via longjmp(). */ | |
640 | if (command_loop_hook) | |
641 | command_loop_hook (); | |
642 | else | |
643 | command_loop (); | |
644 | quit_command ((char *)0, instream == stdin); | |
645 | } | |
646 | } | |
c906108c SS |
647 | /* No exit -- exit is through quit_command. */ |
648 | #endif | |
649 | ||
650 | } | |
651 | ||
652 | /* Don't use *_filtered for printing help. We don't want to prompt | |
653 | for continue no matter how small the screen or how much we're going | |
654 | to print. */ | |
655 | ||
656 | static void | |
657 | print_gdb_help (stream) | |
658 | GDB_FILE *stream; | |
659 | { | |
660 | fputs_unfiltered ("\ | |
661 | This is the GNU debugger. Usage:\n\n\ | |
662 | gdb [options] [executable-file [core-file or process-id]]\n\n\ | |
663 | Options:\n\n\ | |
0f71a2f6 JM |
664 | ", stream); |
665 | fputs_unfiltered ("\ | |
666 | --[no]async Enable (disable) asynchronous version of CLI\n\ | |
c906108c SS |
667 | ", stream); |
668 | fputs_unfiltered ("\ | |
669 | -b BAUDRATE Set serial port baud rate used for remote debugging.\n\ | |
670 | --batch Exit after processing options.\n\ | |
671 | --cd=DIR Change current directory to DIR.\n\ | |
672 | --command=FILE Execute GDB commands from FILE.\n\ | |
673 | --core=COREFILE Analyze the core dump COREFILE.\n\ | |
674 | ", stream); | |
675 | fputs_unfiltered ("\ | |
676 | --dbx DBX compatibility mode.\n\ | |
677 | --directory=DIR Search for source files in DIR.\n\ | |
678 | --epoch Output information used by epoch emacs-GDB interface.\n\ | |
679 | --exec=EXECFILE Use EXECFILE as the executable.\n\ | |
680 | --fullname Output information used by emacs-GDB interface.\n\ | |
681 | --help Print this message.\n\ | |
682 | ", stream); | |
683 | fputs_unfiltered ("\ | |
684 | --mapped Use mapped symbol files if supported on this system.\n\ | |
685 | --nw Do not use a window interface.\n\ | |
686 | --nx Do not read .gdbinit file.\n\ | |
687 | --quiet Do not print version number on startup.\n\ | |
688 | --readnow Fully read symbol files on first access.\n\ | |
689 | ", stream); | |
690 | fputs_unfiltered ("\ | |
691 | --se=FILE Use FILE as symbol file and executable file.\n\ | |
692 | --symbols=SYMFILE Read symbols from SYMFILE.\n\ | |
693 | --tty=TTY Use TTY for input/output by the program being debugged.\n\ | |
694 | ", stream); | |
695 | #if defined(TUI) | |
696 | fputs_unfiltered ("\ | |
697 | --tui Use a terminal user interface.\n\ | |
698 | ", stream); | |
699 | #endif | |
700 | fputs_unfiltered ("\ | |
701 | --version Print version information and then exit.\n\ | |
702 | -w Use a window interface.\n\ | |
703 | --write Set writing into executable and core files.\n\ | |
704 | --xdb XDB compatibility mode.\n\ | |
705 | ", stream); | |
706 | #ifdef ADDITIONAL_OPTION_HELP | |
707 | fputs_unfiltered (ADDITIONAL_OPTION_HELP, stream); | |
708 | #endif | |
709 | fputs_unfiltered ("\n\ | |
710 | For more information, type \"help\" from within GDB, or consult the\n\ | |
711 | GDB manual (available as on-line info or a printed manual).\n\ | |
712 | Report bugs to \"[email protected]\".\ | |
713 | ", stream); | |
714 | } | |
715 | ||
716 | \f | |
ac9a91a7 JM |
717 | /* All TUI I/O sent to the *_filtered and *_unfiltered functions |
718 | eventually ends up here. The fputs_unfiltered_hook is primarily | |
719 | used by GUIs to collect all output and send it to the GUI, instead | |
720 | of the controlling terminal. Only output to gdb_stdout and | |
721 | gdb_stderr are sent to the hook. Everything else is sent on to | |
722 | fputs to allow file I/O to be handled appropriately. */ | |
723 | ||
724 | /* FIXME: Should be broken up and moved to a TUI specific file. */ | |
c906108c SS |
725 | |
726 | void | |
ac9a91a7 | 727 | tui_file_fputs (linebuffer, file) |
c906108c | 728 | const char *linebuffer; |
ac9a91a7 | 729 | GDB_FILE *file; |
c906108c | 730 | { |
ac9a91a7 | 731 | struct tui_stream *stream = gdb_file_data (file); |
c906108c SS |
732 | #if defined(TUI) |
733 | extern int tui_owns_terminal; | |
734 | #endif | |
735 | /* If anything (GUI, TUI) wants to capture GDB output, this is | |
736 | * the place... the way to do it is to set up | |
737 | * fputs_unfiltered_hook. | |
738 | * Our TUI ("gdb -tui") used to hook output, but in the | |
739 | * new (XDB style) scheme, we do not do that anymore... - RT | |
740 | */ | |
741 | if (fputs_unfiltered_hook | |
ac9a91a7 JM |
742 | && (file == gdb_stdout |
743 | || file == gdb_stderr)) | |
744 | fputs_unfiltered_hook (linebuffer, file); | |
c906108c SS |
745 | else |
746 | { | |
747 | #if defined(TUI) | |
748 | if (tui_version && tui_owns_terminal) { | |
749 | /* If we get here somehow while updating the TUI (from | |
750 | * within a tuiDo(), then we need to temporarily | |
751 | * set up the terminal for GDB output. This probably just | |
752 | * happens on error output. | |
753 | */ | |
754 | ||
755 | if (stream->ts_streamtype == astring) { | |
756 | gdb_file_adjust_strbuf(strlen(linebuffer), stream); | |
757 | strcat(stream->ts_strbuf, linebuffer); | |
758 | } else { | |
759 | tuiTermUnsetup(0, (tui_version) ? cmdWin->detail.commandInfo.curch : 0); | |
760 | fputs (linebuffer, stream->ts_filestream); | |
761 | tuiTermSetup(0); | |
762 | if (linebuffer[strlen(linebuffer) - 1] == '\n') | |
763 | tuiClearCommandCharCount(); | |
764 | else | |
765 | tuiIncrCommandCharCountBy(strlen(linebuffer)); | |
766 | } | |
767 | } else { | |
768 | /* The normal case - just do a fputs() */ | |
769 | if (stream->ts_streamtype == astring) { | |
770 | gdb_file_adjust_strbuf(strlen(linebuffer), stream); | |
771 | strcat(stream->ts_strbuf, linebuffer); | |
772 | } else fputs (linebuffer, stream->ts_filestream); | |
773 | } | |
774 | ||
775 | ||
776 | #else | |
777 | if (stream->ts_streamtype == astring) { | |
ac9a91a7 | 778 | gdb_file_adjust_strbuf(strlen(linebuffer), file); |
c906108c SS |
779 | strcat(stream->ts_strbuf, linebuffer); |
780 | } else fputs (linebuffer, stream->ts_filestream); | |
781 | #endif | |
782 | } | |
783 | } |