/* Top level stuff for GDB, the GNU debugger.
- Copyright (C) 1986-2016 Free Software Foundation, Inc.
+ Copyright (C) 1986-2017 Free Software Foundation, Inc.
This file is part of GDB.
warning (_("%s is not a directory."), new_datadir);
xfree (gdb_datadir);
- gdb_datadir = gdb_realpath (new_datadir);
+ gdb_datadir = gdb_realpath (new_datadir).release ();
/* gdb_realpath won't return an absolute path if the path doesn't exist,
but we still want to record an absolute path here. If the user entered
isn't canonical, but that's ok. */
if (!IS_ABSOLUTE_PATH (gdb_datadir))
{
- char *abs_datadir = gdb_abspath (gdb_datadir);
+ gdb::unique_xmalloc_ptr<char> abs_datadir = gdb_abspath (gdb_datadir);
xfree (gdb_datadir);
- gdb_datadir = abs_datadir;
+ gdb_datadir = abs_datadir.release ();
}
}
{
/* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
to gdb_datadir. */
- char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
+ char *tmp_sys_gdbinit = xstrdup (&SYSTEM_GDBINIT[datadir_len]);
char *p;
for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p)
#endif
}
-/* Call command_loop. If it happens to return, pass that through as a
- non-zero return status. */
+/* Call command_loop. */
-static int
-captured_command_loop (void *data)
+static void
+captured_command_loop ()
{
struct ui *ui = current_ui;
check to detect bad FUNCs code. */
do_cleanups (all_cleanups ());
/* If the command_loop returned, normally (rather than threw an
- error) we try to quit. If the quit is aborted, catch_errors()
- which called this catch the signal and restart the command
- loop. */
+ error) we try to quit. If the quit is aborted, our caller
+ catches the signal and restarts the command loop. */
quit_command (NULL, ui->instream == ui->stdin_stream);
- return 1;
}
-/* Handle command errors thrown from within
- catch_command_errors/catch_command_errors_const. */
+/* Handle command errors thrown from within catch_command_errors. */
static int
handle_command_errors (struct gdb_exception e)
return 1;
}
-/* Type of the command callback passed to catch_command_errors_const. */
+/* Type of the command callback passed to the const
+ catch_command_errors. */
typedef void (catch_command_errors_const_ftype) (const char *, int);
-/* Like catch_command_errors, but works with const command and args. */
+/* Const-correct catch_command_errors. */
static int
-catch_command_errors_const (catch_command_errors_const_ftype *command,
- const char *arg, int from_tty)
+catch_command_errors (catch_command_errors_const_ftype command,
+ const char *arg, int from_tty)
{
TRY
{
};
/* Arguments of --command option and its counterpart. */
-struct cmdarg {
+struct cmdarg
+{
+ cmdarg (cmdarg_kind type_, char *string_)
+ : type (type_), string (string_)
+ {}
+
/* Type of this option. */
enum cmdarg_kind type;
int save_auto_load;
struct objfile *objfile;
- struct cleanup *chain;
-
#ifdef HAVE_SBRK
/* Set this before constructing scoped_command_stats. */
lim_at_start = (char *) sbrk (0);
setvbuf (stderr, NULL, _IONBF, BUFSIZ);
#endif
- main_ui = new_ui (stdin, stdout, stderr);
+ main_ui = new ui (stdin, stdout, stderr);
current_ui = main_ui;
gdb_stdtargerr = gdb_stderr; /* for moment */
#endif
/* Prefix warning messages with the command name. */
- warning_pre_print = xstrprintf ("%s: warning: ", gdb_program_name);
+ gdb::unique_xmalloc_ptr<char> tmp_warn_preprint
+ (xstrprintf ("%s: warning: ", gdb_program_name));
+ warning_pre_print = tmp_warn_preprint.get ();
- if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
+ current_directory = getcwd (NULL, 0);
+ if (current_directory == NULL)
perror_warning_with_name (_("error finding working directory"));
- current_directory = gdb_dirbuf;
-
/* Set the sysroot path. */
gdb_sysroot = relocate_gdb_directory (TARGET_SYSTEM_ROOT,
TARGET_SYSTEM_ROOT_RELOCATABLE);
pidarg = optarg;
break;
case 'x':
- {
- struct cmdarg cmdarg = { CMDARG_FILE, optarg };
-
- cmdarg_vec.push_back (cmdarg);
- }
+ cmdarg_vec.emplace_back (CMDARG_FILE, optarg);
break;
case 'X':
- {
- struct cmdarg cmdarg = { CMDARG_COMMAND, optarg };
-
- cmdarg_vec.push_back (cmdarg);
- }
+ cmdarg_vec.emplace_back (CMDARG_COMMAND, optarg);
break;
case OPT_IX:
- {
- struct cmdarg cmdarg = { CMDARG_INIT_FILE, optarg };
-
- cmdarg_vec.push_back (cmdarg);
- }
+ cmdarg_vec.emplace_back (CMDARG_INIT_FILE, optarg);
break;
case OPT_IEX:
- {
- struct cmdarg cmdarg = { CMDARG_INIT_COMMAND, optarg };
-
- cmdarg_vec.push_back (cmdarg);
- }
+ cmdarg_vec.emplace_back (CMDARG_INIT_COMMAND, optarg);
break;
case 'B':
batch_flag = batch_silent = 1;
- gdb_stdout = ui_file_new();
+ gdb_stdout = new null_file ();
break;
case 'D':
if (optarg[0] == '\0')
}
/* Set off error and warning messages with a blank line. */
- xfree (warning_pre_print);
+ tmp_warn_preprint.reset ();
warning_pre_print = _("\nwarning: ");
/* Read and execute the system-wide gdbinit file, if it exists.
processed; it sets global parameters, which are independent of
what file you are debugging or what directory you are in. */
if (system_gdbinit && !inhibit_gdbinit)
- catch_command_errors_const (source_script, system_gdbinit, 0);
+ catch_command_errors (source_script, system_gdbinit, 0);
/* Read and execute $HOME/.gdbinit file, if it exists. This is done
*before* all the command line arguments are processed; it sets
debugging or what directory you are in. */
if (home_gdbinit && !inhibit_gdbinit && !inhibit_home_gdbinit)
- catch_command_errors_const (source_script, home_gdbinit, 0);
+ catch_command_errors (source_script, home_gdbinit, 0);
/* Process '-ix' and '-iex' options early. */
for (i = 0; i < cmdarg_vec.size (); i++)
switch (cmdarg_p.type)
{
case CMDARG_INIT_FILE:
- catch_command_errors_const (source_script, cmdarg_p.string,
- !batch_flag);
+ catch_command_errors (source_script, cmdarg_p.string,
+ !batch_flag);
break;
case CMDARG_INIT_COMMAND:
catch_command_errors (execute_command, cmdarg_p.string,
/* The exec file and the symbol-file are the same. If we can't
open it, better only print one error message.
catch_command_errors returns non-zero on success! */
- if (catch_command_errors_const (exec_file_attach, execarg,
- !batch_flag))
- catch_command_errors_const (symbol_file_add_main_adapter, symarg,
- !batch_flag);
+ if (catch_command_errors (exec_file_attach, execarg,
+ !batch_flag))
+ catch_command_errors (symbol_file_add_main_adapter, symarg,
+ !batch_flag);
}
else
{
if (execarg != NULL)
- catch_command_errors_const (exec_file_attach, execarg,
- !batch_flag);
+ catch_command_errors (exec_file_attach, execarg,
+ !batch_flag);
if (symarg != NULL)
- catch_command_errors_const (symbol_file_add_main_adapter, symarg,
- !batch_flag);
+ catch_command_errors (symbol_file_add_main_adapter, symarg,
+ !batch_flag);
}
if (corearg && pidarg)
the same as the $HOME/.gdbinit file (it should exist, also). */
if (local_gdbinit)
{
- auto_load_local_gdbinit_pathname = gdb_realpath (local_gdbinit);
+ auto_load_local_gdbinit_pathname
+ = gdb_realpath (local_gdbinit).release ();
if (!inhibit_gdbinit && auto_load_local_gdbinit
&& file_is_auto_load_safe (local_gdbinit,
{
auto_load_local_gdbinit_loaded = 1;
- catch_command_errors_const (source_script, local_gdbinit, 0);
+ catch_command_errors (source_script, local_gdbinit, 0);
}
}
switch (cmdarg_p.type)
{
case CMDARG_FILE:
- catch_command_errors_const (source_script, cmdarg_p.string,
- !batch_flag);
+ catch_command_errors (source_script, cmdarg_p.string,
+ !batch_flag);
break;
case CMDARG_COMMAND:
catch_command_errors (execute_command, cmdarg_p.string,
change - SET_TOP_LEVEL() - has been eliminated. */
while (1)
{
- catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
+ TRY
+ {
+ captured_command_loop ();
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ exception_print (gdb_stderr, ex);
+ }
+ END_CATCH
}
/* No exit -- exit is through quit_command. */
}