/* Top level stuff for GDB, the GNU debugger.
- Copyright (C) 1986-2021 Free Software Foundation, Inc.
+ Copyright (C) 1986-2023 Free Software Foundation, Inc.
This file is part of GDB.
#include "observable.h"
#include "serial.h"
-/* The selected interpreter. This will be used as a set command
- variable, so it should always be malloc'ed - since
- do_setshow_command will free it. */
-char *interpreter_p;
-
-/* Whether dbx commands will be handled. */
-int dbx_commands = 0;
+/* The selected interpreter. */
+std::string interpreter_p;
/* System root path, used to find libraries etc. */
-char *gdb_sysroot = 0;
+std::string gdb_sysroot;
/* GDB datadir, used to store data files. */
std::string gdb_datadir;
{
int save_errno = errno;
- fprintf_unfiltered (gdb_stderr, "Warning: ");
+ gdb_printf (gdb_stderr, "Warning: ");
print_sys_errmsg (new_datadir, save_errno);
}
else if (!S_ISDIR (st.st_mode))
"../foo" and "../foo" doesn't exist then we'll record $(pwd)/../foo which
isn't canonical, but that's ok. */
if (!IS_ABSOLUTE_PATH (gdb_datadir.c_str ()))
- {
- gdb::unique_xmalloc_ptr<char> abs_datadir
- = gdb_abspath (gdb_datadir.c_str ());
-
- gdb_datadir = abs_datadir.get ();
- }
+ gdb_datadir = gdb_abspath (gdb_datadir.c_str ());
}
/* Relocate a file or directory. PROGNAME is the name by which gdb
/* Option type -ix. */
CMDARG_INIT_FILE,
-
+
/* Option type -iex. */
CMDARG_INIT_COMMAND,
- /* Option type -sx. */
+ /* Option type -eix. */
CMDARG_EARLYINIT_FILE,
- /* Option type -sex. */
+ /* Option type -eiex. */
CMDARG_EARLYINIT_COMMAND
};
main_ui = new ui (stdin, stdout, stderr);
current_ui = main_ui;
- gdb_stdtargerr = gdb_stderr; /* for moment */
- gdb_stdtargin = gdb_stdin; /* for moment */
+ gdb_stdtarg = gdb_stderr;
+ gdb_stdtargerr = gdb_stderr;
+ gdb_stdtargin = gdb_stdin;
if (bfd_init () != BFD_INIT_MAGIC)
error (_("fatal error: libbfd ABI mismatch"));
/* Prefix warning messages with the command name. */
gdb::unique_xmalloc_ptr<char> tmp_warn_preprint
- (xstrprintf ("%s: warning: ", gdb_program_name));
+ = xstrprintf ("%s: warning: ", gdb_program_name);
warning_pre_print = tmp_warn_preprint.get ();
current_directory = getcwd (NULL, 0);
perror_warning_with_name (_("error finding working directory"));
/* Set the sysroot path. */
- gdb_sysroot
- = xstrdup (relocate_gdb_directory (TARGET_SYSTEM_ROOT,
- TARGET_SYSTEM_ROOT_RELOCATABLE).c_str ());
+ gdb_sysroot = relocate_gdb_directory (TARGET_SYSTEM_ROOT,
+ TARGET_SYSTEM_ROOT_RELOCATABLE);
- if (*gdb_sysroot == '\0')
- {
- xfree (gdb_sysroot);
- gdb_sysroot = xstrdup (TARGET_SYSROOT_PREFIX);
- }
+ if (gdb_sysroot.empty ())
+ gdb_sysroot = TARGET_SYSROOT_PREFIX;
debug_file_directory
- = xstrdup (relocate_gdb_directory (DEBUGDIR,
- DEBUGDIR_RELOCATABLE).c_str ());
+ = relocate_gdb_directory (DEBUGDIR, DEBUGDIR_RELOCATABLE);
gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
GDB_DATADIR_RELOCATABLE);
this captured main, or one specified by the user at start up, or
the console. Initialize the interpreter to the one requested by
the application. */
- interpreter_p = xstrdup (context->interpreter_p);
+ interpreter_p = context->interpreter_p;
/* Parse arguments and options. */
{
static struct option long_options[] =
{
{"tui", no_argument, 0, OPT_TUI},
- {"dbx", no_argument, &dbx_commands, 1},
{"readnow", no_argument, NULL, OPT_READNOW},
{"readnever", no_argument, NULL, OPT_READNEVER},
{"r", no_argument, NULL, OPT_READNOW},
case OPT_TUI:
/* --tui is equivalent to -i=tui. */
#ifdef TUI
- xfree (interpreter_p);
- interpreter_p = xstrdup (INTERP_TUI);
+ interpreter_p = INTERP_TUI;
#else
error (_("%s: TUI mode is not supported"), gdb_program_name);
#endif
actually useful, and if it is, what it should do. */
#ifdef GDBTK
/* --windows is equivalent to -i=insight. */
- xfree (interpreter_p);
- interpreter_p = xstrdup (INTERP_INSIGHT);
+ interpreter_p = INTERP_INSIGHT;
#endif
break;
case OPT_NOWINDOWS:
/* -nw is equivalent to -i=console. */
- xfree (interpreter_p);
- interpreter_p = xstrdup (INTERP_CONSOLE);
+ interpreter_p = INTERP_CONSOLE;
break;
case 'f':
annotation_level = 1;
}
#endif /* GDBTK */
case 'i':
- xfree (interpreter_p);
- interpreter_p = xstrdup (optarg);
+ interpreter_p = optarg;
break;
case 'd':
dirarg.push_back (optarg);
gdb::alternate_signal_stack signal_stack;
/* Initialize all files. */
- gdb_init (gdb_program_name);
+ gdb_init ();
/* Process early init files and early init options from the command line. */
if (!inhibit_gdbinit)
execute_cmdargs (&cmdarg_vec, CMDARG_EARLYINIT_FILE,
CMDARG_EARLYINIT_COMMAND, &ret);
+ /* Initialize the extension languages. */
+ ext_lang_initialization ();
+
+ /* Recheck if we're starting up quietly after processing the startup
+ scripts and commands. */
+ if (!quiet)
+ quiet = check_quiet_mode ();
+
/* Now that gdb_init has created the initial inferior, we're in
position to set args for that inferior. */
if (set_args)
/* Any argument left on the command line is unexpected and
will be ignored. Inform the user. */
if (optind < argc)
- fprintf_unfiltered (gdb_stderr,
- _("Excess command line "
- "arguments ignored. (%s%s)\n"),
- argv[optind],
- (optind == argc - 1) ? "" : " ...");
+ gdb_printf (gdb_stderr,
+ _("Excess command line "
+ "arguments ignored. (%s%s)\n"),
+ argv[optind],
+ (optind == argc - 1) ? "" : " ...");
}
/* Lookup gdbinit files. Note that the gdbinit file name may be
if (print_version)
{
print_gdb_version (gdb_stdout, false);
- wrap_here ("");
- printf_filtered ("\n");
+ gdb_printf ("\n");
exit (0);
}
if (print_configuration)
{
print_gdb_configuration (gdb_stdout);
- wrap_here ("");
- printf_filtered ("\n");
+ gdb_printf ("\n");
exit (0);
}
- /* FIXME: cagney/2003-02-03: The big hack (part 1 of 2) that lets
- GDB retain the old MI1 interpreter startup behavior. Output the
- copyright message before the interpreter is installed. That way
- it isn't encapsulated in MI output. */
- if (!quiet && strcmp (interpreter_p, INTERP_MI1) == 0)
- {
- /* Print all the junk at the top, with trailing "..." if we are
- about to read a symbol file (possibly slowly). */
- print_gdb_version (gdb_stdout, true);
- if (symarg)
- printf_filtered ("..");
- wrap_here ("");
- printf_filtered ("\n");
- gdb_flush (gdb_stdout); /* Force to screen during slow
- operations. */
- }
-
/* Install the default UI. All the interpreters should have had a
look at things by now. Initialize the default interpreter. */
- set_top_level_interpreter (interpreter_p);
+ set_top_level_interpreter (interpreter_p.c_str ());
- /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets
- GDB retain the old MI1 interpreter startup behavior. Output the
- copyright message after the interpreter is installed when it is
- any sane interpreter. */
- if (!quiet && !current_interp_named_p (INTERP_MI1))
+ if (!quiet)
{
/* Print all the junk at the top, with trailing "..." if we are
about to read a symbol file (possibly slowly). */
print_gdb_version (gdb_stdout, true);
if (symarg)
- printf_filtered ("..");
- wrap_here ("");
- printf_filtered ("\n");
+ gdb_printf ("..");
+ gdb_printf ("\n");
gdb_flush (gdb_stdout); /* Force to screen during slow
operations. */
}
/* Note: The options in the list below are only approximately sorted
in the alphabetical order, so as to group closely related options
together. */
- fputs_unfiltered (_("\
+ gdb_puts (_("\
This is the GNU debugger. Usage:\n\n\
gdb [options] [executable-file [core-file or process-id]]\n\
gdb [options] --args executable-file [inferior-arguments ...]\n\n\
"), stream);
- fputs_unfiltered (_("\
+ gdb_puts (_("\
Selection of debuggee and its files:\n\n\
--args Arguments after executable-file are passed to inferior.\n\
--core=COREFILE Analyze the core dump COREFILE.\n\
--readnever Do not read symbol files.\n\
--write Set writing into executable and core files.\n\n\
"), stream);
- fputs_unfiltered (_("\
+ gdb_puts (_("\
Initial commands and command files:\n\n\
--command=FILE, -x Execute GDB commands from FILE.\n\
--init-command=FILE, -ix\n\
--nh Do not read ~/.gdbinit.\n\
--nx Do not read any .gdbinit files in any directory.\n\n\
"), stream);
- fputs_unfiltered (_("\
+ gdb_puts (_("\
Output and user interface control:\n\n\
--fullname Output information used by emacs-GDB interface.\n\
--interpreter=INTERP\n\
--nw Do not use the GUI interface.\n\
"), stream);
#if defined(TUI)
- fputs_unfiltered (_("\
+ gdb_puts (_("\
--tui Use a terminal user interface.\n\
"), stream);
#endif
- fputs_unfiltered (_("\
- --dbx DBX compatibility mode.\n\
+ gdb_puts (_("\
-q, --quiet, --silent\n\
Do not print version number on startup.\n\n\
"), stream);
- fputs_unfiltered (_("\
+ gdb_puts (_("\
Operating modes:\n\n\
--batch Exit after processing options.\n\
--batch-silent Like --batch, but suppress all gdb stdout output.\n\
--data-directory=DIR, -D\n\
Set GDB's data-directory to DIR.\n\
"), stream);
- fputs_unfiltered (_("\n\
+ gdb_puts (_("\n\
At startup, GDB reads the following early init files and executes their\n\
commands:\n\
"), stream);
if (!home_gdbearlyinit.empty ())
- fprintf_unfiltered (stream, _("\
+ gdb_printf (stream, _("\
* user-specific early init file: %s\n\
"), home_gdbearlyinit.c_str ());
if (home_gdbearlyinit.empty ())
- fprintf_unfiltered (stream, _("\
+ gdb_printf (stream, _("\
None found.\n"));
- fputs_unfiltered (_("\n\
+ gdb_puts (_("\n\
At startup, GDB reads the following init files and executes their commands:\n\
"), stream);
if (!system_gdbinit.empty ())
if (idx < system_gdbinit.size () - 1)
output += ", ";
}
- fprintf_unfiltered (stream, _("\
+ gdb_printf (stream, _("\
* system-wide init files: %s\n\
"), output.c_str ());
}
if (!home_gdbinit.empty ())
- fprintf_unfiltered (stream, _("\
+ gdb_printf (stream, _("\
* user-specific init file: %s\n\
"), home_gdbinit.c_str ());
if (!local_gdbinit.empty ())
- fprintf_unfiltered (stream, _("\
+ gdb_printf (stream, _("\
* local init file (see also 'set auto-load local-gdbinit'): ./%s\n\
"), local_gdbinit.c_str ());
if (system_gdbinit.empty () && home_gdbinit.empty ()
&& local_gdbinit.empty ())
- fprintf_unfiltered (stream, _("\
+ gdb_printf (stream, _("\
None found.\n"));
- fputs_unfiltered (_("\n\
+ gdb_puts (_("\n\
For more information, type \"help\" from within GDB, or consult the\n\
GDB manual (available as on-line info or a printed manual).\n\
"), stream);
if (REPORT_BUGS_TO[0] && stream == gdb_stdout)
- fprintf_unfiltered (stream, _("\n\
-Report bugs to %s.\n\
-"), REPORT_BUGS_TO);
+ gdb_printf (stream, _("\n\
+Report bugs to %ps.\n\
+"), styled_string (file_name_style.style (), REPORT_BUGS_TO));
if (stream == gdb_stdout)
- fprintf_unfiltered (stream, _("\n\
+ gdb_printf (stream, _("\n\
You can ask GDB-related questions on the GDB users mailing list\n\
(gdb@sourceware.org) or on GDB's IRC channel (#gdb on Freenode).\n"));
}