1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "amlcode.h"
47#include "acdebug.h"
48#include "acinterp.h"
49
50#define _COMPONENT ACPI_CA_DEBUGGER
51ACPI_MODULE_NAME("dbxface")
52
53
54static acpi_status
55acpi_db_start_command(struct acpi_walk_state *walk_state,
56 union acpi_parse_object *op);
57
58#ifdef ACPI_OBSOLETE_FUNCTIONS
59void acpi_db_method_end(struct acpi_walk_state *walk_state);
60#endif
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75static acpi_status
76acpi_db_start_command(struct acpi_walk_state *walk_state,
77 union acpi_parse_object *op)
78{
79 acpi_status status;
80
81
82
83
84
85
86
87 acpi_gbl_method_executing = TRUE;
88 status = AE_CTRL_TRUE;
89
90 while (status == AE_CTRL_TRUE) {
91
92
93
94 status = acpi_os_notify_command_complete();
95 if (ACPI_FAILURE(status)) {
96 goto error_exit;
97 }
98
99
100
101 status = acpi_os_wait_command_ready();
102 if (ACPI_FAILURE(status)) {
103 goto error_exit;
104 }
105
106 status =
107 acpi_db_command_dispatch(acpi_gbl_db_line_buf, walk_state,
108 op);
109 }
110
111
112
113error_exit:
114 if (ACPI_FAILURE(status) && status != AE_CTRL_TERMINATE) {
115 ACPI_EXCEPTION((AE_INFO, status,
116 "While parsing/handling command line"));
117 }
118 return (status);
119}
120
121
122
123
124
125
126
127
128
129
130
131
132
133void acpi_db_signal_break_point(struct acpi_walk_state *walk_state)
134{
135
136#ifndef ACPI_APPLICATION
137 if (acpi_gbl_db_thread_id != acpi_os_get_thread_id()) {
138 return;
139 }
140#endif
141
142
143
144
145
146
147 acpi_gbl_cm_single_step = TRUE;
148 acpi_os_printf("**break** Executed AML BreakPoint opcode\n");
149}
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165acpi_status
166acpi_db_single_step(struct acpi_walk_state *walk_state,
167 union acpi_parse_object *op, u32 opcode_class)
168{
169 union acpi_parse_object *next;
170 acpi_status status = AE_OK;
171 u32 original_debug_level;
172 union acpi_parse_object *display_op;
173 union acpi_parse_object *parent_op;
174 u32 aml_offset;
175
176 ACPI_FUNCTION_ENTRY();
177
178#ifndef ACPI_APPLICATION
179 if (acpi_gbl_db_thread_id != acpi_os_get_thread_id()) {
180 return (AE_OK);
181 }
182#endif
183
184
185
186 if (acpi_gbl_abort_method) {
187 acpi_gbl_abort_method = FALSE;
188 return (AE_ABORT_METHOD);
189 }
190
191 aml_offset = (u32)ACPI_PTR_DIFF(op->common.aml,
192 walk_state->parser_state.aml_start);
193
194
195
196 if (walk_state->method_breakpoint &&
197 (walk_state->method_breakpoint <= aml_offset)) {
198
199
200
201
202 acpi_os_printf("***Break*** at AML offset %X\n", aml_offset);
203 acpi_gbl_cm_single_step = TRUE;
204 acpi_gbl_step_to_next_call = FALSE;
205 walk_state->method_breakpoint = 0;
206 }
207
208
209
210 else if (walk_state->user_breakpoint &&
211 (walk_state->user_breakpoint == aml_offset)) {
212 acpi_os_printf("***UserBreakpoint*** at AML offset %X\n",
213 aml_offset);
214 acpi_gbl_cm_single_step = TRUE;
215 acpi_gbl_step_to_next_call = FALSE;
216 walk_state->method_breakpoint = 0;
217 }
218
219
220
221
222
223 if (op->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
224 return (AE_OK);
225 }
226
227 switch (opcode_class) {
228 case AML_CLASS_UNKNOWN:
229 case AML_CLASS_ARGUMENT:
230
231 return (AE_OK);
232
233 default:
234
235
236 break;
237 }
238
239
240
241
242 if ((acpi_gbl_db_output_to_file) ||
243 (acpi_gbl_cm_single_step) || (acpi_dbg_level & ACPI_LV_PARSE)) {
244 if ((acpi_gbl_db_output_to_file) ||
245 (acpi_dbg_level & ACPI_LV_PARSE)) {
246 acpi_os_printf
247 ("\nAML Debug: Next AML Opcode to execute:\n");
248 }
249
250
251
252
253
254
255 original_debug_level = acpi_dbg_level;
256 acpi_dbg_level &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);
257 next = op->common.next;
258 op->common.next = NULL;
259
260 display_op = op;
261 parent_op = op->common.parent;
262 if (parent_op) {
263 if ((walk_state->control_state) &&
264 (walk_state->control_state->common.state ==
265 ACPI_CONTROL_PREDICATE_EXECUTING)) {
266
267
268
269
270
271 while (parent_op) {
272 if ((parent_op->common.aml_opcode ==
273 AML_IF_OP)
274 || (parent_op->common.aml_opcode ==
275 AML_WHILE_OP)) {
276 display_op = parent_op;
277 break;
278 }
279 parent_op = parent_op->common.parent;
280 }
281 } else {
282 while (parent_op) {
283 if ((parent_op->common.aml_opcode ==
284 AML_IF_OP)
285 || (parent_op->common.aml_opcode ==
286 AML_ELSE_OP)
287 || (parent_op->common.aml_opcode ==
288 AML_SCOPE_OP)
289 || (parent_op->common.aml_opcode ==
290 AML_METHOD_OP)
291 || (parent_op->common.aml_opcode ==
292 AML_WHILE_OP)) {
293 break;
294 }
295 display_op = parent_op;
296 parent_op = parent_op->common.parent;
297 }
298 }
299 }
300
301
302
303#ifdef ACPI_DISASSEMBLER
304 acpi_dm_disassemble(walk_state, display_op, ACPI_UINT32_MAX);
305#endif
306
307 if ((op->common.aml_opcode == AML_IF_OP) ||
308 (op->common.aml_opcode == AML_WHILE_OP)) {
309 if (walk_state->control_state->common.value) {
310 acpi_os_printf
311 ("Predicate = [True], IF block was executed\n");
312 } else {
313 acpi_os_printf
314 ("Predicate = [False], Skipping IF block\n");
315 }
316 } else if (op->common.aml_opcode == AML_ELSE_OP) {
317 acpi_os_printf
318 ("Predicate = [False], ELSE block was executed\n");
319 }
320
321
322
323 op->common.next = next;
324 acpi_os_printf("\n");
325 if ((acpi_gbl_db_output_to_file) ||
326 (acpi_dbg_level & ACPI_LV_PARSE)) {
327 acpi_os_printf("\n");
328 }
329 acpi_dbg_level = original_debug_level;
330 }
331
332
333
334 if (!acpi_gbl_cm_single_step) {
335 return (AE_OK);
336 }
337
338
339
340
341
342 if (acpi_gbl_step_to_next_call) {
343 if (op->common.aml_opcode != AML_INT_METHODCALL_OP) {
344
345
346
347 return (AE_OK);
348 }
349
350
351
352 acpi_gbl_step_to_next_call = FALSE;
353 }
354
355
356
357
358
359 if (op->common.aml_opcode == AML_INT_METHODCALL_OP) {
360
361
362
363 acpi_gbl_cm_single_step = FALSE;
364
365
366
367
368
369 walk_state->method_breakpoint = 1;
370 }
371
372 acpi_ex_exit_interpreter();
373 status = acpi_db_start_command(walk_state, op);
374 acpi_ex_enter_interpreter();
375
376
377
378 return (status);
379}
380
381
382
383
384
385
386
387
388
389
390
391
392
393acpi_status acpi_initialize_debugger(void)
394{
395 acpi_status status;
396
397 ACPI_FUNCTION_TRACE(acpi_initialize_debugger);
398
399
400
401 acpi_gbl_db_buffer = NULL;
402 acpi_gbl_db_filename = NULL;
403 acpi_gbl_db_output_to_file = FALSE;
404
405 acpi_gbl_db_debug_level = ACPI_LV_VERBOSITY2;
406 acpi_gbl_db_console_debug_level = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
407 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;
408
409 acpi_gbl_db_opt_no_ini_methods = FALSE;
410
411 acpi_gbl_db_buffer = acpi_os_allocate(ACPI_DEBUG_BUFFER_SIZE);
412 if (!acpi_gbl_db_buffer) {
413 return_ACPI_STATUS(AE_NO_MEMORY);
414 }
415 memset(acpi_gbl_db_buffer, 0, ACPI_DEBUG_BUFFER_SIZE);
416
417
418
419 acpi_gbl_db_scope_buf[0] = AML_ROOT_PREFIX;
420 acpi_gbl_db_scope_buf[1] = 0;
421 acpi_gbl_db_scope_node = acpi_gbl_root_node;
422
423
424
425 acpi_gbl_db_terminate_loop = FALSE;
426
427
428
429
430
431
432 if (acpi_gbl_debugger_configuration & DEBUGGER_MULTI_THREADED) {
433
434
435
436 status = acpi_os_initialize_debugger();
437 if (ACPI_FAILURE(status)) {
438 acpi_os_printf("Could not get debugger mutex\n");
439 return_ACPI_STATUS(status);
440 }
441
442
443
444 acpi_gbl_db_threads_terminated = FALSE;
445 status = acpi_os_execute(OSL_DEBUGGER_MAIN_THREAD,
446 acpi_db_execute_thread, NULL);
447 if (ACPI_FAILURE(status)) {
448 ACPI_EXCEPTION((AE_INFO, status,
449 "Could not start debugger thread"));
450 acpi_gbl_db_threads_terminated = TRUE;
451 return_ACPI_STATUS(status);
452 }
453 } else {
454 acpi_gbl_db_thread_id = acpi_os_get_thread_id();
455 }
456
457 return_ACPI_STATUS(AE_OK);
458}
459
460ACPI_EXPORT_SYMBOL(acpi_initialize_debugger)
461
462
463
464
465
466
467
468
469
470
471
472
473void acpi_terminate_debugger(void)
474{
475
476
477
478 acpi_gbl_db_terminate_loop = TRUE;
479
480 if (acpi_gbl_debugger_configuration & DEBUGGER_MULTI_THREADED) {
481
482
483
484 while (!acpi_gbl_db_threads_terminated) {
485 acpi_os_sleep(100);
486 }
487
488 acpi_os_terminate_debugger();
489 }
490
491 if (acpi_gbl_db_buffer) {
492 acpi_os_free(acpi_gbl_db_buffer);
493 acpi_gbl_db_buffer = NULL;
494 }
495
496
497
498 acpi_gbl_db_output_flags = ACPI_DB_DISABLE_OUTPUT;
499}
500
501ACPI_EXPORT_SYMBOL(acpi_terminate_debugger)
502
503
504
505
506
507
508
509
510
511
512
513
514void acpi_set_debugger_thread_id(acpi_thread_id thread_id)
515{
516 acpi_gbl_db_thread_id = thread_id;
517}
518
519ACPI_EXPORT_SYMBOL(acpi_set_debugger_thread_id)
520