]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.c
MdeModulePkg/EbcDxe: Fix incorrect Copyright format
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbCommand.c
1 /** @file
2
3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 **/
14
15 #include "Edb.h"
16
17 //
18 // Debugger Command Table
19 //
20 EFI_DEBUGGER_COMMAND_SET mDebuggerCommandSet[] = {
21 //
22 // Execution
23 //
24 {
25 L"G",
26 L"G/[F5] - continue to run the program\n",
27 L"The go command is used to cause the debugger to not interrupt execution of the EBC image. The debugger will only break execution of the interpreter if an exception is encountered (including an EBC breakpoint).\n\n",
28 L"G [til <Address|Symbol>]\n"
29 L" (No Argument) - It means continue run the program.\n"
30 L" til - It means continuing run the program till IP is the Address.\n"
31 L" <Address> - The hexical address user want to break at.\n"
32 L" <Symbol> - The symbol name for target address user want to break at. It has following format [MapFileName:]SymbolName\n",
33 L"Execution:\n",
34 {SCAN_F5, CHAR_NULL},
35 DebuggerGo
36 },
37 {
38 L"T",
39 L"T/[F8] - step into\n",
40 L"The step into command will cause the EBC debugger to step a single instruction. If the instruction is a call to internal code (CALL), then the debugger will break at the new function CALL.\n\n",
41 L"T\n"
42 L" (No Argument)\n",
43 L"",
44 {SCAN_F8, CHAR_NULL},
45 DebuggerStepInto
46 },
47 {
48 L"P",
49 L"P/[F10] - step over\n",
50 L"The step over command will cause the EBC debugger to step a single instruction. If the instruction is a call to internal code (CALL), then the external call will be made and the debugger will break at the instruction following the CALL.\n\n",
51 L"P\n"
52 L" (No Argument)\n",
53 L"",
54 {SCAN_F10, CHAR_NULL},
55 DebuggerStepOver
56 },
57 {
58 L"O",
59 L"O/[F11] - step out\n",
60 L"The step out command causes the EBC debugger to step out function calls. The function will be executed, but the debugger will stop after the called function returns.\n\n",
61 L"O\n"
62 L" (No Argument)\n",
63 L"",
64 {SCAN_F11, CHAR_NULL},
65 DebuggerStepOut
66 },
67 {
68 L"Q",
69 L"Q - reset the debugger to default value and go\n",
70 L"The quit command will reset the debugger to default value and go.\n\n",
71 L"Q\n"
72 L" (No Argument)\n",
73 L"",
74 {SCAN_NULL, CHAR_NULL},
75 DebuggerQuit
76 },
77 //
78 // Break
79 //
80 {
81 L"BOC",
82 L"BO[C|CX|R|E|T|K] - break on CALL/CALLEX/RET/Entrypoint/Native Thunk/Key\n",
83 L"Enabling break-on-call will cause the debugger to halt execution and display the debugger prompt prior to executing any EBC CALL (to EBC) instructions.\n\n",
84 L"BOC [on|off]\n"
85 L" (No Argument) - show current state\n"
86 L" on - enable break-on-call\n"
87 L" off - disable break-on-call\n",
88 L"Break:\n",
89 {SCAN_NULL, CHAR_NULL},
90 DebuggerBreakOnCALL
91 },
92 {
93 L"BOCX",
94 L"",
95 L"Enabling break-on-callex will cause the debugger to halt execution and display the debugger prompt prior to executing EBC CALLEX (thunk out) instructions.\n\n",
96 L"BOCX [on|off]\n"
97 L" (No Argument) - show current state\n"
98 L" on - enable break-on-callex\n"
99 L" off - disable break-on-callex\n",
100 L"",
101 {SCAN_NULL, CHAR_NULL},
102 DebuggerBreakOnCALLEX
103 },
104 {
105 L"BOR",
106 L"",
107 L"Enabling break-on-return will cause the debugger to halt execution and display the debugger prompt prior to executing EBC RET instructions.\n\n",
108 L"BOR [on|off]\n"
109 L" (No Argument) - show current state\n"
110 L" on - enable break-on-return\n"
111 L" off - disable break-on-return\n",
112 L"",
113 {SCAN_NULL, CHAR_NULL},
114 DebuggerBreakOnRET
115 },
116 {
117 L"BOE",
118 L"",
119 L"Enabling break-on-entrypoint will cause the debugger to halt execution and display the debugger prompt prior to start a driver entry point. (Default is on)\n\n",
120 L"BOE [on|off]\n"
121 L" (No Argument) - show current state\n"
122 L" on - enable break-on-entrypoint\n"
123 L" off - disable break-on-entrypoint\n",
124 L"",
125 {SCAN_NULL, CHAR_NULL},
126 DebuggerBreakOnEntrypoint
127 },
128 {
129 L"BOT",
130 L"",
131 L"Enabling break-on-thunk will cause the debugger to halt execution and display the debugger prompt prior to start native call EBC thunk. (Default is on)\n\n",
132 L"BOT [on|off]\n"
133 L" (No Argument) - show current state\n"
134 L" on - enable break-on-thunk\n"
135 L" off - disable break-on-thunk\n",
136 L"",
137 {SCAN_NULL, CHAR_NULL},
138 DebuggerBreakOnThunk
139 },
140 {
141 L"BOK",
142 L"",
143 L"Enabling break-on-key will cause the debugger to halt execution and display the debugger prompt after press any key.\n\n",
144 L"BOK [on|off]\n"
145 L" (No Argument) - show current state\n"
146 L" on - enable break-on-key\n"
147 L" off - disable break-on-key\n",
148 L"",
149 {SCAN_NULL, CHAR_NULL},
150 DebuggerBreakOnKey
151 },
152 {
153 L"BL",
154 L"B[L|P|C|D|E] - breakpoint list/set/clear/disable/enable\n",
155 L"List Breakpoint\n\n",
156 L"BL\n"
157 L" (No Argument) - show the state for current breakpoint\n",
158 L"",
159 {SCAN_NULL, CHAR_NULL},
160 DebuggerBreakpointList
161 },
162 {
163 L"BP",
164 L"",
165 L"Set Breakpoint\n\n",
166 L"BP <Address|Symbol>\n"
167 L" <Address> - Hexical breakpoint address\n"
168 L" <Symbol> - Symbol name for breakpoint address. It has following format [MapFileName:]SymbolName.\n",
169 L"",
170 {SCAN_NULL, CHAR_NULL},
171 DebuggerBreakpointSet
172 },
173 {
174 L"BC",
175 L"",
176 L"Clear Breakpoint\n\n",
177 L"BC <Index>|*\n"
178 L" <Index> - Decimal breakpoint index, which can be got from BL command\n"
179 L" * - For all the breakpoint\n",
180 L"",
181 {SCAN_NULL, CHAR_NULL},
182 DebuggerBreakpointClear
183 },
184 {
185 L"BD",
186 L"",
187 L"Disable Breakpoint\n\n",
188 L"BD <Index>|*\n"
189 L" <Index> - Decimal breakpoint index, which can be got from BL command\n"
190 L" * - For all the breakpoint\n",
191 L"",
192 {SCAN_NULL, CHAR_NULL},
193 DebuggerBreakpointDisable
194 },
195 {
196 L"BE",
197 L"",
198 L"Enable Breakpoint\n\n",
199 L"BE <Index>|*\n"
200 L" <Index> - Decimal breakpoint index, which can be got from BL command\n"
201 L" * - For all the breakpoint\n",
202 L"",
203 {SCAN_NULL, CHAR_NULL},
204 DebuggerBreakpointEnable
205 },
206 //
207 // Information
208 //
209 {
210 L"K",
211 L"K - show/clear call-stack\n",
212 L"The call-stack command will show or clear the current call-stack.\n\n",
213 L"K [p [<ParameterNum>]|c]\n"
214 L" (No Argument) - Show current call-stack\n"
215 L" p - Show current call-stack with parameters\n"
216 L" ParameterNum - Decimal call-stack parameters number, 8 by default, 16 as max\n"
217 L" c - Clear current call-stack\n",
218 L"Information:\n",
219 {SCAN_NULL, CHAR_NULL},
220 DebuggerCallStack
221 },
222 {
223 L"TRACE",
224 L"TRACE - show/clear trace instruction branch\n",
225 L"The trace command will show or clear the latest instruction branch.\n\n",
226 L"TRACE [c]\n"
227 L" (No Argument) - Show current instrcution branch\n"
228 L" c - Clear current instruction branch\n",
229 L"",
230 {SCAN_NULL, CHAR_NULL},
231 DebuggerInstructionBranch
232 },
233 {
234 L"R",
235 L"R/[F2] - display/modify register\n",
236 L"The register command is used to display or modify the contents of EBC VM registers. (R0~R7, Flags, IP)\n\n",
237 L"R [<Register> <Value>]\n"
238 L" (No Argument) - Display all registers\n"
239 L" <Register> - EBC VM register name (R0~R7, Flags, ControlFlags, and IP\n"
240 L" <Value> - The Hexical value of register\n",
241 L"",
242 {SCAN_F2, CHAR_NULL},
243 DebuggerRegister
244 },
245 {
246 L"L",
247 L"L/[F4] - show/load instruction assembly count\n",
248 L"The list assembly command will disassemble instructions starting with the current EBC VM instruction pointer. (by default 5 instructions)\n\n",
249 L"L [<Count>]\n"
250 L" (No Argument) - List current assembly code\n"
251 L" Count - The decimal instruction assembly count\n",
252 L"",
253 {SCAN_F4, CHAR_NULL},
254 DebuggerList
255 },
256 {
257 L"SCOPE",
258 L"SCOPE - load scope address\n",
259 L"The scope command will disassemble instructions starting with the Scope. (by default current EBC VM IP)\n\n",
260 L"SCOPE <Address|Symbol>\n"
261 L" <Address> - The Hexical address where user wants to see the assembly code\n"
262 L" <Symbol> - Symbol name for scope address. It has following format [MapFileName:]SymbolName.\n",
263 L"",
264 {SCAN_NULL, CHAR_NULL},
265 DebuggerScope
266 },
267 {
268 L"DB",
269 L"[D|E][B|W|D|Q] - display/modify memory\n",
270 L"Display BYTES Memory\n\n",
271 L"DB <Address|Symbol> [<Count>]\n"
272 L" <Address> - The hexical memory address\n"
273 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
274 L" <Count> - The hexical memory count (not set means 1)\n",
275 L"",
276 {SCAN_NULL, CHAR_NULL},
277 DebuggerMemoryDB
278 },
279 {
280 L"DW",
281 L"",
282 L"Display WORDS Memory\n\n",
283 L"DW <Address|Symbol> [<Count>]\n"
284 L" <Address> - The hexical memory address\n"
285 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
286 L" <Count> - The hexical memory count (not set means 1)\n",
287 L"",
288 {SCAN_NULL, CHAR_NULL},
289 DebuggerMemoryDW
290 },
291 {
292 L"DD",
293 L"",
294 L"Display DWORDS Memory\n\n",
295 L"DD <Address|Symbol> [<Count>]\n"
296 L" <Address> - The hexical memory address\n"
297 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
298 L" <Count> - The hexical memory count (not set means 1)\n",
299 L"",
300 {SCAN_NULL, CHAR_NULL},
301 DebuggerMemoryDD
302 },
303 {
304 L"DQ",
305 L"",
306 L"Display QWORDS Memory\n\n",
307 L"DQ <Address|Symbol> [<Count>]\n"
308 L" <Address> - The hexical memory address\n"
309 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
310 L" <Count> - The hexical memory count (not set means 1)\n",
311 L"",
312 {SCAN_NULL, CHAR_NULL},
313 DebuggerMemoryDQ
314 },
315 {
316 L"EB",
317 L"",
318 L"Enter BYTES Memory\n\n",
319 L"EB <Address|Symbol> <Value>\n"
320 L" <Address> - The hexical memory address\n"
321 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
322 L" <Value> - The hexical memory value\n",
323 L"",
324 {SCAN_NULL, CHAR_NULL},
325 DebuggerMemoryEB
326 },
327 {
328 L"EW",
329 L"",
330 L"Enter WORDS Memory\n\n",
331 L"EW <Address|Symbol> <Value>\n"
332 L" <Address> - The hexical memory address\n"
333 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
334 L" <Value> - The hexical memory value\n",
335 L"",
336 {SCAN_NULL, CHAR_NULL},
337 DebuggerMemoryEW
338 },
339 {
340 L"ED",
341 L"",
342 L"Enter DWORDS Memory\n\n",
343 L"ED <Address|Symbol> <Value>\n"
344 L" <Address> - The hexical memory address\n"
345 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
346 L" <Value> - The hexical memory value\n",
347 L"",
348 {SCAN_NULL, CHAR_NULL},
349 DebuggerMemoryED
350 },
351 {
352 L"EQ",
353 L"",
354 L"Enter QWORDS Memory\n\n",
355 L"EQ <Address|Symbol> <Value>\n"
356 L" <Address> - The hexical memory address\n"
357 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
358 L" <Value> - The hexical memory value\n",
359 L"",
360 {SCAN_NULL, CHAR_NULL},
361 DebuggerMemoryEQ
362 },
363 //
364 // Symbol
365 //
366 {
367 L"LN",
368 L"LN - list the symbol\n",
369 L"The show symbol command will list all the current symbol. It can list the symbol in one symbol file, or list the same symbol in all the files. It can also list the symbol according to nearest address.\n\n",
370 L"LN [[F <SymbolFile>] [S <Symbol>]] | <Address>\n"
371 L" (No Argument) - List all the symbol\n"
372 L" F <SymbolFile> - List the symbol in this symbol file only\n"
373 L" S <Symbol> - List this symbol only\n"
374 L" <Address> - The hexical memory address, which user want to find the symbol for.\n",
375 L"Symbol:\n",
376 {SCAN_NULL, CHAR_NULL},
377 DebuggerListSymbol
378 },
379 {
380 L"LOADSYMBOL",
381 L"[UN]LOADSYMBOL - load/unload the symbol file\n",
382 L"The load symbol command will load the ebc map file. Then it parses the function name and global variable, and the print real name when do the disassembly. (Symbol file name should be XXX.MAP)\n\n",
383 L"LOADSYMBOL <SymbolFile> [a]\n"
384 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n"
385 L" a - Automatically load code files in the same dir\n",
386 L"",
387 {SCAN_NULL, CHAR_NULL},
388 DebuggerLoadSymbol
389 },
390 {
391 L"UNLOADSYMBOL",
392 L"",
393 L"The unload symbol command will unload the ebc map and cod file. After that the name will not be print.\n\n",
394 L"UNLOADSYMBOL <SymbolFile>\n"
395 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",
396 L"",
397 {SCAN_NULL, CHAR_NULL},
398 DebuggerUnloadSymbol
399 },
400 {
401 L"LOADCODE",
402 L"[UN]LOADCODE - load/unload the code file\n",
403 L"The load code command will load the ebc cod file. Then it parses the cod file, and the print source code when do the disassembly. (Code file name should be XXX.COD)\n\n",
404 L"LOADCODE <CodeFile> <SymbolFile>\n"
405 L" CodeFile - The EBC code file (Its name should be XXX.COD)\n"
406 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",
407 L"",
408 {SCAN_NULL, CHAR_NULL},
409 DebuggerLoadCode
410 },
411 {
412 L"UNLOADCODE",
413 L"",
414 L"The unload code command will unload the ebc cod file. After that the source code will not be print.\n\n",
415 L"UNLOADCODE <CodeFile> <SymbolFile>\n"
416 L" CodeFile - The EBC code file (Its name should be XXX.COD)\n"
417 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",
418 L"",
419 {SCAN_NULL, CHAR_NULL},
420 DebuggerUnloadCode
421 },
422 {
423 L"DISPLAYSYMBOL",
424 L"DISPLAYSYMBOL/[F3] - disable/enable the symbol output\n",
425 L"",
426 L"The display symbol command will configure the symbol show or not-show when disassembly.\n\n"
427 L"DISPLAYSYMBOL [on|off]\n"
428 L" (No Argument) - swtich symbol output state to another one\n"
429 L" on - enable symbol output\n"
430 L" off - disable symbol output\n",
431 L"",
432 {SCAN_F3, CHAR_NULL},
433 DebuggerDisplaySymbol
434 },
435 {
436 L"DISPLAYCODE",
437 L"DISPLAYCODE/[F6] - disable/enable the source code only output\n",
438 L"",
439 L"The display code command will configure the source code only show or misc source code with assembly.\n\n"
440 L"DISPLAYCODE [on|off]\n"
441 L" (No Argument) - swtich source only output state to another one\n"
442 L" on - enable source only output\n"
443 L" off - disable source only output\n",
444 L"",
445 {SCAN_F6, CHAR_NULL},
446 DebuggerDisplayCode
447 },
448 //
449 // Other
450 //
451 {
452 L"H",
453 L"",
454 L"The help command will print help information for each command\n\n",
455 L"H [<Command>]\n",
456 L"",
457 {SCAN_F1, CHAR_NULL},
458 DebuggerHelp
459 },
460 /*
461 //
462 // Extended
463 //
464 {
465 L"!IB",
466 L"![I|O][B|W|D] - display/modify IO\n",
467 L"",
468 L"!IB <Address>\n",
469 L"Extended:\n",
470 {SCAN_NULL, CHAR_NULL},
471 DebuggerExtIoIB
472 },
473 {
474 L"!IW",
475 L"",
476 L"",
477 L"!IW <Address>\n",
478 L"",
479 {SCAN_NULL, CHAR_NULL},
480 DebuggerExtIoIW
481 },
482 {
483 L"!ID",
484 L"",
485 L"",
486 L"!ID <Address>\n",
487 L"",
488 {SCAN_NULL, CHAR_NULL},
489 DebuggerExtIoID
490 },
491 {
492 L"!OB",
493 L"",
494 L"",
495 L"!OB <Address> <Value>\n",
496 L"",
497 {SCAN_NULL, CHAR_NULL},
498 DebuggerExtIoOB
499 },
500 {
501 L"!OW",
502 L"",
503 L"",
504 L"!OW <Address> <Value>\n",
505 L"",
506 {SCAN_NULL, CHAR_NULL},
507 DebuggerExtIoOW
508 },
509 {
510 L"!OD",
511 L"",
512 L"",
513 L"!OD <Address> <Value>\n",
514 L"",
515 {SCAN_NULL, CHAR_NULL},
516 DebuggerExtIoOD
517 },
518 {
519 L"!PCIL",
520 L"!PCIL - list PCI device, with BAR\n",
521 L"",
522 L"!PCIL [B]\n",
523 L"",
524 {SCAN_NULL, CHAR_NULL},
525 DebuggerExtPciPCIL
526 },
527 {
528 L"!PCID",
529 L"!PCID - show PCI space\n",
530 L"",
531 L"!PCID Bus Device Function [H|B|E]\n",
532 L"",
533 {SCAN_NULL, CHAR_NULL},
534 DebuggerExtPciPCID
535 },
536 {
537 L"!CFGB",
538 L"!CFG[B|W|D] - show/modify PCI space",
539 L"",
540 L"!CFGB <Address> [<Value>]\n",
541 L"",
542 {SCAN_NULL, CHAR_NULL},
543 DebuggerExtPciCFGB
544 },
545 {
546 L"!CFGW",
547 L"",
548 L"",
549 L"!CFGW <Address> [<Value>]\n",
550 L"",
551 {SCAN_NULL, CHAR_NULL},
552 DebuggerExtPciCFGW
553 },
554 {
555 L"!CFGD",
556 L"",
557 L"",
558 L"!CFGD <Address> [<Value>]\n",
559 L"",
560 {SCAN_NULL, CHAR_NULL},
561 DebuggerExtPciCFGD
562 },
563 */
564 {
565 NULL,
566 NULL,
567 NULL,
568 NULL,
569 NULL,
570 {SCAN_NULL, CHAR_NULL},
571 NULL
572 },
573 };
574
575 /**
576
577 Find the command according to name.
578
579 @param CommandName - Command Name
580 @param CommandArg - Command Argument
581
582 @return Not NULL - The DebuggerCommand is found successfully
583 @return NULL - not found
584
585 **/
586 EFI_DEBUGGER_COMMAND
587 MatchDebuggerCommand (
588 IN CHAR16 *CommandName,
589 IN CHAR16 **CommandArg
590 )
591 {
592 UINTN Index;
593 CHAR16 *Temp;
594
595 //
596 // Get Command Name
597 //
598 Temp = StrGetNewTokenLine (CommandName, L" ");
599 CommandName = Temp;
600 //
601 // Get Command Argument
602 //
603 Temp = StrGetNextTokenLine (L" ");
604 *CommandArg = Temp;
605
606 if (CommandName == NULL) {
607 return NULL;
608 }
609
610 //
611 // Go through each command, check the CommandName
612 //
613 for (Index = 0; mDebuggerCommandSet[Index].CommandName != NULL; Index++) {
614 if (StriCmp (CommandName, mDebuggerCommandSet[Index].CommandName) == 0) {
615 //
616 // Found
617 //
618 return mDebuggerCommandSet[Index].CommandFunc;
619 }
620 }
621
622 //
623 // Not found
624 //
625 return NULL;
626 }
627
628 /**
629
630 Find the command name according to the function key.
631
632 @param CommandKey - Command Function Key
633
634 @return Not NULL - The DebuggerName is found successfully
635 @return NULL - not found
636
637 **/
638 CHAR16 *
639 GetCommandNameByKey (
640 IN EFI_INPUT_KEY CommandKey
641 )
642 {
643 UINTN Index;
644
645 //
646 // Go through each command, check the CommandKey
647 //
648 for (Index = 0; mDebuggerCommandSet[Index].CommandName != NULL; Index++) {
649 if ((mDebuggerCommandSet[Index].CommandKey.UnicodeChar == CommandKey.UnicodeChar) &&
650 (mDebuggerCommandSet[Index].CommandKey.ScanCode == CommandKey.ScanCode)) {
651 //
652 // Found
653 //
654 return mDebuggerCommandSet[Index].CommandName;
655 }
656 }
657
658 //
659 // Not found
660 //
661 return NULL;
662 }