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