1 | /* $Id: DBGCInternal.h 41553 2012-06-02 20:11:07Z 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 | */
|
---|
37 | typedef 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. */
|
---|
49 | typedef DBGCBP *PDBGCBP;
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Named variable.
|
---|
54 | *
|
---|
55 | * Always allocated from heap in one single block.
|
---|
56 | */
|
---|
57 | typedef struct DBGCNAMEDVAR
|
---|
58 | {
|
---|
59 | /** The variable. */
|
---|
60 | DBGCVAR Var;
|
---|
61 | /** Its name. */
|
---|
62 | char szName[1];
|
---|
63 | } DBGCNAMEDVAR;
|
---|
64 | /** Pointer to named variable. */
|
---|
65 | typedef 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 | */
|
---|
74 | typedef 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. */
|
---|
86 | typedef DBGCPLUGIN *PDBGCPLUGIN;
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Debugger console status
|
---|
91 | */
|
---|
92 | typedef enum DBGCSTATUS
|
---|
93 | {
|
---|
94 | /** Normal status, .*/
|
---|
95 | DBGC_HALTED
|
---|
96 |
|
---|
97 | } DBGCSTATUS;
|
---|
98 |
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Debugger console instance data.
|
---|
102 | */
|
---|
103 | typedef 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 command and functions for the current debugger emulation. */
|
---|
121 | PCDBGCCMD paEmulationCmds;
|
---|
122 | /** The number of commands paEmulationCmds points to. */
|
---|
123 | unsigned cEmulationCmds;
|
---|
124 | /** Log indicator. (If set we're writing the log to the console.) */
|
---|
125 | bool fLog;
|
---|
126 |
|
---|
127 | /** Indicates whether we're in guest (true) or hypervisor (false) register context. */
|
---|
128 | bool fRegCtxGuest;
|
---|
129 | /** Indicates whether the register are terse or sparse. */
|
---|
130 | bool fRegTerse;
|
---|
131 | /** Counter use to suppress the printing of the headers. */
|
---|
132 | uint8_t cPagingHierarchyDumps;
|
---|
133 |
|
---|
134 | /** Current disassembler position. */
|
---|
135 | DBGCVAR DisasmPos;
|
---|
136 | /** Current source position. (flat GC) */
|
---|
137 | DBGCVAR SourcePos;
|
---|
138 | /** Current memory dump position. */
|
---|
139 | DBGCVAR DumpPos;
|
---|
140 | /** Size of the previous dump element. */
|
---|
141 | unsigned cbDumpElement;
|
---|
142 | /** Points to DisasmPos, SourcePos or DumpPos depending on which was
|
---|
143 | * used last. */
|
---|
144 | PCDBGCVAR pLastPos;
|
---|
145 |
|
---|
146 | /** Number of variables in papVars. */
|
---|
147 | unsigned cVars;
|
---|
148 | /** Array of global variables.
|
---|
149 | * Global variables can be referenced using the $ operator and set
|
---|
150 | * and unset using command with those names. */
|
---|
151 | PDBGCNAMEDVAR *papVars;
|
---|
152 |
|
---|
153 | /** The list of plug-in. (singly linked) */
|
---|
154 | PDBGCPLUGIN pPlugInHead;
|
---|
155 |
|
---|
156 | /** The list of breakpoints. (singly linked) */
|
---|
157 | PDBGCBP pFirstBp;
|
---|
158 |
|
---|
159 | /** Save search pattern. */
|
---|
160 | uint8_t abSearch[256];
|
---|
161 | /** The length of the search pattern. */
|
---|
162 | uint32_t cbSearch;
|
---|
163 | /** The search unit */
|
---|
164 | uint32_t cbSearchUnit;
|
---|
165 | /** The max hits. */
|
---|
166 | uint64_t cMaxSearchHits;
|
---|
167 | /** The address to resume searching from. */
|
---|
168 | DBGFADDRESS SearchAddr;
|
---|
169 | /** What's left of the original search range. */
|
---|
170 | RTGCUINTPTR cbSearchRange;
|
---|
171 |
|
---|
172 | /** @name Parsing and Execution
|
---|
173 | * @{ */
|
---|
174 |
|
---|
175 | /** Input buffer. */
|
---|
176 | char achInput[2048];
|
---|
177 | /** To ease debugging. */
|
---|
178 | unsigned uInputZero;
|
---|
179 | /** Write index in the input buffer. */
|
---|
180 | unsigned iWrite;
|
---|
181 | /** Read index in the input buffer. */
|
---|
182 | unsigned iRead;
|
---|
183 | /** The number of lines in the buffer. */
|
---|
184 | unsigned cInputLines;
|
---|
185 | /** Indicates that we have a buffer overflow condition.
|
---|
186 | * This means that input is ignored up to the next newline. */
|
---|
187 | bool fInputOverflow;
|
---|
188 | /** Indicates whether or we're ready for input. */
|
---|
189 | bool fReady;
|
---|
190 | /** Scratch buffer position. */
|
---|
191 | char *pszScratch;
|
---|
192 | /** Scratch buffer. */
|
---|
193 | char achScratch[16384];
|
---|
194 | /** Argument array position. */
|
---|
195 | unsigned iArg;
|
---|
196 | /** Array of argument variables. */
|
---|
197 | DBGCVAR aArgs[100];
|
---|
198 |
|
---|
199 | /** rc from the last dbgcHlpPrintfV(). */
|
---|
200 | int rcOutput;
|
---|
201 | /** The last character we wrote. */
|
---|
202 | char chLastOutput;
|
---|
203 |
|
---|
204 | /** rc from the last command. */
|
---|
205 | int rcCmd;
|
---|
206 | /** @} */
|
---|
207 | } DBGC;
|
---|
208 | /** Pointer to debugger console instance data. */
|
---|
209 | typedef DBGC *PDBGC;
|
---|
210 |
|
---|
211 | /** Converts a Command Helper pointer to a pointer to DBGC instance data. */
|
---|
212 | #define DBGC_CMDHLP2DBGC(pCmdHlp) ( (PDBGC)((uintptr_t)(pCmdHlp) - RT_OFFSETOF(DBGC, CmdHlp)) )
|
---|
213 |
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Chunk of external commands.
|
---|
217 | */
|
---|
218 | typedef struct DBGCEXTCMDS
|
---|
219 | {
|
---|
220 | /** Number of commands descriptors. */
|
---|
221 | unsigned cCmds;
|
---|
222 | /** Pointer to array of command descriptors. */
|
---|
223 | PCDBGCCMD paCmds;
|
---|
224 | /** Pointer to the next chunk. */
|
---|
225 | struct DBGCEXTCMDS *pNext;
|
---|
226 | } DBGCEXTCMDS;
|
---|
227 | /** Pointer to chunk of external commands. */
|
---|
228 | typedef DBGCEXTCMDS *PDBGCEXTCMDS;
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Unary 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 pArg The argument.
|
---|
240 | * @param enmCat The desired result category. Can be ignored.
|
---|
241 | * @param pResult Where to store the result.
|
---|
242 | */
|
---|
243 | typedef DECLCALLBACK(int) FNDBGCOPUNARY(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
|
---|
244 | /** Pointer to a unary operator handler function. */
|
---|
245 | typedef FNDBGCOPUNARY *PFNDBGCOPUNARY;
|
---|
246 |
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Binary operator handler function.
|
---|
250 | *
|
---|
251 | * @returns 0 on success.
|
---|
252 | * @returns VBox evaluation / parsing error code on failure.
|
---|
253 | * The caller does the bitching.
|
---|
254 | * @param pDbgc Debugger console instance data.
|
---|
255 | * @param pArg1 The first argument.
|
---|
256 | * @param pArg2 The 2nd argument.
|
---|
257 | * @param pResult Where to store the result.
|
---|
258 | */
|
---|
259 | typedef DECLCALLBACK(int) FNDBGCOPBINARY(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
|
---|
260 | /** Pointer to a binary operator handler function. */
|
---|
261 | typedef FNDBGCOPBINARY *PFNDBGCOPBINARY;
|
---|
262 |
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Operator descriptor.
|
---|
266 | */
|
---|
267 | typedef struct DBGCOP
|
---|
268 | {
|
---|
269 | /** Operator mnemonic. */
|
---|
270 | char szName[4];
|
---|
271 | /** Length of name. */
|
---|
272 | const unsigned cchName;
|
---|
273 | /** Whether or not this is a binary operator.
|
---|
274 | * Unary operators are evaluated right-to-left while binary are left-to-right. */
|
---|
275 | bool fBinary;
|
---|
276 | /** Precedence level. */
|
---|
277 | unsigned iPrecedence;
|
---|
278 | /** Unary operator handler. */
|
---|
279 | PFNDBGCOPUNARY pfnHandlerUnary;
|
---|
280 | /** Binary operator handler. */
|
---|
281 | PFNDBGCOPBINARY pfnHandlerBinary;
|
---|
282 | /** The category of the 1st argument.
|
---|
283 | * Set to DBGCVAR_CAT_ANY if anything goes. */
|
---|
284 | DBGCVARCAT enmCatArg1;
|
---|
285 | /** The category of the 2nd argument.
|
---|
286 | * Set to DBGCVAR_CAT_ANY if anything goes. */
|
---|
287 | DBGCVARCAT enmCatArg2;
|
---|
288 | /** Operator description. */
|
---|
289 | const char *pszDescription;
|
---|
290 | } DBGCOP;
|
---|
291 | /** Pointer to an operator descriptor. */
|
---|
292 | typedef DBGCOP *PDBGCOP;
|
---|
293 | /** Pointer to a const operator descriptor. */
|
---|
294 | typedef const DBGCOP *PCDBGCOP;
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 | /** Pointer to symbol descriptor. */
|
---|
299 | typedef struct DBGCSYM *PDBGCSYM;
|
---|
300 | /** Pointer to const symbol descriptor. */
|
---|
301 | typedef const struct DBGCSYM *PCDBGCSYM;
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * Get builtin symbol.
|
---|
305 | *
|
---|
306 | * @returns 0 on success.
|
---|
307 | * @returns VBox evaluation / parsing error code on failure.
|
---|
308 | * The caller does the bitching.
|
---|
309 | * @param pSymDesc Pointer to the symbol descriptor.
|
---|
310 | * @param pCmdHlp Pointer to the command callback structure.
|
---|
311 | * @param enmType The result type.
|
---|
312 | * @param pResult Where to store the result.
|
---|
313 | */
|
---|
314 | typedef DECLCALLBACK(int) FNDBGCSYMGET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, DBGCVARTYPE enmType, PDBGCVAR pResult);
|
---|
315 | /** Pointer to get function for a builtin symbol. */
|
---|
316 | typedef FNDBGCSYMGET *PFNDBGCSYMGET;
|
---|
317 |
|
---|
318 | /**
|
---|
319 | * Set builtin symbol.
|
---|
320 | *
|
---|
321 | * @returns 0 on success.
|
---|
322 | * @returns VBox evaluation / parsing error code on failure.
|
---|
323 | * The caller does the bitching.
|
---|
324 | * @param pSymDesc Pointer to the symbol descriptor.
|
---|
325 | * @param pCmdHlp Pointer to the command callback structure.
|
---|
326 | * @param pValue The value to assign the symbol.
|
---|
327 | */
|
---|
328 | typedef DECLCALLBACK(int) FNDBGCSYMSET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, PCDBGCVAR pValue);
|
---|
329 | /** Pointer to set function for a builtin symbol. */
|
---|
330 | typedef FNDBGCSYMSET *PFNDBGCSYMSET;
|
---|
331 |
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Symbol description (for builtin symbols).
|
---|
335 | */
|
---|
336 | typedef struct DBGCSYM
|
---|
337 | {
|
---|
338 | /** Symbol name. */
|
---|
339 | const char *pszName;
|
---|
340 | /** Get function. */
|
---|
341 | PFNDBGCSYMGET pfnGet;
|
---|
342 | /** Set function. (NULL if readonly) */
|
---|
343 | PFNDBGCSYMSET pfnSet;
|
---|
344 | /** User data. */
|
---|
345 | unsigned uUser;
|
---|
346 | } DBGCSYM;
|
---|
347 |
|
---|
348 |
|
---|
349 | /*******************************************************************************
|
---|
350 | * Internal Functions *
|
---|
351 | *******************************************************************************/
|
---|
352 | int dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
|
---|
353 | int dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
|
---|
354 | int dbgcBpDelete(PDBGC pDbgc, RTUINT iBp);
|
---|
355 | PDBGCBP dbgcBpGet(PDBGC pDbgc, RTUINT iBp);
|
---|
356 | int dbgcBpExec(PDBGC pDbgc, RTUINT iBp);
|
---|
357 |
|
---|
358 | void dbgcEvalInit(void);
|
---|
359 | int dbgcEvalSub(PDBGC pDbgc, char *pszExpr, size_t cchExpr, DBGCVARCAT enmCategory, PDBGCVAR pResult);
|
---|
360 | int dbgcEvalCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd, bool fNoExecute);
|
---|
361 |
|
---|
362 | int dbgcSymbolGet(PDBGC pDbgc, const char *pszSymbol, DBGCVARTYPE enmType, PDBGCVAR pResult);
|
---|
363 | PCDBGCSYM dbgcLookupRegisterSymbol(PDBGC pDbgc, const char *pszSymbol);
|
---|
364 | PCDBGCOP dbgcOperatorLookup(PDBGC pDbgc, const char *pszExpr, bool fPreferBinary, char chPrev);
|
---|
365 | PCDBGCCMD dbgcRoutineLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal);
|
---|
366 |
|
---|
367 | DECLCALLBACK(int) dbgcOpRegister(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
|
---|
368 | DECLCALLBACK(int) dbgcOpAddrFlat(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
|
---|
369 | DECLCALLBACK(int) dbgcOpAddrHost(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
|
---|
370 | DECLCALLBACK(int) dbgcOpAddrPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
|
---|
371 | DECLCALLBACK(int) dbgcOpAddrHostPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
|
---|
372 |
|
---|
373 | void dbgcInitCmdHlp(PDBGC pDbgc);
|
---|
374 |
|
---|
375 | void dbgcPlugInAutoLoad(PDBGC pDbgc);
|
---|
376 | void dbgcPlugInUnloadAll(PDBGC pDbgc);
|
---|
377 |
|
---|
378 | /* For tstDBGCParser: */
|
---|
379 | int dbgcCreate(PDBGC *ppDbgc, PDBGCBACK pBack, unsigned fFlags);
|
---|
380 | int dbgcRun(PDBGC pDbgc);
|
---|
381 | int dbgcProcessInput(PDBGC pDbgc, bool fNoExecute);
|
---|
382 | void dbgcDestroy(PDBGC pDbgc);
|
---|
383 |
|
---|
384 |
|
---|
385 | /*******************************************************************************
|
---|
386 | * Global Variables *
|
---|
387 | *******************************************************************************/
|
---|
388 | extern const DBGCCMD g_aCmds[];
|
---|
389 | extern const unsigned g_cCmds;
|
---|
390 | extern const DBGCCMD g_aCmdsCodeView[];
|
---|
391 | extern const unsigned g_cCmdsCodeView;
|
---|
392 | extern const DBGCOP g_aOps[];
|
---|
393 | extern const unsigned g_cOps;
|
---|
394 |
|
---|
395 |
|
---|
396 | #endif
|
---|
397 |
|
---|