VirtualBox

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

最後變更 在這個檔案從41565是 41565,由 vboxsync 提交於 13 年 前

DBGC: Implemented the functions by(addr), dwo(addr), not(value/addr), poi(addr), qwo(addr), and wo(addr). (untested)

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 38.8 KB
 
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.alldomusa.eu.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#ifdef IN_RING3 /* The debugger stuff is ring-3 only. */
45
46/** @def VBOX_WITH_DEBUGGER
47 * The build is with debugger module. Test if this is defined before registering
48 * external debugger commands. This is normally defined in Config.kmk.
49 */
50#ifdef DOXYGEN_RUNNING
51# define VBOX_WITH_DEBUGGER
52#endif
53
54
55/**
56 * DBGC variable category.
57 *
58 * Used to describe an argument to a command or function and a functions
59 * return value.
60 */
61typedef enum DBGCVARCAT
62{
63 /** Any type is fine. */
64 DBGCVAR_CAT_ANY = 0,
65 /** Any kind of pointer or number. */
66 DBGCVAR_CAT_POINTER_NUMBER,
67 /** Any kind of pointer or number, no range. */
68 DBGCVAR_CAT_POINTER_NUMBER_NO_RANGE,
69 /** Any kind of pointer. */
70 DBGCVAR_CAT_POINTER,
71 /** Any kind of pointer with no range option. */
72 DBGCVAR_CAT_POINTER_NO_RANGE,
73 /** GC pointer. */
74 DBGCVAR_CAT_GC_POINTER,
75 /** GC pointer with no range option. */
76 DBGCVAR_CAT_GC_POINTER_NO_RANGE,
77 /** Numeric argument. */
78 DBGCVAR_CAT_NUMBER,
79 /** Numeric argument with no range option. */
80 DBGCVAR_CAT_NUMBER_NO_RANGE,
81 /** String. */
82 DBGCVAR_CAT_STRING,
83 /** Symbol. */
84 DBGCVAR_CAT_SYMBOL,
85 /** Option. */
86 DBGCVAR_CAT_OPTION,
87 /** Option + string. */
88 DBGCVAR_CAT_OPTION_STRING,
89 /** Option + number. */
90 DBGCVAR_CAT_OPTION_NUMBER
91} DBGCVARCAT;
92
93
94/**
95 * DBGC variable type.
96 */
97typedef enum DBGCVARTYPE
98{
99 /** unknown... */
100 DBGCVAR_TYPE_UNKNOWN = 0,
101 /** Flat GC pointer. */
102 DBGCVAR_TYPE_GC_FLAT,
103 /** Segmented GC pointer. */
104 DBGCVAR_TYPE_GC_FAR,
105 /** Physical GC pointer. */
106 DBGCVAR_TYPE_GC_PHYS,
107 /** Flat HC pointer. */
108 DBGCVAR_TYPE_HC_FLAT,
109 /** Physical HC pointer. */
110 DBGCVAR_TYPE_HC_PHYS,
111 /** String. */
112 DBGCVAR_TYPE_STRING,
113 /** Number. */
114 DBGCVAR_TYPE_NUMBER,
115 /** Symbol.
116 * @todo drop this */
117 DBGCVAR_TYPE_SYMBOL,
118 /** Special type used when querying symbols. */
119 DBGCVAR_TYPE_ANY
120} DBGCVARTYPE;
121
122/** @todo Rename to DBGCVAR_IS_xyz. */
123
124/** Checks if the specified variable type is of a pointer persuasion. */
125#define DBGCVAR_ISPOINTER(enmType) ((enmType) >= DBGCVAR_TYPE_GC_FLAT && enmType <= DBGCVAR_TYPE_HC_PHYS)
126/** Checks if the specified variable type is of a pointer persuasion. */
127#define DBGCVAR_IS_FAR_PTR(enmType) ((enmType) == DBGCVAR_TYPE_GC_FAR)
128/** Checks if the specified variable type is of a pointer persuasion and of the guest context sort. */
129#define DBGCVAR_ISGCPOINTER(enmType) ((enmType) >= DBGCVAR_TYPE_GC_FLAT && (enmType) <= DBGCVAR_TYPE_GC_PHYS)
130/** Checks if the specified variable type is of a pointer persuasion and of the host context sort. */
131#define DBGCVAR_ISHCPOINTER(enmType) ((enmType) >= DBGCVAR_TYPE_HC_FLAT && (enmType) <= DBGCVAR_TYPE_HC_PHYS)
132
133
134/**
135 * DBGC variable range type.
136 */
137typedef enum DBGCVARRANGETYPE
138{
139 /** No range appliable or no range specified. */
140 DBGCVAR_RANGE_NONE = 0,
141 /** Number of elements. */
142 DBGCVAR_RANGE_ELEMENTS,
143 /** Number of bytes. */
144 DBGCVAR_RANGE_BYTES
145} DBGCVARRANGETYPE;
146
147
148/**
149 * Variable descriptor.
150 */
151typedef struct DBGCVARDESC
152{
153 /** The minimal number of times this argument may occur.
154 * Use 0 here to inidicate that the argument is optional. */
155 unsigned cTimesMin;
156 /** Maximum number of occurrences.
157 * Use ~0 here to indicate infinite. */
158 unsigned cTimesMax;
159 /** Argument category. */
160 DBGCVARCAT enmCategory;
161 /** Flags, DBGCVD_FLAGS_* */
162 unsigned fFlags;
163 /** Argument name. */
164 const char *pszName;
165 /** Argument name. */
166 const char *pszDescription;
167} DBGCVARDESC;
168/** Pointer to an argument descriptor. */
169typedef DBGCVARDESC *PDBGCVARDESC;
170/** Pointer to a const argument descriptor. */
171typedef const DBGCVARDESC *PCDBGCVARDESC;
172
173/** Variable descriptor flags.
174 * @{ */
175/** Indicates that the variable depends on the previous being present. */
176#define DBGCVD_FLAGS_DEP_PREV RT_BIT(1)
177/** @} */
178
179
180/**
181 * DBGC variable.
182 */
183typedef struct DBGCVAR
184{
185 /** Pointer to the argument descriptor. */
186 PCDBGCVARDESC pDesc;
187 /** Pointer to the next argument. */
188 struct DBGCVAR *pNext;
189
190 /** Argument type. */
191 DBGCVARTYPE enmType;
192 /** Type specific. */
193 union
194 {
195 /** Flat GC Address. (DBGCVAR_TYPE_GC_FLAT) */
196 RTGCPTR GCFlat;
197 /** Far (16:32) GC Address. (DBGCVAR_TYPE_GC_FAR) */
198 RTFAR32 GCFar;
199 /** Physical GC Address. (DBGCVAR_TYPE_GC_PHYS) */
200 RTGCPHYS GCPhys;
201 /** Flat HC Address. (DBGCVAR_TYPE_HC_FLAT) */
202 void *pvHCFlat;
203 /** Physical GC Address. (DBGCVAR_TYPE_HC_PHYS) */
204 RTHCPHYS HCPhys;
205 /** String. (DBGCVAR_TYPE_STRING)
206 * The basic idea is the the this is a pointer to the expression we're
207 * parsing, so no messing with freeing. */
208 const char *pszString;
209 /** Number. (DBGCVAR_TYPE_NUMBER) */
210 uint64_t u64Number;
211 } u;
212
213 /** Range type. */
214 DBGCVARRANGETYPE enmRangeType;
215 /** Range. The use of the content depends on the enmRangeType. */
216 uint64_t u64Range;
217} DBGCVAR;
218/** Pointer to a command argument. */
219typedef DBGCVAR *PDBGCVAR;
220/** Pointer to a const command argument. */
221typedef const DBGCVAR *PCDBGCVAR;
222
223
224/**
225 * Macro for initializing a DBGC variable with defaults.
226 * The result is an unknown variable type without any range.
227 */
228#define DBGCVAR_INIT(pVar) \
229 do { \
230 (pVar)->pDesc = NULL;\
231 (pVar)->pNext = NULL; \
232 (pVar)->enmType = DBGCVAR_TYPE_UNKNOWN; \
233 (pVar)->u.u64Number = 0; \
234 (pVar)->enmRangeType = DBGCVAR_RANGE_NONE; \
235 (pVar)->u64Range = 0; \
236 } while (0)
237
238/**
239 * Macro for initializing a DBGC variable with a HC physical address.
240 */
241#define DBGCVAR_INIT_HC_PHYS(pVar, Phys) \
242 do { \
243 DBGCVAR_INIT(pVar); \
244 (pVar)->enmType = DBGCVAR_TYPE_HC_PHYS; \
245 (pVar)->u.HCPhys = (Phys); \
246 } while (0)
247
248/**
249 * Macro for initializing a DBGC variable with a HC flat address.
250 */
251#define DBGCVAR_INIT_HC_FLAT(pVar, Flat) \
252 do { \
253 DBGCVAR_INIT(pVar); \
254 (pVar)->enmType = DBGCVAR_TYPE_HC_FLAT; \
255 (pVar)->u.pvHCFlat = (Flat); \
256 } while (0)
257
258/**
259 * Macro for initializing a DBGC variable with a GC physical address.
260 */
261#define DBGCVAR_INIT_GC_PHYS(pVar, Phys) \
262 do { \
263 DBGCVAR_INIT(pVar); \
264 (pVar)->enmType = DBGCVAR_TYPE_GC_PHYS; \
265 (pVar)->u.GCPhys = (Phys); \
266 } while (0)
267
268/**
269 * Macro for initializing a DBGC variable with a GC flat address.
270 */
271#define DBGCVAR_INIT_GC_FLAT(pVar, Flat) \
272 do { \
273 DBGCVAR_INIT(pVar); \
274 (pVar)->enmType = DBGCVAR_TYPE_GC_FLAT; \
275 (pVar)->u.GCFlat = (Flat); \
276 } while (0)
277
278/**
279 * Macro for initializing a DBGC variable with a GC flat address.
280 */
281#define DBGCVAR_INIT_GC_FLAT_BYTE_RANGE(pVar, Flat, cbRange) \
282 do { \
283 DBGCVAR_INIT(pVar); \
284 (pVar)->enmType = DBGCVAR_TYPE_GC_FLAT; \
285 (pVar)->u.GCFlat = (Flat); \
286 DBGCVAR_SET_RANGE(pVar, DBGCVAR_RANGE_BYTES, cbRange); \
287 } while (0)
288
289/**
290 * Macro for initializing a DBGC variable with a GC far address.
291 */
292#define DBGCVAR_INIT_GC_FAR(pVar, _sel, _off) \
293 do { \
294 DBGCVAR_INIT(pVar); \
295 (pVar)->enmType = DBGCVAR_TYPE_GC_FAR; \
296 (pVar)->u.GCFar.sel = (_sel); \
297 (pVar)->u.GCFar.off = (_off); \
298 } while (0)
299
300/**
301 * Macro for initializing a DBGC variable with a number.
302 */
303#define DBGCVAR_INIT_NUMBER(pVar, Value) \
304 do { \
305 DBGCVAR_INIT(pVar); \
306 (pVar)->enmType = DBGCVAR_TYPE_NUMBER; \
307 (pVar)->u.u64Number = (Value); \
308 } while (0)
309
310/**
311 * Macro for initializing a DBGC variable with a string.
312 */
313#define DBGCVAR_INIT_STRING(pVar, a_pszString) \
314 do { \
315 DBGCVAR_INIT(pVar); \
316 (pVar)->enmType = DBGCVAR_TYPE_STRING; \
317 (pVar)->enmRangeType = DBGCVAR_RANGE_BYTES; \
318 (pVar)->u.pszString = (a_pszString); \
319 (pVar)->u64Range = strlen(a_pszString); \
320 } while (0)
321
322
323/**
324 * Macro for setting the range of a DBGC variable.
325 * @param pVar The variable.
326 * @param _enmRangeType The range type.
327 * @param Value The range length value.
328 */
329#define DBGCVAR_SET_RANGE(pVar, _enmRangeType, Value) \
330 do { \
331 (pVar)->enmRangeType = (_enmRangeType); \
332 (pVar)->u64Range = (Value); \
333 } while (0)
334
335
336/**
337 * Macro for setting the range of a DBGC variable.
338 * @param a_pVar The variable.
339 * @param a_cbRange The range, in bytes.
340 */
341#define DBGCVAR_SET_BYTE_RANGE(a_pVar, a_cbRange) \
342 DBGCVAR_SET_RANGE(a_pVar, DBGCVAR_RANGE_BYTES, a_cbRange)
343
344
345/**
346 * Macro for resetting the range a DBGC variable.
347 * @param a_pVar The variable.
348 */
349#define DBGCVAR_ZAP_RANGE(a_pVar) \
350 do { \
351 (a_pVar)->enmRangeType = DBGCVAR_RANGE_NONE; \
352 (a_pVar)->u64Range = 0; \
353 } while (0)
354
355
356/**
357 * Macro for assigning one DBGC variable to another.
358 * @param a_pResult The result (target) variable.
359 * @param a_pVar The source variable.
360 */
361#define DBGCVAR_ASSIGN(a_pResult, a_pVar) \
362 do { \
363 *(a_pResult) = *(a_pVar); \
364 } while (0)
365
366
367/** Pointer to a command descriptor. */
368typedef struct DBGCCMD *PDBGCCMD;
369/** Pointer to a const command descriptor. */
370typedef const struct DBGCCMD *PCDBGCCMD;
371
372/** Pointer to a function descriptor. */
373typedef struct DBGCFUNC *PDBGCFUNC;
374/** Pointer to a const function descriptor. */
375typedef const struct DBGCFUNC *PCDBGCFUNC;
376
377/** Pointer to helper functions for commands. */
378typedef struct DBGCCMDHLP *PDBGCCMDHLP;
379
380
381/**
382 * Helper functions for commands.
383 */
384typedef struct DBGCCMDHLP
385{
386 /** Magic value (DBGCCMDHLP_MAGIC). */
387 uint32_t u32Magic;
388
389 /**
390 * Command helper for writing formatted text to the debug console.
391 *
392 * @returns VBox status.
393 * @param pCmdHlp Pointer to the command callback structure.
394 * @param pcb Where to store the number of bytes written.
395 * @param pszFormat The format string. This may use all IPRT extensions as
396 * well as the debugger ones.
397 * @param ... Arguments specified in the format string.
398 */
399 DECLCALLBACKMEMBER(int, pfnPrintf)(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, ...);
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. This may use all IPRT extensions as
408 * well as the debugger ones.
409 * @param args Arguments specified in the format string.
410 */
411 DECLCALLBACKMEMBER(int, pfnPrintfV)(PDBGCCMDHLP pCmdHlp, size_t *pcbWritten, const char *pszFormat, va_list args);
412
413 /**
414 * Command helper for formatting a string with debugger format specifiers.
415 *
416 * @returns The number of bytes written.
417 * @param pCmdHlp Pointer to the command callback structure.
418 * @param pszBuf The output buffer.
419 * @param cbBuf The size of the output buffer.
420 * @param pszFormat The format string. This may use all IPRT extensions as
421 * well as the debugger ones.
422 * @param ... Arguments specified in the format string.
423 */
424 DECLCALLBACKMEMBER(size_t, pfnStrPrintf)(PDBGCCMDHLP pCmdHlp, char *pszBuf, size_t cbBuf, const char *pszFormat, ...);
425
426 /**
427 * Command helper for formatting a string with debugger format specifiers.
428 *
429 * @returns The number of bytes written.
430 * @param pCmdHlp Pointer to the command callback structure.
431 * @param pszBuf The output buffer.
432 * @param cbBuf The size of the output buffer.
433 * @param pszFormat The format string. This may use all IPRT extensions as
434 * well as the debugger ones.
435 * @param va Arguments specified in the format string.
436 */
437 DECLCALLBACKMEMBER(size_t, pfnStrPrintfV)(PDBGCCMDHLP pCmdHlp, char *pszBuf, size_t cbBuf,
438 const char *pszFormat, va_list va);
439
440 /**
441 * Command helper for formatting and error message for a VBox status code.
442 *
443 * @returns VBox status code appropriate to return from a command.
444 * @param pCmdHlp Pointer to the command callback structure.
445 * @param rc The VBox status code.
446 * @param pszFormat Format string for additional messages. Can be NULL.
447 * @param ... Format arguments, optional.
448 */
449 DECLCALLBACKMEMBER(int, pfnVBoxError)(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, ...);
450
451 /**
452 * Command helper for formatting and error message for a VBox status code.
453 *
454 * @returns VBox status code appropriate to return from a command.
455 * @param pCmdHlp Pointer to the command callback structure.
456 * @param rc The VBox status code.
457 * @param pcb Where to store the number of bytes written.
458 * @param pszFormat Format string for additional messages. Can be NULL.
459 * @param args Format arguments, optional.
460 */
461 DECLCALLBACKMEMBER(int, pfnVBoxErrorV)(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, va_list args);
462
463 /**
464 * Command helper for reading memory specified by a DBGC variable.
465 *
466 * @returns VBox status code appropriate to return from a command.
467 * @param pCmdHlp Pointer to the command callback structure.
468 * @param pVM VM handle if GC or physical HC address.
469 * @param pvBuffer Where to store the read data.
470 * @param cbRead Number of bytes to read.
471 * @param pVarPointer DBGC variable specifying where to start reading.
472 * @param pcbRead Where to store the number of bytes actually read.
473 * This optional, but it's useful when read GC virtual memory where a
474 * page in the requested range might not be present.
475 * If not specified not-present failure or end of a HC physical page
476 * will cause failure.
477 */
478 DECLCALLBACKMEMBER(int, pfnMemRead)(PDBGCCMDHLP pCmdHlp, PVM pVM, void *pvBuffer, size_t cbRead, PCDBGCVAR pVarPointer, size_t *pcbRead);
479
480 /**
481 * Command helper for writing memory specified by a DBGC variable.
482 *
483 * @returns VBox status code appropriate to return from a command.
484 * @param pCmdHlp Pointer to the command callback structure.
485 * @param pVM VM handle if GC or physical HC address.
486 * @param pvBuffer What to write.
487 * @param cbWrite Number of bytes to write.
488 * @param pVarPointer DBGC variable specifying where to start reading.
489 * @param pcbWritten Where to store the number of bytes written.
490 * This is optional. If NULL be aware that some of the buffer
491 * might have been written to the specified address.
492 */
493 DECLCALLBACKMEMBER(int, pfnMemWrite)(PDBGCCMDHLP pCmdHlp, PVM pVM, const void *pvBuffer, size_t cbWrite, PCDBGCVAR pVarPointer, size_t *pcbWritten);
494
495 /**
496 * Executes command an expression.
497 * (Hopefully the parser and functions are fully reentrant.)
498 *
499 * @returns VBox status code appropriate to return from a command.
500 * @param pCmdHlp Pointer to the command callback structure.
501 * @param pszExpr The expression. Format string with the format DBGC extensions.
502 * @param ... Format arguments.
503 */
504 DECLCALLBACKMEMBER(int, pfnExec)(PDBGCCMDHLP pCmdHlp, const char *pszExpr, ...);
505
506 /**
507 * Evaluates an expression.
508 * (Hopefully the parser and functions are fully reentrant.)
509 *
510 * @returns VBox status code appropriate to return from a command.
511 * @param pCmdHlp Pointer to the command callback structure.
512 * @param pResult Where to store the result.
513 * @param pszExpr The expression. Format string with the format DBGC extensions.
514 * @param va Format arguments.
515 */
516 DECLCALLBACKMEMBER(int, pfnEvalV)(PDBGCCMDHLP pCmdHlp, PDBGCVAR pResult, const char *pszExpr, va_list va);
517
518 /**
519 * Print an error and fail the current command.
520 *
521 * @returns VBox status code to pass upwards.
522 *
523 * @param pCmdHlp Pointer to the command callback structure.
524 * @param pCmd The failing command.
525 * @param pszFormat The error message format string.
526 * @param va Format arguments.
527 */
528 DECLCALLBACKMEMBER(int, pfnFailV)(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, const char *pszFormat, va_list va);
529
530 /**
531 * Print an error and fail the current command.
532 *
533 * @returns VBox status code to pass upwards.
534 *
535 * @param pCmdHlp Pointer to the command callback structure.
536 * @param pCmd The failing command.
537 * @param rc The status code indicating the failure. This will
538 * be appended to the message after a colon (': ').
539 * @param pszFormat The error message format string.
540 * @param va Format arguments.
541 *
542 * @see DBGCCmdHlpFailRc
543 */
544 DECLCALLBACKMEMBER(int, pfnFailRcV)(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, int rc, const char *pszFormat, va_list va);
545
546 /**
547 * Parser error.
548 *
549 * @returns VBox status code to pass upwards.
550 *
551 * @param pCmdHlp Pointer to the command callback structure.
552 * @param pCmd The failing command, can be NULL but shouldn't.
553 * @param iArg The offending argument, -1 when lazy.
554 * @param pszExpr The expression.
555 * @param iLine The line number.
556 */
557 DECLCALLBACKMEMBER(int, pfnParserError)(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, int iArg, const char *pszExpr, unsigned iLine);
558
559 /**
560 * Converts a DBGC variable to a DBGF address structure.
561 *
562 * @returns VBox status code.
563 * @param pCmdHlp Pointer to the command callback structure.
564 * @param pVar The variable to convert.
565 * @param pAddress The target address.
566 */
567 DECLCALLBACKMEMBER(int, pfnVarToDbgfAddr)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, PDBGFADDRESS pAddress);
568
569 /**
570 * Converts a DBGF address structure to a DBGC variable.
571 *
572 * @returns VBox status code.
573 * @param pCmdHlp Pointer to the command callback structure.
574 * @param pAddress The source address.
575 * @param pResult The result variable.
576 */
577 DECLCALLBACKMEMBER(int, pfnVarFromDbgfAddr)(PDBGCCMDHLP pCmdHlp, PCDBGFADDRESS pAddress, PDBGCVAR pResult);
578
579 /**
580 * Converts a DBGC variable to a 64-bit number.
581 *
582 * @returns VBox status code.
583 * @param pCmdHlp Pointer to the command callback structure.
584 * @param pVar The variable to convert.
585 * @param pu64Number Where to store the number.
586 */
587 DECLCALLBACKMEMBER(int, pfnVarToNumber)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t *pu64Number);
588
589 /**
590 * Converts a DBGC variable to a boolean.
591 *
592 * @returns VBox status code.
593 * @param pCmdHlp Pointer to the command callback structure.
594 * @param pVar The variable to convert.
595 * @param pf Where to store the boolean.
596 */
597 DECLCALLBACKMEMBER(int, pfnVarToBool)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, bool *pf);
598
599 /**
600 * Get the range of a variable in bytes, resolving symbols if necessary.
601 *
602 * @returns VBox status code.
603 * @param pCmdHlp Pointer to the command callback structure.
604 * @param pVar The variable to convert.
605 * @param cbElement Conversion factor for element ranges.
606 * @param cbDefault The default range.
607 * @param pcbRange The length of the range.
608 */
609 DECLCALLBACKMEMBER(int, pfnVarGetRange)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t cbElement, uint64_t cbDefault,
610 uint64_t *pcbRange);
611
612 /**
613 * Converts a variable to one with the specified type.
614 *
615 * This preserves the range.
616 *
617 * @returns VBox status code.
618 * @param pCmdHlp Pointer to the command callback structure.
619 * @param pVar The variable to convert.
620 * @param enmToType The target type.
621 * @param fConvSyms If @c true, then attempt to resolve symbols.
622 * @param pResult The output variable. Can be the same as @a pVar.
623 */
624 DECLCALLBACKMEMBER(int, pfnVarConvert)(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, DBGCVARTYPE enmToType, bool fConvSyms,
625 PDBGCVAR pResult);
626
627 /**
628 * Gets a DBGF output helper that directs the output to the debugger
629 * console.
630 *
631 * @returns Pointer to the helper structure.
632 * @param pCmdHlp Pointer to the command callback structure.
633 */
634 DECLCALLBACKMEMBER(PCDBGFINFOHLP, pfnGetDbgfOutputHlp)(PDBGCCMDHLP pCmdHlp);
635
636 /**
637 * Gets the ID currently selected CPU.
638 *
639 * @returns Current CPU ID.
640 * @param pCmdHlp Pointer to the command callback structure.
641 */
642 DECLCALLBACKMEMBER(VMCPUID, pfnGetCurrentCpu)(PDBGCCMDHLP pCmdHlp);
643
644 /**
645 * Gets the mode the currently selected CPU is running in, in the current
646 * context.
647 *
648 * @returns Current CPU mode.
649 * @param pCmdHlp Pointer to the command callback structure.
650 */
651 DECLCALLBACKMEMBER(CPUMMODE, pfnGetCpuMode)(PDBGCCMDHLP pCmdHlp);
652
653 /** End marker (DBGCCMDHLP_MAGIC). */
654 uint32_t u32EndMarker;
655} DBGCCMDHLP;
656
657/** Magic value for DBGCCMDHLP::u32Magic. (Fyodor Mikhaylovich Dostoyevsky) */
658#define DBGCCMDHLP_MAGIC UINT32_C(18211111)
659
660
661#ifdef IN_RING3
662
663/**
664 * @copydoc DBGCCMDHLP::pfnPrintf
665 */
666DECLINLINE(int) DBGCCmdHlpPrintf(PDBGCCMDHLP pCmdHlp, const char *pszFormat, ...)
667{
668 va_list va;
669 int rc;
670
671 va_start(va, pszFormat);
672 rc = pCmdHlp->pfnPrintfV(pCmdHlp, NULL, pszFormat, va);
673 va_end(va);
674
675 return rc;
676}
677
678
679/**
680 * @copydoc DBGCCMDHLP::pfnStrPrintf
681 */
682DECLINLINE(size_t) DBGCCmdHlpStrPrintf(PDBGCCMDHLP pCmdHlp, char *pszBuf, size_t cbBuf, const char *pszFormat, ...)
683{
684 va_list va;
685 size_t cch;
686
687 va_start(va, pszFormat);
688 cch = pCmdHlp->pfnStrPrintfV(pCmdHlp, pszBuf, cbBuf, pszFormat, va);
689 va_end(va);
690
691 return cch;
692}
693
694/**
695 * @copydoc FNDBGCHLPVBOXERROR
696 */
697DECLINLINE(int) DBGCCmdHlpVBoxError(PDBGCCMDHLP pCmdHlp, int rc, const char *pszFormat, ...)
698{
699 va_list va;
700
701 va_start(va, pszFormat);
702 rc = pCmdHlp->pfnVBoxErrorV(pCmdHlp, rc, pszFormat, va);
703 va_end(va);
704
705 return rc;
706}
707
708/**
709 * @copydoc FNDBGCHLPMEMREAD
710 */
711DECLINLINE(int) DBGCCmdHlpMemRead(PDBGCCMDHLP pCmdHlp, PVM pVM, void *pvBuffer, size_t cbRead, PCDBGCVAR pVarPointer, size_t *pcbRead)
712{
713 return pCmdHlp->pfnMemRead(pCmdHlp, pVM, pvBuffer, cbRead, pVarPointer, pcbRead);
714}
715
716/**
717 * Evaluates an expression.
718 * (Hopefully the parser and functions are fully reentrant.)
719 *
720 * @returns VBox status code appropriate to return from a command.
721 * @param pCmdHlp Pointer to the command callback structure.
722 * @param pResult Where to store the result.
723 * @param pszExpr The expression. Format string with the format DBGC extensions.
724 * @param ... Format arguments.
725 */
726DECLINLINE(int) DBGCCmdHlpEval(PDBGCCMDHLP pCmdHlp, PDBGCVAR pResult, const char *pszExpr, ...)
727{
728 va_list va;
729 int rc;
730
731 va_start(va, pszExpr);
732 rc = pCmdHlp->pfnEvalV(pCmdHlp, pResult, pszExpr, va);
733 va_end(va);
734
735 return rc;
736}
737
738/**
739 * Print an error and fail the current command.
740 *
741 * @returns VBox status code to pass upwards.
742 *
743 * @param pCmdHlp Pointer to the command callback structure.
744 * @param pCmd The failing command.
745 * @param pszFormat The error message format string.
746 * @param ... Format arguments.
747 */
748DECLINLINE(int) DBGCCmdHlpFail(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, const char *pszFormat, ...)
749{
750 va_list va;
751 int rc;
752
753 va_start(va, pszFormat);
754 rc = pCmdHlp->pfnFailV(pCmdHlp, pCmd, pszFormat, va);
755 va_end(va);
756
757 return rc;
758}
759
760/**
761 * Print an error and fail the current command.
762 *
763 * Usage example:
764 * @code
765 int rc = VMMR3Something(pVM);
766 if (RT_FAILURE(rc))
767 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "VMMR3Something");
768 return VINF_SUCCESS;
769 * @endcode
770 *
771 * @returns VBox status code to pass upwards.
772 *
773 * @param pCmdHlp Pointer to the command callback structure.
774 * @param pCmd The failing command.
775 * @param rc The status code indicating the failure.
776 * @param pszFormat The error message format string.
777 * @param ... Format arguments.
778 */
779DECLINLINE(int) DBGCCmdHlpFailRc(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, int rc, const char *pszFormat, ...)
780{
781 va_list va;
782
783 va_start(va, pszFormat);
784 rc = pCmdHlp->pfnFailRcV(pCmdHlp, pCmd, rc, pszFormat, va);
785 va_end(va);
786
787 return rc;
788}
789
790/**
791 * @copydoc DBGCCMDHLP::pfnParserError
792 */
793DECLINLINE(int) DBGCCmdHlpParserError(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, int iArg, const char *pszExpr, unsigned iLine)
794{
795 return pCmdHlp->pfnParserError(pCmdHlp, pCmd, iArg, pszExpr, iLine);
796}
797
798/** Assert+return like macro for checking parser sanity.
799 * Returns with failure if the precodition is not met. */
800#define DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, iArg, expr) \
801 do { \
802 if (!(expr)) \
803 return DBGCCmdHlpParserError(pCmdHlp, pCmd, iArg, #expr, __LINE__); \
804 } while (0)
805
806/** Assert+return like macro that the VM handle is present.
807 * Returns with failure if the VM handle is NIL. */
808#define DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM) \
809 do { \
810 if (!(pVM)) \
811 return DBGCCmdHlpFail(pCmdHlp, pCmd, "No VM selected"); \
812 } while (0)
813
814/**
815 * @copydoc DBGCCMDHLP::pfnVarToDbgfAddr
816 */
817DECLINLINE(int) DBGCCmdHlpVarToDbgfAddr(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, PDBGFADDRESS pAddress)
818{
819 return pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pVar, pAddress);
820}
821
822/**
823 * @copydoc DBGCCMDHLP::pfnVarToDbgfAddr
824 */
825DECLINLINE(int) DBGCCmdHlpVarFromDbgfAddr(PDBGCCMDHLP pCmdHlp, PCDBGFADDRESS pAddress, PDBGCVAR pResult)
826{
827 return pCmdHlp->pfnVarFromDbgfAddr(pCmdHlp, pAddress, pResult);
828}
829
830/**
831 * Converts an variable to a flat address.
832 *
833 * @returns VBox status code.
834 * @param pCmdHlp Pointer to the command callback structure.
835 * @param pVar The variable to convert.
836 * @param pFlatPtr Where to store the flat address.
837 */
838DECLINLINE(int) DBGCCmdHlpVarToFlatAddr(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, PRTGCPTR pFlatPtr)
839{
840 DBGFADDRESS Addr;
841 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pVar, &Addr);
842 if (RT_SUCCESS(rc))
843 *pFlatPtr = Addr.FlatPtr;
844 return rc;
845}
846
847/**
848 * @copydoc DBGCCMDHLP::pfnVarToNumber
849 */
850DECLINLINE(int) DBGCCmdHlpVarToNumber(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t *pu64Number)
851{
852 return pCmdHlp->pfnVarToNumber(pCmdHlp, pVar, pu64Number);
853}
854
855/**
856 * @copydoc DBGCCMDHLP::pfnVarToBool
857 */
858DECLINLINE(int) DBGCCmdHlpVarToBool(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, bool *pf)
859{
860 return pCmdHlp->pfnVarToBool(pCmdHlp, pVar, pf);
861}
862
863/**
864 * @copydoc DBGCCMDHLP::pfnVarGetRange
865 */
866DECLINLINE(int) DBGCCmdHlpVarGetRange(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, uint64_t cbElement, uint64_t cbDefault, uint64_t *pcbRange)
867{
868 return pCmdHlp->pfnVarGetRange(pCmdHlp, pVar, cbElement, cbDefault, pcbRange);
869}
870
871/**
872 * @copydoc DBGCCMDHLP::pfnVarConvert
873 */
874DECLINLINE(int) DBGCCmdHlpConvert(PDBGCCMDHLP pCmdHlp, PCDBGCVAR pVar, DBGCVARTYPE enmToType, bool fConvSyms, PDBGCVAR pResult)
875{
876 return pCmdHlp->pfnVarConvert(pCmdHlp, pVar, enmToType, fConvSyms, pResult);
877}
878
879/**
880 * @copydoc DBGCCMDHLP::pfnGetDbgfOutputHlp
881 */
882DECLINLINE(PCDBGFINFOHLP) DBGCCmdHlpGetDbgfOutputHlp(PDBGCCMDHLP pCmdHlp)
883{
884 return pCmdHlp->pfnGetDbgfOutputHlp(pCmdHlp);
885}
886
887/**
888 * @copydoc DBGCCMDHLP::pfnGetCurrentCpu
889 */
890DECLINLINE(VMCPUID) DBGCCmdHlpGetCurrentCpu(PDBGCCMDHLP pCmdHlp)
891{
892 return pCmdHlp->pfnGetCurrentCpu(pCmdHlp);
893}
894
895/**
896 * @copydoc DBGCCMDHLP::pfnGetCpuMode
897 */
898DECLINLINE(CPUMMODE) DBGCCmdHlpGetCpuMode(PDBGCCMDHLP pCmdHlp)
899{
900 return pCmdHlp->pfnGetCpuMode(pCmdHlp);
901}
902
903#endif /* IN_RING3 */
904
905
906
907/**
908 * Command handler.
909 *
910 * The console will call the handler for a command once it's finished
911 * parsing the user input. The command handler function is responsible
912 * for executing the command itself.
913 *
914 * @returns VBox status.
915 * @param pCmd Pointer to the command descriptor (as registered).
916 * @param pCmdHlp Pointer to command helper functions.
917 * @param pVM Pointer to the current VM (if any).
918 * @param paArgs Pointer to (readonly) array of arguments.
919 * @param cArgs Number of arguments in the array.
920 */
921typedef DECLCALLBACK(int) FNDBGCCMD(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
922/** Pointer to a FNDBGCCMD() function. */
923typedef FNDBGCCMD *PFNDBGCCMD;
924
925/**
926 * DBGC command descriptor.
927 */
928typedef struct DBGCCMD
929{
930 /** Command string. */
931 const char *pszCmd;
932 /** Minimum number of arguments. */
933 unsigned cArgsMin;
934 /** Max number of arguments. */
935 unsigned cArgsMax;
936 /** Argument descriptors (array). */
937 PCDBGCVARDESC paArgDescs;
938 /** Number of argument descriptors. */
939 unsigned cArgDescs;
940 /** flags. (reserved for now) */
941 unsigned fFlags;
942 /** Handler function. */
943 PFNDBGCCMD pfnHandler;
944 /** Command syntax. */
945 const char *pszSyntax;
946 /** Command description. */
947 const char *pszDescription;
948} DBGCCMD;
949
950/** DBGCCMD Flags.
951 * @{
952 */
953/** @} */
954
955
956/**
957 * Function handler.
958 *
959 * The console will call the handler for a command once it's finished
960 * parsing the user input. The command handler function is responsible
961 * for executing the command itself.
962 *
963 * @returns VBox status.
964 * @param pCmd Pointer to the command descriptor (as registered).
965 * @param pCmdHlp Pointer to command helper functions.
966 * @param pVM Pointer to the current VM (if any).
967 * @param paArgs Pointer to (readonly) array of arguments.
968 * @param cArgs Number of arguments in the array.
969 * @param pResult Where to return the result.
970 */
971typedef DECLCALLBACK(int) FNDBGCFUNC(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs,
972 PDBGCVAR pResult);
973/** Pointer to a FNDBGCFUNC() function. */
974typedef FNDBGCFUNC *PFNDBGCFUNC;
975
976/**
977 * DBGC function descriptor.
978 */
979typedef struct DBGCFUNC
980{
981 /** Command string. */
982 const char *pszFuncNm;
983 /** Minimum number of arguments. */
984 unsigned cArgsMin;
985 /** Max number of arguments. */
986 unsigned cArgsMax;
987 /** Argument descriptors (array). */
988 PCDBGCVARDESC paArgDescs;
989 /** Number of argument descriptors. */
990 unsigned cArgDescs;
991 /** flags. (reserved for now) */
992 unsigned fFlags;
993 /** Handler function. */
994 PFNDBGCFUNC pfnHandler;
995 /** Function syntax. */
996 const char *pszSyntax;
997 /** Function description. */
998 const char *pszDescription;
999} DBGCFUNC;
1000
1001
1002
1003/** Pointer to a DBGC backend. */
1004typedef struct DBGCBACK *PDBGCBACK;
1005
1006/**
1007 * Checks if there is input.
1008 *
1009 * @returns true if there is input ready.
1010 * @returns false if there not input ready.
1011 * @param pBack Pointer to the backend structure supplied by
1012 * the backend. The backend can use this to find
1013 * it's instance data.
1014 * @param cMillies Number of milliseconds to wait on input data.
1015 */
1016typedef DECLCALLBACK(bool) FNDBGCBACKINPUT(PDBGCBACK pBack, uint32_t cMillies);
1017/** Pointer to a FNDBGCBACKINPUT() callback. */
1018typedef FNDBGCBACKINPUT *PFNDBGCBACKINPUT;
1019
1020/**
1021 * Read input.
1022 *
1023 * @returns VBox status code.
1024 * @param pBack Pointer to the backend structure supplied by
1025 * the backend. The backend can use this to find
1026 * it's instance data.
1027 * @param pvBuf Where to put the bytes we read.
1028 * @param cbBuf Maximum nymber of bytes to read.
1029 * @param pcbRead Where to store the number of bytes actually read.
1030 * If NULL the entire buffer must be filled for a
1031 * successful return.
1032 */
1033typedef DECLCALLBACK(int) FNDBGCBACKREAD(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
1034/** Pointer to a FNDBGCBACKREAD() callback. */
1035typedef FNDBGCBACKREAD *PFNDBGCBACKREAD;
1036
1037/**
1038 * Write (output).
1039 *
1040 * @returns VBox status code.
1041 * @param pBack Pointer to the backend structure supplied by
1042 * the backend. The backend can use this to find
1043 * it's instance data.
1044 * @param pvBuf What to write.
1045 * @param cbBuf Number of bytes to write.
1046 * @param pcbWritten Where to store the number of bytes actually written.
1047 * If NULL the entire buffer must be successfully written.
1048 */
1049typedef DECLCALLBACK(int) FNDBGCBACKWRITE(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
1050/** Pointer to a FNDBGCBACKWRITE() callback. */
1051typedef FNDBGCBACKWRITE *PFNDBGCBACKWRITE;
1052
1053/**
1054 * Ready / busy notification.
1055 *
1056 * @param pBack Pointer to the backend structure supplied by
1057 * the backend. The backend can use this to find
1058 * it's instance data.
1059 * @param fReady Whether it's ready (true) or busy (false).
1060 */
1061typedef DECLCALLBACK(void) FNDBGCBACKSETREADY(PDBGCBACK pBack, bool fReady);
1062/** Pointer to a FNDBGCBACKSETREADY() callback. */
1063typedef FNDBGCBACKSETREADY *PFNDBGCBACKSETREADY;
1064
1065
1066/**
1067 * The communication backend provides the console with a number of callbacks
1068 * which can be used
1069 */
1070typedef struct DBGCBACK
1071{
1072 /** Check for input. */
1073 PFNDBGCBACKINPUT pfnInput;
1074 /** Read input. */
1075 PFNDBGCBACKREAD pfnRead;
1076 /** Write output. */
1077 PFNDBGCBACKWRITE pfnWrite;
1078 /** Ready / busy notification. */
1079 PFNDBGCBACKSETREADY pfnSetReady;
1080} DBGCBACK;
1081
1082
1083/**
1084 * Make a console instance.
1085 *
1086 * This will not return until either an 'exit' command is issued or a error code
1087 * indicating connection loss is encountered.
1088 *
1089 * @returns VINF_SUCCESS if console termination caused by the 'exit' command.
1090 * @returns The VBox status code causing the console termination.
1091 *
1092 * @param pVM VM Handle.
1093 * @param pBack Pointer to the backend structure. This must contain
1094 * a full set of function pointers to service the console.
1095 * @param fFlags Reserved, must be zero.
1096 * @remark A forced termination of the console is easiest done by forcing the
1097 * callbacks to return fatal failures.
1098 */
1099DBGDECL(int) DBGCCreate(PVM pVM, PDBGCBACK pBack, unsigned fFlags);
1100
1101
1102/**
1103 * Register one or more external commands.
1104 *
1105 * @returns VBox status.
1106 * @param paCommands Pointer to an array of command descriptors.
1107 * The commands must be unique. It's not possible
1108 * to register the same commands more than once.
1109 * @param cCommands Number of commands.
1110 */
1111DBGDECL(int) DBGCRegisterCommands(PCDBGCCMD paCommands, unsigned cCommands);
1112
1113
1114/**
1115 * Deregister one or more external commands previously registered by
1116 * DBGCRegisterCommands().
1117 *
1118 * @returns VBox status.
1119 * @param paCommands Pointer to an array of command descriptors
1120 * as given to DBGCRegisterCommands().
1121 * @param cCommands Number of commands.
1122 */
1123DBGDECL(int) DBGCDeregisterCommands(PCDBGCCMD paCommands, unsigned cCommands);
1124
1125
1126/**
1127 * Spawns a new thread with a TCP based debugging console service.
1128 *
1129 * @returns VBox status.
1130 * @param pVM VM handle.
1131 * @param ppvData Where to store the pointer to instance data.
1132 */
1133DBGDECL(int) DBGCTcpCreate(PVM pVM, void **ppvUser);
1134
1135/**
1136 * Terminates any running TCP base debugger console service.
1137 *
1138 * @returns VBox status.
1139 * @param pVM VM handle.
1140 * @param pvData Instance data set by DBGCTcpCreate().
1141 */
1142DBGDECL(int) DBGCTcpTerminate(PVM pVM, void *pvData);
1143
1144
1145/** @defgroup grp_dbgc_plug_in The DBGC Plug-in Interface
1146 * @{
1147 */
1148
1149/** The plug-in module name prefix. */
1150#define DBGC_PLUG_IN_PREFIX "DBGCPlugIn"
1151
1152/** The name of the plug-in entry point (FNDBGCPLUGIN) */
1153#define DBGC_PLUG_IN_ENTRYPOINT "DBGCPlugInEntry"
1154
1155/**
1156 * DBGC plug-in operations.
1157 */
1158typedef enum DBGCPLUGINOP
1159{
1160 /** The usual invalid first value. */
1161 DBGCPLUGINOP_INVALID,
1162 /** Initialize the plug-in, register all the stuff.
1163 * The plug-in will be unloaded on failure.
1164 * uArg: The VirtualBox version (major+minor). */
1165 DBGCPLUGINOP_INIT,
1166 /** Terminate the plug-ing, deregister all the stuff.
1167 * The plug-in will be unloaded after this call regardless of the return
1168 * code. */
1169 DBGCPLUGINOP_TERM,
1170 /** The usual 32-bit hack. */
1171 DBGCPLUGINOP_32BIT_HACK = 0x7fffffff
1172} DBGCPLUGINOP;
1173
1174/**
1175 * DBGC plug-in main entry point.
1176 *
1177 * @returns VBox status code.
1178 *
1179 * @param enmOperation The operation.
1180 * @param pVM The VM handle. This may be NULL.
1181 * @param uArg Extra argument.
1182 */
1183typedef DECLCALLBACK(int) FNDBGCPLUGIN(DBGCPLUGINOP enmOperation, PVM pVM, uintptr_t uArg);
1184/** Pointer to a FNDBGCPLUGIN. */
1185typedef FNDBGCPLUGIN *PFNDBGCPLUGIN;
1186
1187/** @copydoc FNDBGCPLUGIN */
1188DECLEXPORT(int) DBGCPlugInEntry(DBGCPLUGINOP enmOperation, PVM pVM, uintptr_t uArg);
1189
1190#endif /* IN_RING3 */
1191
1192/** @} */
1193
1194
1195RT_C_DECLS_END
1196
1197#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette