在 GNU Octave 中查看单个文件的执行情况 (echo fcnname on)

在 GNU Octave 中查看单个文件的执行情况 (echo fcnname on)

问题很简单:在 MATLAB 中,你可以简单地用来echo myFun on设置echo单个功能m-file 到on,然后它会显示执行的每一行。

然而,在 GNU Octave 中缺少这样的语法。help echo显示:

octave:1> help echo
'echo' is a built-in function from the file libinterp/corefcn/input.cc

 -- Command: echo
 -- Command: echo on
 -- Command: echo off
 -- Command: echo on all
 -- Command: echo off all
     Control whether commands are displayed as they are executed.

     Valid options are:

     'on'
          Enable echoing of commands as they are executed in script
          files.

     'off'
          Disable echoing of commands as they are executed in script
          files.

     'on all'
          Enable echoing of commands as they are executed in script
          files and functions.

     'off all'
          Disable echoing of commands as they are executed in script
          files and functions.

     With no arguments, 'echo' toggles the current echo state.

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the [email protected]
mailing list.

深入挖掘,信息页面显示了更多信息:

 -- Built-in Function: VAL = echo_executing_commands ()
 -- Built-in Function: OLD_VAL = echo_executing_commands (NEW_VAL)
 -- Built-in Function: echo_executing_commands (NEW_VAL, "local")
     Query or set the internal variable that controls the echo state.

     It may be the sum of the following values:

     1
          Echo commands read from script files.

     2
          Echo commands from functions.

     4
          Echo commands read from command line.

     More than one state can be active at once.  For example, a value of
     3 is equivalent to the command 'echo on all'.

     The value of 'echo_executing_commands' may be set by the 'echo'
     command or the command line option '--echo-commands'.

     When called from inside a function with the "local" option, the
     variable is changed locally for the function and any subroutines it
     calls.  The original variable value is restored when exiting the
     function.

因此,像我下面的尝试可能会解决这个问题;然而,正如文档所暗示的,它会影响功能和 任何 子程序调用。所以问题仍然没有解决;我以为我已经回答了我自己的问题,但我发现并没有。

只需在需要调试的函数文件的开头添加即可echo_executing_commands(2, 'local');;换句话说,打开myFun.m,并在函数 m 文件的开头插入语句。注意这是仅有的Octave 函数,为了完全兼容,请使用:

if exist('OCTAVE_VERSION', 'builtin') ~= 0; echo_executing_commands(2, 'local');end

答案1

这不起作用

只需在需要调试的函数文件的开头添加即可echo_executing_commands(2, 'local');;换句话说,打开myFun.m,并在函数 m 文件的开头插入语句。注意这是仅有的Octave 函数,为了完全兼容,请使用:

if exist('OCTAVE_VERSION', 'builtin') ~= 0; echo_executing_commands(2, 'local');end

相关内容