public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-pmuldoon-python-backtrace: Add -stack-list-locals, add a lot of MI test cases.  Fix several locals bugs.
@ 2012-08-09 16:59 pmuldoon
  0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2012-08-09 16:59 UTC (permalink / raw)
  To: archer-commits

The branch, archer-pmuldoon-python-backtrace has been updated
       via  3f14f035eced37f12bd9c065ea8f86ccf26f4150 (commit)
      from  a3fd891ea77a71d9c15e93cefa46ef828e3463a2 (commit)

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

- Log -----------------------------------------------------------------
commit 3f14f035eced37f12bd9c065ea8f86ccf26f4150
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Thu Aug 9 17:58:51 2012 +0100

    Add -stack-list-locals, add a lot of MI test cases.  Fix several
    locals bugs.

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

Summary of changes:
 gdb/mi/mi-cmd-stack.c                          |   41 ++++++-
 gdb/python/lib/gdb/BaseFrameWrapper.py         |   33 ++++-
 gdb/python/py-framefilter.c                    |  152 ++++++++++++++++--------
 gdb/testsuite/gdb.python/py-framefilter-mi.exp |   29 ++++-
 gdb/testsuite/gdb.python/py-framefilter.c      |    2 +
 gdb/testsuite/gdb.python/py-framefilter.exp    |   20 ++-
 6 files changed, 212 insertions(+), 65 deletions(-)

First 500 lines of diff:
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index c6f429f..92ab4c2 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -199,13 +199,48 @@ void
 mi_cmd_stack_list_locals (char *command, char **argv, int argc)
 {
   struct frame_info *frame;
+  int raw_arg = 0;
+  int result = 0;
 
-  if (argc != 1)
-    error (_("-stack-list-locals: Usage: PRINT_VALUES"));
+  if (argc == 2)
+    {
+      int j;
+      /* Find 'raw-frames' at argv[1] if passed as an argument */
+      for (j = 0; j < strlen (argv[1]); j++)
+	argv[1][j] = tolower (argv[1][j]);
+
+      if (subset_compare (argv[1], "raw-frames"))
+	raw_arg = 1;
+    }
+
+  if (argc < 1 || argc > 2 || (argc == 2 && ! raw_arg)
+      || (argc == 1 && raw_arg))
+    error (_("-stack-list-locals: Usage: PRINT_VALUES [RAW-FRAMES]"));
 
    frame = get_selected_frame (NULL);
 
-   list_args_or_locals (locals, parse_print_values (argv[0]), frame);
+   if (! raw_arg && frame_filters)
+     {
+       int count = 1;
+       int arg = atoi (argv[0]);
+
+       result = apply_frame_filter (frame,/* frame */
+				    1, /* print_level */
+				    LOC_AND_ADDRESS, /* print_what */
+				    0, /* print_frame_info */
+				    0, /* print_args */
+				    arg, /* mi_print_args_type */
+				    0, /* cli_print_args_type */
+				    current_uiout, /* out */
+				    1, /* print_locals */
+				    count /* count */);
+     }
+
+   if (! frame_filters || raw_arg || result == PY_BT_ERROR
+       || result == PY_BT_NO_FILTERS)
+     {
+       list_args_or_locals (locals, parse_print_values (argv[0]), frame);
+     }
 }
 
 /* Print a list of the arguments for the current frame.  With argument
diff --git a/gdb/python/lib/gdb/BaseFrameWrapper.py b/gdb/python/lib/gdb/BaseFrameWrapper.py
index c41e1f0..e4ca58d 100644
--- a/gdb/python/lib/gdb/BaseFrameWrapper.py
+++ b/gdb/python/lib/gdb/BaseFrameWrapper.py
@@ -106,6 +106,25 @@ class FrameVars ():
     def __init__(self,frame):
         self.frame = frame
 
+    def fetch_b (self, sym):
+
+        # We may have a string as a symbol, in the case of synthetic
+        # locals/args
+        if isinstance(sym, basestring):
+            return True
+
+        sym_type = sym.addr_class
+
+        return {
+            gdb.SYMBOL_LOC_STATIC: True,
+            gdb.SYMBOL_LOC_REGISTER: True,
+            gdb.SYMBOL_LOC_ARG: True,
+            gdb.SYMBOL_LOC_REF_ARG: True,
+            gdb.SYMBOL_LOC_LOCAL: True,
+	    gdb.SYMBOL_LOC_REGPARM_ADDR: True,
+	    gdb.SYMBOL_LOC_COMPUTED: True
+          }.get(sym_type, False)
+
     def fetch_frame_locals (self):
         lvars = []
         block = self.frame.block()
@@ -113,8 +132,8 @@ class FrameVars ():
         for sym in block:
             if sym.is_argument:
                 continue;
-
-            lvars.append(BaseSymValueWrapper(sym, self.get_value(sym,block)))
+            if self.fetch_b (sym):
+                lvars.append(BaseSymValueWrapper(sym, self.get_value(sym,block)))
 
         if len(lvars) == 0:
             return None
@@ -128,8 +147,8 @@ class FrameVars ():
         for sym in block:
             if not sym.is_argument:
                 continue;
-
-            args.append(BaseSymValueWrapper(sym,self.get_value (sym,block)))
+            if self.fetch_b (sym):
+                args.append(BaseSymValueWrapper(sym,self.get_value (sym,block)))
 
         if len(args) == 0:
             return None
@@ -139,9 +158,9 @@ class FrameVars ():
     def get_value (self, sym, block):
         if len (sym.linkage_name):
             nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
-
-            if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
-                sym = nsym
+            if nsym != None:
+                if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
+                    sym = nsym
 
         try:
             val = sym.value (self.frame)
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 05db015..14217f3 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -116,11 +116,46 @@ extract_sym_and_value (PyObject *obj, char **name,
 }
 
 static int
+py_print_type (struct ui_out *out,
+	       struct value *val)
+{
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      struct type *type;
+      struct ui_file *stb;
+      struct cleanup *cleanup;
+
+      stb = mem_fileopen ();
+      cleanup = make_cleanup_ui_file_delete (stb);
+      type = check_typedef (value_type (val));
+      type_print (type, "", stb, -1);
+      ui_out_field_stream (out, "type", stb);
+      do_cleanups (cleanup);
+    }
+  if (except.reason > 0)
+    {
+      PyErr_SetString (PyExc_RuntimeError,
+		       except.message);
+      return 0;
+    }
+
+  return 1;
+}
+
+static int
 py_print_locals (PyObject *filter,
-		 struct value_print_options opts)
+		 struct ui_out *out,
+		 struct value_print_options opts,
+		 int mi_print_type,
+		 int indent)
 {
-  int indent = 4;
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+  /* In traditional bt full backtraces this is num_tabs (4) * 2 = 8.  It
+     never appears to deviate from this.  */
+  struct cleanup *old_chain = make_cleanup_ui_out_list_begin_end (out,
+								  "locals");
+
 
   if (PyObject_HasAttrString (filter, "frame_locals"))
     {
@@ -156,40 +191,70 @@ py_print_locals (PyObject *filter,
 		      struct value *val;
 		      int value_success = 0;
 		      volatile struct gdb_exception except;
-
-		      if (! item)
-			goto locals_error;
+		      struct cleanup *inner_cleanup =
+			make_cleanup (null_cleanup, NULL);
 
 		      value_success = extract_sym_and_value (item, &sym_name,
 							     &val,
 							     &language);
+
 		      Py_DECREF (item);
-		      item = NULL;
 
 		      if (! value_success)
 			goto locals_error;
 
-		      fprintf_filtered (gdb_stdout, "%s%s = ",
-					n_spaces (2 * indent),
-					sym_name);
+		      if (ui_out_is_mi_like_p (out))
+			{
+			  if (mi_print_type != PRINT_NO_VALUES)
+			    {
+			      inner_cleanup =
+				make_cleanup_ui_out_tuple_begin_end (out,
+								     NULL);
+			    }
+			}
+		      else
+			ui_out_spaces (out, (8 + (indent * 2)));
 
+		      ui_out_field_string (out, "name", sym_name);
 		      xfree (sym_name);
 
-		      TRY_CATCH (except, RETURN_MASK_ERROR)
+		      if (! ui_out_is_mi_like_p (out))
+			ui_out_text (out, " = ");
+
+		      if (ui_out_is_mi_like_p (out)
+			  && mi_print_type == PRINT_SIMPLE_VALUES)
 			{
-			  opts.deref_ref = 1;
-			  common_val_print (val, gdb_stdout,
-					    indent, &opts,
-					    language);
+			  if (! py_print_type (out, val))
+			    goto locals_error;
 			}
-		      if (except.reason < 0)
+
+		      if (! ui_out_is_mi_like_p (out)
+			  || (ui_out_is_mi_like_p (out)
+			      && mi_print_type != PRINT_NO_VALUES))
 			{
-			  PyErr_SetString (PyExc_RuntimeError,
-					   except.message);
-			  goto locals_error;
+			  struct ui_file *stb;
+			  stb = mem_fileopen ();
+			  make_cleanup_ui_file_delete (stb);
+
+			  TRY_CATCH (except, RETURN_MASK_ALL)
+			    {
+			      get_user_print_options (&opts);
+			      opts.deref_ref = 1;
+			      common_val_print (val, stb, 2, &opts, language);
+			    }
+			  if (except.reason > 0)
+			    {
+			      PyErr_SetString (PyExc_RuntimeError,
+					       except.message);
+			      goto locals_error;
+			    }
+
+			  ui_out_field_stream (out, "value", stb);
 			}
-		      fprintf_filtered (gdb_stdout, "\n");
-		      gdb_flush (gdb_stdout);
+
+		      ui_out_text (out, "\n");
+		      do_cleanups (inner_cleanup);
+
 		    }
 
 		  if (! item && PyErr_Occurred())
@@ -197,9 +262,10 @@ py_print_locals (PyObject *filter,
 		}
 	    }
 	}
+      else
+	goto locals_error;
     }
-  else
-    goto locals_error;
+
 
   do_cleanups (old_chain);
   return 1;
@@ -213,7 +279,7 @@ static int
 py_print_args (PyObject *filter,
 	       struct ui_out *out,
 	       struct value_print_options opts,
-	       int print_type,
+	       int mi_print_type,
 	       const char *print_args_type)
 {
   struct cleanup *old_chain;
@@ -285,7 +351,7 @@ py_print_args (PyObject *filter,
 
 		      if (ui_out_is_mi_like_p (out))
 			{
-			  if(print_type != PRINT_NO_VALUES)
+			  if(mi_print_type != PRINT_NO_VALUES)
 			    {
 			      inner_cleanup =
 				make_cleanup_ui_out_tuple_begin_end (out,
@@ -303,23 +369,9 @@ py_print_args (PyObject *filter,
 		      opts.deref_ref = 1;
 
 		      if (ui_out_is_mi_like_p (out)
-			  && print_type == PRINT_SIMPLE_VALUES)
+			  && mi_print_type == PRINT_SIMPLE_VALUES)
 			{
-			  TRY_CATCH (except, RETURN_MASK_ALL)
-			    {
-			      struct type *type;
-			      stb = mem_fileopen ();
-			      make_cleanup_ui_file_delete (stb);
-			      type = check_typedef (value_type (val));
-			      type_print (type, "", stb, -1);
-			      ui_out_field_stream (out, "type", stb);
-			    }
-			  if (except.reason > 0)
-			    {
-			      PyErr_SetString (PyExc_RuntimeError,
-					       except.message);
-			      goto args_error;
-			    }
+			  py_print_type (out, val);
 			}
 
 		      if (! ui_out_is_mi_like_p (out))
@@ -327,8 +379,9 @@ py_print_args (PyObject *filter,
 			  opts.summary = !strcmp (print_args_type, "scalars");
 			}
 
-		      if (ui_out_is_mi_like_p (out)
-			  && print_type != PRINT_NO_VALUES)
+		      if (! ui_out_is_mi_like_p (out)
+			  || (ui_out_is_mi_like_p (out)
+			      && mi_print_type != PRINT_NO_VALUES))
 			{
 			  stb = mem_fileopen ();
 			  make_cleanup_ui_file_delete (stb);
@@ -420,7 +473,10 @@ py_print_frame (PyObject *filter,
   struct frame_info *frame = NULL;
   struct cleanup *cleanup_stack = make_cleanup (null_cleanup, NULL);
 
-  cleanup_stack	= make_cleanup_ui_out_tuple_begin_end (out, "frame");
+  /* -stack-list-locals and -stack-list-arguments do not require a
+     wrapping frame attribute.  */
+  if (print_frame_info || print_args)
+    make_cleanup_ui_out_tuple_begin_end (out, "frame");
 
   /* Get the underlying frame.  */
   if (PyObject_HasAttrString (filter, "inferior_frame"))
@@ -473,7 +529,7 @@ py_print_frame (PyObject *filter,
 
     }
   /* Print frame level.  */
-  if (print_level)
+  if ((print_frame_info || print_args) && print_level)
     {
       struct frame_info **slot;
       int level;
@@ -620,7 +676,9 @@ py_print_frame (PyObject *filter,
 
   if (print_locals)
     {
-      int success = py_print_locals (filter, opts);
+      int success = py_print_locals (filter, out, opts,
+				     mi_print_args_type, indent);
+
       if (success == 0 && PyErr_Occurred ())
 	goto error;
     }
@@ -669,7 +727,7 @@ py_print_frame (PyObject *filter,
 		  if (success == 0 && PyErr_Occurred ())
 		    {
 		      Py_DECREF (item);
-		      do_cleanups (cleanup_stack);
+		      //do_cleanups (cleanup_stack);
 		      goto error;
 		    }
 
diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
index a4210e4..e946396 100644
--- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
+++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
@@ -104,10 +104,35 @@ mi_gdb_test "-stack-list-arguments 2 22 27" \
 
 mi_gdb_test "-stack-list-arguments 2 raw-frames" \
     "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
-    "stack-list-arguments 2"
+    "stack-list-arguments 2 raw-frames"
 
 mi_gdb_test "-stack-list-arguments 2 raw-frames 22 27" \
     "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
-    "stack-list-arguments 2 22 27"
+    "stack-list-arguments 2 raw-frames 22 27"
+
+#stack-list-locals
+mi_gdb_test "-stack-list-locals 0 raw-frames" \
+    "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
+    "stack-list-locals 0 raw-frames"
+
+mi_gdb_test "-stack-list-locals 1 raw-frames" \
+    "\\^done,locals=\\\[{name=\"str\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",value=\"12\"},{name=\"c\",value=\"5\"}\\\]" \
+    "stack-list-locals 1 raw-frames"
+
+mi_gdb_test "-stack-list-locals 2 raw-frames" \
+    "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short int\",value=\"5\"}\\\]" \
+    "stack-list-locals 2 raw-frames"
+
+mi_gdb_test "-stack-list-locals 0" \
+    "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
+    "stack-list-locals 0"
+
+mi_gdb_test "-stack-list-locals 1" \
+    "\\^done,locals=\\\[{name=\"str\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",value=\"12\"},{name=\"c\",value=\"5\"}\\\]" \
+    "stack-list-locals 1"
+
+mi_gdb_test "-stack-list-locals 2" \
+    "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short int\",value=\"5\"}\\\]" \
+    "stack-list-locals 2"
 
 remote_file host delete ${remote_python_file}
diff --git a/gdb/testsuite/gdb.python/py-framefilter.c b/gdb/testsuite/gdb.python/py-framefilter.c
index 931ae42..3e7f145 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.c
+++ b/gdb/testsuite/gdb.python/py-framefilter.c
@@ -67,6 +67,8 @@ void func1(void)
 
 int func2(void)
 {
+  int foo = 42;
+
   func1();
   return 1;
 }
diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp
index 44db502..e08c349 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.exp
+++ b/gdb/testsuite/gdb.python/py-framefilter.exp
@@ -17,6 +17,7 @@
 # frame-filters.
 
 load_lib gdb-python.exp
+global hex
 
 set testfile "py-framefilter"
 set srcfile ${testfile}.c
@@ -61,24 +62,31 @@ gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"]
 gdb_continue_to_breakpoint "Backtrace end breakpoint"
 
 gdb_test "info frame-filter" \
-    {.*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*}
+    ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*"
 # Test raw
 gdb_test "bt raw" \
-    {.*#0.*end_func.*#22.*in func1.*#27.*in main ().*}
+    ".*#0.*end_func.*#22.*in func1.*#27.*in main ().*"
 
 # Test reverse
 gdb_test "bt" \
-    {.*#0.*cnuf_dne.*#22.*in 1cnuf.*#27.*in niam ().*}
+    ".*#0.*cnuf_dne.*#22.*in 1cnuf.*#27.*in niam ().*"
 
 # Disable Reverse
 gdb_test_no_output "set python frame-filter disable global Reverse"
 gdb_test "bt" \
-    {.*#0.*end_func.*#22.*in func1.*#27.*in main ().*}
+    ".*#0.*end_func.*#22.*in func1.*#27.*in main ().*"
 
 gdb_test "bt -2" \
-    {.*#26.*func5.*#27.*in main ().*}
+    ".*#26.*func5.*#27.*in main ().*"
 
 gdb_test "bt 3" \
-    {.*#0.*end_func.*#1.*in funca ().*#2.*in funcb ().*}
+    ".*#0.*end_func.*#1.*in funca ().*#2.*in funcb ().*"
+
+gdb_test "bt raw full" \
+    ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca ().*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*"
+
+gdb_test "bt full" \
+    ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca ().*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*#22.*in func1 \\(\\).*#23.*in func2 \\(\\).*foo = 42.*"
+
 
 remote_file host delete ${remote_python_file}


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


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

only message in thread, other threads:[~2012-08-09 16:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-09 16:59 [SCM] archer-pmuldoon-python-backtrace: Add -stack-list-locals, add a lot of MI test cases. Fix several locals bugs 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).