VirtualBox

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

Last change on this file since 31512 was 31510, checked in by vboxsync, 14 years ago

The debugger is back in the OSE.

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