Patchwork [2/6] framefilter quit: Code cleanup: Reindentation

login
register
mail settings
Submitter Jan Kratochvil
Date Feb. 7, 2015, 2:45 p.m.
Message ID <20150207144515.14897.80283.stgit@host1.jankratochvil.net>
Download mbox | patch
Permalink /patch/4955/
State New
Headers show

Comments

Jan Kratochvil - Feb. 7, 2015, 2:45 p.m.
Hi,

nothing significant but I find code more clear with less deep indentation.

Providing also more readable diff with -b.


Jan


gdb/ChangeLog
2015-02-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* python/py-framefilter.c (py_print_frame): Put conditional code paths
	with goto first, indent the former else codepath left.  Put variable
	'elided' to a new inner block.

#--- a/gdb/python/py-framefilter.c
#+++ b/gdb/python/py-framefilter.c
#@@ -1016,7 +1016,7 @@ py_print_frame (PyObject *filter, int flags,
#   struct frame_info *frame = NULL;
#   struct cleanup *cleanup_stack = make_cleanup (null_cleanup, NULL);
#   struct value_print_options opts;
#-  PyObject *py_inf_frame, *elided;
#+  PyObject *py_inf_frame;
#   int print_level, print_frame_info, print_args, print_locals;
#   volatile struct gdb_exception except;
#
#@@ -1058,12 +1058,9 @@ py_print_frame (PyObject *filter, int flags,
#       if (py_mi_print_variables (filter, out, &opts,
# 				 args_type, frame) == EXT_LANG_BT_ERROR)
# 	goto error;
#-      else
#-	{
#       do_cleanups (cleanup_stack);
#       return EXT_LANG_BT_COMPLETED;
#     }
#-    }
#
#   /* -stack-list-locals does not require a
#      wrapping frame attribute.  */
#@@ -1092,8 +1089,10 @@ py_print_frame (PyObject *filter, int flags,
#       if (PyObject_HasAttrString (filter, "address"))
# 	{
# 	  PyObject *paddr = PyObject_CallMethod (filter, "address", NULL);
#-	  if (paddr != NULL)
#-	    {
#+
#+	  if (paddr == NULL)
#+	    goto error;
#+
# 	  if (paddr != Py_None)
# 	    {
# 	      address = PyLong_AsLong (paddr);
#@@ -1101,9 +1100,6 @@ py_print_frame (PyObject *filter, int flags,
# 	    }
# 	  Py_DECREF (paddr);
# 	}
#-	  else
#-	    goto error;
#-	}
#     }
#
#   /* Print frame level.  MI does not require the level if
#@@ -1167,11 +1163,11 @@ py_print_frame (PyObject *filter, int flags,
#       if (PyObject_HasAttrString (filter, "function"))
# 	{
# 	  PyObject *py_func = PyObject_CallMethod (filter, "function", NULL);
#-
#-	  if (py_func != NULL)
#-	    {
# 	  const char *function = NULL;
#
#+	  if (py_func == NULL)
#+	    goto error;
#+
# 	  if (gdbpy_is_string (py_func))
# 	    {
# 	      char *function_to_free;
#@@ -1223,9 +1220,6 @@ py_print_frame (PyObject *filter, int flags,
# 	    }
# 	  Py_DECREF (py_func);
# 	}
#-	  else
#-	    goto error;
#-	}
#     }
#
#
#@@ -1254,8 +1248,9 @@ py_print_frame (PyObject *filter, int flags,
# 	{
# 	  PyObject *py_fn = PyObject_CallMethod (filter, "filename", NULL);
#
#-	  if (py_fn != NULL)
#-	    {
#+	  if (py_fn == NULL)
#+	    goto error;
#+
# 	  if (py_fn != Py_None)
# 	    {
# 	      char *filename = python_string_to_host_string (py_fn);
#@@ -1284,17 +1279,15 @@ py_print_frame (PyObject *filter, int flags,
# 	    }
# 	  Py_DECREF (py_fn);
# 	}
#-	  else
#-	    goto error;
#-	}
#
#       if (PyObject_HasAttrString (filter, "line"))
# 	{
# 	  PyObject *py_line = PyObject_CallMethod (filter, "line", NULL);
# 	  int line;
#
#-	  if (py_line != NULL)
#-	    {
#+	  if (py_line == NULL)
#+	    goto error;
#+
# 	  if (py_line != Py_None)
# 	    {
# 	      line = PyLong_AsLong (py_line);
#@@ -1313,9 +1306,6 @@ py_print_frame (PyObject *filter, int flags,
# 	    }
# 	  Py_DECREF (py_line);
# 	}
#-	  else
#-	    goto error;
#-	}
#     }
#
#   /* For MI we need to deal with the "children" list population of
#@@ -1341,6 +1331,9 @@ py_print_frame (PyObject *filter, int flags,
# 	goto error;
#     }
#
#+  {
#+    PyObject *elided;
#+
#     /* Finally recursively print elided frames, if any.  */
#     elided = get_py_iter_from_func (filter, "elided");
#     if (elided == NULL)
#@@ -1374,6 +1367,7 @@ py_print_frame (PyObject *filter, int flags,
# 	if (item == NULL && PyErr_Occurred ())
# 	  goto error;
#       }
#+    }
#
#
#   do_cleanups (cleanup_stack);
---
 gdb/python/py-framefilter.c |  259 +++++++++++++++++++++----------------------
 1 file changed, 126 insertions(+), 133 deletions(-)
Jan Kratochvil - Feb. 11, 2015, 1:39 p.m.
On Sat, 07 Feb 2015 15:45:16 +0100, Jan Kratochvil wrote:
> gdb/ChangeLog
> 2015-02-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	* python/py-framefilter.c (py_print_frame): Put conditional code paths
> 	with goto first, indent the former else codepath left.  Put variable
> 	'elided' to a new inner block.

34019068f0082676b31926c7ec84dba0cfb2aba5 master
a9189a245363137825ce02a23202df45b04db179 7.9


Jan

Patch

diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index c1c2653..896e2a8 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1016,7 +1016,7 @@  py_print_frame (PyObject *filter, int flags,
   struct frame_info *frame = NULL;
   struct cleanup *cleanup_stack = make_cleanup (null_cleanup, NULL);
   struct value_print_options opts;
-  PyObject *py_inf_frame, *elided;
+  PyObject *py_inf_frame;
   int print_level, print_frame_info, print_args, print_locals;
   volatile struct gdb_exception except;
 
@@ -1058,11 +1058,8 @@  py_print_frame (PyObject *filter, int flags,
       if (py_mi_print_variables (filter, out, &opts,
 				 args_type, frame) == EXT_LANG_BT_ERROR)
 	goto error;
-      else
-	{
-	  do_cleanups (cleanup_stack);
-	  return EXT_LANG_BT_COMPLETED;
-	}
+      do_cleanups (cleanup_stack);
+      return EXT_LANG_BT_COMPLETED;
     }
 
   /* -stack-list-locals does not require a
@@ -1092,17 +1089,16 @@  py_print_frame (PyObject *filter, int flags,
       if (PyObject_HasAttrString (filter, "address"))
 	{
 	  PyObject *paddr = PyObject_CallMethod (filter, "address", NULL);
-	  if (paddr != NULL)
+
+	  if (paddr == NULL)
+	    goto error;
+
+	  if (paddr != Py_None)
 	    {
-	      if (paddr != Py_None)
-		{
-		  address = PyLong_AsLong (paddr);
-		  has_addr = 1;
-		}
-	      Py_DECREF (paddr);
+	      address = PyLong_AsLong (paddr);
+	      has_addr = 1;
 	    }
-	  else
-	    goto error;
+	  Py_DECREF (paddr);
 	}
     }
 
@@ -1167,64 +1163,61 @@  py_print_frame (PyObject *filter, int flags,
       if (PyObject_HasAttrString (filter, "function"))
 	{
 	  PyObject *py_func = PyObject_CallMethod (filter, "function", NULL);
+	  const char *function = NULL;
 
-	  if (py_func != NULL)
-	    {
-	      const char *function = NULL;
-
-	      if (gdbpy_is_string (py_func))
-		{
-		  char *function_to_free;
-
-		  function = function_to_free =
-		    python_string_to_host_string (py_func);
+	  if (py_func == NULL)
+	    goto error;
 
-		  if (function == NULL)
-		    {
-		      Py_DECREF (py_func);
-		      goto error;
-		    }
-		  make_cleanup (xfree, function_to_free);
-		}
-	      else if (PyLong_Check (py_func))
-		{
-		  CORE_ADDR addr = PyLong_AsUnsignedLongLong (py_func);
-		  struct bound_minimal_symbol msymbol;
+	  if (gdbpy_is_string (py_func))
+	    {
+	      char *function_to_free;
 
-		  if (PyErr_Occurred ())
-		    goto error;
+	      function = function_to_free =
+		python_string_to_host_string (py_func);
 
-		  msymbol = lookup_minimal_symbol_by_pc (addr);
-		  if (msymbol.minsym != NULL)
-		    function = MSYMBOL_PRINT_NAME (msymbol.minsym);
-		}
-	      else if (py_func != Py_None)
+	      if (function == NULL)
 		{
-		  PyErr_SetString (PyExc_RuntimeError,
-				   _("FrameDecorator.function: expecting a " \
-				     "String, integer or None."));
 		  Py_DECREF (py_func);
 		  goto error;
 		}
+	      make_cleanup (xfree, function_to_free);
+	    }
+	  else if (PyLong_Check (py_func))
+	    {
+	      CORE_ADDR addr = PyLong_AsUnsignedLongLong (py_func);
+	      struct bound_minimal_symbol msymbol;
 
-	      TRY_CATCH (except, RETURN_MASK_ALL)
-		{
-		  annotate_frame_function_name ();
-		  if (function == NULL)
-		    ui_out_field_skip (out, "func");
-		  else
-		    ui_out_field_string (out, "func", function);
-		}
-	      if (except.reason < 0)
-		{
-		  Py_DECREF (py_func);
-		  gdbpy_convert_exception (except);
-		  goto error;
-		}
+	      if (PyErr_Occurred ())
+		goto error;
+
+	      msymbol = lookup_minimal_symbol_by_pc (addr);
+	      if (msymbol.minsym != NULL)
+		function = MSYMBOL_PRINT_NAME (msymbol.minsym);
+	    }
+	  else if (py_func != Py_None)
+	    {
+	      PyErr_SetString (PyExc_RuntimeError,
+			       _("FrameDecorator.function: expecting a " \
+				 "String, integer or None."));
 	      Py_DECREF (py_func);
+	      goto error;
 	    }
-	  else
-	    goto error;
+
+	  TRY_CATCH (except, RETURN_MASK_ALL)
+	    {
+	      annotate_frame_function_name ();
+	      if (function == NULL)
+		ui_out_field_skip (out, "func");
+	      else
+		ui_out_field_string (out, "func", function);
+	    }
+	  if (except.reason < 0)
+	    {
+	      Py_DECREF (py_func);
+	      gdbpy_convert_exception (except);
+	      goto error;
+	    }
+	  Py_DECREF (py_func);
 	}
     }
 
@@ -1254,38 +1247,36 @@  py_print_frame (PyObject *filter, int flags,
 	{
 	  PyObject *py_fn = PyObject_CallMethod (filter, "filename", NULL);
 
-	  if (py_fn != NULL)
+	  if (py_fn == NULL)
+	    goto error;
+
+	  if (py_fn != Py_None)
 	    {
-	      if (py_fn != Py_None)
-		{
-		  char *filename = python_string_to_host_string (py_fn);
+	      char *filename = python_string_to_host_string (py_fn);
 
-		  if (filename == NULL)
-		    {
-		      Py_DECREF (py_fn);
-		      goto error;
-		    }
+	      if (filename == NULL)
+		{
+		  Py_DECREF (py_fn);
+		  goto error;
+		}
 
-		  make_cleanup (xfree, filename);
-		  TRY_CATCH (except, RETURN_MASK_ALL)
-		    {
-		      ui_out_wrap_hint (out, "   ");
-		      ui_out_text (out, " at ");
-		      annotate_frame_source_file ();
-		      ui_out_field_string (out, "file", filename);
-		      annotate_frame_source_file_end ();
-		    }
-		  if (except.reason < 0)
-		    {
-		      Py_DECREF (py_fn);
-		      gdbpy_convert_exception (except);
-		      goto error;
-		    }
+	      make_cleanup (xfree, filename);
+	      TRY_CATCH (except, RETURN_MASK_ALL)
+		{
+		  ui_out_wrap_hint (out, "   ");
+		  ui_out_text (out, " at ");
+		  annotate_frame_source_file ();
+		  ui_out_field_string (out, "file", filename);
+		  annotate_frame_source_file_end ();
+		}
+	      if (except.reason < 0)
+		{
+		  Py_DECREF (py_fn);
+		  gdbpy_convert_exception (except);
+		  goto error;
 		}
-	      Py_DECREF (py_fn);
 	    }
-	  else
-	    goto error;
+	  Py_DECREF (py_fn);
 	}
 
       if (PyObject_HasAttrString (filter, "line"))
@@ -1293,28 +1284,26 @@  py_print_frame (PyObject *filter, int flags,
 	  PyObject *py_line = PyObject_CallMethod (filter, "line", NULL);
 	  int line;
 
-	  if (py_line != NULL)
+	  if (py_line == NULL)
+	    goto error;
+
+	  if (py_line != Py_None)
 	    {
-	      if (py_line != Py_None)
+	      line = PyLong_AsLong (py_line);
+	      TRY_CATCH (except, RETURN_MASK_ALL)
 		{
-		  line = PyLong_AsLong (py_line);
-		  TRY_CATCH (except, RETURN_MASK_ALL)
-		    {
-		      ui_out_text (out, ":");
-		      annotate_frame_source_line ();
-		      ui_out_field_int (out, "line", line);
-		    }
-		  if (except.reason < 0)
-		    {
-		      Py_DECREF (py_line);
-		      gdbpy_convert_exception (except);
-		      goto error;
-		    }
+		  ui_out_text (out, ":");
+		  annotate_frame_source_line ();
+		  ui_out_field_int (out, "line", line);
+		}
+	      if (except.reason < 0)
+		{
+		  Py_DECREF (py_line);
+		  gdbpy_convert_exception (except);
+		  goto error;
 		}
-	      Py_DECREF (py_line);
 	    }
-	  else
-	    goto error;
+	  Py_DECREF (py_line);
 	}
     }
 
@@ -1341,38 +1330,42 @@  py_print_frame (PyObject *filter, int flags,
 	goto error;
     }
 
-  /* Finally recursively print elided frames, if any.  */
-  elided = get_py_iter_from_func (filter, "elided");
-  if (elided == NULL)
-    goto error;
+  {
+    PyObject *elided;
 
-  make_cleanup_py_decref (elided);
-  if (elided != Py_None)
-    {
-      PyObject *item;
+    /* Finally recursively print elided frames, if any.  */
+    elided = get_py_iter_from_func (filter, "elided");
+    if (elided == NULL)
+      goto error;
 
-      make_cleanup_ui_out_list_begin_end (out, "children");
+    make_cleanup_py_decref (elided);
+    if (elided != Py_None)
+      {
+	PyObject *item;
 
-      if (! ui_out_is_mi_like_p (out))
-	indent++;
+	make_cleanup_ui_out_list_begin_end (out, "children");
 
-      while ((item = PyIter_Next (elided)))
-	{
-	  enum ext_lang_bt_status success = py_print_frame (item, flags,
-							    args_type, out,
-							    indent,
-							    levels_printed);
+	if (! ui_out_is_mi_like_p (out))
+	  indent++;
 
-	  if (success == EXT_LANG_BT_ERROR)
-	    {
-	      Py_DECREF (item);
-	      goto error;
-	    }
+	while ((item = PyIter_Next (elided)))
+	  {
+	    enum ext_lang_bt_status success = py_print_frame (item, flags,
+							      args_type, out,
+							      indent,
+							      levels_printed);
 
-	  Py_DECREF (item);
-	}
-      if (item == NULL && PyErr_Occurred ())
-	goto error;
+	    if (success == EXT_LANG_BT_ERROR)
+	      {
+		Py_DECREF (item);
+		goto error;
+	      }
+
+	    Py_DECREF (item);
+	  }
+	if (item == NULL && PyErr_Occurred ())
+	  goto error;
+      }
     }