- Timestamp:
- Aug 24, 2010 1:50:41 PM (14 years ago)
- Location:
- trunk/src/VBox/Debugger
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGCOps.cpp
r31530 r31926 70 70 static DECLCALLBACK(int) dbgcOpRangeLengthBytes(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult); 71 71 static DECLCALLBACK(int) dbgcOpRangeTo(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult); 72 73 74 /******************************************************************************* 75 * Defined Constants And Macros * 76 *******************************************************************************/ 77 /** 78 * Generic implementation of a binary operator. 79 * 80 * @returns VINF_SUCCESS on success. 81 * @returns VBox evaluation / parsing error code on failure. 82 * The caller does the bitching. 83 * @param pDbgc Debugger console instance data. 84 * @param pArg1 The first argument. 85 * @param pArg2 The 2nd argument. 86 * @param pResult Where to store the result. 87 * @param Operator The C operator. 88 * @param fIsDiv Set if it's division and we need to check for zero on the 89 * right hand side. 90 */ 91 #define DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, Operator, fIsDiv) \ 92 do \ 93 { \ 94 /* Get the 64-bit right side value. */ \ 95 uint64_t u64Right; \ 96 int rc = dbgcOpHelperGetNumber(pDbgc, pArg2, &u64Right); \ 97 if (fIsDiv && RT_SUCCESS(rc) && !u64Right) /* div/0 kludge */ \ 98 DBGCVAR_INIT_NUMBER(pResult, UINT64_MAX); \ 99 else if (RT_SUCCESS(rc)) \ 100 { \ 101 /* Apply it to the left hand side. */ \ 102 if ( pArg1->enmType == DBGCVAR_TYPE_SYMBOL \ 103 || pArg1->enmType == DBGCVAR_TYPE_STRING) \ 104 { \ 105 rc = dbgcSymbolGet(pDbgc, pArg1->u.pszString, DBGCVAR_TYPE_ANY, pResult); \ 106 if (RT_FAILURE(rc)) \ 107 return rc; \ 108 } \ 109 else \ 110 *pResult = *pArg1; \ 111 switch (pResult->enmType) \ 112 { \ 113 case DBGCVAR_TYPE_GC_FLAT: \ 114 pResult->u.GCFlat = pResult->u.GCFlat Operator u64Right; \ 115 break; \ 116 case DBGCVAR_TYPE_GC_FAR: \ 117 pResult->u.GCFar.off = pResult->u.GCFar.off Operator u64Right; \ 118 break; \ 119 case DBGCVAR_TYPE_GC_PHYS: \ 120 pResult->u.GCPhys = pResult->u.GCPhys Operator u64Right; \ 121 break; \ 122 case DBGCVAR_TYPE_HC_FLAT: \ 123 pResult->u.pvHCFlat = (void *)((uintptr_t)pResult->u.pvHCFlat Operator u64Right); \ 124 break; \ 125 case DBGCVAR_TYPE_HC_FAR: \ 126 pResult->u.HCFar.off = pResult->u.HCFar.off Operator u64Right; \ 127 break; \ 128 case DBGCVAR_TYPE_HC_PHYS: \ 129 pResult->u.HCPhys = pResult->u.HCPhys Operator u64Right; \ 130 break; \ 131 case DBGCVAR_TYPE_NUMBER: \ 132 pResult->u.u64Number = pResult->u.u64Number Operator u64Right; \ 133 break; \ 134 default: \ 135 return VERR_PARSE_INCORRECT_ARG_TYPE; \ 136 } \ 137 } \ 138 return rc; \ 139 } while (0) 72 140 73 141 … … 112 180 113 181 /** 182 * Convers an argument to a number value. 183 * 184 * @returns VBox status code. 185 * @param pDbgc The DBGC instance. 186 * @param pArg The argument to convert. 187 * @param pu64Ret Where to return the value. 188 */ 189 static int dbgcOpHelperGetNumber(PDBGC pDbgc, PCDBGCVAR pArg, uint64_t *pu64Ret) 190 { 191 DBGCVAR Var = *pArg; 192 switch (Var.enmType) 193 { 194 case DBGCVAR_TYPE_GC_FLAT: 195 *pu64Ret = Var.u.GCFlat; 196 break; 197 case DBGCVAR_TYPE_GC_FAR: 198 *pu64Ret = Var.u.GCFar.off; 199 break; 200 case DBGCVAR_TYPE_GC_PHYS: 201 *pu64Ret = Var.u.GCPhys; 202 break; 203 case DBGCVAR_TYPE_HC_FLAT: 204 *pu64Ret = (uintptr_t)Var.u.pvHCFlat; 205 break; 206 case DBGCVAR_TYPE_HC_FAR: 207 *pu64Ret = Var.u.HCFar.off; 208 break; 209 case DBGCVAR_TYPE_HC_PHYS: 210 *pu64Ret = Var.u.HCPhys; 211 break; 212 case DBGCVAR_TYPE_STRING: 213 case DBGCVAR_TYPE_SYMBOL: 214 { 215 int rc = dbgcSymbolGet(pDbgc, Var.u.pszString, DBGCVAR_TYPE_NUMBER, &Var); 216 if (RT_FAILURE(rc)) 217 return rc; 218 /* fall thru */ 219 } 220 case DBGCVAR_TYPE_NUMBER: 221 *pu64Ret = Var.u.u64Number; 222 break; 223 default: 224 return VERR_PARSE_INCORRECT_ARG_TYPE; 225 } 226 return VINF_SUCCESS; 227 } 228 229 230 /** 114 231 * Minus (unary). 115 232 * 116 * @returns 0on success.233 * @returns VINF_SUCCESS on success. 117 234 * @returns VBox evaluation / parsing error code on failure. 118 235 * The caller does the bitching. … … 123 240 static DECLCALLBACK(int) dbgcOpMinus(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 124 241 { 125 //LogFlow(("dbgcOpMinus\n"));242 LogFlow(("dbgcOpMinus\n")); 126 243 *pResult = *pArg; 127 244 switch (pArg->enmType) … … 155 272 } 156 273 NOREF(pDbgc); 157 return 0;274 return VINF_SUCCESS; 158 275 } 159 276 … … 162 279 * Pluss (unary). 163 280 * 164 * @returns 0on success.281 * @returns VINF_SUCCESS on success. 165 282 * @returns VBox evaluation / parsing error code on failure. 166 283 * The caller does the bitching. … … 171 288 static DECLCALLBACK(int) dbgcOpPluss(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 172 289 { 173 //LogFlow(("dbgcOpPluss\n"));290 LogFlow(("dbgcOpPluss\n")); 174 291 *pResult = *pArg; 175 292 switch (pArg->enmType) … … 190 307 } 191 308 NOREF(pDbgc); 192 return 0;309 return VINF_SUCCESS; 193 310 } 194 311 … … 197 314 * Boolean not (unary). 198 315 * 199 * @returns 0on success.316 * @returns VINF_SUCCESS on success. 200 317 * @returns VBox evaluation / parsing error code on failure. 201 318 * The caller does the bitching. … … 206 323 static DECLCALLBACK(int) dbgcOpBooleanNot(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 207 324 { 208 //LogFlow(("dbgcOpBooleanNot\n"));325 LogFlow(("dbgcOpBooleanNot\n")); 209 326 *pResult = *pArg; 210 327 switch (pArg->enmType) … … 241 358 pResult->enmType = DBGCVAR_TYPE_NUMBER; 242 359 NOREF(pDbgc); 243 return 0;360 return VINF_SUCCESS; 244 361 } 245 362 … … 248 365 * Bitwise not (unary). 249 366 * 250 * @returns 0on success.367 * @returns VINF_SUCCESS on success. 251 368 * @returns VBox evaluation / parsing error code on failure. 252 369 * The caller does the bitching. … … 257 374 static DECLCALLBACK(int) dbgcOpBitwiseNot(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 258 375 { 259 //LogFlow(("dbgcOpBitwiseNot\n"));376 LogFlow(("dbgcOpBitwiseNot\n")); 260 377 *pResult = *pArg; 261 378 switch (pArg->enmType) … … 289 406 } 290 407 NOREF(pDbgc); 291 return 0;408 return VINF_SUCCESS; 292 409 } 293 410 … … 296 413 * Reference variable (unary). 297 414 * 298 * @returns 0on success.415 * @returns VINF_SUCCESS on success. 299 416 * @returns VBox evaluation / parsing error code on failure. 300 417 * The caller does the bitching. … … 305 422 static DECLCALLBACK(int) dbgcOpVar(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 306 423 { 307 // LogFlow(("dbgcOpVar: %s\n", pArg->u.pszString)); 424 LogFlow(("dbgcOpVar: %s\n", pArg->u.pszString)); 425 308 426 /* 309 427 * Parse sanity. … … 321 439 { 322 440 *pResult = pDbgc->papVars[iVar]->Var; 323 return 0;441 return VINF_SUCCESS; 324 442 } 325 443 } … … 341 459 DECLCALLBACK(int) dbgcOpAddrFlat(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 342 460 { 343 //LogFlow(("dbgcOpAddrFlat\n"));461 LogFlow(("dbgcOpAddrFlat\n")); 344 462 int rc; 345 463 *pResult = *pArg; … … 400 518 * Physical address (unary). 401 519 * 402 * @returns 0on success.520 * @returns VINF_SUCCESS on success. 403 521 * @returns VBox evaluation / parsing error code on failure. 404 522 * The caller does the bitching. … … 409 527 DECLCALLBACK(int) dbgcOpAddrPhys(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 410 528 { 411 //LogFlow(("dbgcOpAddrPhys\n"));529 LogFlow(("dbgcOpAddrPhys\n")); 412 530 int rc; 413 531 DBGFADDRESS Address; … … 423 541 &pResult->u.GCPhys); 424 542 if (RT_SUCCESS(rc)) 425 return 0;543 return VINF_SUCCESS; 426 544 return VERR_PARSE_CONVERSION_FAILED; 427 545 … … 434 552 rc = DBGFR3AddrToPhys(pDbgc->pVM, pDbgc->idCpu, &Address, &pResult->u.GCPhys); 435 553 if (RT_SUCCESS(rc)) 436 return 0;554 return VINF_SUCCESS; 437 555 } 438 556 return VERR_PARSE_CONVERSION_FAILED; 439 557 440 558 case DBGCVAR_TYPE_GC_PHYS: 441 return 0;559 return VINF_SUCCESS; 442 560 443 561 case DBGCVAR_TYPE_HC_FLAT: … … 446 564 rc = PGMR3DbgR3Ptr2GCPhys(pDbgc->pVM, pArg->u.pvHCFlat, &pResult->u.GCPhys); 447 565 if (RT_SUCCESS(rc)) 448 return 0;566 return VINF_SUCCESS; 449 567 /** @todo more memory types! */ 450 568 return VERR_PARSE_CONVERSION_FAILED; … … 454 572 455 573 case DBGCVAR_TYPE_HC_PHYS: 456 return 0;574 return VINF_SUCCESS; 457 575 458 576 case DBGCVAR_TYPE_NUMBER: 459 577 pResult->enmType = DBGCVAR_TYPE_GC_PHYS; 460 578 pResult->u.GCPhys = (RTGCPHYS)pResult->u.u64Number; 461 return 0;579 return VINF_SUCCESS; 462 580 463 581 case DBGCVAR_TYPE_STRING: … … 468 586 return VERR_PARSE_INCORRECT_ARG_TYPE; 469 587 } 470 return 0;588 return VINF_SUCCESS; 471 589 } 472 590 … … 475 593 * Physical host address (unary). 476 594 * 477 * @returns 0on success.595 * @returns VINF_SUCCESS on success. 478 596 * @returns VBox evaluation / parsing error code on failure. 479 597 * The caller does the bitching. … … 484 602 DECLCALLBACK(int) dbgcOpAddrHostPhys(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 485 603 { 486 //LogFlow(("dbgcOpAddrPhys\n"));604 LogFlow(("dbgcOpAddrPhys\n")); 487 605 DBGFADDRESS Address; 488 606 int rc; … … 498 616 &pResult->u.GCPhys); 499 617 if (RT_SUCCESS(rc)) 500 return 0;618 return VINF_SUCCESS; 501 619 return VERR_PARSE_CONVERSION_FAILED; 502 620 … … 510 628 rc = DBGFR3AddrToHostPhys(pDbgc->pVM, pDbgc->idCpu, &Address, &pResult->u.GCPhys); 511 629 if (RT_SUCCESS(rc)) 512 return 0;630 return VINF_SUCCESS; 513 631 } 514 632 return VERR_PARSE_CONVERSION_FAILED; … … 522 640 &pResult->u.GCPhys); 523 641 if (RT_SUCCESS(rc)) 524 return 0;642 return VINF_SUCCESS; 525 643 return VERR_PARSE_CONVERSION_FAILED; 526 644 … … 530 648 rc = PGMR3DbgR3Ptr2HCPhys(pDbgc->pVM, pArg->u.pvHCFlat, &pResult->u.HCPhys); 531 649 if (RT_SUCCESS(rc)) 532 return 0;650 return VINF_SUCCESS; 533 651 /** @todo more memory types! */ 534 652 return VERR_PARSE_CONVERSION_FAILED; … … 538 656 539 657 case DBGCVAR_TYPE_HC_PHYS: 540 return 0;658 return VINF_SUCCESS; 541 659 542 660 case DBGCVAR_TYPE_NUMBER: 543 661 pResult->enmType = DBGCVAR_TYPE_HC_PHYS; 544 662 pResult->u.HCPhys = (RTGCPHYS)pResult->u.u64Number; 545 return 0;663 return VINF_SUCCESS; 546 664 547 665 case DBGCVAR_TYPE_STRING: … … 552 670 return VERR_PARSE_INCORRECT_ARG_TYPE; 553 671 } 554 return 0;672 return VINF_SUCCESS; 555 673 } 556 674 … … 559 677 * Host address (unary). 560 678 * 561 * @returns 0on success.679 * @returns VINF_SUCCESS on success. 562 680 * @returns VBox evaluation / parsing error code on failure. 563 681 * The caller does the bitching. … … 568 686 DECLCALLBACK(int) dbgcOpAddrHost(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult) 569 687 { 570 Log 6(("dbgcOpAddrHost\n"));688 LogFlow(("dbgcOpAddrHost\n")); 571 689 int rc; 572 690 DBGFADDRESS Address; … … 583 701 &pResult->u.pvHCFlat); 584 702 if (RT_SUCCESS(rc)) 585 return 0;703 return VINF_SUCCESS; 586 704 return VERR_PARSE_CONVERSION_FAILED; 587 705 … … 595 713 false /*fReadOnly*/, &pResult->u.pvHCFlat); 596 714 if (RT_SUCCESS(rc)) 597 return 0;715 return VINF_SUCCESS; 598 716 } 599 717 return VERR_PARSE_CONVERSION_FAILED; … … 607 725 &pResult->u.pvHCFlat); 608 726 if (RT_SUCCESS(rc)) 609 return 0;727 return VINF_SUCCESS; 610 728 return VERR_PARSE_CONVERSION_FAILED; 611 729 612 730 case DBGCVAR_TYPE_HC_FLAT: 613 return 0;731 return VINF_SUCCESS; 614 732 615 733 case DBGCVAR_TYPE_HC_FAR: … … 621 739 pResult->enmType = DBGCVAR_TYPE_HC_FLAT; 622 740 pResult->u.pvHCFlat = (void *)(uintptr_t)pResult->u.u64Number; 623 return 0;741 return VINF_SUCCESS; 624 742 625 743 case DBGCVAR_TYPE_STRING: … … 636 754 * Bitwise not (unary). 637 755 * 638 * @returns 0on success.756 * @returns VINF_SUCCESS on success. 639 757 * @returns VBox evaluation / parsing error code on failure. 640 758 * The caller does the bitching. … … 645 763 static DECLCALLBACK(int) dbgcOpAddrFar(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult) 646 764 { 647 //LogFlow(("dbgcOpAddrFar\n"));765 LogFlow(("dbgcOpAddrFar\n")); 648 766 int rc; 649 767 … … 708 826 return VERR_PARSE_INCORRECT_ARG_TYPE; 709 827 } 710 return 0;828 return VINF_SUCCESS; 711 829 712 830 } … … 716 834 * Multiplication operator (binary). 717 835 * 718 * @returns 0on success.836 * @returns VINF_SUCCESS on success. 719 837 * @returns VBox evaluation / parsing error code on failure. 720 838 * The caller does the bitching. … … 726 844 static DECLCALLBACK(int) dbgcOpMult(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult) 727 845 { 728 // LogFlow(("dbgcOpMult\n")); 729 int rc; 846 LogFlow(("dbgcOpMult\n")); 730 847 731 848 /* … … 743 860 } 744 861 745 /* 746 * Convert the 2nd number into a number we use multiply the first with. 747 */ 748 DBGCVAR Factor2 = *pArg2; 749 if ( Factor2.enmType == DBGCVAR_TYPE_STRING 750 || Factor2.enmType == DBGCVAR_TYPE_SYMBOL) 751 { 752 rc = dbgcSymbolGet(pDbgc, pArg2->u.pszString, DBGCVAR_TYPE_NUMBER, &Factor2); 753 if (RT_FAILURE(rc)) 754 return rc; 755 } 756 uint64_t u64Factor; 757 switch (Factor2.enmType) 758 { 759 case DBGCVAR_TYPE_GC_FLAT: u64Factor = Factor2.u.GCFlat; break; 760 case DBGCVAR_TYPE_GC_FAR: u64Factor = Factor2.u.GCFar.off; break; 761 case DBGCVAR_TYPE_GC_PHYS: u64Factor = Factor2.u.GCPhys; break; 762 case DBGCVAR_TYPE_HC_FLAT: u64Factor = (uintptr_t)Factor2.u.pvHCFlat; break; 763 case DBGCVAR_TYPE_HC_FAR: u64Factor = Factor2.u.HCFar.off; break; 764 case DBGCVAR_TYPE_HC_PHYS: u64Factor = Factor2.u.HCPhys; break; 765 case DBGCVAR_TYPE_NUMBER: u64Factor = Factor2.u.u64Number; break; 766 default: 767 return VERR_PARSE_INCORRECT_ARG_TYPE; 768 } 769 770 /* 771 * Fix symbols in the 1st factor. 772 */ 773 *pResult = *pArg1; 774 if ( pResult->enmType == DBGCVAR_TYPE_STRING 775 || pResult->enmType == DBGCVAR_TYPE_SYMBOL) 776 { 777 rc = dbgcSymbolGet(pDbgc, pArg1->u.pszString, DBGCVAR_TYPE_ANY, pResult); 778 if (RT_FAILURE(rc)) 779 return rc; 780 } 781 782 /* 783 * Do the multiplication. 784 */ 785 switch (pArg1->enmType) 786 { 787 case DBGCVAR_TYPE_GC_FLAT: pResult->u.GCFlat *= u64Factor; break; 788 case DBGCVAR_TYPE_GC_FAR: pResult->u.GCFar.off *= u64Factor; break; 789 case DBGCVAR_TYPE_GC_PHYS: pResult->u.GCPhys *= u64Factor; break; 790 case DBGCVAR_TYPE_HC_FLAT: 791 pResult->u.pvHCFlat = (void *)(uintptr_t)((uintptr_t)pResult->u.pvHCFlat * u64Factor); 792 break; 793 case DBGCVAR_TYPE_HC_FAR: pResult->u.HCFar.off *= u64Factor; break; 794 case DBGCVAR_TYPE_HC_PHYS: pResult->u.HCPhys *= u64Factor; break; 795 case DBGCVAR_TYPE_NUMBER: pResult->u.u64Number *= u64Factor; break; 796 default: 797 return VERR_PARSE_INCORRECT_ARG_TYPE; 798 } 799 return 0; 862 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, *, false); 800 863 } 801 864 … … 804 867 * Division operator (binary). 805 868 * 806 * @returns 0on success.869 * @returns VINF_SUCCESS on success. 807 870 * @returns VBox evaluation / parsing error code on failure. 808 871 * The caller does the bitching. … … 815 878 { 816 879 LogFlow(("dbgcOpDiv\n")); 817 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 818 return -1; 880 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, /, true); 819 881 } 820 882 … … 823 885 * Modulus operator (binary). 824 886 * 825 * @returns 0on success.887 * @returns VINF_SUCCESS on success. 826 888 * @returns VBox evaluation / parsing error code on failure. 827 889 * The caller does the bitching. … … 834 896 { 835 897 LogFlow(("dbgcOpMod\n")); 836 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 837 return -1; 898 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, %, false); 838 899 } 839 900 … … 842 903 * Addition operator (binary). 843 904 * 844 * @returns 0on success.905 * @returns VINF_SUCCESS on success. 845 906 * @returns VBox evaluation / parsing error code on failure. 846 907 * The caller does the bitching. … … 852 913 static DECLCALLBACK(int) dbgcOpAdd(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult) 853 914 { 854 //LogFlow(("dbgcOpAdd\n"));915 LogFlow(("dbgcOpAdd\n")); 855 916 856 917 /* … … 1029 1090 1030 1091 } 1031 return 0;1092 return VINF_SUCCESS; 1032 1093 } 1033 1094 … … 1036 1097 * Subtration operator (binary). 1037 1098 * 1038 * @returns 0on success.1099 * @returns VINF_SUCCESS on success. 1039 1100 * @returns VBox evaluation / parsing error code on failure. 1040 1101 * The caller does the bitching. … … 1046 1107 static DECLCALLBACK(int) dbgcOpSub(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult) 1047 1108 { 1048 //LogFlow(("dbgcOpSub\n"));1109 LogFlow(("dbgcOpSub\n")); 1049 1110 1050 1111 /* … … 1287 1348 1288 1349 } 1289 return 0;1350 return VINF_SUCCESS; 1290 1351 } 1291 1352 … … 1294 1355 * Bitwise shift left operator (binary). 1295 1356 * 1296 * @returns 0on success.1357 * @returns VINF_SUCCESS on success. 1297 1358 * @returns VBox evaluation / parsing error code on failure. 1298 1359 * The caller does the bitching. … … 1305 1366 { 1306 1367 LogFlow(("dbgcOpBitwiseShiftLeft\n")); 1307 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 1308 return -1; 1368 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, <<, false); 1309 1369 } 1310 1370 … … 1313 1373 * Bitwise shift right operator (binary). 1314 1374 * 1315 * @returns 0on success.1375 * @returns VINF_SUCCESS on success. 1316 1376 * @returns VBox evaluation / parsing error code on failure. 1317 1377 * The caller does the bitching. … … 1324 1384 { 1325 1385 LogFlow(("dbgcOpBitwiseShiftRight\n")); 1326 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 1327 return -1; 1386 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, >>, false); 1328 1387 } 1329 1388 … … 1332 1391 * Bitwise and operator (binary). 1333 1392 * 1334 * @returns 0on success.1393 * @returns VINF_SUCCESS on success. 1335 1394 * @returns VBox evaluation / parsing error code on failure. 1336 1395 * The caller does the bitching. … … 1343 1402 { 1344 1403 LogFlow(("dbgcOpBitwiseAnd\n")); 1345 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 1346 return -1; 1404 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, &, false); 1347 1405 } 1348 1406 … … 1351 1409 * Bitwise exclusive or operator (binary). 1352 1410 * 1353 * @returns 0on success.1411 * @returns VINF_SUCCESS on success. 1354 1412 * @returns VBox evaluation / parsing error code on failure. 1355 1413 * The caller does the bitching. … … 1362 1420 { 1363 1421 LogFlow(("dbgcOpBitwiseXor\n")); 1364 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 1365 return -1; 1422 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, ^, false); 1366 1423 } 1367 1424 … … 1370 1427 * Bitwise inclusive or operator (binary). 1371 1428 * 1372 * @returns 0on success.1429 * @returns VINF_SUCCESS on success. 1373 1430 * @returns VBox evaluation / parsing error code on failure. 1374 1431 * The caller does the bitching. … … 1381 1438 { 1382 1439 LogFlow(("dbgcOpBitwiseOr\n")); 1383 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 1384 return -1; 1440 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, |, false); 1385 1441 } 1386 1442 … … 1389 1445 * Boolean and operator (binary). 1390 1446 * 1391 * @returns 0on success.1447 * @returns VINF_SUCCESS on success. 1392 1448 * @returns VBox evaluation / parsing error code on failure. 1393 1449 * The caller does the bitching. … … 1400 1456 { 1401 1457 LogFlow(("dbgcOpBooleanAnd\n")); 1402 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 1403 return -1; 1458 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, &&, false); 1404 1459 } 1405 1460 … … 1408 1463 * Boolean or operator (binary). 1409 1464 * 1410 * @returns 0on success.1465 * @returns VINF_SUCCESS on success. 1411 1466 * @returns VBox evaluation / parsing error code on failure. 1412 1467 * The caller does the bitching. … … 1419 1474 { 1420 1475 LogFlow(("dbgcOpBooleanOr\n")); 1421 NOREF(pDbgc); NOREF(pArg1); NOREF(pArg2); NOREF(pResult); 1422 return -1; 1476 DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, ||, false); 1423 1477 } 1424 1478 … … 1427 1481 * Range to operator (binary). 1428 1482 * 1429 * @returns 0on success.1483 * @returns VINF_SUCCESS on success. 1430 1484 * @returns VBox evaluation / parsing error code on failure. 1431 1485 * The caller does the bitching. … … 1437 1491 static DECLCALLBACK(int) dbgcOpRangeLength(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult) 1438 1492 { 1439 // LogFlow(("dbgcOpRangeLength\n")); 1493 LogFlow(("dbgcOpRangeLength\n")); 1494 1440 1495 /* 1441 1496 * Make result. Strings needs to be resolved into symbols. … … 1480 1535 * Range to operator (binary). 1481 1536 * 1482 * @returns 0on success.1537 * @returns VINF_SUCCESS on success. 1483 1538 * @returns VBox evaluation / parsing error code on failure. 1484 1539 * The caller does the bitching. … … 1490 1545 static DECLCALLBACK(int) dbgcOpRangeLengthBytes(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult) 1491 1546 { 1492 //LogFlow(("dbgcOpRangeLengthBytes\n"));1547 LogFlow(("dbgcOpRangeLengthBytes\n")); 1493 1548 int rc = dbgcOpRangeLength(pDbgc, pArg1, pArg2, pResult); 1494 1549 if (RT_SUCCESS(rc)) … … 1501 1556 * Range to operator (binary). 1502 1557 * 1503 * @returns 0on success.1558 * @returns VINF_SUCCESS on success. 1504 1559 * @returns VBox evaluation / parsing error code on failure. 1505 1560 * The caller does the bitching. … … 1511 1566 static DECLCALLBACK(int) dbgcOpRangeTo(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult) 1512 1567 { 1513 // LogFlow(("dbgcOpRangeTo\n")); 1568 LogFlow(("dbgcOpRangeTo\n")); 1569 1514 1570 /* 1515 1571 * Calc number of bytes between the two args. … … 1551 1607 } 1552 1608 1553 return 0;1609 return VINF_SUCCESS; 1554 1610 } 1555 1611 -
trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp
r31530 r31926 22 22 #include "../DBGCInternal.h" 23 23 24 #include <iprt/stream.h>25 24 #include <iprt/string.h> 26 #include <iprt/ initterm.h>25 #include <iprt/test.h> 27 26 28 27 … … 39 38 * Global Variables * 40 39 *******************************************************************************/ 41 /** Global error counter. */ 42 static unsigned g_cErrors = 0; 40 /** The test handle. */ 41 static RTTEST g_hTest = NIL_RTTEST; 42 43 43 /** The DBGC backend structure for use in this testcase. */ 44 44 static DBGCBACK g_tstBack = … … 50 50 }; 51 51 /** For keeping track of output prefixing. */ 52 static bool g_fPendingPrefix = true;52 static bool g_fPendingPrefix = true; 53 53 /** Pointer to the current input position. */ 54 const char *g_pszInput = NULL; 54 const char *g_pszInput = NULL; 55 /** The output of the last command. */ 56 static char g_szOutput[1024]; 57 /** The current offset into g_szOutput. */ 58 static size_t g_offOutput = 0; 59 55 60 56 61 /** … … 120 125 while (cbBuf-- > 0) 121 126 { 127 /* screen/log output */ 122 128 if (g_fPendingPrefix) 123 129 { 124 RT Printf("tstDBGCParser:OUTPUT: ");130 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "OUTPUT: "); 125 131 g_fPendingPrefix = false; 126 132 } 127 133 if (*pch == '\n') 128 134 g_fPendingPrefix = true; 129 RTPrintf("%c", *pch); 135 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%c", *pch); 136 137 /* buffer output */ 138 if (g_offOutput < sizeof(g_szOutput) - 1) 139 { 140 g_szOutput[g_offOutput++] = *pch; 141 g_szOutput[g_offOutput] = '\0'; 142 } 143 144 /* advance */ 130 145 pch++; 131 146 } … … 154 169 { 155 170 if (!g_fPendingPrefix) 156 RT Printf("\n");171 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "\n"); 157 172 g_fPendingPrefix = true; 158 173 } … … 164 179 * @param pszCmds The command to test. 165 180 * @param rcCmd The expected result. 166 */ 167 static void tstTry(PDBGC pDbgc, const char *pszCmds, int rcCmd) 168 { 181 * @param fNoExecute When set, the command is not executed. 182 * @param pszExpected Expected output. This does not need to include all 183 * of the output, just the start of it. Thus the 184 * prompt can be omitted. 185 */ 186 static void tstTryEx(PDBGC pDbgc, const char *pszCmds, int rcCmd, bool fNoExecute, const char *pszExpected) 187 { 188 RT_ZERO(g_szOutput); 189 g_offOutput = 0; 169 190 g_pszInput = pszCmds; 170 191 if (strchr(pszCmds, '\0')[-1] == '\n') 171 RT Printf("tstDBGCParser:RUNNING: %s", pszCmds);192 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "RUNNING: %s", pszCmds); 172 193 else 173 RT Printf("tstDBGCParser:RUNNING: %s\n", pszCmds);194 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "RUNNING: %s\n", pszCmds); 174 195 175 196 pDbgc->rcCmd = VERR_INTERNAL_ERROR; 176 dbgcProcessInput(pDbgc, true /* fNoExecute */);197 dbgcProcessInput(pDbgc, fNoExecute); 177 198 tstCompleteOutput(); 178 199 179 200 if (pDbgc->rcCmd != rcCmd) 180 { 181 RTPrintf("tstDBGCParser: rcCmd=%Rrc expected =%Rrc\n", pDbgc->rcCmd, rcCmd); 182 g_cErrors++; 183 } 184 } 201 RTTestFailed(g_hTest, "rcCmd=%Rrc expected =%Rrc\n", pDbgc->rcCmd, rcCmd); 202 else if ( !fNoExecute 203 && pszExpected 204 && strncmp(pszExpected, g_szOutput, strlen(pszExpected))) 205 RTTestFailed(g_hTest, "Wrong output - expected \"%s\"", pszExpected); 206 } 207 208 209 /** 210 * Tries one command string without executing it. 211 * 212 * @param pDbgc Pointer to the debugger instance. 213 * @param pszCmds The command to test. 214 * @param rcCmd The expected result. 215 */ 216 static void tstTry(PDBGC pDbgc, const char *pszCmds, int rcCmd) 217 { 218 return tstTryEx(pDbgc, pszCmds, rcCmd, true /*fNoExecute*/, NULL); 219 } 220 221 222 /** 223 * Tries to execute one command string. 224 * @param pDbgc Pointer to the debugger instance. 225 * @param pszCmds The command to test. 226 * @param rcCmd The expected result. 227 * @param pszExpected Expected output. This does not need to include all 228 * of the output, just the start of it. Thus the 229 * prompt can be omitted. 230 */ 231 static void tstTryExec(PDBGC pDbgc, const char *pszCmds, int rcCmd, const char *pszExpected) 232 { 233 return tstTryEx(pDbgc, pszCmds, rcCmd, false /*fNoExecute*/, pszExpected); 234 } 235 236 237 /** 238 * Test an operator on an expression resulting a plain number. 239 * 240 * @param pDbgc Pointer to the debugger instance. 241 * @param pszExpr The express to test. 242 * @param u64Expect The expected result. 243 */ 244 static void tstNumOp(PDBGC pDbgc, const char *pszExpr, uint64_t u64Expect) 245 { 246 char szCmd[80]; 247 RTStrPrintf(szCmd, sizeof(szCmd), "format %s\n", pszExpr); 248 249 char szExpected[80]; 250 RTStrPrintf(szExpected, sizeof(szExpected), 251 "Number: hex %llx dec 0i%lld oct 0t%llo", u64Expect, u64Expect, u64Expect); 252 253 return tstTryEx(pDbgc, szCmd, VINF_SUCCESS, false /*fNoExecute*/, szExpected); 254 } 255 185 256 186 257 … … 190 261 * Init. 191 262 */ 192 RTR3Init(); 193 RTPrintf("tstDBGCParser: TESTING...\n"); 263 int rc = RTTestInitAndCreate("tstDBGCParser", &g_hTest); 264 if (rc) 265 return rc; 266 RTTestBanner(g_hTest); 194 267 195 268 /* … … 197 270 */ 198 271 PDBGC pDbgc; 199 intrc = dbgcCreate(&pDbgc, &g_tstBack, 0);272 rc = dbgcCreate(&pDbgc, &g_tstBack, 0); 200 273 if (RT_SUCCESS(rc)) 201 274 { … … 205 278 { 206 279 tstTry(pDbgc, "stop\n", VINF_SUCCESS); 280 tstTry(pDbgc, "format 1\n", VINF_SUCCESS); 207 281 tstTry(pDbgc, "format \n", VERR_PARSE_TOO_FEW_ARGUMENTS); 208 282 tstTry(pDbgc, "format 0 1 23 4\n", VERR_PARSE_TOO_MANY_ARGUMENTS); 209 283 tstTry(pDbgc, "sa 3 23 4 'q' \"21123123\" 'b' \n", VINF_SUCCESS); 284 285 tstNumOp(pDbgc, "1", 1); 286 tstNumOp(pDbgc, "1", 1); 287 tstNumOp(pDbgc, "1", 1); 288 289 tstNumOp(pDbgc, "+1", 1); 290 tstNumOp(pDbgc, "++++++1", 1); 291 292 tstNumOp(pDbgc, "-1", UINT64_MAX); 293 tstNumOp(pDbgc, "--1", 1); 294 tstNumOp(pDbgc, "---1", UINT64_MAX); 295 tstNumOp(pDbgc, "----1", 1); 296 297 tstNumOp(pDbgc, "~0", UINT64_MAX); 298 tstNumOp(pDbgc, "~1", UINT64_MAX-1); 299 tstNumOp(pDbgc, "~~0", 0); 300 tstNumOp(pDbgc, "~~1", 1); 301 302 tstNumOp(pDbgc, "!1", 0); 303 tstNumOp(pDbgc, "!0", 1); 304 tstNumOp(pDbgc, "!42", 0); 305 tstNumOp(pDbgc, "!!42", 1); 306 tstNumOp(pDbgc, "!!!42", 0); 307 tstNumOp(pDbgc, "!!!!42", 1); 308 309 tstNumOp(pDbgc, "1 +1", 2); 310 tstNumOp(pDbgc, "1 + 1", 2); 311 tstNumOp(pDbgc, "1+1", 2); 312 tstNumOp(pDbgc, "1+ 1", 2); 313 314 tstNumOp(pDbgc, "1 - 1", 0); 315 tstNumOp(pDbgc, "99 - 90", 9); 316 317 tstNumOp(pDbgc, "2 * 2", 4); 318 319 tstNumOp(pDbgc, "2 / 2", 1); 320 tstNumOp(pDbgc, "2 / 0", UINT64_MAX); 321 tstNumOp(pDbgc, "0i1024 / 0i4", 256); 322 323 tstNumOp(pDbgc, "1<<1", 2); 324 tstNumOp(pDbgc, "1<<0i32", 0x0000000100000000); 325 tstNumOp(pDbgc, "1<<0i48", 0x0001000000000000); 326 tstNumOp(pDbgc, "1<<0i63", 0x8000000000000000); 327 328 tstNumOp(pDbgc, "fedcba0987654321>>0i04", 0x0fedcba098765432); 329 tstNumOp(pDbgc, "fedcba0987654321>>0i32", 0xfedcba09); 330 tstNumOp(pDbgc, "fedcba0987654321>>0i48", 0x0000fedc); 331 332 tstNumOp(pDbgc, "0ef & 4", 4); 333 tstNumOp(pDbgc, "01234567891 & fff", 0x00000000891); 334 tstNumOp(pDbgc, "01234567891 & ~fff", 0x01234567000); 335 336 tstNumOp(pDbgc, "1 | 1", 1); 337 tstNumOp(pDbgc, "0 | 4", 4); 338 tstNumOp(pDbgc, "4 | 0", 4); 339 tstNumOp(pDbgc, "4 | 4", 4); 340 tstNumOp(pDbgc, "1 | 4 | 2", 7); 341 342 tstNumOp(pDbgc, "1 ^ 1", 0); 343 tstNumOp(pDbgc, "1 ^ 0", 1); 344 tstNumOp(pDbgc, "0 ^ 1", 1); 345 tstNumOp(pDbgc, "3 ^ 1", 2); 346 tstNumOp(pDbgc, "7 ^ 3", 4); 347 348 tstNumOp(pDbgc, "7 || 3", 1); 349 tstNumOp(pDbgc, "1 || 0", 1); 350 tstNumOp(pDbgc, "0 || 1", 1); 351 tstNumOp(pDbgc, "0 || 0", 0); 352 353 tstNumOp(pDbgc, "0 && 0", 0); 354 tstNumOp(pDbgc, "1 && 0", 0); 355 tstNumOp(pDbgc, "0 && 1", 0); 356 tstNumOp(pDbgc, "1 && 1", 1); 357 tstNumOp(pDbgc, "4 && 1", 1); 358 210 359 } 211 360 … … 216 365 * Summary 217 366 */ 218 if (!g_cErrors) 219 RTPrintf("tstDBGCParser: SUCCESS\n"); 220 else 221 RTPrintf("tstDBGCParser: FAILURE - %d errors\n", g_cErrors); 222 return g_cErrors != 0; 223 } 367 return RTTestSummaryAndDestroy(g_hTest); 368 }
Note:
See TracChangeset
for help on using the changeset viewer.