VirtualBox

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

Last change on this file since 59176 was 59072, checked in by vboxsync, 9 years ago

DBGC: Implemented the DBGC side of the sx* commands. (DBGF isn't quite there yet.)

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