Changeset 41575 in vbox
- Timestamp:
- Jun 5, 2012 11:48:40 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGCCommands.cpp
r41573 r41575 414 414 415 415 416 417 418 416 /** 419 417 * Prints full command help. 420 418 */ 421 static int dbgcPrintHelp (PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, bool fExternal)419 static int dbgcPrintHelpCmd(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, bool fExternal) 422 420 { 423 421 int rc; … … 466 464 467 465 466 static int dbgcCmdHelpCommandsWorker(PDBGC pDbgc, PDBGCCMDHLP pCmdHlp, PCDBGCCMD paCmds, size_t cCmds, bool fExternal, 467 const char *pszDescFmt, ...) 468 { 469 int rc = VINF_SUCCESS; 470 if (pszDescFmt) 471 { 472 va_list va; 473 va_start(va, pszDescFmt); 474 rc = pCmdHlp->pfnPrintfV(pCmdHlp, NULL, pszDescFmt, va); 475 va_end(va); 476 } 477 478 for (unsigned i = 0; i < cCmds && RT_SUCCESS(rc); i++) 479 rc = DBGCCmdHlpPrintf(pCmdHlp, 480 !fExternal ? "%-11s %-30s %s\n" : ".%-10s %-30s %s\n", 481 paCmds[i].pszCmd, 482 paCmds[i].pszSyntax, 483 paCmds[i].pszDescription); 484 return VINF_SUCCESS; 485 } 486 487 488 static int dbgcCmdHelpCommands(PDBGC pDbgc, PDBGCCMDHLP pCmdHlp) 489 { 490 int rc = dbgcCmdHelpCommandsWorker(pDbgc, pCmdHlp, pDbgc->paEmulationCmds, pDbgc->cEmulationCmds, false, 491 "Commands for %s emulation:\n", pDbgc->pszEmulation); 492 if (RT_SUCCESS(rc)) 493 rc = dbgcCmdHelpCommandsWorker(pDbgc, pCmdHlp, g_aDbgcCmds, RT_ELEMENTS(g_aDbgcCmds), false, 494 "\nCommon Commands:\n"); 495 496 if (RT_SUCCESS(rc)) 497 { 498 DBGCEXTLISTS_LOCK_RD(); 499 const char *pszDesc = "\nExternal Commands:\n"; 500 for (PDBGCEXTCMDS pExtCmd = g_pExtCmdsHead; pExtCmd && RT_SUCCESS(rc); pExtCmd = pExtCmd->pNext) 501 { 502 rc = dbgcCmdHelpCommandsWorker(pDbgc, pCmdHlp, pExtCmd->paCmds, pExtCmd->cCmds, false, 503 pszDesc); 504 pszDesc = NULL; 505 } 506 DBGCEXTLISTS_UNLOCK_RD(); 507 } 508 509 return rc; 510 } 511 512 513 /** 514 * Prints full function help. 515 */ 516 static int dbgcPrintHelpFunction(PDBGCCMDHLP pCmdHlp, PCDBGCFUNC pFunc, bool fExternal) 517 { 518 int rc; 519 520 /* the command */ 521 rc = DBGCCmdHlpPrintf(pCmdHlp, "%s%-*s %-30s %s", 522 fExternal ? "." : "", 523 fExternal ? 10 : 11, 524 pFunc->pszFuncNm, 525 pFunc->pszSyntax, 526 pFunc->pszDescription); 527 if (!pFunc->cArgsMin && pFunc->cArgsMin == pFunc->cArgsMax) 528 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <no args>\n"); 529 else if (pFunc->cArgsMin == pFunc->cArgsMax) 530 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u args>\n", pFunc->cArgsMin); 531 else if (pFunc->cArgsMax == ~0U) 532 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u+ args>\n", pFunc->cArgsMin); 533 else 534 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u to %u args>\n", pFunc->cArgsMin, pFunc->cArgsMax); 535 536 /* argument descriptions. */ 537 for (unsigned i = 0; i < pFunc->cArgDescs; i++) 538 { 539 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 540 " %-12s %s", 541 pFunc->paArgDescs[i].pszName, 542 pFunc->paArgDescs[i].pszDescription); 543 if (!pFunc->paArgDescs[i].cTimesMin) 544 { 545 if (pFunc->paArgDescs[i].cTimesMax == ~0U) 546 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <optional+>\n"); 547 else 548 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <optional-%u>\n", pFunc->paArgDescs[i].cTimesMax); 549 } 550 else 551 { 552 if (pFunc->paArgDescs[i].cTimesMax == ~0U) 553 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u+>\n", pFunc->paArgDescs[i].cTimesMin); 554 else 555 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u-%u>\n", pFunc->paArgDescs[i].cTimesMin, pFunc->paArgDescs[i].cTimesMax); 556 } 557 } 558 return rc; 559 } 560 561 562 static int dbgcCmdHelpFunctionsWorker(PDBGC pDbgc, PDBGCCMDHLP pCmdHlp, PCDBGCFUNC paFuncs, size_t cFuncs, bool fExternal, 563 const char *pszDescFmt, ...) 564 { 565 int rc = VINF_SUCCESS; 566 if (pszDescFmt) 567 { 568 va_list va; 569 va_start(va, pszDescFmt); 570 rc = DBGCCmdHlpPrintf(pCmdHlp, pszDescFmt, va); 571 va_end(va); 572 } 573 574 for (unsigned i = 0; i < cFuncs && RT_SUCCESS(rc); i++) 575 rc = DBGCCmdHlpPrintf(pCmdHlp, 576 !fExternal ? "%-11s %-30s %s\n" : ".%-10s %-30s %s\n", 577 paFuncs[i].pszFuncNm, 578 paFuncs[i].pszSyntax, 579 paFuncs[i].pszDescription); 580 return VINF_SUCCESS; 581 } 582 583 584 static int dbgcCmdHelpFunctions(PDBGC pDbgc, PDBGCCMDHLP pCmdHlp) 585 { 586 int rc = dbgcCmdHelpFunctionsWorker(pDbgc, pCmdHlp, pDbgc->paEmulationFuncs, pDbgc->cEmulationFuncs, false, 587 "Functions for %s emulation:\n", pDbgc->pszEmulation); 588 if (RT_SUCCESS(rc)) 589 rc = dbgcCmdHelpFunctionsWorker(pDbgc, pCmdHlp, g_aDbgcFuncs, g_cDbgcFuncs, false, 590 "\nCommon Functions:\n"); 591 #if 0 592 if (RT_SUCCESS(rc)) 593 { 594 DBGCEXTLISTS_LOCK_RD(); 595 const char *pszDesc = "\nExternal Functions:\n"; 596 for (PDBGCEXTFUNCS pExtFunc = g_pExtFuncsHead; pExtFunc && RT_SUCCESS(rc); pExtFunc = pExtFunc->pNext) 597 { 598 rc = dbgcCmdHelpFunctionsWorker(pDbgc, pCmdHlp, pExtFunc->paFuncs, pExtFunc->cFuncs, false, 599 pszDesc); 600 pszDesc = NULL; 601 } 602 DBGCEXTLISTS_UNLOCK_RD(); 603 } 604 #endif 605 return rc; 606 } 607 608 609 static int dbgcCmdHelpOperators(PDBGC pDbgc, PDBGCCMDHLP pCmdHlp) 610 { 611 int rc = DBGCCmdHlpPrintf(pCmdHlp, "Operators:\n"); 612 613 unsigned iPrecedence = 0; 614 unsigned cLeft = g_cDbgcOps; 615 while (cLeft > 0) 616 { 617 for (unsigned i = 0; i < g_cDbgcOps; i++) 618 if (g_aDbgcOps[i].iPrecedence == iPrecedence) 619 { 620 rc = DBGCCmdHlpPrintf(pCmdHlp, 621 "%-10s %s %s\n", 622 g_aDbgcOps[i].szName, 623 g_aDbgcOps[i].fBinary ? "Binary" : "Unary ", 624 g_aDbgcOps[i].pszDescription); 625 cLeft--; 626 } 627 iPrecedence++; 628 } 629 return rc; 630 } 631 632 468 633 /** 469 634 * The 'help' command. … … 480 645 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp); 481 646 int rc = VINF_SUCCESS; 482 unsigned i; 483 484 /** @todo rewrite this. */ 647 485 648 if (!cArgs) 486 649 { 487 650 /* 488 * All the stuff.651 * No arguments, show summary. 489 652 */ 490 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 491 "VirtualBox Debugger\n" 492 "-------------------\n" 493 "\n" 494 "Commands:\n"); 495 for (i = 0; i < RT_ELEMENTS(g_aDbgcCmds); i++) 496 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 497 "%-11s %-30s %s\n", 498 g_aDbgcCmds[i].pszCmd, 499 g_aDbgcCmds[i].pszSyntax, 500 g_aDbgcCmds[i].pszDescription); 501 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 502 "\n" 503 "Emulation: %s\n", pDbgc->pszEmulation); 504 PCDBGCCMD pCmd2 = pDbgc->paEmulationCmds; 505 for (i = 0; i < pDbgc->cEmulationCmds; i++, pCmd2++) 506 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 507 "%-11s %-30s %s\n", 508 pCmd2->pszCmd, 509 pCmd2->pszSyntax, 510 pCmd2->pszDescription); 511 512 if (g_pExtCmdsHead) 513 { 514 DBGCEXTLISTS_LOCK_RD(); 515 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 516 "\n" 517 "External Commands:\n"); 518 for (PDBGCEXTCMDS pExtCmd = g_pExtCmdsHead; pExtCmd; pExtCmd = pExtCmd->pNext) 519 for (i = 0; i < pExtCmd->cCmds; i++) 520 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 521 ".%-10s %-30s %s\n", 522 pExtCmd->paCmds[i].pszCmd, 523 pExtCmd->paCmds[i].pszSyntax, 524 pExtCmd->paCmds[i].pszDescription); 525 DBGCEXTLISTS_UNLOCK_RD(); 526 } 527 528 529 530 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 531 "\n" 532 "Operators:\n"); 533 unsigned iPrecedence = 0; 534 unsigned cLeft = g_cDbgcOps; 535 while (cLeft > 0) 536 { 537 for (i = 0; i < g_cDbgcOps; i++) 538 if (g_aDbgcOps[i].iPrecedence == iPrecedence) 539 { 540 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 541 "%-10s %s %s\n", 542 g_aDbgcOps[i].szName, 543 g_aDbgcOps[i].fBinary ? "Binary" : "Unary ", 544 g_aDbgcOps[i].pszDescription); 545 cLeft--; 546 } 547 iPrecedence++; 548 } 653 rc = DBGCCmdHlpPrintf(pCmdHlp, 654 "VirtualBox Debugger Help Summary\n" 655 "--------------------------------\n" 656 "\n" 657 "help commands Show help on all commands.\n" 658 "help functions Show help on all functions.\n" 659 "help operators Show help on all operators.\n" 660 "help <cmd-pattern> [...]\n" 661 " Show details help on individual commands, simple\n" 662 " patterns can be used to match several commands.\n" 663 ); 664 549 665 } 550 666 else … … 553 669 * Search for the arguments (strings). 554 670 */ 555 for (unsigned iArg = 0; iArg < cArgs; iArg++) 671 DBGCEXTCMDS aFixedCmds[] = 672 { 673 { pDbgc->cEmulationCmds, pDbgc->paEmulationCmds, NULL }, 674 { g_cDbgcCmds, g_aDbgcCmds, NULL }, 675 }; 676 DBGCEXTFUNCS aFixedFuncs[] = 677 { 678 { pDbgc->cEmulationFuncs, pDbgc->paEmulationFuncs, NULL }, 679 { g_cDbgcFuncs, g_aDbgcFuncs, NULL }, 680 }; 681 682 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++) 556 683 { 557 684 AssertReturn(paArgs[iArg].enmType == DBGCVAR_TYPE_STRING, VERR_DBGC_PARSE_BUG); 558 685 const char *pszPattern = paArgs[iArg].u.pszString; 559 bool fFound = false; 560 561 /* lookup in the emulation command list first */ 562 for (i = 0; i < pDbgc->cEmulationCmds; i++) 563 if (RTStrSimplePatternMatch(pszPattern, pDbgc->paEmulationCmds[i].pszCmd)) 564 { 565 rc = dbgcPrintHelp(pCmdHlp, &pDbgc->paEmulationCmds[i], false); 566 fFound = true; 567 } 568 569 /* lookup in the command list (even when found in the emulation) */ 570 for (i = 0; i < RT_ELEMENTS(g_aDbgcCmds); i++) 571 if (RTStrSimplePatternMatch(pszPattern, g_aDbgcCmds[i].pszCmd)) 572 { 573 rc = dbgcPrintHelp(pCmdHlp, &g_aDbgcCmds[i], false); 574 fFound = true; 575 } 576 577 /* external commands */ 578 if ( !fFound 579 && g_pExtCmdsHead 580 && ( *pszPattern == '.' 581 || *pszPattern == '?' 582 || *pszPattern == '*')) 583 { 584 DBGCEXTLISTS_LOCK_RD(); 585 const char *pszPattern2 = pszPattern + (*pszPattern == '.' || *pszPattern == '?'); 586 for (PDBGCEXTCMDS pExtCmd = g_pExtCmdsHead; pExtCmd; pExtCmd = pExtCmd->pNext) 587 for (i = 0; i < pExtCmd->cCmds; i++) 588 if (RTStrSimplePatternMatch(pszPattern2, pExtCmd->paCmds[i].pszCmd)) 686 687 /* aliases */ 688 if (!strcmp(pszPattern, "commands")) 689 rc = dbgcCmdHelpCommands(pDbgc, pCmdHlp); 690 else if (!strcmp(pszPattern, "functions")) 691 rc = dbgcCmdHelpFunctions(pDbgc, pCmdHlp); 692 else if (!strcmp(pszPattern, "operators")) 693 rc = dbgcCmdHelpOperators(pDbgc, pCmdHlp); 694 else if (!strcmp(pszPattern, "all")) 695 { 696 rc = dbgcCmdHelpFunctions(pDbgc, pCmdHlp); 697 rc = DBGCCmdHlpPrintf(pCmdHlp, 698 "VirtualBox Debugger Help\n" 699 "------------------------\n" 700 "\n"); 701 rc = dbgcCmdHelpCommands(pDbgc, pCmdHlp); 702 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n"); 703 rc = dbgcCmdHelpFunctions(pDbgc, pCmdHlp); 704 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n"); 705 rc = dbgcCmdHelpOperators(pDbgc, pCmdHlp); 706 } 707 else 708 { 709 /* Individual commands. */ 710 bool fFound = false; 711 712 /* lookup in the emulation command list first */ 713 for (unsigned j = 0; j < RT_ELEMENTS(aFixedCmds); j++) 714 for (unsigned i = 0; i < aFixedCmds[j].cCmds; i++) 715 if (RTStrSimplePatternMatch(pszPattern, aFixedCmds[j].paCmds[i].pszCmd)) 716 { 717 rc = dbgcPrintHelpCmd(pCmdHlp, &aFixedCmds[j].paCmds[i], false); 718 fFound = true; 719 } 720 for (unsigned j = 0; j < RT_ELEMENTS(aFixedFuncs); j++) 721 for (unsigned i = 0; i < aFixedFuncs[j].cFuncs; i++) 722 if (RTStrSimplePatternMatch(pszPattern, aFixedFuncs[j].paFuncs[i].pszFuncNm)) 723 { 724 rc = dbgcPrintHelpFunction(pCmdHlp, &aFixedFuncs[j].paFuncs[i], false); 725 fFound = true; 726 } 727 728 /* external commands */ 729 if ( g_pExtCmdsHead 730 && ( *pszPattern == '.' 731 || *pszPattern == '?' 732 || *pszPattern == '*')) 733 { 734 DBGCEXTLISTS_LOCK_RD(); 735 const char *pszPattern2 = pszPattern + (*pszPattern == '.' || *pszPattern == '?'); 736 for (PDBGCEXTCMDS pExtCmd = g_pExtCmdsHead; pExtCmd; pExtCmd = pExtCmd->pNext) 737 for (unsigned i = 0; i < pExtCmd->cCmds; i++) 738 if (RTStrSimplePatternMatch(pszPattern2, pExtCmd->paCmds[i].pszCmd)) 739 { 740 rc = dbgcPrintHelpCmd(pCmdHlp, &pExtCmd->paCmds[i], true); 741 fFound = true; 742 } 743 #if 0 744 for (PDBGCEXTFUNCS pExtFunc = g_pExtFuncsHead; pExtFunc; pExtFunc = pExtFunc->pNext) 745 for (unsigned i = 0; i < pExtFunc->cFuncs; i++) 746 if (RTStrSimplePatternMatch(pszPattern2, pExtFunc->paFuncs[i].pszFuncNm)) 747 { 748 rc = dbgcPrintHelpFunction(pCmdHlp, &pExtFunc->paFuncs[i], true); 749 fFound = true; 750 } 751 #endif 752 DBGCEXTLISTS_UNLOCK_RD(); 753 } 754 755 /* operators */ 756 if (!fFound && strlen(paArgs[iArg].u.pszString) < sizeof(g_aDbgcOps[0].szName)) 757 for (unsigned i = 0; i < g_cDbgcOps && RT_SUCCESS(rc); i++) 758 if (RTStrSimplePatternMatch(pszPattern, g_aDbgcOps[i].szName)) 589 759 { 590 rc = dbgcPrintHelp(pCmdHlp, &pExtCmd->paCmds[i], true); 760 rc = DBGCCmdHlpPrintf(pCmdHlp, "%-10s %s %s\n", 761 g_aDbgcOps[i].szName, 762 g_aDbgcOps[i].fBinary ? "Binary" : "Unary ", 763 g_aDbgcOps[i].pszDescription); 591 764 fFound = true; 592 765 } 593 DBGCEXTLISTS_UNLOCK_RD(); 594 } 595 596 /* operators */ 597 if (!fFound && strlen(paArgs[iArg].u.pszString) < sizeof(g_aDbgcOps[i].szName)) 598 { 599 for (i = 0; i < g_cDbgcOps; i++) 600 if (RTStrSimplePatternMatch(pszPattern, g_aDbgcOps[i].szName)) 601 { 602 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 603 "%-10s %s %s\n", 604 g_aDbgcOps[i].szName, 605 g_aDbgcOps[i].fBinary ? "Binary" : "Unary ", 606 g_aDbgcOps[i].pszDescription); 607 fFound = true; 608 } 609 } 610 611 /* found? */ 612 if (!fFound) 613 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, 614 "error: '%s' was not found!\n", 615 paArgs[iArg].u.pszString); 766 767 /* found? */ 768 if (!fFound) 769 rc = DBGCCmdHlpPrintf(pCmdHlp, "error: '%s' was not found!\n", 770 paArgs[iArg].u.pszString); 771 } 616 772 } /* foreach argument */ 617 773 }
Note:
See TracChangeset
for help on using the changeset viewer.