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