| 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 = setjmp (error_return)) \ |
| 46 | ? (PTR) 0 : (PTR) memcpy (quit_return, error_return, sizeof (jmp_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 | extern void gdb_init PARAMS ((void)); |
| 58 | |
| 59 | int |
| 60 | main (argc, argv) |
| 61 | int argc; |
| 62 | char **argv; |
| 63 | { |
| 64 | int count; |
| 65 | static int quiet = 0; |
| 66 | static int batch = 0; |
| 67 | |
| 68 | /* Pointers to various arguments from command line. */ |
| 69 | char *symarg = NULL; |
| 70 | char *execarg = NULL; |
| 71 | char *corearg = NULL; |
| 72 | char *cdarg = NULL; |
| 73 | char *ttyarg = NULL; |
| 74 | |
| 75 | /* These are static so that we can take their address in an initializer. */ |
| 76 | static int print_help; |
| 77 | static int print_version; |
| 78 | |
| 79 | /* Pointers to all arguments of --command option. */ |
| 80 | char **cmdarg; |
| 81 | /* Allocated size of cmdarg. */ |
| 82 | int cmdsize; |
| 83 | /* Number of elements of cmdarg used. */ |
| 84 | int ncmd; |
| 85 | |
| 86 | /* Indices of all arguments of --directory option. */ |
| 87 | char **dirarg; |
| 88 | /* Allocated size. */ |
| 89 | int dirsize; |
| 90 | /* Number of elements used. */ |
| 91 | int ndir; |
| 92 | |
| 93 | struct stat homebuf, cwdbuf; |
| 94 | char *homedir, *homeinit; |
| 95 | |
| 96 | register int i; |
| 97 | |
| 98 | long time_at_startup = get_run_time (); |
| 99 | |
| 100 | START_PROGRESS (argv[0], 0); |
| 101 | |
| 102 | #ifdef MPW |
| 103 | /* Do all Mac-specific setup. */ |
| 104 | mac_init (); |
| 105 | #endif /* MPW */ |
| 106 | |
| 107 | /* This needs to happen before the first use of malloc. */ |
| 108 | init_malloc ((PTR) NULL); |
| 109 | |
| 110 | #if defined (ALIGN_STACK_ON_STARTUP) |
| 111 | i = (int) &count & 0x3; |
| 112 | if (i != 0) |
| 113 | alloca (4 - i); |
| 114 | #endif |
| 115 | |
| 116 | /* If error() is called from initialization code, just exit */ |
| 117 | if (SET_TOP_LEVEL ()) { |
| 118 | exit(1); |
| 119 | } |
| 120 | |
| 121 | cmdsize = 1; |
| 122 | cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg)); |
| 123 | ncmd = 0; |
| 124 | dirsize = 1; |
| 125 | dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg)); |
| 126 | ndir = 0; |
| 127 | |
| 128 | quit_flag = 0; |
| 129 | line = (char *) xmalloc (linesize); |
| 130 | line[0] = '\0'; /* Terminate saved (now empty) cmd line */ |
| 131 | instream = stdin; |
| 132 | |
| 133 | getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); |
| 134 | current_directory = gdb_dirbuf; |
| 135 | |
| 136 | /* Parse arguments and options. */ |
| 137 | { |
| 138 | int c; |
| 139 | /* When var field is 0, use flag field to record the equivalent |
| 140 | short option (or arbitrary numbers starting at 10 for those |
| 141 | with no equivalent). */ |
| 142 | static struct option long_options[] = |
| 143 | { |
| 144 | {"readnow", no_argument, &readnow_symbol_files, 1}, |
| 145 | {"r", no_argument, &readnow_symbol_files, 1}, |
| 146 | {"mapped", no_argument, &mapped_symbol_files, 1}, |
| 147 | {"m", no_argument, &mapped_symbol_files, 1}, |
| 148 | {"quiet", no_argument, &quiet, 1}, |
| 149 | {"q", no_argument, &quiet, 1}, |
| 150 | {"silent", no_argument, &quiet, 1}, |
| 151 | {"nx", no_argument, &inhibit_gdbinit, 1}, |
| 152 | {"n", no_argument, &inhibit_gdbinit, 1}, |
| 153 | {"batch", no_argument, &batch, 1}, |
| 154 | {"epoch", no_argument, &epoch_interface, 1}, |
| 155 | |
| 156 | /* This is a synonym for "--annotate=1". --annotate is now preferred, |
| 157 | but keep this here for a long time because people will be running |
| 158 | emacses which use --fullname. */ |
| 159 | {"fullname", no_argument, 0, 'f'}, |
| 160 | {"f", no_argument, 0, 'f'}, |
| 161 | |
| 162 | {"annotate", required_argument, 0, 12}, |
| 163 | {"help", no_argument, &print_help, 1}, |
| 164 | {"se", required_argument, 0, 10}, |
| 165 | {"symbols", required_argument, 0, 's'}, |
| 166 | {"s", required_argument, 0, 's'}, |
| 167 | {"exec", required_argument, 0, 'e'}, |
| 168 | {"e", required_argument, 0, 'e'}, |
| 169 | {"core", required_argument, 0, 'c'}, |
| 170 | {"c", required_argument, 0, 'c'}, |
| 171 | {"command", required_argument, 0, 'x'}, |
| 172 | {"version", no_argument, &print_version, 1}, |
| 173 | {"x", required_argument, 0, 'x'}, |
| 174 | {"directory", required_argument, 0, 'd'}, |
| 175 | {"cd", required_argument, 0, 11}, |
| 176 | {"tty", required_argument, 0, 't'}, |
| 177 | {"baud", required_argument, 0, 'b'}, |
| 178 | {"b", required_argument, 0, 'b'}, |
| 179 | {"nw", no_argument, &use_windows, 0}, |
| 180 | {"nowindows", no_argument, &use_windows, 0}, |
| 181 | {"w", no_argument, &use_windows, 1}, |
| 182 | {"windows", no_argument, &use_windows, 1}, |
| 183 | {"statistics", no_argument, 0, 13}, |
| 184 | /* Allow machine descriptions to add more options... */ |
| 185 | #ifdef ADDITIONAL_OPTIONS |
| 186 | ADDITIONAL_OPTIONS |
| 187 | #endif |
| 188 | {0, no_argument, 0, 0} |
| 189 | }; |
| 190 | |
| 191 | while (1) |
| 192 | { |
| 193 | int option_index; |
| 194 | |
| 195 | c = getopt_long_only (argc, argv, "", |
| 196 | long_options, &option_index); |
| 197 | if (c == EOF) |
| 198 | break; |
| 199 | |
| 200 | /* Long option that takes an argument. */ |
| 201 | if (c == 0 && long_options[option_index].flag == 0) |
| 202 | c = long_options[option_index].val; |
| 203 | |
| 204 | switch (c) |
| 205 | { |
| 206 | case 0: |
| 207 | /* Long option that just sets a flag. */ |
| 208 | break; |
| 209 | case 10: |
| 210 | symarg = optarg; |
| 211 | execarg = optarg; |
| 212 | break; |
| 213 | case 11: |
| 214 | cdarg = optarg; |
| 215 | break; |
| 216 | case 12: |
| 217 | /* FIXME: what if the syntax is wrong (e.g. not digits)? */ |
| 218 | annotation_level = atoi (optarg); |
| 219 | break; |
| 220 | case 13: |
| 221 | /* Enable the display of both time and space usage. */ |
| 222 | display_time = 1; |
| 223 | display_space = 1; |
| 224 | break; |
| 225 | case 'f': |
| 226 | annotation_level = 1; |
| 227 | /* We have probably been invoked from emacs. Disable window interface. */ |
| 228 | use_windows = 0; |
| 229 | break; |
| 230 | case 's': |
| 231 | symarg = optarg; |
| 232 | break; |
| 233 | case 'e': |
| 234 | execarg = optarg; |
| 235 | break; |
| 236 | case 'c': |
| 237 | corearg = optarg; |
| 238 | break; |
| 239 | case 'x': |
| 240 | cmdarg[ncmd++] = optarg; |
| 241 | if (ncmd >= cmdsize) |
| 242 | { |
| 243 | cmdsize *= 2; |
| 244 | cmdarg = (char **) xrealloc ((char *)cmdarg, |
| 245 | cmdsize * sizeof (*cmdarg)); |
| 246 | } |
| 247 | break; |
| 248 | case 'd': |
| 249 | dirarg[ndir++] = optarg; |
| 250 | if (ndir >= dirsize) |
| 251 | { |
| 252 | dirsize *= 2; |
| 253 | dirarg = (char **) xrealloc ((char *)dirarg, |
| 254 | dirsize * sizeof (*dirarg)); |
| 255 | } |
| 256 | break; |
| 257 | case 't': |
| 258 | ttyarg = optarg; |
| 259 | break; |
| 260 | case 'q': |
| 261 | quiet = 1; |
| 262 | break; |
| 263 | case 'b': |
| 264 | { |
| 265 | int i; |
| 266 | char *p; |
| 267 | |
| 268 | i = strtol (optarg, &p, 0); |
| 269 | if (i == 0 && p == optarg) |
| 270 | |
| 271 | /* Don't use *_filtered or warning() (which relies on |
| 272 | current_target) until after initialize_all_files(). */ |
| 273 | |
| 274 | fprintf_unfiltered |
| 275 | (gdb_stderr, |
| 276 | "warning: could not set baud rate to `%s'.\n", optarg); |
| 277 | else |
| 278 | baud_rate = i; |
| 279 | } |
| 280 | case 'l': |
| 281 | { |
| 282 | int i; |
| 283 | char *p; |
| 284 | |
| 285 | i = strtol (optarg, &p, 0); |
| 286 | if (i == 0 && p == optarg) |
| 287 | |
| 288 | /* Don't use *_filtered or warning() (which relies on |
| 289 | current_target) until after initialize_all_files(). */ |
| 290 | |
| 291 | fprintf_unfiltered |
| 292 | (gdb_stderr, |
| 293 | "warning: could not set timeout limit to `%s'.\n", optarg); |
| 294 | else |
| 295 | remote_timeout = i; |
| 296 | } |
| 297 | break; |
| 298 | |
| 299 | #ifdef ADDITIONAL_OPTION_CASES |
| 300 | ADDITIONAL_OPTION_CASES |
| 301 | #endif |
| 302 | case '?': |
| 303 | fprintf_unfiltered (gdb_stderr, |
| 304 | "Use `%s --help' for a complete list of options.\n", |
| 305 | argv[0]); |
| 306 | exit (1); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* If --help or --version, disable window interface. */ |
| 311 | if (print_help || print_version) |
| 312 | use_windows = 0; |
| 313 | |
| 314 | /* OK, that's all the options. The other arguments are filenames. */ |
| 315 | count = 0; |
| 316 | for (; optind < argc; optind++) |
| 317 | switch (++count) |
| 318 | { |
| 319 | case 1: |
| 320 | symarg = argv[optind]; |
| 321 | execarg = argv[optind]; |
| 322 | break; |
| 323 | case 2: |
| 324 | corearg = argv[optind]; |
| 325 | break; |
| 326 | case 3: |
| 327 | fprintf_unfiltered (gdb_stderr, |
| 328 | "Excess command line arguments ignored. (%s%s)\n", |
| 329 | argv[optind], (optind == argc - 1) ? "" : " ..."); |
| 330 | break; |
| 331 | } |
| 332 | if (batch) |
| 333 | quiet = 1; |
| 334 | } |
| 335 | |
| 336 | gdb_init (); |
| 337 | |
| 338 | /* Do these (and anything which might call wrap_here or *_filtered) |
| 339 | after initialize_all_files. */ |
| 340 | if (print_version) |
| 341 | { |
| 342 | print_gdb_version (gdb_stdout); |
| 343 | wrap_here (""); |
| 344 | printf_filtered ("\n"); |
| 345 | exit (0); |
| 346 | } |
| 347 | |
| 348 | if (print_help) |
| 349 | { |
| 350 | /* --version is intentionally not documented here, because we |
| 351 | are printing the version here, and the help is long enough |
| 352 | already. */ |
| 353 | |
| 354 | print_gdb_version (gdb_stdout); |
| 355 | /* Make sure the output gets printed. */ |
| 356 | wrap_here (""); |
| 357 | printf_filtered ("\n"); |
| 358 | |
| 359 | /* But don't use *_filtered here. We don't want to prompt for continue |
| 360 | no matter how small the screen or how much we're going to print. */ |
| 361 | fputs_unfiltered ("\ |
| 362 | This is the GNU debugger. Usage:\n\ |
| 363 | gdb [options] [executable-file [core-file or process-id]]\n\ |
| 364 | Options:\n\ |
| 365 | --help Print this message.\n\ |
| 366 | --quiet Do not print version number on startup.\n\ |
| 367 | --fullname Output information used by emacs-GDB interface.\n\ |
| 368 | --epoch Output information used by epoch emacs-GDB interface.\n\ |
| 369 | ", gdb_stdout); |
| 370 | fputs_unfiltered ("\ |
| 371 | --batch Exit after processing options.\n\ |
| 372 | --nx Do not read .gdbinit file.\n\ |
| 373 | --tty=TTY Use TTY for input/output by the program being debugged.\n\ |
| 374 | --cd=DIR Change current directory to DIR.\n\ |
| 375 | --directory=DIR Search for source files in DIR.\n\ |
| 376 | ", gdb_stdout); |
| 377 | fputs_unfiltered ("\ |
| 378 | --command=FILE Execute GDB commands from FILE.\n\ |
| 379 | --symbols=SYMFILE Read symbols from SYMFILE.\n\ |
| 380 | --exec=EXECFILE Use EXECFILE as the executable.\n\ |
| 381 | --se=FILE Use FILE as symbol file and executable file.\n\ |
| 382 | ", gdb_stdout); |
| 383 | fputs_unfiltered ("\ |
| 384 | --core=COREFILE Analyze the core dump COREFILE.\n\ |
| 385 | -b BAUDRATE Set serial port baud rate used for remote debugging.\n\ |
| 386 | --mapped Use mapped symbol files if supported on this system.\n\ |
| 387 | --readnow Fully read symbol files on first access.\n\ |
| 388 | --nw Do not use a window interface.\n\ |
| 389 | ", gdb_stdout); |
| 390 | #ifdef ADDITIONAL_OPTION_HELP |
| 391 | fputs_unfiltered (ADDITIONAL_OPTION_HELP, gdb_stdout); |
| 392 | #endif |
| 393 | fputs_unfiltered ("\n\ |
| 394 | For more information, type \"help\" from within GDB, or consult the\n\ |
| 395 | GDB manual (available as on-line info or a printed manual).\n", gdb_stdout); |
| 396 | exit (0); |
| 397 | } |
| 398 | |
| 399 | if (!quiet) |
| 400 | { |
| 401 | /* Print all the junk at the top, with trailing "..." if we are about |
| 402 | to read a symbol file (possibly slowly). */ |
| 403 | print_gnu_advertisement (); |
| 404 | print_gdb_version (gdb_stdout); |
| 405 | if (symarg) |
| 406 | printf_filtered (".."); |
| 407 | wrap_here(""); |
| 408 | gdb_flush (gdb_stdout); /* Force to screen during slow operations */ |
| 409 | } |
| 410 | |
| 411 | error_pre_print = "\n\n"; |
| 412 | quit_pre_print = error_pre_print; |
| 413 | |
| 414 | /* We may get more than one warning, don't double space all of them... */ |
| 415 | warning_pre_print = "\nwarning: "; |
| 416 | |
| 417 | /* Read and execute $HOME/.gdbinit file, if it exists. This is done |
| 418 | *before* all the command line arguments are processed; it sets |
| 419 | global parameters, which are independent of what file you are |
| 420 | debugging or what directory you are in. */ |
| 421 | homedir = getenv ("HOME"); |
| 422 | if (homedir) |
| 423 | { |
| 424 | homeinit = (char *) alloca (strlen (getenv ("HOME")) + |
| 425 | strlen (gdbinit) + 10); |
| 426 | strcpy (homeinit, getenv ("HOME")); |
| 427 | strcat (homeinit, "/"); |
| 428 | strcat (homeinit, gdbinit); |
| 429 | |
| 430 | if (!inhibit_gdbinit) |
| 431 | { |
| 432 | if (!SET_TOP_LEVEL ()) |
| 433 | source_command (homeinit, 0); |
| 434 | } |
| 435 | do_cleanups (ALL_CLEANUPS); |
| 436 | |
| 437 | /* Do stats; no need to do them elsewhere since we'll only |
| 438 | need them if homedir is set. Make sure that they are |
| 439 | zero in case one of them fails (this guarantees that they |
| 440 | won't match if either exists). */ |
| 441 | |
| 442 | memset (&homebuf, 0, sizeof (struct stat)); |
| 443 | memset (&cwdbuf, 0, sizeof (struct stat)); |
| 444 | |
| 445 | stat (homeinit, &homebuf); |
| 446 | stat (gdbinit, &cwdbuf); /* We'll only need this if |
| 447 | homedir was set. */ |
| 448 | } |
| 449 | |
| 450 | /* Now perform all the actions indicated by the arguments. */ |
| 451 | if (cdarg != NULL) |
| 452 | { |
| 453 | if (!SET_TOP_LEVEL ()) |
| 454 | { |
| 455 | cd_command (cdarg, 0); |
| 456 | } |
| 457 | } |
| 458 | do_cleanups (ALL_CLEANUPS); |
| 459 | |
| 460 | for (i = 0; i < ndir; i++) |
| 461 | if (!SET_TOP_LEVEL ()) |
| 462 | directory_command (dirarg[i], 0); |
| 463 | free ((PTR)dirarg); |
| 464 | do_cleanups (ALL_CLEANUPS); |
| 465 | |
| 466 | if (execarg != NULL |
| 467 | && symarg != NULL |
| 468 | && STREQ (execarg, symarg)) |
| 469 | { |
| 470 | /* The exec file and the symbol-file are the same. If we can't open |
| 471 | it, better only print one error message. */ |
| 472 | if (!SET_TOP_LEVEL ()) |
| 473 | { |
| 474 | exec_file_command (execarg, !batch); |
| 475 | symbol_file_command (symarg, 0); |
| 476 | } |
| 477 | } |
| 478 | else |
| 479 | { |
| 480 | if (execarg != NULL) |
| 481 | if (!SET_TOP_LEVEL ()) |
| 482 | exec_file_command (execarg, !batch); |
| 483 | if (symarg != NULL) |
| 484 | if (!SET_TOP_LEVEL ()) |
| 485 | symbol_file_command (symarg, 0); |
| 486 | } |
| 487 | do_cleanups (ALL_CLEANUPS); |
| 488 | |
| 489 | /* After the symbol file has been read, print a newline to get us |
| 490 | beyond the copyright line... But errors should still set off |
| 491 | the error message with a (single) blank line. */ |
| 492 | if (!quiet) |
| 493 | printf_filtered ("\n"); |
| 494 | error_pre_print = "\n"; |
| 495 | quit_pre_print = error_pre_print; |
| 496 | warning_pre_print = "\nwarning: "; |
| 497 | |
| 498 | if (corearg != NULL) |
| 499 | if (!SET_TOP_LEVEL ()) |
| 500 | core_file_command (corearg, !batch); |
| 501 | else if (isdigit (corearg[0]) && !SET_TOP_LEVEL ()) |
| 502 | attach_command (corearg, !batch); |
| 503 | do_cleanups (ALL_CLEANUPS); |
| 504 | |
| 505 | if (ttyarg != NULL) |
| 506 | if (!SET_TOP_LEVEL ()) |
| 507 | tty_command (ttyarg, !batch); |
| 508 | do_cleanups (ALL_CLEANUPS); |
| 509 | |
| 510 | #ifdef ADDITIONAL_OPTION_HANDLER |
| 511 | ADDITIONAL_OPTION_HANDLER; |
| 512 | #endif |
| 513 | |
| 514 | /* Error messages should no longer be distinguished with extra output. */ |
| 515 | error_pre_print = NULL; |
| 516 | quit_pre_print = NULL; |
| 517 | warning_pre_print = "warning: "; |
| 518 | |
| 519 | /* Read the .gdbinit file in the current directory, *if* it isn't |
| 520 | the same as the $HOME/.gdbinit file (it should exist, also). */ |
| 521 | |
| 522 | if (!homedir |
| 523 | || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat))) |
| 524 | if (!inhibit_gdbinit) |
| 525 | { |
| 526 | if (!SET_TOP_LEVEL ()) |
| 527 | source_command (gdbinit, 0); |
| 528 | } |
| 529 | do_cleanups (ALL_CLEANUPS); |
| 530 | |
| 531 | for (i = 0; i < ncmd; i++) |
| 532 | { |
| 533 | if (!SET_TOP_LEVEL ()) |
| 534 | { |
| 535 | if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0') |
| 536 | read_command_file (stdin); |
| 537 | else |
| 538 | source_command (cmdarg[i], !batch); |
| 539 | do_cleanups (ALL_CLEANUPS); |
| 540 | } |
| 541 | } |
| 542 | free ((PTR)cmdarg); |
| 543 | |
| 544 | /* Read in the old history after all the command files have been read. */ |
| 545 | init_history(); |
| 546 | |
| 547 | if (batch) |
| 548 | { |
| 549 | /* We have hit the end of the batch file. */ |
| 550 | exit (0); |
| 551 | } |
| 552 | |
| 553 | /* Do any host- or target-specific hacks. This is used for i960 targets |
| 554 | to force the user to set a nindy target and spec its parameters. */ |
| 555 | |
| 556 | #ifdef BEFORE_MAIN_LOOP_HOOK |
| 557 | BEFORE_MAIN_LOOP_HOOK; |
| 558 | #endif |
| 559 | |
| 560 | END_PROGRESS (argv[0]); |
| 561 | |
| 562 | /* Show time and/or space usage. */ |
| 563 | |
| 564 | if (display_time) |
| 565 | { |
| 566 | long init_time = get_run_time () - time_at_startup; |
| 567 | |
| 568 | printf_unfiltered ("Startup time: %ld.%06ld\n", |
| 569 | init_time / 1000000, init_time % 1000000); |
| 570 | } |
| 571 | |
| 572 | if (display_space) |
| 573 | { |
| 574 | #ifdef HAVE_SBRK |
| 575 | extern char **environ; |
| 576 | char *lim = (char *) sbrk (0); |
| 577 | |
| 578 | printf_unfiltered ("Startup size: data size %ld\n", |
| 579 | (long) (lim - (char *) &environ)); |
| 580 | #endif |
| 581 | } |
| 582 | |
| 583 | /* The default command loop. |
| 584 | The WIN32 Gui calls this main to set up gdb's state, and |
| 585 | has its own command loop. */ |
| 586 | #ifndef _WIN32 |
| 587 | while (1) |
| 588 | { |
| 589 | if (!SET_TOP_LEVEL ()) |
| 590 | { |
| 591 | do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */ |
| 592 | /* GUIs generally have their own command loop, mainloop, or whatever. |
| 593 | This is a good place to gain control because many error |
| 594 | conditions will end up here via longjmp(). */ |
| 595 | if (command_loop_hook) |
| 596 | command_loop_hook (); |
| 597 | else |
| 598 | command_loop (); |
| 599 | quit_command ((char *)0, instream == stdin); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /* No exit -- exit is through quit_command. */ |
| 604 | #endif |
| 605 | |
| 606 | } |
| 607 | \f |
| 608 | void |
| 609 | init_proc () |
| 610 | { |
| 611 | } |
| 612 | |
| 613 | void |
| 614 | proc_remove_foreign (pid) |
| 615 | int pid; |
| 616 | { |
| 617 | } |
| 618 | |
| 619 | void |
| 620 | fputs_unfiltered (linebuffer, stream) |
| 621 | const char *linebuffer; |
| 622 | FILE *stream; |
| 623 | { |
| 624 | if (fputs_unfiltered_hook) |
| 625 | { |
| 626 | /* FIXME: I think we should only be doing this for stdout or stderr. |
| 627 | Either that or we should be passing stream to the hook so it can |
| 628 | deal with it. If that is cleaned up, this function can go back |
| 629 | into utils.c and the fputs_unfiltered_hook can replace the current |
| 630 | ability to avoid this function by not linking with main.c. */ |
| 631 | fputs_unfiltered_hook (linebuffer, stream); |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | fputs (linebuffer, stream); |
| 636 | } |