1 | /* $Id: DisasmTest.cpp 41717 2012-06-14 18:03:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox disassembler - Test application
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #include <VBox/dis.h>
|
---|
22 | #include <iprt/test.h>
|
---|
23 | #include <iprt/ctype.h>
|
---|
24 | #include <iprt/string.h>
|
---|
25 | #include <iprt/err.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | DECLASM(int) TestProc32(void);
|
---|
29 | DECLASM(int) TestProc32_EndProc(void);
|
---|
30 | #ifndef RT_OS_OS2
|
---|
31 | DECLASM(int) TestProc64(void);
|
---|
32 | DECLASM(int) TestProc64_EndProc(void);
|
---|
33 | #endif
|
---|
34 | //uint8_t aCode16[] = { 0x66, 0x67, 0x89, 0x07 };
|
---|
35 |
|
---|
36 | static void testDisasp(const char *pszSub, uint8_t const *pabInstrs, uintptr_t uEndPtr, DISCPUMODE enmDisCpuMode)
|
---|
37 | {
|
---|
38 | RTTestISub(pszSub);
|
---|
39 | size_t const cbInstrs = uEndPtr - (uintptr_t)pabInstrs;
|
---|
40 | for (size_t off = 0; off < cbInstrs;)
|
---|
41 | {
|
---|
42 | uint32_t const cErrBefore = RTTestIErrorCount();
|
---|
43 | uint32_t cb = 1;
|
---|
44 | DISCPUSTATE Cpu;
|
---|
45 | char szOutput[256] = {0};
|
---|
46 | int rc = DISInstrToStr(&pabInstrs[off], enmDisCpuMode, &Cpu, &cb, szOutput, sizeof(szOutput));
|
---|
47 |
|
---|
48 | RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
|
---|
49 | RTTESTI_CHECK(cb == Cpu.opsize);
|
---|
50 | RTTESTI_CHECK(cb > 0);
|
---|
51 | RTTESTI_CHECK(cb <= 16);
|
---|
52 | RTStrStripR(szOutput);
|
---|
53 | RTTESTI_CHECK(szOutput[0]);
|
---|
54 | if (szOutput[0])
|
---|
55 | {
|
---|
56 | char *pszBytes = strchr(szOutput, '[');
|
---|
57 | RTTESTI_CHECK(pszBytes);
|
---|
58 | if (pszBytes)
|
---|
59 | {
|
---|
60 | RTTESTI_CHECK(pszBytes[-1] == ' ');
|
---|
61 | RTTESTI_CHECK(RT_C_IS_XDIGIT(pszBytes[1]));
|
---|
62 | RTTESTI_CHECK(pszBytes[cb * 3] == ']');
|
---|
63 | RTTESTI_CHECK(pszBytes[cb * 3 + 1] == ' ');
|
---|
64 |
|
---|
65 | size_t cch = strlen(szOutput);
|
---|
66 | RTTESTI_CHECK(szOutput[cch - 1] != ',');
|
---|
67 | }
|
---|
68 | }
|
---|
69 | if (cErrBefore != RTTestIErrorCount())
|
---|
70 | RTTestIFailureDetails("rc=%Rrc, off=%#x (%u) cbInstr=%u enmDisCpuMode=%d\n",
|
---|
71 | rc, off, Cpu.opsize, enmDisCpuMode);
|
---|
72 | RTTestIPrintf(RTTESTLVL_ALWAYS, "%s\n", szOutput);
|
---|
73 | off += cb;
|
---|
74 | }
|
---|
75 |
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | int main(int argc, char **argv)
|
---|
80 | {
|
---|
81 | RTTEST hTest;
|
---|
82 | RTEXITCODE rcExit = RTTestInitAndCreate("tstDisasm", &hTest);
|
---|
83 | if (rcExit)
|
---|
84 | return rcExit;
|
---|
85 | RTTestBanner(hTest);
|
---|
86 |
|
---|
87 | testDisas("32-bit", (uint8_t const *)(uintptr_t)TestProc32, (uintptr_t)&TestProc32_EndProc, DISCPUMODE_32BIT);
|
---|
88 | #ifndef RT_OS_OS2
|
---|
89 | testDisas("64-bit", (uint8_t const *)(uintptr_t)TestProc64, (uintptr_t)&TestProc64_EndProc, DISCPUMODE_64BIT);
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | return RTTestSummaryAndDestroy(hTest);
|
---|
93 | }
|
---|
94 |
|
---|