bugGNU Octave - Bugs: bug #55939, 'dbstop if error' stops in...

 
 

bug #55939: 'dbstop if error' stops in function str2num, when no error is present

Submitted by:  Floris Van de Vijver <fvandevijver>
Submitted on:  Sun 17 Mar 2019 10:43:46 AM UTC  
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Fri 22 Mar 2019 11:02:42 PM UTC, comment #14: 

The quickest fix was to change str2num to wrap the eval() in a try/catch block.  I made the fix on the development branch here (https://hg.savannah.gnu.org/hgweb/octave/rev/1a79f289ca33).

Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Fri 22 Mar 2019 08:04:49 PM UTC, comment #13: 

Matlab r2019a, with 'dbstop if error' set, executes testfunc.m with two arguments eval stmt w/o error, but with a one argument eval stmt emits a long error message about "Invalid expression" and throws you in the editor in debug mode with a pointer on the offending L. 2.

Philip Nienhuis <philipnienhuis>
Project Member
Fri 22 Mar 2019 07:55:19 PM UTC, comment #12: 

Thanks.  That is what I expected.  The one-input form is just like any other ordinary octave statement and so if it has an error then it will drop in to the debugger at that point.

The two-input form is equivalent to try/catch and swallows the error.

Let me take a look.

Rik <rik5>
Project Administrator
Fri 22 Mar 2019 07:38:53 PM UTC, comment #11: 

i currently have only access to Matlab2007b, but this is the result for the 1 argument eval testfunc:

>> testfunc

??? Error: Unexpected MATLAB expression.

Error in ==> testfunc at 2
  eval('1z')

>> dbstop if error
>> testfunc

??? Error: Unexpected MATLAB expression.

Error in ==> testfunc at 2
  eval('1z')

2     eval('1z')

Floris Van de Vijver <fvandevijver>
Fri 22 Mar 2019 07:33:56 PM UTC, comment #10: 

@Floris: Can you try the 1-input form?

In testfunc.m

function testfunc()
  eval('1z')
end

And then

dbstop if error
testfunc

I could imagine that having the optional second argument to eval, the "catch" statement, stops Matlab from dropping in to the debugger.

Rik <rik5>
Project Administrator
Fri 22 Mar 2019 07:19:26 PM UTC, comment #9: 

I think in Matlab, eval with two arguments is deprecated and no longer documented. But testing does show that it still works, and acts like a try-catch, suppresses an error in the first argument from being raised, and evaluates the second argument.

I think eval with one argument does propagate an error normally, and probably triggers a breakpoint too.

I think Andrew's suggestion is that we should avoid using the 2-argument form completely and rely on try-catch instead.

The bottom line in this bug report is still that str2num should not raise an error and should not trigger a breakpoint even if the input argument is not a valid number, however that gets done. Easiest seems to be adding a try-catch and using eval with 1 argument.

Mike Miller <mtmiller>
Project Administrator
Fri 22 Mar 2019 07:14:32 PM UTC, comment #8: 

hi Rik,

comment #4 was a reply on comment #3, where it was asked to check a testfunction, containing only the eval function with 2 arguments. nowhere was a mention of an eval function with 1 argument. so IMHO it is clear.

I agree that renaming the title would be helpful. what do you propose? is 'Octave should not stop on breakpoints at error in the eval function' clearer?

Floris Van de Vijver <fvandevijver>
Fri 22 Mar 2019 07:08:08 PM UTC, comment #7: 

Can the issue report be re-titled to reflect the root problem?  I can't tell if it is str2num which needs to change, by adding a try statement, or whether eval needs to change.  In particular, I couldn't decide what comment #4 meant.

it indeed stops on the 'eval' after a 'dbstop if error'

in Matlab 2007b and 2013a it does not stop and just returns 1

Does that mean that eval with 1-argument stops, but eval with 2-arguments does not?

Rik <rik5>
Project Administrator
Wed 20 Mar 2019 09:40:02 PM UTC, comment #6: 

  eval('1z', '1')

Note that the second argument to `eval` is undocumented. So there may be no reason to support it, or expect that it behaves consistently across Matlab versions.

Andrew Janke <apjanke>
Mon 18 Mar 2019 05:56:39 PM UTC, comment #5: 

Ok, so it seems like Octave needs to make errors in eval not stop on breakpoints.

Mike Miller <mtmiller>
Project Administrator
Mon 18 Mar 2019 07:48:34 AM UTC, comment #4: 

it indeed stops on the 'eval' after a 'dbstop if error'

in Matlab 2007b and 2013a it does not stop and just returns 1

Floris Van de Vijver <fvandevijver>
Sun 17 Mar 2019 09:37:30 PM UTC, comment #3: 

I think it would be useful to know some more details in order to proceed to ensure that we don't break something else.

  • Does Matlab break to debug mode if a function calls 'eval' with a string that causes an error not inside of a 'try'? IOW does our 'eval' function need to be fixed?
  • Would adding a 'try' to 'str2num' break any other compatible behavior with 'str2num'? As I understand it, we have to use 'eval' to be compatible with Matlab, but are there corner cases where 'str2num' might have a side effect that 'try' would suppress?

With the following function testfunc.m:

function testfunc()
  eval('1z', '1')
end

Does 'dbstop if error' stop on the 'eval'?

It would also be much better if we could have someone test with a current version of Matlab.

Mike Miller <mtmiller>
Project Administrator
Sun 17 Mar 2019 08:29:58 PM UTC, comment #2: 

yes [matlab 2007b]. the behavior is not seen there.

>> str2num('600n')

ans =
     []

>> dbstop if error
>> str2num('600n')

ans =
     []

as a possible fix, the eval statement could be done inside a try catch statement, such that the 'dbstop if error' would not stop on that line.

Floris Van de Vijver <fvandevijver>
Sun 17 Mar 2019 08:20:35 PM UTC, comment #1: 

Thank you for your bug report. An error actually does occur, but it's caught because it happens inside the eval(). The same might happen with errors raised inside of a try. I think this will need someone to test for compatibility in Matlab, do you have Matlab to test this?

Mike Miller <mtmiller>
Project Administrator
Sun 17 Mar 2019 10:43:46 AM UTC, original submission:  

if a simple str2num command is given, the result is empy, but no error is thrown; but if 'dbstop if error' command is executed it suddently stops [on line 62].
This looks like unexpected behavior/error

>> str2num('600n')


ans = [](0x0)

>> dbstop if error
>> str2num('600n')

stopped in C:\Octave\OCTAVE~2.0\mingw64\share\octave\5.1.0\m\strings\str2num.m at line 62
62:   eval (s, "m = []; state = false;");
debug> dbcont
ans = [](0x0

Floris Van de Vijver <fvandevijver>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by apjanke (Posted a comment)
  • -email is unavailable- added by fvandevijver (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-22 rik5 StatusNeed Info => Fixed
        Open/ClosedOpen => Closed
        Release5.1.0 => dev
        Operating SystemMicrosoft Windows => Any
    2019-03-17 mtmiller Severity3 - Normal => 2 - Minor
        Item GroupUnexpected Error or Warning => Matlab Compatibility
    2019-03-17 mtmiller StatusNone => Need Info

    Back to the top


    Powered by Savane 3.5