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