Use gdbpy_enter in gdbpy_before_prompt_hook
[binutils-gdb.git] / gdb / typeprint.c
index e77513e1c4ad85b7ab17cb8667048483c6c03b32..56e993e91f24fb633a1fb9a9175166349e02edc9 100644 (file)
@@ -1,6 +1,6 @@
 /* Language independent support for printing types 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.
 
@@ -368,10 +368,10 @@ type_print (struct type *type, const char *varstring, struct ui_file *stream,
 /* Print TYPE to a string, returning it.  The caller is responsible for
    freeing the string.  */
 
-char *
+std::string
 type_to_string (struct type *type)
 {
-  char *s = NULL;
+  std::string s;
   struct ui_file *stb;
   struct cleanup *old_chain;
 
@@ -381,11 +381,10 @@ type_to_string (struct type *type)
   TRY
     {
       type_print (type, "", stb, -1);
-      s = ui_file_xstrdup (stb, NULL);
+      s = ui_file_as_string (stb);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
-      s = NULL;
     }
   END_CATCH
 
@@ -400,7 +399,6 @@ type_to_string (struct type *type)
 static void
 whatis_exp (char *exp, int show)
 {
-  struct expression *expr;
   struct value *val;
   struct cleanup *old_chain;
   struct type *real_type = NULL;
@@ -451,9 +449,8 @@ whatis_exp (char *exp, int show)
          exp = skip_spaces (exp);
        }
 
-      expr = parse_expression (exp);
-      make_cleanup (free_current_contents, &expr);
-      val = evaluate_type (expr);
+      expression_up expr = parse_expression (exp);
+      val = evaluate_type (expr.get ());
     }
   else
     val = access_value_history (0);
@@ -600,13 +597,10 @@ maintenance_print_type (char *type_name, int from_tty)
 {
   struct value *val;
   struct type *type;
-  struct cleanup *old_chain;
-  struct expression *expr;
 
   if (type_name != NULL)
     {
-      expr = parse_expression (type_name);
-      old_chain = make_cleanup (free_current_contents, &expr);
+      expression_up expr = parse_expression (type_name);
       if (expr->elts[0].opcode == OP_TYPE)
        {
          /* The user expression names a type directly, just use that type.  */
@@ -616,14 +610,13 @@ maintenance_print_type (char *type_name, int from_tty)
        {
          /* The user expression may name a type indirectly by naming an
             object of that type.  Find that indirectly named type.  */
-         val = evaluate_type (expr);
+         val = evaluate_type (expr.get ());
          type = value_type (val);
        }
       if (type != NULL)
        {
          recursive_dump_type (type, 0);
        }
-      do_cleanups (old_chain);
     }
 }
 \f