dbinput.c revision 1.15.2.1 1 /*******************************************************************************
2 *
3 * Module Name: dbinput - user front-end to the AML debugger
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2019, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdebug.h"
47
48 #ifdef ACPI_APPLICATION
49 #include "acapps.h"
50 #endif
51
52 #define _COMPONENT ACPI_CA_DEBUGGER
53 ACPI_MODULE_NAME ("dbinput")
54
55
56 /* Local prototypes */
57
58 static UINT32
59 AcpiDbGetLine (
60 char *InputBuffer);
61
62 static UINT32
63 AcpiDbMatchCommand (
64 char *UserCommand);
65
66 static void
67 AcpiDbDisplayCommandInfo (
68 const char *Command,
69 BOOLEAN DisplayAll);
70
71 static void
72 AcpiDbDisplayHelp (
73 char *Command);
74
75 static BOOLEAN
76 AcpiDbMatchCommandHelp (
77 const char *Command,
78 const ACPI_DB_COMMAND_HELP *Help);
79
80
81 /*
82 * Top-level debugger commands.
83 *
84 * This list of commands must match the string table below it
85 */
86 enum AcpiExDebuggerCommands
87 {
88 CMD_NOT_FOUND = 0,
89 CMD_NULL,
90 CMD_ALLOCATIONS,
91 CMD_ARGS,
92 CMD_ARGUMENTS,
93 CMD_BREAKPOINT,
94 CMD_BUSINFO,
95 CMD_CALL,
96 CMD_DEBUG,
97 CMD_DISASSEMBLE,
98 CMD_DISASM,
99 CMD_DUMP,
100 CMD_EVALUATE,
101 CMD_EXECUTE,
102 CMD_EXIT,
103 CMD_FIND,
104 CMD_GO,
105 CMD_HANDLERS,
106 CMD_HELP,
107 CMD_HELP2,
108 CMD_HISTORY,
109 CMD_HISTORY_EXE,
110 CMD_HISTORY_LAST,
111 CMD_INFORMATION,
112 CMD_INTEGRITY,
113 CMD_INTO,
114 CMD_LEVEL,
115 CMD_LIST,
116 CMD_LOCALS,
117 CMD_LOCKS,
118 CMD_METHODS,
119 CMD_NAMESPACE,
120 CMD_NOTIFY,
121 CMD_OBJECTS,
122 CMD_OSI,
123 CMD_OWNER,
124 CMD_PATHS,
125 CMD_PREDEFINED,
126 CMD_PREFIX,
127 CMD_QUIT,
128 CMD_REFERENCES,
129 CMD_RESOURCES,
130 CMD_RESULTS,
131 CMD_SET,
132 CMD_STATS,
133 CMD_STOP,
134 CMD_TABLES,
135 CMD_TEMPLATE,
136 CMD_TRACE,
137 CMD_TREE,
138 CMD_TYPE,
139 #ifdef ACPI_APPLICATION
140 CMD_ENABLEACPI,
141 CMD_EVENT,
142 CMD_GPE,
143 CMD_GPES,
144 CMD_SCI,
145 CMD_SLEEP,
146
147 CMD_CLOSE,
148 CMD_LOAD,
149 CMD_OPEN,
150 CMD_UNLOAD,
151
152 CMD_TERMINATE,
153 CMD_BACKGROUND,
154 CMD_THREADS,
155
156 CMD_TEST,
157 #endif
158 };
159
160 #define CMD_FIRST_VALID 2
161
162
163 /* Second parameter is the required argument count */
164
165 static const ACPI_DB_COMMAND_INFO AcpiGbl_DbCommands[] =
166 {
167 {"<NOT FOUND>", 0},
168 {"<NULL>", 0},
169 {"ALLOCATIONS", 0},
170 {"ARGS", 0},
171 {"ARGUMENTS", 0},
172 {"BREAKPOINT", 1},
173 {"BUSINFO", 0},
174 {"CALL", 0},
175 {"DEBUG", 1},
176 {"DISASSEMBLE", 1},
177 {"DISASM", 1},
178 {"DUMP", 1},
179 {"EVALUATE", 1},
180 {"EXECUTE", 1},
181 {"EXIT", 0},
182 {"FIND", 1},
183 {"GO", 0},
184 {"HANDLERS", 0},
185 {"HELP", 0},
186 {"?", 0},
187 {"HISTORY", 0},
188 {"!", 1},
189 {"!!", 0},
190 {"INFORMATION", 0},
191 {"INTEGRITY", 0},
192 {"INTO", 0},
193 {"LEVEL", 0},
194 {"LIST", 0},
195 {"LOCALS", 0},
196 {"LOCKS", 0},
197 {"METHODS", 0},
198 {"NAMESPACE", 0},
199 {"NOTIFY", 2},
200 {"OBJECTS", 0},
201 {"OSI", 0},
202 {"OWNER", 1},
203 {"PATHS", 0},
204 {"PREDEFINED", 0},
205 {"PREFIX", 0},
206 {"QUIT", 0},
207 {"REFERENCES", 1},
208 {"RESOURCES", 0},
209 {"RESULTS", 0},
210 {"SET", 3},
211 {"STATS", 1},
212 {"STOP", 0},
213 {"TABLES", 0},
214 {"TEMPLATE", 1},
215 {"TRACE", 1},
216 {"TREE", 0},
217 {"TYPE", 1},
218 #ifdef ACPI_APPLICATION
219 {"ENABLEACPI", 0},
220 {"EVENT", 1},
221 {"GPE", 1},
222 {"GPES", 0},
223 {"SCI", 0},
224 {"SLEEP", 0},
225
226 {"CLOSE", 0},
227 {"LOAD", 1},
228 {"OPEN", 1},
229 {"UNLOAD", 1},
230
231 {"TERMINATE", 0},
232 {"BACKGROUND", 1},
233 {"THREADS", 3},
234
235 {"TEST", 1},
236 #endif
237 {NULL, 0}
238 };
239
240 /*
241 * Help for all debugger commands. First argument is the number of lines
242 * of help to output for the command.
243 *
244 * Note: Some commands are not supported by the kernel-level version of
245 * the debugger.
246 */
247 static const ACPI_DB_COMMAND_HELP AcpiGbl_DbCommandHelp[] =
248 {
249 {0, "\nNamespace Access:", "\n"},
250 {1, " Businfo", "Display system bus info\n"},
251 {1, " Disassemble <Method>", "Disassemble a control method\n"},
252 {1, " Find <AcpiName> (? is wildcard)", "Find ACPI name(s) with wildcards\n"},
253 {1, " Integrity", "Validate namespace integrity\n"},
254 {1, " Methods", "Display list of loaded control methods\n"},
255 {1, " Namespace [Object] [Depth]", "Display loaded namespace tree/subtree\n"},
256 {1, " Notify <Object> <Value>", "Send a notification on Object\n"},
257 {1, " Objects [ObjectType]", "Display summary of all objects or just given type\n"},
258 {1, " Owner <OwnerId> [Depth]", "Display loaded namespace by object owner\n"},
259 {1, " Paths", "Display full pathnames of namespace objects\n"},
260 {1, " Predefined", "Check all predefined names\n"},
261 {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"},
262 {1, " References <Addr>", "Find all references to object at addr\n"},
263 {1, " Resources [DeviceName]", "Display Device resources (no arg = all devices)\n"},
264 {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"},
265 {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},
266 {1, " Type <Object>", "Display object type\n"},
267
268 {0, "\nControl Method Execution:", "\n"},
269 {1, " Evaluate <Namepath> [Arguments]", "Evaluate object or control method\n"},
270 {1, " Execute <Namepath> [Arguments]", "Synonym for Evaluate\n"},
271 #ifdef ACPI_APPLICATION
272 {1, " Background <Namepath> [Arguments]", "Evaluate object/method in a separate thread\n"},
273 {1, " Thread <Threads><Loops><NamePath>", "Spawn threads to execute method(s)\n"},
274 #endif
275 {1, " Debug <Namepath> [Arguments]", "Single-Step a control method\n"},
276 {7, " [Arguments] formats:", "Control method argument formats\n"},
277 {1, " Hex Integer", "Integer\n"},
278 {1, " \"Ascii String\"", "String\n"},
279 {1, " (Hex Byte List)", "Buffer\n"},
280 {1, " (01 42 7A BF)", "Buffer example (4 bytes)\n"},
281 {1, " [Package Element List]", "Package\n"},
282 {1, " [0x01 0x1234 \"string\"]", "Package example (3 elements)\n"},
283
284 {0, "\nMiscellaneous:", "\n"},
285 {1, " Allocations", "Display list of current memory allocations\n"},
286 {2, " Dump <Address>|<Namepath>", "\n"},
287 {0, " [Byte|Word|Dword|Qword]", "Display ACPI objects or memory\n"},
288 {1, " Handlers", "Info about global handlers\n"},
289 {1, " Help [Command]", "This help screen or individual command\n"},
290 {1, " History", "Display command history buffer\n"},
291 {1, " Level <DebugLevel>] [console]", "Get/Set debug level for file or console\n"},
292 {1, " Locks", "Current status of internal mutexes\n"},
293 {1, " Osi [Install|Remove <name>]", "Display or modify global _OSI list\n"},
294 {1, " Quit or Exit", "Exit this command\n"},
295 {8, " Stats <SubCommand>", "Display namespace and memory statistics\n"},
296 {1, " Allocations", "Display list of current memory allocations\n"},
297 {1, " Memory", "Dump internal memory lists\n"},
298 {1, " Misc", "Namespace search and mutex stats\n"},
299 {1, " Objects", "Summary of namespace objects\n"},
300 {1, " Sizes", "Sizes for each of the internal objects\n"},
301 {1, " Stack", "Display CPU stack usage\n"},
302 {1, " Tables", "Info about current ACPI table(s)\n"},
303 {1, " Tables", "Display info about loaded ACPI tables\n"},
304 #ifdef ACPI_APPLICATION
305 {1, " Terminate", "Delete namespace and all internal objects\n"},
306 #endif
307 {1, " ! <CommandNumber>", "Execute command from history buffer\n"},
308 {1, " !!", "Execute last command again\n"},
309
310 {0, "\nMethod and Namespace Debugging:", "\n"},
311 {5, " Trace <State> [<Namepath>] [Once]", "Trace control method execution\n"},
312 {1, " Enable", "Enable all messages\n"},
313 {1, " Disable", "Disable tracing\n"},
314 {1, " Method", "Enable method execution messages\n"},
315 {1, " Opcode", "Enable opcode execution messages\n"},
316 {3, " Test <TestName>", "Invoke a debug test\n"},
317 {1, " Objects", "Read/write/compare all namespace data objects\n"},
318 {1, " Predefined", "Validate all ACPI predefined names (_STA, etc.)\n"},
319 {1, " Execute predefined", "Execute all predefined (public) methods\n"},
320
321 {0, "\nControl Method Single-Step Execution:","\n"},
322 {1, " Arguments (or Args)", "Display method arguments\n"},
323 {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},
324 {1, " Call", "Run to next control method invocation\n"},
325 {1, " Go", "Allow method to run to completion\n"},
326 {1, " Information", "Display info about the current method\n"},
327 {1, " Into", "Step into (not over) a method call\n"},
328 {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},
329 {1, " Locals", "Display method local variables\n"},
330 {1, " Results", "Display method result stack\n"},
331 {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
332 {1, " Stop", "Terminate control method\n"},
333 {1, " Tree", "Display control method calling tree\n"},
334 {1, " <Enter>", "Single step next AML opcode (over calls)\n"},
335
336 #ifdef ACPI_APPLICATION
337 {0, "\nFile Operations:", "\n"},
338 {1, " Close", "Close debug output file\n"},
339 {1, " Load <Input Filename>", "Load ACPI table from a file\n"},
340 {1, " Open <Output Filename>", "Open a file for debug output\n"},
341 {1, " Unload <Namepath>", "Unload an ACPI table via namespace object\n"},
342
343 {0, "\nHardware Simulation:", "\n"},
344 {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},
345 {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
346 {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
347 {1, " Gpes", "Display info on all GPE devices\n"},
348 {1, " Sci", "Generate an SCI\n"},
349 {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
350 #endif
351 {0, NULL, NULL}
352 };
353
354
355 /*******************************************************************************
356 *
357 * FUNCTION: AcpiDbMatchCommandHelp
358 *
359 * PARAMETERS: Command - Command string to match
360 * Help - Help table entry to attempt match
361 *
362 * RETURN: TRUE if command matched, FALSE otherwise
363 *
364 * DESCRIPTION: Attempt to match a command in the help table in order to
365 * print help information for a single command.
366 *
367 ******************************************************************************/
368
369 static BOOLEAN
370 AcpiDbMatchCommandHelp (
371 const char *Command,
372 const ACPI_DB_COMMAND_HELP *Help)
373 {
374 const char *Invocation = Help->Invocation;
375 UINT32 LineCount;
376
377
378 /* Valid commands in the help table begin with a couple of spaces */
379
380 if (*Invocation != ' ')
381 {
382 return (FALSE);
383 }
384
385 while (*Invocation == ' ')
386 {
387 Invocation++;
388 }
389
390 /* Match command name (full command or substring) */
391
392 while ((*Command) && (*Invocation) && (*Invocation != ' '))
393 {
394 if (tolower ((int) *Command) != tolower ((int) *Invocation))
395 {
396 return (FALSE);
397 }
398
399 Invocation++;
400 Command++;
401 }
402
403 /* Print the appropriate number of help lines */
404
405 LineCount = Help->LineCount;
406 while (LineCount)
407 {
408 AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
409 Help++;
410 LineCount--;
411 }
412
413 return (TRUE);
414 }
415
416
417 /*******************************************************************************
418 *
419 * FUNCTION: AcpiDbDisplayCommandInfo
420 *
421 * PARAMETERS: Command - Command string to match
422 * DisplayAll - Display all matching commands, or just
423 * the first one (substring match)
424 *
425 * RETURN: None
426 *
427 * DESCRIPTION: Display help information for a Debugger command.
428 *
429 ******************************************************************************/
430
431 static void
432 AcpiDbDisplayCommandInfo (
433 const char *Command,
434 BOOLEAN DisplayAll)
435 {
436 const ACPI_DB_COMMAND_HELP *Next;
437 BOOLEAN Matched;
438
439
440 Next = AcpiGbl_DbCommandHelp;
441 while (Next->Invocation)
442 {
443 Matched = AcpiDbMatchCommandHelp (Command, Next);
444 if (!DisplayAll && Matched)
445 {
446 return;
447 }
448
449 Next++;
450 }
451 }
452
453
454 /*******************************************************************************
455 *
456 * FUNCTION: AcpiDbDisplayHelp
457 *
458 * PARAMETERS: Command - Optional command string to display help.
459 * if not specified, all debugger command
460 * help strings are displayed
461 *
462 * RETURN: None
463 *
464 * DESCRIPTION: Display help for a single debugger command, or all of them.
465 *
466 ******************************************************************************/
467
468 static void
469 AcpiDbDisplayHelp (
470 char *Command)
471 {
472 const ACPI_DB_COMMAND_HELP *Next = AcpiGbl_DbCommandHelp;
473
474
475 if (!Command)
476 {
477 /* No argument to help, display help for all commands */
478
479 AcpiOsPrintf ("\nSummary of AML Debugger Commands\n\n");
480
481 while (Next->Invocation)
482 {
483 AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
484 Next++;
485 }
486 AcpiOsPrintf ("\n");
487
488 }
489 else
490 {
491 /* Display help for all commands that match the subtring */
492
493 AcpiDbDisplayCommandInfo (Command, TRUE);
494 }
495 }
496
497
498 /*******************************************************************************
499 *
500 * FUNCTION: AcpiDbGetNextToken
501 *
502 * PARAMETERS: String - Command buffer
503 * Next - Return value, end of next token
504 *
505 * RETURN: Pointer to the start of the next token.
506 *
507 * DESCRIPTION: Command line parsing. Get the next token on the command line
508 *
509 ******************************************************************************/
510
511 char *
512 AcpiDbGetNextToken (
513 char *String,
514 char **Next,
515 ACPI_OBJECT_TYPE *ReturnType)
516 {
517 char *Start;
518 UINT32 Depth;
519 ACPI_OBJECT_TYPE Type = ACPI_TYPE_INTEGER;
520
521
522 /* At end of buffer? */
523
524 if (!String || !(*String))
525 {
526 return (NULL);
527 }
528
529 /* Remove any spaces at the beginning */
530
531 if (*String == ' ')
532 {
533 while (*String && (*String == ' '))
534 {
535 String++;
536 }
537
538 if (!(*String))
539 {
540 return (NULL);
541 }
542 }
543
544 switch (*String)
545 {
546 case '"':
547
548 /* This is a quoted string, scan until closing quote */
549
550 String++;
551 Start = String;
552 Type = ACPI_TYPE_STRING;
553
554 /* Find end of string */
555
556 while (*String && (*String != '"'))
557 {
558 String++;
559 }
560 break;
561
562 case '(':
563
564 /* This is the start of a buffer, scan until closing paren */
565
566 String++;
567 Start = String;
568 Type = ACPI_TYPE_BUFFER;
569
570 /* Find end of buffer */
571
572 while (*String && (*String != ')'))
573 {
574 String++;
575 }
576 break;
577
578 case '[':
579
580 /* This is the start of a package, scan until closing bracket */
581
582 String++;
583 Depth = 1;
584 Start = String;
585 Type = ACPI_TYPE_PACKAGE;
586
587 /* Find end of package (closing bracket) */
588
589 while (*String)
590 {
591 /* Handle String package elements */
592
593 if (*String == '"')
594 {
595 /* Find end of string */
596
597 String++;
598 while (*String && (*String != '"'))
599 {
600 String++;
601 }
602 if (!(*String))
603 {
604 break;
605 }
606 }
607 else if (*String == '[')
608 {
609 Depth++; /* A nested package declaration */
610 }
611 else if (*String == ']')
612 {
613 Depth--;
614 if (Depth == 0) /* Found final package closing bracket */
615 {
616 break;
617 }
618 }
619
620 String++;
621 }
622 break;
623
624 default:
625
626 Start = String;
627
628 /* Find end of token */
629
630 while (*String && (*String != ' '))
631 {
632 String++;
633 }
634 break;
635 }
636
637 if (!(*String))
638 {
639 *Next = NULL;
640 }
641 else
642 {
643 *String = 0;
644 *Next = String + 1;
645 }
646
647 *ReturnType = Type;
648 return (Start);
649 }
650
651
652 /*******************************************************************************
653 *
654 * FUNCTION: AcpiDbGetLine
655 *
656 * PARAMETERS: InputBuffer - Command line buffer
657 *
658 * RETURN: Count of arguments to the command
659 *
660 * DESCRIPTION: Get the next command line from the user. Gets entire line
661 * up to the next newline
662 *
663 ******************************************************************************/
664
665 static UINT32
666 AcpiDbGetLine (
667 char *InputBuffer)
668 {
669 UINT32 i;
670 UINT32 Count;
671 char *Next;
672 char *This;
673
674
675 if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),
676 InputBuffer))
677 {
678 AcpiOsPrintf (
679 "Buffer overflow while parsing input line (max %u characters)\n",
680 sizeof (AcpiGbl_DbParsedBuf));
681 return (0);
682 }
683
684 This = AcpiGbl_DbParsedBuf;
685 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
686 {
687 AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
688 &AcpiGbl_DbArgTypes[i]);
689 if (!AcpiGbl_DbArgs[i])
690 {
691 break;
692 }
693
694 This = Next;
695 }
696
697 /* Uppercase the actual command */
698
699 AcpiUtStrupr (AcpiGbl_DbArgs[0]);
700
701 Count = i;
702 if (Count)
703 {
704 Count--; /* Number of args only */
705 }
706
707 return (Count);
708 }
709
710
711 /*******************************************************************************
712 *
713 * FUNCTION: AcpiDbMatchCommand
714 *
715 * PARAMETERS: UserCommand - User command line
716 *
717 * RETURN: Index into command array, -1 if not found
718 *
719 * DESCRIPTION: Search command array for a command match
720 *
721 ******************************************************************************/
722
723 static UINT32
724 AcpiDbMatchCommand (
725 char *UserCommand)
726 {
727 UINT32 i;
728
729
730 if (!UserCommand || UserCommand[0] == 0)
731 {
732 return (CMD_NULL);
733 }
734
735 for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
736 {
737 if (strstr (
738 ACPI_CAST_PTR (char, AcpiGbl_DbCommands[i].Name), UserCommand) ==
739 AcpiGbl_DbCommands[i].Name)
740 {
741 return (i);
742 }
743 }
744
745 /* Command not recognized */
746
747 return (CMD_NOT_FOUND);
748 }
749
750
751 /*******************************************************************************
752 *
753 * FUNCTION: AcpiDbCommandDispatch
754 *
755 * PARAMETERS: InputBuffer - Command line buffer
756 * WalkState - Current walk
757 * Op - Current (executing) parse op
758 *
759 * RETURN: Status
760 *
761 * DESCRIPTION: Command dispatcher.
762 *
763 ******************************************************************************/
764
765 ACPI_STATUS
766 AcpiDbCommandDispatch (
767 char *InputBuffer,
768 ACPI_WALK_STATE *WalkState,
769 ACPI_PARSE_OBJECT *Op)
770 {
771 UINT32 Temp;
772 UINT32 CommandIndex;
773 UINT32 ParamCount;
774 char *CommandLine;
775 ACPI_STATUS Status = AE_CTRL_TRUE;
776
777
778 /* If AcpiTerminate has been called, terminate this thread */
779
780 if (AcpiGbl_DbTerminateLoop)
781 {
782 return (AE_CTRL_TERMINATE);
783 }
784
785 /* Find command and add to the history buffer */
786
787 ParamCount = AcpiDbGetLine (InputBuffer);
788 CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
789 Temp = 0;
790
791 /*
792 * We don't want to add the !! command to the history buffer. It
793 * would cause an infinite loop because it would always be the
794 * previous command.
795 */
796 if (CommandIndex != CMD_HISTORY_LAST)
797 {
798 AcpiDbAddToHistory (InputBuffer);
799 }
800
801 /* Verify that we have the minimum number of params */
802
803 if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
804 {
805 AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
806 ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
807 AcpiGbl_DbCommands[CommandIndex].MinArgs);
808
809 AcpiDbDisplayCommandInfo (
810 AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
811 return (AE_CTRL_TRUE);
812 }
813
814 /* Decode and dispatch the command */
815
816 switch (CommandIndex)
817 {
818 case CMD_NULL:
819
820 if (Op)
821 {
822 return (AE_OK);
823 }
824 break;
825
826 case CMD_ALLOCATIONS:
827
828 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
829 AcpiUtDumpAllocations ((UINT32) -1, NULL);
830 #endif
831 break;
832
833 case CMD_ARGS:
834 case CMD_ARGUMENTS:
835
836 AcpiDbDisplayArguments ();
837 break;
838
839 case CMD_BREAKPOINT:
840
841 AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
842 break;
843
844 case CMD_BUSINFO:
845
846 AcpiDbGetBusInfo ();
847 break;
848
849 case CMD_CALL:
850
851 AcpiDbSetMethodCallBreakpoint (Op);
852 Status = AE_OK;
853 break;
854
855 case CMD_DEBUG:
856
857 AcpiDbExecute (AcpiGbl_DbArgs[1],
858 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
859 break;
860
861 case CMD_DISASSEMBLE:
862 case CMD_DISASM:
863
864 #ifdef ACPI_DISASSEMBLER
865 (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
866 #else
867 AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
868 #endif
869 break;
870
871 case CMD_DUMP:
872
873 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
874 break;
875
876 case CMD_EVALUATE:
877 case CMD_EXECUTE:
878
879 AcpiDbExecute (AcpiGbl_DbArgs[1],
880 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
881 break;
882
883 case CMD_FIND:
884
885 Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
886 break;
887
888 case CMD_GO:
889
890 AcpiGbl_CmSingleStep = FALSE;
891 return (AE_OK);
892
893 case CMD_HANDLERS:
894
895 AcpiDbDisplayHandlers ();
896 break;
897
898 case CMD_HELP:
899 case CMD_HELP2:
900
901 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
902 break;
903
904 case CMD_HISTORY:
905
906 AcpiDbDisplayHistory ();
907 break;
908
909 case CMD_HISTORY_EXE: /* ! command */
910
911 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
912 if (!CommandLine)
913 {
914 return (AE_CTRL_TRUE);
915 }
916
917 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
918 return (Status);
919
920 case CMD_HISTORY_LAST: /* !! command */
921
922 CommandLine = AcpiDbGetFromHistory (NULL);
923 if (!CommandLine)
924 {
925 return (AE_CTRL_TRUE);
926 }
927
928 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
929 return (Status);
930
931 case CMD_INFORMATION:
932
933 AcpiDbDisplayMethodInfo (Op);
934 break;
935
936 case CMD_INTEGRITY:
937
938 AcpiDbCheckIntegrity ();
939 break;
940
941 case CMD_INTO:
942
943 if (Op)
944 {
945 AcpiGbl_CmSingleStep = TRUE;
946 return (AE_OK);
947 }
948 break;
949
950 case CMD_LEVEL:
951
952 if (ParamCount == 0)
953 {
954 AcpiOsPrintf (
955 "Current debug level for file output is: %8.8lX\n",
956 AcpiGbl_DbDebugLevel);
957 AcpiOsPrintf (
958 "Current debug level for console output is: %8.8lX\n",
959 AcpiGbl_DbConsoleDebugLevel);
960 }
961 else if (ParamCount == 2)
962 {
963 Temp = AcpiGbl_DbConsoleDebugLevel;
964 AcpiGbl_DbConsoleDebugLevel =
965 strtoul (AcpiGbl_DbArgs[1], NULL, 16);
966 AcpiOsPrintf (
967 "Debug Level for console output was %8.8lX, now %8.8lX\n",
968 Temp, AcpiGbl_DbConsoleDebugLevel);
969 }
970 else
971 {
972 Temp = AcpiGbl_DbDebugLevel;
973 AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);
974 AcpiOsPrintf (
975 "Debug Level for file output was %8.8lX, now %8.8lX\n",
976 Temp, AcpiGbl_DbDebugLevel);
977 }
978 break;
979
980 case CMD_LIST:
981
982 #ifdef ACPI_DISASSEMBLER
983 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
984 #else
985 AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
986 #endif
987 break;
988
989 case CMD_LOCKS:
990
991 AcpiDbDisplayLocks ();
992 break;
993
994 case CMD_LOCALS:
995
996 AcpiDbDisplayLocals ();
997 break;
998
999 case CMD_METHODS:
1000 Status = AcpiDbDisplayObjects (__UNCONST("METHOD"), AcpiGbl_DbArgs[1]);
1001 break;
1002
1003 case CMD_NAMESPACE:
1004
1005 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1006 break;
1007
1008 case CMD_NOTIFY:
1009
1010 Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);
1011 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
1012 break;
1013
1014 case CMD_OBJECTS:
1015
1016 AcpiUtStrupr (AcpiGbl_DbArgs[1]);
1017 Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1018 break;
1019
1020 case CMD_OSI:
1021
1022 AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1023 break;
1024
1025 case CMD_OWNER:
1026
1027 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1028 break;
1029
1030 case CMD_PATHS:
1031
1032 AcpiDbDumpNamespacePaths ();
1033 break;
1034
1035 case CMD_PREFIX:
1036
1037 AcpiDbSetScope (AcpiGbl_DbArgs[1]);
1038 break;
1039
1040 case CMD_REFERENCES:
1041
1042 AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
1043 break;
1044
1045 case CMD_RESOURCES:
1046
1047 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
1048 break;
1049
1050 case CMD_RESULTS:
1051
1052 AcpiDbDisplayResults ();
1053 break;
1054
1055 case CMD_SET:
1056
1057 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1058 AcpiGbl_DbArgs[3]);
1059 break;
1060
1061 case CMD_STATS:
1062
1063 Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
1064 break;
1065
1066 case CMD_STOP:
1067
1068 return (AE_NOT_IMPLEMENTED);
1069
1070 case CMD_TABLES:
1071
1072 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
1073 break;
1074
1075 case CMD_TEMPLATE:
1076
1077 AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
1078 break;
1079
1080 case CMD_TRACE:
1081
1082 AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
1083 break;
1084
1085 case CMD_TREE:
1086
1087 AcpiDbDisplayCallingTree ();
1088 break;
1089
1090 case CMD_TYPE:
1091
1092 AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
1093 break;
1094
1095 #ifdef ACPI_APPLICATION
1096
1097 /* Hardware simulation commands. */
1098
1099 case CMD_ENABLEACPI:
1100 #if (!ACPI_REDUCED_HARDWARE)
1101
1102 Status = AcpiEnable();
1103 if (ACPI_FAILURE(Status))
1104 {
1105 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
1106 return (Status);
1107 }
1108 #endif /* !ACPI_REDUCED_HARDWARE */
1109 break;
1110
1111 case CMD_EVENT:
1112
1113 AcpiOsPrintf ("Event command not implemented\n");
1114 break;
1115
1116 case CMD_GPE:
1117
1118 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1119 break;
1120
1121 case CMD_GPES:
1122
1123 AcpiDbDisplayGpes ();
1124 break;
1125
1126 case CMD_SCI:
1127
1128 AcpiDbGenerateSci ();
1129 break;
1130
1131 case CMD_SLEEP:
1132
1133 Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
1134 break;
1135
1136 /* File I/O commands. */
1137
1138 case CMD_CLOSE:
1139
1140 AcpiDbCloseDebugFile ();
1141 break;
1142
1143 case CMD_LOAD:
1144 {
1145 ACPI_NEW_TABLE_DESC *ListHead = NULL;
1146
1147 Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1],
1148 ACPI_GET_ALL_TABLES, &ListHead);
1149 if (ACPI_SUCCESS (Status))
1150 {
1151 AcpiDbLoadTables (ListHead);
1152 }
1153 }
1154 break;
1155
1156 case CMD_OPEN:
1157
1158 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
1159 break;
1160
1161 /* User space commands. */
1162
1163 case CMD_TERMINATE:
1164
1165 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1166 AcpiUtSubsystemShutdown ();
1167
1168 /*
1169 * TBD: [Restructure] Need some way to re-initialize without
1170 * re-creating the semaphores!
1171 */
1172
1173 AcpiGbl_DbTerminateLoop = TRUE;
1174 /* AcpiInitialize (NULL); */
1175 break;
1176
1177 case CMD_BACKGROUND:
1178
1179 AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2],
1180 &AcpiGbl_DbArgTypes[2]);
1181 break;
1182
1183 case CMD_THREADS:
1184
1185 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1186 AcpiGbl_DbArgs[3]);
1187 break;
1188
1189 /* Debug test commands. */
1190
1191 case CMD_PREDEFINED:
1192
1193 AcpiDbCheckPredefinedNames ();
1194 break;
1195
1196 case CMD_TEST:
1197
1198 AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);
1199 break;
1200
1201 case CMD_UNLOAD:
1202
1203 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
1204 break;
1205 #endif
1206
1207 case CMD_EXIT:
1208 case CMD_QUIT:
1209
1210 if (Op)
1211 {
1212 AcpiOsPrintf ("Method execution terminated\n");
1213 return (AE_CTRL_TERMINATE);
1214 }
1215
1216 if (!AcpiGbl_DbOutputToFile)
1217 {
1218 AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
1219 }
1220
1221 #ifdef ACPI_APPLICATION
1222 AcpiDbCloseDebugFile ();
1223 #endif
1224 AcpiGbl_DbTerminateLoop = TRUE;
1225 return (AE_CTRL_TERMINATE);
1226
1227 case CMD_NOT_FOUND:
1228 default:
1229
1230 AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);
1231 return (AE_CTRL_TRUE);
1232 }
1233
1234 if (ACPI_SUCCESS (Status))
1235 {
1236 Status = AE_CTRL_TRUE;
1237 }
1238
1239 return (Status);
1240 }
1241
1242
1243 /*******************************************************************************
1244 *
1245 * FUNCTION: AcpiDbExecuteThread
1246 *
1247 * PARAMETERS: Context - Not used
1248 *
1249 * RETURN: None
1250 *
1251 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1252 * simply dispatches it.
1253 *
1254 ******************************************************************************/
1255
1256 void ACPI_SYSTEM_XFACE
1257 AcpiDbExecuteThread (
1258 void *Context)
1259 {
1260
1261 (void) AcpiDbUserCommands ();
1262 AcpiGbl_DbThreadsTerminated = TRUE;
1263 }
1264
1265
1266 /*******************************************************************************
1267 *
1268 * FUNCTION: AcpiDbUserCommands
1269 *
1270 * PARAMETERS: None
1271 *
1272 * RETURN: None
1273 *
1274 * DESCRIPTION: Command line execution for the AML debugger. Commands are
1275 * matched and dispatched here.
1276 *
1277 ******************************************************************************/
1278
1279 ACPI_STATUS
1280 AcpiDbUserCommands (
1281 void)
1282 {
1283 ACPI_STATUS Status = AE_OK;
1284
1285
1286 AcpiOsPrintf ("\n");
1287
1288 /* TBD: [Restructure] Need a separate command line buffer for step mode */
1289
1290 while (!AcpiGbl_DbTerminateLoop)
1291 {
1292 /* Wait the readiness of the command */
1293
1294 Status = AcpiOsWaitCommandReady ();
1295 if (ACPI_FAILURE (Status))
1296 {
1297 break;
1298 }
1299
1300 /* Just call to the command line interpreter */
1301
1302 AcpiGbl_MethodExecuting = FALSE;
1303 AcpiGbl_StepToNextCall = FALSE;
1304
1305 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1306
1307 /* Notify the completion of the command */
1308
1309 Status = AcpiOsNotifyCommandComplete ();
1310 if (ACPI_FAILURE (Status))
1311 {
1312 break;
1313 }
1314 }
1315
1316 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
1317 {
1318 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1319 }
1320 return (Status);
1321 }
1322