VirtualBox

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

Last change on this file since 43421 was 41561, checked in by vboxsync, 12 years ago

DBGC: Made the parse cope with functions.

  • 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 41561 2012-06-04 12:10:19Z vboxsync $ */
2/** @file
3 * DBGC - Debugger Console, Internal Header File.
4 */
5
6/*
7 * Copyright (C) 2006-2011 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#ifndef ___Debugger_DBGCInternal_h
20#define ___Debugger_DBGCInternal_h
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <VBox/dbg.h>
27#include <VBox/err.h>
28
29
30/*******************************************************************************
31* Structures and Typedefs *
32*******************************************************************************/
33
34/**
35 * Debugger console per breakpoint data.
36 */
37typedef struct DBGCBP
38{
39 /** Pointer to the next breakpoint in the list. */
40 struct DBGCBP *pNext;
41 /** The breakpoint identifier. */
42 uint32_t iBp;
43 /** The size of the command. */
44 size_t cchCmd;
45 /** The command to execute when the breakpoint is hit. */
46 char szCmd[1];
47} DBGCBP;
48/** Pointer to a breakpoint. */
49typedef DBGCBP *PDBGCBP;
50
51
52/**
53 * Named variable.
54 *
55 * Always allocated from heap in one single block.
56 */
57typedef struct DBGCNAMEDVAR
58{
59 /** The variable. */
60 DBGCVAR Var;
61 /** Its name. */
62 char szName[1];
63} DBGCNAMEDVAR;
64/** Pointer to named variable. */
65typedef DBGCNAMEDVAR *PDBGCNAMEDVAR;
66
67
68/** The max length of a plug-in name, zero terminator included. */
69#define DBGCPLUGIN_MAX_NAME 32
70
71/**
72 * Plug-in tracking record.
73 */
74typedef struct DBGCPLUGIN
75{
76 /** Pointer to the next plug-in. */
77 struct DBGCPLUGIN *pNext;
78 /** The loader handle. */
79 RTLDRMOD hLdrMod;
80 /** The plug-in entry point. */
81 PFNDBGCPLUGIN pfnEntry;
82 /** The plug-in name (variable length). */
83 char szName[DBGCPLUGIN_MAX_NAME];
84} DBGCPLUGIN;
85/** Pointer to plug-in tracking record. */
86typedef DBGCPLUGIN *PDBGCPLUGIN;
87
88
89/**
90 * Debugger console status
91 */
92typedef enum DBGCSTATUS
93{
94 /** Normal status, .*/
95 DBGC_HALTED
96
97} DBGCSTATUS;
98
99
100/**
101 * Debugger console instance data.
102 */
103typedef struct DBGC
104{
105 /** Command helpers. */
106 DBGCCMDHLP CmdHlp;
107 /** Wrappers for DBGF output. */
108 DBGFINFOHLP DbgfOutputHlp;
109 /** Pointer to backend callback structure. */
110 PDBGCBACK pBack;
111
112 /** Pointer to the current VM. */
113 PVM pVM;
114 /** The ID of current virtual CPU. */
115 VMCPUID idCpu;
116 /** The current address space handle. */
117 RTDBGAS hDbgAs;
118 /** The current debugger emulation. */
119 const char *pszEmulation;
120 /** Pointer to the commands for the current debugger emulation. */
121 PCDBGCCMD paEmulationCmds;
122 /** The number of commands paEmulationCmds points to. */
123 unsigned cEmulationCmds;
124 /** Pointer to the functions for the current debugger emulation. */
125 PCDBGCFUNC paEmulationFuncs;
126 /** The number of functions paEmulationFuncs points to. */
127 uint32_t cEmulationFuncs;
128 /** Log indicator. (If set we're writing the log to the console.) */
129 bool fLog;
130
131 /** Indicates whether we're in guest (true) or hypervisor (false) register context. */
132 bool fRegCtxGuest;
133 /** Indicates whether the register are terse or sparse. */
134 bool fRegTerse;
135 /** Counter use to suppress the printing of the headers. */
136 uint8_t cPagingHierarchyDumps;
137
138 /** Current disassembler position. */
139 DBGCVAR DisasmPos;
140 /** Current source position. (flat GC) */
141 DBGCVAR SourcePos;
142 /** Current memory dump position. */
143 DBGCVAR DumpPos;
144 /** Size of the previous dump element. */
145 unsigned cbDumpElement;
146 /** Points to DisasmPos, SourcePos or DumpPos depending on which was
147 * used last. */
148 PCDBGCVAR pLastPos;
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 plug-in. (singly linked) */
158 PDBGCPLUGIN pPlugInHead;
159
160 /** The list of breakpoints. (singly linked) */
161 PDBGCBP pFirstBp;
162
163 /** Save search pattern. */
164 uint8_t abSearch[256];
165 /** The length of the search pattern. */
166 uint32_t cbSearch;
167 /** The search unit */
168 uint32_t cbSearchUnit;
169 /** The max hits. */
170 uint64_t cMaxSearchHits;
171 /** The address to resume searching from. */
172 DBGFADDRESS SearchAddr;
173 /** What's left of the original search range. */
174 RTGCUINTPTR cbSearchRange;
175
176 /** @name Parsing and Execution
177 * @{ */
178
179 /** Input buffer. */
180 char achInput[2048];
181 /** To ease debugging. */
182 unsigned uInputZero;
183 /** Write index in the input buffer. */
184 unsigned iWrite;
185 /** Read index in the input buffer. */
186 unsigned iRead;
187 /** The number of lines in the buffer. */
188 unsigned cInputLines;
189 /** Indicates that we have a buffer overflow condition.
190 * This means that input is ignored up to the next newline. */
191 bool fInputOverflow;
192 /** Indicates whether or we're ready for input. */
193 bool fReady;
194 /** Scratch buffer position. */
195 char *pszScratch;
196 /** Scratch buffer. */
197 char achScratch[16384];
198 /** Argument array position. */
199 unsigned iArg;
200 /** Array of argument variables. */
201 DBGCVAR aArgs[100];
202
203 /** rc from the last dbgcHlpPrintfV(). */
204 int rcOutput;
205 /** The last character we wrote. */
206 char chLastOutput;
207
208 /** rc from the last command. */
209 int rcCmd;
210 /** @} */
211} DBGC;
212/** Pointer to debugger console instance data. */
213typedef DBGC *PDBGC;
214
215/** Converts a Command Helper pointer to a pointer to DBGC instance data. */
216#define DBGC_CMDHLP2DBGC(pCmdHlp) ( (PDBGC)((uintptr_t)(pCmdHlp) - RT_OFFSETOF(DBGC, CmdHlp)) )
217
218
219/**
220 * Chunk of external commands.
221 */
222typedef struct DBGCEXTCMDS
223{
224 /** Number of commands descriptors. */
225 unsigned cCmds;
226 /** Pointer to array of command descriptors. */
227 PCDBGCCMD paCmds;
228 /** Pointer to the next chunk. */
229 struct DBGCEXTCMDS *pNext;
230} DBGCEXTCMDS;
231/** Pointer to chunk of external commands. */
232typedef DBGCEXTCMDS *PDBGCEXTCMDS;
233
234
235/**
236 * Chunk of external functions.
237 */
238typedef struct DBGCEXTFUNCS
239{
240 /** Number of functions descriptors. */
241 uint32_t cFuncs;
242 /** Pointer to array of functions descriptors. */
243 PCDBGCFUNC paFuncs;
244 /** Pointer to the next chunk. */
245 struct DBGCEXTFUNCS *pNext;
246} DBGCEXTFUNCS;
247/** Pointer to chunk of external functions. */
248typedef DBGCEXTFUNCS *PDBGCEXTFUNCS;
249
250
251
252/**
253 * Unary operator handler function.
254 *
255 * @returns 0 on success.
256 * @returns VBox evaluation / parsing error code on failure.
257 * The caller does the bitching.
258 * @param pDbgc Debugger console instance data.
259 * @param pArg The argument.
260 * @param enmCat The desired result category. Can be ignored.
261 * @param pResult Where to store the result.
262 */
263typedef DECLCALLBACK(int) FNDBGCOPUNARY(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
264/** Pointer to a unary operator handler function. */
265typedef FNDBGCOPUNARY *PFNDBGCOPUNARY;
266
267
268/**
269 * Binary operator handler function.
270 *
271 * @returns 0 on success.
272 * @returns VBox evaluation / parsing error code on failure.
273 * The caller does the bitching.
274 * @param pDbgc Debugger console instance data.
275 * @param pArg1 The first argument.
276 * @param pArg2 The 2nd argument.
277 * @param pResult Where to store the result.
278 */
279typedef DECLCALLBACK(int) FNDBGCOPBINARY(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
280/** Pointer to a binary operator handler function. */
281typedef FNDBGCOPBINARY *PFNDBGCOPBINARY;
282
283
284/**
285 * Operator descriptor.
286 */
287typedef struct DBGCOP
288{
289 /** Operator mnemonic. */
290 char szName[4];
291 /** Length of name. */
292 const unsigned cchName;
293 /** Whether or not this is a binary operator.
294 * Unary operators are evaluated right-to-left while binary are left-to-right. */
295 bool fBinary;
296 /** Precedence level. */
297 unsigned iPrecedence;
298 /** Unary operator handler. */
299 PFNDBGCOPUNARY pfnHandlerUnary;
300 /** Binary operator handler. */
301 PFNDBGCOPBINARY pfnHandlerBinary;
302 /** The category of the 1st argument.
303 * Set to DBGCVAR_CAT_ANY if anything goes. */
304 DBGCVARCAT enmCatArg1;
305 /** The category of the 2nd argument.
306 * Set to DBGCVAR_CAT_ANY if anything goes. */
307 DBGCVARCAT enmCatArg2;
308 /** Operator description. */
309 const char *pszDescription;
310} DBGCOP;
311/** Pointer to an operator descriptor. */
312typedef DBGCOP *PDBGCOP;
313/** Pointer to a const operator descriptor. */
314typedef const DBGCOP *PCDBGCOP;
315
316
317
318/** Pointer to symbol descriptor. */
319typedef struct DBGCSYM *PDBGCSYM;
320/** Pointer to const symbol descriptor. */
321typedef const struct DBGCSYM *PCDBGCSYM;
322
323/**
324 * Get builtin symbol.
325 *
326 * @returns 0 on success.
327 * @returns VBox evaluation / parsing error code on failure.
328 * The caller does the bitching.
329 * @param pSymDesc Pointer to the symbol descriptor.
330 * @param pCmdHlp Pointer to the command callback structure.
331 * @param enmType The result type.
332 * @param pResult Where to store the result.
333 */
334typedef DECLCALLBACK(int) FNDBGCSYMGET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, DBGCVARTYPE enmType, PDBGCVAR pResult);
335/** Pointer to get function for a builtin symbol. */
336typedef FNDBGCSYMGET *PFNDBGCSYMGET;
337
338/**
339 * Set builtin symbol.
340 *
341 * @returns 0 on success.
342 * @returns VBox evaluation / parsing error code on failure.
343 * The caller does the bitching.
344 * @param pSymDesc Pointer to the symbol descriptor.
345 * @param pCmdHlp Pointer to the command callback structure.
346 * @param pValue The value to assign the symbol.
347 */
348typedef DECLCALLBACK(int) FNDBGCSYMSET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, PCDBGCVAR pValue);
349/** Pointer to set function for a builtin symbol. */
350typedef FNDBGCSYMSET *PFNDBGCSYMSET;
351
352
353/**
354 * Symbol description (for builtin symbols).
355 */
356typedef struct DBGCSYM
357{
358 /** Symbol name. */
359 const char *pszName;
360 /** Get function. */
361 PFNDBGCSYMGET pfnGet;
362 /** Set function. (NULL if readonly) */
363 PFNDBGCSYMSET pfnSet;
364 /** User data. */
365 unsigned uUser;
366} DBGCSYM;
367
368
369/*******************************************************************************
370* Internal Functions *
371*******************************************************************************/
372int dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
373int dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
374int dbgcBpDelete(PDBGC pDbgc, RTUINT iBp);
375PDBGCBP dbgcBpGet(PDBGC pDbgc, RTUINT iBp);
376int dbgcBpExec(PDBGC pDbgc, RTUINT iBp);
377
378void dbgcEvalInit(void);
379int dbgcEvalSub(PDBGC pDbgc, char *pszExpr, size_t cchExpr, DBGCVARCAT enmCategory, PDBGCVAR pResult);
380int dbgcEvalCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd, bool fNoExecute);
381
382int dbgcSymbolGet(PDBGC pDbgc, const char *pszSymbol, DBGCVARTYPE enmType, PDBGCVAR pResult);
383PCDBGCSYM dbgcLookupRegisterSymbol(PDBGC pDbgc, const char *pszSymbol);
384PCDBGCOP dbgcOperatorLookup(PDBGC pDbgc, const char *pszExpr, bool fPreferBinary, char chPrev);
385PCDBGCCMD dbgcCommandLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal);
386PCDBGCFUNC dbgcFunctionLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal);
387
388DECLCALLBACK(int) dbgcOpRegister(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
389DECLCALLBACK(int) dbgcOpAddrFlat(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
390DECLCALLBACK(int) dbgcOpAddrHost(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
391DECLCALLBACK(int) dbgcOpAddrPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
392DECLCALLBACK(int) dbgcOpAddrHostPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
393
394void dbgcInitCmdHlp(PDBGC pDbgc);
395
396void dbgcPlugInAutoLoad(PDBGC pDbgc);
397void dbgcPlugInUnloadAll(PDBGC pDbgc);
398
399/* For tstDBGCParser: */
400int dbgcCreate(PDBGC *ppDbgc, PDBGCBACK pBack, unsigned fFlags);
401int dbgcRun(PDBGC pDbgc);
402int dbgcProcessInput(PDBGC pDbgc, bool fNoExecute);
403void dbgcDestroy(PDBGC pDbgc);
404
405
406/*******************************************************************************
407* Global Variables *
408*******************************************************************************/
409extern const DBGCCMD g_aDbgcCmds[];
410extern const uint32_t g_cDbgcCmds;
411extern const DBGCFUNC g_aDbgcFuncs[];
412extern const uint32_t g_cDbgcFuncs;
413extern const DBGCCMD g_aCmdsCodeView[];
414extern const uint32_t g_cCmdsCodeView;
415extern const DBGCFUNC g_aFuncsCodeView[];
416extern const uint32_t g_cFuncsCodeView;
417extern const DBGCOP g_aDbgcOps[];
418extern const uint32_t g_cDbgcOps;
419
420
421/*******************************************************************************
422* Defined Constants And Macros *
423*******************************************************************************/
424/** Locks the g_pExtCmdsHead and g_pExtFuncsHead lists for reading. */
425#define DBGCEXTLISTS_LOCK_RD() do { } while (0)
426/** Locks the g_pExtCmdsHead and g_pExtFuncsHead lists for writing. */
427#define DBGCEXTLISTS_LOCK_WR() do { } while (0)
428/** UnLocks the g_pExtCmdsHead and g_pExtFuncsHead lists after reading. */
429#define DBGCEXTLISTS_UNLOCK_RD() do { } while (0)
430/** UnLocks the g_pExtCmdsHead and g_pExtFuncsHead lists after writing. */
431#define DBGCEXTLISTS_UNLOCK_WR() do { } while (0)
432
433
434
435#endif
436
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use