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