/* Ada language support routines for GDB, the GNU debugger.
- Copyright (C) 1992-2016 Free Software Foundation, Inc.
+ Copyright (C) 1992-2017 Free Software Foundation, Inc.
This file is part of GDB.
#include "mi/mi-common.h"
#include "arch-utils.h"
#include "cli/cli-utils.h"
+#include "common/function-view.h"
/* Define whether or not the C operator '/' truncates towards zero for
differently signed operands (truncation direction is undefined in C).
static int possible_user_operator_p (enum exp_opcode, struct value **);
-static char *ada_op_name (enum exp_opcode);
+static const char *ada_op_name (enum exp_opcode);
static const char *ada_decoded_op_name (enum exp_opcode);
static struct symbol *find_old_style_renaming_symbol (const char *,
const struct block *);
-static struct type *ada_lookup_struct_elt_type (struct type *, char *,
+static struct type *ada_lookup_struct_elt_type (struct type *, const char *,
int, int, int *);
static struct value *evaluate_subexp_type (struct expression *, int *);
/* Maximum-sized dynamic type. */
static unsigned int varsize_limit;
-/* FIXME: brobecker/2003-09-17: No longer a const because it is
- returned by a function that does not return a const char *. */
-static char *ada_completer_word_break_characters =
+static const char ada_completer_word_break_characters[] =
#ifdef VMS
" \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
#else
return result;
}
-static char *
+static const char *
ada_get_gdb_completer_word_break_characters (void)
{
return ada_completer_word_break_characters;
/* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */
-static char *bound_name[] = {
+static const char *bound_name[] = {
"LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
"LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
};
int
get_selections (int *choices, int n_choices, int max_results,
- int is_all_choice, char *annotation_suffix)
+ int is_all_choice, const char *annotation_suffix)
{
char *args;
- char *prompt;
+ const char *prompt;
int n_chosen;
int first_choice = is_all_choice ? 2 : 1;
/* Implementation of the la_iterate_over_symbols method. */
static void
-ada_iterate_over_symbols (const struct block *block,
- const char *name, domain_enum domain,
- symbol_found_callback_ftype *callback,
- void *data)
+ada_iterate_over_symbols
+ (const struct block *block, const char *name, domain_enum domain,
+ gdb::function_view<symbol_found_callback_ftype> callback)
{
int ndefs, i;
struct block_symbol *results;
ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
for (i = 0; i < ndefs; ++i)
{
- if (! (*callback) (results[i].symbol, data))
+ if (!callback (results[i].symbol))
break;
}
}
VEC_safe_push (char_ptr, *sv, completion);
}
-/* An object of this type is passed as the user_data argument to the
- expand_symtabs_matching method. */
-struct add_partial_datum
-{
- VEC(char_ptr) **completions;
- const char *text;
- int text_len;
- const char *text0;
- const char *word;
- int wild_match;
- int encoded;
-};
-
-/* A callback for expand_symtabs_matching. */
-
-static int
-ada_complete_symbol_matcher (const char *name, void *user_data)
-{
- struct add_partial_datum *data = (struct add_partial_datum *) user_data;
-
- return symbol_completion_match (name, data->text, data->text_len,
- data->wild_match, data->encoded) != NULL;
-}
-
/* Return a list of possible symbol names completing TEXT0. WORD is
the entire command on which completion is made. */
}
/* First, look at the partial symtab symbols. */
- {
- struct add_partial_datum data;
-
- data.completions = &completions;
- data.text = text;
- data.text_len = text_len;
- data.text0 = text0;
- data.word = word;
- data.wild_match = wild_match_p;
- data.encoded = encoded_p;
- expand_symtabs_matching (NULL, ada_complete_symbol_matcher, NULL,
- ALL_DOMAIN, &data);
- }
+ expand_symtabs_matching (NULL,
+ [&] (const char *symname)
+ {
+ return symbol_completion_match (symname,
+ text, text_len,
+ wild_match_p,
+ encoded_p);
+ },
+ NULL,
+ ALL_DOMAIN);
/* At this point scan through the misc symbol vectors and add each
symbol you find to the list. Eventually we want to ignore
struct type *
ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
{
- char *name = ada_variant_discrim_name (var_type);
+ const char *name = ada_variant_discrim_name (var_type);
return ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL);
}
returns the name of the discriminant controlling the variant.
The value is valid until the next call to ada_variant_discrim_name. */
-char *
+const char *
ada_variant_discrim_name (struct type *type0)
{
static char *result = NULL;
calling error. */
struct value *
-ada_value_struct_elt (struct value *arg, char *name, int no_err)
+ada_value_struct_elt (struct value *arg, const char *name, int no_err)
{
struct type *t, *t1;
struct value *v;
static std::string
type_as_string (struct type *type)
{
- struct ui_file *tmp_stream = mem_fileopen ();
- struct cleanup *old_chain;
+ string_file tmp_stream;
- tmp_stream = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (tmp_stream);
+ type_print (type, "", &tmp_stream, -1);
- type_print (type, "", tmp_stream, -1);
- std::string str = ui_file_as_string (tmp_stream);
-
- do_cleanups (old_chain);
- return str;
+ return std::move (tmp_stream.string ());
}
/* Given a type TYPE, look up the type of the component of type named NAME.
TYPE is not a type of the right kind. */
static struct type *
-ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
+ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
int noerr, int *dispp)
{
int i;
static int
is_unchecked_variant (struct type *var_type, struct type *outer_type)
{
- char *discrim_name = ada_variant_discrim_name (var_type);
+ const char *discrim_name = ada_variant_discrim_name (var_type);
return (ada_lookup_struct_elt_type (outer_type, discrim_name, 0, 1, NULL)
== NULL);
{
int others_clause;
int i;
- char *discrim_name = ada_variant_discrim_name (var_type);
+ const char *discrim_name = ada_variant_discrim_name (var_type);
struct value *outer;
struct value *discrim;
LONGEST discrim_val;
should return a ref as it should be valid to ask
for its address; so rebuild a ref after coerce. */
arg1 = ada_coerce_ref (arg1);
- return value_ref (arg1);
+ return value_ref (arg1, TYPE_CODE_REF);
}
}
an Ada83 compiler). As such, we do not include Numeric_Error from
this list of standard exceptions. */
-static char *standard_exc[] = {
+static const char *standard_exc[] = {
"constraint_error",
"program_error",
"storage_error",
annotate_catchpoint (b->number);
- if (ui_out_is_mi_like_p (uiout))
+ if (uiout->is_mi_like_p ())
{
- ui_out_field_string (uiout, "reason",
+ uiout->field_string ("reason",
async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
- ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
+ uiout->field_string ("disp", bpdisp_text (b->disposition));
}
- ui_out_text (uiout,
- b->disposition == disp_del ? "\nTemporary catchpoint "
- : "\nCatchpoint ");
- ui_out_field_int (uiout, "bkptno", b->number);
- ui_out_text (uiout, ", ");
+ uiout->text (b->disposition == disp_del
+ ? "\nTemporary catchpoint " : "\nCatchpoint ");
+ uiout->field_int ("bkptno", b->number);
+ uiout->text (", ");
/* ada_exception_name_addr relies on the selected frame being the
current frame. Need to do this here because this function may be
hit. We used ui_out_text to make sure that this extra
info does not pollute the exception name in the MI case. */
if (ex == ada_catch_exception_unhandled)
- ui_out_text (uiout, "unhandled ");
- ui_out_field_string (uiout, "exception-name", exception_name);
+ uiout->text ("unhandled ");
+ uiout->field_string ("exception-name", exception_name);
}
break;
case ada_catch_assert:
that his program just hit an assertion-failure catchpoint.
We used ui_out_text because this info does not belong in
the MI output. */
- ui_out_text (uiout, "failed assertion");
+ uiout->text ("failed assertion");
break;
}
- ui_out_text (uiout, " at ");
+ uiout->text (" at ");
ada_find_printable_frame (get_current_frame ());
return PRINT_SRC_AND_LOC;
if (opts.addressprint)
{
annotate_field (4);
- ui_out_field_core_addr (uiout, "addr", b->loc->gdbarch, b->loc->address);
+ uiout->field_core_addr ("addr", b->loc->gdbarch, b->loc->address);
}
annotate_field (5);
{
char *msg = xstrprintf (_("`%s' Ada exception"), c->excep_string);
- ui_out_field_string (uiout, "what", msg);
+ uiout->field_string ("what", msg);
xfree (msg);
}
else
- ui_out_field_string (uiout, "what", "all Ada exceptions");
+ uiout->field_string ("what", "all Ada exceptions");
break;
case ada_catch_exception_unhandled:
- ui_out_field_string (uiout, "what", "unhandled Ada exceptions");
+ uiout->field_string ("what", "unhandled Ada exceptions");
break;
case ada_catch_assert:
- ui_out_field_string (uiout, "what", "failed Ada assertions");
+ uiout->field_string ("what", "failed Ada assertions");
break;
default:
struct ada_catchpoint *c = (struct ada_catchpoint *) b;
struct ui_out *uiout = current_uiout;
- ui_out_text (uiout, b->disposition == disp_del ? _("Temporary catchpoint ")
+ uiout->text (b->disposition == disp_del ? _("Temporary catchpoint ")
: _("Catchpoint "));
- ui_out_field_int (uiout, "bkptno", b->number);
- ui_out_text (uiout, ": ");
+ uiout->field_int ("bkptno", b->number);
+ uiout->text (": ");
switch (ex)
{
char *info = xstrprintf (_("`%s' Ada exception"), c->excep_string);
struct cleanup *old_chain = make_cleanup (xfree, info);
- ui_out_text (uiout, info);
+ uiout->text (info);
do_cleanups (old_chain);
}
else
- ui_out_text (uiout, _("all Ada exceptions"));
+ uiout->text (_("all Ada exceptions"));
break;
case ada_catch_exception_unhandled:
- ui_out_text (uiout, _("unhandled Ada exceptions"));
+ uiout->text (_("unhandled Ada exceptions"));
break;
case ada_catch_assert:
- ui_out_text (uiout, _("failed Ada assertions"));
+ uiout->text (_("failed Ada assertions"));
break;
default:
Return NULL if ARGPS does not contain any more tokens. */
static char *
-ada_get_next_arg (char **argsp)
+ada_get_next_arg (const char **argsp)
{
- char *args = *argsp;
- char *end;
+ const char *args = *argsp;
+ const char *end;
char *result;
- args = skip_spaces (args);
+ args = skip_spaces_const (args);
if (args[0] == '\0')
return NULL; /* No more arguments. */
/* Find the end of the current argument. */
- end = skip_to_space (args);
+ end = skip_to_space_const (args);
/* Adjust ARGSP to point to the start of the next argument. */
after use). Otherwise COND_STRING is set to NULL. */
static void
-catch_ada_exception_command_split (char *args,
+catch_ada_exception_command_split (const char *args,
enum ada_exception_catchpoint_kind *ex,
char **excep_string,
char **cond_string)
/* Check to see if we have a condition. */
- args = skip_spaces (args);
+ args = skip_spaces_const (args);
if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
- args = skip_spaces (args);
+ args = skip_spaces_const (args);
if (args[0] == '\0')
error (_("Condition missing after `if' keyword"));
/* Implement the "catch exception" command. */
static void
-catch_ada_exception_command (char *arg, int from_tty,
+catch_ada_exception_command (char *arg_entry, int from_tty,
struct cmd_list_element *command)
{
+ const char *arg = arg_entry;
struct gdbarch *gdbarch = get_current_arch ();
int tempflag;
enum ada_exception_catchpoint_kind ex_kind;
(the memory needs to be deallocated after use). */
static void
-catch_ada_assert_command_split (char *args, char **cond_string)
+catch_ada_assert_command_split (const char *args, char **cond_string)
{
- args = skip_spaces (args);
+ args = skip_spaces_const (args);
/* Check whether a condition was provided. */
if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
- args = skip_spaces (args);
+ args = skip_spaces_const (args);
if (args[0] == '\0')
error (_("condition missing after `if' keyword"));
*cond_string = xstrdup (args);
/* Implement the "catch assert" command. */
static void
-catch_assert_command (char *arg, int from_tty,
+catch_assert_command (char *arg_entry, int from_tty,
struct cmd_list_element *command)
{
+ const char *arg = arg_entry;
struct gdbarch *gdbarch = get_current_arch ();
int tempflag;
char *cond_string = NULL;
VEC_truncate(ada_exc_info, *exceptions, skip + to_sort_len);
}
-/* A function intended as the "name_matcher" callback in the struct
- quick_symbol_functions' expand_symtabs_matching method.
-
- SEARCH_NAME is the symbol's search name.
-
- If USER_DATA is not NULL, it is a pointer to a regext_t object
- used to match the symbol (by natural name). Otherwise, when USER_DATA
- is null, no filtering is performed, and all symbols are a positive
- match. */
-
-static int
-ada_exc_search_name_matches (const char *search_name, void *user_data)
-{
- regex_t *preg = (regex_t *) user_data;
-
- if (preg == NULL)
- return 1;
-
- /* In Ada, the symbol "search name" is a linkage name, whereas
- the regular expression used to do the matching refers to
- the natural name. So match against the decoded name. */
- return (regexec (preg, ada_decode (search_name), 0, NULL, 0) == 0);
-}
-
/* Add all exceptions defined by the Ada standard whose name match
a regular expression.
}
}
+/* Return true if NAME matches PREG or if PREG is NULL. */
+
+static bool
+name_matches_regex (const char *name, regex_t *preg)
+{
+ return (preg == NULL
+ || regexec (preg, ada_decode (name), 0, NULL, 0) == 0);
+}
+
/* Add all exceptions defined globally whose name name match
a regular expression, excluding standard exceptions.
struct objfile *objfile;
struct compunit_symtab *s;
- expand_symtabs_matching (NULL, ada_exc_search_name_matches, NULL,
- VARIABLES_DOMAIN, preg);
+ /* In Ada, the symbol "search name" is a linkage name, whereas the
+ regular expression used to do the matching refers to the natural
+ name. So match against the decoded name. */
+ expand_symtabs_matching (NULL,
+ [&] (const char *search_name)
+ {
+ const char *decoded = ada_decode (search_name);
+ return name_matches_regex (decoded, preg);
+ },
+ NULL,
+ VARIABLES_DOMAIN);
ALL_COMPUNITS (objfile, s)
{
ALL_BLOCK_SYMBOLS (b, iter, sym)
if (ada_is_non_standard_exception_sym (sym)
- && (preg == NULL
- || regexec (preg, SYMBOL_NATURAL_NAME (sym),
- 0, NULL, 0) == 0))
+ && name_matches_regex (SYMBOL_NATURAL_NAME (sym), preg))
{
struct ada_exc_info info
= {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
return 0;
}
-static char *
+static const char *
ada_op_name (enum exp_opcode opcode)
{
switch (opcode)