Another useful debugging command in Octave

In a previous post, I shared some Octave functions to do debugging.  Somehow I got problem in using dbstop function in my main script. It kept on telling me it can’t find the function. However, I found another useful way to stop the program and enter into debug mode. It’s to use the “keyboard” function.

From GNU Octave manual it says

Built-in Function: keyboard (prompt)
This function is normally used for simple debugging. When the keyboard function is executed, Octave prints a prompt and waits for user input. The input strings are then evaluated and the results are printed. This makes it possible to examine the values of variables within a function, and to assign new values to variables. No value is returned from the keyboard function, and it continues to prompt for input until the user types ‘quit’, or ‘exit’.

If keyboard is invoked without any arguments, a default prompt of ‘debug> ’ is used.

so what you need to do is just to insert “keyboard” into the line where you want to stop. That easy!

note: I somehow got strange behaviour if I rerun the script again, it gives me

debug> “error: input: reading user-input failed!”

Advertisements

2 Responses

  1. when you use keyboard() to stop, type “exit” to continue. If you type dbcont, it will enter into another debug mode.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: