Mercurial > hg > octave-lyh
comparison scripts/miscellaneous/dbstack.m @ 7736:a059b5679fbb
implement dbstack
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 25 Apr 2008 15:11:03 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7735:6848970153ba | 7736:a059b5679fbb |
---|---|
1 ## Copyright (C) 2008 John W. Eaton | |
2 ## | |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Loadable Function} {[@var{stack}, @var{idx}]} dbstack (@var{n}) | |
21 ## Print or return current stack information. With optional argument | |
22 ## @var{n}, omit the @var{n} innermost stack frames. | |
23 ## @seealso{dbclear, dbstatus, dbstop} | |
24 ## @end deftypefn | |
25 | |
26 ## Author: jwe | |
27 | |
28 function [stack, idx] = dbstack (n = 0) | |
29 | |
30 if (n < 0 || round (n) != n) | |
31 error ("dbstack: expecting N to be a non-negative integer"); | |
32 endif | |
33 | |
34 ## Add one here to skip the dbstack stack frame. | |
35 [t_stack, t_idx] = __dbstack__ (n+1); | |
36 | |
37 if (nargout == 0) | |
38 nframes = numel (t_stack); | |
39 if (nframes > 0) | |
40 puts ("Stopped in:\n\n"); | |
41 for i = 1:nframes | |
42 if (i == t_idx) | |
43 puts ("--> "); | |
44 else | |
45 puts (" "); | |
46 endif | |
47 f = t_stack(i); | |
48 printf ("%s at line %d column %d\n", f.name, f.line, f.column); | |
49 endfor | |
50 endif | |
51 else | |
52 stack = t_stack; | |
53 idx = t_idx; | |
54 endif | |
55 | |
56 endfunction |