[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
keyboard command
From: |
John W. Eaton |
Subject: |
keyboard command |
Date: |
Wed, 8 Sep 2004 14:36:55 -0400 |
On 8-Sep-2004, Keith Goodman <address@hidden> wrote:
| I'm using the 'keyboard' command to help me port code written in a
| mostly octave compatible proprietary language. I have several
| 'keyboard' commands distributed across several functions. So when
| Octave puts me in the debug mode I'm not sure where I am in the code.
|
| I've tried
|
| disp('You're on line 146 of function fx'); keyboard
|
| But that's slow. Is there a way to automate it so that the result of keyboard
is
|
| line 146 of /home/me/code/fx.m
| debug>
|
| instead of just
|
| debug>
|
| ?
Please try the following patch.
Paul K: I think this should provide what is needed to make allow the
warning messages to include better location information.
jwe
src/ChangeLog:
2004-09-08 John W. Eaton <address@hidden>
* ov-usr-fcn.cc (octave_user_function::do_multi_index_op):
Save and set curr_caller_function and curr_caller_statement here.
* ov-mapper.cc (octave_mapper::do_multi_index_op): Likewise.
* ov-builtin.cc (octave_builtin::do_multi_index_op): Likewise.
* pt-stmt.cc (curr_caller_statement): New variable.
* pt-stmt.h: Provide decl.
* toplev.cc (curr_caller_function): New variable.
* toplev.h: Provide decl.
* input.cc (get_user_input): Print location info before the debug
prompt. From Keith Goodman <address@hidden>.
Index: src/input.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/input.cc,v
retrieving revision 1.155
diff -u -r1.155 input.cc
--- a/src/input.cc 25 Feb 2004 05:14:19 -0000 1.155
+++ b/src/input.cc 8 Sep 2004 18:34:50 -0000
@@ -535,7 +535,43 @@
if (nargin == 2)
read_as_string++;
- std::string prompt ("debug> ");
+ std::string nm;
+ int line = -1;
+
+ // We look at curr_caller_function because curr_function is always
+ // "keyboard".
+
+ if (curr_caller_function)
+ {
+ nm = curr_caller_function->fcn_file_name ();
+
+ if (nm.empty ())
+ nm = curr_caller_function->name ();
+
+ if (curr_statement)
+ line = curr_statement->line ();
+ }
+
+ OSSTREAM buf;
+
+ if (! nm.empty ())
+ {
+ buf << "stopped in " << nm;
+
+ if (line > 0)
+ buf << " at line " << line;
+ }
+
+ buf << OSSTREAM_ENDS;
+
+ std::string msg = OSSTREAM_STR (buf);
+
+ OSSTREAM_FREEZE (buf);
+
+ if (! msg.empty ())
+ message ("keyboard", msg.c_str ());
+
+ std::string prompt = "debug> ";
if (nargin > 0)
{
Index: src/ov-builtin.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-builtin.cc,v
retrieving revision 1.13
diff -u -r1.13 ov-builtin.cc
--- a/src/ov-builtin.cc 7 Feb 2004 06:27:28 -0000 1.13
+++ b/src/ov-builtin.cc 8 Sep 2004 18:34:50 -0000
@@ -109,6 +109,9 @@
else
{
unwind_protect_ptr (curr_function);
+ unwind_protect_ptr (curr_caller_function);
+
+ curr_caller_function = curr_function;
curr_function = this;
retval = (*f) (args, nargout);
Index: src/ov-mapper.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-mapper.cc,v
retrieving revision 1.19
diff -u -r1.19 ov-mapper.cc
--- a/src/ov-mapper.cc 7 Feb 2004 06:27:28 -0000 1.19
+++ b/src/ov-mapper.cc 8 Sep 2004 18:34:50 -0000
@@ -288,6 +288,9 @@
if (args(0).is_defined ())
{
unwind_protect_ptr (curr_function);
+ unwind_protect_ptr (curr_caller_function);
+
+ curr_caller_function = curr_function;
curr_function = this;
retval = apply (args(0));
Index: src/ov-usr-fcn.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-usr-fcn.cc,v
retrieving revision 1.55
diff -u -r1.55 ov-usr-fcn.cc
--- a/src/ov-usr-fcn.cc 5 Aug 2004 04:55:26 -0000 1.55
+++ b/src/ov-usr-fcn.cc 8 Sep 2004 18:34:50 -0000
@@ -393,6 +393,11 @@
curr_sym_tab = sym_tab;
unwind_protect_ptr (curr_function);
+ unwind_protect_ptr (curr_caller_function);
+ unwind_protect_ptr (curr_caller_statement);
+
+ curr_caller_statement = curr_statement;
+ curr_caller_function = curr_function;
curr_function = this;
if (! is_nested_function ())
Index: src/pt-stmt.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/pt-stmt.cc,v
retrieving revision 1.22
diff -u -r1.22 pt-stmt.cc
--- a/src/pt-stmt.cc 10 Nov 2003 15:50:40 -0000 1.22
+++ b/src/pt-stmt.cc 8 Sep 2004 18:34:50 -0000
@@ -51,6 +51,9 @@
// Pointer to the current statement being executed.
tree_statement *curr_statement = 0;
+// Pointer to the current statement being executed in the calling function.
+tree_statement *curr_caller_statement = 0;
+
// A list of commands to be executed.
tree_statement::~tree_statement (void)
Index: src/pt-stmt.h
===================================================================
RCS file: /usr/local/cvsroot/octave/src/pt-stmt.h,v
retrieving revision 1.12
diff -u -r1.12 pt-stmt.h
--- a/src/pt-stmt.h 6 Aug 2004 03:17:13 -0000 1.12
+++ b/src/pt-stmt.h 8 Sep 2004 18:34:51 -0000
@@ -159,6 +159,9 @@
// Pointer to the current statement being executed.
extern tree_statement *curr_statement;
+// Pointer to the current statement being executed in the calling function.
+extern tree_statement *curr_caller_statement;
+
#endif
/*
Index: src/toplev.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/toplev.cc,v
retrieving revision 1.152
diff -u -r1.152 toplev.cc
--- a/src/toplev.cc 15 Feb 2004 00:08:07 -0000 1.152
+++ b/src/toplev.cc 8 Sep 2004 18:34:51 -0000
@@ -93,6 +93,9 @@
// Pointer to function that is currently being evaluated.
octave_function *curr_function = 0;
+// Pointer to caller of curr_function.
+octave_function *curr_caller_function = 0;
+
// Pointer to parent function that is currently being evaluated.
octave_function *curr_parent_function = 0;
Index: src/toplev.h
===================================================================
RCS file: /usr/local/cvsroot/octave/src/toplev.h,v
retrieving revision 1.52
diff -u -r1.52 toplev.h
--- a/src/toplev.h 7 Feb 2004 06:27:28 -0000 1.52
+++ b/src/toplev.h 8 Sep 2004 18:34:51 -0000
@@ -48,6 +48,9 @@
// Pointer to function that is currently being evaluated.
extern octave_function *curr_function;
+// Pointer to caller of curr_function.
+extern octave_function *curr_caller_function;
+
// Pointer to parent function that is currently being evaluated.
extern octave_function *curr_parent_function;
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------