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