4 * Copyright (c) 1999 Takanori Watanabe
5 * Copyright (c) 1999, 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Id: debug.c,v 1.19 2000/08/16 18:15:00 iwasaki Exp
30 * $FreeBSD: src/usr.sbin/acpi/amldb/debug.c,v 1.3 2000/11/09 06:24:40 iwasaki Exp $
32 #include <sys/cdefs.h>
35 #include <sys/param.h>
37 #include <acpi_common.h>
38 #include <aml/aml_name.h>
39 #include <aml/aml_amlmem.h>
40 #include <aml/aml_status.h>
41 #include <aml/aml_env.h>
42 #include <aml/aml_obj.h>
43 #include <aml/aml_evalobj.h>
44 #include <aml/aml_parse.h>
45 #include <aml/aml_region.h>
46 #include <aml/aml_store.h>
47 #include <aml/aml_common.h>
59 print_named_object(struct aml_name
*name
, va_list ap
)
62 aml_print_curname(name
);
65 return (0); /* always return success to continue the search */
69 aml_dbgr(struct aml_environ
*env1
, struct aml_environ
*env2
)
73 static char lastcommand
[CMDBUFLEN
];
74 char commandline
[CMDBUFLEN
];
75 char argbuf
[7][ARGBUFLEN
];
80 struct aml_name
*name
;
81 union aml_object argv
[7], *retval
;
84 fputs("AML>", stderr
);
85 fgets(commandline
, 512, stdin
);
86 commandline
[512 - 1] = '\n'; /* safety */
90 if (commandline
[0] == '\n') {
91 memcpy(commandline
, lastcommand
, sizeof commandline
);
93 memcpy(lastcommand
, commandline
, sizeof commandline
);
94 switch (commandline
[0]) {
97 env2
->stat
= aml_stat_step
;
101 env1
->stat
= aml_stat_step
;
104 env1
->stat
= aml_stat_none
;
107 env1
->stat
= aml_stat_panic
;
111 ptr
= &commandline
[1];
112 while (ptr
[0] != '\n')
116 /* move pointer to object name */
117 ptr
= &commandline
[1];
118 while (ptr
[0] == ' ')
121 /* show current tree if no argument */
122 if (ptr
[0] == '\0') {
123 aml_showtree(env1
->curname
, 0);
126 /* start from root? */
127 if (ptr
[0] == '\\') {
128 if (ptr
[1] == '\0') {
129 aml_showtree(aml_get_rootname(), 0);
132 if ((name
= aml_find_from_namespace(aml_get_rootname(), ptr
))) {
133 aml_showtree(name
, 0);
137 if ((name
= aml_find_from_namespace(env1
->curname
, ptr
))) {
138 aml_showtree(name
, 0);
141 for (i
= 0; i
< 7; i
++) {
142 struct aml_name
*tmp
=
143 aml_local_stack_getArgX(NULL
, i
);
145 if (tmp
== NULL
|| tmp
->property
== NULL
) {
148 printf(" Arg%d ", i
);
149 aml_showobject(tmp
->property
);
151 for (i
= 0; i
< 8; i
++) {
152 struct aml_name
*tmp
=
153 aml_local_stack_getLocalX(i
);
155 if (tmp
== NULL
|| tmp
->property
== NULL
) {
158 printf(" Local%d ", i
);
159 aml_showobject(tmp
->property
);
163 aml_debug_prompt_reginput
=
164 (aml_debug_prompt_reginput
== 0) ? 1 : 0;
165 if (aml_debug_prompt_reginput
)
166 fputs("REGION INPUT ON\n", stderr
);
168 fputs("REGION INPUT OFF\n", stderr
);
171 aml_debug_prompt_regoutput
=
172 (aml_debug_prompt_regoutput
== 0) ? 1 : 0;
173 if (aml_debug_prompt_regoutput
)
174 fputs("REGION OUTPUT ON\n", stderr
);
176 fputs("REGION OUTPUT OFF\n", stderr
);
179 memman_statistics(aml_memman
);
183 ptr
= &commandline
[1];
184 while (ptr
[0] != '\n')
188 /* move pointer to method name */
189 ptr
= &commandline
[1];
190 while (ptr
[0] == ' ')
193 if (ptr
[0] == '\0') {
196 name
= aml_find_from_namespace(aml_get_rootname(), ptr
);
198 printf("%s:%d:aml_dbgr: not found name %s\n",
199 __FILE__
, __LINE__
, ptr
);
202 if (name
->property
== NULL
||
203 name
->property
->type
!= aml_t_method
) {
204 printf("%s:%d:aml_dbgr: not method %s\n",
205 __FILE__
, __LINE__
, ptr
);
208 aml_showobject(name
->property
);
211 argnum
= name
->property
->meth
.argnum
& 0x07;
213 fputs(" Enter argument values "
214 "(ex. number 1 / string foo). "
215 "'q' to quit.\n", stderr
);
217 /* get and parse argument values */
218 for (i
= 0; i
< argnum
; i
++) {
220 fprintf(stderr
, " Arg%d ? ", i
);
221 if (read(0, argbuf
[i
], ARGBUFLEN
) == 0) {
225 argbuf
[i
][ARGBUFLEN
- 1] = '\n';
226 if (argbuf
[i
][0] == 'q') {
227 goto finish_execution
;
229 if (argbuf
[i
][0] == '\n') {
232 /* move pointer to the value */
234 while (ptr
[0] != ' ' && ptr
[0] != '\n') {
237 while (ptr
[0] == ' ') {
240 if (ptr
[0] == '\n') {
243 switch (argbuf
[i
][0]) {
245 argv
[i
].type
= aml_t_num
;
249 argv
[i
].num
.number
= strtoq(ptr
, &ep
, 16);
251 argv
[i
].num
.number
= strtoq(ptr
, &ep
, 10);
254 fputs("Wrong value for number.\n",
260 argv
[i
].type
= aml_t_string
;
261 argv
[i
].str
.needfree
= 0;
262 argv
[i
].str
.string
= (u_int8_t
*)ptr
;
264 while (ptr
[0] != '\n') {
270 fputs("Invalid data type "
271 "(supports number or string only)\n",
276 bzero(lastcommand
, sizeof lastcommand
);
277 fprintf(stderr
, "==== Running %s. ====\n", method
);
278 aml_local_stack_push(aml_local_stack_create());
279 retval
= aml_invoke_method_by_name(method
, argnum
, argv
);
280 aml_showobject(retval
);
281 aml_local_stack_delete(aml_local_stack_pop());
282 fprintf(stderr
, "==== %s finished. ====\n", method
);
287 ptr
= &commandline
[1];
288 while (ptr
[0] != '\n')
292 /* move pointer to object name */
293 ptr
= &commandline
[1];
294 while (ptr
[0] == ' ')
297 aml_apply_foreach_found_objects(aml_get_rootname(),
298 ptr
, print_named_object
);
301 fputs("s Single step\n"
303 "c Continue program being debugged\n"
304 "q Quit method execution\n"
305 "t Show local name space tree and variables\n"
306 "i Toggle region input prompt\n"
307 "o Toggle region output prompt\n"
308 "m Show memory management statistics\n"
309 "r Run specified method\n"
310 "f Find named objects from namespace.\n"
311 "h Show this messsage\n", stderr
);