VirtualBox

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

Last change on this file since 5730 was 5686, checked in by vboxsync, 17 years ago

Got the DBGC parser testcase framework going. enough fun for now.

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