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