views:

37

answers:

1

I issue following command in the interactive matlab console:

>> foo = [1 inf];
>> dbstop if naninf
>> foo

I now get weird behaviour: matlab seems to to break into two different files, but doesn't actually stop execution. This is pretty slow because the editor switches between those two files repeatedly, Ctrl+C doesn't do anything. Output is:

481     end
20  if ~isfloat(value)
20  if ~isfloat(value)
399     if numel(var) > numelLimit
20  if ~isfloat(value)
20  if ~isfloat(value)
399     if numel(var) > numelLimit
20  if ~isfloat(value)
20  if ~isfloat(value)
399     if numel(var) > numelLimit
...
...

it then finally stops with a debug prompt, with a really long (recursive) stack like:

dbstack
  In codetools/private/dataviewerhelper>upconvertIntegralType at 20
  In codetools/private/dataviewerhelper at 9
  In workspacefunc>createComplexScalar at 271
> In workspacefunc>num2complex at 241
  In workspacefunc>getShortValueObjectJ at 230
  In workspacefunc>getShortValueObjectsJ at 349
  In workspacefunc at 21
  In codetools/private/dataviewerhelper>upconvertIntegralType at 20
  In codetools/private/dataviewerhelper at 9
  In workspacefunc>createComplexScalar at 271
  In workspacefunc>num2complex at 241
  In workspacefunc>getShortValueObjectJ at 230
  In workspacefunc>getShortValueObjectsJ at 349
  In workspacefunc at 21
  In workspacefunc>getStatObjectsJ at 399
  In workspacefunc at 27
  In codetools/private/dataviewerhelper>upconvertIntegralType at 20
  In codetools/private/dataviewerhelper at 9
  In workspacefunc>createComplexScalar at 271
  In workspacefunc>num2complex at 241
  In workspacefunc>getShortValueObjectJ at 230
  In workspacefunc>getShortValueObjectsJ at 349
  In workspacefunc at 21
  In codetools/private/dataviewerhelper>upconvertIntegralType at 20
  In codetools/private/dataviewerhelper at 9
  In workspacefunc>createComplexScalar at 271
  In workspacefunc>num2complex at 241
  In workspacefunc>getShortValueObjectJ at 230
  In workspacefunc>getShortValueObjectsJ at 349
  In workspacefunc at 21
  In workspacefunc>getStatObjectsJ at 399
  In workspacefunc at 27
...
...

In my real program I'm trying to debug I get the same but even worse so that sometimes I hit the recursion limit error and abort, sometimes matlab simply completely crashes. I would really like to be able to use dbstop if naninf, but this makes it pretty much impossible and this makes me sad. Any advice?

Using Matlab 2009b 64 bit on linux.

Thanks!

Edit:

I just tried it on matlab 2007b 32 bit Linux:

>> foo = [1 inf]
foo =
     1   Inf
>> dbstop if naninf                         
>> foo                                      
foo =                                       
     1   Inf                                
>> foo = [1 inf]                            
foo =                                       
     1   Inf                                
>>      
>> t = foo(2)                                                                          
t =                                                                                    
   Inf 

So here dbstop if naninf does't seem to do anything when deliberately assigning inf to a variable. The docs say:

bstop if naninf or dbstop if infnan stops execution when any MATLAB program file you subsequently run produces an infinite value (Inf) or a value that is not a number (NaN) as a result of an operator, function call, or scalar assignment, putting MATLAB in debug mode, paused immediately after the line where Inf or NaN was encountered.

Shouldn't this hit even when I deliberately assign a inf to a variable (as in above t = foo(2) or s = inf) or what is meant by "scalar assignment"?

+1  A: 

That weird deeply recursive breakpoint you're seeing looks like you're hitting breakpoints in the part of the Matlab GUI that is itself implemented in M-code, when it's trying to display NaN or Inf values in your workspace. (This is one of the downsides of the Matlab IDE running in the Matlab VM along with user code.) I can reproduce. Try turning off the Workspace view in the Desktop menu, or switching to a minimal layout with Desktop > Desktop Layout > Command Window Only.

For the second part: the breakpoint won't be hit for expressions entered directly at the command line. If you throw it in a script or function you'll hit the breakpoint. For example:

function repro_dbstop_naninf
foo = Inf;
foo = [1 Inf];
bar = foo(2);
disp('last line');

When you invoke this function, it'll break on (after, actually) lines 2 and 4.

>> dbstop if naninf
>> repro_dbstop_naninf
NaN/Inf breakpoint hit for repro_dbstop_naninf on line 2.
Stopping at next line.
2   foo = Inf;
3   foo = [1 Inf];
K>> 
Andrew Janke
Ah, I think you're absolutely right. Looking at the stack again also shows it with the dataviewerhelper calls etc. The test I did with 2007b when the problem didn't occur was matlab on the command-line, so no additional windows. Thank you so much!
Ben Schwehn

related questions