/* Print and select stack frames for GDB, the GNU debugger.
- Copyright (C) 1986-2018 Free Software Foundation, Inc.
+ Copyright (C) 1986-2019 Free Software Foundation, Inc.
This file is part of GDB.
/* Prototypes for local functions. */
-static void print_frame_local_vars (struct frame_info *, int,
- struct ui_file *);
+static void print_frame_local_vars (struct frame_info *frame,
+ bool quiet,
+ const char *regexp, const char *t_regexp,
+ int num_tabs, struct ui_file *stream);
static void print_frame (struct frame_info *frame, int print_level,
enum print_what print_what, int print_args,
if (current_uiout->is_mi_like_p ())
print_what = LOC_AND_ADDRESS;
- TRY
+ try
{
print_frame_info (frame, print_level, print_what, 1 /* print_args */,
set_current_sal);
if (set_current_sal)
set_current_sal_from_frame (frame);
}
- CATCH (e, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &e)
{
}
- END_CATCH
}
/* Print nameless arguments of frame FRAME on STREAM, where START is
print_frame_arg (const struct frame_arg *arg)
{
struct ui_out *uiout = current_uiout;
- const char *error_message = NULL;
string_file stb;
if (arg->entry_kind == print_entry_values_only
|| arg->entry_kind == print_entry_values_compact)
stb.puts ("@entry");
- uiout->field_stream ("name", stb);
+ uiout->field_stream ("name", stb, ui_out_style_kind::VARIABLE);
annotate_arg_name_end ();
uiout->text ("=");
else
{
if (arg->error)
- error_message = arg->error;
+ stb.printf (_("<error reading variable: %s>"), arg->error);
else
{
- TRY
+ try
{
const struct language_defn *language;
struct value_print_options opts;
common_val_print (arg->val, &stb, 2, &opts, language);
}
- CATCH (except, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &except)
{
- error_message = except.message;
+ stb.printf (_("<error reading variable: %s>"),
+ except.what ());
}
- END_CATCH
}
- if (error_message != NULL)
- stb.printf (_("<error reading variable: %s>"), error_message);
}
uiout->field_stream ("value", stb);
argp->val = NULL;
argp->error = NULL;
- TRY
+ try
{
argp->val = read_var_value (sym, NULL, frame);
}
- CATCH (except, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &except)
{
- argp->error = xstrdup (except.message);
+ argp->error = xstrdup (except.what ());
}
- END_CATCH
}
/* Read in inferior function parameter SYM at FRAME into ARGP. Caller is
if (print_entry_values != print_entry_values_only
&& print_entry_values != print_entry_values_preferred)
{
- TRY
+ try
{
val = read_var_value (sym, NULL, frame);
}
- CATCH (except, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &except)
{
- val_error = (char *) alloca (strlen (except.message) + 1);
- strcpy (val_error, except.message);
+ val_error = (char *) alloca (except.message->size () + 1);
+ strcpy (val_error, except.what ());
}
- END_CATCH
}
if (SYMBOL_COMPUTED_OPS (sym) != NULL
&& (print_entry_values != print_entry_values_if_needed
|| !val || value_optimized_out (val)))
{
- TRY
+ try
{
const struct symbol_computed_ops *ops;
ops = SYMBOL_COMPUTED_OPS (sym);
entryval = ops->read_variable_at_entry (sym, frame);
}
- CATCH (except, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &except)
{
if (except.error != NO_ENTRY_VALUE_ERROR)
{
- entryval_error = (char *) alloca (strlen (except.message) + 1);
- strcpy (entryval_error, except.message);
+ entryval_error = (char *) alloca (except.message->size () + 1);
+ strcpy (entryval_error, except.what ());
}
}
- END_CATCH
if (entryval != NULL && value_optimized_out (entryval))
entryval = NULL;
value. If it is a reference still try to verify if
dereferenced DW_AT_call_data_value does not differ. */
- TRY
+ try
{
struct type *type_deref;
TYPE_LENGTH (type_deref)))
val_equal = 1;
}
- CATCH (except, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &except)
{
/* If the dereferenced content could not be
fetched do not display anything. */
val_equal = 1;
else if (except.message != NULL)
{
- entryval_error = (char *) alloca (strlen (except.message) + 1);
- strcpy (entryval_error, except.message);
+ entryval_error
+ = (char *) alloca (except.message->size () + 1);
+ strcpy (entryval_error, except.what ());
}
}
- END_CATCH
/* Value was not a reference; and its content matches. */
if (val == val_deref)
{
gdb_assert (val == NULL);
- TRY
+ try
{
val = read_var_value (sym, NULL, frame);
}
- CATCH (except, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &except)
{
- val_error = (char *) alloca (strlen (except.message) + 1);
- strcpy (val_error, except.message);
+ val_error = (char *) alloca (except.message->size () + 1);
+ strcpy (val_error, except.what ());
}
- END_CATCH
}
if (print_entry_values == print_entry_values_only
|| print_entry_values == print_entry_values_both
int how_many, CORE_ADDR low, CORE_ADDR high)
{
- TRY
+ try
{
gdb_disassembly (gdbarch, current_uiout,
DISASSEMBLY_RAW_INSN, how_many,
low, high);
}
- CATCH (exception, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &exception)
{
/* If an exception was thrown while doing the disassembly, print
the error message, to give the user a clue of what happened. */
exception_print (gdb_stderr, exception);
}
- END_CATCH
}
/* Print information about frame FRAME. The output is format according
if (get_frame_type (frame) == DUMMY_FRAME)
{
annotate_function_call ();
- uiout->field_string ("func", "<function called from gdb>");
+ uiout->field_string ("func", "<function called from gdb>",
+ ui_out_style_kind::FUNCTION);
}
else if (get_frame_type (frame) == SIGTRAMP_FRAME)
{
annotate_signal_handler_caller ();
- uiout->field_string ("func", "<signal handler called>");
+ uiout->field_string ("func", "<signal handler called>",
+ ui_out_style_kind::FUNCTION);
}
else if (get_frame_type (frame) == ARCH_FRAME)
{
- uiout->field_string ("func", "<cross-architecture call>");
+ uiout->field_string ("func", "<cross-architecture call>",
+ ui_out_style_kind::FUNCTION);
}
uiout->text ("\n");
annotate_frame_end ();
if (pc_p)
uiout->field_core_addr ("addr", gdbarch, pc);
else
- uiout->field_string ("addr", "<unavailable>");
+ uiout->field_string ("addr", "<unavailable>",
+ ui_out_style_kind::ADDRESS);
annotate_frame_address_end ();
uiout->text (" in ");
}
string_file stb;
fprintf_symbol_filtered (&stb, funname ? funname.get () : "??",
funlang, DMGL_ANSI);
- uiout->field_stream ("func", stb);
+ uiout->field_stream ("func", stb, ui_out_style_kind::FUNCTION);
uiout->wrap_hint (" ");
annotate_frame_args ();
-
+
uiout->text (" (");
if (print_args)
{
{
ui_out_emit_list list_emitter (uiout, "args");
- TRY
+ try
{
print_frame_args (func, frame, numargs, gdb_stdout);
}
- CATCH (e, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &e)
{
}
- END_CATCH
/* FIXME: ARGS must be a list. If one argument is a string it
will have " that will not be properly escaped. */
uiout->wrap_hint (" ");
uiout->text (" at ");
annotate_frame_source_file ();
- uiout->field_string ("file", filename_display);
+ uiout->field_string ("file", filename_display, ui_out_style_kind::FILE);
if (uiout->is_mi_like_p ())
{
const char *fullname = symtab_to_fullname (sal.symtab);
val_print_not_saved (gdb_stdout);
else
{
- TRY
+ try
{
caller_pc = frame_unwind_caller_pc (fi);
caller_pc_p = 1;
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
switch (ex.error)
{
val_print_not_saved (gdb_stdout);
break;
default:
- fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
+ fprintf_filtered (gdb_stdout, _("<error: %s>"),
+ ex.what ());
break;
}
}
- END_CATCH
}
if (caller_pc_p)
}
count = 0;
- numregs = gdbarch_num_regs (gdbarch)
- + gdbarch_num_pseudo_regs (gdbarch);
+ numregs = gdbarch_num_cooked_regs (gdbarch);
for (i = 0; i < numregs; i++)
if (i != sp_regnum
&& gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
void
select_frame_for_mi (struct frame_info *fi)
{
- select_frame_command_core (fi, FALSE /* Ignored. */);
+ select_frame_command_core (fi, false /* Ignored. */);
}
/* The core of all the "frame" sub-commands. Select frame FI, and if this
{
struct frame_id frame_id = get_frame_id (fi);
- print_frame_local_vars (fi, 1, gdb_stdout);
+ print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout);
/* print_frame_local_vars invalidates FI. */
fi = frame_find_by_id (frame_id);
struct print_variable_and_value_data
{
+ gdb::optional<compiled_regex> preg;
+ gdb::optional<compiled_regex> treg;
struct frame_id frame_id;
int num_tabs;
struct ui_file *stream;
= (struct print_variable_and_value_data *) cb_data;
struct frame_info *frame;
+ if (p->preg.has_value ()
+ && p->preg->exec (SYMBOL_NATURAL_NAME (sym), 0,
+ NULL, 0) != 0)
+ return;
+ if (p->treg.has_value ()
+ && !treg_matches_sym_type_name (*p->treg, sym))
+ return;
+
frame = frame_find_by_id (p->frame_id);
if (frame == NULL)
{
p->values_printed = 1;
}
+/* Prepares the regular expression REG from REGEXP.
+ If REGEXP is NULL, it results in an empty regular expression. */
+
+static void
+prepare_reg (const char *regexp, gdb::optional<compiled_regex> *reg)
+{
+ if (regexp != NULL)
+ {
+ int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off
+ ? REG_ICASE : 0);
+ reg->emplace (regexp, cflags, _("Invalid regexp"));
+ }
+ else
+ reg->reset ();
+}
+
/* Print all variables from the innermost up to the function block of FRAME.
Print them with values to STREAM indented by NUM_TABS.
+ If REGEXP is not NULL, only print local variables whose name
+ matches REGEXP.
+ If T_REGEXP is not NULL, only print local variables whose type
+ matches T_REGEXP.
+ If no local variables have been printed and !QUIET, prints a message
+ explaining why no local variables could be printed.
This function will invalidate FRAME. */
static void
-print_frame_local_vars (struct frame_info *frame, int num_tabs,
- struct ui_file *stream)
+print_frame_local_vars (struct frame_info *frame,
+ bool quiet,
+ const char *regexp, const char *t_regexp,
+ int num_tabs, struct ui_file *stream)
{
struct print_variable_and_value_data cb_data;
const struct block *block;
if (!get_frame_pc_if_available (frame, &pc))
{
- fprintf_filtered (stream,
- _("PC unavailable, cannot determine locals.\n"));
+ if (!quiet)
+ fprintf_filtered (stream,
+ _("PC unavailable, cannot determine locals.\n"));
return;
}
block = get_frame_block (frame, 0);
if (block == 0)
{
- fprintf_filtered (stream, "No symbol table info available.\n");
+ if (!quiet)
+ fprintf_filtered (stream, "No symbol table info available.\n");
return;
}
+ prepare_reg (regexp, &cb_data.preg);
+ prepare_reg (t_regexp, &cb_data.treg);
cb_data.frame_id = get_frame_id (frame);
cb_data.num_tabs = 4 * num_tabs;
cb_data.stream = stream;
do_print_variable_and_value,
&cb_data);
- if (!cb_data.values_printed)
- fprintf_filtered (stream, _("No locals.\n"));
+ if (!cb_data.values_printed && !quiet)
+ {
+ if (regexp == NULL && t_regexp == NULL)
+ fprintf_filtered (stream, _("No locals.\n"));
+ else
+ fprintf_filtered (stream, _("No matching locals.\n"));
+ }
}
void
info_locals_command (const char *args, int from_tty)
{
+ std::string regexp;
+ std::string t_regexp;
+ bool quiet = false;
+
+ while (args != NULL
+ && extract_info_print_args (&args, &quiet, ®exp, &t_regexp))
+ ;
+
+ if (args != NULL)
+ report_unrecognized_option_error ("info locals", args);
+
print_frame_local_vars (get_selected_frame (_("No frame selected.")),
+ quiet,
+ regexp.empty () ? NULL : regexp.c_str (),
+ t_regexp.empty () ? NULL : t_regexp.c_str (),
0, gdb_stdout);
}
/* Print all argument variables of the function of FRAME.
Print them with values to STREAM.
+ If REGEXP is not NULL, only print argument variables whose name
+ matches REGEXP.
+ If T_REGEXP is not NULL, only print argument variables whose type
+ matches T_REGEXP.
+ If no argument variables have been printed and !QUIET, prints a message
+ explaining why no argument variables could be printed.
This function will invalidate FRAME. */
static void
-print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
+print_frame_arg_vars (struct frame_info *frame,
+ bool quiet,
+ const char *regexp, const char *t_regexp,
+ struct ui_file *stream)
{
struct print_variable_and_value_data cb_data;
struct symbol *func;
CORE_ADDR pc;
+ gdb::optional<compiled_regex> preg;
+ gdb::optional<compiled_regex> treg;
if (!get_frame_pc_if_available (frame, &pc))
{
- fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n"));
+ if (!quiet)
+ fprintf_filtered (stream,
+ _("PC unavailable, cannot determine args.\n"));
return;
}
func = get_frame_function (frame);
if (func == NULL)
{
- fprintf_filtered (stream, _("No symbol table info available.\n"));
+ if (!quiet)
+ fprintf_filtered (stream, _("No symbol table info available.\n"));
return;
}
+ prepare_reg (regexp, &cb_data.preg);
+ prepare_reg (t_regexp, &cb_data.treg);
cb_data.frame_id = get_frame_id (frame);
cb_data.num_tabs = 0;
cb_data.stream = stream;
/* do_print_variable_and_value invalidates FRAME. */
frame = NULL;
- if (!cb_data.values_printed)
- fprintf_filtered (stream, _("No arguments.\n"));
+ if (!cb_data.values_printed && !quiet)
+ {
+ if (regexp == NULL && t_regexp == NULL)
+ fprintf_filtered (stream, _("No arguments.\n"));
+ else
+ fprintf_filtered (stream, _("No matching arguments.\n"));
+ }
}
void
-info_args_command (const char *ignore, int from_tty)
+info_args_command (const char *args, int from_tty)
{
+ std::string regexp;
+ std::string t_regexp;
+ bool quiet = false;
+
+ while (args != NULL
+ && extract_info_print_args (&args, &quiet, ®exp, &t_regexp))
+ ;
+
+ if (args != NULL)
+ report_unrecognized_option_error ("info args", args);
+
+
print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
+ quiet,
+ regexp.empty () ? NULL : regexp.c_str (),
+ t_regexp.empty () ? NULL : t_regexp.c_str (),
gdb_stdout);
}
\f
QUIT;
select_frame (fi);
- TRY
+ try
{
std::string cmd_result;
{
set to the selected frame. */
scoped_restore_current_thread restore_fi_current_frame;
- cmd_result = execute_command_to_string (cmd, from_tty);
+ cmd_result = execute_command_to_string
+ (cmd, from_tty, gdb_stdout->term_out ());
}
fi = get_selected_frame (_("frame apply "
"unable to get selected frame."));
printf_filtered ("%s", cmd_result.c_str ());
}
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
fi = get_selected_frame (_("frame apply "
"unable to get selected frame."));
if (!flags.quiet)
print_stack_frame (fi, 1, LOCATION, 0);
if (flags.cont)
- printf_filtered ("%s\n", ex.message);
+ printf_filtered ("%s\n", ex.what ());
else
- throw_exception (ex);
+ throw;
}
}
- END_CATCH;
}
}
&info_frame_cmd_list);
add_info ("locals", info_locals_command,
- _("Local variables of current stack frame."));
+ info_print_args_help (_("\
+All local variables of current stack frame or those matching REGEXPs.\n\
+Usage: info locals [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
+Prints the local variables of the current stack frame.\n"),
+ _("local variables")));
add_info ("args", info_args_command,
- _("Argument variables of current stack frame."));
+ info_print_args_help (_("\
+All argument variables of current stack frame or those matching REGEXPs.\n\
+Usage: info args [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
+Prints the argument variables of the current stack frame.\n"),
+ _("argument variables")));
if (dbx_commands)
add_com ("func", class_stack, func_command, _("\