VirtualBox

source: vbox/trunk/include/VBox/dbg.h@ 35673

Last change on this file since 35673 was 35673, checked in by vboxsync, 14 years ago

Debugger Console: Some cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.9 KB
Line 
1/** @file
2 * Debugger Interfaces. (VBoxDbg)
3 *
4 * This header covers all external interfaces of the Debugger module.
5 * However, it does not cover the DBGF interface since that part of the
6 * VMM. Use dbgf.h for that.
7 */
8
9/*
10 * Copyright (C) 2006-2007 Oracle Corporation
11 *
12 * This file is part of VirtualBox Open Source Edition (OSE), as
13 * available from http://www.virtualbox.org. This file is free software;
14 * you can redistribute it and/or modify it under the terms of the GNU
15 * General Public License (GPL) as published by the Free Software
16 * Foundation, in version 2 as it comes in the "COPYING" file of the
17 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19 *
20 * The contents of this file may alternatively be used under the terms
21 * of the Common Development and Distribution License Version 1.0
22 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
23 * VirtualBox OSE distribution, in which case the provisions of the
24 * CDDL are applicable instead of those of the GPL.
25 *
26 * You may elect to license modified versions of this file under the
27 * terms and conditions of either the GPL or the CDDL or both.
28 */
29
30#ifndef ___VBox_dbg_h
31#define ___VBox_dbg_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <VBox/vmm/dbgf.h>
36
37#include <iprt/stdarg.h>
38#ifdef IN_RING3
39# include <iprt/err.h>
40#endif
41
42RT_C_DECLS_BEGIN
43
44/** @def VBOX_WITH_DEBUGGER
45 * The build is with debugger module. Test if this is defined before registering
46 * external debugger commands. This is normally defined in Config.kmk.
47 */
48#ifdef DOXYGEN_RUNNING
49# define VBOX_WITH_DEBUGGER
50#endif
51
52
53/**
54 * DBGC variable category.
55 *
56 * Used to describe an argument to a command or function and a functions
57 * return value.
58 */
59typedef enum DBGCVARCAT
60{
61 /** Any type is fine. */
62 DBGCVAR_CAT_ANY = 0,
63 /** Any kind of pointer or number. */
64 DBGCVAR_CAT_POINTER_NUMBER,
65 /** Any kind of pointer or number, no range. */
66 DBGCVAR_CAT_POINTER_NUMBER_NO_RANGE,
67 /** Any kind of pointer. */
68 DBGCVAR_CAT_POINTER,
69 /** Any kind of pointer with no range option. */
70 DBGCVAR_CAT_POINTER_NO_RANGE,
71 /** GC pointer. */
72 DBGCVAR_CAT_GC_POINTER,
73 /** GC pointer with no range option. */
74 DBGCVAR_CAT_GC_POINTER_NO_RANGE,
75 /** Numeric argument. */
76 DBGCVAR_CAT_NUMBER,
77 /** Numeric argument with no range option. */
78 DBGCVAR_CAT_NUMBER_NO_RANGE,
79 /** String. */
80 DBGCVAR_CAT_STRING,
81 /** Symbol. */
82 DBGCVAR_CAT_SYMBOL,
83 /** Option. */
84 DBGCVAR_CAT_OPTION,
85 /** Option + string. */
86 DBGCVAR_CAT_OPTION_STRING,
87 /** Option + number. */
88 DBGCVAR_CAT_OPTION_NUMBER
89} DBGCVARCAT;
90
91
92/**
93 * DBGC variable type.
94 */
95typedef enum DBGCVARTYPE
96{
97 /** unknown... */
98 DBGCVAR_TYPE_UNKNOWN = 0,
99 /** Flat GC pointer. */
100 DBGCVAR_TYPE_GC_FLAT,
101 /** Segmented GC pointer. */
102 DBGCVAR_TYPE_GC_FAR,
103 /** Physical GC pointer. */
104 DBGCVAR_TYPE_GC_PHYS,
105 /** Flat HC pointer. */
106 DBGCVAR_TYPE_HC_FLAT,
107 /** Physical HC pointer. */
108 DBGCVAR_TYPE_HC_PHYS,
109 /** String. */
110 DBGCVAR_TYPE_STRING,
111 /** Number. */
112 DBGCVAR_TYPE_NUMBER,
113 /** Symbol.
114 * @todo drop this */
115 DBGCVAR_TYPE_SYMBOL,
116 /** Special type used when querying symbols. */
117 DBGCVAR_TYPE_ANY
118} DBGCVARTYPE;
119
120/** @todo Rename to DBGCVAR_IS_xyz. */
121
122/** Checks if the specified variable type is of a pointer persuasion. */
123#define DBGCVAR_ISPOINTER(enmType) ((enmType) >= DBGCVAR_TYPE_GC_FLAT && enmType <= DBGCVAR_TYPE_HC_PHYS)
124/** Checks if the specified variable type is of a pointer persuasion. */
125#define DBGCVAR_IS_FAR_PTR(enmType) ((enmType) == DBGCVAR_TYPE_GC_FAR)
126/** Checks if the specified variable type is of a pointer persuasion and of the guest context sort. */
127#define DBGCVAR_ISGCPOINTER(enmType) ((enmType) >= DBGCVAR_TYPE_GC_FLAT && (enmType) <= DBGCVAR_TYPE_GC_PHYS)
128/** Checks if the specified variable type is of a pointer persuasion and of the host context sort. */
129#define DBGCVAR_ISHCPOINTER(enmType) ((enmType) >= DBGCVAR_TYPE_HC_FLAT && (enmType) <= DBGCVAR_TYPE_HC_PHYS)
130
131
132/**
133 * DBGC variable range type.
134 */
135typedef enum DBGCVARRANGETYPE
136{
137 /** No range appliable or no range specified. */
138 DBGCVAR_RANGE_NONE = 0,
139 /** Number of elements. */
140 DBGCVAR_RANGE_ELEMENTS,
141 /** Number of bytes. */
142 DBGCVAR_RANGE_BYTES
143} DBGCVARRANGETYPE;
144
145
146/**
147 * Variable descriptor.
148 */
149typedef struct DBGCVARDESC
150{
151 /** The minimal number of times this argument may occur.
152 * Use 0 here to inidicate that the argument is optional. */
153 unsigned cTimesMin;
154 /** Maximum number of occurrences.
155 * Use ~0 here to indicate infinite. */
156 unsigned cTimesMax;
157 /** Argument category. */
158 DBGCVARCAT enmCategory;
159 /** Flags, DBGCVD_FLAGS_* */
160 unsigned fFlags;
161 /** Argument name. */
162 const char *pszName;
163 /** Argument name. */
164 const char *pszDescription;
165} DBGCVARDESC;
166/** Pointer to an argument descriptor. */
167typedef DBGCVARDESC *PDBGCVARDESC;
168/** Pointer to a const argument descriptor. */
169typedef const DBGCVARDESC *PCDBGCVARDESC;
170
171/** Variable descriptor flags.
172 * @{ */
173/** Indicates that the variable depends on the previous being present. */
174#define DBGCVD_FLAGS_DEP_PREV RT_BIT(1)
175/** @} */
176
177
178/**
179 * DBGC variable.
180 */
181typedef struct DBGCVAR
182{
183 /** Pointer to the argument descriptor. */
184 PCDBGCVARDESC pDesc;
185 /** Pointer to the next argument. */
186 struct DBGCVAR *pNext;
187
188 /** Argument type. */
189 DBGCVARTYPE enmType;
190 /** Type specific. */
191 union
192 {
193 /** Flat GC Address. (DBGCVAR_TYPE_GC_FLAT) */
194 RTGCPTR GCFlat;
195 /** Far (16:32) GC Address. (DBGCVAR_TYPE_GC_FAR) */
196 RTFAR32 GCFar;
197 /** Physical GC Address. (DBGCVAR_TYPE_GC_PHYS) */
198 RTGCPHYS GCPhys;
199 /** Flat HC Address. (DBGCVAR_TYPE_HC_FLAT) */
200 void *pvHCFlat;
201 /** Physical GC Address. (DBGCVAR_TYPE_HC_PHYS) */
202 RTHCPHYS HCPhys;
203 /** String. (DBGCVAR_TYPE_STRING)
204 * The basic idea is the the this is a pointer to the expression we're
205 * parsing, so no messing with freeing. */
206 const char *pszString;
207 /** Number. (DBGCVAR_TYPE_NUMBER) */
208 uint64_t u64Number;
209 } u;
210
211 /** Range type. */
212 DBGCVARRANGETYPE enmRangeType;
213 /** Range. The use of the content depends on the enmRangeType. */
214 uint64_t u64Range;
215} DBGCVAR;
216/** Pointer to a command argument. */
217typedef DBGCVAR *PDBGCVAR;
218/** Pointer to a const command argument. */
219typedef const DBGCVAR *PCDBGCVAR;
220
221
222/**
223 * Macro for initializing a DBGC variable with defaults.
224 * The result is an unknown variable type without any range.
225 */
226#define DBGCVAR_INIT(pVar) \
227 do { \
228 (pVar)->pDesc = NULL;\
229 (pVar)->pNext = NULL; \
230 (pVar)->enmType = DBGCVAR_TYPE_UNKNOWN; \
231 (pVar)->u.u64Number = 0; \
232 (pVar)->enmRangeType = DBGCVAR_RANGE_NONE; \
233 (pVar)->u64Range = 0; \
234 } while (0)
235
236/**
237 * Macro for initializing a DBGC variable with a HC physical address.
238 */
239#define DBGCVAR_INIT_HC_PHYS(pVar, Phys) \
240 do { \
241 DBGCVAR_INIT(pVar); \
242 (pVar)->enmType = DBGCVAR_TYPE_HC_PHYS; \
243 (pVar)->u.HCPhys = (Phys); \
244 } while (0)
245
246/**
247 * Macro for initializing a DBGC variable with a HC flat address.
248 */
249#define DBGCVAR_INIT_HC_FLAT(pVar, Flat) \
250 do { \
251 DBGCVAR_INIT(pVar); \
252 (pVar)->enmType = DBGCVAR_TYPE_HC_FLAT; \
253 (pVar)->u.pvHCFlat = (Flat); \
254 } while (0)
255
256/**
257 * Macro for initializing a DBGC variable with a GC physical address.
258 */
259#define DBGCVAR_INIT_GC_PHYS(pVar, Phys) \
260 do { \
261 DBGCVAR_INIT(pVar); \
262 (pVar)->enmType = DBGCVAR_TYPE_GC_PHYS; \
263 (pVar)->u.GCPhys = (Phys); \
264 } while (0)
265
266/**
267 * Macro for initializing a DBGC variable with a GC flat address.
268 */
269#define DBGCVAR_INIT_GC_FLAT(pVar, Flat) \
270 do { \
271 DBGCVAR_INIT(pVar); \
272 (pVar)->enmType = DBGCVAR_TYPE_GC_FLAT; \
273 (pVar)->u.GCFlat = (Flat); \
274 } while (0)
275
276/**
277 * Macro for initializing a DBGC variable with a GC flat address.
278 */
279#define DBGCVAR_INIT_GC_FLAT_BYTE_RANGE(pVar, Flat, cbRange) \
280 do { \
281 DBGCVAR_INIT(pVar); \
282 (pVar)->enmType = DBGCVAR_TYPE_GC_FLAT; \
283 (pVar)->u.GCFlat = (Flat); \
284 DBGCVAR_SET_RANGE(pVar, DBGCVAR_RANGE_BYTES, cbRange); \
285 } while (0)
286
287/**
288 * Macro for initializing a DBGC variable with a GC far address.
289 */
290#define DBGCVAR_INIT_GC_FAR(pVar, _sel, _off) \
291 do { \
292 DBGCVAR_INIT(pVar); \
293 (pVar)->enmType = DBGCVAR_TYPE_GC_FAR; \
294 (pVar)->u.GCFar.sel = (_sel); \
295 (pVar)->u.GCFar.off = (_off); \
296 } while (0)
297
298/**
299 * Macro for initializing a DBGC variable with a number.
300 */
301#define DBGCVAR_INIT_NUMBER(pVar, Value) \
302 do { \
303 DBGCVAR_INIT(pVar); \
304 (pVar)->enmType = DBGCVAR_TYPE_NUMBER; \
305 (pVar)->u.u64Number = (Value); \
306 } while (0)
307
308/**
309 * Macro for initializing a DBGC variable with a string.
310 */
311#define DBGCVAR_INIT_STRING(pVar, a_pszString) \
312 do { \
313 DBGCVAR_INIT(pVar); \
314 (pVar)->enmType = DBGCVAR_TYPE_STRING; \
315 (pVar)->enmRangeType = DBGCVAR_RANGE_BYTES; \
316 (pVar)->u.pszString = (a_pszString); \
317 (pVar)->u64Range = strlen(a_pszString); \
318 } while (0)
319
320
321/**
322 * Macro for setting the range of a DBGC variable.
323 * @param pVar The variable.
324 * @param _enmRangeType The range type.
325 * @param Value The range length value.
326 */
327#define DBGCVAR_SET_RANGE(pVar, _enmRangeType, Value) \
328 do { \
329 (pVar)->enmRangeType = (_enmRangeType); \
330 (pVar)->u64Range = (Value); \
331 } while (0)
332
333
334/**
335 * Macro for setting the range of a DBGC variable.
336 * @param a_pVar The variable.
337 * @param a_cbRange The range, in bytes.
338 */
339#define DBGCVAR_SET_BYTE_RANGE(a_pVar, a_cbRange) \
340 DBGCVAR_SET_RANGE(a_pVar, DBGCVAR_RANGE_BYTES, a_cbRange)
341
342
343/**
344 * Macro for resetting the range a DBGC variable.
345 * @param a_pVar The variable.
346 */
347#define DBGCVAR_ZAP_RANGE(a_pVar) \
348 do { \
349 (a_pVar)->enmRangeType = DBGCVAR_RANGE_NONE; \
350 (a_pVar)->u64Range = 0; \
351 } while (0)
352
353
354/**
355 * Macro for assigning one DBGC variable to another.
356 * @param a_pResult The result (target) variable.
357 * @param a_pVar The source variable.
358 */
359#define DBGCVAR_ASSIGN(a_pResult, a_pVar) \
360 do { \
361 *(a_pResult) = *(a_pVar); \
362 } while (0)
363
364
365/** Pointer to command descriptor. */
366typedef struct DBGCCMD *PDBGCCMD;
367/** Pointer to const command descriptor. */
368typedef const struct DBGCCMD *PCDBGCCMD;
369
370/** Pointer to helper functions for commands. */
371typedef struct DBGCCMDHLP *PDBGCCMDHLP;
372
373/**
374 * Command helper for writing text to the debug console.
375 *
376 * @returns VBox status.
377 * @param pCmdHlp Pointer to the command callback structure.
378 * @param pvBuf What to write.
379 * @param cbBuf Number of bytes to write.
380 * @param pcbWritten Where to store the number of bytes actually written.
381 * If NULL the entire buffer must be successfully written.
382 */
383typedef DECLCALLBACK(int) FNDBGCHLPWRITE(PDBGCCMDHLP pCmdHlp, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
384/** Pointer to a FNDBGCHLPWRITE() function. */
385typedef FNDBGCHLPWRITE *PFNDBGCHLPWRITE;
386
387/**
388 * Command helper for writing formatted text to the debug console.
389 *
390 * @returns VBox status.
391 * @param pCmdHlp Pointer to the command callback structure.
392 * @param pcb Where to store the number of bytes written.
393 * @param pszFormat The format string.
394 * This is using the log formatter, so it's format extensions can be used.
395 * @param ... Arguments specified in the format string.
396 */
397typedef DECLCALLBACK(int) FNDBGCHLPPRINTF(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, ...);
398/** Pointer to a FNDBGCHLPPRINTF() function. */
399typedef FNDBGCHLPPRINTF *PFNDBGCHLPPRINTF;
400
401/**
402 * Command helper for writing formatted text to the debug console.
403 *
404 * @returns VBox status.
405 * @param pCmdHlp Pointer to the command callback structure.
406 * @param pcb Where to store the number of bytes written.
407 * @param pszFormat The format string.
408 * This is using the log formatter, so it's format extensions can be used.
409 * @param args Arguments specified in the format string.
410 */
411typedef DECLCALLBACK(int) FNDBGCHLPPRINTFV(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, va_list args);
412/** Pointer to a FNDBGCHLPPRINTFV() function. */
413typedef FNDBGCHLPPRINTFV *PFNDBGCHLPPRINTFV;
414
415/**
416 * Command helper for formatting and error message for a VBox status code.
417 *
418 * @returns VBox status code appropriate to return from a command.
419 * @param pCmdHlp Pointer to the command callback structure.
420 * @param rc The VBox status code.
421 * @param pszFormat Format string for additional messages. Can be NULL.
422 * @param ... Format arguments, optional.
423 */
424typedef DECLCALLBACK(int) FNDBGCHLPVBOXERROR(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, ...);
425/** Pointer to a FNDBGCHLPVBOXERROR() function. */
426typedef FNDBGCHLPVBOXERROR *PFNDBGCHLPVBOXERROR;
427
428/**
429 * Command helper for formatting and error message for a VBox status code.
430 *
431 * @returns VBox status code appropriate to return from a command.
432 * @param pCmdHlp Pointer to the command callback structure.
433 * @param rc The VBox status code.
434 * @param pcb Where to store the number of bytes written.
435 * @param pszFormat Format string for additional messages. Can be NULL.
436 * @param args Format arguments, optional.
437 */
438typedef DECLCALLBACK(int) FNDBGCHLPVBOXERRORV(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, va_list args);
439/** Pointer to a FNDBGCHLPVBOXERRORV() function. */
440typedef FNDBGCHLPVBOXERRORV *PFNDBGCHLPVBOXERRORV;
441
442/**
443 * Command helper for reading memory specified by a DBGC variable.
444 *
445 * @returns VBox status code appropriate to return from a command.
446 * @param pCmdHlp Pointer to the command callback structure.
447 * @param pVM VM handle if GC or physical HC address.
448 * @param pvBuffer Where to store the read data.
449 * @param cbRead Number of bytes to read.
450 * @param pVarPointer DBGC variable specifying where to start reading.
451 * @param pcbRead Where to store the number of bytes actually read.
452 * This optional, but it's useful when read GC virtual memory where a
453 * page in the requested range might not be present.
454 * If not specified not-present failure or end of a HC physical page
455 * will cause failure.
456 */
457typedef DECLCALLBACK(int) FNDBGCHLPMEMREAD(PDBGCCMDHLP pCmdHlp, PVM pVM, void *pvBuffer, size_t cbRead, PCDBGCVAR pVarPointer, size_t *pcbRead);
458/** Pointer to a FNDBGCHLPMEMREAD() function. */
459typedef FNDBGCHLPMEMREAD *PFNDBGCHLPMEMREAD;
460
461/**
462 * Command helper for writing memory specified by a DBGC variable.
463 *
464 * @returns VBox status code appropriate to return from a command.
465 * @param pCmdHlp Pointer to the command callback structure.
466 * @param pVM VM handle if GC or physical HC address.
467 * @param pvBuffer What to write.
468 * @param cbWrite Number of bytes to write.
469 * @param pVarPointer DBGC variable specifying where to start reading.
470 * @param pcbWritten Where to store the number of bytes written.
471 * This is optional. If NULL be aware that some of the buffer
472 * might have been written to the specified address.
473 */
474typedef DECLCALLBACK(int) FNDBGCHLPMEMWRITE(PDBGCCMDHLP pCmdHlp, PVM pVM, const void *pvBuffer, size_t cbWrite, PCDBGCVAR pVarPointer, size_t *pcbWritten);
475/** Pointer to a FNDBGCHLPMEMWRITE() function. */
476typedef FNDBGCHLPMEMWRITE *PFNDBGCHLPMEMWRITE;
477
478
479
480/**
481 * Executes command an expression.
482 * (Hopefully the parser and functions are fully reentrant.)
483 *
484 * @returns VBox status code appropriate to return from a command.
485 * @param pCmdHlp Pointer to the command callback structure.
486 * @param pszExpr The expression. Format string with the format DBGC extensions.
487 * @param ... Format arguments.
488 */
489typedef DECLCALLBACK(int) FNDBGCHLPEXEC(PDBGCCMDHLP pCmdHlp, const char *pszExpr, ...);
490/** Pointer to a FNDBGCHLPEVAL() function. */
491typedef FNDBGCHLPEXEC *PFNDBGCHLPEXEC;
492
493
494/**
495 * Helper functions for commands.
496 */
497typedef struct DBGCCMDHLP
498{
499 /** Pointer to a FNDBCHLPWRITE() function. */
500 PFNDBGCHLPWRITE pfnWrite;
501 /** Pointer to a FNDBGCHLPPRINTF() function. */
502 PFNDBGCHLPPRINTF pfnPrintf;
503 /** Pointer to a FNDBGCHLPPRINTFV() function. */
504 PFNDBGCHLPPRINTFV pfnPrintfV;
505 /** Pointer to a FNDBGCHLPVBOXERROR() function. */
506 PFNDBGCHLPVBOXERROR pfnVBoxError;
507 /** Pointer to a FNDBGCHLPVBOXERRORV() function. */
508 PFNDBGCHLPVBOXERRORV pfnVBoxErrorV;
509 /** Pointer to a FNDBGCHLPMEMREAD() function. */
510 PFNDBGCHLPMEMREAD pfnMemRead;
511 /** Pointer to a FNDBGCHLPMEMWRITE() function. */
512 PFNDBGCHLPMEMWRITE pfnMemWrite;
513 /** Pointer to a FNDBGCHLPEXEC() function. */
514 PFNDBGCHLPEXEC pfnExec;
515
516 /**
517 * Evaluates an expression.
518 * (Hopefully the parser and functions are fully reentrant.)
519 *
520 * @returns VBox status code appropriate to return from a command.
521 * @param pCmdHlp Pointer to the command callback structure.
522 * @param pResult Where to store the result.
523 * @param pszExpr The expression. Format string with the format DBGC extensions.
524 * @param va Format arguments.
525 */
526 DECLCALLBACKMEMBER(int, pfnEvalV)(PDBGCCMDHLP pCmdHlp, PDBGCVAR pResult, const char *pszExpr, va_list va);
527
528 /**
529 * Print an error and fail the current command.
530 *
531 * @returns VBox status code to pass upwards.
532 *
533 * @param pCmdHlp Pointer to the command callback structure.
534 * @param pCmd The failing command.
535 * @param pszFormat The error message format string.
536 * @param va Format arguments.
537 */
538 DECLCALLBACKMEMBER(int, pfnFailV)(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, const char *pszFormat, va_list va);
539
540 /**
541 * Converts a DBGC variable to a DBGF address structure.
542 *
543 * @returns VBox status code.
544 * @param pCmdHlp Pointer to the command callback structure.
545 * @param pVar The variable to convert.
546 * @param pAddress The target address.
547 */
548 DECLCALLBACKMEMBER(int, pfnVarToDbgfAddr)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, PDBGFADDRESS pAddress);
549
550 /**
551 * Converts a DBGF address structure to a DBGC variable.
552 *
553 * @returns VBox status code.
554 * @param pCmdHlp Pointer to the command callback structure.
555 * @param pAddress The source address.
556 * @param pResult The result variable.
557 */
558 DECLCALLBACKMEMBER(int, pfnVarFromDbgfAddr)(PDBGCCMDHLP pCmdHlp, PCDBGFADDRESS pAddress, PDBGCVAR pResult);
559
560 /**
561 * Converts a DBGC variable to a 64-bit number.
562 *
563 * @returns VBox status code.
564 * @param pCmdHlp Pointer to the command callback structure.
565 * @param pVar The variable to convert.
566 * @param pu64Number Where to store the number.
567 */
568 DECLCALLBACKMEMBER(int, pfnVarToNumber)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t *pu64Number);
569
570 /**
571 * Converts a DBGC variable to a boolean.
572 *
573 * @returns VBox status code.
574 * @param pCmdHlp Pointer to the command callback structure.
575 * @param pVar The variable to convert.
576 * @param pf Where to store the boolean.
577 */
578 DECLCALLBACKMEMBER(int, pfnVarToBool)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, bool *pf);
579
580 /**
581 * Get the range of a variable in bytes, resolving symbols if necessary.
582 *
583 * @returns VBox status code.
584 * @param pCmdHlp Pointer to the command callback structure.
585 * @param pVar The variable to convert.
586 * @param cbElement Conversion factor for element ranges.
587 * @param cbDefault The default range.
588 * @param pcbRange The length of the range.
589 */
590 DECLCALLBACKMEMBER(int, pfnVarGetRange)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t cbElement, uint64_t cbDefault,
591 uint64_t *pcbRange);
592
593 /**
594 * Converts a variable to one with the specified type.
595 *
596 * This preserves the range.
597 *
598 * @returns VBox status code.
599 * @param pCmdHlp Pointer to the command callback structure.
600 * @param pVar The variable to convert.
601 * @param enmToType The target type.
602 * @param fConvSyms If @c true, then attempt to resolve symbols.
603 * @param pResult The output variable. Can be the same as @a pVar.
604 */
605 DECLCALLBACKMEMBER(int, pfnVarConvert)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, DBGCVARTYPE enmToType, bool fConvSyms,
606 PDBGCVAR pResult);
607
608 /**
609 * Gets a DBGF output helper that directs the output to the debugger
610 * console.
611 *
612 * @returns Pointer to the helper structure.
613 * @param pCmdHlp Pointer to the command callback structure.
614 */
615 DECLCALLBACKMEMBER(PCDBGFINFOHLP, pfnGetDbgfOutputHlp)(PDBGCCMDHLP pCmdHlp);
616
617} DBGCCMDHLP;
618
619
620#ifdef IN_RING3
621
622/**
623 * Command helper for writing formatted text to the debug console.
624 *
625 * @returns VBox status.
626 * @param pCmdHlp Pointer to the command callback structure.
627 * @param pszFormat The format string.
628 * This is using the log formatter, so it's format extensions can be used.
629 * @param ... Arguments specified in the format string.
630 */
631DECLINLINE(int) DBGCCmdHlpPrintf(PDBGCCMDHLP pCmdHlp, const char *pszFormat, ...)
632{
633 va_list va;
634 int rc;
635
636 va_start(va, pszFormat);
637 rc = pCmdHlp->pfnPrintfV(pCmdHlp, NULL, pszFormat, va);
638 va_end(va);
639
640 return rc;
641}
642
643/**
644 * @copydoc FNDBGCHLPVBOXERROR
645 */
646DECLINLINE(int) DBGCCmdHlpVBoxError(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, ...)
647{
648 va_list va;
649
650 va_start(va, pszFormat);
651 rc = pCmdHlp->pfnVBoxErrorV(pCmdHlp, rc, pszFormat, va);
652 va_end(va);
653
654 return rc;
655}
656
657/**
658 * @copydoc FNDBGCHLPMEMREAD
659 */
660DECLINLINE(int) DBGCCmdHlpMemRead(PDBGCCMDHLP pCmdHlp, PVM pVM, void *pvBuffer, size_t cbRead, PCDBGCVAR pVarPointer, size_t *pcbRead)
661{
662 return pCmdHlp->pfnMemRead(pCmdHlp, pVM, pvBuffer, cbRead, pVarPointer, pcbRead);
663}
664
665/**
666 * Evaluates an expression.
667 * (Hopefully the parser and functions are fully reentrant.)
668 *
669 * @returns VBox status code appropriate to return from a command.
670 * @param pCmdHlp Pointer to the command callback structure.
671 * @param pResult Where to store the result.
672 * @param pszExpr The expression. Format string with the format DBGC extensions.
673 * @param ... Format arguments.
674 */
675DECLINLINE(int) DBGCCmdHlpEval(PDBGCCMDHLP pCmdHlp, PDBGCVAR pResult, const char *pszExpr, ...)
676{
677 va_list va;
678 int rc;
679
680 va_start(va, pszExpr);
681 rc = pCmdHlp->pfnEvalV(pCmdHlp, pResult, pszExpr, va);
682 va_end(va);
683
684 return rc;
685}
686
687/**
688 * Print an error and fail the current command.
689 *
690 * @returns VBox status code to pass upwards.
691 *
692 * @param pCmdHlp Pointer to the command callback structure.
693 * @param pCmd The failing command.
694 * @param pszFormat The error message format string.
695 * @param ... Format arguments.
696 */
697DECLINLINE(int) DBGCCmdHlpFail(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, const char *pszFormat, ...)
698{
699 va_list va;
700 int rc;
701
702 va_start(va, pszFormat);
703 rc = pCmdHlp->pfnFailV(pCmdHlp, pCmd, pszFormat, va);
704 va_end(va);
705
706 return rc;
707}
708
709/**
710 * @copydoc DBGCCMDHLP::pfnVarToDbgfAddr
711 */
712DECLINLINE(int) DBGCCmdHlpVarToDbgfAddr(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, PDBGFADDRESS pAddress)
713{
714 return pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pVar, pAddress);
715}
716
717/**
718 * @copydoc DBGCCMDHLP::pfnVarToDbgfAddr
719 */
720DECLINLINE(int) DBGCCmdHlpVarFromDbgfAddr(PDBGCCMDHLP pCmdHlp, PCDBGFADDRESS pAddress, PDBGCVAR pResult)
721{
722 return pCmdHlp->pfnVarFromDbgfAddr(pCmdHlp, pAddress, pResult);
723}
724
725/**
726 * Converts an variable to a flat address.
727 *
728 * @returns VBox status code.
729 * @param pCmdHlp Pointer to the command callback structure.
730 * @param pVar The variable to convert.
731 * @param pFlatPtr Where to store the flat address.
732 */
733DECLINLINE(int) DBGCCmdHlpVarToFlatAddr(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, PRTGCPTR pFlatPtr)
734{
735 DBGFADDRESS Addr;
736 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pVar, &Addr);
737 if (RT_SUCCESS(rc))
738 *pFlatPtr = Addr.FlatPtr;
739 return rc;
740}
741
742/**
743 * @copydoc DBGCCMDHLP::pfnVarToNumber
744 */
745DECLINLINE(int) DBGCCmdHlpVarToNumber(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t *pu64Number)
746{
747 return pCmdHlp->pfnVarToNumber(pCmdHlp, pVar, pu64Number);
748}
749
750/**
751 * @copydoc DBGCCMDHLP::pfnVarToBool
752 */
753DECLINLINE(int) DBGCCmdHlpVarToBool(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, bool *pf)
754{
755 return pCmdHlp->pfnVarToBool(pCmdHlp, pVar, pf);
756}
757
758/**
759 * @copydoc DBGCCMDHLP::pfnVarGetRange
760 */
761DECLINLINE(int) DBGCCmdHlpVarGetRange(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t cbElement, uint64_t cbDefault, uint64_t *pcbRange)
762{
763 return pCmdHlp->pfnVarGetRange(pCmdHlp, pVar, cbElement, cbDefault, pcbRange);
764}
765
766/**
767 * @copydoc DBGCCMDHLP::pfnVarConvert
768 */
769DECLINLINE(int) DBGCCmdHlpConvert(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, DBGCVARTYPE enmToType, bool fConvSyms, PDBGCVAR pResult)
770{
771 return pCmdHlp->pfnVarConvert(pCmdHlp, pVar, enmToType, fConvSyms, pResult);
772}
773
774/**
775 * @copydoc DBGCCMDHLP::pfnGetDbgfOutputHlp
776 */
777DECLINLINE(PCDBGFINFOHLP) DBGCCmdHlpGetDbgfOutputHlp(PDBGCCMDHLP pCmdHlp)
778{
779 return pCmdHlp->pfnGetDbgfOutputHlp(pCmdHlp);
780}
781
782#endif /* IN_RING3 */
783
784
785
786/**
787 * Command handler.
788 *
789 * The console will call the handler for a command once it's finished
790 * parsing the user input. The command handler function is responsible
791 * for executing the command itself.
792 *
793 * @returns VBox status.
794 * @param pCmd Pointer to the command descriptor (as registered).
795 * @param pCmdHlp Pointer to command helper functions.
796 * @param pVM Pointer to the current VM (if any).
797 * @param paArgs Pointer to (readonly) array of arguments.
798 * @param cArgs Number of arguments in the array.
799 * @param pResult Where to store the result. NULL if no result descriptor was specified.
800 */
801typedef DECLCALLBACK(int) FNDBGCCMD(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pArgs, unsigned cArgs, PDBGCVAR pResult);
802/** Pointer to a FNDBGCCMD() function. */
803typedef FNDBGCCMD *PFNDBGCCMD;
804
805/**
806 * DBGC command descriptor.
807 *
808 * If a pResultDesc is specified the command can be called and used
809 * as a function too. If it's a pure function, set fFlags to
810 * DBGCCMD_FLAGS_FUNCTION.
811 */
812typedef struct DBGCCMD
813{
814 /** Command string. */
815 const char *pszCmd;
816 /** Minimum number of arguments. */
817 unsigned cArgsMin;
818 /** Max number of arguments. */
819 unsigned cArgsMax;
820 /** Argument descriptors (array). */
821 PCDBGCVARDESC paArgDescs;
822 /** Number of argument descriptors. */
823 unsigned cArgDescs;
824 /** Result descriptor. */
825 PCDBGCVARDESC pResultDesc;
826 /** flags. (reserved for now) */
827 unsigned fFlags;
828 /** Handler function. */
829 PFNDBGCCMD pfnHandler;
830 /** Command syntax. */
831 const char *pszSyntax;
832 /** Command description. */
833 const char *pszDescription;
834} DBGCCMD;
835
836/** DBGCCMD Flags.
837 * @{
838 */
839/** The description is of a pure function which cannot be invoked
840 * as a command from the commandline. */
841#define DBGCCMD_FLAGS_FUNCTION 1
842/** @} */
843
844
845
846/** Pointer to a DBGC backend. */
847typedef struct DBGCBACK *PDBGCBACK;
848
849/**
850 * Checks if there is input.
851 *
852 * @returns true if there is input ready.
853 * @returns false if there not input ready.
854 * @param pBack Pointer to the backend structure supplied by
855 * the backend. The backend can use this to find
856 * it's instance data.
857 * @param cMillies Number of milliseconds to wait on input data.
858 */
859typedef DECLCALLBACK(bool) FNDBGCBACKINPUT(PDBGCBACK pBack, uint32_t cMillies);
860/** Pointer to a FNDBGCBACKINPUT() callback. */
861typedef FNDBGCBACKINPUT *PFNDBGCBACKINPUT;
862
863/**
864 * Read input.
865 *
866 * @returns VBox status code.
867 * @param pBack Pointer to the backend structure supplied by
868 * the backend. The backend can use this to find
869 * it's instance data.
870 * @param pvBuf Where to put the bytes we read.
871 * @param cbBuf Maximum nymber of bytes to read.
872 * @param pcbRead Where to store the number of bytes actually read.
873 * If NULL the entire buffer must be filled for a
874 * successful return.
875 */
876typedef DECLCALLBACK(int) FNDBGCBACKREAD(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
877/** Pointer to a FNDBGCBACKREAD() callback. */
878typedef FNDBGCBACKREAD *PFNDBGCBACKREAD;
879
880/**
881 * Write (output).
882 *
883 * @returns VBox status code.
884 * @param pBack Pointer to the backend structure supplied by
885 * the backend. The backend can use this to find
886 * it's instance data.
887 * @param pvBuf What to write.
888 * @param cbBuf Number of bytes to write.
889 * @param pcbWritten Where to store the number of bytes actually written.
890 * If NULL the entire buffer must be successfully written.
891 */
892typedef DECLCALLBACK(int) FNDBGCBACKWRITE(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
893/** Pointer to a FNDBGCBACKWRITE() callback. */
894typedef FNDBGCBACKWRITE *PFNDBGCBACKWRITE;
895
896/**
897 * Ready / busy notification.
898 *
899 * @param pBack Pointer to the backend structure supplied by
900 * the backend. The backend can use this to find
901 * it's instance data.
902 * @param fReady Whether it's ready (true) or busy (false).
903 */
904typedef DECLCALLBACK(void) FNDBGCBACKSETREADY(PDBGCBACK pBack, bool fReady);
905/** Pointer to a FNDBGCBACKSETREADY() callback. */
906typedef FNDBGCBACKSETREADY *PFNDBGCBACKSETREADY;
907
908
909/**
910 * The communication backend provides the console with a number of callbacks
911 * which can be used
912 */
913typedef struct DBGCBACK
914{
915 /** Check for input. */
916 PFNDBGCBACKINPUT pfnInput;
917 /** Read input. */
918 PFNDBGCBACKREAD pfnRead;
919 /** Write output. */
920 PFNDBGCBACKWRITE pfnWrite;
921 /** Ready / busy notification. */
922 PFNDBGCBACKSETREADY pfnSetReady;
923} DBGCBACK;
924
925
926/**
927 * Make a console instance.
928 *
929 * This will not return until either an 'exit' command is issued or a error code
930 * indicating connection loss is encountered.
931 *
932 * @returns VINF_SUCCESS if console termination caused by the 'exit' command.
933 * @returns The VBox status code causing the console termination.
934 *
935 * @param pVM VM Handle.
936 * @param pBack Pointer to the backend structure. This must contain
937 * a full set of function pointers to service the console.
938 * @param fFlags Reserved, must be zero.
939 * @remark A forced termination of the console is easiest done by forcing the
940 * callbacks to return fatal failures.
941 */
942DBGDECL(int) DBGCCreate(PVM pVM, PDBGCBACK pBack, unsigned fFlags);
943
944
945/**
946 * Register one or more external commands.
947 *
948 * @returns VBox status.
949 * @param paCommands Pointer to an array of command descriptors.
950 * The commands must be unique. It's not possible
951 * to register the same commands more than once.
952 * @param cCommands Number of commands.
953 */
954DBGDECL(int) DBGCRegisterCommands(PCDBGCCMD paCommands, unsigned cCommands);
955
956
957/**
958 * Deregister one or more external commands previously registered by
959 * DBGCRegisterCommands().
960 *
961 * @returns VBox status.
962 * @param paCommands Pointer to an array of command descriptors
963 * as given to DBGCRegisterCommands().
964 * @param cCommands Number of commands.
965 */
966DBGDECL(int) DBGCDeregisterCommands(PCDBGCCMD paCommands, unsigned cCommands);
967
968
969/**
970 * Spawns a new thread with a TCP based debugging console service.
971 *
972 * @returns VBox status.
973 * @param pVM VM handle.
974 * @param ppvData Where to store the pointer to instance data.
975 */
976DBGDECL(int) DBGCTcpCreate(PVM pVM, void **ppvUser);
977
978/**
979 * Terminates any running TCP base debugger console service.
980 *
981 * @returns VBox status.
982 * @param pVM VM handle.
983 * @param pvData Instance data set by DBGCTcpCreate().
984 */
985DBGDECL(int) DBGCTcpTerminate(PVM pVM, void *pvData);
986
987
988/** @defgroup grp_dbgc_plug_in The DBGC Plug-in Interface
989 * @{
990 */
991
992/** The plug-in module name prefix. */
993#define DBGC_PLUG_IN_PREFIX "DBGCPlugIn"
994
995/** The name of the plug-in entry point (FNDBGCPLUGIN) */
996#define DBGC_PLUG_IN_ENTRYPOINT "DBGCPlugInEntry"
997
998/**
999 * DBGC plug-in operations.
1000 */
1001typedef enum DBGCPLUGINOP
1002{
1003 /** The usual invalid first value. */
1004 DBGCPLUGINOP_INVALID,
1005 /** Initialize the plug-in, register all the stuff.
1006 * The plug-in will be unloaded on failure.
1007 * uArg: The VirtualBox version (major+minor). */
1008 DBGCPLUGINOP_INIT,
1009 /** Terminate the plug-ing, deregister all the stuff.
1010 * The plug-in will be unloaded after this call regardless of the return
1011 * code. */
1012 DBGCPLUGINOP_TERM,
1013 /** The usual 32-bit hack. */
1014 DBGCPLUGINOP_32BIT_HACK = 0x7fffffff
1015} DBGCPLUGINOP;
1016
1017/**
1018 * DBGC plug-in main entry point.
1019 *
1020 * @returns VBox status code.
1021 *
1022 * @param enmOperation The operation.
1023 * @param pVM The VM handle. This may be NULL.
1024 * @param uArg Extra argument.
1025 */
1026typedef DECLCALLBACK(int) FNDBGCPLUGIN(DBGCPLUGINOP enmOperation, PVM pVM, uintptr_t uArg);
1027/** Pointer to a FNDBGCPLUGIN. */
1028typedef FNDBGCPLUGIN *PFNDBGCPLUGIN;
1029
1030/** @copydoc FNDBGCPLUGIN */
1031DECLEXPORT(int) DBGCPlugInEntry(DBGCPLUGINOP enmOperation, PVM pVM, uintptr_t uArg);
1032
1033/** @} */
1034
1035
1036RT_C_DECLS_END
1037
1038#endif
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