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