VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGCFunctions.cpp@ 99771

Last change on this file since 99771 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: DBGCFunctions.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * DBGC - Debugger Console, Native Functions.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DBGC
33#include <VBox/dbg.h>
34#include <VBox/vmm/dbgf.h>
35#include <VBox/err.h>
36#include <VBox/log.h>
37
38#include <iprt/assert.h>
39#include <iprt/rand.h>
40#include <iprt/string.h>
41
42#include "DBGCInternal.h"
43
44
45
46/*********************************************************************************************************************************
47* Global Variables *
48*********************************************************************************************************************************/
49/** Pointer to head of the list of exteranl functions. */
50static PDBGCEXTFUNCS g_pExtFuncsHead;
51
52
53
54
55/**
56 * @callback_method_impl{FNDBGCFUNC, The randu32() function implementation.}
57 */
58static DECLCALLBACK(int) dbgcFuncRandU32(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
59 PDBGCVAR pResult)
60{
61 AssertReturn(cArgs == 0, VERR_DBGC_PARSE_BUG);
62 uint32_t u32 = RTRandU32();
63 DBGCVAR_INIT_NUMBER(pResult, u32);
64 NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM); NOREF(paArgs);
65 return VINF_SUCCESS;
66}
67
68
69/** Functions descriptors for the basic functions. */
70const DBGCFUNC g_aDbgcFuncs[] =
71{
72 /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
73 { "randu32", 0, 0, NULL, 0, 0, dbgcFuncRandU32, "", "Returns an unsigned 32-bit random number." },
74};
75
76/** The number of function descriptions in g_aDbgcFuncs. */
77const uint32_t g_cDbgcFuncs = RT_ELEMENTS(g_aDbgcFuncs);
78
79
80/**
81 * Looks up a function.
82 *
83 * @returns Pointer to the function descriptor on success, NULL if not found.
84 * @param pDbgc The DBGC instance.
85 * @param pachName The first charater in the name.
86 * @param cchName The length of the function name.
87 * @param fExternal Whether it's an external function.
88 */
89PCDBGCFUNC dbgcFunctionLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal)
90{
91 if (!fExternal)
92 {
93 /* emulation first, so commands can be overloaded (info ++). */
94 PCDBGCFUNC pFunc = pDbgc->paEmulationFuncs;
95 uint32_t cLeft = pDbgc->cEmulationFuncs;
96 while (cLeft-- > 0)
97 {
98 if ( !strncmp(pachName, pFunc->pszFuncNm, cchName)
99 && !pFunc->pszFuncNm[cchName])
100 return pFunc;
101 pFunc++;
102 }
103
104 for (uint32_t iFunc = 0; iFunc < RT_ELEMENTS(g_aDbgcFuncs); iFunc++)
105 {
106 if ( !strncmp(pachName, g_aDbgcFuncs[iFunc].pszFuncNm, cchName)
107 && !g_aDbgcFuncs[iFunc].pszFuncNm[cchName])
108 return &g_aDbgcFuncs[iFunc];
109 }
110 }
111 else
112 {
113 DBGCEXTLISTS_LOCK_RD();
114 for (PDBGCEXTFUNCS pExtFuncs = g_pExtFuncsHead; pExtFuncs; pExtFuncs = pExtFuncs->pNext)
115 {
116 for (uint32_t iFunc = 0; iFunc < pExtFuncs->cFuncs; iFunc++)
117 {
118 if ( !strncmp(pachName, pExtFuncs->paFuncs[iFunc].pszFuncNm, cchName)
119 && !pExtFuncs->paFuncs[iFunc].pszFuncNm[cchName])
120 return &pExtFuncs->paFuncs[iFunc];
121 }
122 }
123 DBGCEXTLISTS_UNLOCK_RD();
124 }
125
126 return NULL;
127}
128
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