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