3 * Copyright (c) 1998 New Generation Software (NGS) Oy
5 * Author: Markku Rossi <mtr@ngs.fi>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26 * $Source: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/kjs/src/debug.c,v $
36 #define STRING_MAX_PRINT_LEN 10
39 js_vm_stacktrace (JSVirtualMachine
*vm
, unsigned int num_frames
)
41 unsigned int frame
= 0;
48 sprintf (buf
, "VM: stacktrace: stacksize=%d, used=%d%s",
50 (vm
->stack
+ vm
->stack_size
- sp
),
52 js_iostream_write (vm
->s_stderr
, buf
, strlen (buf
));
56 /* Find frame pointer. */
57 for (fp
= sp
+ 1; fp
->type
!= JS_IPTR
; fp
++)
60 /* The first iptr is the return address. */
63 /* The second iptr is the with pointer. */
66 /* The third item is a JS_ARGS_FIX node. */
67 assert (fp
->type
== JS_ARGS_FIX
);
70 while (fp
&& frame
< num_frames
)
73 const char *func_name
= js_vm_func_name (vm
, pc
);
75 sprintf (buf
, "#%-3u %s%s:", frame
++, func_name
,
76 func_name
[0] == '.' ? "" : "()");
77 js_iostream_write (vm
->s_stderr
, buf
, strlen (buf
));
79 if (vm
->verbose_stacktrace
)
82 " ra=0x%lx, wp=0x%lx, af=%d:%d, ofp=0x%lx",
83 (unsigned long) (fp
- 3)->u
.iptr
,
84 (unsigned long) JS_WITHPTR
->u
.iptr
,
85 JS_ARGS_FIXP
->u
.args_fix
.argc
,
86 JS_ARGS_FIXP
->u
.args_fix
.delta
,
87 (unsigned long) fp
->u
.iptr
);
88 js_iostream_write (vm
->s_stderr
, buf
, strlen (buf
));
91 for (n
= sp
+ 1; n
!= fp
- 3; n
++)
96 sprintf (buf
, " undefined");
100 sprintf (buf
, " null");
104 sprintf (buf
, " %s", n
->u
.vboolean
? "true" : "false");
108 sprintf (buf
, " %ld", n
->u
.vinteger
);
112 if (n
->u
.vstring
->len
> STRING_MAX_PRINT_LEN
)
113 sprintf (buf
, " \"%.*s...\"",
114 STRING_MAX_PRINT_LEN
,
117 sprintf (buf
, " \"%.*s\"",
118 (int) n
->u
.vstring
->len
,
123 sprintf (buf
, " %g", n
->u
.vfloat
);
127 sprintf (buf
, " array");
131 sprintf (buf
, " object");
135 sprintf (buf
, " %s", js_vm_symname (vm
, n
->u
.vsymbol
));
139 sprintf (buf
, " builtin");
143 sprintf (buf
, " function");
147 sprintf (buf
, " 0x%lx", (unsigned long) n
->u
.iptr
);
151 sprintf (buf
, " <num=%d, delta=%d>", n
->u
.args_fix
.argc
,
152 n
->u
.args_fix
.delta
);
156 sprintf (buf
, " type=%d???", n
->type
);
160 js_iostream_write (vm
->s_stderr
, buf
, strlen (buf
));
163 js_iostream_write (vm
->s_stderr
, JS_HOST_LINE_BREAK
,
164 JS_HOST_LINE_BREAK_LEN
);
166 /* Move to the caller. */