Changeset 8986 in vbox
- Timestamp:
- May 21, 2008 12:08:29 AM (17 years ago)
- Location:
- trunk/src/VBox/Disassembler/testcase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Disassembler/testcase/Makefile.kmk
r8970 r8986 34 34 $(LIB_RUNTIME) 35 35 36 # Tests that 36 # Tests that will be build, disassembled and re-build from disassembly. 37 37 VBOX_DISAS_TESTS_BUILD = \ 38 38 tstAsmLock-1.asm \ 39 39 40 # Tests that makes use of --all-invalid.40 # Tests that only contains invalid/undefined instructions. 41 41 VBOX_DISAS_TESTS_INVALID = \ 42 42 tstAsmLock-2.asm \ … … 120 120 $(CMP) $(@:.tst=.bin) $< 121 121 @$(APPEND) $@ "done" 122 @$(ECHO) "PASSED: $(<F) [re-assembled]" 122 123 123 124 … … 127 128 128 129 $(addprefix $(VBOX_DISAS_TEST_PATH)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-16.tst)): $$(patsubst %.tst,%.bin,$$@) $$(INSTARGET_tstDisasm-2) | $$(call DIRDEP,$$(@D)) 129 @$(ECHO) " Verifying all-invalid: $(@F)"130 @$(ECHO) "TESTING: $(@F) [--undef-op=all]" 130 131 @$(RM) -f $@ 131 $(INSTARGET_tstDisasm-2) -- all-invalid--cpumode=16 $<132 $(INSTARGET_tstDisasm-2) --undef-op=all --cpumode=16 $< 132 133 @$(APPEND) $@ "done" 134 @$(ECHO) "PASSED: $(@F) [--undef-op=all]" 133 135 134 136 $(addprefix $(VBOX_DISAS_TEST_PATH)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-32.tst)): $$(patsubst %.tst,%.bin,$$@) $$(INSTARGET_tstDisasm-2) | $$(call DIRDEP,$$(@D)) 135 @$(ECHO) " Verifying all-invalid: $(@F)"137 @$(ECHO) "TESTING: $(@F) [--undef-op=all]" 136 138 @$(RM) -f $@ 137 $(INSTARGET_tstDisasm-2) -- all-invalid--cpumode=32 $<139 $(INSTARGET_tstDisasm-2) --undef-op=all --cpumode=32 $< 138 140 @$(APPEND) $@ "done" 141 @$(ECHO) "PASSED: $(@F) [--undef-op=all]" 139 142 140 143 $(addprefix $(VBOX_DISAS_TEST_PATH)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-64.tst)): $$(patsubst %.tst,%.bin,$$@) $$(INSTARGET_tstDisasm-2) | $$(call DIRDEP,$$(@D)) 141 @$(ECHO) " Verifying all-invalid: $(@F)"144 @$(ECHO) "TESTING: $(@F) [--undef-op=all]" 142 145 @$(RM) -f $@ 143 $(INSTARGET_tstDisasm-2) -- all-invalid--cpumode=64 $<146 $(INSTARGET_tstDisasm-2) --undef-op=all --cpumode=64 $< 144 147 @$(APPEND) $@ "done" 148 @$(ECHO) "PASSED: $(@F) [--undef-op=all]" 145 149 146 150 # Add the .tst to the clean up. -
trunk/src/VBox/Disassembler/testcase/tstDisasm-2.cpp
r8937 r8986 36 36 *******************************************************************************/ 37 37 typedef enum { kAsmStyle_Default, kAsmStyle_yasm, kAsmStyle_masm, kAsmStyle_invalid } ASMSTYLE; 38 typedef enum { kUndefOp_Fail, kUndefOp_All, kUndefOp_DefineByte, kUndefOp_End } UNDEFOPHANDLING; 38 39 39 40 typedef struct MYDISSTATE … … 43 44 uint8_t *pbInstr; /**< The current instruction (pointer). */ 44 45 uint32_t cbInstr; /**< The size of the current instruction. */ 45 bool f Invalid; /**< Whether the instruction is invalid/illegal or not.*/46 bool fRaw; /**< Whether invalid instructions are printed as byte defintions or not. */46 bool fUndefOp; /**< Whether the current instruction is really an undefined opcode.*/ 47 UNDEFOPHANDLING enmUndefOp; /**< How to treat undefined opcodes. */ 47 48 int rc; /**< Set if we hit EOF. */ 48 49 size_t cbLeft; /**< The number of bytes left. (read) */ … … 135 136 /* 136 137 * Jumping up the stream. 138 * This occures when the byte sequence is added to the output string. 137 139 */ 138 140 uint64_t offReq64 = uSrcAddr - pState->uAddress; … … 210 212 * @param enmStyle The assembly output style. 211 213 * @param fListing Whether to print in a listing like mode. 212 * @param fRaw Whether to output byte definitions for invalid sequences. 213 * @param fAllInvalid Whether all instructions are expected to be invalid. 214 * @param enmUndefOp How to deal with undefined opcodes. 214 215 */ 215 216 static int MyDisasmBlock(const char *argv0, DISCPUMODE enmCpuMode, uint64_t uAddress, uint8_t *pbFile, size_t cbFile, 216 ASMSTYLE enmStyle, bool fListing, bool fRaw, bool fAllInvalid)217 ASMSTYLE enmStyle, bool fListing, UNDEFOPHANDLING enmUndefOp) 217 218 { 218 219 /* … … 225 226 State.pbInstr = pbFile; 226 227 State.cbInstr = 0; 227 State.fInvalid = false; 228 State.fRaw = fRaw; 228 State.enmUndefOp = enmUndefOp; 229 229 State.rc = VINF_SUCCESS; 230 230 State.cbLeft = cbFile; … … 269 269 if (RT_SUCCESS(rc)) 270 270 { 271 State.f Invalid= State.Cpu.pCurInstr->opcode == OP_INVALID271 State.fUndefOp = State.Cpu.pCurInstr->opcode == OP_INVALID 272 272 || State.Cpu.pCurInstr->opcode == OP_ILLUD2; 273 if (!fAllInvalid || State.fInvalid) 274 pfnFormatter(&State); 275 else 273 if (!State.fUndefOp && State.enmUndefOp == kUndefOp_All) 276 274 { 277 275 RTPrintf("%s: error at %#RX64: unexpected valid instruction (op=%d)\n", argv0, State.uAddress, State.Cpu.pCurInstr->opcode); … … 279 277 rcRet = VERR_GENERAL_FAILURE; 280 278 } 279 else if (State.fUndefOp && State.enmUndefOp == kUndefOp_Fail) 280 { 281 RTPrintf("%s: error at %#RX64: undefined opcode (op=%d)\n", argv0, State.uAddress, State.Cpu.pCurInstr->opcode); 282 pfnFormatter(&State); 283 rcRet = VERR_GENERAL_FAILURE; 284 } 285 else 286 pfnFormatter(&State); 281 287 } 282 288 else … … 325 331 " --cpumode|-c <16|32|64>\n" 326 332 " The cpu mode. Default: 32\n" 327 " --all-invalid|-i\n"328 " When specified all instructions are expected to be invalid.\n"329 333 " --listing|-l, --no-listing|-L\n" 330 334 " Enables or disables listing mode. Default: --no-listing\n" 331 335 " --offset|-o <offset>\n" 332 336 " The file offset at which to start disassembling. Default: 0\n" 333 " --raw|-r, --no-raw|-R\n"334 " Whether to employ byte defines for unknown bits. Default: --no-raw\n"335 337 " --style|-s <default|yasm|masm>\n" 336 338 " The assembly output style. Default: default\n" 339 " --undef-op|-u <fail|all|db>\n" 340 " How to treat undefined opcodes. Default: fail\n" 337 341 , argv0, argv0); 338 342 return 1; … … 348 352 uint64_t uAddress = 0; 349 353 ASMSTYLE enmStyle = kAsmStyle_Default; 354 UNDEFOPHANDLING enmUndefOp = kUndefOp_Fail; 350 355 bool fListing = true; 351 bool fRaw = false;352 bool fAllInvalid = false;353 356 DISCPUMODE enmCpuMode = CPUMODE_32BIT; 354 357 RTFOFF off = 0; … … 364 367 { "--help", 'h', 0 }, 365 368 { "--bytes", 'b', RTGETOPT_REQ_INT64 }, 366 { "--all-invalid", 'i', 0, },367 369 { "--listing", 'l', 0 }, 368 370 { "--no-listing", 'L', 0 }, 369 371 { "--offset", 'o', RTGETOPT_REQ_INT64 }, 370 { "--raw", 'r', 0 },371 { "--no-raw", 'R', 0 },372 372 { "--style", 's', RTGETOPT_REQ_STRING }, 373 { "--undef-op", 'u', RTGETOPT_REQ_STRING }, 373 374 }; 374 375 … … 405 406 return Usage(argv0); 406 407 407 case 'i':408 fAllInvalid = true;409 break;410 411 408 case 'l': 412 409 fListing = true; … … 419 416 case 'o': 420 417 off = ValueUnion.i; 421 break;422 423 case 'r':424 fRaw = true;425 break;426 427 case 'R':428 fRaw = false;429 418 break; 430 419 … … 447 436 break; 448 437 438 case 'u': 439 if (!strcmp(ValueUnion.psz, "fail")) 440 enmUndefOp = kUndefOp_Fail; 441 else if (!strcmp(ValueUnion.psz, "all")) 442 enmUndefOp = kUndefOp_All; 443 else if (!strcmp(ValueUnion.psz, "db")) 444 enmUndefOp = kUndefOp_DefineByte; 445 else 446 { 447 RTStrmPrintf(g_pStdErr, "%s: unknown undefined opcode handling method: %s\n", argv0, ValueUnion.psz); 448 return 1; 449 } 450 break; 451 449 452 default: 450 453 RTStrmPrintf(g_pStdErr, "%s: syntax error: %Rrc\n", argv0, ch); … … 476 479 * Disassemble it. 477 480 */ 478 rc = MyDisasmBlock(argv0, enmCpuMode, uAddress, (uint8_t *)pvFile, cbFile, enmStyle, fListing, fRaw, fAllInvalid);481 rc = MyDisasmBlock(argv0, enmCpuMode, uAddress, (uint8_t *)pvFile, cbFile, enmStyle, fListing, enmUndefOp); 479 482 if (RT_FAILURE(rc)) 480 483 break;
Note:
See TracChangeset
for help on using the changeset viewer.