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