I have an Octave (v. 4.0.0 on CentOS 6.6) code that I normally run like octave-cli mycode someargument
.
I'd like to debug this code from the Octave command line interpreter. Here is a minimal working example:
$ cat somefunc.m
function somefunc
printf("hello world\n");
args = argv();
printf("args = %s\n", args{1});
endfunction
somefunc();
printf("this is the end\n");
This code runs like:
$ octave-cli somefunc.m somearg
hello world
args = somearg
this is the end
I'd like to be able to debug this code from the command line, and pass somearg
such that argv()
catches it e.g.
$ octave-cli
octave:1> dbstop somefunc 4;
octave:2> somefunc somearg
stopped in /some/path/somefunc.m at line 4
4: printf("args = %s\n", args{1});
hello world
debug> dbcont
error: somefunc: A(I): index out of bounds; value 1 out of bound 0
error: called from
somefunc at line 4 column 5
octave:2>
But I cannot figure out how to get argv()
to read the command line argument. Do I need to put in a some ugly switch? Something like:
if(is_interactive_mode)
args = "somearg";
else
args = argv();
end
In Python I wouldn't have this problem, e.g. python -m pdb ./somefunc.py somearg
and in C (using Gdb) I'd pass the arguments when starting gdb or would be passed to the command run
.
Question : How do I pass command line arguments to a program when running it interactively from the octave command line?