Fix a new warning on Cygwin
[binutils-gdb.git] / gdb / main.c
1 /* Top level stuff for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2022 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "top.h"
22 #include "target.h"
23 #include "inferior.h"
24 #include "symfile.h"
25 #include "gdbcore.h"
26 #include "getopt.h"
27
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <ctype.h>
31 #include "gdbsupport/event-loop.h"
32 #include "ui-out.h"
33
34 #include "interps.h"
35 #include "main.h"
36 #include "source.h"
37 #include "cli/cli-cmds.h"
38 #include "objfiles.h"
39 #include "auto-load.h"
40 #include "maint.h"
41
42 #include "filenames.h"
43 #include "gdbsupport/filestuff.h"
44 #include <signal.h>
45 #include "event-top.h"
46 #include "infrun.h"
47 #include "gdbsupport/signals-state-save-restore.h"
48 #include <algorithm>
49 #include <vector>
50 #include "gdbsupport/pathstuff.h"
51 #include "cli/cli-style.h"
52 #ifdef GDBTK
53 #include "gdbtk/generic/gdbtk.h"
54 #endif
55 #include "gdbsupport/alt-stack.h"
56 #include "observable.h"
57 #include "serial.h"
58
59 /* The selected interpreter. This will be used as a set command
60 variable, so it should always be malloc'ed - since
61 do_setshow_command will free it. */
62 char *interpreter_p;
63
64 /* System root path, used to find libraries etc. */
65 std::string gdb_sysroot;
66
67 /* GDB datadir, used to store data files. */
68 std::string gdb_datadir;
69
70 /* Non-zero if GDB_DATADIR was provided on the command line.
71 This doesn't track whether data-directory is set later from the
72 command line, but we don't reread system.gdbinit when that happens. */
73 static int gdb_datadir_provided = 0;
74
75 /* If gdb was configured with --with-python=/path,
76 the possibly relocated path to python's lib directory. */
77 std::string python_libdir;
78
79 /* Target IO streams. */
80 struct ui_file *gdb_stdtargin;
81 struct ui_file *gdb_stdtarg;
82 struct ui_file *gdb_stdtargerr;
83
84 /* True if --batch or --batch-silent was seen. */
85 int batch_flag = 0;
86
87 /* Support for the --batch-silent option. */
88 int batch_silent = 0;
89
90 /* Support for --return-child-result option.
91 Set the default to -1 to return error in the case
92 that the program does not run or does not complete. */
93 int return_child_result = 0;
94 int return_child_result_value = -1;
95
96
97 /* GDB as it has been invoked from the command line (i.e. argv[0]). */
98 static char *gdb_program_name;
99
100 /* Return read only pointer to GDB_PROGRAM_NAME. */
101 const char *
102 get_gdb_program_name (void)
103 {
104 return gdb_program_name;
105 }
106
107 static void print_gdb_help (struct ui_file *);
108
109 /* Set the data-directory parameter to NEW_DATADIR.
110 If NEW_DATADIR is not a directory then a warning is printed.
111 We don't signal an error for backward compatibility. */
112
113 void
114 set_gdb_data_directory (const char *new_datadir)
115 {
116 struct stat st;
117
118 if (stat (new_datadir, &st) < 0)
119 {
120 int save_errno = errno;
121
122 gdb_printf (gdb_stderr, "Warning: ");
123 print_sys_errmsg (new_datadir, save_errno);
124 }
125 else if (!S_ISDIR (st.st_mode))
126 warning (_("%ps is not a directory."),
127 styled_string (file_name_style.style (), new_datadir));
128
129 gdb_datadir = gdb_realpath (new_datadir).get ();
130
131 /* gdb_realpath won't return an absolute path if the path doesn't exist,
132 but we still want to record an absolute path here. If the user entered
133 "../foo" and "../foo" doesn't exist then we'll record $(pwd)/../foo which
134 isn't canonical, but that's ok. */
135 if (!IS_ABSOLUTE_PATH (gdb_datadir.c_str ()))
136 gdb_datadir = gdb_abspath (gdb_datadir.c_str ());
137 }
138
139 /* Relocate a file or directory. PROGNAME is the name by which gdb
140 was invoked (i.e., argv[0]). INITIAL is the default value for the
141 file or directory. RELOCATABLE is true if the value is relocatable,
142 false otherwise. This may return an empty string under the same
143 conditions as make_relative_prefix returning NULL. */
144
145 static std::string
146 relocate_path (const char *progname, const char *initial, bool relocatable)
147 {
148 if (relocatable)
149 {
150 gdb::unique_xmalloc_ptr<char> str (make_relative_prefix (progname,
151 BINDIR,
152 initial));
153 if (str != nullptr)
154 return str.get ();
155 return std::string ();
156 }
157 return initial;
158 }
159
160 /* Like relocate_path, but specifically checks for a directory.
161 INITIAL is relocated according to the rules of relocate_path. If
162 the result is a directory, it is used; otherwise, INITIAL is used.
163 The chosen directory is then canonicalized using lrealpath. */
164
165 std::string
166 relocate_gdb_directory (const char *initial, bool relocatable)
167 {
168 std::string dir = relocate_path (gdb_program_name, initial, relocatable);
169 if (!dir.empty ())
170 {
171 struct stat s;
172
173 if (stat (dir.c_str (), &s) != 0 || !S_ISDIR (s.st_mode))
174 {
175 dir.clear ();
176 }
177 }
178 if (dir.empty ())
179 dir = initial;
180
181 /* Canonicalize the directory. */
182 if (!dir.empty ())
183 {
184 gdb::unique_xmalloc_ptr<char> canon_sysroot (lrealpath (dir.c_str ()));
185
186 if (canon_sysroot)
187 dir = canon_sysroot.get ();
188 }
189
190 return dir;
191 }
192
193 /* Given a gdbinit path in FILE, adjusts it according to the gdb_datadir
194 parameter if it is in the data dir, or passes it through relocate_path
195 otherwise. */
196
197 static std::string
198 relocate_file_path_maybe_in_datadir (const std::string &file,
199 bool relocatable)
200 {
201 size_t datadir_len = strlen (GDB_DATADIR);
202
203 std::string relocated_path;
204
205 /* If SYSTEM_GDBINIT lives in data-directory, and data-directory
206 has been provided, search for SYSTEM_GDBINIT there. */
207 if (gdb_datadir_provided
208 && datadir_len < file.length ()
209 && filename_ncmp (file.c_str (), GDB_DATADIR, datadir_len) == 0
210 && IS_DIR_SEPARATOR (file[datadir_len]))
211 {
212 /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
213 to gdb_datadir. */
214
215 size_t start = datadir_len;
216 for (; IS_DIR_SEPARATOR (file[start]); ++start)
217 ;
218 relocated_path = gdb_datadir + SLASH_STRING + file.substr (start);
219 }
220 else
221 {
222 relocated_path = relocate_path (gdb_program_name, file.c_str (),
223 relocatable);
224 }
225 return relocated_path;
226 }
227
228 /* A class to wrap up the logic for finding the three different types of
229 initialisation files GDB uses, system wide, home directory, and current
230 working directory. */
231
232 class gdb_initfile_finder
233 {
234 public:
235 /* Constructor. Finds initialisation files named FILENAME in the home
236 directory or local (current working) directory. System initialisation
237 files are found in both SYSTEM_FILENAME and SYSTEM_DIRNAME if these
238 are not nullptr (either or both can be). The matching *_RELOCATABLE
239 flag is passed through to RELOCATE_FILE_PATH_MAYBE_IN_DATADIR.
240
241 If FILENAME starts with a '.' then when looking in the home directory
242 this first '.' can be ignored in some cases. */
243 explicit gdb_initfile_finder (const char *filename,
244 const char *system_filename,
245 bool system_filename_relocatable,
246 const char *system_dirname,
247 bool system_dirname_relocatable,
248 bool lookup_local_file)
249 {
250 struct stat s;
251
252 if (system_filename != nullptr && system_filename[0] != '\0')
253 {
254 std::string relocated_filename
255 = relocate_file_path_maybe_in_datadir (system_filename,
256 system_filename_relocatable);
257 if (!relocated_filename.empty ()
258 && stat (relocated_filename.c_str (), &s) == 0)
259 m_system_files.push_back (relocated_filename);
260 }
261
262 if (system_dirname != nullptr && system_dirname[0] != '\0')
263 {
264 std::string relocated_dirname
265 = relocate_file_path_maybe_in_datadir (system_dirname,
266 system_dirname_relocatable);
267 if (!relocated_dirname.empty ())
268 {
269 gdb_dir_up dir (opendir (relocated_dirname.c_str ()));
270 if (dir != nullptr)
271 {
272 std::vector<std::string> files;
273 while (true)
274 {
275 struct dirent *ent = readdir (dir.get ());
276 if (ent == nullptr)
277 break;
278 std::string name (ent->d_name);
279 if (name == "." || name == "..")
280 continue;
281 /* ent->d_type is not available on all systems
282 (e.g. mingw, Solaris), so we have to call stat(). */
283 std::string tmp_filename
284 = relocated_dirname + SLASH_STRING + name;
285 if (stat (tmp_filename.c_str (), &s) != 0
286 || !S_ISREG (s.st_mode))
287 continue;
288 const struct extension_language_defn *extlang
289 = get_ext_lang_of_file (tmp_filename.c_str ());
290 /* We effectively don't support "set script-extension
291 off/soft", because we are loading system init files
292 here, so it does not really make sense to depend on
293 a setting. */
294 if (extlang != nullptr && ext_lang_present_p (extlang))
295 files.push_back (std::move (tmp_filename));
296 }
297 std::sort (files.begin (), files.end ());
298 m_system_files.insert (m_system_files.end (),
299 files.begin (), files.end ());
300 }
301 }
302 }
303
304 /* If the .gdbinit file in the current directory is the same as
305 the $HOME/.gdbinit file, it should not be sourced. homebuf
306 and cwdbuf are used in that purpose. Make sure that the stats
307 are zero in case one of them fails (this guarantees that they
308 won't match if either exists). */
309
310 struct stat homebuf, cwdbuf;
311 memset (&homebuf, 0, sizeof (struct stat));
312 memset (&cwdbuf, 0, sizeof (struct stat));
313
314 m_home_file = find_gdb_home_config_file (filename, &homebuf);
315
316 if (lookup_local_file && stat (filename, &cwdbuf) == 0)
317 {
318 if (m_home_file.empty ()
319 || memcmp ((char *) &homebuf, (char *) &cwdbuf,
320 sizeof (struct stat)))
321 m_local_file = filename;
322 }
323 }
324
325 DISABLE_COPY_AND_ASSIGN (gdb_initfile_finder);
326
327 /* Return a list of system initialisation files. The list could be
328 empty. */
329 const std::vector<std::string> &system_files () const
330 { return m_system_files; }
331
332 /* Return the path to the home initialisation file. The string can be
333 empty if there is no such file. */
334 const std::string &home_file () const
335 { return m_home_file; }
336
337 /* Return the path to the local initialisation file. The string can be
338 empty if there is no such file. */
339 const std::string &local_file () const
340 { return m_local_file; }
341
342 private:
343
344 /* Vector of all system init files in the order they should be processed.
345 Could be empty. */
346 std::vector<std::string> m_system_files;
347
348 /* Initialization file from the home directory. Could be the empty
349 string if there is no such file found. */
350 std::string m_home_file;
351
352 /* Initialization file from the current working directory. Could be the
353 empty string if there is no such file found. */
354 std::string m_local_file;
355 };
356
357 /* Compute the locations of init files that GDB should source and return
358 them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. The SYSTEM_GDBINIT
359 can be returned as an empty vector, and HOME_GDBINIT and LOCAL_GDBINIT
360 can be returned as empty strings if there is no init file of that
361 type. */
362
363 static void
364 get_init_files (std::vector<std::string> *system_gdbinit,
365 std::string *home_gdbinit,
366 std::string *local_gdbinit)
367 {
368 /* Cache the file lookup object so we only actually search for the files
369 once. */
370 static gdb::optional<gdb_initfile_finder> init_files;
371 if (!init_files.has_value ())
372 init_files.emplace (GDBINIT, SYSTEM_GDBINIT, SYSTEM_GDBINIT_RELOCATABLE,
373 SYSTEM_GDBINIT_DIR, SYSTEM_GDBINIT_DIR_RELOCATABLE,
374 true);
375
376 *system_gdbinit = init_files->system_files ();
377 *home_gdbinit = init_files->home_file ();
378 *local_gdbinit = init_files->local_file ();
379 }
380
381 /* Compute the location of the early init file GDB should source and return
382 it in HOME_GDBEARLYINIT. HOME_GDBEARLYINIT could be returned as an
383 empty string if there is no early init file found. */
384
385 static void
386 get_earlyinit_files (std::string *home_gdbearlyinit)
387 {
388 /* Cache the file lookup object so we only actually search for the files
389 once. */
390 static gdb::optional<gdb_initfile_finder> init_files;
391 if (!init_files.has_value ())
392 init_files.emplace (GDBEARLYINIT, nullptr, false, nullptr, false, false);
393
394 *home_gdbearlyinit = init_files->home_file ();
395 }
396
397 /* Start up the event loop. This is the entry point to the event loop
398 from the command loop. */
399
400 static void
401 start_event_loop ()
402 {
403 /* Loop until there is nothing to do. This is the entry point to
404 the event loop engine. gdb_do_one_event will process one event
405 for each invocation. It blocks waiting for an event and then
406 processes it. */
407 while (1)
408 {
409 int result = 0;
410
411 try
412 {
413 result = gdb_do_one_event ();
414 }
415 catch (const gdb_exception &ex)
416 {
417 exception_print (gdb_stderr, ex);
418
419 /* If any exception escaped to here, we better enable
420 stdin. Otherwise, any command that calls async_disable_stdin,
421 and then throws, will leave stdin inoperable. */
422 SWITCH_THRU_ALL_UIS ()
423 {
424 async_enable_stdin ();
425 }
426 /* If we long-jumped out of do_one_event, we probably didn't
427 get around to resetting the prompt, which leaves readline
428 in a messed-up state. Reset it here. */
429 current_ui->prompt_state = PROMPT_NEEDED;
430 gdb::observers::command_error.notify ();
431 /* This call looks bizarre, but it is required. If the user
432 entered a command that caused an error,
433 after_char_processing_hook won't be called from
434 rl_callback_read_char_wrapper. Using a cleanup there
435 won't work, since we want this function to be called
436 after a new prompt is printed. */
437 if (after_char_processing_hook)
438 (*after_char_processing_hook) ();
439 /* Maybe better to set a flag to be checked somewhere as to
440 whether display the prompt or not. */
441 }
442
443 if (result < 0)
444 break;
445 }
446
447 /* We are done with the event loop. There are no more event sources
448 to listen to. So we exit GDB. */
449 return;
450 }
451
452 /* Call command_loop. */
453
454 /* Prevent inlining this function for the benefit of GDB's selftests
455 in the testsuite. Those tests want to run GDB under GDB and stop
456 here. */
457 static void captured_command_loop () __attribute__((noinline));
458
459 static void
460 captured_command_loop ()
461 {
462 struct ui *ui = current_ui;
463
464 /* Top-level execution commands can be run in the background from
465 here on. */
466 current_ui->async = 1;
467
468 /* Give the interpreter a chance to print a prompt, if necessary */
469 if (ui->prompt_state != PROMPT_BLOCKED)
470 interp_pre_command_loop (top_level_interpreter ());
471
472 /* Now it's time to start the event loop. */
473 start_event_loop ();
474
475 /* If the command_loop returned, normally (rather than threw an
476 error) we try to quit. If the quit is aborted, our caller
477 catches the signal and restarts the command loop. */
478 quit_command (NULL, ui->instream == ui->stdin_stream);
479 }
480
481 /* Handle command errors thrown from within catch_command_errors. */
482
483 static int
484 handle_command_errors (const struct gdb_exception &e)
485 {
486 if (e.reason < 0)
487 {
488 exception_print (gdb_stderr, e);
489
490 /* If any exception escaped to here, we better enable stdin.
491 Otherwise, any command that calls async_disable_stdin, and
492 then throws, will leave stdin inoperable. */
493 async_enable_stdin ();
494 return 0;
495 }
496 return 1;
497 }
498
499 /* Type of the command callback passed to the const
500 catch_command_errors. */
501
502 typedef void (catch_command_errors_const_ftype) (const char *, int);
503
504 /* Wrap calls to commands run before the event loop is started. */
505
506 static int
507 catch_command_errors (catch_command_errors_const_ftype command,
508 const char *arg, int from_tty,
509 bool do_bp_actions = false)
510 {
511 try
512 {
513 int was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
514
515 command (arg, from_tty);
516
517 maybe_wait_sync_command_done (was_sync);
518
519 /* Do any commands attached to breakpoint we stopped at. */
520 if (do_bp_actions)
521 bpstat_do_actions ();
522 }
523 catch (const gdb_exception &e)
524 {
525 return handle_command_errors (e);
526 }
527
528 return 1;
529 }
530
531 /* Adapter for symbol_file_add_main that translates 'from_tty' to a
532 symfile_add_flags. */
533
534 static void
535 symbol_file_add_main_adapter (const char *arg, int from_tty)
536 {
537 symfile_add_flags add_flags = 0;
538
539 if (from_tty)
540 add_flags |= SYMFILE_VERBOSE;
541
542 symbol_file_add_main (arg, add_flags);
543 }
544
545 /* Perform validation of the '--readnow' and '--readnever' flags. */
546
547 static void
548 validate_readnow_readnever ()
549 {
550 if (readnever_symbol_files && readnow_symbol_files)
551 {
552 error (_("%s: '--readnow' and '--readnever' cannot be "
553 "specified simultaneously"),
554 gdb_program_name);
555 }
556 }
557
558 /* Type of this option. */
559 enum cmdarg_kind
560 {
561 /* Option type -x. */
562 CMDARG_FILE,
563
564 /* Option type -ex. */
565 CMDARG_COMMAND,
566
567 /* Option type -ix. */
568 CMDARG_INIT_FILE,
569
570 /* Option type -iex. */
571 CMDARG_INIT_COMMAND,
572
573 /* Option type -eix. */
574 CMDARG_EARLYINIT_FILE,
575
576 /* Option type -eiex. */
577 CMDARG_EARLYINIT_COMMAND
578 };
579
580 /* Arguments of --command option and its counterpart. */
581 struct cmdarg
582 {
583 cmdarg (cmdarg_kind type_, char *string_)
584 : type (type_), string (string_)
585 {}
586
587 /* Type of this option. */
588 enum cmdarg_kind type;
589
590 /* Value of this option - filename or the GDB command itself. String memory
591 is not owned by this structure despite it is 'const'. */
592 char *string;
593 };
594
595 /* From CMDARG_VEC execute command files (matching FILE_TYPE) or commands
596 (matching CMD_TYPE). Update the value in *RET if and scripts or
597 commands are executed. */
598
599 static void
600 execute_cmdargs (const std::vector<struct cmdarg> *cmdarg_vec,
601 cmdarg_kind file_type, cmdarg_kind cmd_type,
602 int *ret)
603 {
604 for (const auto &cmdarg_p : *cmdarg_vec)
605 {
606 if (cmdarg_p.type == file_type)
607 *ret = catch_command_errors (source_script, cmdarg_p.string,
608 !batch_flag);
609 else if (cmdarg_p.type == cmd_type)
610 *ret = catch_command_errors (execute_command, cmdarg_p.string,
611 !batch_flag, true);
612 }
613 }
614
615 static void
616 captured_main_1 (struct captured_main_args *context)
617 {
618 int argc = context->argc;
619 char **argv = context->argv;
620
621 static int quiet = 0;
622 static int set_args = 0;
623 static int inhibit_home_gdbinit = 0;
624
625 /* Pointers to various arguments from command line. */
626 char *symarg = NULL;
627 char *execarg = NULL;
628 char *pidarg = NULL;
629 char *corearg = NULL;
630 char *pid_or_core_arg = NULL;
631 char *cdarg = NULL;
632 char *ttyarg = NULL;
633
634 /* These are static so that we can take their address in an
635 initializer. */
636 static int print_help;
637 static int print_version;
638 static int print_configuration;
639
640 /* Pointers to all arguments of --command option. */
641 std::vector<struct cmdarg> cmdarg_vec;
642
643 /* All arguments of --directory option. */
644 std::vector<char *> dirarg;
645
646 int i;
647 int save_auto_load;
648 int ret = 1;
649
650 #ifdef HAVE_USEFUL_SBRK
651 /* Set this before constructing scoped_command_stats. */
652 lim_at_start = (char *) sbrk (0);
653 #endif
654
655 scoped_command_stats stat_reporter (false);
656
657 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
658 setlocale (LC_MESSAGES, "");
659 #endif
660 #if defined (HAVE_SETLOCALE)
661 setlocale (LC_CTYPE, "");
662 #endif
663 #ifdef ENABLE_NLS
664 bindtextdomain (PACKAGE, LOCALEDIR);
665 textdomain (PACKAGE);
666 #endif
667
668 notice_open_fds ();
669
670 #ifdef __MINGW32__
671 /* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented
672 as a Windows pipe, and Windows buffers on pipes. */
673 setvbuf (stderr, NULL, _IONBF, BUFSIZ);
674 #endif
675
676 /* Note: `error' cannot be called before this point, because the
677 caller will crash when trying to print the exception. */
678 main_ui = new ui (stdin, stdout, stderr);
679 current_ui = main_ui;
680
681 gdb_stdtargerr = gdb_stderr; /* for moment */
682 gdb_stdtargin = gdb_stdin; /* for moment */
683
684 if (bfd_init () != BFD_INIT_MAGIC)
685 error (_("fatal error: libbfd ABI mismatch"));
686
687 #ifdef __MINGW32__
688 /* On Windows, argv[0] is not necessarily set to absolute form when
689 GDB is found along PATH, without which relocation doesn't work. */
690 gdb_program_name = windows_get_absolute_argv0 (argv[0]);
691 #else
692 gdb_program_name = xstrdup (argv[0]);
693 #endif
694
695 /* Prefix warning messages with the command name. */
696 gdb::unique_xmalloc_ptr<char> tmp_warn_preprint
697 = xstrprintf ("%s: warning: ", gdb_program_name);
698 warning_pre_print = tmp_warn_preprint.get ();
699
700 current_directory = getcwd (NULL, 0);
701 if (current_directory == NULL)
702 perror_warning_with_name (_("error finding working directory"));
703
704 /* Set the sysroot path. */
705 gdb_sysroot = relocate_gdb_directory (TARGET_SYSTEM_ROOT,
706 TARGET_SYSTEM_ROOT_RELOCATABLE);
707
708 if (gdb_sysroot.empty ())
709 gdb_sysroot = TARGET_SYSROOT_PREFIX;
710
711 debug_file_directory
712 = relocate_gdb_directory (DEBUGDIR, DEBUGDIR_RELOCATABLE);
713
714 gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
715 GDB_DATADIR_RELOCATABLE);
716
717 #ifdef WITH_PYTHON_LIBDIR
718 python_libdir = relocate_gdb_directory (WITH_PYTHON_LIBDIR,
719 PYTHON_LIBDIR_RELOCATABLE);
720 #endif
721
722 #ifdef RELOC_SRCDIR
723 add_substitute_path_rule (RELOC_SRCDIR,
724 make_relative_prefix (gdb_program_name, BINDIR,
725 RELOC_SRCDIR));
726 #endif
727
728 /* There will always be an interpreter. Either the one passed into
729 this captured main, or one specified by the user at start up, or
730 the console. Initialize the interpreter to the one requested by
731 the application. */
732 interpreter_p = xstrdup (context->interpreter_p);
733
734 /* Parse arguments and options. */
735 {
736 int c;
737 /* When var field is 0, use flag field to record the equivalent
738 short option (or arbitrary numbers starting at 10 for those
739 with no equivalent). */
740 enum {
741 OPT_SE = 10,
742 OPT_CD,
743 OPT_ANNOTATE,
744 OPT_STATISTICS,
745 OPT_TUI,
746 OPT_NOWINDOWS,
747 OPT_WINDOWS,
748 OPT_IX,
749 OPT_IEX,
750 OPT_EIX,
751 OPT_EIEX,
752 OPT_READNOW,
753 OPT_READNEVER
754 };
755 /* This struct requires int* in the struct, but write_files is a bool.
756 So use this temporary int that we write back after argument parsing. */
757 int write_files_1 = 0;
758 static struct option long_options[] =
759 {
760 {"tui", no_argument, 0, OPT_TUI},
761 {"readnow", no_argument, NULL, OPT_READNOW},
762 {"readnever", no_argument, NULL, OPT_READNEVER},
763 {"r", no_argument, NULL, OPT_READNOW},
764 {"quiet", no_argument, &quiet, 1},
765 {"q", no_argument, &quiet, 1},
766 {"silent", no_argument, &quiet, 1},
767 {"nh", no_argument, &inhibit_home_gdbinit, 1},
768 {"nx", no_argument, &inhibit_gdbinit, 1},
769 {"n", no_argument, &inhibit_gdbinit, 1},
770 {"batch-silent", no_argument, 0, 'B'},
771 {"batch", no_argument, &batch_flag, 1},
772
773 /* This is a synonym for "--annotate=1". --annotate is now
774 preferred, but keep this here for a long time because people
775 will be running emacses which use --fullname. */
776 {"fullname", no_argument, 0, 'f'},
777 {"f", no_argument, 0, 'f'},
778
779 {"annotate", required_argument, 0, OPT_ANNOTATE},
780 {"help", no_argument, &print_help, 1},
781 {"se", required_argument, 0, OPT_SE},
782 {"symbols", required_argument, 0, 's'},
783 {"s", required_argument, 0, 's'},
784 {"exec", required_argument, 0, 'e'},
785 {"e", required_argument, 0, 'e'},
786 {"core", required_argument, 0, 'c'},
787 {"c", required_argument, 0, 'c'},
788 {"pid", required_argument, 0, 'p'},
789 {"p", required_argument, 0, 'p'},
790 {"command", required_argument, 0, 'x'},
791 {"eval-command", required_argument, 0, 'X'},
792 {"version", no_argument, &print_version, 1},
793 {"configuration", no_argument, &print_configuration, 1},
794 {"x", required_argument, 0, 'x'},
795 {"ex", required_argument, 0, 'X'},
796 {"init-command", required_argument, 0, OPT_IX},
797 {"init-eval-command", required_argument, 0, OPT_IEX},
798 {"ix", required_argument, 0, OPT_IX},
799 {"iex", required_argument, 0, OPT_IEX},
800 {"early-init-command", required_argument, 0, OPT_EIX},
801 {"early-init-eval-command", required_argument, 0, OPT_EIEX},
802 {"eix", required_argument, 0, OPT_EIX},
803 {"eiex", required_argument, 0, OPT_EIEX},
804 #ifdef GDBTK
805 {"tclcommand", required_argument, 0, 'z'},
806 {"enable-external-editor", no_argument, 0, 'y'},
807 {"editor-command", required_argument, 0, 'w'},
808 #endif
809 {"ui", required_argument, 0, 'i'},
810 {"interpreter", required_argument, 0, 'i'},
811 {"i", required_argument, 0, 'i'},
812 {"directory", required_argument, 0, 'd'},
813 {"d", required_argument, 0, 'd'},
814 {"data-directory", required_argument, 0, 'D'},
815 {"D", required_argument, 0, 'D'},
816 {"cd", required_argument, 0, OPT_CD},
817 {"tty", required_argument, 0, 't'},
818 {"baud", required_argument, 0, 'b'},
819 {"b", required_argument, 0, 'b'},
820 {"nw", no_argument, NULL, OPT_NOWINDOWS},
821 {"nowindows", no_argument, NULL, OPT_NOWINDOWS},
822 {"w", no_argument, NULL, OPT_WINDOWS},
823 {"windows", no_argument, NULL, OPT_WINDOWS},
824 {"statistics", no_argument, 0, OPT_STATISTICS},
825 {"write", no_argument, &write_files_1, 1},
826 {"args", no_argument, &set_args, 1},
827 {"l", required_argument, 0, 'l'},
828 {"return-child-result", no_argument, &return_child_result, 1},
829 {0, no_argument, 0, 0}
830 };
831
832 while (1)
833 {
834 int option_index;
835
836 c = getopt_long_only (argc, argv, "",
837 long_options, &option_index);
838 if (c == EOF || set_args)
839 break;
840
841 /* Long option that takes an argument. */
842 if (c == 0 && long_options[option_index].flag == 0)
843 c = long_options[option_index].val;
844
845 switch (c)
846 {
847 case 0:
848 /* Long option that just sets a flag. */
849 break;
850 case OPT_SE:
851 symarg = optarg;
852 execarg = optarg;
853 break;
854 case OPT_CD:
855 cdarg = optarg;
856 break;
857 case OPT_ANNOTATE:
858 /* FIXME: what if the syntax is wrong (e.g. not digits)? */
859 annotation_level = atoi (optarg);
860 break;
861 case OPT_STATISTICS:
862 /* Enable the display of both time and space usage. */
863 set_per_command_time (1);
864 set_per_command_space (1);
865 break;
866 case OPT_TUI:
867 /* --tui is equivalent to -i=tui. */
868 #ifdef TUI
869 xfree (interpreter_p);
870 interpreter_p = xstrdup (INTERP_TUI);
871 #else
872 error (_("%s: TUI mode is not supported"), gdb_program_name);
873 #endif
874 break;
875 case OPT_WINDOWS:
876 /* FIXME: cagney/2003-03-01: Not sure if this option is
877 actually useful, and if it is, what it should do. */
878 #ifdef GDBTK
879 /* --windows is equivalent to -i=insight. */
880 xfree (interpreter_p);
881 interpreter_p = xstrdup (INTERP_INSIGHT);
882 #endif
883 break;
884 case OPT_NOWINDOWS:
885 /* -nw is equivalent to -i=console. */
886 xfree (interpreter_p);
887 interpreter_p = xstrdup (INTERP_CONSOLE);
888 break;
889 case 'f':
890 annotation_level = 1;
891 break;
892 case 's':
893 symarg = optarg;
894 break;
895 case 'e':
896 execarg = optarg;
897 break;
898 case 'c':
899 corearg = optarg;
900 break;
901 case 'p':
902 pidarg = optarg;
903 break;
904 case 'x':
905 cmdarg_vec.emplace_back (CMDARG_FILE, optarg);
906 break;
907 case 'X':
908 cmdarg_vec.emplace_back (CMDARG_COMMAND, optarg);
909 break;
910 case OPT_IX:
911 cmdarg_vec.emplace_back (CMDARG_INIT_FILE, optarg);
912 break;
913 case OPT_IEX:
914 cmdarg_vec.emplace_back (CMDARG_INIT_COMMAND, optarg);
915 break;
916 case OPT_EIX:
917 cmdarg_vec.emplace_back (CMDARG_EARLYINIT_FILE, optarg);
918 break;
919 case OPT_EIEX:
920 cmdarg_vec.emplace_back (CMDARG_EARLYINIT_COMMAND, optarg);
921 break;
922 case 'B':
923 batch_flag = batch_silent = 1;
924 gdb_stdout = new null_file ();
925 break;
926 case 'D':
927 if (optarg[0] == '\0')
928 error (_("%s: empty path for `--data-directory'"),
929 gdb_program_name);
930 set_gdb_data_directory (optarg);
931 gdb_datadir_provided = 1;
932 break;
933 #ifdef GDBTK
934 case 'z':
935 {
936 if (!gdbtk_test (optarg))
937 error (_("%s: unable to load tclcommand file \"%s\""),
938 gdb_program_name, optarg);
939 break;
940 }
941 case 'y':
942 /* Backwards compatibility only. */
943 break;
944 case 'w':
945 {
946 /* Set the external editor commands when gdb is farming out files
947 to be edited by another program. */
948 external_editor_command = xstrdup (optarg);
949 break;
950 }
951 #endif /* GDBTK */
952 case 'i':
953 xfree (interpreter_p);
954 interpreter_p = xstrdup (optarg);
955 break;
956 case 'd':
957 dirarg.push_back (optarg);
958 break;
959 case 't':
960 ttyarg = optarg;
961 break;
962 case 'q':
963 quiet = 1;
964 break;
965 case 'b':
966 {
967 int rate;
968 char *p;
969
970 rate = strtol (optarg, &p, 0);
971 if (rate == 0 && p == optarg)
972 warning (_("could not set baud rate to `%s'."),
973 optarg);
974 else
975 baud_rate = rate;
976 }
977 break;
978 case 'l':
979 {
980 int timeout;
981 char *p;
982
983 timeout = strtol (optarg, &p, 0);
984 if (timeout == 0 && p == optarg)
985 warning (_("could not set timeout limit to `%s'."),
986 optarg);
987 else
988 remote_timeout = timeout;
989 }
990 break;
991
992 case OPT_READNOW:
993 {
994 readnow_symbol_files = 1;
995 validate_readnow_readnever ();
996 }
997 break;
998
999 case OPT_READNEVER:
1000 {
1001 readnever_symbol_files = 1;
1002 validate_readnow_readnever ();
1003 }
1004 break;
1005
1006 case '?':
1007 error (_("Use `%s --help' for a complete list of options."),
1008 gdb_program_name);
1009 }
1010 }
1011 write_files = (write_files_1 != 0);
1012
1013 if (batch_flag)
1014 {
1015 quiet = 1;
1016
1017 /* Disable all output styling when running in batch mode. */
1018 cli_styling = 0;
1019 }
1020 }
1021
1022 save_original_signals_state (quiet);
1023
1024 /* Try to set up an alternate signal stack for SIGSEGV handlers. */
1025 gdb::alternate_signal_stack signal_stack;
1026
1027 /* Initialize all files. */
1028 gdb_init ();
1029
1030 /* Process early init files and early init options from the command line. */
1031 if (!inhibit_gdbinit)
1032 {
1033 std::string home_gdbearlyinit;
1034 get_earlyinit_files (&home_gdbearlyinit);
1035 if (!home_gdbearlyinit.empty () && !inhibit_home_gdbinit)
1036 ret = catch_command_errors (source_script,
1037 home_gdbearlyinit.c_str (), 0);
1038 }
1039 execute_cmdargs (&cmdarg_vec, CMDARG_EARLYINIT_FILE,
1040 CMDARG_EARLYINIT_COMMAND, &ret);
1041
1042 /* Initialize the extension languages. */
1043 ext_lang_initialization ();
1044
1045 /* Recheck if we're starting up quietly after processing the startup
1046 scripts and commands. */
1047 if (!quiet)
1048 quiet = check_quiet_mode ();
1049
1050 /* Now that gdb_init has created the initial inferior, we're in
1051 position to set args for that inferior. */
1052 if (set_args)
1053 {
1054 /* The remaining options are the command-line options for the
1055 inferior. The first one is the sym/exec file, and the rest
1056 are arguments. */
1057 if (optind >= argc)
1058 error (_("%s: `--args' specified but no program specified"),
1059 gdb_program_name);
1060
1061 symarg = argv[optind];
1062 execarg = argv[optind];
1063 ++optind;
1064 set_inferior_args_vector (argc - optind, &argv[optind]);
1065 }
1066 else
1067 {
1068 /* OK, that's all the options. */
1069
1070 /* The first argument, if specified, is the name of the
1071 executable. */
1072 if (optind < argc)
1073 {
1074 symarg = argv[optind];
1075 execarg = argv[optind];
1076 optind++;
1077 }
1078
1079 /* If the user hasn't already specified a PID or the name of a
1080 core file, then a second optional argument is allowed. If
1081 present, this argument should be interpreted as either a
1082 PID or a core file, whichever works. */
1083 if (pidarg == NULL && corearg == NULL && optind < argc)
1084 {
1085 pid_or_core_arg = argv[optind];
1086 optind++;
1087 }
1088
1089 /* Any argument left on the command line is unexpected and
1090 will be ignored. Inform the user. */
1091 if (optind < argc)
1092 gdb_printf (gdb_stderr,
1093 _("Excess command line "
1094 "arguments ignored. (%s%s)\n"),
1095 argv[optind],
1096 (optind == argc - 1) ? "" : " ...");
1097 }
1098
1099 /* Lookup gdbinit files. Note that the gdbinit file name may be
1100 overridden during file initialization, so get_init_files should be
1101 called after gdb_init. */
1102 std::vector<std::string> system_gdbinit;
1103 std::string home_gdbinit;
1104 std::string local_gdbinit;
1105 get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
1106
1107 /* Do these (and anything which might call wrap_here or *_filtered)
1108 after initialize_all_files() but before the interpreter has been
1109 installed. Otherwize the help/version messages will be eaten by
1110 the interpreter's output handler. */
1111
1112 if (print_version)
1113 {
1114 print_gdb_version (gdb_stdout, false);
1115 gdb_printf ("\n");
1116 exit (0);
1117 }
1118
1119 if (print_help)
1120 {
1121 print_gdb_help (gdb_stdout);
1122 exit (0);
1123 }
1124
1125 if (print_configuration)
1126 {
1127 print_gdb_configuration (gdb_stdout);
1128 gdb_printf ("\n");
1129 exit (0);
1130 }
1131
1132 /* FIXME: cagney/2003-02-03: The big hack (part 1 of 2) that lets
1133 GDB retain the old MI1 interpreter startup behavior. Output the
1134 copyright message before the interpreter is installed. That way
1135 it isn't encapsulated in MI output. */
1136 if (!quiet && strcmp (interpreter_p, INTERP_MI1) == 0)
1137 {
1138 /* Print all the junk at the top, with trailing "..." if we are
1139 about to read a symbol file (possibly slowly). */
1140 print_gdb_version (gdb_stdout, true);
1141 if (symarg)
1142 gdb_printf ("..");
1143 gdb_printf ("\n");
1144 gdb_flush (gdb_stdout); /* Force to screen during slow
1145 operations. */
1146 }
1147
1148 /* Install the default UI. All the interpreters should have had a
1149 look at things by now. Initialize the default interpreter. */
1150 set_top_level_interpreter (interpreter_p);
1151
1152 /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets
1153 GDB retain the old MI1 interpreter startup behavior. Output the
1154 copyright message after the interpreter is installed when it is
1155 any sane interpreter. */
1156 if (!quiet && !current_interp_named_p (INTERP_MI1))
1157 {
1158 /* Print all the junk at the top, with trailing "..." if we are
1159 about to read a symbol file (possibly slowly). */
1160 print_gdb_version (gdb_stdout, true);
1161 if (symarg)
1162 gdb_printf ("..");
1163 gdb_printf ("\n");
1164 gdb_flush (gdb_stdout); /* Force to screen during slow
1165 operations. */
1166 }
1167
1168 /* Set off error and warning messages with a blank line. */
1169 tmp_warn_preprint.reset ();
1170 warning_pre_print = _("\nwarning: ");
1171
1172 /* Read and execute the system-wide gdbinit file, if it exists.
1173 This is done *before* all the command line arguments are
1174 processed; it sets global parameters, which are independent of
1175 what file you are debugging or what directory you are in. */
1176 if (!system_gdbinit.empty () && !inhibit_gdbinit)
1177 {
1178 for (const std::string &file : system_gdbinit)
1179 ret = catch_command_errors (source_script, file.c_str (), 0);
1180 }
1181
1182 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
1183 *before* all the command line arguments are processed; it sets
1184 global parameters, which are independent of what file you are
1185 debugging or what directory you are in. */
1186
1187 if (!home_gdbinit.empty () && !inhibit_gdbinit && !inhibit_home_gdbinit)
1188 ret = catch_command_errors (source_script, home_gdbinit.c_str (), 0);
1189
1190 /* Process '-ix' and '-iex' options early. */
1191 execute_cmdargs (&cmdarg_vec, CMDARG_INIT_FILE, CMDARG_INIT_COMMAND, &ret);
1192
1193 /* Now perform all the actions indicated by the arguments. */
1194 if (cdarg != NULL)
1195 {
1196 ret = catch_command_errors (cd_command, cdarg, 0);
1197 }
1198
1199 for (i = 0; i < dirarg.size (); i++)
1200 ret = catch_command_errors (directory_switch, dirarg[i], 0);
1201
1202 /* Skip auto-loading section-specified scripts until we've sourced
1203 local_gdbinit (which is often used to augment the source search
1204 path). */
1205 save_auto_load = global_auto_load;
1206 global_auto_load = 0;
1207
1208 if (execarg != NULL
1209 && symarg != NULL
1210 && strcmp (execarg, symarg) == 0)
1211 {
1212 /* The exec file and the symbol-file are the same. If we can't
1213 open it, better only print one error message.
1214 catch_command_errors returns non-zero on success! */
1215 ret = catch_command_errors (exec_file_attach, execarg,
1216 !batch_flag);
1217 if (ret != 0)
1218 ret = catch_command_errors (symbol_file_add_main_adapter,
1219 symarg, !batch_flag);
1220 }
1221 else
1222 {
1223 if (execarg != NULL)
1224 ret = catch_command_errors (exec_file_attach, execarg,
1225 !batch_flag);
1226 if (symarg != NULL)
1227 ret = catch_command_errors (symbol_file_add_main_adapter,
1228 symarg, !batch_flag);
1229 }
1230
1231 if (corearg && pidarg)
1232 error (_("Can't attach to process and specify "
1233 "a core file at the same time."));
1234
1235 if (corearg != NULL)
1236 {
1237 ret = catch_command_errors (core_file_command, corearg,
1238 !batch_flag);
1239 }
1240 else if (pidarg != NULL)
1241 {
1242 ret = catch_command_errors (attach_command, pidarg, !batch_flag);
1243 }
1244 else if (pid_or_core_arg)
1245 {
1246 /* The user specified 'gdb program pid' or gdb program core'.
1247 If pid_or_core_arg's first character is a digit, try attach
1248 first and then corefile. Otherwise try just corefile. */
1249
1250 if (isdigit (pid_or_core_arg[0]))
1251 {
1252 ret = catch_command_errors (attach_command, pid_or_core_arg,
1253 !batch_flag);
1254 if (ret == 0)
1255 ret = catch_command_errors (core_file_command,
1256 pid_or_core_arg,
1257 !batch_flag);
1258 }
1259 else
1260 {
1261 /* Can't be a pid, better be a corefile. */
1262 ret = catch_command_errors (core_file_command,
1263 pid_or_core_arg,
1264 !batch_flag);
1265 }
1266 }
1267
1268 if (ttyarg != NULL)
1269 current_inferior ()->set_tty (ttyarg);
1270
1271 /* Error messages should no longer be distinguished with extra output. */
1272 warning_pre_print = _("warning: ");
1273
1274 /* Read the .gdbinit file in the current directory, *if* it isn't
1275 the same as the $HOME/.gdbinit file (it should exist, also). */
1276 if (!local_gdbinit.empty ())
1277 {
1278 auto_load_local_gdbinit_pathname
1279 = gdb_realpath (local_gdbinit.c_str ()).release ();
1280
1281 if (!inhibit_gdbinit && auto_load_local_gdbinit)
1282 {
1283 auto_load_debug_printf ("Loading .gdbinit file \"%s\".",
1284 local_gdbinit.c_str ());
1285
1286 if (file_is_auto_load_safe (local_gdbinit.c_str ()))
1287 {
1288 auto_load_local_gdbinit_loaded = 1;
1289
1290 ret = catch_command_errors (source_script, local_gdbinit.c_str (), 0);
1291 }
1292 }
1293 }
1294
1295 /* Now that all .gdbinit's have been read and all -d options have been
1296 processed, we can read any scripts mentioned in SYMARG.
1297 We wait until now because it is common to add to the source search
1298 path in local_gdbinit. */
1299 global_auto_load = save_auto_load;
1300 for (objfile *objfile : current_program_space->objfiles ())
1301 load_auto_scripts_for_objfile (objfile);
1302
1303 /* Process '-x' and '-ex' options. */
1304 execute_cmdargs (&cmdarg_vec, CMDARG_FILE, CMDARG_COMMAND, &ret);
1305
1306 /* Read in the old history after all the command files have been
1307 read. */
1308 init_history ();
1309
1310 if (batch_flag)
1311 {
1312 int error_status = EXIT_FAILURE;
1313 int *exit_arg = ret == 0 ? &error_status : NULL;
1314
1315 /* We have hit the end of the batch file. */
1316 quit_force (exit_arg, 0);
1317 }
1318 }
1319
1320 static void
1321 captured_main (void *data)
1322 {
1323 struct captured_main_args *context = (struct captured_main_args *) data;
1324
1325 captured_main_1 (context);
1326
1327 /* NOTE: cagney/1999-11-07: There is probably no reason for not
1328 moving this loop and the code found in captured_command_loop()
1329 into the command_loop() proper. The main thing holding back that
1330 change - SET_TOP_LEVEL() - has been eliminated. */
1331 while (1)
1332 {
1333 try
1334 {
1335 captured_command_loop ();
1336 }
1337 catch (const gdb_exception &ex)
1338 {
1339 exception_print (gdb_stderr, ex);
1340 }
1341 }
1342 /* No exit -- exit is through quit_command. */
1343 }
1344
1345 int
1346 gdb_main (struct captured_main_args *args)
1347 {
1348 try
1349 {
1350 captured_main (args);
1351 }
1352 catch (const gdb_exception &ex)
1353 {
1354 exception_print (gdb_stderr, ex);
1355 }
1356
1357 /* The only way to end up here is by an error (normal exit is
1358 handled by quit_force()), hence always return an error status. */
1359 return 1;
1360 }
1361
1362
1363 /* Don't use *_filtered for printing help. We don't want to prompt
1364 for continue no matter how small the screen or how much we're going
1365 to print. */
1366
1367 static void
1368 print_gdb_help (struct ui_file *stream)
1369 {
1370 std::vector<std::string> system_gdbinit;
1371 std::string home_gdbinit;
1372 std::string local_gdbinit;
1373 std::string home_gdbearlyinit;
1374
1375 get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
1376 get_earlyinit_files (&home_gdbearlyinit);
1377
1378 /* Note: The options in the list below are only approximately sorted
1379 in the alphabetical order, so as to group closely related options
1380 together. */
1381 gdb_puts (_("\
1382 This is the GNU debugger. Usage:\n\n\
1383 gdb [options] [executable-file [core-file or process-id]]\n\
1384 gdb [options] --args executable-file [inferior-arguments ...]\n\n\
1385 "), stream);
1386 gdb_puts (_("\
1387 Selection of debuggee and its files:\n\n\
1388 --args Arguments after executable-file are passed to inferior.\n\
1389 --core=COREFILE Analyze the core dump COREFILE.\n\
1390 --exec=EXECFILE Use EXECFILE as the executable.\n\
1391 --pid=PID Attach to running process PID.\n\
1392 --directory=DIR Search for source files in DIR.\n\
1393 --se=FILE Use FILE as symbol file and executable file.\n\
1394 --symbols=SYMFILE Read symbols from SYMFILE.\n\
1395 --readnow Fully read symbol files on first access.\n\
1396 --readnever Do not read symbol files.\n\
1397 --write Set writing into executable and core files.\n\n\
1398 "), stream);
1399 gdb_puts (_("\
1400 Initial commands and command files:\n\n\
1401 --command=FILE, -x Execute GDB commands from FILE.\n\
1402 --init-command=FILE, -ix\n\
1403 Like -x but execute commands before loading inferior.\n\
1404 --eval-command=COMMAND, -ex\n\
1405 Execute a single GDB command.\n\
1406 May be used multiple times and in conjunction\n\
1407 with --command.\n\
1408 --init-eval-command=COMMAND, -iex\n\
1409 Like -ex but before loading inferior.\n\
1410 --nh Do not read ~/.gdbinit.\n\
1411 --nx Do not read any .gdbinit files in any directory.\n\n\
1412 "), stream);
1413 gdb_puts (_("\
1414 Output and user interface control:\n\n\
1415 --fullname Output information used by emacs-GDB interface.\n\
1416 --interpreter=INTERP\n\
1417 Select a specific interpreter / user interface.\n\
1418 --tty=TTY Use TTY for input/output by the program being debugged.\n\
1419 -w Use the GUI interface.\n\
1420 --nw Do not use the GUI interface.\n\
1421 "), stream);
1422 #if defined(TUI)
1423 gdb_puts (_("\
1424 --tui Use a terminal user interface.\n\
1425 "), stream);
1426 #endif
1427 gdb_puts (_("\
1428 -q, --quiet, --silent\n\
1429 Do not print version number on startup.\n\n\
1430 "), stream);
1431 gdb_puts (_("\
1432 Operating modes:\n\n\
1433 --batch Exit after processing options.\n\
1434 --batch-silent Like --batch, but suppress all gdb stdout output.\n\
1435 --return-child-result\n\
1436 GDB exit code will be the child's exit code.\n\
1437 --configuration Print details about GDB configuration and then exit.\n\
1438 --help Print this message and then exit.\n\
1439 --version Print version information and then exit.\n\n\
1440 Remote debugging options:\n\n\
1441 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
1442 -l TIMEOUT Set timeout in seconds for remote debugging.\n\n\
1443 Other options:\n\n\
1444 --cd=DIR Change current directory to DIR.\n\
1445 --data-directory=DIR, -D\n\
1446 Set GDB's data-directory to DIR.\n\
1447 "), stream);
1448 gdb_puts (_("\n\
1449 At startup, GDB reads the following early init files and executes their\n\
1450 commands:\n\
1451 "), stream);
1452 if (!home_gdbearlyinit.empty ())
1453 gdb_printf (stream, _("\
1454 * user-specific early init file: %s\n\
1455 "), home_gdbearlyinit.c_str ());
1456 if (home_gdbearlyinit.empty ())
1457 gdb_printf (stream, _("\
1458 None found.\n"));
1459 gdb_puts (_("\n\
1460 At startup, GDB reads the following init files and executes their commands:\n\
1461 "), stream);
1462 if (!system_gdbinit.empty ())
1463 {
1464 std::string output;
1465 for (size_t idx = 0; idx < system_gdbinit.size (); ++idx)
1466 {
1467 output += system_gdbinit[idx];
1468 if (idx < system_gdbinit.size () - 1)
1469 output += ", ";
1470 }
1471 gdb_printf (stream, _("\
1472 * system-wide init files: %s\n\
1473 "), output.c_str ());
1474 }
1475 if (!home_gdbinit.empty ())
1476 gdb_printf (stream, _("\
1477 * user-specific init file: %s\n\
1478 "), home_gdbinit.c_str ());
1479 if (!local_gdbinit.empty ())
1480 gdb_printf (stream, _("\
1481 * local init file (see also 'set auto-load local-gdbinit'): ./%s\n\
1482 "), local_gdbinit.c_str ());
1483 if (system_gdbinit.empty () && home_gdbinit.empty ()
1484 && local_gdbinit.empty ())
1485 gdb_printf (stream, _("\
1486 None found.\n"));
1487 gdb_puts (_("\n\
1488 For more information, type \"help\" from within GDB, or consult the\n\
1489 GDB manual (available as on-line info or a printed manual).\n\
1490 "), stream);
1491 if (REPORT_BUGS_TO[0] && stream == gdb_stdout)
1492 gdb_printf (stream, _("\n\
1493 Report bugs to %ps.\n\
1494 "), styled_string (file_name_style.style (), REPORT_BUGS_TO));
1495 if (stream == gdb_stdout)
1496 gdb_printf (stream, _("\n\
1497 You can ask GDB-related questions on the GDB users mailing list\n\
1498 (gdb@sourceware.org) or on GDB's IRC channel (#gdb on Freenode).\n"));
1499 }