VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/DBGFInfo.cpp@ 92192

Last change on this file since 92192 was 90549, checked in by vboxsync, 3 years ago

VMM,*: s/DBGFR3InfoGenricGetOptError/DBGFR3InfoGenericGetOptError/g

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 50.2 KB
Line 
1/* $Id: DBGFInfo.cpp 90549 2021-08-06 13:57:29Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, Info.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DBGF_INFO
23#include <VBox/vmm/dbgf.h>
24
25#include <VBox/vmm/mm.h>
26#include "DBGFInternal.h"
27#include <VBox/vmm/vm.h>
28#include <VBox/vmm/uvm.h>
29#include <VBox/err.h>
30#include <VBox/log.h>
31
32#include <iprt/assert.h>
33#include <iprt/ctype.h>
34#include <iprt/getopt.h>
35#include <iprt/param.h>
36#include <iprt/semaphore.h>
37#include <iprt/stream.h>
38#include <iprt/string.h>
39#include <iprt/thread.h>
40
41
42/*********************************************************************************************************************************
43* Internal Functions *
44*********************************************************************************************************************************/
45static DECLCALLBACK(void) dbgfR3InfoLog_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
46static DECLCALLBACK(void) dbgfR3InfoLog_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
47static DECLCALLBACK(void) dbgfR3InfoLogRel_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
48static DECLCALLBACK(void) dbgfR3InfoLogRel_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
49static DECLCALLBACK(void) dbgfR3InfoStdErr_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
50static DECLCALLBACK(void) dbgfR3InfoStdErr_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
51static DECLCALLBACK(void) dbgfR3InfoHelp(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
52
53
54/*********************************************************************************************************************************
55* Global Variables *
56*********************************************************************************************************************************/
57/** Logger output. */
58static const DBGFINFOHLP g_dbgfR3InfoLogHlp =
59{
60 dbgfR3InfoLog_Printf,
61 dbgfR3InfoLog_PrintfV,
62 DBGFR3InfoGenericGetOptError,
63};
64
65/** Release logger output. */
66static const DBGFINFOHLP g_dbgfR3InfoLogRelHlp =
67{
68 dbgfR3InfoLogRel_Printf,
69 dbgfR3InfoLogRel_PrintfV,
70 DBGFR3InfoGenericGetOptError
71};
72
73/** Standard error output. */
74static const DBGFINFOHLP g_dbgfR3InfoStdErrHlp =
75{
76 dbgfR3InfoStdErr_Printf,
77 dbgfR3InfoStdErr_PrintfV,
78 DBGFR3InfoGenericGetOptError
79};
80
81
82/**
83 * Initialize the info handlers.
84 *
85 * This is called first during the DBGF init process and thus does the shared
86 * critsect init.
87 *
88 * @returns VBox status code.
89 * @param pUVM The user mode VM handle.
90 */
91int dbgfR3InfoInit(PUVM pUVM)
92{
93 /*
94 * Make sure we already didn't initialized in the lazy manner.
95 */
96 if (RTCritSectRwIsInitialized(&pUVM->dbgf.s.CritSect))
97 return VINF_SUCCESS;
98
99 /*
100 * Initialize the crit sect.
101 */
102 int rc = RTCritSectRwInit(&pUVM->dbgf.s.CritSect);
103 AssertRCReturn(rc, rc);
104
105 /*
106 * Register the 'info help' item.
107 */
108 rc = DBGFR3InfoRegisterInternal(pUVM->pVM, "help", "List of info items.", dbgfR3InfoHelp);
109 AssertRCReturn(rc, rc);
110
111 return VINF_SUCCESS;
112}
113
114
115/**
116 * Terminate the info handlers.
117 *
118 * @returns VBox status code.
119 * @param pUVM The user mode VM handle.
120 */
121int dbgfR3InfoTerm(PUVM pUVM)
122{
123 /*
124 * Delete the crit sect.
125 */
126 int rc = RTCritSectRwDelete(&pUVM->dbgf.s.CritSect);
127 AssertRC(rc);
128 return rc;
129}
130
131
132/**
133 * @interface_method_impl{DBGFINFOHLP,pfnGetOptError}
134 */
135VMMR3DECL(void) DBGFR3InfoGenericGetOptError(PCDBGFINFOHLP pHlp, int rc, PRTGETOPTUNION pValueUnion, PRTGETOPTSTATE pState)
136{
137 RT_NOREF(pState);
138 char szMsg[1024];
139 RTGetOptFormatError(szMsg, sizeof(szMsg), rc, pValueUnion);
140 pHlp->pfnPrintf(pHlp, "syntax error: %s\n", szMsg);
141}
142
143
144/**
145 * @interface_method_impl{DBGFINFOHLP,pfnPrintf, Logger output.}
146 */
147static DECLCALLBACK(void) dbgfR3InfoLog_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
148{
149 NOREF(pHlp);
150 va_list args;
151 va_start(args, pszFormat);
152 RTLogPrintfV(pszFormat, args);
153 va_end(args);
154}
155
156
157/**
158 * @interface_method_impl{DBGFINFOHLP,pfnPrintfV, Logger output.}
159 */
160static DECLCALLBACK(void) dbgfR3InfoLog_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
161{
162 NOREF(pHlp);
163 RTLogPrintfV(pszFormat, args);
164}
165
166
167/**
168 * Gets the logger info helper.
169 * The returned info helper will unconditionally write all output to the log.
170 *
171 * @returns Pointer to the logger info helper.
172 */
173VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogHlp(void)
174{
175 return &g_dbgfR3InfoLogHlp;
176}
177
178
179/**
180 * @interface_method_impl{DBGFINFOHLP,pfnPrintf, Release logger output.}
181 */
182static DECLCALLBACK(void) dbgfR3InfoLogRel_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
183{
184 NOREF(pHlp);
185 va_list args;
186 va_start(args, pszFormat);
187 RTLogRelPrintfV(pszFormat, args);
188 va_end(args);
189}
190
191
192/**
193 * @interface_method_impl{DBGFINFOHLP,pfnPrintfV, Release logger output.}
194 */
195static DECLCALLBACK(void) dbgfR3InfoLogRel_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
196{
197 NOREF(pHlp);
198 RTLogRelPrintfV(pszFormat, args);
199}
200
201
202/**
203 * @interface_method_impl{DBGFINFOHLP,pfnPrintf, Stdandard error output.}
204 */
205static DECLCALLBACK(void) dbgfR3InfoStdErr_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
206{
207 NOREF(pHlp);
208 va_list args;
209 va_start(args, pszFormat);
210 RTStrmPrintfV(g_pStdErr, pszFormat, args);
211 va_end(args);
212}
213
214
215/**
216 * @interface_method_impl{DBGFINFOHLP,pfnPrintfV, Stdandard error output.}
217 */
218static DECLCALLBACK(void) dbgfR3InfoStdErr_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
219{
220 NOREF(pHlp);
221 RTStrmPrintfV(g_pStdErr, pszFormat, args);
222}
223
224
225/**
226 * Gets the release logger info helper.
227 * The returned info helper will unconditionally write all output to the release log.
228 *
229 * @returns Pointer to the release logger info helper.
230 */
231VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogRelHlp(void)
232{
233 return &g_dbgfR3InfoLogRelHlp;
234}
235
236
237/**
238 * Handle registration worker.
239 *
240 * This allocates the structure, initializes the common fields and inserts into the list.
241 * Upon successful return the we're inside the crit sect and the caller must leave it.
242 *
243 * @returns VBox status code.
244 * @param pUVM The user mode VM handle.
245 * @param pszName The identifier of the info.
246 * @param pszDesc The description of the info and any arguments the handler may take.
247 * @param fFlags The flags.
248 * @param ppInfo Where to store the created
249 */
250static int dbgfR3InfoRegister(PUVM pUVM, const char *pszName, const char *pszDesc, uint32_t fFlags, PDBGFINFO *ppInfo)
251{
252 /*
253 * Validate.
254 */
255 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
256 AssertReturn(*pszName, VERR_INVALID_PARAMETER);
257 AssertPtrReturn(pszDesc, VERR_INVALID_POINTER);
258 AssertMsgReturn(!(fFlags & ~(DBGFINFO_FLAGS_RUN_ON_EMT | DBGFINFO_FLAGS_ALL_EMTS)),
259 ("fFlags=%#x\n", fFlags), VERR_INVALID_FLAGS);
260
261 /*
262 * Allocate and initialize.
263 */
264 int rc;
265 size_t cchName = strlen(pszName) + 1;
266 PDBGFINFO pInfo = (PDBGFINFO)MMR3HeapAllocU(pUVM, MM_TAG_DBGF_INFO, RT_UOFFSETOF_DYN(DBGFINFO, szName[cchName]));
267 if (pInfo)
268 {
269 pInfo->enmType = DBGFINFOTYPE_INVALID;
270 pInfo->fFlags = fFlags;
271 pInfo->pszDesc = pszDesc;
272 pInfo->cchName = cchName - 1;
273 memcpy(pInfo->szName, pszName, cchName);
274
275 /* lazy init */
276 rc = VINF_SUCCESS;
277 if (!RTCritSectRwIsInitialized(&pUVM->dbgf.s.CritSect))
278 rc = dbgfR3InfoInit(pUVM);
279 if (RT_SUCCESS(rc))
280 {
281 /*
282 * Insert in alphabetical order.
283 */
284 rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect);
285 AssertRC(rc);
286 PDBGFINFO pPrev = NULL;
287 PDBGFINFO pCur;
288 for (pCur = pUVM->dbgf.s.pInfoFirst; pCur; pPrev = pCur, pCur = pCur->pNext)
289 if (strcmp(pszName, pCur->szName) < 0)
290 break;
291 pInfo->pNext = pCur;
292 if (pPrev)
293 pPrev->pNext = pInfo;
294 else
295 pUVM->dbgf.s.pInfoFirst = pInfo;
296
297 *ppInfo = pInfo;
298 return VINF_SUCCESS;
299 }
300 MMR3HeapFree(pInfo);
301 }
302 else
303 rc = VERR_NO_MEMORY;
304 return rc;
305}
306
307
308/**
309 * Register a info handler owned by a device.
310 *
311 * @returns VBox status code.
312 * @param pVM The cross context VM structure.
313 * @param pszName The identifier of the info.
314 * @param pszDesc The description of the info and any arguments the handler may take.
315 * @param pfnHandler The handler function to be called to display the info.
316 * @param pDevIns The device instance owning the info.
317 */
318VMMR3_INT_DECL(int) DBGFR3InfoRegisterDevice(PVM pVM, const char *pszName, const char *pszDesc,
319 PFNDBGFHANDLERDEV pfnHandler, PPDMDEVINS pDevIns)
320{
321 LogFlow(("DBGFR3InfoRegisterDevice: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pDevIns=%p\n",
322 pszName, pszName, pszDesc, pszDesc, pfnHandler, pDevIns));
323
324 /*
325 * Validate the specific stuff.
326 */
327 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
328 AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
329
330 /*
331 * Register
332 */
333 PDBGFINFO pInfo;
334 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
335 if (RT_SUCCESS(rc))
336 {
337 pInfo->enmType = DBGFINFOTYPE_DEV;
338 pInfo->u.Dev.pfnHandler = pfnHandler;
339 pInfo->u.Dev.pDevIns = pDevIns;
340 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
341 }
342
343 return rc;
344}
345
346
347/**
348 * Register a info handler owned by a driver.
349 *
350 * @returns VBox status code.
351 * @param pVM The cross context VM structure.
352 * @param pszName The identifier of the info.
353 * @param pszDesc The description of the info and any arguments the handler may take.
354 * @param pfnHandler The handler function to be called to display the info.
355 * @param pDrvIns The driver instance owning the info.
356 */
357VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriver(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler, PPDMDRVINS pDrvIns)
358{
359 LogFlow(("DBGFR3InfoRegisterDriver: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pDrvIns=%p\n",
360 pszName, pszName, pszDesc, pszDesc, pfnHandler, pDrvIns));
361
362 /*
363 * Validate the specific stuff.
364 */
365 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
366 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
367
368 /*
369 * Register
370 */
371 PDBGFINFO pInfo;
372 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
373 if (RT_SUCCESS(rc))
374 {
375 pInfo->enmType = DBGFINFOTYPE_DRV;
376 pInfo->u.Drv.pfnHandler = pfnHandler;
377 pInfo->u.Drv.pDrvIns = pDrvIns;
378 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
379 }
380
381 return rc;
382}
383
384
385/**
386 * Register a info handler owned by an internal component.
387 *
388 * @returns VBox status code.
389 * @param pVM The cross context VM structure.
390 * @param pszName The identifier of the info.
391 * @param pszDesc The description of the info and any arguments the handler may take.
392 * @param pfnHandler The handler function to be called to display the info.
393 */
394VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler)
395{
396 return DBGFR3InfoRegisterInternalEx(pVM, pszName, pszDesc, pfnHandler, 0);
397}
398
399
400/**
401 * Register a info handler owned by an internal component.
402 *
403 * @returns VBox status code.
404 * @param pVM The cross context VM structure.
405 * @param pszName The identifier of the info.
406 * @param pszDesc The description of the info and any arguments the handler may take.
407 * @param pfnHandler The handler function to be called to display the info.
408 * @param fFlags Flags, see the DBGFINFO_FLAGS_*.
409 */
410VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalEx(PVM pVM, const char *pszName, const char *pszDesc,
411 PFNDBGFHANDLERINT pfnHandler, uint32_t fFlags)
412{
413 LogFlow(("DBGFR3InfoRegisterInternalEx: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p fFlags=%x\n",
414 pszName, pszName, pszDesc, pszDesc, pfnHandler, fFlags));
415
416 /*
417 * Validate the specific stuff.
418 */
419 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
420
421 /*
422 * Register
423 */
424 PDBGFINFO pInfo;
425 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, fFlags, &pInfo);
426 if (RT_SUCCESS(rc))
427 {
428 pInfo->enmType = DBGFINFOTYPE_INT;
429 pInfo->u.Int.pfnHandler = pfnHandler;
430 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
431 }
432
433 return rc;
434}
435
436
437/**
438 * Register a info handler owned by an external component.
439 *
440 * @returns VBox status code.
441 * @param pUVM The user mode VM handle.
442 * @param pszName The identifier of the info.
443 * @param pszDesc The description of the info and any arguments the handler may take.
444 * @param pfnHandler The handler function to be called to display the info.
445 * @param pvUser User argument to be passed to the handler.
446 */
447VMMR3DECL(int) DBGFR3InfoRegisterExternal(PUVM pUVM, const char *pszName, const char *pszDesc,
448 PFNDBGFHANDLEREXT pfnHandler, void *pvUser)
449{
450 LogFlow(("DBGFR3InfoRegisterExternal: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pvUser=%p\n",
451 pszName, pszName, pszDesc, pszDesc, pfnHandler, pvUser));
452
453 /*
454 * Validate the specific stuff.
455 */
456 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
457 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
458
459 /*
460 * Register
461 */
462 PDBGFINFO pInfo;
463 int rc = dbgfR3InfoRegister(pUVM, pszName, pszDesc, 0, &pInfo);
464 if (RT_SUCCESS(rc))
465 {
466 pInfo->enmType = DBGFINFOTYPE_EXT;
467 pInfo->u.Ext.pfnHandler = pfnHandler;
468 pInfo->u.Ext.pvUser = pvUser;
469 RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
470 }
471
472 return rc;
473}
474
475
476/**
477 * Register a info handler owned by a device, argv style.
478 *
479 * @returns VBox status code.
480 * @param pVM The cross context VM structure.
481 * @param pszName The identifier of the info.
482 * @param pszDesc The description of the info and any arguments the handler may take.
483 * @param pfnHandler The handler function to be called to display the info.
484 * @param pDevIns The device instance owning the info.
485 */
486VMMR3_INT_DECL(int) DBGFR3InfoRegisterDeviceArgv(PVM pVM, const char *pszName, const char *pszDesc,
487 PFNDBGFINFOARGVDEV pfnHandler, PPDMDEVINS pDevIns)
488{
489 LogFlow(("DBGFR3InfoRegisterDeviceArgv: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pDevIns=%p\n",
490 pszName, pszName, pszDesc, pszDesc, pfnHandler, pDevIns));
491
492 /*
493 * Validate the specific stuff.
494 */
495 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
496 AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
497
498 /*
499 * Register
500 */
501 PDBGFINFO pInfo;
502 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
503 if (RT_SUCCESS(rc))
504 {
505 pInfo->enmType = DBGFINFOTYPE_DEV_ARGV;
506 pInfo->u.DevArgv.pfnHandler = pfnHandler;
507 pInfo->u.DevArgv.pDevIns = pDevIns;
508 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
509 }
510
511 return rc;
512}
513
514
515/**
516 * Register a info handler owned by a driver, argv style.
517 *
518 * @returns VBox status code.
519 * @param pVM The cross context VM structure.
520 * @param pszName The identifier of the info.
521 * @param pszDesc The description of the info and any arguments the handler may take.
522 * @param pfnHandler The handler function to be called to display the info.
523 * @param pDrvIns The driver instance owning the info.
524 */
525VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriverArgv(PVM pVM, const char *pszName, const char *pszDesc,
526 PFNDBGFINFOARGVDRV pfnHandler, PPDMDRVINS pDrvIns)
527{
528 LogFlow(("DBGFR3InfoRegisterDriverArgv: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pDrvIns=%p\n",
529 pszName, pszName, pszDesc, pszDesc, pfnHandler, pDrvIns));
530
531 /*
532 * Validate the specific stuff.
533 */
534 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
535 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
536
537 /*
538 * Register
539 */
540 PDBGFINFO pInfo;
541 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
542 if (RT_SUCCESS(rc))
543 {
544 pInfo->enmType = DBGFINFOTYPE_DRV_ARGV;
545 pInfo->u.DrvArgv.pfnHandler = pfnHandler;
546 pInfo->u.DrvArgv.pDrvIns = pDrvIns;
547 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
548 }
549
550 return rc;
551}
552
553
554/**
555 * Register a info handler owned by a USB device, argv style.
556 *
557 * @returns VBox status code.
558 * @param pVM The cross context VM structure.
559 * @param pszName The identifier of the info.
560 * @param pszDesc The description of the info and any arguments the handler may take.
561 * @param pfnHandler The handler function to be called to display the info.
562 * @param pUsbIns The USB device instance owning the info.
563 */
564VMMR3_INT_DECL(int) DBGFR3InfoRegisterUsbArgv(PVM pVM, const char *pszName, const char *pszDesc,
565 PFNDBGFINFOARGVUSB pfnHandler, PPDMUSBINS pUsbIns)
566{
567 LogFlow(("DBGFR3InfoRegisterDriverArgv: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pUsbIns=%p\n",
568 pszName, pszName, pszDesc, pszDesc, pfnHandler, pUsbIns));
569
570 /*
571 * Validate the specific stuff.
572 */
573 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
574 AssertPtrReturn(pUsbIns, VERR_INVALID_POINTER);
575
576 /*
577 * Register
578 */
579 PDBGFINFO pInfo;
580 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
581 if (RT_SUCCESS(rc))
582 {
583 pInfo->enmType = DBGFINFOTYPE_USB_ARGV;
584 pInfo->u.UsbArgv.pfnHandler = pfnHandler;
585 pInfo->u.UsbArgv.pUsbIns = pUsbIns;
586 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
587 }
588
589 return rc;
590}
591
592
593/**
594 * Register a info handler owned by an internal component, argv style.
595 *
596 * @returns VBox status code.
597 * @param pVM The cross context VM structure.
598 * @param pszName The identifier of the info.
599 * @param pszDesc The description of the info and any arguments the handler may take.
600 * @param pfnHandler The handler function to be called to display the info.
601 * @param fFlags Flags, see the DBGFINFO_FLAGS_*.
602 */
603VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalArgv(PVM pVM, const char *pszName, const char *pszDesc,
604 PFNDBGFINFOARGVINT pfnHandler, uint32_t fFlags)
605{
606 LogFlow(("DBGFR3InfoRegisterInternalArgv: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p fFlags=%x\n",
607 pszName, pszName, pszDesc, pszDesc, pfnHandler, fFlags));
608
609 /*
610 * Validate the specific stuff.
611 */
612 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
613
614 /*
615 * Register
616 */
617 PDBGFINFO pInfo;
618 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, fFlags, &pInfo);
619 if (RT_SUCCESS(rc))
620 {
621 pInfo->enmType = DBGFINFOTYPE_INT_ARGV;
622 pInfo->u.IntArgv.pfnHandler = pfnHandler;
623 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
624 }
625
626 return rc;
627}
628
629
630/**
631 * Register a info handler owned by an external component.
632 *
633 * @returns VBox status code.
634 * @param pUVM The user mode VM handle.
635 * @param pszName The identifier of the info.
636 * @param pszDesc The description of the info and any arguments the handler may take.
637 * @param pfnHandler The handler function to be called to display the info.
638 * @param pvUser User argument to be passed to the handler.
639 */
640VMMR3DECL(int) DBGFR3InfoRegisterExternalArgv(PUVM pUVM, const char *pszName, const char *pszDesc,
641 PFNDBGFINFOARGVEXT pfnHandler, void *pvUser)
642{
643 LogFlow(("DBGFR3InfoRegisterExternalArgv: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pvUser=%p\n",
644 pszName, pszName, pszDesc, pszDesc, pfnHandler, pvUser));
645
646 /*
647 * Validate the specific stuff.
648 */
649 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
650 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
651
652 /*
653 * Register
654 */
655 PDBGFINFO pInfo;
656 int rc = dbgfR3InfoRegister(pUVM, pszName, pszDesc, 0, &pInfo);
657 if (RT_SUCCESS(rc))
658 {
659 pInfo->enmType = DBGFINFOTYPE_EXT_ARGV;
660 pInfo->u.ExtArgv.pfnHandler = pfnHandler;
661 pInfo->u.ExtArgv.pvUser = pvUser;
662 RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
663 }
664
665 return rc;
666}
667
668
669/**
670 * Deregister one(/all) info handler(s) owned by a device.
671 *
672 * @returns VBox status code.
673 * @param pVM The cross context VM structure.
674 * @param pDevIns Device instance.
675 * @param pszName The identifier of the info. If NULL all owned by the device.
676 */
677VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName)
678{
679 LogFlow(("DBGFR3InfoDeregisterDevice: pDevIns=%p pszName=%p:{%s}\n", pDevIns, pszName, pszName));
680
681 /*
682 * Validate input.
683 */
684 AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
685 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
686 size_t cchName = pszName ? strlen(pszName) : 0;
687 PUVM pUVM = pVM->pUVM;
688
689 /*
690 * Enumerate the info handlers and free the requested entries.
691 */
692 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect); AssertRC(rc);
693 rc = VERR_FILE_NOT_FOUND;
694 PDBGFINFO pPrev = NULL;
695 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
696 if (pszName)
697 {
698 /*
699 * Free a specific one.
700 */
701 for (; pInfo; pPrev = pInfo, pInfo = pInfo->pNext)
702 if ( ( (pInfo->enmType == DBGFINFOTYPE_DEV && pInfo->u.Dev.pDevIns == pDevIns)
703 || (pInfo->enmType == DBGFINFOTYPE_DEV_ARGV && pInfo->u.DevArgv.pDevIns == pDevIns))
704 && pInfo->cchName == cchName
705 && memcmp(pInfo->szName, pszName, cchName) == 0)
706 {
707 if (pPrev)
708 pPrev->pNext = pInfo->pNext;
709 else
710 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
711 MMR3HeapFree(pInfo);
712 rc = VINF_SUCCESS;
713 break;
714 }
715 }
716 else
717 {
718 /*
719 * Free all owned by the device.
720 */
721 while (pInfo != NULL)
722 if ( (pInfo->enmType == DBGFINFOTYPE_DEV && pInfo->u.Dev.pDevIns == pDevIns)
723 || (pInfo->enmType == DBGFINFOTYPE_DEV_ARGV && pInfo->u.DevArgv.pDevIns == pDevIns))
724 {
725 PDBGFINFO volatile pFree = pInfo;
726 pInfo = pInfo->pNext;
727 if (pPrev)
728 pPrev->pNext = pInfo;
729 else
730 pUVM->dbgf.s.pInfoFirst = pInfo;
731 MMR3HeapFree(pFree);
732 }
733 else
734 {
735 pPrev = pInfo;
736 pInfo = pInfo->pNext;
737 }
738 rc = VINF_SUCCESS;
739 }
740 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
741 AssertRC(rc2);
742 AssertRC(rc);
743 LogFlow(("DBGFR3InfoDeregisterDevice: returns %Rrc\n", rc));
744 return rc;
745}
746
747
748/**
749 * Deregister one(/all) info handler(s) owned by a driver.
750 *
751 * @returns VBox status code.
752 * @param pVM The cross context VM structure.
753 * @param pDrvIns Driver instance.
754 * @param pszName The identifier of the info. If NULL all owned by the driver.
755 */
756VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName)
757{
758 LogFlow(("DBGFR3InfoDeregisterDriver: pDrvIns=%p pszName=%p:{%s}\n", pDrvIns, pszName, pszName));
759
760 /*
761 * Validate input.
762 */
763 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
764 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
765 size_t cchName = pszName ? strlen(pszName) : 0;
766 PUVM pUVM = pVM->pUVM;
767
768 /*
769 * Enumerate the info handlers and free the requested entries.
770 */
771 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect); AssertRC(rc);
772 rc = VERR_FILE_NOT_FOUND;
773 PDBGFINFO pPrev = NULL;
774 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
775 if (pszName)
776 {
777 /*
778 * Free a specific one.
779 */
780 for (; pInfo; pPrev = pInfo, pInfo = pInfo->pNext)
781 if ( ( (pInfo->enmType == DBGFINFOTYPE_DRV && pInfo->u.Drv.pDrvIns == pDrvIns)
782 || (pInfo->enmType == DBGFINFOTYPE_DRV_ARGV && pInfo->u.DrvArgv.pDrvIns == pDrvIns))
783 && pInfo->cchName == cchName
784 && memcmp(pInfo->szName, pszName, cchName) == 0)
785 {
786 if (pPrev)
787 pPrev->pNext = pInfo->pNext;
788 else
789 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
790 MMR3HeapFree(pInfo);
791 rc = VINF_SUCCESS;
792 break;
793 }
794 }
795 else
796 {
797 /*
798 * Free all owned by the driver.
799 */
800 while (pInfo != NULL)
801 if ( (pInfo->enmType == DBGFINFOTYPE_DRV && pInfo->u.Drv.pDrvIns == pDrvIns)
802 || (pInfo->enmType == DBGFINFOTYPE_DRV_ARGV && pInfo->u.DrvArgv.pDrvIns == pDrvIns))
803 {
804 PDBGFINFO volatile pFree = pInfo;
805 pInfo = pInfo->pNext;
806 if (pPrev)
807 pPrev->pNext = pInfo;
808 else
809 pUVM->dbgf.s.pInfoFirst = pInfo;
810 MMR3HeapFree(pFree);
811 }
812 else
813 {
814 pPrev = pInfo;
815 pInfo = pInfo->pNext;
816 }
817 rc = VINF_SUCCESS;
818 }
819 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
820 AssertRC(rc2);
821 AssertRC(rc);
822 LogFlow(("DBGFR3InfoDeregisterDriver: returns %Rrc\n", rc));
823 return rc;
824}
825
826
827/**
828 * Deregister one(/all) info handler(s) owned by a USB device.
829 *
830 * @returns VBox status code.
831 * @param pVM The cross context VM structure.
832 * @param pUsbIns USB device instance.
833 * @param pszName The identifier of the info. If NULL all owned by the driver.
834 */
835VMMR3_INT_DECL(int) DBGFR3InfoDeregisterUsb(PVM pVM, PPDMUSBINS pUsbIns, const char *pszName)
836{
837 LogFlow(("DBGFR3InfoDeregisterUsb: pUsbIns=%p pszName=%p:{%s}\n", pUsbIns, pszName, pszName));
838
839 /*
840 * Validate input.
841 */
842 AssertPtrReturn(pUsbIns, VERR_INVALID_POINTER);
843 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
844 size_t cchName = pszName ? strlen(pszName) : 0;
845 PUVM pUVM = pVM->pUVM;
846
847 /*
848 * Enumerate the info handlers and free the requested entries.
849 */
850 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect); AssertRC(rc);
851 rc = VERR_FILE_NOT_FOUND;
852 PDBGFINFO pPrev = NULL;
853 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
854 if (pszName)
855 {
856 /*
857 * Free a specific one.
858 */
859 for (; pInfo; pPrev = pInfo, pInfo = pInfo->pNext)
860 if ( pInfo->enmType == DBGFINFOTYPE_USB_ARGV
861 && pInfo->u.UsbArgv.pUsbIns == pUsbIns
862 && pInfo->cchName == cchName
863 && memcmp(pInfo->szName, pszName, cchName) == 0)
864 {
865 if (pPrev)
866 pPrev->pNext = pInfo->pNext;
867 else
868 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
869 MMR3HeapFree(pInfo);
870 rc = VINF_SUCCESS;
871 break;
872 }
873 }
874 else
875 {
876 /*
877 * Free all owned by the driver.
878 */
879 while (pInfo != NULL)
880 if ( pInfo->enmType == DBGFINFOTYPE_USB_ARGV
881 && pInfo->u.UsbArgv.pUsbIns == pUsbIns)
882 {
883 PDBGFINFO volatile pFree = pInfo;
884 pInfo = pInfo->pNext;
885 if (pPrev)
886 pPrev->pNext = pInfo;
887 else
888 pUVM->dbgf.s.pInfoFirst = pInfo;
889 MMR3HeapFree(pFree);
890 }
891 else
892 {
893 pPrev = pInfo;
894 pInfo = pInfo->pNext;
895 }
896 rc = VINF_SUCCESS;
897 }
898 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
899 AssertRC(rc2);
900 AssertRC(rc);
901 LogFlow(("DBGFR3InfoDeregisterDriver: returns %Rrc\n", rc));
902 return rc;
903}
904
905
906/**
907 * Internal deregistration helper.
908 *
909 * @returns VBox status code.
910 * @param pUVM Pointer to the VM.
911 * @param pszName The identifier of the info.
912 * @param enmType1 The first info owner type (old style).
913 * @param enmType2 The second info owner type (argv).
914 */
915static int dbgfR3InfoDeregister(PUVM pUVM, const char *pszName, DBGFINFOTYPE enmType1, DBGFINFOTYPE enmType2)
916{
917 /*
918 * Validate input.
919 */
920 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
921
922 /*
923 * Find the info handler.
924 */
925 size_t cchName = strlen(pszName);
926 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect);
927 AssertRC(rc);
928 rc = VERR_FILE_NOT_FOUND;
929 PDBGFINFO pPrev = NULL;
930 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
931 for (; pInfo; pPrev = pInfo, pInfo = pInfo->pNext)
932 if ( pInfo->cchName == cchName
933 && memcmp(pInfo->szName, pszName, cchName) == 0
934 && (pInfo->enmType == enmType1 || pInfo->enmType == enmType2))
935 {
936 if (pPrev)
937 pPrev->pNext = pInfo->pNext;
938 else
939 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
940 MMR3HeapFree(pInfo);
941 rc = VINF_SUCCESS;
942 break;
943 }
944 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
945 AssertRC(rc2);
946 AssertRC(rc);
947 LogFlow(("dbgfR3InfoDeregister: returns %Rrc\n", rc));
948 return rc;
949}
950
951
952/**
953 * Deregister a info handler owned by an internal component.
954 *
955 * @returns VBox status code.
956 * @param pVM The cross context VM structure.
957 * @param pszName The identifier of the info. If NULL all owned by the device.
958 */
959VMMR3_INT_DECL(int) DBGFR3InfoDeregisterInternal(PVM pVM, const char *pszName)
960{
961 LogFlow(("DBGFR3InfoDeregisterInternal: pszName=%p:{%s}\n", pszName, pszName));
962 return dbgfR3InfoDeregister(pVM->pUVM, pszName, DBGFINFOTYPE_INT, DBGFINFOTYPE_INT_ARGV);
963}
964
965
966/**
967 * Deregister a info handler owned by an external component.
968 *
969 * @returns VBox status code.
970 * @param pUVM The user mode VM handle.
971 * @param pszName The identifier of the info. If NULL all owned by the device.
972 */
973VMMR3DECL(int) DBGFR3InfoDeregisterExternal(PUVM pUVM, const char *pszName)
974{
975 LogFlow(("DBGFR3InfoDeregisterExternal: pszName=%p:{%s}\n", pszName, pszName));
976 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
977 return dbgfR3InfoDeregister(pUVM, pszName, DBGFINFOTYPE_EXT, DBGFINFOTYPE_EXT_ARGV);
978}
979
980
981/**
982 * Worker for DBGFR3InfoEx.
983 *
984 * @returns VBox status code.
985 * @param pUVM The user mode VM handle.
986 * @param idCpu Which CPU to run EMT bound handlers on. VMCPUID_ANY or
987 * a valid CPU ID.
988 * @param pszName What to dump.
989 * @param pszArgs Arguments, optional.
990 * @param pHlp Output helper, optional.
991 */
992static DECLCALLBACK(int) dbgfR3Info(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
993{
994 /*
995 * Validate input.
996 */
997 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
998 AssertPtrNullReturn(pszArgs, VERR_INVALID_POINTER);
999 if (pHlp)
1000 {
1001 AssertPtrReturn(pHlp, VERR_INVALID_PARAMETER);
1002 AssertPtrReturn(pHlp->pfnPrintf, VERR_INVALID_PARAMETER);
1003 AssertPtrReturn(pHlp->pfnPrintfV, VERR_INVALID_PARAMETER);
1004 }
1005 else
1006 pHlp = &g_dbgfR3InfoLogHlp;
1007 Assert(idCpu == NIL_VMCPUID || idCpu < pUVM->cCpus); /* if not nil, we're on that EMT already. */
1008
1009 /*
1010 * Find the info handler.
1011 */
1012 size_t cchName = strlen(pszName);
1013 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
1014 AssertRC(rc);
1015 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
1016 for (; pInfo; pInfo = pInfo->pNext)
1017 if ( pInfo->cchName == cchName
1018 && !memcmp(pInfo->szName, pszName, cchName))
1019 break;
1020 if (pInfo)
1021 {
1022 /*
1023 * Found it.
1024 */
1025 VMCPUID idDstCpu = NIL_VMCPUID;
1026 if ((pInfo->fFlags & (DBGFINFO_FLAGS_RUN_ON_EMT | DBGFINFO_FLAGS_ALL_EMTS)) && idCpu == NIL_VMCPUID)
1027 idDstCpu = pInfo->fFlags & DBGFINFO_FLAGS_ALL_EMTS ? VMCPUID_ALL : VMCPUID_ANY;
1028
1029 rc = VINF_SUCCESS;
1030 switch (pInfo->enmType)
1031 {
1032 case DBGFINFOTYPE_DEV:
1033 if (idDstCpu != NIL_VMCPUID)
1034 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Dev.pfnHandler, 3,
1035 pInfo->u.Dev.pDevIns, pHlp, pszArgs);
1036 else
1037 pInfo->u.Dev.pfnHandler(pInfo->u.Dev.pDevIns, pHlp, pszArgs);
1038 break;
1039
1040 case DBGFINFOTYPE_DRV:
1041 if (idDstCpu != NIL_VMCPUID)
1042 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Drv.pfnHandler, 3,
1043 pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
1044 else
1045 pInfo->u.Drv.pfnHandler(pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
1046 break;
1047
1048 case DBGFINFOTYPE_INT:
1049 if (RT_VALID_PTR(pUVM->pVM))
1050 {
1051 if (idDstCpu != NIL_VMCPUID)
1052 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Int.pfnHandler, 3,
1053 pUVM->pVM, pHlp, pszArgs);
1054 else
1055 pInfo->u.Int.pfnHandler(pUVM->pVM, pHlp, pszArgs);
1056 }
1057 else
1058 rc = VERR_INVALID_VM_HANDLE;
1059 break;
1060
1061 case DBGFINFOTYPE_EXT:
1062 if (idDstCpu != NIL_VMCPUID)
1063 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Ext.pfnHandler, 3,
1064 pInfo->u.Ext.pvUser, pHlp, pszArgs);
1065 else
1066 pInfo->u.Ext.pfnHandler(pInfo->u.Ext.pvUser, pHlp, pszArgs);
1067 break;
1068
1069 case DBGFINFOTYPE_DEV_ARGV:
1070 case DBGFINFOTYPE_DRV_ARGV:
1071 case DBGFINFOTYPE_USB_ARGV:
1072 case DBGFINFOTYPE_INT_ARGV:
1073 case DBGFINFOTYPE_EXT_ARGV:
1074 {
1075 char **papszArgv;
1076 int cArgs;
1077 rc = RTGetOptArgvFromString(&papszArgv, &cArgs, pszArgs ? pszArgs : "", RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
1078 if (RT_SUCCESS(rc))
1079 {
1080 switch (pInfo->enmType)
1081 {
1082 case DBGFINFOTYPE_DEV_ARGV:
1083 if (idDstCpu != NIL_VMCPUID)
1084 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.DevArgv.pfnHandler, 4,
1085 pInfo->u.DevArgv.pDevIns, pHlp, cArgs, papszArgv);
1086 else
1087 pInfo->u.DevArgv.pfnHandler(pInfo->u.DevArgv.pDevIns, pHlp, cArgs, papszArgv);
1088 break;
1089
1090 case DBGFINFOTYPE_DRV_ARGV:
1091 if (idDstCpu != NIL_VMCPUID)
1092 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.DrvArgv.pfnHandler, 4,
1093 pInfo->u.DrvArgv.pDrvIns, pHlp, cArgs, papszArgv);
1094 else
1095 pInfo->u.DrvArgv.pfnHandler(pInfo->u.DrvArgv.pDrvIns, pHlp, cArgs, papszArgv);
1096 break;
1097
1098 case DBGFINFOTYPE_USB_ARGV:
1099 if (idDstCpu != NIL_VMCPUID)
1100 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.UsbArgv.pfnHandler, 4,
1101 pInfo->u.UsbArgv.pUsbIns, pHlp, cArgs, papszArgv);
1102 else
1103 pInfo->u.UsbArgv.pfnHandler(pInfo->u.UsbArgv.pUsbIns, pHlp, cArgs, papszArgv);
1104 break;
1105
1106 case DBGFINFOTYPE_INT_ARGV:
1107 if (RT_VALID_PTR(pUVM->pVM))
1108 {
1109 if (idDstCpu != NIL_VMCPUID)
1110 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.IntArgv.pfnHandler, 4,
1111 pUVM->pVM, pHlp, cArgs, papszArgv);
1112 else
1113 pInfo->u.IntArgv.pfnHandler(pUVM->pVM, pHlp, cArgs, papszArgv);
1114 }
1115 else
1116 rc = VERR_INVALID_VM_HANDLE;
1117 break;
1118
1119 case DBGFINFOTYPE_EXT_ARGV:
1120 if (idDstCpu != NIL_VMCPUID)
1121 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.ExtArgv.pfnHandler, 4,
1122 pInfo->u.ExtArgv.pvUser, pHlp, cArgs, papszArgv);
1123 else
1124 pInfo->u.ExtArgv.pfnHandler(pInfo->u.ExtArgv.pvUser, pHlp, cArgs, papszArgv);
1125 break;
1126
1127 default:
1128 AssertFailedBreakStmt(rc = VERR_INTERNAL_ERROR);
1129 }
1130
1131 RTGetOptArgvFree(papszArgv);
1132 }
1133 break;
1134 }
1135
1136 default:
1137 AssertMsgFailedReturn(("Invalid info type enmType=%d\n", pInfo->enmType), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
1138 }
1139
1140 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
1141 AssertRC(rc2);
1142 }
1143 else
1144 {
1145 rc = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
1146 AssertRC(rc);
1147 rc = VERR_FILE_NOT_FOUND;
1148 }
1149 return rc;
1150}
1151
1152
1153/**
1154 * Display a piece of info writing to the supplied handler.
1155 *
1156 * @returns VBox status code.
1157 * @param pUVM The user mode VM handle.
1158 * @param pszName The identifier of the info to display.
1159 * @param pszArgs Arguments to the info handler.
1160 * @param pHlp The output helper functions. If NULL the logger will be used.
1161 */
1162VMMR3DECL(int) DBGFR3Info(PUVM pUVM, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
1163{
1164 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, pHlp);
1165}
1166
1167
1168/**
1169 * Display a piece of info writing to the supplied handler.
1170 *
1171 * @returns VBox status code.
1172 * @param pUVM The user mode VM handle.
1173 * @param idCpu The CPU to exectue the request on. Pass NIL_VMCPUID
1174 * to not involve any EMT unless necessary.
1175 * @param pszName The identifier of the info to display.
1176 * @param pszArgs Arguments to the info handler.
1177 * @param pHlp The output helper functions. If NULL the logger will be used.
1178 */
1179VMMR3DECL(int) DBGFR3InfoEx(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
1180{
1181 /*
1182 * Some input validation.
1183 */
1184 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
1185 AssertReturn( idCpu != VMCPUID_ANY_QUEUE
1186 && idCpu != VMCPUID_ALL
1187 && idCpu != VMCPUID_ALL_REVERSE, VERR_INVALID_PARAMETER);
1188
1189 /*
1190 * Run on any specific EMT?
1191 */
1192 if (idCpu == NIL_VMCPUID)
1193 return dbgfR3Info(pUVM, NIL_VMCPUID, pszName, pszArgs, pHlp);
1194 return VMR3ReqPriorityCallWaitU(pUVM, idCpu,
1195 (PFNRT)dbgfR3Info, 5, pUVM, idCpu, pszName, pszArgs, pHlp);
1196}
1197
1198
1199/**
1200 * Wrapper for DBGFR3Info that outputs to the release log.
1201 *
1202 * @returns See DBGFR3Info.
1203 * @param pUVM The user mode VM handle.
1204 * @param pszName See DBGFR3Info.
1205 * @param pszArgs See DBGFR3Info.
1206 */
1207VMMR3DECL(int) DBGFR3InfoLogRel(PUVM pUVM, const char *pszName, const char *pszArgs)
1208{
1209 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, &g_dbgfR3InfoLogRelHlp);
1210}
1211
1212
1213/**
1214 * Wrapper for DBGFR3Info that outputs to standard error.
1215 *
1216 * @returns See DBGFR3Info.
1217 * @param pUVM The user mode VM handle.
1218 * @param pszName See DBGFR3Info.
1219 * @param pszArgs See DBGFR3Info.
1220 */
1221VMMR3DECL(int) DBGFR3InfoStdErr(PUVM pUVM, const char *pszName, const char *pszArgs)
1222{
1223 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, &g_dbgfR3InfoStdErrHlp);
1224}
1225
1226
1227/**
1228 * Display several info items.
1229 *
1230 * This is intended used by the fatal error dump only.
1231 *
1232 * @returns VBox status code.
1233 * @param pVM The cross context VM structure.
1234 * @param pszIncludePat Simple string pattern of info items to include.
1235 * @param pszExcludePat Simple string pattern of info items to exclude.
1236 * @param pszSepFmt Item separator format string. The item name will be
1237 * given as parameter.
1238 * @param pHlp The output helper functions. If NULL the logger
1239 * will be used.
1240 *
1241 * @thread EMT
1242 */
1243VMMR3_INT_DECL(int) DBGFR3InfoMulti(PVM pVM, const char *pszIncludePat, const char *pszExcludePat, const char *pszSepFmt,
1244 PCDBGFINFOHLP pHlp)
1245{
1246 /*
1247 * Validate input.
1248 */
1249 PUVM pUVM = pVM->pUVM;
1250 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
1251 AssertPtrReturn(pszIncludePat, VERR_INVALID_POINTER);
1252 AssertPtrReturn(pszExcludePat, VERR_INVALID_POINTER);
1253 if (pHlp)
1254 {
1255 AssertPtrReturn(pHlp->pfnPrintf, VERR_INVALID_POINTER);
1256 AssertPtrReturn(pHlp->pfnPrintfV, VERR_INVALID_POINTER);
1257 }
1258 else
1259 pHlp = &g_dbgfR3InfoLogHlp;
1260
1261 size_t const cchIncludePat = strlen(pszIncludePat);
1262 size_t const cchExcludePat = strlen(pszExcludePat);
1263 const char *pszArgs = "";
1264
1265 /*
1266 * Enumerate the info handlers and call the ones matching.
1267 * Note! We won't leave the critical section here...
1268 */
1269 char *apszArgs[2] = { NULL, NULL };
1270 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
1271 AssertRC(rc);
1272 rc = VWRN_NOT_FOUND;
1273 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
1274 {
1275 if ( RTStrSimplePatternMultiMatch(pszIncludePat, cchIncludePat, pInfo->szName, pInfo->cchName, NULL)
1276 && !RTStrSimplePatternMultiMatch(pszExcludePat, cchExcludePat, pInfo->szName, pInfo->cchName, NULL))
1277 {
1278 pHlp->pfnPrintf(pHlp, pszSepFmt, pInfo->szName);
1279
1280 VMCPUID idDstCpu = NIL_VMCPUID;
1281 if (pInfo->fFlags & (DBGFINFO_FLAGS_RUN_ON_EMT | DBGFINFO_FLAGS_ALL_EMTS))
1282 idDstCpu = pInfo->fFlags & DBGFINFO_FLAGS_ALL_EMTS ? VMCPUID_ALL : VMCPUID_ANY;
1283
1284 rc = VINF_SUCCESS;
1285 switch (pInfo->enmType)
1286 {
1287 case DBGFINFOTYPE_DEV:
1288 if (idDstCpu != NIL_VMCPUID)
1289 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Dev.pfnHandler, 3,
1290 pInfo->u.Dev.pDevIns, pHlp, pszArgs);
1291 else
1292 pInfo->u.Dev.pfnHandler(pInfo->u.Dev.pDevIns, pHlp, pszArgs);
1293 break;
1294
1295 case DBGFINFOTYPE_DRV:
1296 if (idDstCpu != NIL_VMCPUID)
1297 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Drv.pfnHandler, 3,
1298 pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
1299 else
1300 pInfo->u.Drv.pfnHandler(pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
1301 break;
1302
1303 case DBGFINFOTYPE_INT:
1304 if (idDstCpu != NIL_VMCPUID)
1305 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Int.pfnHandler, 3,
1306 pVM, pHlp, pszArgs);
1307 else
1308 pInfo->u.Int.pfnHandler(pVM, pHlp, pszArgs);
1309 break;
1310
1311 case DBGFINFOTYPE_EXT:
1312 if (idDstCpu != NIL_VMCPUID)
1313 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Ext.pfnHandler, 3,
1314 pInfo->u.Ext.pvUser, pHlp, pszArgs);
1315 else
1316 pInfo->u.Ext.pfnHandler(pInfo->u.Ext.pvUser, pHlp, pszArgs);
1317 break;
1318
1319 case DBGFINFOTYPE_DEV_ARGV:
1320 if (idDstCpu != NIL_VMCPUID)
1321 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.DevArgv.pfnHandler, 4,
1322 pInfo->u.DevArgv.pDevIns, pHlp, 0, &apszArgs[0]);
1323 else
1324 pInfo->u.DevArgv.pfnHandler(pInfo->u.DevArgv.pDevIns, pHlp, 0, &apszArgs[0]);
1325 break;
1326
1327 case DBGFINFOTYPE_DRV_ARGV:
1328 if (idDstCpu != NIL_VMCPUID)
1329 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.DrvArgv.pfnHandler, 4,
1330 pInfo->u.DrvArgv.pDrvIns, pHlp, 0, &apszArgs[0]);
1331 else
1332 pInfo->u.DrvArgv.pfnHandler(pInfo->u.DrvArgv.pDrvIns, pHlp, 0, &apszArgs[0]);
1333 break;
1334
1335 case DBGFINFOTYPE_USB_ARGV:
1336 if (idDstCpu != NIL_VMCPUID)
1337 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.UsbArgv.pfnHandler, 4,
1338 pInfo->u.UsbArgv.pUsbIns, pHlp, 0, &apszArgs[0]);
1339 else
1340 pInfo->u.UsbArgv.pfnHandler(pInfo->u.UsbArgv.pUsbIns, pHlp, 0, &apszArgs[0]);
1341 break;
1342
1343 case DBGFINFOTYPE_INT_ARGV:
1344 if (RT_VALID_PTR(pUVM->pVM))
1345 {
1346 if (idDstCpu != NIL_VMCPUID)
1347 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.IntArgv.pfnHandler, 4,
1348 pUVM->pVM, pHlp, 0, &apszArgs[0]);
1349 else
1350 pInfo->u.IntArgv.pfnHandler(pUVM->pVM, pHlp, 0, &apszArgs[0]);
1351 }
1352 else
1353 rc = VERR_INVALID_VM_HANDLE;
1354 break;
1355
1356 case DBGFINFOTYPE_EXT_ARGV:
1357 if (idDstCpu != NIL_VMCPUID)
1358 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.ExtArgv.pfnHandler, 4,
1359 pInfo->u.ExtArgv.pvUser, pHlp, 0, &apszArgs[0]);
1360 else
1361 pInfo->u.ExtArgv.pfnHandler(pInfo->u.ExtArgv.pvUser, pHlp, 0, &apszArgs[0]);
1362 break;
1363
1364 default:
1365 AssertMsgFailedReturn(("Invalid info type enmType=%d\n", pInfo->enmType), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
1366 }
1367 }
1368 }
1369 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
1370 AssertRC(rc2);
1371
1372 return rc;
1373}
1374
1375
1376/**
1377 * Enumerate all the register info handlers.
1378 *
1379 * @returns VBox status code.
1380 * @param pUVM The user mode VM handle.
1381 * @param pfnCallback Pointer to callback function.
1382 * @param pvUser User argument to pass to the callback.
1383 */
1384VMMR3DECL(int) DBGFR3InfoEnum(PUVM pUVM, PFNDBGFINFOENUM pfnCallback, void *pvUser)
1385{
1386 LogFlow(("DBGFR3InfoLog: pfnCallback=%p pvUser=%p\n", pfnCallback, pvUser));
1387
1388 /*
1389 * Validate input.
1390 */
1391 if (!pfnCallback)
1392 {
1393 AssertMsgFailed(("!pfnCallback\n"));
1394 return VERR_INVALID_PARAMETER;
1395 }
1396 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
1397
1398 /*
1399 * Enter and enumerate.
1400 */
1401 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
1402 AssertRC(rc);
1403
1404 rc = VINF_SUCCESS;
1405 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; RT_SUCCESS(rc) && pInfo; pInfo = pInfo->pNext)
1406 rc = pfnCallback(pUVM, pInfo->szName, pInfo->pszDesc, pvUser);
1407
1408 /*
1409 * Leave and exit.
1410 */
1411 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
1412 AssertRC(rc2);
1413
1414 LogFlow(("DBGFR3InfoLog: returns %Rrc\n", rc));
1415 return rc;
1416}
1417
1418
1419/**
1420 * Info handler, internal version.
1421 *
1422 * @param pVM The cross context VM structure.
1423 * @param pHlp Callback functions for doing output.
1424 * @param pszArgs Argument string. Optional and specific to the handler.
1425 */
1426static DECLCALLBACK(void) dbgfR3InfoHelp(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
1427{
1428 LogFlow(("dbgfR3InfoHelp: pszArgs=%s\n", pszArgs));
1429
1430 /*
1431 * Enter and enumerate.
1432 */
1433 PUVM pUVM = pVM->pUVM;
1434 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
1435 AssertRC(rc);
1436
1437 if (pszArgs && *pszArgs)
1438 {
1439 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
1440 {
1441 const char *psz = strstr(pszArgs, pInfo->szName);
1442 if ( psz
1443 && ( psz == pszArgs
1444 || RT_C_IS_SPACE(psz[-1]))
1445 && ( !psz[pInfo->cchName]
1446 || RT_C_IS_SPACE(psz[pInfo->cchName])))
1447 pHlp->pfnPrintf(pHlp, "%-16s %s\n",
1448 pInfo->szName, pInfo->pszDesc);
1449 }
1450 }
1451 else
1452 {
1453 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
1454 pHlp->pfnPrintf(pHlp, "%-16s %s\n",
1455 pInfo->szName, pInfo->pszDesc);
1456 }
1457
1458 /*
1459 * Leave and exit.
1460 */
1461 rc = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
1462 AssertRC(rc);
1463}
1464
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