4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <fcode/private.h>
33 #include <fcode/log.h>
37 static void (*trace_fn
)(fcode_env_t
*);
40 set_tracer(fcode_env_t
*env
, void (*tracer
)(fcode_env_t
*))
50 debug
= get_interpreter_debug_level();
51 set_interpreter_debug_level(debug
| lvl
);
59 debug
= get_interpreter_debug_level();
60 set_interpreter_debug_level(debug
& ~lvl
);
64 enable_trace(fcode_env_t
*env
)
66 set_level(DEBUG_TRACING
);
70 enable_stack_trace(fcode_env_t
*env
)
72 set_level(DEBUG_TRACE_STACK
);
76 disable_stack_trace(fcode_env_t
*env
)
78 unset_level(DEBUG_TRACE_STACK
);
82 disable_trace(fcode_env_t
*env
)
84 unset_level(DEBUG_TRACING
);
88 call_trace(fcode_env_t
*env
)
90 set_level(DEBUG_CALL_METHOD
);
94 no_call_trace(fcode_env_t
*env
)
96 unset_level(DEBUG_CALL_METHOD
);
100 do_fclib_trace(fcode_env_t
*env
, void *fn
)
106 if (dladdr((void *) fn
, &dlip
)) {
109 address
= dlsym(RTLD_DEFAULT
, dlip
.dli_sname
);
110 offset
= ((char *) fn
) - ((char *) address
);
112 log_message(MSG_FC_DEBUG
, "%s: tracing %s()\n",
113 dlip
.dli_fname
, dlip
.dli_sname
);
115 log_message(MSG_FC_DEBUG
, "%s: tracing %s%s0x%x()\n",
116 dlip
.dli_fname
, dlip
.dli_sname
,
117 ((offset
< 0) ? "-" : "+"),
118 ((offset
< 0) ? -offset
: offset
));
121 log_message(MSG_FC_DEBUG
, "do_fclib_trace: <Unknown> %p\n", fn
);
128 output_step_message(fcode_env_t
*env
)
130 log_message(MSG_INFO
, "Step keys: <space>, Continue, Forth, Go,"
131 " Help, Step, Quit\n");
135 enable_step(fcode_env_t
*env
)
137 output_step_message(env
);
138 set_level(DEBUG_STEPPING
);
143 disable_step(fcode_env_t
*env
)
145 unset_level(DEBUG_STEPPING
);
149 * Output of state info is done elsewhere
152 do_fclib_step(fcode_env_t
*env
)
155 fcode_env_t
*new_env
;
160 while (getchar() != '\n')
172 DEBUG_EXEC_TRACE
|DEBUG_EXEC_DUMP_DS
);
180 unset_level(DEBUG_STEPPING
);
181 new_env
= clone_environment(env
, NULL
);
182 do_interact(new_env
);
183 destroy_environment(new_env
);
184 set_level(DEBUG_STEPPING
);
191 case 'd': /* Unimplemented */
192 case 'u': /* Unimplemented */
194 output_step_message(env
);
207 fcode_env_t
*env
= initial_env
;
213 FORTH(0, "stack-trace", enable_stack_trace
);
214 FORTH(0, "no-stack-trace", disable_stack_trace
);
215 FORTH(0, "trace-on", enable_trace
);
216 FORTH(0, "trace-off", disable_trace
);
217 FORTH(0, "call-trace", call_trace
);
218 FORTH(0, "no-call-trace", no_call_trace
);
219 FORTH(0, "step-on", enable_step
);
220 FORTH(0, "step-off", disable_step
);