Offline debug code

Let's say I have some function foothat is used in a standalone application (i.e. compiled into an executable c mcc -m), which has an important intermediate result bar. I usually don’t need this intermediate result after the function completes, and therefore it is not a return value. However, for development and debugging purposes, it’s useful to be able to make this intermediate result available, which I can use assigninto put the intermediate result in some debugging workspace.

Now the problem is that it is assigninnot possible in offline compilation, but mccwill complain about an error if there is one in the code assignin. What I would like to do is enable assigninonly when the code is launched interactively, and not when compiled as a separate application. In addition, this will speed up the process, since I do not need an intermediate result in a stand-alone application, and thus it can simultaneously and / or memory without having to assignin in a stand-alone application. In any other programming environment, you could call this compilation in debug and release mode.

In the pseudo malaby:

function res = foo()
  bar = some complicated formula
  if ~standalone
    assignin('debug', 'foo_bar', bar)
  end
  res = some complicated formula involving bar

, , if ~standalone, -, , , , , , mcc , .

, , assignin. , , .

Matlab, , ? , , .

+3
2

, assignin , . . , , , . .

, .

function out = isdebugging(value)
%ISDEBUGGING Get or set the global debugging state

persistent state
if isempty(state)
    state = false;
end

switch nargin
    case 0 % Getter
        out = state;
    case 1 % Setter
        state = value;
end

, , .

function out = debugval(action, name, value)
%DEBUGVAL Stash values for debugging

persistent stash
if isempty(stash)
    stash = struct;
end

% Short-circuit when not in debugging mode to save space
if ~isdebugging()
    return;
end

switch action
    case 'get'
        out = stash.(name);
    case 'getall'
        out = stash;
    case 'set'
        stash.(name) = value;
    case 'list'
        out = fieldnames(stash);
    case 'remove'
        stash = rmfield(stash, name);
    case 'clear'
        stash = struct;
end

, . Matlab isdebugging (true). . , , , , . GUI , , .

isdebugging() . isdebugging(), , . , .

Java log4j , . Matlab.

+2

isdeployed. isdeployed true MCR false MATLAB.

EDIT: , . , assignin..

+1

Source: https://habr.com/ru/post/1792540/


All Articles