VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGCInternal.h@ 5681

Last change on this file since 5681 was 5676, checked in by vboxsync, 17 years ago

Split out the DBGCCMDHLP stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 KB
Line 
1/** $Id: DBGCInternal.h 5676 2007-11-11 05:50:06Z vboxsync $ */
2/** @file
3 * DBGC - Debugger Console, Internal Header File.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___DBGCInternal_h
19#define ___DBGCInternal_h
20
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <VBox/dbg.h>
26
27
28/*******************************************************************************
29* Defined Constants And Macros *
30*******************************************************************************/
31/* to err.h! */
32#define VERR_DBGC_QUIT (-11999)
33#define VERR_PARSE_FIRST (-11000)
34#define VERR_PARSE_TOO_FEW_ARGUMENTS (VERR_PARSE_FIRST - 0)
35#define VERR_PARSE_TOO_MANY_ARGUMENTS (VERR_PARSE_FIRST - 1)
36#define VERR_PARSE_ARGUMENT_OVERFLOW (VERR_PARSE_FIRST - 2)
37#define VERR_PARSE_ARGUMENT_TYPE_MISMATCH (VERR_PARSE_FIRST - 3)
38#define VERR_PARSE_NO_RANGE_ALLOWED (VERR_PARSE_FIRST - 4)
39#define VERR_PARSE_UNBALANCED_QUOTE (VERR_PARSE_FIRST - 5)
40#define VERR_PARSE_UNBALANCED_PARENTHESIS (VERR_PARSE_FIRST - 6)
41#define VERR_PARSE_EMPTY_ARGUMENT (VERR_PARSE_FIRST - 7)
42#define VERR_PARSE_UNEXPECTED_OPERATOR (VERR_PARSE_FIRST - 8)
43#define VERR_PARSE_INVALID_NUMBER (VERR_PARSE_FIRST - 9)
44#define VERR_PARSE_NUMBER_TOO_BIG (VERR_PARSE_FIRST - 10)
45#define VERR_PARSE_INVALID_OPERATION (VERR_PARSE_FIRST - 11)
46#define VERR_PARSE_FUNCTION_NOT_FOUND (VERR_PARSE_FIRST - 12)
47#define VERR_PARSE_NOT_A_FUNCTION (VERR_PARSE_FIRST - 13)
48#define VERR_PARSE_NO_MEMORY (VERR_PARSE_FIRST - 14)
49#define VERR_PARSE_INCORRECT_ARG_TYPE (VERR_PARSE_FIRST - 15)
50#define VERR_PARSE_VARIABLE_NOT_FOUND (VERR_PARSE_FIRST - 16)
51#define VERR_PARSE_CONVERSION_FAILED (VERR_PARSE_FIRST - 17)
52#define VERR_PARSE_NOT_IMPLEMENTED (VERR_PARSE_FIRST - 18)
53#define VERR_PARSE_BAD_RESULT_TYPE (VERR_PARSE_FIRST - 19)
54#define VERR_PARSE_WRITEONLY_SYMBOL (VERR_PARSE_FIRST - 20)
55#define VERR_PARSE_NO_ARGUMENT_MATCH (VERR_PARSE_FIRST - 21)
56#define VERR_PARSE_LAST (VERR_PARSE_FIRST - 30)
57
58#define VWRN_DBGC_CMD_PENDING 12000
59#define VWRN_DBGC_ALREADY_REGISTERED 12001
60#define VERR_DBGC_COMMANDS_NOT_REGISTERED (-12002)
61#define VERR_DBGC_BP_NOT_FOUND (-12003)
62#define VERR_DBGC_BP_EXISTS (-12004)
63#define VINF_DBGC_BP_NO_COMMAND 12005
64
65
66/*******************************************************************************
67* Structures and Typedefs *
68*******************************************************************************/
69
70/**
71 * Debugger console per breakpoint data.
72 */
73typedef struct DBGCBP
74{
75 /** Pointer to the next breakpoint in the list. */
76 struct DBGCBP *pNext;
77 /** The breakpoint identifier. */
78 RTUINT iBp;
79 /** The size of the command. */
80 size_t cchCmd;
81 /** The command to execute when the breakpoint is hit. */
82 char szCmd[1];
83} DBGCBP;
84/** Pointer to a breakpoint. */
85typedef DBGCBP *PDBGCBP;
86
87
88/**
89 * Named variable.
90 *
91 * Always allocated from heap in one signle block.
92 */
93typedef struct DBGCNAMEDVAR
94{
95 /** The variable. */
96 DBGCVAR Var;
97 /** It's name. */
98 char szName[1];
99} DBGCNAMEDVAR;
100/** Pointer to named variable. */
101typedef DBGCNAMEDVAR *PDBGCNAMEDVAR;
102
103
104/**
105 * Debugger console status
106 */
107typedef enum DBGCSTATUS
108{
109 /** Normal status, .*/
110 DBGC_HALTED
111
112} DBGCSTATUS;
113
114
115/**
116 * Debugger console instance data.
117 */
118typedef struct DBGC
119{
120 /** Command helpers. */
121 DBGCCMDHLP CmdHlp;
122 /** Pointer to backend callback structure. */
123 PDBGCBACK pBack;
124
125 /** Pointer to the current VM. */
126 PVM pVM;
127 /** The current debugger emulation. */
128 const char *pszEmulation;
129 /** Pointer to the command and functions for the current debugger emulation. */
130 PCDBGCCMD paEmulationCmds;
131 /** The number of commands paEmulationCmds points to. */
132 unsigned cEmulationCmds;
133 /** Log indicator. (If set we're writing the log to the console.) */
134 bool fLog;
135
136 /** Indicates whether we're in guest (true) or hypervisor (false) register context. */
137 bool fRegCtxGuest;
138 /** Indicates whether the register are terse or sparse. */
139 bool fRegTerse;
140
141 /** Current dissassembler position. */
142 DBGCVAR DisasmPos;
143 /** Current source position. (flat GC) */
144 DBGCVAR SourcePos;
145 /** Current memory dump position. */
146 DBGCVAR DumpPos;
147 /** Size of the previous dump element. */
148 unsigned cbDumpElement;
149
150 /** Number of variables in papVars. */
151 unsigned cVars;
152 /** Array of global variables.
153 * Global variables can be referenced using the $ operator and set
154 * and unset using command with those names. */
155 PDBGCNAMEDVAR *papVars;
156
157 /** The list of breakpoints. (singly linked) */
158 PDBGCBP pFirstBp;
159
160 /** @name Parsing and Execution
161 * @{ */
162
163 /** Input buffer. */
164 char achInput[2048];
165 /** To ease debugging. */
166 unsigned uInputZero;
167 /** Write index in the input buffer. */
168 unsigned iWrite;
169 /** Read index in the input buffer. */
170 unsigned iRead;
171 /** The number of lines in the buffer. */
172 unsigned cInputLines;
173 /** Indicates that we have a buffer overflow condition.
174 * This means that input is ignored up to the next newline. */
175 bool fInputOverflow;
176 /** Indicates whether or we're ready for input. */
177 bool fReady;
178
179 /** Scratch buffer position. */
180 char *pszScratch;
181 /** Scratch buffer. */
182 char achScratch[16384];
183 /** Argument array position. */
184 unsigned iArg;
185 /** Array of argument variables. */
186 DBGCVAR aArgs[100];
187
188 /** rc from last dbgcHlpPrintfV(). */
189 int rcOutput;
190
191 /** @} */
192} DBGC;
193/** Pointer to debugger console instance data. */
194typedef DBGC *PDBGC;
195
196/** Converts a Command Helper pointer to a pointer to DBGC instance data. */
197#define DBGC_CMDHLP2DBGC(pCmdHlp) ( (PDBGC)((uintptr_t)(pCmdHlp) - RT_OFFSETOF(DBGC, CmdHlp)) )
198
199
200/**
201 * Chunk of external commands.
202 */
203typedef struct DBGCEXTCMDS
204{
205 /** Number of commands descriptors. */
206 unsigned cCmds;
207 /** Pointer to array of command descriptors. */
208 PCDBGCCMD paCmds;
209 /** Pointer to the next chunk. */
210 struct DBGCEXTCMDS *pNext;
211} DBGCEXTCMDS;
212/** Pointer to chunk of external commands. */
213typedef DBGCEXTCMDS *PDBGCEXTCMDS;
214
215
216
217/**
218 * Unary operator handler function.
219 *
220 * @returns 0 on success.
221 * @returns VBox evaluation / parsing error code on failure.
222 * The caller does the bitching.
223 * @param pDbgc Debugger console instance data.
224 * @param pArg The argument.
225 * @param pResult Where to store the result.
226 */
227typedef DECLCALLBACK(int) FNDBGCOPUNARY(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult);
228/** Pointer to a unary operator handler function. */
229typedef FNDBGCOPUNARY *PFNDBGCOPUNARY;
230
231
232/**
233 * Binary operator handler function.
234 *
235 * @returns 0 on success.
236 * @returns VBox evaluation / parsing error code on failure.
237 * The caller does the bitching.
238 * @param pDbgc Debugger console instance data.
239 * @param pArg1 The first argument.
240 * @param pArg2 The 2nd argument.
241 * @param pResult Where to store the result.
242 */
243typedef DECLCALLBACK(int) FNDBGCOPBINARY(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
244/** Pointer to a binary operator handler function. */
245typedef FNDBGCOPBINARY *PFNDBGCOPBINARY;
246
247
248/**
249 * Operator descriptor.
250 */
251typedef struct DBGCOP
252{
253 /** Operator mnemonic. */
254 char szName[4];
255 /** Length of name. */
256 const unsigned cchName;
257 /** Whether or not this is a binary operator.
258 * Unary operators are evaluated right-to-left while binary are left-to-right. */
259 bool fBinary;
260 /** Precedence level. */
261 unsigned iPrecedence;
262 /** Unary operator handler. */
263 PFNDBGCOPUNARY pfnHandlerUnary;
264 /** Binary operator handler. */
265 PFNDBGCOPBINARY pfnHandlerBinary;
266 /** Operator description. */
267 const char *pszDescription;
268} DBGCOP;
269/** Pointer to an operator descriptor. */
270typedef DBGCOP *PDBGCOP;
271/** Pointer to a const operator descriptor. */
272typedef const DBGCOP *PCDBGCOP;
273
274
275
276/** Pointer to symbol descriptor. */
277typedef struct DBGCSYM *PDBGCSYM;
278/** Pointer to const symbol descriptor. */
279typedef const struct DBGCSYM *PCDBGCSYM;
280
281/**
282 * Get builtin symbol.
283 *
284 * @returns 0 on success.
285 * @returns VBox evaluation / parsing error code on failure.
286 * The caller does the bitching.
287 * @param pSymDesc Pointer to the symbol descriptor.
288 * @param pCmdHlp Pointer to the command callback structure.
289 * @param enmType The result type.
290 * @param pResult Where to store the result.
291 */
292typedef DECLCALLBACK(int) FNDBGCSYMGET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, DBGCVARTYPE enmType, PDBGCVAR pResult);
293/** Pointer to get function for a builtin symbol. */
294typedef FNDBGCSYMGET *PFNDBGCSYMGET;
295
296/**
297 * Set builtin symbol.
298 *
299 * @returns 0 on success.
300 * @returns VBox evaluation / parsing error code on failure.
301 * The caller does the bitching.
302 * @param pSymDesc Pointer to the symbol descriptor.
303 * @param pCmdHlp Pointer to the command callback structure.
304 * @param pValue The value to assign the symbol.
305 */
306typedef DECLCALLBACK(int) FNDBGCSYMSET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, PCDBGCVAR pValue);
307/** Pointer to set function for a builtin symbol. */
308typedef FNDBGCSYMSET *PFNDBGCSYMSET;
309
310
311/**
312 * Symbol description (for builtin symbols).
313 */
314typedef struct DBGCSYM
315{
316 /** Symbol name. */
317 const char *pszName;
318 /** Get function. */
319 PFNDBGCSYMGET pfnGet;
320 /** Set function. (NULL if readonly) */
321 PFNDBGCSYMSET pfnSet;
322 /** User data. */
323 unsigned uUser;
324} DBGCSYM;
325
326
327/*******************************************************************************
328* Internal Functions *
329*******************************************************************************/
330int dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
331int dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
332int dbgcBpDelete(PDBGC pDbgc, RTUINT iBp);
333PDBGCBP dbgcBpGet(PDBGC pDbgc, RTUINT iBp);
334int dbgcBpExec(PDBGC pDbgc, RTUINT iBp);
335
336void dbgcVarSetGCFlat(PDBGCVAR pVar, RTGCPTR GCFlat);
337void dbgcVarSetGCFlatByteRange(PDBGCVAR pVar, RTGCPTR GCFlat, uint64_t cb);
338void dbgcVarSetVar(PDBGCVAR pVar, PCDBGCVAR pVar2);
339void dbgcVarSetNoRange(PDBGCVAR pVar);
340void dbgcVarSetByteRange(PDBGCVAR pVar, uint64_t cb);
341int dbgcVarToDbgfAddr(PDBGC pDbgc, PCDBGCVAR pVar, PDBGFADDRESS pAddress);
342
343int dbgcEvalSub(PDBGC pDbgc, char *pszExpr, size_t cchExpr, PDBGCVAR pResult);
344int dbgcProcessCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd);
345
346int dbgcSymbolGet(PDBGC pDbgc, const char *pszSymbol, DBGCVARTYPE enmType, PDBGCVAR pResult);
347PCDBGCSYM dbgcLookupRegisterSymbol(PDBGC pDbgc, const char *pszSymbol);
348PCDBGCOP dbgcOperatorLookup(PDBGC pDbgc, const char *pszExpr, bool fPreferBinary, char chPrev);
349PCDBGCCMD dbgcRoutineLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal);
350
351DECLCALLBACK(int) dbgcOpAddrFlat(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult);
352DECLCALLBACK(int) dbgcOpAddrHost(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult);
353DECLCALLBACK(int) dbgcOpAddrPhys(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult);
354DECLCALLBACK(int) dbgcOpAddrHostPhys(PDBGC pDbgc, PCDBGCVAR pArg, PDBGCVAR pResult);
355
356void dbgcInitCmdHlp(PDBGC pDbgc);
357
358
359/*******************************************************************************
360* Global Variables *
361*******************************************************************************/
362extern const DBGCCMD g_aCmds[];
363extern const unsigned g_cCmds;
364extern const DBGCCMD g_aCmdsCodeView[];
365extern const unsigned g_cCmdsCodeView;
366extern const DBGCOP g_aOps[];
367extern const unsigned g_cOps;
368
369
370#endif
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