VirtualBox

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

Last change on this file since 49221 was 44399, checked in by vboxsync, 12 years ago

DBGF,DBGC,++: PVM -> PUVM. Some refactoring and cleanup as well.

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