changeset 7818:5640a70cbab1

Add Ffilemarker and fix for 'dbstep in'
author David Bateman <dbateman@free.fr>
date Sun, 25 May 2008 15:04:37 +0200
parents 31fb919ba0c0
children b7e8ea6a5143
files src/ChangeLog src/debug.cc src/input.cc src/input.h src/pt-bp.h src/pt.cc src/pt.h src/symtab.cc src/toplev.cc src/utils.cc
diffstat 10 files changed, 132 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun May 25 16:32:30 2008 +0200
+++ b/src/ChangeLog	Sun May 25 15:04:37 2008 +0200
@@ -1,5 +1,29 @@
 2008-06-02  David Bateman  <dbateman@free.fr>
 
+	* pt.cc (tree:last_break_function): Next pointer to last function
+	with a breakpoint.
+	* pt.h (tree:last_break_function): ditto.
+	* debug.cc (Fdbstep): Use tree::break_function value of zero to
+	signal to step into the next function. Set tree::last_break_function
+	to indicate position of last breakpoint.
+	(Fdbnext):  Set tree::last_break_function to indicate position of
+	last breakpoint.
+	* pt-bp.h (MAYBE_DO_BREAKPOINT): Check tree::break_function value
+	of zero as well. Only check tree::last_line if we are in teh same
+	function as the last breakpoint.
+	* input.cc (char Vfilemarker): New global variable.
+	(Ffilemarker): New function to query and set Vfilemarker.
+	* input.h (extern char Vfilemarker): Make Vfilemarker available.
+	* util.cc (fcn_file_in_path): If the input argument contains
+	Vfilemarker, strip the trailing part of string from this point
+	when looking for function file.
+	* toplev.cc (octave_call_stack::fo_backtrace): Mark subfunctions
+	with the name of the parent function and Vfilemarker.
+	* symtab.cc (symbol_table::find_function (const std::string&,
+	tree_argument_list *, const string_vector&, octave_value_list*,
+	bool&): If function name contains Vfilemarker, check in scope of
+	specified parent function.
+
 	* DLD-FUNCTIONS/betainc.cc: Move test code here. Add test code for
 	single precision type.
 	* DLD-FUNCTIONS/gammainc.cc: Ditto.
--- a/src/debug.cc	Sun May 25 16:32:30 2008 +0200
+++ b/src/debug.cc	Sun May 25 15:04:37 2008 +0200
@@ -869,9 +869,12 @@
 
 		  tree::break_next = 0;
 
-		  tree::last_line = 0;
+		  tree::last_line = Vdebugging_current_line;
 
-		  tree::break_function = octave_call_stack::caller_user_code ();
+		  tree::break_function = 0;
+
+		  tree::last_break_function = 
+		    octave_call_stack::caller_user_code ();
 		}
 	      else if (arg == "out")
 		{
@@ -883,7 +886,11 @@
 
 		  // Next to skip 2 here. One for the oct-file dbstep and 
 		  // another for the function we actually want to step out of.
-		  tree::break_function = octave_call_stack::caller_user_code (2);
+		  tree::break_function = 
+		    octave_call_stack::caller_user_code (2);
+
+		  tree::last_break_function = 
+		    octave_call_stack::caller_user_code ();
 		}
 	      else
 		{
@@ -899,6 +906,9 @@
 		  tree::last_line = Vdebugging_current_line;
 		  
 		  tree::break_function = octave_call_stack::caller_user_code ();
+
+		  tree::last_break_function = 
+		    octave_call_stack::caller_user_code ();
 		}
 	    }
 	}
@@ -911,6 +921,9 @@
 	  tree::last_line = Vdebugging_current_line;
 		  
 	  tree::break_function = octave_call_stack::caller_user_code ();
+
+	  tree::last_break_function = 
+	    octave_call_stack::caller_user_code ();
 	}
     }
   else
@@ -974,6 +987,8 @@
 	tree::last_line = Vdebugging_current_line;
 		  
 	tree::break_function = octave_call_stack::caller_user_code ();
+
+	tree::last_break_function = octave_call_stack::caller_user_code ();
       }
     else
       print_usage ();
--- a/src/input.cc	Sun May 25 16:32:30 2008 +0200
+++ b/src/input.cc	Sun May 25 15:04:37 2008 +0200
@@ -153,6 +153,9 @@
 // TRUE if we are running in the Emacs GUD mode.
 static bool Vgud_mode = false;
 
+// The filemarker used to separate filenames from subfunction names
+char Vfilemarker = '>';
+
 static void
 do_input_echo (const std::string& input_string)
 {
@@ -1333,6 +1336,44 @@
   return retval;
 }
 
+DEFUN (filemarker, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} filemarker ()\n\
+Returns or sets the character used to separate filename from the\n\
+the subfunction names contained within the file. This can be used in\n\
+a generic manner to interact with subfunctions. For example\n\
+\n\
+@example\n\
+help ([\"myfunc\", filemarker, \"mysubfunc\"])\n\
+@end example\n\
+\n\
+@noindent\n\
+returns the help string associated with the sub-function @code{mysubfunc}\n\
+of the function @code{myfunc}. Another use of @code{filemarker} is when\n\
+debugging it allows easier placement of breakpoints within sub-functions.\n\
+For example\n\
+\n\
+@example\n\
+dbstop ([\"myfunc\", filemarker, \"mysubfunc\"])\n\
+@end example\n\
+\n\
+@noindent\n\
+will set a breakpoint at the first line of the subfunction @code{mysubfunc}.\n\
+@end deftypefn")
+{
+  char tmp = Vfilemarker;
+  octave_value retval = SET_INTERNAL_VARIABLE (filemarker);
+
+  // The character passed must not be a legal character for a function name
+  if (! error_state && (::isalnum (Vfilemarker) || Vfilemarker == '_'))
+    {
+      Vfilemarker = tmp;
+      error ("filemarker: character can not be a valid character for a function name");
+    }
+
+  return retval;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/input.h	Sun May 25 16:32:30 2008 +0200
+++ b/src/input.h	Sun May 25 15:04:37 2008 +0200
@@ -104,6 +104,8 @@
 
 extern std::string VPS4;
 
+extern char Vfilemarker;
+
 enum echo_state
 {
   ECHO_OFF = 0,
--- a/src/pt-bp.h	Sun May 25 16:32:30 2008 +0200
+++ b/src/pt-bp.h	Sun May 25 15:04:37 2008 +0200
@@ -166,10 +166,9 @@
       octave_function *xfcn = octave_call_stack::current (); \
  \
       if (octave_debug_on_interrupt_state \
-	  || (tree::break_next >= 0 && tree::last_line == 0) \
 	  || (tree::break_next >= 0 \
-	      && xfcn == tree::break_function \
-	      && tree::last_line != line ()) \
+	      && (tree::break_function == 0 || tree::break_function == xfcn) \
+	      && (tree::last_break_function != xfcn || tree::last_line != line ())) \
 	  || is_breakpoint ()) \
         { \
 	  if (!octave_debug_on_interrupt_state && tree::break_next > 0) \
--- a/src/pt.cc	Sun May 25 16:32:30 2008 +0200
+++ b/src/pt.cc	Sun May 25 15:04:37 2008 +0200
@@ -40,6 +40,9 @@
 int tree::last_line = 0;
 
 // The function where the last breakpoint occurred.
+const octave_function *tree::last_break_function = 0;
+
+// The function where the next breakpoint is request.
 const octave_function *tree::break_function = 0;
 
 // The statement where the last breakpoint occurred.
--- a/src/pt.h	Sun May 25 16:32:30 2008 +0200
+++ b/src/pt.h	Sun May 25 15:04:37 2008 +0200
@@ -72,6 +72,9 @@
   static int last_line; 
 
   // The function where the last breakpoint occurred.
+  static const octave_function *last_break_function;
+
+  // The function where the next breakpoint is request.
   static const octave_function *break_function;
 
   // The statement where the last breakpoint occurred.
--- a/src/symtab.cc	Sun May 25 16:32:30 2008 +0200
+++ b/src/symtab.cc	Sun May 25 15:04:37 2008 +0200
@@ -792,7 +792,32 @@
 			     octave_value_list& evaluated_args,
 			     bool& args_evaluated)
 {
-  return find (name, args, arg_names, evaluated_args, args_evaluated, true);
+  octave_value retval;
+  size_t pos = name.find_first_of (Vfilemarker);
+
+  if (pos == NPOS)
+    retval = find (name, args, arg_names, evaluated_args, args_evaluated, true);
+  else
+    {
+      std::string fcn_scope = name.substr(0, pos);
+      scope_id stored_scope = xcurrent_scope;
+      xcurrent_scope = xtop_scope;
+      octave_value parent = find_function (name.substr(0, pos));
+      if (parent.is_defined ())
+	{
+	  octave_function *parent_fcn = parent.function_value ();
+	  if (parent_fcn)
+	    {
+	      xcurrent_scope = parent_fcn->scope ();
+	      if (xcurrent_scope > 1)
+		retval = find_function (name.substr (pos + 1), args, arg_names, 
+					evaluated_args, args_evaluated);
+	    }
+	}
+      xcurrent_scope = stored_scope;
+    }
+
+  return retval;
 }
 
 void
--- a/src/toplev.cc	Sun May 25 16:32:30 2008 +0200
+++ b/src/toplev.cc	Sun May 25 15:04:37 2008 +0200
@@ -213,7 +213,11 @@
 	  if (f)
 	    {
 	      file(k) = f->fcn_file_name ();
-	      name(k) = f->name ();
+	      std::string parent_fcn_name = f->parent_fcn_name ();
+	      if (parent_fcn_name == std::string ())
+		name(k) = f->name ();
+	      else
+		name(k) = f->parent_fcn_name () + Vfilemarker + f->name ();
 
 	      tree_statement *stmt = elt.stmt;
 
--- a/src/utils.cc	Sun May 25 16:32:30 2008 +0200
+++ b/src/utils.cc	Sun May 25 15:04:37 2008 +0200
@@ -435,7 +435,14 @@
       else if (len > 2 && name [len - 2] == '.' && name [len - 1] == 'm')
 	retval = load_path::find_fcn_file (name.substr (0, len-2));
       else
-	retval = load_path::find_fcn_file (name);
+	{
+	  std::string fname = name;
+	  size_t pos = name.find_first_of (Vfilemarker);
+	  if (pos != NPOS)
+	    fname = name.substr (0, pos);
+
+	  retval = load_path::find_fcn_file (fname);
+	}
     }
 
   return retval;