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