VirtualBox

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

Last change on this file since 76397 was 73097, checked in by vboxsync, 6 years ago

*: Made RT_UOFFSETOF, RT_OFFSETOF, RT_UOFFSETOF_ADD and RT_OFFSETOF_ADD work like builtin_offsetof() and require compile time resolvable requests, adding RT_UOFFSETOF_DYN for the dynamic questions that can only be answered at runtime.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 34.2 KB
RevLine 
[23]1/* $Id: DBGFInfo.cpp 73097 2018-07-12 21:06:33Z vboxsync $ */
[1]2/** @file
[12677]3 * DBGF - Debugger Facility, Info.
[1]4 */
5
6/*
[69111]7 * Copyright (C) 2006-2017 Oracle Corporation
[1]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
[5999]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.
[1]16 */
17
18
[57358]19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
[1]22#define LOG_GROUP LOG_GROUP_DBGF_INFO
[35346]23#include <VBox/vmm/dbgf.h>
[20152]24
[35346]25#include <VBox/vmm/mm.h>
[1]26#include "DBGFInternal.h"
[35346]27#include <VBox/vmm/vm.h>
[44399]28#include <VBox/vmm/uvm.h>
[20152]29#include <VBox/err.h>
30#include <VBox/log.h>
[1]31
[20152]32#include <iprt/assert.h>
33#include <iprt/ctype.h>
[44399]34#include <iprt/param.h>
[1]35#include <iprt/semaphore.h>
[20152]36#include <iprt/stream.h>
37#include <iprt/string.h>
[1]38#include <iprt/thread.h>
39
40
[57358]41/*********************************************************************************************************************************
42* Internal Functions *
43*********************************************************************************************************************************/
[1]44static DECLCALLBACK(void) dbgfR3InfoLog_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
45static DECLCALLBACK(void) dbgfR3InfoLog_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
46static DECLCALLBACK(void) dbgfR3InfoLogRel_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
47static DECLCALLBACK(void) dbgfR3InfoLogRel_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
[20152]48static DECLCALLBACK(void) dbgfR3InfoStdErr_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
49static DECLCALLBACK(void) dbgfR3InfoStdErr_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
[1]50static DECLCALLBACK(void) dbgfR3InfoHelp(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
51
52
[57358]53/*********************************************************************************************************************************
54* Global Variables *
55*********************************************************************************************************************************/
[1]56/** Logger output. */
57static const DBGFINFOHLP g_dbgfR3InfoLogHlp =
58{
59 dbgfR3InfoLog_Printf,
60 dbgfR3InfoLog_PrintfV
61};
62
63/** Release logger output. */
64static const DBGFINFOHLP g_dbgfR3InfoLogRelHlp =
65{
66 dbgfR3InfoLogRel_Printf,
67 dbgfR3InfoLogRel_PrintfV
68};
69
[20152]70/** Standard error output. */
71static const DBGFINFOHLP g_dbgfR3InfoStdErrHlp =
72{
73 dbgfR3InfoStdErr_Printf,
74 dbgfR3InfoStdErr_PrintfV
75};
[1]76
[20152]77
[1]78/**
79 * Initialize the info handlers.
80 *
[55881]81 * This is called first during the DBGF init process and thus does the shared
82 * critsect init.
83 *
[1]84 * @returns VBox status code.
[44399]85 * @param pUVM The user mode VM handle.
[1]86 */
[44399]87int dbgfR3InfoInit(PUVM pUVM)
[1]88{
89 /*
90 * Make sure we already didn't initialized in the lazy manner.
91 */
[55881]92 if (RTCritSectRwIsInitialized(&pUVM->dbgf.s.CritSect))
[1]93 return VINF_SUCCESS;
94
95 /*
96 * Initialize the crit sect.
97 */
[55881]98 int rc = RTCritSectRwInit(&pUVM->dbgf.s.CritSect);
[1]99 AssertRCReturn(rc, rc);
100
101 /*
102 * Register the 'info help' item.
103 */
[44399]104 rc = DBGFR3InfoRegisterInternal(pUVM->pVM, "help", "List of info items.", dbgfR3InfoHelp);
[1]105 AssertRCReturn(rc, rc);
106
107 return VINF_SUCCESS;
108}
109
110
111/**
112 * Terminate the info handlers.
113 *
114 * @returns VBox status code.
[44399]115 * @param pUVM The user mode VM handle.
[1]116 */
[44399]117int dbgfR3InfoTerm(PUVM pUVM)
[1]118{
119 /*
120 * Delete the crit sect.
121 */
[55881]122 int rc = RTCritSectRwDelete(&pUVM->dbgf.s.CritSect);
[1]123 AssertRC(rc);
124 return rc;
125}
126
127
128/** Logger output.
129 * @copydoc DBGFINFOHLP::pfnPrintf */
130static DECLCALLBACK(void) dbgfR3InfoLog_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
131{
[39078]132 NOREF(pHlp);
[1]133 va_list args;
134 va_start(args, pszFormat);
135 RTLogPrintfV(pszFormat, args);
136 va_end(args);
137}
138
139/** Logger output.
140 * @copydoc DBGFINFOHLP::pfnPrintfV */
141static DECLCALLBACK(void) dbgfR3InfoLog_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
142{
[39078]143 NOREF(pHlp);
[1]144 RTLogPrintfV(pszFormat, args);
145}
146
147
148/**
149 * Gets the logger info helper.
150 * The returned info helper will unconditionally write all output to the log.
151 *
152 * @returns Pointer to the logger info helper.
153 */
[12989]154VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogHlp(void)
[1]155{
156 return &g_dbgfR3InfoLogHlp;
157}
158
159
160/** Release logger output.
161 * @copydoc DBGFINFOHLP::pfnPrintf */
162static DECLCALLBACK(void) dbgfR3InfoLogRel_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
163{
[39078]164 NOREF(pHlp);
[1]165 va_list args;
166 va_start(args, pszFormat);
167 RTLogRelPrintfV(pszFormat, args);
168 va_end(args);
169}
170
171/** Release logger output.
172 * @copydoc DBGFINFOHLP::pfnPrintfV */
173static DECLCALLBACK(void) dbgfR3InfoLogRel_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
174{
[39078]175 NOREF(pHlp);
[1]176 RTLogRelPrintfV(pszFormat, args);
177}
178
179
[20152]180/** Standard error output.
181 * @copydoc DBGFINFOHLP::pfnPrintf */
182static DECLCALLBACK(void) dbgfR3InfoStdErr_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
183{
[39078]184 NOREF(pHlp);
[20152]185 va_list args;
186 va_start(args, pszFormat);
187 RTStrmPrintfV(g_pStdErr, pszFormat, args);
188 va_end(args);
189}
190
191/** Standard error output.
192 * @copydoc DBGFINFOHLP::pfnPrintfV */
193static DECLCALLBACK(void) dbgfR3InfoStdErr_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
194{
[39078]195 NOREF(pHlp);
[20152]196 RTStrmPrintfV(g_pStdErr, pszFormat, args);
197}
198
199
[1]200/**
201 * Gets the release logger info helper.
202 * The returned info helper will unconditionally write all output to the release log.
203 *
204 * @returns Pointer to the release logger info helper.
205 */
[12989]206VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogRelHlp(void)
[1]207{
208 return &g_dbgfR3InfoLogRelHlp;
209}
210
211
212/**
213 * Handle registration worker.
[55881]214 *
[33540]215 * This allocates the structure, initializes the common fields and inserts into the list.
[1]216 * Upon successful return the we're inside the crit sect and the caller must leave it.
217 *
218 * @returns VBox status code.
[44399]219 * @param pUVM The user mode VM handle.
[1]220 * @param pszName The identifier of the info.
221 * @param pszDesc The description of the info and any arguments the handler may take.
[2250]222 * @param fFlags The flags.
[1]223 * @param ppInfo Where to store the created
224 */
[44399]225static int dbgfR3InfoRegister(PUVM pUVM, const char *pszName, const char *pszDesc, uint32_t fFlags, PDBGFINFO *ppInfo)
[1]226{
227 /*
228 * Validate.
229 */
[2250]230 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
231 AssertReturn(*pszName, VERR_INVALID_PARAMETER);
232 AssertPtrReturn(pszDesc, VERR_INVALID_POINTER);
[61570]233 AssertMsgReturn(!(fFlags & ~(DBGFINFO_FLAGS_RUN_ON_EMT | DBGFINFO_FLAGS_ALL_EMTS)),
234 ("fFlags=%#x\n", fFlags), VERR_INVALID_FLAGS);
[1]235
236 /*
237 * Allocate and initialize.
238 */
239 int rc;
240 size_t cchName = strlen(pszName) + 1;
[73097]241 PDBGFINFO pInfo = (PDBGFINFO)MMR3HeapAllocU(pUVM, MM_TAG_DBGF_INFO, RT_UOFFSETOF_DYN(DBGFINFO, szName[cchName]));
[1]242 if (pInfo)
243 {
244 pInfo->enmType = DBGFINFOTYPE_INVALID;
[2250]245 pInfo->fFlags = fFlags;
[1]246 pInfo->pszDesc = pszDesc;
247 pInfo->cchName = cchName - 1;
248 memcpy(pInfo->szName, pszName, cchName);
249
250 /* lazy init */
251 rc = VINF_SUCCESS;
[55881]252 if (!RTCritSectRwIsInitialized(&pUVM->dbgf.s.CritSect))
[44399]253 rc = dbgfR3InfoInit(pUVM);
[13816]254 if (RT_SUCCESS(rc))
[1]255 {
256 /*
257 * Insert in alphabetical order.
258 */
[55881]259 rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect);
[1]260 AssertRC(rc);
261 PDBGFINFO pPrev = NULL;
262 PDBGFINFO pCur;
[44399]263 for (pCur = pUVM->dbgf.s.pInfoFirst; pCur; pPrev = pCur, pCur = pCur->pNext)
[1]264 if (strcmp(pszName, pCur->szName) < 0)
265 break;
266 pInfo->pNext = pCur;
267 if (pPrev)
268 pPrev->pNext = pInfo;
269 else
[44399]270 pUVM->dbgf.s.pInfoFirst = pInfo;
[1]271
272 *ppInfo = pInfo;
273 return VINF_SUCCESS;
274 }
275 MMR3HeapFree(pInfo);
276 }
277 else
278 rc = VERR_NO_MEMORY;
279 return rc;
280}
281
282
283/**
284 * Register a info handler owned by a device.
285 *
286 * @returns VBox status code.
[58122]287 * @param pVM The cross context VM structure.
[1]288 * @param pszName The identifier of the info.
289 * @param pszDesc The description of the info and any arguments the handler may take.
290 * @param pfnHandler The handler function to be called to display the info.
291 * @param pDevIns The device instance owning the info.
292 */
[44399]293VMMR3_INT_DECL(int) DBGFR3InfoRegisterDevice(PVM pVM, const char *pszName, const char *pszDesc,
294 PFNDBGFHANDLERDEV pfnHandler, PPDMDEVINS pDevIns)
[1]295{
296 LogFlow(("DBGFR3InfoRegisterDevice: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pDevIns=%p\n",
297 pszName, pszName, pszDesc, pszDesc, pfnHandler, pDevIns));
298
299 /*
300 * Validate the specific stuff.
301 */
[44399]302 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
303 AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
[1]304
305 /*
306 * Register
307 */
308 PDBGFINFO pInfo;
[44399]309 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
[13816]310 if (RT_SUCCESS(rc))
[1]311 {
312 pInfo->enmType = DBGFINFOTYPE_DEV;
313 pInfo->u.Dev.pfnHandler = pfnHandler;
314 pInfo->u.Dev.pDevIns = pDevIns;
[55881]315 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
[1]316 }
317
318 return rc;
319}
320
321
322/**
323 * Register a info handler owned by a driver.
324 *
325 * @returns VBox status code.
[58122]326 * @param pVM The cross context VM structure.
[1]327 * @param pszName The identifier of the info.
328 * @param pszDesc The description of the info and any arguments the handler may take.
329 * @param pfnHandler The handler function to be called to display the info.
330 * @param pDrvIns The driver instance owning the info.
331 */
[44399]332VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriver(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler, PPDMDRVINS pDrvIns)
[1]333{
334 LogFlow(("DBGFR3InfoRegisterDriver: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pDrvIns=%p\n",
335 pszName, pszName, pszDesc, pszDesc, pfnHandler, pDrvIns));
336
337 /*
338 * Validate the specific stuff.
339 */
[44399]340 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
341 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
[1]342
343 /*
344 * Register
345 */
346 PDBGFINFO pInfo;
[44399]347 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
[13816]348 if (RT_SUCCESS(rc))
[1]349 {
350 pInfo->enmType = DBGFINFOTYPE_DRV;
351 pInfo->u.Drv.pfnHandler = pfnHandler;
352 pInfo->u.Drv.pDrvIns = pDrvIns;
[55881]353 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
[1]354 }
355
356 return rc;
357}
358
359
360/**
361 * Register a info handler owned by an internal component.
362 *
363 * @returns VBox status code.
[58122]364 * @param pVM The cross context VM structure.
[1]365 * @param pszName The identifier of the info.
366 * @param pszDesc The description of the info and any arguments the handler may take.
367 * @param pfnHandler The handler function to be called to display the info.
368 */
[44399]369VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler)
[1]370{
[2250]371 return DBGFR3InfoRegisterInternalEx(pVM, pszName, pszDesc, pfnHandler, 0);
372}
[1]373
[2250]374
375/**
376 * Register a info handler owned by an internal component.
377 *
378 * @returns VBox status code.
[58122]379 * @param pVM The cross context VM structure.
[2250]380 * @param pszName The identifier of the info.
381 * @param pszDesc The description of the info and any arguments the handler may take.
382 * @param pfnHandler The handler function to be called to display the info.
383 * @param fFlags Flags, see the DBGFINFO_FLAGS_*.
384 */
[44399]385VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalEx(PVM pVM, const char *pszName, const char *pszDesc,
386 PFNDBGFHANDLERINT pfnHandler, uint32_t fFlags)
[2250]387{
388 LogFlow(("DBGFR3InfoRegisterInternal: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p fFlags=%x\n",
389 pszName, pszName, pszDesc, pszDesc, pfnHandler, fFlags));
390
[1]391 /*
392 * Validate the specific stuff.
393 */
[44399]394 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
[1]395
396 /*
397 * Register
398 */
399 PDBGFINFO pInfo;
[44399]400 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, fFlags, &pInfo);
[13816]401 if (RT_SUCCESS(rc))
[1]402 {
403 pInfo->enmType = DBGFINFOTYPE_INT;
404 pInfo->u.Int.pfnHandler = pfnHandler;
[55881]405 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
[1]406 }
407
408 return rc;
409}
410
411
412/**
413 * Register a info handler owned by an external component.
414 *
415 * @returns VBox status code.
[44399]416 * @param pUVM The user mode VM handle.
[1]417 * @param pszName The identifier of the info.
418 * @param pszDesc The description of the info and any arguments the handler may take.
419 * @param pfnHandler The handler function to be called to display the info.
420 * @param pvUser User argument to be passed to the handler.
421 */
[44399]422VMMR3DECL(int) DBGFR3InfoRegisterExternal(PUVM pUVM, const char *pszName, const char *pszDesc,
423 PFNDBGFHANDLEREXT pfnHandler, void *pvUser)
[1]424{
425 LogFlow(("DBGFR3InfoRegisterExternal: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p pvUser=%p\n",
426 pszName, pszName, pszDesc, pszDesc, pfnHandler, pvUser));
427
428 /*
429 * Validate the specific stuff.
430 */
[44399]431 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
432 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
[1]433
434 /*
435 * Register
436 */
437 PDBGFINFO pInfo;
[44399]438 int rc = dbgfR3InfoRegister(pUVM, pszName, pszDesc, 0, &pInfo);
[13816]439 if (RT_SUCCESS(rc))
[1]440 {
441 pInfo->enmType = DBGFINFOTYPE_EXT;
442 pInfo->u.Ext.pfnHandler = pfnHandler;
443 pInfo->u.Ext.pvUser = pvUser;
[55881]444 RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
[1]445 }
446
447 return rc;
448}
449
450
451/**
452 * Deregister one(/all) info handler(s) owned by a device.
453 *
454 * @returns VBox status code.
[58122]455 * @param pVM The cross context VM structure.
[1]456 * @param pDevIns Device instance.
457 * @param pszName The identifier of the info. If NULL all owned by the device.
458 */
[44399]459VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName)
[1]460{
461 LogFlow(("DBGFR3InfoDeregisterDevice: pDevIns=%p pszName=%p:{%s}\n", pDevIns, pszName, pszName));
462
463 /*
464 * Validate input.
465 */
[44399]466 AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
467 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
[1]468 size_t cchName = pszName ? strlen(pszName) : 0;
[44399]469 PUVM pUVM = pVM->pUVM;
[1]470
471 /*
472 * Enumerate the info handlers and free the requested entries.
473 */
[55881]474 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect); AssertRC(rc);
[1]475 rc = VERR_FILE_NOT_FOUND;
476 PDBGFINFO pPrev = NULL;
[44399]477 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
[1]478 if (pszName)
479 {
480 /*
481 * Free a specific one.
482 */
483 for (; pInfo; pPrev = pInfo, pInfo = pInfo->pNext)
484 if ( pInfo->enmType == DBGFINFOTYPE_DEV
485 && pInfo->u.Dev.pDevIns == pDevIns
486 && pInfo->cchName == cchName
487 && !strcmp(pInfo->szName, pszName))
488 {
489 if (pPrev)
490 pPrev->pNext = pInfo->pNext;
491 else
[44399]492 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
[1]493 MMR3HeapFree(pInfo);
494 rc = VINF_SUCCESS;
495 break;
496 }
497 }
498 else
499 {
500 /*
[44399]501 * Free all owned by the device.
[1]502 */
[68255]503 while (pInfo != NULL)
[1]504 if ( pInfo->enmType == DBGFINFOTYPE_DEV
505 && pInfo->u.Dev.pDevIns == pDevIns)
506 {
[68255]507 PDBGFINFO volatile pFree = pInfo;
[68256]508 pInfo = pInfo->pNext;
[1]509 if (pPrev)
[68256]510 pPrev->pNext = pInfo;
[1]511 else
[68256]512 pUVM->dbgf.s.pInfoFirst = pInfo;
[68255]513 MMR3HeapFree(pFree);
[1]514 }
[68255]515 else
516 {
517 pPrev = pInfo;
518 pInfo = pInfo->pNext;
519 }
[1]520 rc = VINF_SUCCESS;
521 }
[55881]522 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
[1]523 AssertRC(rc2);
524 AssertRC(rc);
[13818]525 LogFlow(("DBGFR3InfoDeregisterDevice: returns %Rrc\n", rc));
[1]526 return rc;
527}
528
529/**
530 * Deregister one(/all) info handler(s) owned by a driver.
531 *
532 * @returns VBox status code.
[58122]533 * @param pVM The cross context VM structure.
[1]534 * @param pDrvIns Driver instance.
535 * @param pszName The identifier of the info. If NULL all owned by the driver.
536 */
[44399]537VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName)
[1]538{
539 LogFlow(("DBGFR3InfoDeregisterDriver: pDrvIns=%p pszName=%p:{%s}\n", pDrvIns, pszName, pszName));
540
541 /*
542 * Validate input.
543 */
[44399]544 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
545 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
[1]546 size_t cchName = pszName ? strlen(pszName) : 0;
[44399]547 PUVM pUVM = pVM->pUVM;
[1]548
549 /*
550 * Enumerate the info handlers and free the requested entries.
551 */
[55881]552 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect); AssertRC(rc);
[1]553 rc = VERR_FILE_NOT_FOUND;
554 PDBGFINFO pPrev = NULL;
[44399]555 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
[1]556 if (pszName)
557 {
558 /*
559 * Free a specific one.
560 */
561 for (; pInfo; pPrev = pInfo, pInfo = pInfo->pNext)
562 if ( pInfo->enmType == DBGFINFOTYPE_DRV
563 && pInfo->u.Drv.pDrvIns == pDrvIns
564 && pInfo->cchName == cchName
565 && !strcmp(pInfo->szName, pszName))
566 {
567 if (pPrev)
568 pPrev->pNext = pInfo->pNext;
569 else
[44399]570 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
[1]571 MMR3HeapFree(pInfo);
572 rc = VINF_SUCCESS;
573 break;
574 }
575 }
576 else
577 {
578 /*
579 * Free all owned by the driver.
580 */
[68255]581 while (pInfo != NULL)
[1]582 if ( pInfo->enmType == DBGFINFOTYPE_DRV
583 && pInfo->u.Drv.pDrvIns == pDrvIns)
584 {
[68255]585 PDBGFINFO volatile pFree = pInfo;
[68256]586 pInfo = pInfo->pNext;
[1]587 if (pPrev)
[68256]588 pPrev->pNext = pInfo;
[1]589 else
[68256]590 pUVM->dbgf.s.pInfoFirst = pInfo;
[68255]591 MMR3HeapFree(pFree);
[1]592 }
[68255]593 else
594 {
595 pPrev = pInfo;
596 pInfo = pInfo->pNext;
597 }
[1]598 rc = VINF_SUCCESS;
599 }
[55881]600 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
[1]601 AssertRC(rc2);
602 AssertRC(rc);
[13818]603 LogFlow(("DBGFR3InfoDeregisterDriver: returns %Rrc\n", rc));
[1]604 return rc;
605}
606
607
608/**
609 * Internal deregistration helper.
610 *
611 * @returns VBox status code.
[44399]612 * @param pUVM Pointer to the VM.
[1]613 * @param pszName The identifier of the info.
614 * @param enmType The info owner type.
615 */
[44399]616static int dbgfR3InfoDeregister(PUVM pUVM, const char *pszName, DBGFINFOTYPE enmType)
[1]617{
618 /*
619 * Validate input.
620 */
[44399]621 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
[1]622
623 /*
624 * Find the info handler.
625 */
626 size_t cchName = strlen(pszName);
[55881]627 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect);
[1]628 AssertRC(rc);
629 rc = VERR_FILE_NOT_FOUND;
630 PDBGFINFO pPrev = NULL;
[44399]631 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
[1]632 for (; pInfo; pPrev = pInfo, pInfo = pInfo->pNext)
633 if ( pInfo->cchName == cchName
634 && !strcmp(pInfo->szName, pszName)
635 && pInfo->enmType == enmType)
636 {
637 if (pPrev)
638 pPrev->pNext = pInfo->pNext;
639 else
[44399]640 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
[1]641 MMR3HeapFree(pInfo);
642 rc = VINF_SUCCESS;
643 break;
644 }
[55881]645 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
[1]646 AssertRC(rc2);
647 AssertRC(rc);
[13818]648 LogFlow(("dbgfR3InfoDeregister: returns %Rrc\n", rc));
[1]649 return rc;
650}
651
[12663]652
[1]653/**
654 * Deregister a info handler owned by an internal component.
655 *
656 * @returns VBox status code.
[58122]657 * @param pVM The cross context VM structure.
[1]658 * @param pszName The identifier of the info. If NULL all owned by the device.
659 */
[44399]660VMMR3_INT_DECL(int) DBGFR3InfoDeregisterInternal(PVM pVM, const char *pszName)
[1]661{
662 LogFlow(("DBGFR3InfoDeregisterInternal: pszName=%p:{%s}\n", pszName, pszName));
[44399]663 return dbgfR3InfoDeregister(pVM->pUVM, pszName, DBGFINFOTYPE_INT);
[1]664}
665
666
667/**
668 * Deregister a info handler owned by an external component.
669 *
670 * @returns VBox status code.
[44399]671 * @param pUVM The user mode VM handle.
[1]672 * @param pszName The identifier of the info. If NULL all owned by the device.
673 */
[44399]674VMMR3DECL(int) DBGFR3InfoDeregisterExternal(PUVM pUVM, const char *pszName)
[1]675{
676 LogFlow(("DBGFR3InfoDeregisterExternal: pszName=%p:{%s}\n", pszName, pszName));
[44399]677 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
678 return dbgfR3InfoDeregister(pUVM, pszName, DBGFINFOTYPE_EXT);
[1]679}
680
681
682/**
[61570]683 * Worker for DBGFR3InfoEx.
[39078]684 *
[1]685 * @returns VBox status code.
[44399]686 * @param pUVM The user mode VM handle.
687 * @param idCpu Which CPU to run EMT bound handlers on. VMCPUID_ANY or
688 * a valid CPU ID.
689 * @param pszName What to dump.
690 * @param pszArgs Arguments, optional.
691 * @param pHlp Output helper, optional.
[1]692 */
[44399]693static DECLCALLBACK(int) dbgfR3Info(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
[1]694{
695 /*
696 * Validate input.
697 */
[38838]698 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
[44399]699 AssertPtrNullReturn(pszArgs, VERR_INVALID_POINTER);
[1]700 if (pHlp)
701 {
[44399]702 AssertPtrReturn(pHlp, VERR_INVALID_PARAMETER);
703 AssertPtrReturn(pHlp->pfnPrintf, VERR_INVALID_PARAMETER);
704 AssertPtrReturn(pHlp->pfnPrintfV, VERR_INVALID_PARAMETER);
[1]705 }
706 else
707 pHlp = &g_dbgfR3InfoLogHlp;
[61570]708 Assert(idCpu == NIL_VMCPUID || idCpu < pUVM->cCpus); /* if not nil, we're on that EMT already. */
[1]709
710 /*
711 * Find the info handler.
712 */
713 size_t cchName = strlen(pszName);
[55881]714 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
[1]715 AssertRC(rc);
[44399]716 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
[1]717 for (; pInfo; pInfo = pInfo->pNext)
718 if ( pInfo->cchName == cchName
719 && !memcmp(pInfo->szName, pszName, cchName))
720 break;
721 if (pInfo)
722 {
723 /*
724 * Found it.
725 */
[61570]726 VMCPUID idDstCpu = NIL_VMCPUID;
727 if ((pInfo->fFlags & (DBGFINFO_FLAGS_RUN_ON_EMT | DBGFINFO_FLAGS_ALL_EMTS)) && idCpu == NIL_VMCPUID)
728 idDstCpu = pInfo->fFlags & DBGFINFO_FLAGS_ALL_EMTS ? VMCPUID_ALL : VMCPUID_ANY;
729
[1]730 rc = VINF_SUCCESS;
[55881]731 switch (pInfo->enmType)
[1]732 {
733 case DBGFINFOTYPE_DEV:
[61570]734 if (idDstCpu != NIL_VMCPUID)
735 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Dev.pfnHandler, 3,
736 pInfo->u.Dev.pDevIns, pHlp, pszArgs);
[2250]737 else
[55881]738 pInfo->u.Dev.pfnHandler(pInfo->u.Dev.pDevIns, pHlp, pszArgs);
[1]739 break;
[2250]740
[1]741 case DBGFINFOTYPE_DRV:
[61570]742 if (idDstCpu != NIL_VMCPUID)
743 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Drv.pfnHandler, 3,
744 pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
[2250]745 else
[55881]746 pInfo->u.Drv.pfnHandler(pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
[1]747 break;
[2250]748
[1]749 case DBGFINFOTYPE_INT:
[44399]750 if (RT_VALID_PTR(pUVM->pVM))
751 {
[61570]752 if (idDstCpu != NIL_VMCPUID)
753 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Int.pfnHandler, 3,
754 pUVM->pVM, pHlp, pszArgs);
[44399]755 else
[55881]756 pInfo->u.Int.pfnHandler(pUVM->pVM, pHlp, pszArgs);
[44399]757 }
[2250]758 else
[44399]759 rc = VERR_INVALID_VM_HANDLE;
[1]760 break;
[2250]761
[1]762 case DBGFINFOTYPE_EXT:
[61570]763 if (idDstCpu != NIL_VMCPUID)
764 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Ext.pfnHandler, 3,
765 pInfo->u.Ext.pvUser, pHlp, pszArgs);
[2250]766 else
[55881]767 pInfo->u.Ext.pfnHandler(pInfo->u.Ext.pvUser, pHlp, pszArgs);
[1]768 break;
[2250]769
[1]770 default:
[55881]771 AssertMsgFailedReturn(("Invalid info type enmType=%d\n", pInfo->enmType), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
[1]772 }
[61570]773
[55881]774 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
775 AssertRC(rc2);
[1]776 }
777 else
778 {
[55881]779 rc = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
[1]780 AssertRC(rc);
781 rc = VERR_FILE_NOT_FOUND;
782 }
783 return rc;
784}
785
[61570]786
[38838]787/**
788 * Display a piece of info writing to the supplied handler.
789 *
790 * @returns VBox status code.
[44399]791 * @param pUVM The user mode VM handle.
[38838]792 * @param pszName The identifier of the info to display.
793 * @param pszArgs Arguments to the info handler.
794 * @param pHlp The output helper functions. If NULL the logger will be used.
795 */
[44399]796VMMR3DECL(int) DBGFR3Info(PUVM pUVM, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
[38838]797{
[61570]798 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, pHlp);
[38838]799}
[1]800
[38838]801
[1]802/**
[38838]803 * Display a piece of info writing to the supplied handler.
804 *
805 * @returns VBox status code.
[44399]806 * @param pUVM The user mode VM handle.
[39078]807 * @param idCpu The CPU to exectue the request on. Pass NIL_VMCPUID
[61570]808 * to not involve any EMT unless necessary.
[38838]809 * @param pszName The identifier of the info to display.
810 * @param pszArgs Arguments to the info handler.
811 * @param pHlp The output helper functions. If NULL the logger will be used.
812 */
[44399]813VMMR3DECL(int) DBGFR3InfoEx(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
[38838]814{
[61570]815 /*
816 * Some input validation.
817 */
[44399]818 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
[61570]819 AssertReturn( idCpu != VMCPUID_ANY_QUEUE
820 && idCpu != VMCPUID_ALL
821 && idCpu != VMCPUID_ALL_REVERSE, VERR_INVALID_PARAMETER);
822
823 /*
824 * Run on any specific EMT?
825 */
[38838]826 if (idCpu == NIL_VMCPUID)
[61570]827 return dbgfR3Info(pUVM, NIL_VMCPUID, pszName, pszArgs, pHlp);
[44399]828 return VMR3ReqPriorityCallWaitU(pUVM, idCpu,
829 (PFNRT)dbgfR3Info, 5, pUVM, idCpu, pszName, pszArgs, pHlp);
[38838]830}
831
832
833/**
[20152]834 * Wrapper for DBGFR3Info that outputs to the release log.
835 *
836 * @returns See DBGFR3Info.
[44399]837 * @param pUVM The user mode VM handle.
838 * @param pszName See DBGFR3Info.
839 * @param pszArgs See DBGFR3Info.
[20152]840 */
[44399]841VMMR3DECL(int) DBGFR3InfoLogRel(PUVM pUVM, const char *pszName, const char *pszArgs)
[20152]842{
[61570]843 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, &g_dbgfR3InfoLogRelHlp);
[20152]844}
845
846
847/**
848 * Wrapper for DBGFR3Info that outputs to standard error.
849 *
850 * @returns See DBGFR3Info.
[44399]851 * @param pUVM The user mode VM handle.
852 * @param pszName See DBGFR3Info.
853 * @param pszArgs See DBGFR3Info.
[20152]854 */
[44399]855VMMR3DECL(int) DBGFR3InfoStdErr(PUVM pUVM, const char *pszName, const char *pszArgs)
[20152]856{
[61570]857 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, &g_dbgfR3InfoStdErrHlp);
[20152]858}
859
860
861/**
[30060]862 * Display several info items.
863 *
864 * This is intended used by the fatal error dump only.
865 *
[58126]866 * @returns VBox status code.
[58122]867 * @param pVM The cross context VM structure.
[30060]868 * @param pszIncludePat Simple string pattern of info items to include.
869 * @param pszExcludePat Simple string pattern of info items to exclude.
870 * @param pszSepFmt Item separator format string. The item name will be
871 * given as parameter.
872 * @param pHlp The output helper functions. If NULL the logger
873 * will be used.
874 *
[58126]875 * @thread EMT
[30060]876 */
[44399]877VMMR3_INT_DECL(int) DBGFR3InfoMulti(PVM pVM, const char *pszIncludePat, const char *pszExcludePat, const char *pszSepFmt,
878 PCDBGFINFOHLP pHlp)
[30060]879{
880 /*
881 * Validate input.
882 */
[44399]883 PUVM pUVM = pVM->pUVM;
[30060]884 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
885 AssertPtrReturn(pszIncludePat, VERR_INVALID_POINTER);
886 AssertPtrReturn(pszExcludePat, VERR_INVALID_POINTER);
887 if (pHlp)
888 {
889 AssertPtrReturn(pHlp->pfnPrintf, VERR_INVALID_POINTER);
890 AssertPtrReturn(pHlp->pfnPrintfV, VERR_INVALID_POINTER);
891 }
892 else
893 pHlp = &g_dbgfR3InfoLogHlp;
894
895 size_t const cchIncludePat = strlen(pszIncludePat);
896 size_t const cchExcludePat = strlen(pszExcludePat);
897 const char *pszArgs = "";
898
899 /*
900 * Enumerate the info handlers and call the ones matching.
901 * Note! We won't leave the critical section here...
902 */
[55881]903 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
[30060]904 AssertRC(rc);
905 rc = VWRN_NOT_FOUND;
[44399]906 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
[30060]907 {
908 if ( RTStrSimplePatternMultiMatch(pszIncludePat, cchIncludePat, pInfo->szName, pInfo->cchName, NULL)
909 && !RTStrSimplePatternMultiMatch(pszExcludePat, cchExcludePat, pInfo->szName, pInfo->cchName, NULL))
910 {
911 pHlp->pfnPrintf(pHlp, pszSepFmt, pInfo->szName);
[61570]912
913 VMCPUID idDstCpu = NIL_VMCPUID;
914 if (pInfo->fFlags & (DBGFINFO_FLAGS_RUN_ON_EMT | DBGFINFO_FLAGS_ALL_EMTS))
915 idDstCpu = pInfo->fFlags & DBGFINFO_FLAGS_ALL_EMTS ? VMCPUID_ALL : VMCPUID_ANY;
916
[30060]917 rc = VINF_SUCCESS;
918 switch (pInfo->enmType)
919 {
920 case DBGFINFOTYPE_DEV:
[61570]921 if (idDstCpu != NIL_VMCPUID)
922 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Dev.pfnHandler, 3,
923 pInfo->u.Dev.pDevIns, pHlp, pszArgs);
[30060]924 else
925 pInfo->u.Dev.pfnHandler(pInfo->u.Dev.pDevIns, pHlp, pszArgs);
926 break;
927
928 case DBGFINFOTYPE_DRV:
[61570]929 if (idDstCpu != NIL_VMCPUID)
930 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Drv.pfnHandler, 3,
931 pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
[30060]932 else
933 pInfo->u.Drv.pfnHandler(pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
934 break;
935
936 case DBGFINFOTYPE_INT:
[61570]937 if (idDstCpu != NIL_VMCPUID)
938 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Int.pfnHandler, 3,
939 pVM, pHlp, pszArgs);
[30060]940 else
941 pInfo->u.Int.pfnHandler(pVM, pHlp, pszArgs);
942 break;
943
944 case DBGFINFOTYPE_EXT:
[61570]945 if (idDstCpu != NIL_VMCPUID)
946 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Ext.pfnHandler, 3,
947 pInfo->u.Ext.pvUser, pHlp, pszArgs);
[30060]948 else
949 pInfo->u.Ext.pfnHandler(pInfo->u.Ext.pvUser, pHlp, pszArgs);
950 break;
951
952 default:
[39405]953 AssertMsgFailedReturn(("Invalid info type enmType=%d\n", pInfo->enmType), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
[30060]954 }
955 }
956 }
[55881]957 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
[30060]958 AssertRC(rc2);
959
960 return rc;
961}
962
963
964/**
[1]965 * Enumerate all the register info handlers.
966 *
967 * @returns VBox status code.
[44399]968 * @param pUVM The user mode VM handle.
[1]969 * @param pfnCallback Pointer to callback function.
970 * @param pvUser User argument to pass to the callback.
971 */
[44399]972VMMR3DECL(int) DBGFR3InfoEnum(PUVM pUVM, PFNDBGFINFOENUM pfnCallback, void *pvUser)
[1]973{
974 LogFlow(("DBGFR3InfoLog: pfnCallback=%p pvUser=%p\n", pfnCallback, pvUser));
975
976 /*
977 * Validate input.
978 */
979 if (!pfnCallback)
980 {
981 AssertMsgFailed(("!pfnCallback\n"));
982 return VERR_INVALID_PARAMETER;
983 }
[44399]984 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
[1]985
986 /*
987 * Enter and enumerate.
988 */
[55881]989 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
[1]990 AssertRC(rc);
991
992 rc = VINF_SUCCESS;
[44399]993 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; RT_SUCCESS(rc) && pInfo; pInfo = pInfo->pNext)
994 rc = pfnCallback(pUVM, pInfo->szName, pInfo->pszDesc, pvUser);
[1]995
996 /*
997 * Leave and exit.
998 */
[55881]999 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
[1]1000 AssertRC(rc2);
1001
[13818]1002 LogFlow(("DBGFR3InfoLog: returns %Rrc\n", rc));
[1]1003 return rc;
1004}
1005
1006
1007/**
1008 * Info handler, internal version.
1009 *
[58122]1010 * @param pVM The cross context VM structure.
[1]1011 * @param pHlp Callback functions for doing output.
1012 * @param pszArgs Argument string. Optional and specific to the handler.
1013 */
1014static DECLCALLBACK(void) dbgfR3InfoHelp(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
1015{
1016 LogFlow(("dbgfR3InfoHelp: pszArgs=%s\n", pszArgs));
1017
1018 /*
1019 * Enter and enumerate.
1020 */
[44399]1021 PUVM pUVM = pVM->pUVM;
[55881]1022 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
[1]1023 AssertRC(rc);
1024
1025 if (pszArgs && *pszArgs)
1026 {
[44399]1027 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
[1]1028 {
1029 const char *psz = strstr(pszArgs, pInfo->szName);
1030 if ( psz
1031 && ( psz == pszArgs
[24009]1032 || RT_C_IS_SPACE(psz[-1]))
[1]1033 && ( !psz[pInfo->cchName]
[24009]1034 || RT_C_IS_SPACE(psz[pInfo->cchName])))
[1]1035 pHlp->pfnPrintf(pHlp, "%-16s %s\n",
1036 pInfo->szName, pInfo->pszDesc);
1037 }
1038 }
1039 else
1040 {
[44399]1041 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
[1]1042 pHlp->pfnPrintf(pHlp, "%-16s %s\n",
1043 pInfo->szName, pInfo->pszDesc);
1044 }
1045
1046 /*
1047 * Leave and exit.
1048 */
[55881]1049 rc = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
[1]1050 AssertRC(rc);
1051}
1052
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use