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