+2010-08-18 Tom Tromey <tromey@redhat.com>
+
+ PR symtab/11919:
+ * gdbtypes.c (lookup_struct_elt_type): Clean up error emission.
+ * parse.c (parse_field_expression): Use RETURN_MASK_ERROR. Move
+ name-copying lower. Document exception behavior.
+ * completer.c (expression_completer): Catch exceptions from
+ parse_field_expression.
+
2010-08-18 Pedro Alves <pedro@codesourcery.com>
PR corefile/8210
#include "filenames.h" /* For DOSish file names. */
#include "language.h"
#include "gdb_assert.h"
+#include "exceptions.h"
#include "cli/cli-decode.h"
char **
expression_completer (struct cmd_list_element *ignore, char *text, char *word)
{
- struct type *type;
+ struct type *type = NULL;
char *fieldname, *p;
+ volatile struct gdb_exception except;
/* Perform a tentative parse of the expression, to see whether a
field completion is required. */
fieldname = NULL;
- type = parse_field_expression (text, &fieldname);
+ TRY_CATCH (except, RETURN_MASK_ERROR)
+ {
+ type = parse_field_expression (text, &fieldname);
+ }
+ if (except.reason < 0)
+ return NULL;
if (fieldname && type)
{
for (;;)
lookup_struct_elt_type (struct type *type, char *name, int noerr)
{
int i;
+ char *typename;
for (;;)
{
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION)
{
- target_terminal_ours ();
- gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- error (_(" is not a structure or union type."));
+ typename = type_to_string (type);
+ make_cleanup (xfree, typename);
+ error (_("Type %s is not a structure or union type."), typename);
}
#if 0
return NULL;
}
- target_terminal_ours ();
- gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- fprintf_unfiltered (gdb_stderr, " has no component named ");
- fputs_filtered (name, gdb_stderr);
- error (("."));
- return (struct type *) -1; /* For lint */
+ typename = type_to_string (type);
+ make_cleanup (xfree, typename);
+ error (_("Type %s has no component named %s."), typename, name);
}
/* Lookup the vptr basetype/fieldno values for TYPE.
/* Parse STRING as an expression. If parsing ends in the middle of a
field reference, return the type of the left-hand-side of the
reference; furthermore, if the parsing ends in the field name,
- return the field name in *NAME. In all other cases, return NULL.
- Returned non-NULL *NAME must be freed by the caller. */
+ return the field name in *NAME. If the parsing ends in the middle
+ of a field reference, but the reference is somehow invalid, throw
+ an exception. In all other cases, return NULL. Returned non-NULL
+ *NAME must be freed by the caller. */
struct type *
parse_field_expression (char *string, char **name)
int subexp;
volatile struct gdb_exception except;
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY_CATCH (except, RETURN_MASK_ERROR)
{
in_parse_field = 1;
exp = parse_exp_in_context (&string, 0, 0, 0, &subexp);
xfree (exp);
return NULL;
}
- /* (*NAME) is a part of the EXP memory block freed below. */
- *name = xstrdup (*name);
+ /* This might throw an exception. If so, we want to let it
+ propagate. */
val = evaluate_subexpression_type (exp, subexp);
+ /* (*NAME) is a part of the EXP memory block freed below. */
+ *name = xstrdup (*name);
xfree (exp);
return value_type (val);
+2010-08-18 Tom Tromey <tromey@redhat.com>
+
+ PR symtab/11919:
+ * gdb.base/completion.exp: Add test.
+
2010-08-18 Doug Evans <dje@google.com>
* gdb.base/call-ar-st.exp (set_lang_c): Delete, unused.
timeout { fail "(timeout) complete 'set follow-fork-mode'" }
}
-send_gdb "p values\[0\].nonex.\t"
-gdb_expect {
- -re "Type struct some_struct has no component named nonex.\r\n$gdb_prompt $"\
- { pass "Completing non-existing component" }
- -re ".*$gdb_prompt $" { fail "Completing non-existing component" }
- timeout { fail "(timeout) Completing non-existing component" }
- eof { fail "(eof) Completing non-existing component #2" }
- }
-# Double memory freeing gets found only on the second run:
-send_gdb "p values\[0\].nonex.\t"
-gdb_expect {
- -re "Type struct some_struct has no component named nonex.\r\n$gdb_prompt $"\
- { pass "Completing non-existing component #2" }
- -re ".*$gdb_prompt $" { fail "Completing non-existing component #2" }
- timeout { fail "(timeout) Completing non-existing component #2" }
- eof { fail "(eof) Completing non-existing component #2" }
- }
+gdb_test_no_output "complete print values\[0\].x." \
+ "field completion with invalid field"
# If there is a non-deprecated completion, it should be returned.
gdb_test "complete sav" "save" "test non-deprecated completion"