octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

debug breakpoint commands want line numbers as strings!!


From: David Bateman
Subject: debug breakpoint commands want line numbers as strings!!
Date: Tue, 22 May 2007 02:45:07 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Is there any reason why the debug commands require that the line numbers
for breakpoints are set as strings? It seems that it makes more sense
that these are integers or matrices instead. It also means that reseting
all breakpoints in a function can't be written as

dbclear ("foo", dbstatus ("foo"))

which would make a lot of sense to me.. what about the attached patch?
The above code then works, and it even keeps backward compatibility.

D.
Index: src/debug.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/debug.cc,v
retrieving revision 1.21
diff -u -r1.21 debug.cc
--- src/debug.cc        16 Feb 2007 08:10:54 -0000      1.21
+++ src/debug.cc        22 May 2007 00:42:09 -0000
@@ -87,14 +87,15 @@
 
 DEFCMD (dbstop, args, ,
   "-*- texinfo -*-\n\
address@hidden {Loadable Function} {rline =} dbstop (func, line)\n\
address@hidden {Loadable Function} {rline =} dbstop (func, line, @dots{})\n\
 Set a breakpoint in a function\n\
 @table @code\n\
 @item func\n\
 String representing the function name.  When already in debug\n\
 mode this should be left out and only the line should be given.\n\
 @item line\n\
-Line you would like the breakpoint to be set on\n\
+Line you would like the breakpoint to be set on. Multiple\n\
+lines might be given as seperate arguments or as a vector.\n\
 @end table\n\
 \n\
 The rline returned is the real line that the breakpoint was set at.\n\
@@ -102,118 +103,152 @@
 @end deftypefn")
 {
   octave_value retval;
-
-  int result = -1;
   int nargin = args.length ();
+  int idx = 0;
+  std::string symbol_name = "";
 
-  string_vector argv = args.make_argv ("dbstop");
+  if (nargin != 1 && args(0).is_string())
+    {
+      symbol_name = args(0).string_value ();
+      idx = 1;
+    }
 
-  if (error_state)
-    return retval;
+  octave_user_function *dbg_fcn = get_user_function (symbol_name);
 
-  if (nargin == 2)
+  if (dbg_fcn)
     {
-      std::string symbol_name = argv[1];
+      octave_idx_type nsize = 10;
+      RowVector results (nsize);
+      octave_idx_type nr = 0;
 
-      std::string line_number = argv[2];
+      tree_statement_list *cmds = dbg_fcn->body ();
 
-      int line = atoi (line_number.c_str ());
+      for (int i = idx; i < nargin; i++)
+       {
+         if (args(i).is_string ())
+           {
+             int line = atoi (args(i).string_value ().c_str ());
 
-      octave_user_function *dbg_fcn = get_user_function (symbol_name);
+             if (error_state)
+               break;
 
-      if (dbg_fcn)
-       {
-         tree_statement_list *cmds = dbg_fcn->body ();
-         result = cmds->set_breakpoint (line);
-       }
-      else
-       error ("dbstop: unable to find the function requested\n");
-    }
-  else if (nargin == 1)
-    {
-      std::string line_number = argv[1];
+             if (nr == nsize)
+               {
+                 nsize *= 2;
+                 results.resize (nsize);
+               }
+
+             results(nr++) = cmds->set_breakpoint (line);
+           }
+         else
+           {
+             const NDArray arg = args(i).array_value();
+
+             if (error_state)
+               break;
+
+             for (octave_idx_type j = 0; j < arg.nelem(); j++)
+               {
+                 int line = static_cast<int> (arg.elem (j));
+
+                 if (error_state)
+                   break;
 
-      int line = atoi (line_number.c_str ());
+                 if (nr == nsize)
+                   {
+                     nsize *= 2;
+                     results.resize (nsize);
+                   }
 
-      octave_user_function *dbg_fcn = get_user_function ();
+                 results(nr++) = cmds->set_breakpoint (line);
+               }
+
+             if (error_state)
+               break;
+           }
+       }
 
-      if (dbg_fcn)
+      if (! error_state)
        {
-         tree_statement_list *cmds = dbg_fcn->body ();
-         result = cmds->set_breakpoint (line);
+         results.resize (nr);
+         retval = results;
        }
-      else
-       error ("dbstop: unable to find the function requested\n");      
     }
   else
-    error ("dbstop: one argument when in a function and two when not\n");
-
-  retval = result;
+    error ("dbstop: unable to find the function requested\n");
 
   return retval;
 }
 
 DEFCMD (dbclear, args, ,
   "-*- texinfo -*-\n\
address@hidden {Loadable Function} {} dbclear (func, line)\n\
address@hidden {Loadable Function} {} dbclear (func, line, @dots{})\n\
 Delete a breakpoint in a function\n\
 @table @code\n\
 @item func\n\
 String representing the function name.  When already in debug\n\
 mode this should be left out and only the line should be given.\n\
 @item line\n\
-Line where you would like to remove the the breakpoint\n\
+Line where you would like to remove the the breakpoint. Multiple\n\
+lines might be given as seperate arguments or as a vector.\n\
 @end table\n\
 No checking is done to make sure that the line you requested is really\n\
-a breakpoint.   If you get the wrong line nothing will happen.\n\
+a breakpoint. If you get the wrong line nothing will happen.\n\
 @seealso{dbstop, dbstatus, dbwhere}\n\
 @end deftypefn")
 {
   octave_value retval;
-
-  std::string symbol_name = "";
-  std::string line_number;
-
-  int line = -1;
   int nargin = args.length ();
+  int idx = 0;
+  std::string symbol_name = "";
 
-  string_vector argv = args.make_argv ("dbclear");
+  if (nargin != 1 && args(0).is_string())
+    {
+      symbol_name = args(0).string_value ();
+      idx = 1;
+    }
 
-  if (error_state)
-    return retval;
+  octave_user_function *dbg_fcn = get_user_function (symbol_name);
 
-  if (nargin == 1 || nargin == 2)
+  if (dbg_fcn)
     {
-      if (nargin == 2)
-       {
-         symbol_name = argv[1];
+      tree_statement_list *cmds = dbg_fcn->body ();
 
-         octave_stdout << argv[1] << std::endl;
-         line_number = argv[2];
-       }
-      else if (nargin == 1)
+      for (int i = idx; i < nargin; i++)
        {
-         line_number = argv[1];
-       }
+         if (args(i).is_string ())
+           {
+             int line = atoi (args(i).string_value ().c_str ());
 
-      if (line_number.compare ("all") && line_number.compare ("ALL"))
-       line = atoi (line_number.c_str ());
-      else
-       line = -1;
+             if (error_state)
+               break;
 
-      octave_stdout << "symbol_name = " << symbol_name << std::endl;
-      octave_user_function *dbg_fcn = get_user_function (symbol_name);
+             cmds->delete_breakpoint (line);
+           }
+         else
+           {
+             const NDArray arg = args(i).array_value();
 
-      if (dbg_fcn)
-       {
-         tree_statement_list *cmds = dbg_fcn->body ();
-         cmds->delete_breakpoint (line);
+             if (error_state)
+               break;
+
+             for (octave_idx_type j = 0; j < arg.nelem(); j++)
+               {
+                 int line = static_cast<int> (arg.elem (j));
+
+                 if (error_state)
+                   break;
+
+                 cmds->delete_breakpoint (line);
+               }
+
+             if (error_state)
+               break;
+           }
        }
-      else
-       error ("dbclear: unable to find the function requested\n");
     }
   else
-    error ("dbclear: expecting one or two arguements\n");
+    error ("dbclear: unable to find the function requested\n");
 
   return retval;
 }
2007-05-21  David Bateman  <address@hidden>

        * debug.cc (Fdbstop): handle integer, vector and multiple line
        arguments.
        (Fdbclar): ditto. Eliminate extraneous debugging messages.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]