VirtualBox

source: vbox/trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp@ 78339

Last change on this file since 78339 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 37.8 KB
Line 
1/* $Id: tstDBGCParser.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * DBGC Testcase - Command Parser.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <VBox/dbg.h>
23#include "../DBGCInternal.h"
24
25#include <iprt/string.h>
26#include <iprt/test.h>
27#include <VBox/err.h>
28
29
30/*********************************************************************************************************************************
31* Internal Functions *
32*********************************************************************************************************************************/
33static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies);
34static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
35static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
36static DECLCALLBACK(void) tstDBGCBackSetReady(PDBGCBACK pBack, bool fReady);
37
38
39/*********************************************************************************************************************************
40* Global Variables *
41*********************************************************************************************************************************/
42/** The test handle. */
43static RTTEST g_hTest = NIL_RTTEST;
44
45/** The DBGC backend structure for use in this testcase. */
46static DBGCBACK g_tstBack =
47{
48 tstDBGCBackInput,
49 tstDBGCBackRead,
50 tstDBGCBackWrite,
51 tstDBGCBackSetReady
52};
53/** For keeping track of output prefixing. */
54static bool g_fPendingPrefix = true;
55/** Pointer to the current input position. */
56const char *g_pszInput = NULL;
57/** The output of the last command. */
58static char g_szOutput[1024];
59/** The current offset into g_szOutput. */
60static size_t g_offOutput = 0;
61
62
63/**
64 * Checks if there is input.
65 *
66 * @returns true if there is input ready.
67 * @returns false if there not input ready.
68 * @param pBack Pointer to the backend structure supplied by
69 * the backend. The backend can use this to find
70 * it's instance data.
71 * @param cMillies Number of milliseconds to wait on input data.
72 */
73static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies)
74{
75 return g_pszInput != NULL
76 && *g_pszInput != '\0';
77}
78
79
80/**
81 * Read input.
82 *
83 * @returns VBox status code.
84 * @param pBack Pointer to the backend structure supplied by
85 * the backend. The backend can use this to find
86 * it's instance data.
87 * @param pvBuf Where to put the bytes we read.
88 * @param cbBuf Maximum nymber of bytes to read.
89 * @param pcbRead Where to store the number of bytes actually read.
90 * If NULL the entire buffer must be filled for a
91 * successful return.
92 */
93static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead)
94{
95 if (g_pszInput && *g_pszInput)
96 {
97 size_t cb = strlen(g_pszInput);
98 if (cb > cbBuf)
99 cb = cbBuf;
100 *pcbRead = cb;
101 memcpy(pvBuf, g_pszInput, cb);
102 g_pszInput += cb;
103 }
104 else
105 *pcbRead = 0;
106 return VINF_SUCCESS;
107}
108
109
110/**
111 * Write (output).
112 *
113 * @returns VBox status code.
114 * @param pBack Pointer to the backend structure supplied by
115 * the backend. The backend can use this to find
116 * it's instance data.
117 * @param pvBuf What to write.
118 * @param cbBuf Number of bytes to write.
119 * @param pcbWritten Where to store the number of bytes actually written.
120 * If NULL the entire buffer must be successfully written.
121 */
122static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
123{
124 const char *pch = (const char *)pvBuf;
125 if (pcbWritten)
126 *pcbWritten = cbBuf;
127 while (cbBuf-- > 0)
128 {
129 /* screen/log output */
130 if (g_fPendingPrefix)
131 {
132 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "OUTPUT: ");
133 g_fPendingPrefix = false;
134 }
135 if (*pch == '\n')
136 g_fPendingPrefix = true;
137 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%c", *pch);
138
139 /* buffer output */
140 if (g_offOutput < sizeof(g_szOutput) - 1)
141 {
142 g_szOutput[g_offOutput++] = *pch;
143 g_szOutput[g_offOutput] = '\0';
144 }
145
146 /* advance */
147 pch++;
148 }
149 return VINF_SUCCESS;
150}
151
152
153/**
154 * Ready / busy notification.
155 *
156 * @param pBack Pointer to the backend structure supplied by
157 * the backend. The backend can use this to find
158 * it's instance data.
159 * @param fReady Whether it's ready (true) or busy (false).
160 */
161static DECLCALLBACK(void) tstDBGCBackSetReady(PDBGCBACK pBack, bool fReady)
162{
163}
164
165
166/**
167 * Completes the output, making sure that we're in
168 * the 1 position of a new line.
169 */
170static void tstCompleteOutput(void)
171{
172 if (!g_fPendingPrefix)
173 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "\n");
174 g_fPendingPrefix = true;
175}
176
177
178/**
179 * Checks if two DBGC variables are identical
180 *
181 * @returns
182 * @param pVar1 .
183 * @param pVar2 .
184 */
185bool DBGCVarAreIdentical(PCDBGCVAR pVar1, PCDBGCVAR pVar2)
186{
187 if (!pVar1)
188 return false;
189 if (pVar1 == pVar2)
190 return true;
191
192 if (pVar1->enmType != pVar2->enmType)
193 return false;
194 switch (pVar1->enmType)
195 {
196 case DBGCVAR_TYPE_GC_FLAT:
197 if (pVar1->u.GCFlat != pVar2->u.GCFlat)
198 return false;
199 break;
200 case DBGCVAR_TYPE_GC_FAR:
201 if (pVar1->u.GCFar.off != pVar2->u.GCFar.off)
202 return false;
203 if (pVar1->u.GCFar.sel != pVar2->u.GCFar.sel)
204 return false;
205 break;
206 case DBGCVAR_TYPE_GC_PHYS:
207 if (pVar1->u.GCPhys != pVar2->u.GCPhys)
208 return false;
209 break;
210 case DBGCVAR_TYPE_HC_FLAT:
211 if (pVar1->u.pvHCFlat != pVar2->u.pvHCFlat)
212 return false;
213 break;
214 case DBGCVAR_TYPE_HC_PHYS:
215 if (pVar1->u.HCPhys != pVar2->u.HCPhys)
216 return false;
217 break;
218 case DBGCVAR_TYPE_NUMBER:
219 if (pVar1->u.u64Number != pVar2->u.u64Number)
220 return false;
221 break;
222 case DBGCVAR_TYPE_STRING:
223 case DBGCVAR_TYPE_SYMBOL:
224 if (RTStrCmp(pVar1->u.pszString, pVar2->u.pszString) != 0)
225 return false;
226 break;
227 default:
228 AssertFailedReturn(false);
229 }
230
231 if (pVar1->enmRangeType != pVar2->enmRangeType)
232 return false;
233 switch (pVar1->enmRangeType)
234 {
235 case DBGCVAR_RANGE_NONE:
236 break;
237
238 case DBGCVAR_RANGE_ELEMENTS:
239 case DBGCVAR_RANGE_BYTES:
240 if (pVar1->u64Range != pVar2->u64Range)
241 return false;
242 break;
243 default:
244 AssertFailedReturn(false);
245 }
246
247 return true;
248}
249
250/**
251 * Tries one command string.
252 * @param pDbgc Pointer to the debugger instance.
253 * @param pszCmds The command to test.
254 * @param rcCmd The expected result.
255 * @param fNoExecute When set, the command is not executed.
256 * @param pszExpected Expected output. This does not need to include all
257 * of the output, just the start of it. Thus the
258 * prompt can be omitted.
259 * @param cArgs The number of expected arguments. -1 if we don't
260 * want to check the parsed arguments.
261 * @param va Info about expected parsed arguments. For each
262 * argument a DBGCVARTYPE, value (depends on type),
263 * DBGCVARRANGETYPE and optionally range value.
264 */
265static void tstTryExV(PDBGC pDbgc, const char *pszCmds, int rcCmd, bool fNoExecute, const char *pszExpected,
266 int32_t cArgs, va_list va)
267{
268 RT_ZERO(g_szOutput);
269 g_offOutput = 0;
270 g_pszInput = pszCmds;
271 if (strchr(pszCmds, '\0')[-1] == '\n')
272 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "RUNNING: %s", pszCmds);
273 else
274 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "RUNNING: %s\n", pszCmds);
275
276 pDbgc->rcCmd = VERR_INTERNAL_ERROR;
277 dbgcProcessInput(pDbgc, fNoExecute);
278 tstCompleteOutput();
279
280 if (pDbgc->rcCmd != rcCmd)
281 RTTestFailed(g_hTest, "rcCmd=%Rrc expected =%Rrc\n", pDbgc->rcCmd, rcCmd);
282 else if ( !fNoExecute
283 && pszExpected
284 && strncmp(pszExpected, g_szOutput, strlen(pszExpected)))
285 RTTestFailed(g_hTest, "Wrong output - expected \"%s\"", pszExpected);
286
287 if (cArgs >= 0)
288 {
289 PCDBGCVAR paArgs = pDbgc->aArgs;
290 for (int32_t iArg = 0; iArg < cArgs; iArg++)
291 {
292 DBGCVAR ExpectedArg;
293 ExpectedArg.enmType = (DBGCVARTYPE)va_arg(va, int/*DBGCVARTYPE*/);
294 switch (ExpectedArg.enmType)
295 {
296 case DBGCVAR_TYPE_GC_FLAT: ExpectedArg.u.GCFlat = va_arg(va, RTGCPTR); break;
297 case DBGCVAR_TYPE_GC_FAR: ExpectedArg.u.GCFar.sel = va_arg(va, int /*RTSEL*/);
298 ExpectedArg.u.GCFar.off = va_arg(va, uint32_t); break;
299 case DBGCVAR_TYPE_GC_PHYS: ExpectedArg.u.GCPhys = va_arg(va, RTGCPHYS); break;
300 case DBGCVAR_TYPE_HC_FLAT: ExpectedArg.u.pvHCFlat = va_arg(va, void *); break;
301 case DBGCVAR_TYPE_HC_PHYS: ExpectedArg.u.HCPhys = va_arg(va, RTHCPHYS); break;
302 case DBGCVAR_TYPE_NUMBER: ExpectedArg.u.u64Number = va_arg(va, uint64_t); break;
303 case DBGCVAR_TYPE_STRING: ExpectedArg.u.pszString = va_arg(va, const char *); break;
304 case DBGCVAR_TYPE_SYMBOL: ExpectedArg.u.pszString = va_arg(va, const char *); break;
305 default:
306 RTTestFailed(g_hTest, "enmType=%u iArg=%u\n", ExpectedArg.enmType, iArg);
307 ExpectedArg.u.u64Number = 0;
308 break;
309 }
310 ExpectedArg.enmRangeType = (DBGCVARRANGETYPE)va_arg(va, int /*DBGCVARRANGETYPE*/);
311 switch (ExpectedArg.enmRangeType)
312 {
313 case DBGCVAR_RANGE_NONE: ExpectedArg.u64Range = 0; break;
314 case DBGCVAR_RANGE_ELEMENTS: ExpectedArg.u64Range = va_arg(va, uint64_t); break;
315 case DBGCVAR_RANGE_BYTES: ExpectedArg.u64Range = va_arg(va, uint64_t); break;
316 default:
317 RTTestFailed(g_hTest, "enmRangeType=%u iArg=%u\n", ExpectedArg.enmRangeType, iArg);
318 ExpectedArg.u64Range = 0;
319 break;
320 }
321
322 if (!DBGCVarAreIdentical(&ExpectedArg, &paArgs[iArg]))
323 RTTestFailed(g_hTest,
324 "Arg #%u\n"
325 "actual: enmType=%u u64=%#RX64 enmRangeType=%u u64Range=%#RX64\n"
326 "expected: enmType=%u u64=%#RX64 enmRangeType=%u u64Range=%#RX64\n",
327 iArg,
328 paArgs[iArg].enmType, paArgs[iArg].u.u64Number, paArgs[iArg].enmRangeType, paArgs[iArg].u64Range,
329 ExpectedArg.enmType, ExpectedArg.u.u64Number, ExpectedArg.enmRangeType, ExpectedArg.u64Range);
330 }
331 }
332}
333
334/**
335 * Tries one command string.
336 *
337 * @param pDbgc Pointer to the debugger instance.
338 * @param pszCmds The command to test.
339 * @param rcCmd The expected result.
340 * @param fNoExecute When set, the command is not executed.
341 * @param pszExpected Expected output. This does not need to include all
342 * of the output, just the start of it. Thus the
343 * prompt can be omitted.
344 * @param cArgs The number of expected arguments. -1 if we don't
345 * want to check the parsed arguments.
346 * @param ... Info about expected parsed arguments. For each
347 * argument a DBGCVARTYPE, value (depends on type),
348 * DBGCVARRANGETYPE and optionally range value.
349 */
350static void tstTryEx(PDBGC pDbgc, const char *pszCmds, int rcCmd, bool fNoExecute, const char *pszExpected, int32_t cArgs, ...)
351{
352 va_list va;
353 va_start(va, cArgs);
354 tstTryExV(pDbgc, pszCmds, rcCmd, fNoExecute, pszExpected, cArgs, va);
355 va_end(va);
356}
357
358
359/**
360 * Tries one command string without executing it.
361 *
362 * @param pDbgc Pointer to the debugger instance.
363 * @param pszCmds The command to test.
364 * @param rcCmd The expected result.
365 */
366static void tstTry(PDBGC pDbgc, const char *pszCmds, int rcCmd)
367{
368 return tstTryEx(pDbgc, pszCmds, rcCmd, true /*fNoExecute*/, NULL, -1);
369}
370
371
372#ifdef SOME_UNUSED_FUNCTION
373/**
374 * Tries to execute one command string.
375 * @param pDbgc Pointer to the debugger instance.
376 * @param pszCmds The command to test.
377 * @param rcCmd The expected result.
378 * @param pszExpected Expected output. This does not need to include all
379 * of the output, just the start of it. Thus the
380 * prompt can be omitted.
381 */
382static void tstTryExec(PDBGC pDbgc, const char *pszCmds, int rcCmd, const char *pszExpected)
383{
384 return tstTryEx(pDbgc, pszCmds, rcCmd, false /*fNoExecute*/, pszExpected, -1);
385}
386#endif
387
388
389/**
390 * Test an operator on an expression resulting a plain number.
391 *
392 * @param pDbgc Pointer to the debugger instance.
393 * @param pszExpr The express to test.
394 * @param u64Expect The expected result.
395 */
396static void tstNumOp(PDBGC pDbgc, const char *pszExpr, uint64_t u64Expect)
397{
398 char szCmd[80];
399 RTStrPrintf(szCmd, sizeof(szCmd), "format %s\n", pszExpr);
400
401 char szExpected[80];
402 RTStrPrintf(szExpected, sizeof(szExpected),
403 "Number: hex %llx dec 0i%lld oct 0t%llo", u64Expect, u64Expect, u64Expect);
404
405 return tstTryEx(pDbgc, szCmd, VINF_SUCCESS, false /*fNoExecute*/, szExpected, -1);
406}
407
408
409/*
410 *
411 * CodeView emulation commands.
412 * CodeView emulation commands.
413 * CodeView emulation commands.
414 *
415 */
416
417
418static void testCodeView_ba(PDBGC pDbgc)
419{
420 RTTestISub("codeview - ba");
421 tstTry(pDbgc, "ba x 1 0f000:0000\n", VINF_SUCCESS);
422 tstTry(pDbgc, "ba x 1 0f000:0000 0\n", VINF_SUCCESS);
423 tstTry(pDbgc, "ba x 1 0f000:0000 0 ~0\n", VINF_SUCCESS);
424 tstTry(pDbgc, "ba x 1 0f000:0000 0 ~0 \"command\"\n", VINF_SUCCESS);
425 tstTry(pDbgc, "ba x 1 0f000:0000 0 ~0 \"command\" too_many\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
426 tstTry(pDbgc, "ba x 1\n", VERR_DBGC_PARSE_TOO_FEW_ARGUMENTS);
427
428 tstTryEx(pDbgc, "ba x 1 0f000:1234 5 1000 \"command\"\n", VINF_SUCCESS,
429 true /*fNoExecute*/, NULL /*pszExpected*/, 6 /*cArgs*/,
430 DBGCVAR_TYPE_STRING, "x", DBGCVAR_RANGE_BYTES, UINT64_C(1),
431 DBGCVAR_TYPE_NUMBER, UINT64_C(1), DBGCVAR_RANGE_NONE,
432 DBGCVAR_TYPE_GC_FAR, 0xf000, UINT32_C(0x1234), DBGCVAR_RANGE_NONE,
433 DBGCVAR_TYPE_NUMBER, UINT64_C(0x5), DBGCVAR_RANGE_NONE,
434 DBGCVAR_TYPE_NUMBER, UINT64_C(0x1000), DBGCVAR_RANGE_NONE,
435 DBGCVAR_TYPE_STRING, "command", DBGCVAR_RANGE_BYTES, UINT64_C(7));
436
437 tstTryEx(pDbgc, "ba x 1 %0f000:1234 5 1000 \"command\"\n", VINF_SUCCESS,
438 true /*fNoExecute*/, NULL /*pszExpected*/, 6 /*cArgs*/,
439 DBGCVAR_TYPE_STRING, "x", DBGCVAR_RANGE_BYTES, UINT64_C(1),
440 DBGCVAR_TYPE_NUMBER, UINT64_C(1), DBGCVAR_RANGE_NONE,
441 DBGCVAR_TYPE_GC_FLAT, UINT64_C(0xf1234), DBGCVAR_RANGE_NONE,
442 DBGCVAR_TYPE_NUMBER, UINT64_C(0x5), DBGCVAR_RANGE_NONE,
443 DBGCVAR_TYPE_NUMBER, UINT64_C(0x1000), DBGCVAR_RANGE_NONE,
444 DBGCVAR_TYPE_STRING, "command", DBGCVAR_RANGE_BYTES, UINT64_C(7));
445
446 tstTry(pDbgc, "ba x 1 bad:bad 5 1000 \"command\"\n", VINF_SUCCESS);
447 tstTry(pDbgc, "ba x 1 %bad:bad 5 1000 \"command\"\n", VERR_DBGC_PARSE_CONVERSION_FAILED);
448
449 tstTryEx(pDbgc, "ba f 1 0f000:1234 5 1000 \"command\"\n", VINF_SUCCESS,
450 true /*fNoExecute*/, NULL /*pszExpected*/, 6 /*cArgs*/,
451 DBGCVAR_TYPE_STRING, "f", DBGCVAR_RANGE_BYTES, UINT64_C(1),
452 DBGCVAR_TYPE_NUMBER, UINT64_C(1), DBGCVAR_RANGE_NONE,
453 DBGCVAR_TYPE_GC_FAR, 0xf000, UINT32_C(0x1234), DBGCVAR_RANGE_NONE,
454 DBGCVAR_TYPE_NUMBER, UINT64_C(0x5), DBGCVAR_RANGE_NONE,
455 DBGCVAR_TYPE_NUMBER, UINT64_C(0x1000), DBGCVAR_RANGE_NONE,
456 DBGCVAR_TYPE_STRING, "command", DBGCVAR_RANGE_BYTES, UINT64_C(7));
457
458 tstTry(pDbgc, "ba x 1 0f000:1234 qnx 1000 \"command\"\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
459 tstTry(pDbgc, "ba x 1 0f000:1234 5 qnx \"command\"\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
460 tstTry(pDbgc, "ba x qnx 0f000:1234 5 1000 \"command\"\n", VERR_DBGC_PARSE_INVALID_NUMBER);
461 tstTry(pDbgc, "ba x 1 qnx 5 1000 \"command\"\n", VERR_DBGC_PARSE_INVALID_NUMBER);
462}
463
464
465static void testCodeView_bc(PDBGC pDbgc)
466{
467 RTTestISub("codeview - bc");
468}
469
470
471static void testCodeView_bd(PDBGC pDbgc)
472{
473 RTTestISub("codeview - bc");
474}
475
476
477static void testCodeView_be(PDBGC pDbgc)
478{
479 RTTestISub("codeview - be");
480}
481
482
483static void testCodeView_bl(PDBGC pDbgc)
484{
485 RTTestISub("codeview - bl");
486}
487
488
489static void testCodeView_bp(PDBGC pDbgc)
490{
491 RTTestISub("codeview - bp");
492}
493
494
495static void testCodeView_br(PDBGC pDbgc)
496{
497 RTTestISub("codeview - br");
498}
499
500
501static void testCodeView_d(PDBGC pDbgc)
502{
503 RTTestISub("codeview - d");
504}
505
506
507static void testCodeView_da(PDBGC pDbgc)
508{
509 RTTestISub("codeview - da");
510}
511
512
513static void testCodeView_db(PDBGC pDbgc)
514{
515 RTTestISub("codeview - db");
516}
517
518
519static void testCodeView_dd(PDBGC pDbgc)
520{
521 RTTestISub("codeview - dd");
522}
523
524
525static void testCodeView_dg(PDBGC pDbgc)
526{
527 RTTestISub("codeview - dg");
528}
529
530
531static void testCodeView_dga(PDBGC pDbgc)
532{
533 RTTestISub("codeview - dga");
534}
535
536
537static void testCodeView_di(PDBGC pDbgc)
538{
539 RTTestISub("codeview - di");
540}
541
542
543static void testCodeView_dia(PDBGC pDbgc)
544{
545 RTTestISub("codeview - dia");
546}
547
548
549static void testCodeView_dl(PDBGC pDbgc)
550{
551 RTTestISub("codeview - dl");
552}
553
554
555static void testCodeView_dla(PDBGC pDbgc)
556{
557 RTTestISub("codeview - dla");
558}
559
560
561static void testCodeView_dpd(PDBGC pDbgc)
562{
563 RTTestISub("codeview - dpd");
564}
565
566
567static void testCodeView_dpda(PDBGC pDbgc)
568{
569 RTTestISub("codeview - dpda");
570}
571
572
573static void testCodeView_dpdb(PDBGC pDbgc)
574{
575 RTTestISub("codeview - dpdb");
576}
577
578
579static void testCodeView_dpdg(PDBGC pDbgc)
580{
581 RTTestISub("codeview - dpdg");
582}
583
584
585static void testCodeView_dpdh(PDBGC pDbgc)
586{
587 RTTestISub("codeview - dpdh");
588}
589
590
591static void testCodeView_dph(PDBGC pDbgc)
592{
593 RTTestISub("codeview - dph");
594}
595
596
597static void testCodeView_dphg(PDBGC pDbgc)
598{
599 RTTestISub("codeview - dphg");
600}
601
602
603static void testCodeView_dphh(PDBGC pDbgc)
604{
605 RTTestISub("codeview - dphh");
606}
607
608
609static void testCodeView_dq(PDBGC pDbgc)
610{
611 RTTestISub("codeview - dq");
612}
613
614
615static void testCodeView_dt(PDBGC pDbgc)
616{
617 RTTestISub("codeview - dt");
618}
619
620
621static void testCodeView_dt16(PDBGC pDbgc)
622{
623 RTTestISub("codeview - dt16");
624}
625
626
627static void testCodeView_dt32(PDBGC pDbgc)
628{
629 RTTestISub("codeview - dt32");
630}
631
632
633static void testCodeView_dt64(PDBGC pDbgc)
634{
635 RTTestISub("codeview - dt64");
636}
637
638
639static void testCodeView_dw(PDBGC pDbgc)
640{
641 RTTestISub("codeview - dw");
642}
643
644
645static void testCodeView_eb(PDBGC pDbgc)
646{
647 RTTestISub("codeview - eb");
648}
649
650
651static void testCodeView_ew(PDBGC pDbgc)
652{
653 RTTestISub("codeview - ew");
654}
655
656
657static void testCodeView_ed(PDBGC pDbgc)
658{
659 RTTestISub("codeview - ed");
660}
661
662
663static void testCodeView_eq(PDBGC pDbgc)
664{
665 RTTestISub("codeview - eq");
666}
667
668
669static void testCodeView_g(PDBGC pDbgc)
670{
671 RTTestISub("codeview - g");
672}
673
674
675static void testCodeView_k(PDBGC pDbgc)
676{
677 RTTestISub("codeview - k");
678}
679
680
681static void testCodeView_kg(PDBGC pDbgc)
682{
683 RTTestISub("codeview - kg");
684}
685
686
687static void testCodeView_kh(PDBGC pDbgc)
688{
689 RTTestISub("codeview - kh");
690}
691
692
693static void testCodeView_lm(PDBGC pDbgc)
694{
695 RTTestISub("codeview - lm");
696}
697
698
699static void testCodeView_lmo(PDBGC pDbgc)
700{
701 RTTestISub("codeview - lmo");
702}
703
704
705static void testCodeView_ln(PDBGC pDbgc)
706{
707 RTTestISub("codeview - ln");
708}
709
710
711static void testCodeView_ls(PDBGC pDbgc)
712{
713 RTTestISub("codeview - ls");
714}
715
716
717static void testCodeView_m(PDBGC pDbgc)
718{
719 RTTestISub("codeview - m");
720}
721
722
723static void testCodeView_r(PDBGC pDbgc)
724{
725 RTTestISub("codeview - r");
726}
727
728
729static void testCodeView_rg(PDBGC pDbgc)
730{
731 RTTestISub("codeview - rg");
732}
733
734
735static void testCodeView_rg32(PDBGC pDbgc)
736{
737 RTTestISub("codeview - rg32");
738}
739
740
741static void testCodeView_rg64(PDBGC pDbgc)
742{
743 RTTestISub("codeview - rg64");
744}
745
746
747static void testCodeView_rh(PDBGC pDbgc)
748{
749 RTTestISub("codeview - rh");
750}
751
752
753static void testCodeView_rt(PDBGC pDbgc)
754{
755 RTTestISub("codeview - rt");
756}
757
758
759static void testCodeView_s(PDBGC pDbgc)
760{
761 RTTestISub("codeview - s");
762}
763
764
765static void testCodeView_sa(PDBGC pDbgc)
766{
767 RTTestISub("codeview - sa");
768}
769
770
771static void testCodeView_sb(PDBGC pDbgc)
772{
773 RTTestISub("codeview - sb");
774}
775
776
777static void testCodeView_sd(PDBGC pDbgc)
778{
779 RTTestISub("codeview - sd");
780}
781
782
783static void testCodeView_sq(PDBGC pDbgc)
784{
785 RTTestISub("codeview - sq");
786}
787
788
789static void testCodeView_su(PDBGC pDbgc)
790{
791 RTTestISub("codeview - su");
792}
793
794
795static void testCodeView_sw(PDBGC pDbgc)
796{
797 RTTestISub("codeview - sw");
798}
799
800
801static void testCodeView_t(PDBGC pDbgc)
802{
803 RTTestISub("codeview - t");
804}
805
806
807static void testCodeView_y(PDBGC pDbgc)
808{
809 RTTestISub("codeview - y");
810}
811
812
813static void testCodeView_u64(PDBGC pDbgc)
814{
815 RTTestISub("codeview - u64");
816}
817
818
819static void testCodeView_u32(PDBGC pDbgc)
820{
821 RTTestISub("codeview - u32");
822}
823
824
825static void testCodeView_u16(PDBGC pDbgc)
826{
827 RTTestISub("codeview - u16");
828}
829
830
831static void testCodeView_uv86(PDBGC pDbgc)
832{
833 RTTestISub("codeview - uv86");
834}
835
836
837/*
838 * Common commands.
839 */
840
841static void testCommon_bye_exit_quit(PDBGC pDbgc)
842{
843 RTTestISub("common - bye/exit/quit");
844 /* These have the same parameter descriptor and handler, the command really
845 just has a couple of aliases.*/
846 tstTry(pDbgc, "bye\n", VINF_SUCCESS);
847 tstTry(pDbgc, "bye x\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
848 tstTry(pDbgc, "bye 1\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
849 tstTry(pDbgc, "bye %bad:bad\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
850 tstTry(pDbgc, "exit\n", VINF_SUCCESS);
851 tstTry(pDbgc, "quit\n", VINF_SUCCESS);
852}
853
854
855static void testCommon_cpu(PDBGC pDbgc)
856{
857 RTTestISub("common - cpu");
858 tstTry(pDbgc, "cpu\n", VINF_SUCCESS);
859 tstTry(pDbgc, "cpu 1\n", VINF_SUCCESS);
860 tstTry(pDbgc, "cpu 1 1\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
861 tstTry(pDbgc, "cpu emt\n", VERR_DBGC_PARSE_INVALID_NUMBER);
862 tstTry(pDbgc, "cpu @eax\n", VINF_SUCCESS);
863 tstTry(pDbgc, "cpu %bad:bad\n", VERR_DBGC_PARSE_CONVERSION_FAILED);
864 tstTry(pDbgc, "cpu '1'\n", VERR_DBGC_PARSE_INVALID_NUMBER);
865}
866
867
868static void testCommon_echo(PDBGC pDbgc)
869{
870 RTTestISub("common - echo");
871 tstTry(pDbgc, "echo\n", VERR_DBGC_PARSE_TOO_FEW_ARGUMENTS);
872 tstTry(pDbgc, "echo 1\n", VINF_SUCCESS);
873 tstTryEx(pDbgc, "echo 1 2 3 4 5 6\n", VINF_SUCCESS, false, "1 2 3 4 5 6", -1);
874
875 /* The idea here is that since the prefered input is a string, we
876 definitely won't be confused by the number like beginning. */
877 tstTryEx(pDbgc, "echo 1234567890abcdefghijklmn\n", VINF_SUCCESS, false, "1234567890abcdefghijklmn", -1);
878
879 /* The idea here is that we'll perform the + operation and then convert the
880 result to a string (hex). */
881 tstTryEx(pDbgc, "echo 1 + 1\n", VINF_SUCCESS, false, "2", -1);
882 tstTryEx(pDbgc, "echo \"1 + 1\"\n", VINF_SUCCESS, false, "1 + 1", -1);
883
884 tstTryEx(pDbgc, "echo 0i10 + 6\n", VINF_SUCCESS, false, "10", -1);
885 tstTryEx(pDbgc, "echo \"0i10 + 6\"\n", VINF_SUCCESS, false, "0i10 + 6", -1);
886
887 tstTryEx(pDbgc, "echo %f000:0010\n", VINF_SUCCESS, false, "%00000000000f0010", -1);
888 tstTryEx(pDbgc, "echo \"%f000:0010\"\n", VINF_SUCCESS, false, "%f000:0010", -1);
889
890 tstTry(pDbgc, "echo %bad:bad\n", VERR_DBGC_PARSE_CONVERSION_FAILED);
891}
892
893
894static void testCommon_format(PDBGC pDbgc)
895{
896 RTTestISub("common - format");
897}
898
899
900static void testCommon_detect(PDBGC pDbgc)
901{
902 RTTestISub("common - detect");
903}
904
905
906static void testCommon_harakiri(PDBGC pDbgc)
907{
908 RTTestISub("common - harakiri");
909}
910
911
912static void testCommon_help(PDBGC pDbgc)
913{
914 RTTestISub("common - help");
915}
916
917
918static void testCommon_info(PDBGC pDbgc)
919{
920 RTTestISub("common - info");
921 tstTry(pDbgc, "info 12fg\n", VINF_SUCCESS);
922 tstTry(pDbgc, "info fflags argument\n", VINF_SUCCESS);
923}
924
925
926static void testCommon_loadimage(PDBGC pDbgc)
927{
928 RTTestISub("common - loadimage");
929}
930
931
932static void testCommon_loadmap(PDBGC pDbgc)
933{
934 RTTestISub("common - loadmap");
935}
936
937
938static void testCommon_loadplugin(PDBGC pDbgc)
939{
940 RTTestISub("common - loadplugin");
941}
942
943
944static void testCommon_loadseg(PDBGC pDbgc)
945{
946 RTTestISub("common - loadseg");
947}
948
949
950static void testCommon_loadsyms(PDBGC pDbgc)
951{
952 RTTestISub("common - loadsyms");
953}
954
955
956static void testCommon_loadvars(PDBGC pDbgc)
957{
958 RTTestISub("common - loadvars");
959}
960
961
962static void testCommon_log(PDBGC pDbgc)
963{
964 RTTestISub("common - log");
965}
966
967
968static void testCommon_logdest(PDBGC pDbgc)
969{
970 RTTestISub("common - logdest");
971}
972
973
974static void testCommon_logflags(PDBGC pDbgc)
975{
976 RTTestISub("common - logflags");
977}
978
979
980static void testCommon_runscript(PDBGC pDbgc)
981{
982 RTTestISub("common - runscript");
983}
984
985
986static void testCommon_set(PDBGC pDbgc)
987{
988 RTTestISub("common - set");
989}
990
991
992static void testCommon_showplugins(PDBGC pDbgc)
993{
994 RTTestISub("common - showplugins");
995}
996
997
998static void testCommon_showvars(PDBGC pDbgc)
999{
1000 RTTestISub("common - showvars");
1001}
1002
1003
1004static void testCommon_stop(PDBGC pDbgc)
1005{
1006 RTTestISub("common - stop");
1007}
1008
1009
1010static void testCommon_unloadplugin(PDBGC pDbgc)
1011{
1012 RTTestISub("common - unloadplugin");
1013}
1014
1015
1016static void testCommon_unset(PDBGC pDbgc)
1017{
1018 RTTestISub("common - unset");
1019}
1020
1021
1022static void testCommon_writecore(PDBGC pDbgc)
1023{
1024 RTTestISub("common - writecore");
1025}
1026
1027
1028
1029/*
1030 * Basic tests.
1031 */
1032
1033static void testBasicsOddCases(PDBGC pDbgc)
1034{
1035 RTTestISub("Odd cases");
1036 tstTry(pDbgc, "r @rax\n", VINF_SUCCESS);
1037 tstTry(pDbgc, "r @eax\n", VINF_SUCCESS);
1038 tstTry(pDbgc, "r @ah\n", VINF_SUCCESS);
1039 tstTry(pDbgc, "r @notavalidregister\n", VERR_DBGF_REGISTER_NOT_FOUND);
1040}
1041
1042
1043static void testBasicsOperators(PDBGC pDbgc)
1044{
1045 RTTestISub("Operators");
1046 tstNumOp(pDbgc, "1", 1);
1047 tstNumOp(pDbgc, "1", 1);
1048 tstNumOp(pDbgc, "1", 1);
1049
1050 tstNumOp(pDbgc, "+1", 1);
1051 tstNumOp(pDbgc, "++++++1", 1);
1052
1053 tstNumOp(pDbgc, "-1", UINT64_MAX);
1054 tstNumOp(pDbgc, "--1", 1);
1055 tstNumOp(pDbgc, "---1", UINT64_MAX);
1056 tstNumOp(pDbgc, "----1", 1);
1057
1058 tstNumOp(pDbgc, "~0", UINT64_MAX);
1059 tstNumOp(pDbgc, "~1", UINT64_MAX-1);
1060 tstNumOp(pDbgc, "~~0", 0);
1061 tstNumOp(pDbgc, "~~1", 1);
1062
1063 tstNumOp(pDbgc, "!1", 0);
1064 tstNumOp(pDbgc, "!0", 1);
1065 tstNumOp(pDbgc, "!42", 0);
1066 tstNumOp(pDbgc, "!!42", 1);
1067 tstNumOp(pDbgc, "!!!42", 0);
1068 tstNumOp(pDbgc, "!!!!42", 1);
1069
1070 tstNumOp(pDbgc, "1 +1", 2);
1071 tstNumOp(pDbgc, "1 + 1", 2);
1072 tstNumOp(pDbgc, "1+1", 2);
1073 tstNumOp(pDbgc, "1+ 1", 2);
1074
1075 tstNumOp(pDbgc, "1 - 1", 0);
1076 tstNumOp(pDbgc, "99 - 90", 9);
1077
1078 tstNumOp(pDbgc, "2 * 2", 4);
1079
1080 tstNumOp(pDbgc, "2 / 2", 1);
1081 tstNumOp(pDbgc, "2 / 0", UINT64_MAX);
1082 tstNumOp(pDbgc, "0i1024 / 0i4", 256);
1083
1084 tstNumOp(pDbgc, "8 mod 7", 1);
1085
1086 tstNumOp(pDbgc, "1<<1", 2);
1087 tstNumOp(pDbgc, "1<<0i32", UINT64_C(0x0000000100000000));
1088 tstNumOp(pDbgc, "1<<0i48", UINT64_C(0x0001000000000000));
1089 tstNumOp(pDbgc, "1<<0i63", UINT64_C(0x8000000000000000));
1090
1091 tstNumOp(pDbgc, "fedcba0987654321>>0i04", UINT64_C(0x0fedcba098765432));
1092 tstNumOp(pDbgc, "fedcba0987654321>>0i32", UINT64_C(0xfedcba09));
1093 tstNumOp(pDbgc, "fedcba0987654321>>0i48", UINT64_C(0x0000fedc));
1094
1095 tstNumOp(pDbgc, "0ef & 4", 4);
1096 tstNumOp(pDbgc, "01234567891 & fff", UINT64_C(0x00000000891));
1097 tstNumOp(pDbgc, "01234567891 & ~fff", UINT64_C(0x01234567000));
1098
1099 tstNumOp(pDbgc, "1 | 1", 1);
1100 tstNumOp(pDbgc, "0 | 4", 4);
1101 tstNumOp(pDbgc, "4 | 0", 4);
1102 tstNumOp(pDbgc, "4 | 4", 4);
1103 tstNumOp(pDbgc, "1 | 4 | 2", 7);
1104
1105 tstNumOp(pDbgc, "1 ^ 1", 0);
1106 tstNumOp(pDbgc, "1 ^ 0", 1);
1107 tstNumOp(pDbgc, "0 ^ 1", 1);
1108 tstNumOp(pDbgc, "3 ^ 1", 2);
1109 tstNumOp(pDbgc, "7 ^ 3", 4);
1110
1111 tstNumOp(pDbgc, "7 || 3", 1);
1112 tstNumOp(pDbgc, "1 || 0", 1);
1113 tstNumOp(pDbgc, "0 || 1", 1);
1114 tstNumOp(pDbgc, "0 || 0", 0);
1115
1116 tstNumOp(pDbgc, "0 && 0", 0);
1117 tstNumOp(pDbgc, "1 && 0", 0);
1118 tstNumOp(pDbgc, "0 && 1", 0);
1119 tstNumOp(pDbgc, "1 && 1", 1);
1120 tstNumOp(pDbgc, "4 && 1", 1);
1121}
1122
1123
1124static void testBasicsFundametalParsing(PDBGC pDbgc)
1125{
1126 RTTestISub("Fundamental parsing");
1127 tstTry(pDbgc, "stop\n", VINF_SUCCESS);
1128 tstTry(pDbgc, "format 1\n", VINF_SUCCESS);
1129 tstTry(pDbgc, "format \n", VERR_DBGC_PARSE_TOO_FEW_ARGUMENTS);
1130 tstTry(pDbgc, "format 0 1 23 4\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
1131 tstTry(pDbgc, "format 'x'\n", VINF_SUCCESS);
1132 tstTry(pDbgc, "format 'x' 'x'\n", VERR_DBGC_PARSE_TOO_MANY_ARGUMENTS);
1133 tstTry(pDbgc, "format 'x''x'\n", VINF_SUCCESS);
1134 tstTry(pDbgc, "format 'x'\"x\"\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
1135 tstTry(pDbgc, "format 'x'1\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
1136 tstTry(pDbgc, "format (1)1\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
1137 tstTry(pDbgc, "format (1)(1)\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
1138 tstTry(pDbgc, "format (1)''\n", VERR_DBGC_PARSE_EXPECTED_BINARY_OP);
1139 tstTry(pDbgc, "format nosuchfunction(1)\n", VERR_DBGC_PARSE_FUNCTION_NOT_FOUND);
1140 tstTry(pDbgc, "format nosuchfunction(1,2,3)\n", VERR_DBGC_PARSE_FUNCTION_NOT_FOUND);
1141 tstTry(pDbgc, "format nosuchfunction()\n", VERR_DBGC_PARSE_FUNCTION_NOT_FOUND);
1142 tstTry(pDbgc, "format randu32()\n", VINF_SUCCESS);
1143 tstTryEx(pDbgc, "format %0\n", VINF_SUCCESS, false, "Guest flat address: %00000000", -1);
1144 tstTryEx(pDbgc, "format %eax\n", VINF_SUCCESS, false, "Guest flat address: %cafebabe", -1);
1145 tstTry(pDbgc, "sa 3 23 4 'q' \"21123123\" 'b' \n", VINF_SUCCESS);
1146 tstTry(pDbgc, "sa 3,23, 4,'q' ,\"21123123\" , 'b' \n", VINF_SUCCESS);
1147}
1148
1149
1150int main()
1151{
1152 /*
1153 * Init.
1154 */
1155 int rc = RTTestInitAndCreate("tstDBGCParser", &g_hTest);
1156 if (rc)
1157 return rc;
1158 RTTestBanner(g_hTest);
1159
1160 /*
1161 * Create a DBGC instance.
1162 */
1163 RTTestSub(g_hTest, "dbgcCreate");
1164 PDBGC pDbgc;
1165 rc = dbgcCreate(&pDbgc, &g_tstBack, 0);
1166 if (RT_SUCCESS(rc))
1167 {
1168 pDbgc->pVM = (PVM)pDbgc;
1169 rc = dbgcProcessInput(pDbgc, true /* fNoExecute */);
1170 tstCompleteOutput();
1171 if (RT_SUCCESS(rc))
1172 {
1173 /*
1174 * Perform basic tests first.
1175 */
1176 testBasicsFundametalParsing(pDbgc);
1177 if (RTTestErrorCount(g_hTest) == 0)
1178 testBasicsOperators(pDbgc);
1179 if (RTTestErrorCount(g_hTest) == 0)
1180 testBasicsOddCases(pDbgc);
1181
1182 /*
1183 * Test commands.
1184 */
1185 if (RTTestErrorCount(g_hTest) == 0)
1186 {
1187 testCodeView_ba(pDbgc);
1188 testCodeView_bc(pDbgc);
1189 testCodeView_bd(pDbgc);
1190 testCodeView_be(pDbgc);
1191 testCodeView_bl(pDbgc);
1192 testCodeView_bp(pDbgc);
1193 testCodeView_br(pDbgc);
1194 testCodeView_d(pDbgc);
1195 testCodeView_da(pDbgc);
1196 testCodeView_db(pDbgc);
1197 testCodeView_dd(pDbgc);
1198 testCodeView_dg(pDbgc);
1199 testCodeView_dga(pDbgc);
1200 testCodeView_di(pDbgc);
1201 testCodeView_dia(pDbgc);
1202 testCodeView_dl(pDbgc);
1203 testCodeView_dla(pDbgc);
1204 testCodeView_dpd(pDbgc);
1205 testCodeView_dpda(pDbgc);
1206 testCodeView_dpdb(pDbgc);
1207 testCodeView_dpdg(pDbgc);
1208 testCodeView_dpdh(pDbgc);
1209 testCodeView_dph(pDbgc);
1210 testCodeView_dphg(pDbgc);
1211 testCodeView_dphh(pDbgc);
1212 testCodeView_dq(pDbgc);
1213 testCodeView_dt(pDbgc);
1214 testCodeView_dt16(pDbgc);
1215 testCodeView_dt32(pDbgc);
1216 testCodeView_dt64(pDbgc);
1217 testCodeView_dw(pDbgc);
1218 testCodeView_eb(pDbgc);
1219 testCodeView_ew(pDbgc);
1220 testCodeView_ed(pDbgc);
1221 testCodeView_eq(pDbgc);
1222 testCodeView_g(pDbgc);
1223 testCodeView_k(pDbgc);
1224 testCodeView_kg(pDbgc);
1225 testCodeView_kh(pDbgc);
1226 testCodeView_lm(pDbgc);
1227 testCodeView_lmo(pDbgc);
1228 testCodeView_ln(pDbgc);
1229 testCodeView_ls(pDbgc);
1230 testCodeView_m(pDbgc);
1231 testCodeView_r(pDbgc);
1232 testCodeView_rg(pDbgc);
1233 testCodeView_rg32(pDbgc);
1234 testCodeView_rg64(pDbgc);
1235 testCodeView_rh(pDbgc);
1236 testCodeView_rt(pDbgc);
1237 testCodeView_s(pDbgc);
1238 testCodeView_sa(pDbgc);
1239 testCodeView_sb(pDbgc);
1240 testCodeView_sd(pDbgc);
1241 testCodeView_sq(pDbgc);
1242 testCodeView_su(pDbgc);
1243 testCodeView_sw(pDbgc);
1244 testCodeView_t(pDbgc);
1245 testCodeView_y(pDbgc);
1246 testCodeView_u64(pDbgc);
1247 testCodeView_u32(pDbgc);
1248 testCodeView_u16(pDbgc);
1249 testCodeView_uv86(pDbgc);
1250
1251 testCommon_bye_exit_quit(pDbgc);
1252 testCommon_cpu(pDbgc);
1253 testCommon_echo(pDbgc);
1254 testCommon_format(pDbgc);
1255 testCommon_detect(pDbgc);
1256 testCommon_harakiri(pDbgc);
1257 testCommon_help(pDbgc);
1258 testCommon_info(pDbgc);
1259 testCommon_loadimage(pDbgc);
1260 testCommon_loadmap(pDbgc);
1261 testCommon_loadplugin(pDbgc);
1262 testCommon_loadseg(pDbgc);
1263 testCommon_loadsyms(pDbgc);
1264 testCommon_loadvars(pDbgc);
1265 testCommon_log(pDbgc);
1266 testCommon_logdest(pDbgc);
1267 testCommon_logflags(pDbgc);
1268 testCommon_runscript(pDbgc);
1269 testCommon_set(pDbgc);
1270 testCommon_showplugins(pDbgc);
1271 testCommon_showvars(pDbgc);
1272 testCommon_stop(pDbgc);
1273 testCommon_unloadplugin(pDbgc);
1274 testCommon_unset(pDbgc);
1275 testCommon_writecore(pDbgc);
1276 }
1277 }
1278
1279 dbgcDestroy(pDbgc);
1280 }
1281
1282 /*
1283 * Summary
1284 */
1285 return RTTestSummaryAndDestroy(g_hTest);
1286}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette