oops - omitted
[deliverable/binutils-gdb.git] / gdb / stack.c
index f2aeb101bf90a3c2fc619b48d1cbe0acf9753e51..a4b392e563b09fbc1fed64795fe02859fb1f915c 100644 (file)
@@ -54,6 +54,7 @@
 
 #include "psymtab.h"
 #include "symfile.h"
+#include "python/python.h"
 
 void (*deprecated_selected_frame_level_changed_hook) (int);
 
@@ -323,7 +324,8 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
        }
     }
 
-  if (SYMBOL_CLASS (sym) == LOC_COMPUTED
+  if (SYMBOL_COMPUTED_OPS (sym) != NULL
+      && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
       && print_entry_values != print_entry_values_no
       && (print_entry_values != print_entry_values_if_needed
          || !val || value_optimized_out (val)))
@@ -1002,10 +1004,10 @@ get_last_displayed_sal (struct symtab_and_line *sal)
 
 
 /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
-   corresponding to FRAME.  */
+   corresponding to FRAME.  FUNNAME needs to be freed by the caller.  */
 
 void
-find_frame_funname (struct frame_info *frame, const char **funname,
+find_frame_funname (struct frame_info *frame, char **funname,
                    enum language *funlang, struct symbol **funcp)
 {
   struct symbol *func;
@@ -1036,27 +1038,29 @@ find_frame_funname (struct frame_info *frame, const char **funname,
          changed (and we'll create a find_pc_minimal_function or some
          such).  */
 
-      struct minimal_symbol *msymbol = NULL;
+      struct bound_minimal_symbol msymbol;
 
       /* Don't attempt to do this for inlined functions, which do not
         have a corresponding minimal symbol.  */
       if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
        msymbol
          = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
+      else
+       memset (&msymbol, 0, sizeof (msymbol));
 
-      if (msymbol != NULL
-         && (SYMBOL_VALUE_ADDRESS (msymbol)
+      if (msymbol.minsym != NULL
+         && (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
              > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
        {
          /* We also don't know anything about the function besides
             its address and name.  */
          func = 0;
-         *funname = SYMBOL_PRINT_NAME (msymbol);
-         *funlang = SYMBOL_LANGUAGE (msymbol);
+         *funname = xstrdup (SYMBOL_PRINT_NAME (msymbol.minsym));
+         *funlang = SYMBOL_LANGUAGE (msymbol.minsym);
        }
       else
        {
-         *funname = SYMBOL_PRINT_NAME (func);
+         *funname = xstrdup (SYMBOL_PRINT_NAME (func));
          *funlang = SYMBOL_LANGUAGE (func);
          if (funcp)
            *funcp = func;
@@ -1071,25 +1075,25 @@ find_frame_funname (struct frame_info *frame, const char **funname,
 
              if (func_only)
                {
+                 xfree (*funname);
                  *funname = func_only;
-                 make_cleanup (xfree, func_only);
                }
            }
        }
     }
   else
     {
-      struct minimal_symbol *msymbol;
+      struct bound_minimal_symbol msymbol;
       CORE_ADDR pc;
 
       if (!get_frame_address_in_block_if_available (frame, &pc))
        return;
 
       msymbol = lookup_minimal_symbol_by_pc (pc);
-      if (msymbol != NULL)
+      if (msymbol.minsym != NULL)
        {
-         *funname = SYMBOL_PRINT_NAME (msymbol);
-         *funlang = SYMBOL_LANGUAGE (msymbol);
+         *funname = xstrdup (SYMBOL_PRINT_NAME (msymbol.minsym));
+         *funlang = SYMBOL_LANGUAGE (msymbol.minsym);
        }
     }
 }
@@ -1101,7 +1105,7 @@ print_frame (struct frame_info *frame, int print_level,
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   struct ui_out *uiout = current_uiout;
-  const char *funname = NULL;
+  char *funname = NULL;
   enum language funlang = language_unknown;
   struct ui_file *stb;
   struct cleanup *old_chain, *list_chain;
@@ -1116,6 +1120,7 @@ print_frame (struct frame_info *frame, int print_level,
   old_chain = make_cleanup_ui_file_delete (stb);
 
   find_frame_funname (frame, &funname, &funlang, &func);
+  make_cleanup (xfree, funname);
 
   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
                        gdbarch, pc);
@@ -1202,12 +1207,9 @@ print_frame (struct frame_info *frame, int print_level,
 
   if (pc_p && (funname == NULL || sal.symtab == NULL))
     {
-#ifdef PC_SOLIB
-      char *lib = PC_SOLIB (get_frame_pc (frame));
-#else
       char *lib = solib_name_from_address (get_frame_program_space (frame),
                                           get_frame_pc (frame));
-#endif
+
       if (lib)
        {
          annotate_frame_where ();
@@ -1423,13 +1425,13 @@ frame_info (char *addr_exp, int from_tty)
     }
   else if (frame_pc_p)
     {
-      struct minimal_symbol *msymbol;
+      struct bound_minimal_symbol msymbol;
 
       msymbol = lookup_minimal_symbol_by_pc (frame_pc);
-      if (msymbol != NULL)
+      if (msymbol.minsym != NULL)
        {
-         funname = SYMBOL_PRINT_NAME (msymbol);
-         funlang = SYMBOL_LANGUAGE (msymbol);
+         funname = SYMBOL_PRINT_NAME (msymbol.minsym);
+         funlang = SYMBOL_LANGUAGE (msymbol.minsym);
        }
     }
   calling_frame_info = get_prev_frame (fi);
@@ -1651,13 +1653,15 @@ frame_info (char *addr_exp, int from_tty)
    frames.  */
 
 static void
-backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
+backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
+                    int from_tty)
 {
   struct frame_info *fi;
   int count;
   int i;
   struct frame_info *trailing;
-  int trailing_level;
+  int trailing_level, py_start = 0, py_end = 0;
+  enum py_bt_status result = PY_BT_ERROR;
 
   if (!target_has_stack)
     error (_("No stack."));
@@ -1676,6 +1680,7 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
        {
          struct frame_info *current;
 
+         py_start = count;
          count = -count;
 
          current = trailing;
@@ -1697,9 +1702,17 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
 
          count = -1;
        }
+      else
+       {
+         py_start = 0;
+         py_end = count;
+       }
     }
   else
-    count = -1;
+    {
+      py_end = -1;
+      count = -1;
+    }
 
   if (info_verbose)
     {
@@ -1719,16 +1732,40 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
        }
     }
 
-  for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
+  if (! no_filters)
     {
-      QUIT;
+      int flags = PRINT_LEVEL | PRINT_FRAME_INFO | PRINT_ARGS;
+      enum py_frame_args arg_type;
 
-      /* Don't use print_stack_frame; if an error() occurs it probably
-         means further attempts to backtrace would fail (on the other
-         hand, perhaps the code does or could be fixed to make sure
-         the frame->prev field gets set to NULL in that case).  */
-      print_frame_info (fi, 1, LOCATION, 1);
       if (show_locals)
+       flags |= PRINT_LOCALS;
+
+      if (!strcmp (print_frame_arguments, "scalars"))
+       arg_type = CLI_SCALAR_VALUES;
+      else if (!strcmp (print_frame_arguments, "all"))
+       arg_type = CLI_ALL_VALUES;
+      else
+       arg_type = NO_VALUES;
+
+      result = apply_frame_filter (get_current_frame (), flags, arg_type,
+                                  current_uiout, py_start, py_end);
+
+    }
+  /* Run the inbuilt backtrace if there are no filters registered, or
+     "no-filters" has been specified from the command.  */
+  if (no_filters ||  result == PY_BT_NO_FILTERS)
+    {
+      for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
+       {
+         QUIT;
+
+         /* Don't use print_stack_frame; if an error() occurs it probably
+            means further attempts to backtrace would fail (on the other
+            hand, perhaps the code does or could be fixed to make sure
+            the frame->prev field gets set to NULL in that case).  */
+
+         print_frame_info (fi, 1, LOCATION, 1);
+         if (show_locals)
        {
          struct frame_id frame_id = get_frame_id (fi);
 
@@ -1744,24 +1781,25 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
            }
        }
 
-      /* Save the last frame to check for error conditions.  */
-      trailing = fi;
-    }
+         /* Save the last frame to check for error conditions.  */
+         trailing = fi;
+       }
 
-  /* If we've stopped before the end, mention that.  */
-  if (fi && from_tty)
-    printf_filtered (_("(More stack frames follow...)\n"));
+      /* If we've stopped before the end, mention that.  */
+      if (fi && from_tty)
+       printf_filtered (_("(More stack frames follow...)\n"));
 
-  /* If we've run out of frames, and the reason appears to be an error
-     condition, print it.  */
-  if (fi == NULL && trailing != NULL)
-    {
-      enum unwind_stop_reason reason;
+      /* If we've run out of frames, and the reason appears to be an error
+        condition, print it.  */
+      if (fi == NULL && trailing != NULL)
+       {
+         enum unwind_stop_reason reason;
 
-      reason = get_frame_unwind_stop_reason (trailing);
-      if (reason >= UNWIND_FIRST_ERROR)
-       printf_filtered (_("Backtrace stopped: %s\n"),
-                        frame_stop_reason_string (reason));
+         reason = get_frame_unwind_stop_reason (trailing);
+         if (reason >= UNWIND_FIRST_ERROR)
+           printf_filtered (_("Backtrace stopped: %s\n"),
+                            frame_stop_reason_string (reason));
+       }
     }
 }
 
@@ -1769,7 +1807,8 @@ static void
 backtrace_command (char *arg, int from_tty)
 {
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-  int fulltrace_arg = -1, arglen = 0, argc = 0;
+  int fulltrace_arg = -1, arglen = 0, argc = 0, no_filters  = -1;
+  int user_arg = 0;
 
   if (arg)
     {
@@ -1786,25 +1825,31 @@ backtrace_command (char *arg, int from_tty)
          for (j = 0; j < strlen (argv[i]); j++)
            argv[i][j] = tolower (argv[i][j]);
 
-         if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
-           fulltrace_arg = argc;
+         if (no_filters < 0 && subset_compare (argv[i], "no-filters"))
+           no_filters = argc;
          else
            {
-             arglen += strlen (argv[i]);
-             argc++;
+             if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
+               fulltrace_arg = argc;
+             else
+               {
+                 user_arg++;
+                 arglen += strlen (argv[i]);
+               }
            }
+         argc++;
        }
-      arglen += argc;
-      if (fulltrace_arg >= 0)
+      arglen += user_arg;
+      if (fulltrace_arg >= 0 || no_filters >= 0)
        {
          if (arglen > 0)
            {
              arg = xmalloc (arglen + 1);
              make_cleanup (xfree, arg);
              arg[0] = 0;
-             for (i = 0; i < (argc + 1); i++)
+             for (i = 0; i < argc; i++)
                {
-                 if (i != fulltrace_arg)
+                 if (i != fulltrace_arg && i != no_filters)
                    {
                      strcat (arg, argv[i]);
                      strcat (arg, " ");
@@ -1816,7 +1861,8 @@ backtrace_command (char *arg, int from_tty)
        }
     }
 
-  backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, from_tty);
+  backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */,
+                      no_filters >= 0 /* no frame-filters */, from_tty);
 
   do_cleanups (old_chain);
 }
@@ -1824,7 +1870,7 @@ backtrace_command (char *arg, int from_tty)
 static void
 backtrace_full_command (char *arg, int from_tty)
 {
-  backtrace_command_1 (arg, 1 /* show_locals */, from_tty);
+  backtrace_command_1 (arg, 1 /* show_locals */, 0, from_tty);
 }
 \f
 
@@ -2558,7 +2604,9 @@ It can be a stack frame number or the address of the frame.\n"));
   add_com ("backtrace", class_stack, backtrace_command, _("\
 Print backtrace of all stack frames, or innermost COUNT frames.\n\
 With a negative argument, print outermost -COUNT frames.\nUse of the \
-'full' qualifier also prints the values of the local variables.\n"));
+'full' qualifier also prints the values of the local variables.\n\
+Use of the 'no-filters' qualifier prohibits frame filters from executing\n\
+on this backtrace.\n"));
   add_com_alias ("bt", "backtrace", class_stack, 0);
   if (xdb_commands)
     {
This page took 0.068633 seconds and 4 git commands to generate.