public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  pmuldoon/python-backtrace: Tom tromey review 3
@ 2013-05-02 13:03 pmuldoon
  0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2013-05-02 13:03 UTC (permalink / raw)
  To: archer-commits

The branch, pmuldoon/python-backtrace has been updated
       via  f27449c171726af57bcd94a7f70d3b6b3396a5cb (commit)
      from  8f43a4f73dff17b107d537a15c4a2a4690ad1d5a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit f27449c171726af57bcd94a7f70d3b6b3396a5cb
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Thu May 2 14:02:36 2013 +0100

    Tom tromey review 3

-----------------------------------------------------------------------

Summary of changes:
 gdb/mi/mi-cmd-stack.c                          |   16 +-
 gdb/python/lib/gdb/FrameIterator.py            |    8 -
 gdb/python/lib/gdb/frames.py                   |   10 +-
 gdb/python/py-framefilter.c                    |  269 +++++++++++------------
 gdb/python/python.h                            |   16 +-
 gdb/stack.c                                    |    3 +-
 gdb/testsuite/gdb.python/py-framefilter-mi.exp |    9 +-
 gdb/testsuite/gdb.python/py-framefilter.exp    |  137 ++++++++-----
 8 files changed, 237 insertions(+), 231 deletions(-)

First 500 lines of diff:
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 06d41a0..07c0510 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -78,7 +78,7 @@ mi_cmd_stack_list_frames (char *command, char **argv, int argc)
   int i;
   struct cleanup *cleanup_stack;
   struct frame_info *fi;
-  int result = PY_BT_ERROR;
+  enum py_bt_status result = PY_BT_ERROR;
   int raw_arg = 0;
   int oind = 0;
   enum opt
@@ -107,14 +107,14 @@ mi_cmd_stack_list_frames (char *command, char **argv, int argc)
 	  break;
 	}
     }
-  if ((argc > 3 && ! raw_arg) || (argc == 1 && ! raw_arg)
-      || (argc == 2 && raw_arg))
+
+  if ((argc > 3) || (argc == 2 && oind) || (argc == 1 && ! oind))
     error (_("-stack-list-frames: Usage: [--no-frame-filters] [FRAME_LOW FRAME_HIGH]"));
 
   if (argc == 3 || argc == 2)
     {
-      frame_low = atoi (argv[0 + raw_arg]);
-      frame_high = atoi (argv[1 + raw_arg]);
+      frame_low = atoi (argv[0 + oind]);
+      frame_high = atoi (argv[1 + oind]);
     }
   else
     {
@@ -224,7 +224,7 @@ mi_cmd_stack_list_locals (char *command, char **argv, int argc)
 {
   struct frame_info *frame;
   int raw_arg = 0;
-  int result = PY_BT_ERROR;
+  enum py_bt_status result = PY_BT_ERROR;
   int print_value;
 
   if (argc > 0)
@@ -268,7 +268,7 @@ mi_cmd_stack_list_args (char *command, char **argv, int argc)
   enum print_values print_values;
   struct ui_out *uiout = current_uiout;
   int raw_arg = 0;
-  int result = PY_BT_ERROR;
+  enum py_bt_status result = PY_BT_ERROR;
 
   if (argc > 0)
     raw_arg = parse_no_frames_option (argv[0]);
@@ -353,7 +353,7 @@ mi_cmd_stack_list_variables (char *command, char **argv, int argc)
 {
   struct frame_info *frame;
   int raw_arg = 0;
-  int result = PY_BT_ERROR;
+  enum py_bt_status result = PY_BT_ERROR;
   int print_value;
 
   if (argc > 0)
diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
index 8791a91..b3af94b 100644
--- a/gdb/python/lib/gdb/FrameIterator.py
+++ b/gdb/python/lib/gdb/FrameIterator.py
@@ -32,14 +32,6 @@ class FrameIterator(object):
     def __iter__(self):
         return self
 
-    def __getitem__(self, index):
-        """__getitem__ implementation.
-
-        Arguments:
-            index: A specific index to fetch."""
-
-        return next(itertools.islice(self.frame, index, index+1))
-
     def next(self):
         """next implementation.
 
diff --git a/gdb/python/lib/gdb/frames.py b/gdb/python/lib/gdb/frames.py
index 2287181..10dce8e 100644
--- a/gdb/python/lib/gdb/frames.py
+++ b/gdb/python/lib/gdb/frames.py
@@ -40,10 +40,7 @@ def get_priority(filter_item):
     """
     # Do not fail here, as the sort will fail.  If a filter has not
     # (incorrectly) set a priority, set it to zero.
-    if hasattr(filter_item, "priority"):
-        return filter_item.priority
-    else:
-        return 0
+    return getattr(filter_item, "priority", 0)
 
 def set_priority(filter_item, priority):
     """ Internal worker function to set the frame-filter's priority.
@@ -76,10 +73,7 @@ def get_enabled(filter_item):
     # If the filter class is badly implemented when called from the
     # Python filter command, do not cease filter operations, just set
     # enabled to False.
-    if hasattr(filter_item, "enabled"):
-        return filter_item.enabled
-    else:
-        return False
+    return getattr(filter_item, "enabled", False)
 
 def set_enabled(filter_item, state):
     """ Internal Worker function to set the frame-filter's enabled
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 95cc2f2..96c9762 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -145,7 +145,7 @@ extract_value (PyObject *obj, struct value **value)
 	  if (*value == NULL)
 	    return PY_BT_ERROR;
 
-	  return 1;
+	  return PY_BT_OK;
 	}
     }
   else
@@ -246,14 +246,13 @@ py_print_value (struct ui_out *out, struct value *val,
 
   /* Never set an indent level for common_val_print if MI.  */
   if (ui_out_is_mi_like_p (out))
-      local_indent = 0;
+    local_indent = 0;
 
   /* MI does not print certain values, differentiated by type,
      depending on what ARGS_TYPE indicates.  Test type against option.
      For CLI print all values.  */
   if (args_type == MI_PRINT_SIMPLE_VALUES
       || args_type == MI_PRINT_ALL_VALUES)
-
     {
       struct type *type = NULL;
 
@@ -362,8 +361,6 @@ py_print_single_arg (struct ui_out *out,
 {
   struct value *val;
   volatile struct gdb_exception except;
-  struct cleanup *cleanups =
-    make_cleanup (null_cleanup, NULL);
 
   if (fa != NULL)
     {
@@ -373,116 +370,107 @@ py_print_single_arg (struct ui_out *out,
   else
     val = fv;
 
-  /*  MI has varying rules for tuples, but generally if there is only
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
+
+      /*  MI has varying rules for tuples, but generally if there is only
       one element in each item in the list, do not start a tuple.  The
       exception is -stack-list-variables which emits an ARGS="1" field
       if the value is a frame argument.  This is denoted in this
       function with PRINT_ARGS_FIELD which is flag from the caller to
       emit the ARGS field.  */
-  if (ui_out_is_mi_like_p (out))
-    {
-      if (print_args_field || args_type != NO_VALUES)
-	make_cleanup_ui_out_tuple_begin_end (out, NULL);
-    }
+      if (ui_out_is_mi_like_p (out))
+	{
+	  if (print_args_field || args_type != NO_VALUES)
+	    make_cleanup_ui_out_tuple_begin_end (out, NULL);
+	}
 
-    TRY_CATCH (except, RETURN_MASK_ALL)
-      {
-	annotate_arg_begin ();
+      annotate_arg_begin ();
 
-	/* If frame argument is populated, check for entry-values and the
-	   entry value options.  */
-	if (fa != NULL)
-	  {
-	    struct ui_file *stb;
-
-	    stb = mem_fileopen ();
-	    make_cleanup_ui_file_delete (stb);
-	    fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (fa->sym),
-				     SYMBOL_LANGUAGE (fa->sym),
-				     DMGL_PARAMS | DMGL_ANSI);
-	    if (fa->entry_kind == print_entry_values_compact)
-	      {
-		fputs_filtered ("=", stb);
-
-		fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (fa->sym),
-					 SYMBOL_LANGUAGE (fa->sym),
-					 DMGL_PARAMS | DMGL_ANSI);
-	      }
-	    if (fa->entry_kind == print_entry_values_only
-		|| fa->entry_kind == print_entry_values_compact)
-	      {
-		fputs_filtered ("@entry", stb);
-	      }
-	    ui_out_field_stream (out, "name", stb);
-	  }
-	else
-	  /* Otherwise, just output the name.  */
-	  ui_out_field_string (out, "name", sym_name);
+      /* If frame argument is populated, check for entry-values and the
+	 entry value options.  */
+      if (fa != NULL)
+	{
+	  struct ui_file *stb;
 
-	annotate_arg_name_end ();
+	  stb = mem_fileopen ();
+	  make_cleanup_ui_file_delete (stb);
+	  fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (fa->sym),
+				   SYMBOL_LANGUAGE (fa->sym),
+				   DMGL_PARAMS | DMGL_ANSI);
+	  if (fa->entry_kind == print_entry_values_compact)
+	    {
+	      fputs_filtered ("=", stb);
 
-	if (! ui_out_is_mi_like_p (out))
-	  ui_out_text (out, "=");
+	      fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (fa->sym),
+				       SYMBOL_LANGUAGE (fa->sym),
+				       DMGL_PARAMS | DMGL_ANSI);
+	    }
+	  if (fa->entry_kind == print_entry_values_only
+	      || fa->entry_kind == print_entry_values_compact)
+	    {
+	      fputs_filtered ("@entry", stb);
+	    }
+	  ui_out_field_stream (out, "name", stb);
+	}
+      else
+	/* Otherwise, just output the name.  */
+	ui_out_field_string (out, "name", sym_name);
 
-	if (print_args_field)
-	  ui_out_field_int (out, "arg", 1);
-      }
-    if (except.reason < 0)
-      {
-	gdbpy_convert_exception (except);
-	goto error;
-      }
+      annotate_arg_name_end ();
 
-  /* For MI print the type, but only for simple values.  This seems
-     weird, but this is how MI choose to format the various output
-     types.  */
-  if (args_type == MI_PRINT_SIMPLE_VALUES)
-    {
-      if (! py_print_type (out, val))
-	goto error;
-    }
+      if (! ui_out_is_mi_like_p (out))
+	ui_out_text (out, "=");
 
-  TRY_CATCH (except, RETURN_MASK_ALL)
-    {
-      annotate_arg_value (value_type (val));
-    }
-  if (except.reason < 0)
-    {
-      gdbpy_convert_exception (except);
-      goto error;
-    }
+      if (print_args_field)
+	ui_out_field_int (out, "arg", 1);
 
-  /* If the output is to the CLI, and the user option "set print
-     frame-arguments" is set to none, just output "...".  */
-  if (! ui_out_is_mi_like_p (out) && args_type == NO_VALUES)
-    {
-      TRY_CATCH (except, RETURN_MASK_ALL)
+      /* For MI print the type, but only for simple values.  This seems
+	 weird, but this is how MI choose to format the various output
+	 types.  */
+      if (args_type == MI_PRINT_SIMPLE_VALUES)
 	{
-	  ui_out_field_string (out, "value", "...");
+	  if (py_print_type (out, val) == PY_BT_ERROR)
+	    {
+	      do_cleanups (cleanups);
+	      goto error;
+	    }
 	}
-      if (except.reason < 0)
+
+      annotate_arg_value (value_type (val));
+
+      /* If the output is to the CLI, and the user option "set print
+	 frame-arguments" is set to none, just output "...".  */
+      if (! ui_out_is_mi_like_p (out) && args_type == NO_VALUES)
+	ui_out_field_string (out, "value", "...");
+      else
 	{
-	  gdbpy_convert_exception (except);
-	  goto error;
+	  /* Otherwise, print the value for both MI and the CLI, except
+	     for the case of MI_PRINT_NO_VALUES.  */
+	  if (args_type != NO_VALUES)
+	    {
+	      if (py_print_value (out, val, opts, 0, args_type, language)
+		  == PY_BT_ERROR)
+		{
+		  do_cleanups (cleanups);
+		  goto error;
+		}
+	    }
 	}
+
+      do_cleanups (cleanups);
     }
-  else
+  if (except.reason < 0)
     {
-      /* Otherwise, print the value for both MI and the CLI, except
-	 for the case of MI_PRINT_NO_VALUES.  */
-      if (args_type != NO_VALUES)
-	{
-	  if (! py_print_value (out, val, opts, 0, args_type, language))
-	    goto error;
-	}
+      gdbpy_convert_exception (except);
+      goto error;
     }
 
-  do_cleanups (cleanups);
-
   return PY_BT_OK;
 
  error:
-  do_cleanups (cleanups);
+  //do_cleanups (cleanups);
   return PY_BT_ERROR;
 }
 
@@ -540,7 +528,7 @@ enumerate_args (PyObject *iter,
       char *sym_name;
       struct symbol *sym;
       struct value *val;
-      int success = PY_BT_ERROR;
+      enum py_bt_status success = PY_BT_ERROR;
 
       success = extract_sym (item, &sym_name, &sym, &language);
       if (success == PY_BT_ERROR)
@@ -721,7 +709,6 @@ enumerate_locals (PyObject *iter,
 {
   PyObject *item;
   struct value_print_options opts;
-  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
 
   get_user_print_options (&opts);
   opts.deref_ref = 1;
@@ -731,34 +718,34 @@ enumerate_locals (PyObject *iter,
       const struct language_defn *language;
       char *sym_name;
       struct value *val;
-      int success = PY_BT_ERROR;
+      enum py_bt_status  success = PY_BT_ERROR;
       struct symbol *sym;
       volatile struct gdb_exception except;
       int local_indent = 8 + (8 * indent);
+      struct cleanup *locals_cleanups;
 
-      make_cleanup (null_cleanup, NULL);
+      locals_cleanups = make_cleanup_py_decref (item);
 
       success = extract_sym (item, &sym_name, &sym, &language);
       if (success == PY_BT_ERROR)
 	{
-	  Py_DECREF (item);
+	  do_cleanups (locals_cleanups);
 	  goto error;
 	}
 
+      make_cleanup (xfree, sym_name);
+
       success = extract_value (item, &val);
       if (success == PY_BT_ERROR)
 	{
-	  xfree (sym_name);
-	  Py_DECREF (item);
+	  do_cleanups (locals_cleanups);
 	  goto error;
 	}
 
-      Py_DECREF (item);
-
       if (sym != NULL && ui_out_is_mi_like_p (out)
 	  && ! mi_should_print (sym, MI_PRINT_LOCALS))
 	{
-	  xfree (sym_name);
+	  do_cleanups (locals_cleanups);
 	  continue;
 	}
 
@@ -771,8 +758,8 @@ enumerate_locals (PyObject *iter,
 	    }
 	  if (except.reason < 0)
 	    {
-	      xfree (sym_name);
 	      gdbpy_convert_exception (except);
+	      do_cleanups (locals_cleanups);
 	      goto error;
 	    }
 	}
@@ -780,29 +767,19 @@ enumerate_locals (PyObject *iter,
       /* With PRINT_NO_VALUES, MI does not emit a tuple normally as
 	 each output contains only one field.  The exception is
 	 -stack-list-variables, which always provides a tuple.  */
-
       if (ui_out_is_mi_like_p (out))
 	{
 	  if (print_args_field || args_type != NO_VALUES)
 	    make_cleanup_ui_out_tuple_begin_end (out, NULL);
 	}
-      else
+      TRY_CATCH (except, RETURN_MASK_ALL)
 	{
-	  TRY_CATCH (except, RETURN_MASK_ALL)
+	  if (! ui_out_is_mi_like_p (out))
 	    {
 	      /* If the output is not MI we indent locals.  */
 	      ui_out_spaces (out, local_indent);
 	    }
-	  if (except.reason < 0)
-	    {
-	      xfree (sym_name);
-	      gdbpy_convert_exception (except);
-	      goto error;
-	    }
-	}
 
-      TRY_CATCH (except, RETURN_MASK_ALL)
-	{
 	  ui_out_field_string (out, "name", sym_name);
 
 	  if (! ui_out_is_mi_like_p (out))
@@ -810,17 +787,18 @@ enumerate_locals (PyObject *iter,
 	}
       if (except.reason < 0)
 	{
-	  xfree (sym_name);
 	  gdbpy_convert_exception (except);
+	  do_cleanups (locals_cleanups);
 	  goto error;
 	}
 
-      xfree (sym_name);
-
       if (args_type == MI_PRINT_SIMPLE_VALUES)
 	{
-	  if (! py_print_type (out, val))
-	    goto error;
+	  if (py_print_type (out, val) == PY_BT_ERROR)
+	    {
+	      do_cleanups (locals_cleanups);
+	      goto error;
+	    }
 	}
 
       /* CLI always prints values for locals.  MI uses the
@@ -831,7 +809,10 @@ enumerate_locals (PyObject *iter,
 
 	  if (py_print_value (out, val, &opts, val_indent, args_type,
 			      language) ==  PY_BT_ERROR)
-	    goto error;
+	    {
+	      do_cleanups (locals_cleanups);
+	      goto error;
+	    }
 	}
       else
 	{
@@ -839,10 +820,15 @@ enumerate_locals (PyObject *iter,
 	    {
 	      if (py_print_value (out, val, &opts, 0, args_type,
 				  language) ==  PY_BT_ERROR)
-		goto error;
+		{
+		  do_cleanups (locals_cleanups);
+		  goto error;
+		}
 	    }
 	}
 
+      do_cleanups (locals_cleanups);
+
       TRY_CATCH (except, RETURN_MASK_ALL)
 	{
 	  ui_out_text (out, "\n");
@@ -852,7 +838,6 @@ enumerate_locals (PyObject *iter,
 	  gdbpy_convert_exception (except);
 	  goto error;
 	}
-      do_cleanups (cleanups);
     }
 


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-05-02 13:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-02 13:03 [SCM] pmuldoon/python-backtrace: Tom tromey review 3 pmuldoon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).