VirtualBox

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

Last change on this file since 49762 was 47569, checked in by vboxsync, 11 years ago

DBGC: v86 disassembly fixes and tweaks.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.7 KB
Line 
1/* $Id: DBGCInternal.h 47569 2013-08-07 03:13:21Z 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 */
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 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 /** The flags that goes with DisasmPos. */
143 uint32_t fDisasm;
144 /** Current source position. (flat GC) */
145 DBGCVAR SourcePos;
146 /** Current memory dump position. */
147 DBGCVAR DumpPos;
148 /** Size of the previous dump element. */
149 unsigned cbDumpElement;
150 /** Points to DisasmPos, SourcePos or DumpPos depending on which was
151 * used last. */
152 PCDBGCVAR pLastPos;
153
154 /** Number of variables in papVars. */
155 unsigned cVars;
156 /** Array of global variables.
157 * Global variables can be referenced using the $ operator and set
158 * and unset using command with those names. */
159 PDBGCNAMEDVAR *papVars;
160
161 /** The list of plug-in. (singly linked) */
162 PDBGCPLUGIN pPlugInHead;
163
164 /** The list of breakpoints. (singly linked) */
165 PDBGCBP pFirstBp;
166
167 /** Save search pattern. */
168 uint8_t abSearch[256];
169 /** The length of the search pattern. */
170 uint32_t cbSearch;
171 /** The search unit */
172 uint32_t cbSearchUnit;
173 /** The max hits. */
174 uint64_t cMaxSearchHits;
175 /** The address to resume searching from. */
176 DBGFADDRESS SearchAddr;
177 /** What's left of the original search range. */
178 RTGCUINTPTR cbSearchRange;
179
180 /** @name Parsing and Execution
181 * @{ */
182
183 /** Input buffer. */
184 char achInput[2048];
185 /** To ease debugging. */
186 unsigned uInputZero;
187 /** Write index in the input buffer. */
188 unsigned iWrite;
189 /** Read index in the input buffer. */
190 unsigned iRead;
191 /** The number of lines in the buffer. */
192 unsigned cInputLines;
193 /** Indicates that we have a buffer overflow condition.
194 * This means that input is ignored up to the next newline. */
195 bool fInputOverflow;
196 /** Indicates whether or we're ready for input. */
197 bool fReady;
198 /** Scratch buffer position. */
199 char *pszScratch;
200 /** Scratch buffer. */
201 char achScratch[16384];
202 /** Argument array position. */
203 unsigned iArg;
204 /** Array of argument variables. */
205 DBGCVAR aArgs[100];
206
207 /** rc from the last dbgcHlpPrintfV(). */
208 int rcOutput;
209 /** The last character we wrote. */
210 char chLastOutput;
211
212 /** rc from the last command. */
213 int rcCmd;
214 /** @} */
215} DBGC;
216/** Pointer to debugger console instance data. */
217typedef DBGC *PDBGC;
218
219/** Converts a Command Helper pointer to a pointer to DBGC instance data. */
220#define DBGC_CMDHLP2DBGC(pCmdHlp) ( (PDBGC)((uintptr_t)(pCmdHlp) - RT_OFFSETOF(DBGC, CmdHlp)) )
221
222
223/**
224 * Chunk of external commands.
225 */
226typedef struct DBGCEXTCMDS
227{
228 /** Number of commands descriptors. */
229 unsigned cCmds;
230 /** Pointer to array of command descriptors. */
231 PCDBGCCMD paCmds;
232 /** Pointer to the next chunk. */
233 struct DBGCEXTCMDS *pNext;
234} DBGCEXTCMDS;
235/** Pointer to chunk of external commands. */
236typedef DBGCEXTCMDS *PDBGCEXTCMDS;
237
238
239/**
240 * Chunk of external functions.
241 */
242typedef struct DBGCEXTFUNCS
243{
244 /** Number of functions descriptors. */
245 uint32_t cFuncs;
246 /** Pointer to array of functions descriptors. */
247 PCDBGCFUNC paFuncs;
248 /** Pointer to the next chunk. */
249 struct DBGCEXTFUNCS *pNext;
250} DBGCEXTFUNCS;
251/** Pointer to chunk of external functions. */
252typedef DBGCEXTFUNCS *PDBGCEXTFUNCS;
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 enmCat The desired result category. Can be ignored.
265 * @param pResult Where to store the result.
266 */
267typedef DECLCALLBACK(int) FNDBGCOPUNARY(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
268/** Pointer to a unary operator handler function. */
269typedef FNDBGCOPUNARY *PFNDBGCOPUNARY;
270
271
272/**
273 * Binary operator handler function.
274 *
275 * @returns 0 on success.
276 * @returns VBox evaluation / parsing error code on failure.
277 * The caller does the bitching.
278 * @param pDbgc Debugger console instance data.
279 * @param pArg1 The first argument.
280 * @param pArg2 The 2nd argument.
281 * @param pResult Where to store the result.
282 */
283typedef DECLCALLBACK(int) FNDBGCOPBINARY(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
284/** Pointer to a binary operator handler function. */
285typedef FNDBGCOPBINARY *PFNDBGCOPBINARY;
286
287
288/**
289 * Operator descriptor.
290 */
291typedef struct DBGCOP
292{
293 /** Operator mnemonic. */
294 char szName[4];
295 /** Length of name. */
296 const unsigned cchName;
297 /** Whether or not this is a binary operator.
298 * Unary operators are evaluated right-to-left while binary are left-to-right. */
299 bool fBinary;
300 /** Precedence level. */
301 unsigned iPrecedence;
302 /** Unary operator handler. */
303 PFNDBGCOPUNARY pfnHandlerUnary;
304 /** Binary operator handler. */
305 PFNDBGCOPBINARY pfnHandlerBinary;
306 /** The category of the 1st argument.
307 * Set to DBGCVAR_CAT_ANY if anything goes. */
308 DBGCVARCAT enmCatArg1;
309 /** The category of the 2nd argument.
310 * Set to DBGCVAR_CAT_ANY if anything goes. */
311 DBGCVARCAT enmCatArg2;
312 /** Operator description. */
313 const char *pszDescription;
314} DBGCOP;
315/** Pointer to an operator descriptor. */
316typedef DBGCOP *PDBGCOP;
317/** Pointer to a const operator descriptor. */
318typedef const DBGCOP *PCDBGCOP;
319
320
321
322/** Pointer to symbol descriptor. */
323typedef struct DBGCSYM *PDBGCSYM;
324/** Pointer to const symbol descriptor. */
325typedef const struct DBGCSYM *PCDBGCSYM;
326
327/**
328 * Get builtin symbol.
329 *
330 * @returns 0 on success.
331 * @returns VBox evaluation / parsing error code on failure.
332 * The caller does the bitching.
333 * @param pSymDesc Pointer to the symbol descriptor.
334 * @param pCmdHlp Pointer to the command callback structure.
335 * @param enmType The result type.
336 * @param pResult Where to store the result.
337 */
338typedef DECLCALLBACK(int) FNDBGCSYMGET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, DBGCVARTYPE enmType, PDBGCVAR pResult);
339/** Pointer to get function for a builtin symbol. */
340typedef FNDBGCSYMGET *PFNDBGCSYMGET;
341
342/**
343 * Set builtin symbol.
344 *
345 * @returns 0 on success.
346 * @returns VBox evaluation / parsing error code on failure.
347 * The caller does the bitching.
348 * @param pSymDesc Pointer to the symbol descriptor.
349 * @param pCmdHlp Pointer to the command callback structure.
350 * @param pValue The value to assign the symbol.
351 */
352typedef DECLCALLBACK(int) FNDBGCSYMSET(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, PCDBGCVAR pValue);
353/** Pointer to set function for a builtin symbol. */
354typedef FNDBGCSYMSET *PFNDBGCSYMSET;
355
356
357/**
358 * Symbol description (for builtin symbols).
359 */
360typedef struct DBGCSYM
361{
362 /** Symbol name. */
363 const char *pszName;
364 /** Get function. */
365 PFNDBGCSYMGET pfnGet;
366 /** Set function. (NULL if readonly) */
367 PFNDBGCSYMSET pfnSet;
368 /** User data. */
369 unsigned uUser;
370} DBGCSYM;
371
372
373/*******************************************************************************
374* Internal Functions *
375*******************************************************************************/
376int dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
377int dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd);
378int dbgcBpDelete(PDBGC pDbgc, RTUINT iBp);
379PDBGCBP dbgcBpGet(PDBGC pDbgc, RTUINT iBp);
380int dbgcBpExec(PDBGC pDbgc, RTUINT iBp);
381
382void dbgcEvalInit(void);
383int dbgcEvalSub(PDBGC pDbgc, char *pszExpr, size_t cchExpr, DBGCVARCAT enmCategory, PDBGCVAR pResult);
384int dbgcEvalCommand(PDBGC pDbgc, char *pszCmd, size_t cchCmd, bool fNoExecute);
385
386int dbgcSymbolGet(PDBGC pDbgc, const char *pszSymbol, DBGCVARTYPE enmType, PDBGCVAR pResult);
387PCDBGCSYM dbgcLookupRegisterSymbol(PDBGC pDbgc, const char *pszSymbol);
388PCDBGCOP dbgcOperatorLookup(PDBGC pDbgc, const char *pszExpr, bool fPreferBinary, char chPrev);
389PCDBGCCMD dbgcCommandLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal);
390PCDBGCFUNC dbgcFunctionLookup(PDBGC pDbgc, const char *pachName, size_t cchName, bool fExternal);
391
392DECLCALLBACK(int) dbgcOpRegister(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
393DECLCALLBACK(int) dbgcOpAddrFlat(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
394DECLCALLBACK(int) dbgcOpAddrHost(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
395DECLCALLBACK(int) dbgcOpAddrPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
396DECLCALLBACK(int) dbgcOpAddrHostPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, 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_aDbgcCmds[];
414extern const uint32_t g_cDbgcCmds;
415extern const DBGCFUNC g_aDbgcFuncs[];
416extern const uint32_t g_cDbgcFuncs;
417extern const DBGCCMD g_aCmdsCodeView[];
418extern const uint32_t g_cCmdsCodeView;
419extern const DBGCFUNC g_aFuncsCodeView[];
420extern const uint32_t g_cFuncsCodeView;
421extern const DBGCOP g_aDbgcOps[];
422extern const uint32_t g_cDbgcOps;
423
424
425/*******************************************************************************
426* Defined Constants And Macros *
427*******************************************************************************/
428/** Locks the g_pExtCmdsHead and g_pExtFuncsHead lists for reading. */
429#define DBGCEXTLISTS_LOCK_RD() do { } while (0)
430/** Locks the g_pExtCmdsHead and g_pExtFuncsHead lists for writing. */
431#define DBGCEXTLISTS_LOCK_WR() do { } while (0)
432/** UnLocks the g_pExtCmdsHead and g_pExtFuncsHead lists after reading. */
433#define DBGCEXTLISTS_UNLOCK_RD() do { } while (0)
434/** UnLocks the g_pExtCmdsHead and g_pExtFuncsHead lists after writing. */
435#define DBGCEXTLISTS_UNLOCK_WR() do { } while (0)
436
437
438
439#endif
440
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