8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / efcode / engine / tracing.c
blob43ade86faa2304ab5f3fbf73af678786e903331f
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <dlfcn.h>
32 #include <fcode/private.h>
33 #include <fcode/log.h>
35 #ifdef DEBUG
37 static void (*trace_fn)(fcode_env_t *);
39 void
40 set_tracer(fcode_env_t *env, void (*tracer)(fcode_env_t *))
42 trace_fn = tracer;
45 void
46 set_level(long lvl)
48 long debug;
50 debug = get_interpreter_debug_level();
51 set_interpreter_debug_level(debug | lvl);
54 void
55 unset_level(long lvl)
57 long debug;
59 debug = get_interpreter_debug_level();
60 set_interpreter_debug_level(debug & ~lvl);
63 void
64 enable_trace(fcode_env_t *env)
66 set_level(DEBUG_TRACING);
69 void
70 enable_stack_trace(fcode_env_t *env)
72 set_level(DEBUG_TRACE_STACK);
75 void
76 disable_stack_trace(fcode_env_t *env)
78 unset_level(DEBUG_TRACE_STACK);
81 void
82 disable_trace(fcode_env_t *env)
84 unset_level(DEBUG_TRACING);
87 void
88 call_trace(fcode_env_t *env)
90 set_level(DEBUG_CALL_METHOD);
93 void
94 no_call_trace(fcode_env_t *env)
96 unset_level(DEBUG_CALL_METHOD);
99 void
100 do_fclib_trace(fcode_env_t *env, void *fn)
102 void *address;
103 Dl_info dlip;
104 static char buf[80];
106 if (dladdr((void *) fn, &dlip)) {
107 int offset;
109 address = dlsym(RTLD_DEFAULT, dlip.dli_sname);
110 offset = ((char *) fn) - ((char *) address);
111 if (offset == 0) {
112 log_message(MSG_FC_DEBUG, "%s: tracing %s()\n",
113 dlip.dli_fname, dlip.dli_sname);
114 } else {
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));
120 } else {
121 log_message(MSG_FC_DEBUG, "do_fclib_trace: <Unknown> %p\n", fn);
123 if (trace_fn)
124 trace_fn(env);
127 void
128 output_step_message(fcode_env_t *env)
130 log_message(MSG_INFO, "Step keys: <space>, Continue, Forth, Go,"
131 " Help, Step, Quit\n");
134 void
135 enable_step(fcode_env_t *env)
137 output_step_message(env);
138 set_level(DEBUG_STEPPING);
142 void
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)
154 int c;
155 fcode_env_t *new_env;
157 for (; ; ) {
158 c = getchar();
159 if (c != '\n') {
160 while (getchar() != '\n')
163 switch (c) {
164 case EOF:
165 case 'q':
166 unbug(env);
167 IP = 0;
168 return (1);
170 case 'c':
171 debug_set_level(env,
172 DEBUG_EXEC_TRACE|DEBUG_EXEC_DUMP_DS);
173 break;
175 case 'g':
176 unbug(env);
177 break;
179 case 'f':
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);
185 continue;
187 case ' ':
188 case '\n':
189 break;
191 case 'd': /* Unimplemented */
192 case 'u': /* Unimplemented */
193 default:
194 output_step_message(env);
195 continue;
197 break;
199 return (0);
202 #pragma init(_init)
204 static void
205 _init(void)
207 fcode_env_t *env = initial_env;
209 ASSERT(env);
210 NOTICE;
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);
223 #endif