1999-01-19 Fernando Nasser <fnasser@totem.to.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / main.c
CommitLineData
b8ec8d4a 1/* Top level stuff for GDB, the GNU debugger.
1a494973 2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
51b57ded 3 Free Software Foundation, Inc.
bd5635a1
RP
4
5This file is part of GDB.
6
e522fb52 7This program is free software; you can redistribute it and/or modify
bd5635a1 8it under the terms of the GNU General Public License as published by
e522fb52
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
bd5635a1 11
e522fb52 12This program is distributed in the hope that it will be useful,
bd5635a1
RP
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
e522fb52 18along with this program; if not, write to the Free Software
b52cac6b 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
bd5635a1 20
bd5635a1 21#include "defs.h"
b8ec8d4a
SS
22#include <setjmp.h>
23#include "top.h"
bd5635a1 24#include "target.h"
844750e3
SS
25#include "inferior.h"
26#include "call-cmds.h"
bd5635a1 27
e522fb52
JG
28#include "getopt.h"
29
bd5635a1 30#include <sys/types.h>
2b576293 31#include "gdb_stat.h"
844750e3 32#include <ctype.h>
b8ec8d4a 33
2b576293 34#include "gdb_string.h"
bd5635a1 35
9748446f 36/* Temporary variable for SET_TOP_LEVEL. */
86db943c 37
9748446f
JK
38static int top_level_val;
39
40/* Do a setjmp on error_return and quit_return. catch_errors is
41 generally a cleaner way to do this, but main() would look pretty
42 ugly if it had to use catch_errors each time. */
43
44#define SET_TOP_LEVEL() \
47792960
KS
45 (((top_level_val = SIGSETJMP (error_return)) \
46 ? (PTR) 0 : (PTR) memcpy (quit_return, error_return, sizeof (SIGJMP_BUF))) \
9748446f
JK
47 , top_level_val)
48
86db943c
SG
49/* If nonzero, display time usage both at startup and for each command. */
50
51int display_time;
52
53/* If nonzero, display space usage both at startup and for each command. */
54
55int display_space;
56
65b07ddc
DT
57/* Whether this is the command line version or not */
58int tui_version = 0;
59
4ef1f467
DT
60/* Whether xdb commands will be handled */
61int xdb_commands = 0;
62
63/* Whether dbx commands will be handled */
64int dbx_commands = 0;
65
65b07ddc
DT
66GDB_FILE *gdb_stdout;
67GDB_FILE *gdb_stderr;
68
47792960
KS
69static void print_gdb_help PARAMS ((GDB_FILE *));
70extern void gdb_init PARAMS ((char *));
d836385e 71#ifdef __CYGWIN__
47792960 72#include <windows.h> /* for MAX_PATH */
4ef1f467 73#include <sys/cygwin.h> /* for cygwin32_conv_to_posix_path */
47792960 74#endif
844750e3 75
bd5635a1
RP
76int
77main (argc, argv)
78 int argc;
79 char **argv;
80{
81 int count;
bd5635a1
RP
82 static int quiet = 0;
83 static int batch = 0;
84
85 /* Pointers to various arguments from command line. */
86 char *symarg = NULL;
87 char *execarg = NULL;
88 char *corearg = NULL;
89 char *cdarg = NULL;
90 char *ttyarg = NULL;
91
c307bb11
JK
92 /* These are static so that we can take their address in an initializer. */
93 static int print_help;
94 static int print_version;
95
96 /* Pointers to all arguments of --command option. */
bd5635a1
RP
97 char **cmdarg;
98 /* Allocated size of cmdarg. */
99 int cmdsize;
100 /* Number of elements of cmdarg used. */
101 int ncmd;
102
c307bb11 103 /* Indices of all arguments of --directory option. */
bd5635a1
RP
104 char **dirarg;
105 /* Allocated size. */
106 int dirsize;
107 /* Number of elements used. */
108 int ndir;
109
3a16d640
JG
110 struct stat homebuf, cwdbuf;
111 char *homedir, *homeinit;
112
bd5635a1
RP
113 register int i;
114
86db943c
SG
115 long time_at_startup = get_run_time ();
116
65b07ddc
DT
117 int gdb_file_size;
118
1a494973
C
119 START_PROGRESS (argv[0], 0);
120
a6b26c44 121#ifdef MPW
b8ec8d4a
SS
122 /* Do all Mac-specific setup. */
123 mac_init ();
a6b26c44 124#endif /* MPW */
1a494973 125
bd5635a1 126 /* This needs to happen before the first use of malloc. */
318bf84f 127 init_malloc ((PTR) NULL);
bd5635a1
RP
128
129#if defined (ALIGN_STACK_ON_STARTUP)
130 i = (int) &count & 0x3;
131 if (i != 0)
132 alloca (4 - i);
133#endif
134
bd099407 135 /* If error() is called from initialization code, just exit */
9748446f 136 if (SET_TOP_LEVEL ()) {
bd099407
JG
137 exit(1);
138 }
139
bd5635a1
RP
140 cmdsize = 1;
141 cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg));
142 ncmd = 0;
143 dirsize = 1;
144 dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
145 ndir = 0;
146
147 quit_flag = 0;
148 line = (char *) xmalloc (linesize);
149 line[0] = '\0'; /* Terminate saved (now empty) cmd line */
150 instream = stdin;
151
b7ec5b8d
FF
152 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
153 current_directory = gdb_dirbuf;
bd5635a1 154
65b07ddc
DT
155 gdb_file_size = sizeof(GDB_FILE);
156
157 gdb_stdout = (GDB_FILE *)xmalloc (gdb_file_size);
158 gdb_stdout->ts_streamtype = afile;
159 gdb_stdout->ts_filestream = stdout;
160 gdb_stdout->ts_strbuf = NULL;
161 gdb_stdout->ts_buflen = 0;
162
163 gdb_stderr = (GDB_FILE *)xmalloc (gdb_file_size);
164 gdb_stderr->ts_streamtype = afile;
165 gdb_stderr->ts_filestream = stderr;
166 gdb_stderr->ts_strbuf = NULL;
167 gdb_stderr->ts_buflen = 0;
168
bd5635a1
RP
169 /* Parse arguments and options. */
170 {
171 int c;
bd5635a1
RP
172 /* When var field is 0, use flag field to record the equivalent
173 short option (or arbitrary numbers starting at 10 for those
174 with no equivalent). */
175 static struct option long_options[] =
176 {
65b07ddc
DT
177#if defined(TUI)
178 {"tui", no_argument, &tui_version, 1},
179#endif
180 {"xdb", no_argument, &xdb_commands, 1},
181 {"dbx", no_argument, &dbx_commands, 1},
318bf84f
FF
182 {"readnow", no_argument, &readnow_symbol_files, 1},
183 {"r", no_argument, &readnow_symbol_files, 1},
184 {"mapped", no_argument, &mapped_symbol_files, 1},
185 {"m", no_argument, &mapped_symbol_files, 1},
ee0613d1
JG
186 {"quiet", no_argument, &quiet, 1},
187 {"q", no_argument, &quiet, 1},
fb29d681 188 {"silent", no_argument, &quiet, 1},
ee0613d1
JG
189 {"nx", no_argument, &inhibit_gdbinit, 1},
190 {"n", no_argument, &inhibit_gdbinit, 1},
191 {"batch", no_argument, &batch, 1},
192 {"epoch", no_argument, &epoch_interface, 1},
6c803036
JK
193
194 /* This is a synonym for "--annotate=1". --annotate is now preferred,
195 but keep this here for a long time because people will be running
196 emacses which use --fullname. */
197 {"fullname", no_argument, 0, 'f'},
198 {"f", no_argument, 0, 'f'},
199
200 {"annotate", required_argument, 0, 12},
ee0613d1
JG
201 {"help", no_argument, &print_help, 1},
202 {"se", required_argument, 0, 10},
203 {"symbols", required_argument, 0, 's'},
204 {"s", required_argument, 0, 's'},
205 {"exec", required_argument, 0, 'e'},
206 {"e", required_argument, 0, 'e'},
207 {"core", required_argument, 0, 'c'},
208 {"c", required_argument, 0, 'c'},
209 {"command", required_argument, 0, 'x'},
c307bb11 210 {"version", no_argument, &print_version, 1},
ee0613d1 211 {"x", required_argument, 0, 'x'},
7f6cb62e 212/* start-sanitize-gdbtk */
d836385e 213#ifdef GDBTK
7f6cb62e 214 {"tclcommand", required_argument, 0, 'z'},
d836385e 215#endif
7f6cb62e 216/* end-sanitize-gdbtk */
ee0613d1
JG
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'},
86db943c
SG
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},
bd5635a1
RP
227/* Allow machine descriptions to add more options... */
228#ifdef ADDITIONAL_OPTIONS
229 ADDITIONAL_OPTIONS
230#endif
86db943c 231 {0, no_argument, 0, 0}
bd5635a1
RP
232 };
233
234 while (1)
235 {
ee0613d1
JG
236 int option_index;
237
bd5635a1
RP
238 c = getopt_long_only (argc, argv, "",
239 long_options, &option_index);
240 if (c == EOF)
241 break;
242
243 /* Long option that takes an argument. */
244 if (c == 0 && long_options[option_index].flag == 0)
245 c = long_options[option_index].val;
246
247 switch (c)
248 {
249 case 0:
250 /* Long option that just sets a flag. */
251 break;
252 case 10:
253 symarg = optarg;
254 execarg = optarg;
255 break;
256 case 11:
257 cdarg = optarg;
258 break;
6c803036
JK
259 case 12:
260 /* FIXME: what if the syntax is wrong (e.g. not digits)? */
261 annotation_level = atoi (optarg);
262 break;
86db943c
SG
263 case 13:
264 /* Enable the display of both time and space usage. */
265 display_time = 1;
266 display_space = 1;
267 break;
6c803036
JK
268 case 'f':
269 annotation_level = 1;
1a494973
C
270/* We have probably been invoked from emacs. Disable window interface. */
271 use_windows = 0;
6c803036 272 break;
bd5635a1
RP
273 case 's':
274 symarg = optarg;
275 break;
276 case 'e':
277 execarg = optarg;
278 break;
279 case 'c':
280 corearg = optarg;
281 break;
282 case 'x':
283 cmdarg[ncmd++] = optarg;
284 if (ncmd >= cmdsize)
285 {
286 cmdsize *= 2;
287 cmdarg = (char **) xrealloc ((char *)cmdarg,
288 cmdsize * sizeof (*cmdarg));
289 }
290 break;
7f6cb62e 291 /* start-sanitize-gdbtk */
d836385e 292#ifdef GDBTK
7f6cb62e
KS
293 case 'z':
294 {
295 extern int gdbtk_test PARAMS ((char *));
296 if (!gdbtk_test (optarg))
297 {
298 fprintf_unfiltered (gdb_stderr, "%s: unable to load tclcommand file \"%s\"",
299 argv[0], optarg);
300 exit (1);
301 }
302 break;
303 }
d836385e 304#endif /* GDBTK */
7f6cb62e 305 /* end-sanitize-gdbtk */
bd5635a1
RP
306 case 'd':
307 dirarg[ndir++] = optarg;
308 if (ndir >= dirsize)
309 {
310 dirsize *= 2;
311 dirarg = (char **) xrealloc ((char *)dirarg,
312 dirsize * sizeof (*dirarg));
313 }
314 break;
315 case 't':
316 ttyarg = optarg;
317 break;
318 case 'q':
319 quiet = 1;
320 break;
321 case 'b':
d0d8484a
SG
322 {
323 int i;
324 char *p;
325
326 i = strtol (optarg, &p, 0);
327 if (i == 0 && p == optarg)
8e4c7b3e
JK
328
329 /* Don't use *_filtered or warning() (which relies on
330 current_target) until after initialize_all_files(). */
331
332 fprintf_unfiltered
333 (gdb_stderr,
334 "warning: could not set baud rate to `%s'.\n", optarg);
d0d8484a
SG
335 else
336 baud_rate = i;
337 }
265c044a
DP
338 case 'l':
339 {
340 int i;
341 char *p;
342
343 i = strtol (optarg, &p, 0);
344 if (i == 0 && p == optarg)
345
346 /* Don't use *_filtered or warning() (which relies on
347 current_target) until after initialize_all_files(). */
348
349 fprintf_unfiltered
350 (gdb_stderr,
351 "warning: could not set timeout limit to `%s'.\n", optarg);
352 else
353 remote_timeout = i;
354 }
bd5635a1 355 break;
d0d8484a 356
bd5635a1
RP
357#ifdef ADDITIONAL_OPTION_CASES
358 ADDITIONAL_OPTION_CASES
359#endif
360 case '?':
199b2450 361 fprintf_unfiltered (gdb_stderr,
fb29d681 362 "Use `%s --help' for a complete list of options.\n",
bd5635a1
RP
363 argv[0]);
364 exit (1);
365 }
bd5635a1 366 }
fb29d681 367
b52cac6b
FF
368 /* If --help or --version, disable window interface. */
369 if (print_help || print_version)
65b07ddc
DT
370 {
371 use_windows = 0;
372#ifdef TUI
373 /* Disable the TUI as well. */
374 tui_version = 0;
375#endif
376 }
377
378#ifdef TUI
379 /* An explicit --tui flag overrides the default UI, which is the
380 window system. */
381 if (tui_version)
b52cac6b 382 use_windows = 0;
65b07ddc 383#endif
b52cac6b 384
bd5635a1
RP
385 /* OK, that's all the options. The other arguments are filenames. */
386 count = 0;
387 for (; optind < argc; optind++)
388 switch (++count)
389 {
390 case 1:
391 symarg = argv[optind];
392 execarg = argv[optind];
393 break;
394 case 2:
395 corearg = argv[optind];
396 break;
397 case 3:
199b2450 398 fprintf_unfiltered (gdb_stderr,
bd5635a1
RP
399 "Excess command line arguments ignored. (%s%s)\n",
400 argv[optind], (optind == argc - 1) ? "" : " ...");
401 break;
402 }
403 if (batch)
404 quiet = 1;
405 }
406
65b07ddc
DT
407#if defined(TUI)
408 if (tui_version)
409 init_ui_hook = tuiInit;
410#endif
47792960 411 gdb_init (argv[0]);
bd5635a1 412
c307bb11
JK
413 /* Do these (and anything which might call wrap_here or *_filtered)
414 after initialize_all_files. */
415 if (print_version)
416 {
199b2450 417 print_gdb_version (gdb_stdout);
c307bb11
JK
418 wrap_here ("");
419 printf_filtered ("\n");
420 exit (0);
421 }
422
423 if (print_help)
424 {
47792960
KS
425 print_gdb_help (gdb_stdout);
426 fputs_unfiltered ("\n", gdb_stdout);
c307bb11
JK
427 exit (0);
428 }
b52cac6b 429
bd5635a1
RP
430 if (!quiet)
431 {
81066208
JG
432 /* Print all the junk at the top, with trailing "..." if we are about
433 to read a symbol file (possibly slowly). */
199b2450 434 print_gdb_version (gdb_stdout);
81066208
JG
435 if (symarg)
436 printf_filtered ("..");
bd099407 437 wrap_here("");
199b2450 438 gdb_flush (gdb_stdout); /* Force to screen during slow operations */
bd5635a1
RP
439 }
440
81066208 441 error_pre_print = "\n\n";
1a494973
C
442 quit_pre_print = error_pre_print;
443
51b57ded
FF
444 /* We may get more than one warning, don't double space all of them... */
445 warning_pre_print = "\nwarning: ";
81066208 446
3a16d640
JG
447 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
448 *before* all the command line arguments are processed; it sets
449 global parameters, which are independent of what file you are
450 debugging or what directory you are in. */
d836385e 451#ifdef __CYGWIN__
47792960
KS
452 {
453 char * tmp = getenv ("HOME");
454
455 if (tmp != NULL)
456 {
457 homedir = (char *) alloca (MAX_PATH+1);
4ef1f467 458 cygwin32_conv_to_posix_path (tmp, homedir);
47792960 459 }
d836385e
GN
460 else
461 homedir = NULL;
47792960
KS
462 }
463#else
464 homedir = getenv ("HOME");
465#endif
3a16d640
JG
466 if (homedir)
467 {
47792960 468 homeinit = (char *) alloca (strlen (homedir) +
3a16d640 469 strlen (gdbinit) + 10);
47792960 470 strcpy (homeinit, homedir);
3a16d640
JG
471 strcat (homeinit, "/");
472 strcat (homeinit, gdbinit);
b52cac6b 473
9e77e83d 474 if (!inhibit_gdbinit)
3a16d640 475 {
9748446f 476 if (!SET_TOP_LEVEL ())
3a16d640
JG
477 source_command (homeinit, 0);
478 }
479 do_cleanups (ALL_CLEANUPS);
480
481 /* Do stats; no need to do them elsewhere since we'll only
482 need them if homedir is set. Make sure that they are
483 zero in case one of them fails (this guarantees that they
484 won't match if either exists). */
485
486 memset (&homebuf, 0, sizeof (struct stat));
487 memset (&cwdbuf, 0, sizeof (struct stat));
488
489 stat (homeinit, &homebuf);
490 stat (gdbinit, &cwdbuf); /* We'll only need this if
491 homedir was set. */
492 }
754e5da2 493
bd5635a1
RP
494 /* Now perform all the actions indicated by the arguments. */
495 if (cdarg != NULL)
496 {
9748446f 497 if (!SET_TOP_LEVEL ())
bd5635a1
RP
498 {
499 cd_command (cdarg, 0);
bd5635a1
RP
500 }
501 }
f266e564
JK
502 do_cleanups (ALL_CLEANUPS);
503
bd5635a1 504 for (i = 0; i < ndir; i++)
9748446f 505 if (!SET_TOP_LEVEL ())
bd5635a1 506 directory_command (dirarg[i], 0);
51b57ded 507 free ((PTR)dirarg);
f266e564
JK
508 do_cleanups (ALL_CLEANUPS);
509
bd5635a1
RP
510 if (execarg != NULL
511 && symarg != NULL
2e4964ad 512 && STREQ (execarg, symarg))
bd5635a1
RP
513 {
514 /* The exec file and the symbol-file are the same. If we can't open
515 it, better only print one error message. */
9748446f 516 if (!SET_TOP_LEVEL ())
bd5635a1
RP
517 {
518 exec_file_command (execarg, !batch);
81066208 519 symbol_file_command (symarg, 0);
bd5635a1
RP
520 }
521 }
522 else
523 {
524 if (execarg != NULL)
9748446f 525 if (!SET_TOP_LEVEL ())
bd5635a1
RP
526 exec_file_command (execarg, !batch);
527 if (symarg != NULL)
9748446f 528 if (!SET_TOP_LEVEL ())
81066208 529 symbol_file_command (symarg, 0);
bd5635a1 530 }
f266e564
JK
531 do_cleanups (ALL_CLEANUPS);
532
81066208
JG
533 /* After the symbol file has been read, print a newline to get us
534 beyond the copyright line... But errors should still set off
535 the error message with a (single) blank line. */
afe4ca15
JG
536 if (!quiet)
537 printf_filtered ("\n");
81066208 538 error_pre_print = "\n";
1a494973 539 quit_pre_print = error_pre_print;
318bf84f 540 warning_pre_print = "\nwarning: ";
81066208 541
bd5635a1 542 if (corearg != NULL)
65b07ddc
DT
543 {
544 if (!SET_TOP_LEVEL ())
545 core_file_command (corearg, !batch);
546 else if (isdigit (corearg[0]) && !SET_TOP_LEVEL ())
547 attach_command (corearg, !batch);
548 }
f266e564 549 do_cleanups (ALL_CLEANUPS);
bd5635a1
RP
550
551 if (ttyarg != NULL)
9748446f 552 if (!SET_TOP_LEVEL ())
bd5635a1 553 tty_command (ttyarg, !batch);
f266e564 554 do_cleanups (ALL_CLEANUPS);
bd5635a1
RP
555
556#ifdef ADDITIONAL_OPTION_HANDLER
557 ADDITIONAL_OPTION_HANDLER;
558#endif
559
81066208 560 /* Error messages should no longer be distinguished with extra output. */
1a494973
C
561 error_pre_print = NULL;
562 quit_pre_print = NULL;
318bf84f 563 warning_pre_print = "warning: ";
81066208 564
3a16d640
JG
565 /* Read the .gdbinit file in the current directory, *if* it isn't
566 the same as the $HOME/.gdbinit file (it should exist, also). */
567
568 if (!homedir
569 || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
9e77e83d 570 if (!inhibit_gdbinit)
bd5635a1 571 {
9748446f 572 if (!SET_TOP_LEVEL ())
d75710b0 573 source_command (gdbinit, 0);
bd5635a1 574 }
d75710b0
FF
575 do_cleanups (ALL_CLEANUPS);
576
577 for (i = 0; i < ncmd; i++)
578 {
9748446f 579 if (!SET_TOP_LEVEL ())
d75710b0
FF
580 {
581 if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0')
582 read_command_file (stdin);
583 else
584 source_command (cmdarg[i], !batch);
585 do_cleanups (ALL_CLEANUPS);
586 }
587 }
51b57ded 588 free ((PTR)cmdarg);
bd5635a1 589
8b3c897a 590 /* Read in the old history after all the command files have been read. */
fc61e9ee 591 init_history();
8b3c897a 592
bd5635a1
RP
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
1a494973
C
606 END_PROGRESS (argv[0]);
607
86db943c
SG
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 {
265c044a 620#ifdef HAVE_SBRK
86db943c
SG
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));
265c044a 626#endif
86db943c
SG
627 }
628
1a494973
C
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. */
47792960 632#if !defined _WIN32 || defined __GNUC__
bd5635a1
RP
633 while (1)
634 {
9748446f 635 if (!SET_TOP_LEVEL ())
bd5635a1 636 {
f266e564 637 do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */
754e5da2
SG
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 ();
a6b26c44 643 else
754e5da2 644 command_loop ();
bd5635a1
RP
645 quit_command ((char *)0, instream == stdin);
646 }
647 }
1a494973 648
bd5635a1 649 /* No exit -- exit is through quit_command. */
1a494973
C
650#endif
651
bd5635a1 652}
47792960
KS
653
654/* Don't use *_filtered for printing help. We don't want to prompt
655 for continue no matter how small the screen or how much we're going
656 to print. */
657
658static void
659print_gdb_help (stream)
660 GDB_FILE *stream;
661{
662 fputs_unfiltered ("\
663This is the GNU debugger. Usage:\n\n\
664 gdb [options] [executable-file [core-file or process-id]]\n\n\
665Options:\n\n\
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 ("\
65b07ddc 675 --dbx DBX compatibility mode.\n\
47792960
KS
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\
65b07ddc
DT
693", stream);
694#if defined(TUI)
695 fputs_unfiltered ("\
696 --tui Use a terminal user interface.\n\
697", stream);
698#endif
699 fputs_unfiltered ("\
47792960 700 --version Print version information and then exit.\n\
65b07ddc 701 --xdb XDB compatibility mode.\n\
47792960
KS
702", stream);
703#ifdef ADDITIONAL_OPTION_HELP
704 fputs_unfiltered (ADDITIONAL_OPTION_HELP, stream);
705#endif
706 fputs_unfiltered ("\n\
707For more information, type \"help\" from within GDB, or consult the\n\
708GDB manual (available as on-line info or a printed manual).\n\
709Report bugs to \"bug-gdb@prep.ai.mit.edu\".\
710", stream);
711}
712
d3507982
JK
713\f
714void
715init_proc ()
716{
717}
718
d3507982
JK
719void
720proc_remove_foreign (pid)
721 int pid;
722{
723}
bd5635a1 724
47792960
KS
725/* All I/O sent to the *_filtered and *_unfiltered functions eventually ends up
726 here. The fputs_unfiltered_hook is primarily used by GUIs to collect all
727 output and send it to the GUI, instead of the controlling terminal. Only
728 output to gdb_stdout and gdb_stderr are sent to the hook. Everything else
729 is sent on to fputs to allow file I/O to be handled appropriately. */
730
bd5635a1 731void
b8ec8d4a
SS
732fputs_unfiltered (linebuffer, stream)
733 const char *linebuffer;
65b07ddc 734 GDB_FILE *stream;
bd5635a1 735{
65b07ddc
DT
736#if defined(TUI)
737 extern int tui_owns_terminal;
738#endif
739 /* If anything (GUI, TUI) wants to capture GDB output, this is
740 * the place... the way to do it is to set up
741 * fputs_unfiltered_hook.
742 * Our TUI ("gdb -tui") used to hook output, but in the
743 * new (XDB style) scheme, we do not do that anymore... - RT
744 */
47792960
KS
745 if (fputs_unfiltered_hook
746 && (stream == gdb_stdout
747 || stream == gdb_stderr))
748 fputs_unfiltered_hook (linebuffer, stream);
749 else
65b07ddc
DT
750 {
751#if defined(TUI)
752 if (tui_version && tui_owns_terminal) {
753 /* If we get here somehow while updating the TUI (from
754 * within a tuiDo(), then we need to temporarily
755 * set up the terminal for GDB output. This probably just
756 * happens on error output.
757 */
758
759 if (stream->ts_streamtype == astring) {
760 gdb_file_adjust_strbuf(strlen(linebuffer), stream);
761 strcat(stream->ts_strbuf, linebuffer);
762 } else {
763 tuiTermUnsetup(0, (tui_version) ? cmdWin->detail.commandInfo.curch : 0);
764 fputs (linebuffer, stream->ts_filestream);
765 tuiTermSetup(0);
766 if (linebuffer[strlen(linebuffer) - 1] == '\n')
767 tuiClearCommandCharCount();
768 else
769 tuiIncrCommandCharCountBy(strlen(linebuffer));
770 }
771 } else {
772 /* The normal case - just do a fputs() */
773 if (stream->ts_streamtype == astring) {
774 gdb_file_adjust_strbuf(strlen(linebuffer), stream);
775 strcat(stream->ts_strbuf, linebuffer);
776 } else fputs (linebuffer, stream->ts_filestream);
777 }
778
779
780#else
781 if (stream->ts_streamtype == astring) {
782 gdb_file_adjust_strbuf(strlen(linebuffer), stream);
783 strcat(stream->ts_strbuf, linebuffer);
784 } else fputs (linebuffer, stream->ts_filestream);
785#endif
786 }
bd5635a1 787}
This page took 0.387909 seconds and 4 git commands to generate.