changeset 33434:69eb4c27d8c8

Emit error when trying to set breakpoint in non-existent method (bug #65610). * libinterp/corefcn/debug.cc (Fdbstop): Use a line number of -1 to indicate that the function was called without line number. * libinterp/parse-tree/bp-table.cc (octave_usercode::operator ()): Return nullptr if `dbstop` was called without line number on a classdef class without having explicitly specified a (valid) method name. (bp_table::add_breakpoints_in_function): Emit error if no function could be found with the specified name. Remove checks for valid pointer that are no longer needed. * test/classdef-debug/test-classdef-breakpoints.tst: Mark test as fixed.
author Markus Mützel <markus.muetzel@gmx.de>
date Fri, 19 Apr 2024 18:30:39 +0200
parents 761b404e9569
children 066a27297ba3 60772ed3e920
files libinterp/corefcn/debug.cc libinterp/parse-tree/bp-table.cc test/classdef-debug/test-classdef-breakpoints.tst
diffstat 3 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/debug.cc	Thu Apr 18 19:43:23 2024 -0700
+++ b/libinterp/corefcn/debug.cc	Fri Apr 19 18:30:39 2024 +0200
@@ -185,7 +185,7 @@
                                      class_name, lines, condition);
 
       if (lines.size () == 0)
-        lines.insert (1);
+        lines.insert (-1);
 
       if (symbol_name != "")
         {
--- a/libinterp/parse-tree/bp-table.cc	Thu Apr 18 19:43:23 2024 -0700
+++ b/libinterp/parse-tree/bp-table.cc	Fri Apr 19 18:30:39 2024 +0200
@@ -797,6 +797,9 @@
     if (is_function ())
       return find_fcn_by_line (m_fcn, line);
 
+    if (line < 0)
+      return nullptr;
+
     return m_cls.get_method (line).user_code_value (true);
   }
 
@@ -834,7 +837,7 @@
   {
       if (m_methods_cache.empty ())
         {
-          // Not the most effecient, but reuses code:
+          // Not the most efficient, but reuses code:
           const std::map<std::string, cdef_method>& map
             = m_cls.get_method_map (false, true);
           for (auto iter = map.cbegin (); iter != map.cend (); ++iter)
@@ -872,6 +875,10 @@
     {
       octave_user_code *dbg_fcn = user_code (lineno);
 
+      if (! dbg_fcn)
+        error ("add_breakpoints_in_function: unable to find function '%s'\n",
+               fcn_ident.c_str ());
+
       // We've found the right (sub)function.  Now insert the breakpoint.
       bp_lines line_info;
       line_info.insert (lineno);
@@ -879,14 +886,13 @@
       bp_lines ret_one;
 
       std::string ident = fcn_ident;
-      if (! user_code.is_function () && fcn_ident[0] != '@' && dbg_fcn)
+      if (! user_code.is_function () && fcn_ident[0] != '@')
         {
           // identifier of the form @class_name/method_name
           ident = "@" + fcn_ident + "/" + dbg_fcn->name ();
         }
 
-      if (dbg_fcn && add_breakpoint_1 (dbg_fcn, ident, line_info,
-                                       condition, ret_one))
+      if (add_breakpoint_1 (dbg_fcn, ident, line_info, condition, ret_one))
         {
           if (! ret_one.empty ())
             {
--- a/test/classdef-debug/test-classdef-breakpoints.tst	Thu Apr 18 19:43:23 2024 -0700
+++ b/test/classdef-debug/test-classdef-breakpoints.tst	Fri Apr 19 18:30:39 2024 +0200
@@ -65,13 +65,12 @@
 %! end_unwind_protect
 
 ## Try to add breakpoint in non-existent method
-%!test <65610>
+%!test <65610*>
 %! if (isguirunning ())
 %!   orig_show_dbg = __event_manager_gui_preference__ ("editor/show_dbg_file",
 %!                                                     "false");
 %! endif
 %! unwind_protect
-%!   ## This should error.  But it does not.
 %!   fail ("dbstop @classdef_breakpoints/baz;", "unable to find function");
 %! unwind_protect_cleanup
 %!   dbclear classdef_breakpoints;