1 | /* $Id: DBGCFunctions.cpp 62480 2016-07-22 18:29:41Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGC - Debugger Console, Native Functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 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 | #define LOG_GROUP LOG_GROUP_DBGC
|
---|
23 | #include <VBox/dbg.h>
|
---|
24 | #include <VBox/vmm/dbgf.h>
|
---|
25 | #include <VBox/err.h>
|
---|
26 | #include <VBox/log.h>
|
---|
27 |
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/rand.h>
|
---|
30 | #include <iprt/string.h>
|
---|
31 |
|
---|
32 | #include "DBGCInternal.h"
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | /*********************************************************************************************************************************
|
---|
37 | * Global Variables *
|
---|
38 | *********************************************************************************************************************************/
|
---|
39 | /** Pointer to head of the list of exteranl functions. */
|
---|
40 | static PDBGCEXTFUNCS g_pExtFuncsHead;
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * @callback_method_impl{FNDBGCFUNC, The randu32() function implementation.}
|
---|
47 | */
|
---|
48 | static DECLCALLBACK(int) dbgcFuncRandU32(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
49 | PDBGCVAR pResult)
|
---|
50 | {
|
---|
51 | AssertReturn(cArgs == 0, VERR_DBGC_PARSE_BUG);
|
---|
52 | uint32_t u32 = RTRandU32();
|
---|
53 | DBGCVAR_INIT_NUMBER(pResult, u32);
|
---|
54 | NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM); NOREF(paArgs);
|
---|
55 | return VINF_SUCCESS;
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /** Functions descriptors for the basic functions. */
|
---|
60 | const DBGCFUNC g_aDbgcFuncs[] =
|
---|
61 | {
|
---|
62 | /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
|
---|
63 | { "randu32", 0, 0, NULL, 0, 0, dbgcFuncRandU32, "", "Returns an unsigned 32-bit random number." },
|
---|
64 | };
|
---|
65 |
|
---|
66 | /** The number of function descriptions in g_aDbgcFuncs. */
|
---|
67 | const uint32_t g_cDbgcFuncs = RT_ELEMENTS(g_aDbgcFuncs);
|
---|
68 |
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Looks up a function.
|
---|
72 | *
|
---|
73 | * @returns Pointer to the function descriptor on success, NULL if not found.
|
---|
74 | * @param pDbgc The DBGC instance.
|
---|
75 | * @param pachName The first charater in the name.
|
---|
76 | * @param cchName The length of the function name.
|
---|
77 | * @param fExternal Whether it's an external function.
|
---|
78 | */
|
---|
79 | PCDBGCFUNC dbgcFunctionLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal)
|
---|
80 | {
|
---|
81 | if (!fExternal)
|
---|
82 | {
|
---|
83 | /* emulation first, so commands can be overloaded (info ++). */
|
---|
84 | PCDBGCFUNC pFunc = pDbgc->paEmulationFuncs;
|
---|
85 | uint32_t cLeft = pDbgc->cEmulationFuncs;
|
---|
86 | while (cLeft-- > 0)
|
---|
87 | {
|
---|
88 | if ( !strncmp(pachName, pFunc->pszFuncNm, cchName)
|
---|
89 | && !pFunc->pszFuncNm[cchName])
|
---|
90 | return pFunc;
|
---|
91 | pFunc++;
|
---|
92 | }
|
---|
93 |
|
---|
94 | for (uint32_t iFunc = 0; iFunc < RT_ELEMENTS(g_aDbgcFuncs); iFunc++)
|
---|
95 | {
|
---|
96 | if ( !strncmp(pachName, g_aDbgcFuncs[iFunc].pszFuncNm, cchName)
|
---|
97 | && !g_aDbgcFuncs[iFunc].pszFuncNm[cchName])
|
---|
98 | return &g_aDbgcFuncs[iFunc];
|
---|
99 | }
|
---|
100 | }
|
---|
101 | else
|
---|
102 | {
|
---|
103 | DBGCEXTLISTS_LOCK_RD();
|
---|
104 | for (PDBGCEXTFUNCS pExtFuncs = g_pExtFuncsHead; pExtFuncs; pExtFuncs = pExtFuncs->pNext)
|
---|
105 | {
|
---|
106 | for (uint32_t iFunc = 0; iFunc < pExtFuncs->cFuncs; iFunc++)
|
---|
107 | {
|
---|
108 | if ( !strncmp(pachName, pExtFuncs->paFuncs[iFunc].pszFuncNm, cchName)
|
---|
109 | && !pExtFuncs->paFuncs[iFunc].pszFuncNm[cchName])
|
---|
110 | return &pExtFuncs->paFuncs[iFunc];
|
---|
111 | }
|
---|
112 | }
|
---|
113 | DBGCEXTLISTS_UNLOCK_RD();
|
---|
114 | }
|
---|
115 |
|
---|
116 | return NULL;
|
---|
117 | }
|
---|
118 |
|
---|