gdb
authorTom Tromey <tromey@redhat.com>
Wed, 18 Aug 2010 19:02:34 +0000 (19:02 +0000)
committerTom Tromey <tromey@redhat.com>
Wed, 18 Aug 2010 19:02:34 +0000 (19:02 +0000)
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.
gdb/testsuite
PR symtab/11919:
* gdb.base/completion.exp: Add test.

gdb/ChangeLog
gdb/completer.c
gdb/gdbtypes.c
gdb/parse.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/completion.exp

index d69d6c5..5ae1bc6 100644 (file)
@@ -1,3 +1,12 @@
+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
index 3ba481e..91b899d 100644 (file)
@@ -24,6 +24,7 @@
 #include "filenames.h"         /* For DOSish file names.  */
 #include "language.h"
 #include "gdb_assert.h"
+#include "exceptions.h"
 
 #include "cli/cli-decode.h"
 
@@ -414,13 +415,19 @@ add_struct_fields (struct type *type, int *nextp, char **output,
 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 (;;)
index da4d673..c35adbb 100644 (file)
@@ -1212,6 +1212,7 @@ struct type *
 lookup_struct_elt_type (struct type *type, char *name, int noerr)
 {
   int i;
+  char *typename;
 
   for (;;)
     {
@@ -1225,11 +1226,9 @@ lookup_struct_elt_type (struct type *type, char *name, int noerr)
   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
@@ -1281,14 +1280,9 @@ lookup_struct_elt_type (struct type *type, char *name, int noerr)
       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.
index c885c6a..035572e 100644 (file)
@@ -1202,8 +1202,10 @@ parse_expression (char *string)
 /* 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)
@@ -1213,7 +1215,7 @@ 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);
@@ -1233,10 +1235,12 @@ parse_field_expression (char *string, char **name)
       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);
index 5490e7e..0cbb3ad 100644 (file)
@@ -1,3 +1,8 @@
+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.
index 5c91631..1f7c214 100644 (file)
@@ -827,23 +827,8 @@ gdb_expect  {
         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"