VirtualBox

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

Last change on this file since 78254 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 34.2 KB
Line 
1/* $Id: DBGFInfo.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, Info.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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/param.h>
35#include <iprt/semaphore.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38#include <iprt/thread.h>
39
40
41/*********************************************************************************************************************************
42* Internal Functions *
43*********************************************************************************************************************************/
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);
48static DECLCALLBACK(void) dbgfR3InfoStdErr_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...);
49static DECLCALLBACK(void) dbgfR3InfoStdErr_PrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args);
50static DECLCALLBACK(void) dbgfR3InfoHelp(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
51
52
53/*********************************************************************************************************************************
54* Global Variables *
55*********************************************************************************************************************************/
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
70/** Standard error output. */
71static const DBGFINFOHLP g_dbgfR3InfoStdErrHlp =
72{
73 dbgfR3InfoStdErr_Printf,
74 dbgfR3InfoStdErr_PrintfV
75};
76
77
78/**
79 * Initialize the info handlers.
80 *
81 * This is called first during the DBGF init process and thus does the shared
82 * critsect init.
83 *
84 * @returns VBox status code.
85 * @param pUVM The user mode VM handle.
86 */
87int dbgfR3InfoInit(PUVM pUVM)
88{
89 /*
90 * Make sure we already didn't initialized in the lazy manner.
91 */
92 if (RTCritSectRwIsInitialized(&pUVM->dbgf.s.CritSect))
93 return VINF_SUCCESS;
94
95 /*
96 * Initialize the crit sect.
97 */
98 int rc = RTCritSectRwInit(&pUVM->dbgf.s.CritSect);
99 AssertRCReturn(rc, rc);
100
101 /*
102 * Register the 'info help' item.
103 */
104 rc = DBGFR3InfoRegisterInternal(pUVM->pVM, "help", "List of info items.", dbgfR3InfoHelp);
105 AssertRCReturn(rc, rc);
106
107 return VINF_SUCCESS;
108}
109
110
111/**
112 * Terminate the info handlers.
113 *
114 * @returns VBox status code.
115 * @param pUVM The user mode VM handle.
116 */
117int dbgfR3InfoTerm(PUVM pUVM)
118{
119 /*
120 * Delete the crit sect.
121 */
122 int rc = RTCritSectRwDelete(&pUVM->dbgf.s.CritSect);
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{
132 NOREF(pHlp);
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{
143 NOREF(pHlp);
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 */
154VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogHlp(void)
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{
164 NOREF(pHlp);
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{
175 NOREF(pHlp);
176 RTLogRelPrintfV(pszFormat, args);
177}
178
179
180/** Standard error output.
181 * @copydoc DBGFINFOHLP::pfnPrintf */
182static DECLCALLBACK(void) dbgfR3InfoStdErr_Printf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
183{
184 NOREF(pHlp);
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{
195 NOREF(pHlp);
196 RTStrmPrintfV(g_pStdErr, pszFormat, args);
197}
198
199
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 */
206VMMR3DECL(PCDBGFINFOHLP) DBGFR3InfoLogRelHlp(void)
207{
208 return &g_dbgfR3InfoLogRelHlp;
209}
210
211
212/**
213 * Handle registration worker.
214 *
215 * This allocates the structure, initializes the common fields and inserts into the list.
216 * Upon successful return the we're inside the crit sect and the caller must leave it.
217 *
218 * @returns VBox status code.
219 * @param pUVM The user mode VM handle.
220 * @param pszName The identifier of the info.
221 * @param pszDesc The description of the info and any arguments the handler may take.
222 * @param fFlags The flags.
223 * @param ppInfo Where to store the created
224 */
225static int dbgfR3InfoRegister(PUVM pUVM, const char *pszName, const char *pszDesc, uint32_t fFlags, PDBGFINFO *ppInfo)
226{
227 /*
228 * Validate.
229 */
230 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
231 AssertReturn(*pszName, VERR_INVALID_PARAMETER);
232 AssertPtrReturn(pszDesc, VERR_INVALID_POINTER);
233 AssertMsgReturn(!(fFlags & ~(DBGFINFO_FLAGS_RUN_ON_EMT | DBGFINFO_FLAGS_ALL_EMTS)),
234 ("fFlags=%#x\n", fFlags), VERR_INVALID_FLAGS);
235
236 /*
237 * Allocate and initialize.
238 */
239 int rc;
240 size_t cchName = strlen(pszName) + 1;
241 PDBGFINFO pInfo = (PDBGFINFO)MMR3HeapAllocU(pUVM, MM_TAG_DBGF_INFO, RT_UOFFSETOF_DYN(DBGFINFO, szName[cchName]));
242 if (pInfo)
243 {
244 pInfo->enmType = DBGFINFOTYPE_INVALID;
245 pInfo->fFlags = fFlags;
246 pInfo->pszDesc = pszDesc;
247 pInfo->cchName = cchName - 1;
248 memcpy(pInfo->szName, pszName, cchName);
249
250 /* lazy init */
251 rc = VINF_SUCCESS;
252 if (!RTCritSectRwIsInitialized(&pUVM->dbgf.s.CritSect))
253 rc = dbgfR3InfoInit(pUVM);
254 if (RT_SUCCESS(rc))
255 {
256 /*
257 * Insert in alphabetical order.
258 */
259 rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect);
260 AssertRC(rc);
261 PDBGFINFO pPrev = NULL;
262 PDBGFINFO pCur;
263 for (pCur = pUVM->dbgf.s.pInfoFirst; pCur; pPrev = pCur, pCur = pCur->pNext)
264 if (strcmp(pszName, pCur->szName) < 0)
265 break;
266 pInfo->pNext = pCur;
267 if (pPrev)
268 pPrev->pNext = pInfo;
269 else
270 pUVM->dbgf.s.pInfoFirst = pInfo;
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.
287 * @param pVM The cross context VM structure.
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 */
293VMMR3_INT_DECL(int) DBGFR3InfoRegisterDevice(PVM pVM, const char *pszName, const char *pszDesc,
294 PFNDBGFHANDLERDEV pfnHandler, PPDMDEVINS pDevIns)
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 */
302 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
303 AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
304
305 /*
306 * Register
307 */
308 PDBGFINFO pInfo;
309 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
310 if (RT_SUCCESS(rc))
311 {
312 pInfo->enmType = DBGFINFOTYPE_DEV;
313 pInfo->u.Dev.pfnHandler = pfnHandler;
314 pInfo->u.Dev.pDevIns = pDevIns;
315 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
316 }
317
318 return rc;
319}
320
321
322/**
323 * Register a info handler owned by a driver.
324 *
325 * @returns VBox status code.
326 * @param pVM The cross context VM structure.
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 */
332VMMR3_INT_DECL(int) DBGFR3InfoRegisterDriver(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler, PPDMDRVINS pDrvIns)
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 */
340 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
341 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
342
343 /*
344 * Register
345 */
346 PDBGFINFO pInfo;
347 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, 0, &pInfo);
348 if (RT_SUCCESS(rc))
349 {
350 pInfo->enmType = DBGFINFOTYPE_DRV;
351 pInfo->u.Drv.pfnHandler = pfnHandler;
352 pInfo->u.Drv.pDrvIns = pDrvIns;
353 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
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.
364 * @param pVM The cross context VM structure.
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 */
369VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternal(PVM pVM, const char *pszName, const char *pszDesc, PFNDBGFHANDLERINT pfnHandler)
370{
371 return DBGFR3InfoRegisterInternalEx(pVM, pszName, pszDesc, pfnHandler, 0);
372}
373
374
375/**
376 * Register a info handler owned by an internal component.
377 *
378 * @returns VBox status code.
379 * @param pVM The cross context VM structure.
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 */
385VMMR3_INT_DECL(int) DBGFR3InfoRegisterInternalEx(PVM pVM, const char *pszName, const char *pszDesc,
386 PFNDBGFHANDLERINT pfnHandler, uint32_t fFlags)
387{
388 LogFlow(("DBGFR3InfoRegisterInternal: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p fFlags=%x\n",
389 pszName, pszName, pszDesc, pszDesc, pfnHandler, fFlags));
390
391 /*
392 * Validate the specific stuff.
393 */
394 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
395
396 /*
397 * Register
398 */
399 PDBGFINFO pInfo;
400 int rc = dbgfR3InfoRegister(pVM->pUVM, pszName, pszDesc, fFlags, &pInfo);
401 if (RT_SUCCESS(rc))
402 {
403 pInfo->enmType = DBGFINFOTYPE_INT;
404 pInfo->u.Int.pfnHandler = pfnHandler;
405 RTCritSectRwLeaveExcl(&pVM->pUVM->dbgf.s.CritSect);
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.
416 * @param pUVM The user mode VM handle.
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 */
422VMMR3DECL(int) DBGFR3InfoRegisterExternal(PUVM pUVM, const char *pszName, const char *pszDesc,
423 PFNDBGFHANDLEREXT pfnHandler, void *pvUser)
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 */
431 AssertPtrReturn(pfnHandler, VERR_INVALID_POINTER);
432 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
433
434 /*
435 * Register
436 */
437 PDBGFINFO pInfo;
438 int rc = dbgfR3InfoRegister(pUVM, pszName, pszDesc, 0, &pInfo);
439 if (RT_SUCCESS(rc))
440 {
441 pInfo->enmType = DBGFINFOTYPE_EXT;
442 pInfo->u.Ext.pfnHandler = pfnHandler;
443 pInfo->u.Ext.pvUser = pvUser;
444 RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
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.
455 * @param pVM The cross context VM structure.
456 * @param pDevIns Device instance.
457 * @param pszName The identifier of the info. If NULL all owned by the device.
458 */
459VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName)
460{
461 LogFlow(("DBGFR3InfoDeregisterDevice: pDevIns=%p pszName=%p:{%s}\n", pDevIns, pszName, pszName));
462
463 /*
464 * Validate input.
465 */
466 AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
467 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
468 size_t cchName = pszName ? strlen(pszName) : 0;
469 PUVM pUVM = pVM->pUVM;
470
471 /*
472 * Enumerate the info handlers and free the requested entries.
473 */
474 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect); AssertRC(rc);
475 rc = VERR_FILE_NOT_FOUND;
476 PDBGFINFO pPrev = NULL;
477 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
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
492 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
493 MMR3HeapFree(pInfo);
494 rc = VINF_SUCCESS;
495 break;
496 }
497 }
498 else
499 {
500 /*
501 * Free all owned by the device.
502 */
503 while (pInfo != NULL)
504 if ( pInfo->enmType == DBGFINFOTYPE_DEV
505 && pInfo->u.Dev.pDevIns == pDevIns)
506 {
507 PDBGFINFO volatile pFree = pInfo;
508 pInfo = pInfo->pNext;
509 if (pPrev)
510 pPrev->pNext = pInfo;
511 else
512 pUVM->dbgf.s.pInfoFirst = pInfo;
513 MMR3HeapFree(pFree);
514 }
515 else
516 {
517 pPrev = pInfo;
518 pInfo = pInfo->pNext;
519 }
520 rc = VINF_SUCCESS;
521 }
522 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
523 AssertRC(rc2);
524 AssertRC(rc);
525 LogFlow(("DBGFR3InfoDeregisterDevice: returns %Rrc\n", rc));
526 return rc;
527}
528
529/**
530 * Deregister one(/all) info handler(s) owned by a driver.
531 *
532 * @returns VBox status code.
533 * @param pVM The cross context VM structure.
534 * @param pDrvIns Driver instance.
535 * @param pszName The identifier of the info. If NULL all owned by the driver.
536 */
537VMMR3_INT_DECL(int) DBGFR3InfoDeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName)
538{
539 LogFlow(("DBGFR3InfoDeregisterDriver: pDrvIns=%p pszName=%p:{%s}\n", pDrvIns, pszName, pszName));
540
541 /*
542 * Validate input.
543 */
544 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
545 AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
546 size_t cchName = pszName ? strlen(pszName) : 0;
547 PUVM pUVM = pVM->pUVM;
548
549 /*
550 * Enumerate the info handlers and free the requested entries.
551 */
552 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect); AssertRC(rc);
553 rc = VERR_FILE_NOT_FOUND;
554 PDBGFINFO pPrev = NULL;
555 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
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
570 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
571 MMR3HeapFree(pInfo);
572 rc = VINF_SUCCESS;
573 break;
574 }
575 }
576 else
577 {
578 /*
579 * Free all owned by the driver.
580 */
581 while (pInfo != NULL)
582 if ( pInfo->enmType == DBGFINFOTYPE_DRV
583 && pInfo->u.Drv.pDrvIns == pDrvIns)
584 {
585 PDBGFINFO volatile pFree = pInfo;
586 pInfo = pInfo->pNext;
587 if (pPrev)
588 pPrev->pNext = pInfo;
589 else
590 pUVM->dbgf.s.pInfoFirst = pInfo;
591 MMR3HeapFree(pFree);
592 }
593 else
594 {
595 pPrev = pInfo;
596 pInfo = pInfo->pNext;
597 }
598 rc = VINF_SUCCESS;
599 }
600 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
601 AssertRC(rc2);
602 AssertRC(rc);
603 LogFlow(("DBGFR3InfoDeregisterDriver: returns %Rrc\n", rc));
604 return rc;
605}
606
607
608/**
609 * Internal deregistration helper.
610 *
611 * @returns VBox status code.
612 * @param pUVM Pointer to the VM.
613 * @param pszName The identifier of the info.
614 * @param enmType The info owner type.
615 */
616static int dbgfR3InfoDeregister(PUVM pUVM, const char *pszName, DBGFINFOTYPE enmType)
617{
618 /*
619 * Validate input.
620 */
621 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
622
623 /*
624 * Find the info handler.
625 */
626 size_t cchName = strlen(pszName);
627 int rc = RTCritSectRwEnterExcl(&pUVM->dbgf.s.CritSect);
628 AssertRC(rc);
629 rc = VERR_FILE_NOT_FOUND;
630 PDBGFINFO pPrev = NULL;
631 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
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
640 pUVM->dbgf.s.pInfoFirst = pInfo->pNext;
641 MMR3HeapFree(pInfo);
642 rc = VINF_SUCCESS;
643 break;
644 }
645 int rc2 = RTCritSectRwLeaveExcl(&pUVM->dbgf.s.CritSect);
646 AssertRC(rc2);
647 AssertRC(rc);
648 LogFlow(("dbgfR3InfoDeregister: returns %Rrc\n", rc));
649 return rc;
650}
651
652
653/**
654 * Deregister a info handler owned by an internal component.
655 *
656 * @returns VBox status code.
657 * @param pVM The cross context VM structure.
658 * @param pszName The identifier of the info. If NULL all owned by the device.
659 */
660VMMR3_INT_DECL(int) DBGFR3InfoDeregisterInternal(PVM pVM, const char *pszName)
661{
662 LogFlow(("DBGFR3InfoDeregisterInternal: pszName=%p:{%s}\n", pszName, pszName));
663 return dbgfR3InfoDeregister(pVM->pUVM, pszName, DBGFINFOTYPE_INT);
664}
665
666
667/**
668 * Deregister a info handler owned by an external component.
669 *
670 * @returns VBox status code.
671 * @param pUVM The user mode VM handle.
672 * @param pszName The identifier of the info. If NULL all owned by the device.
673 */
674VMMR3DECL(int) DBGFR3InfoDeregisterExternal(PUVM pUVM, const char *pszName)
675{
676 LogFlow(("DBGFR3InfoDeregisterExternal: pszName=%p:{%s}\n", pszName, pszName));
677 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
678 return dbgfR3InfoDeregister(pUVM, pszName, DBGFINFOTYPE_EXT);
679}
680
681
682/**
683 * Worker for DBGFR3InfoEx.
684 *
685 * @returns VBox status code.
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.
692 */
693static DECLCALLBACK(int) dbgfR3Info(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
694{
695 /*
696 * Validate input.
697 */
698 AssertPtrReturn(pszName, VERR_INVALID_POINTER);
699 AssertPtrNullReturn(pszArgs, VERR_INVALID_POINTER);
700 if (pHlp)
701 {
702 AssertPtrReturn(pHlp, VERR_INVALID_PARAMETER);
703 AssertPtrReturn(pHlp->pfnPrintf, VERR_INVALID_PARAMETER);
704 AssertPtrReturn(pHlp->pfnPrintfV, VERR_INVALID_PARAMETER);
705 }
706 else
707 pHlp = &g_dbgfR3InfoLogHlp;
708 Assert(idCpu == NIL_VMCPUID || idCpu < pUVM->cCpus); /* if not nil, we're on that EMT already. */
709
710 /*
711 * Find the info handler.
712 */
713 size_t cchName = strlen(pszName);
714 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
715 AssertRC(rc);
716 PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst;
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 */
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
730 rc = VINF_SUCCESS;
731 switch (pInfo->enmType)
732 {
733 case DBGFINFOTYPE_DEV:
734 if (idDstCpu != NIL_VMCPUID)
735 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Dev.pfnHandler, 3,
736 pInfo->u.Dev.pDevIns, pHlp, pszArgs);
737 else
738 pInfo->u.Dev.pfnHandler(pInfo->u.Dev.pDevIns, pHlp, pszArgs);
739 break;
740
741 case DBGFINFOTYPE_DRV:
742 if (idDstCpu != NIL_VMCPUID)
743 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Drv.pfnHandler, 3,
744 pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
745 else
746 pInfo->u.Drv.pfnHandler(pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
747 break;
748
749 case DBGFINFOTYPE_INT:
750 if (RT_VALID_PTR(pUVM->pVM))
751 {
752 if (idDstCpu != NIL_VMCPUID)
753 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Int.pfnHandler, 3,
754 pUVM->pVM, pHlp, pszArgs);
755 else
756 pInfo->u.Int.pfnHandler(pUVM->pVM, pHlp, pszArgs);
757 }
758 else
759 rc = VERR_INVALID_VM_HANDLE;
760 break;
761
762 case DBGFINFOTYPE_EXT:
763 if (idDstCpu != NIL_VMCPUID)
764 rc = VMR3ReqPriorityCallWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Ext.pfnHandler, 3,
765 pInfo->u.Ext.pvUser, pHlp, pszArgs);
766 else
767 pInfo->u.Ext.pfnHandler(pInfo->u.Ext.pvUser, pHlp, pszArgs);
768 break;
769
770 default:
771 AssertMsgFailedReturn(("Invalid info type enmType=%d\n", pInfo->enmType), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
772 }
773
774 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
775 AssertRC(rc2);
776 }
777 else
778 {
779 rc = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
780 AssertRC(rc);
781 rc = VERR_FILE_NOT_FOUND;
782 }
783 return rc;
784}
785
786
787/**
788 * Display a piece of info writing to the supplied handler.
789 *
790 * @returns VBox status code.
791 * @param pUVM The user mode VM handle.
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 */
796VMMR3DECL(int) DBGFR3Info(PUVM pUVM, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
797{
798 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, pHlp);
799}
800
801
802/**
803 * Display a piece of info writing to the supplied handler.
804 *
805 * @returns VBox status code.
806 * @param pUVM The user mode VM handle.
807 * @param idCpu The CPU to exectue the request on. Pass NIL_VMCPUID
808 * to not involve any EMT unless necessary.
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 */
813VMMR3DECL(int) DBGFR3InfoEx(PUVM pUVM, VMCPUID idCpu, const char *pszName, const char *pszArgs, PCDBGFINFOHLP pHlp)
814{
815 /*
816 * Some input validation.
817 */
818 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
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 */
826 if (idCpu == NIL_VMCPUID)
827 return dbgfR3Info(pUVM, NIL_VMCPUID, pszName, pszArgs, pHlp);
828 return VMR3ReqPriorityCallWaitU(pUVM, idCpu,
829 (PFNRT)dbgfR3Info, 5, pUVM, idCpu, pszName, pszArgs, pHlp);
830}
831
832
833/**
834 * Wrapper for DBGFR3Info that outputs to the release log.
835 *
836 * @returns See DBGFR3Info.
837 * @param pUVM The user mode VM handle.
838 * @param pszName See DBGFR3Info.
839 * @param pszArgs See DBGFR3Info.
840 */
841VMMR3DECL(int) DBGFR3InfoLogRel(PUVM pUVM, const char *pszName, const char *pszArgs)
842{
843 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, &g_dbgfR3InfoLogRelHlp);
844}
845
846
847/**
848 * Wrapper for DBGFR3Info that outputs to standard error.
849 *
850 * @returns See DBGFR3Info.
851 * @param pUVM The user mode VM handle.
852 * @param pszName See DBGFR3Info.
853 * @param pszArgs See DBGFR3Info.
854 */
855VMMR3DECL(int) DBGFR3InfoStdErr(PUVM pUVM, const char *pszName, const char *pszArgs)
856{
857 return DBGFR3InfoEx(pUVM, NIL_VMCPUID, pszName, pszArgs, &g_dbgfR3InfoStdErrHlp);
858}
859
860
861/**
862 * Display several info items.
863 *
864 * This is intended used by the fatal error dump only.
865 *
866 * @returns VBox status code.
867 * @param pVM The cross context VM structure.
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 *
875 * @thread EMT
876 */
877VMMR3_INT_DECL(int) DBGFR3InfoMulti(PVM pVM, const char *pszIncludePat, const char *pszExcludePat, const char *pszSepFmt,
878 PCDBGFINFOHLP pHlp)
879{
880 /*
881 * Validate input.
882 */
883 PUVM pUVM = pVM->pUVM;
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 */
903 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
904 AssertRC(rc);
905 rc = VWRN_NOT_FOUND;
906 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
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);
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
917 rc = VINF_SUCCESS;
918 switch (pInfo->enmType)
919 {
920 case DBGFINFOTYPE_DEV:
921 if (idDstCpu != NIL_VMCPUID)
922 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Dev.pfnHandler, 3,
923 pInfo->u.Dev.pDevIns, pHlp, pszArgs);
924 else
925 pInfo->u.Dev.pfnHandler(pInfo->u.Dev.pDevIns, pHlp, pszArgs);
926 break;
927
928 case DBGFINFOTYPE_DRV:
929 if (idDstCpu != NIL_VMCPUID)
930 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Drv.pfnHandler, 3,
931 pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
932 else
933 pInfo->u.Drv.pfnHandler(pInfo->u.Drv.pDrvIns, pHlp, pszArgs);
934 break;
935
936 case DBGFINFOTYPE_INT:
937 if (idDstCpu != NIL_VMCPUID)
938 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Int.pfnHandler, 3,
939 pVM, pHlp, pszArgs);
940 else
941 pInfo->u.Int.pfnHandler(pVM, pHlp, pszArgs);
942 break;
943
944 case DBGFINFOTYPE_EXT:
945 if (idDstCpu != NIL_VMCPUID)
946 rc = VMR3ReqPriorityCallVoidWaitU(pUVM, idDstCpu, (PFNRT)pInfo->u.Ext.pfnHandler, 3,
947 pInfo->u.Ext.pvUser, pHlp, pszArgs);
948 else
949 pInfo->u.Ext.pfnHandler(pInfo->u.Ext.pvUser, pHlp, pszArgs);
950 break;
951
952 default:
953 AssertMsgFailedReturn(("Invalid info type enmType=%d\n", pInfo->enmType), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
954 }
955 }
956 }
957 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
958 AssertRC(rc2);
959
960 return rc;
961}
962
963
964/**
965 * Enumerate all the register info handlers.
966 *
967 * @returns VBox status code.
968 * @param pUVM The user mode VM handle.
969 * @param pfnCallback Pointer to callback function.
970 * @param pvUser User argument to pass to the callback.
971 */
972VMMR3DECL(int) DBGFR3InfoEnum(PUVM pUVM, PFNDBGFINFOENUM pfnCallback, void *pvUser)
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 }
984 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
985
986 /*
987 * Enter and enumerate.
988 */
989 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
990 AssertRC(rc);
991
992 rc = VINF_SUCCESS;
993 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; RT_SUCCESS(rc) && pInfo; pInfo = pInfo->pNext)
994 rc = pfnCallback(pUVM, pInfo->szName, pInfo->pszDesc, pvUser);
995
996 /*
997 * Leave and exit.
998 */
999 int rc2 = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
1000 AssertRC(rc2);
1001
1002 LogFlow(("DBGFR3InfoLog: returns %Rrc\n", rc));
1003 return rc;
1004}
1005
1006
1007/**
1008 * Info handler, internal version.
1009 *
1010 * @param pVM The cross context VM structure.
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 */
1021 PUVM pUVM = pVM->pUVM;
1022 int rc = RTCritSectRwEnterShared(&pUVM->dbgf.s.CritSect);
1023 AssertRC(rc);
1024
1025 if (pszArgs && *pszArgs)
1026 {
1027 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
1028 {
1029 const char *psz = strstr(pszArgs, pInfo->szName);
1030 if ( psz
1031 && ( psz == pszArgs
1032 || RT_C_IS_SPACE(psz[-1]))
1033 && ( !psz[pInfo->cchName]
1034 || RT_C_IS_SPACE(psz[pInfo->cchName])))
1035 pHlp->pfnPrintf(pHlp, "%-16s %s\n",
1036 pInfo->szName, pInfo->pszDesc);
1037 }
1038 }
1039 else
1040 {
1041 for (PDBGFINFO pInfo = pUVM->dbgf.s.pInfoFirst; pInfo; pInfo = pInfo->pNext)
1042 pHlp->pfnPrintf(pHlp, "%-16s %s\n",
1043 pInfo->szName, pInfo->pszDesc);
1044 }
1045
1046 /*
1047 * Leave and exit.
1048 */
1049 rc = RTCritSectRwLeaveShared(&pUVM->dbgf.s.CritSect);
1050 AssertRC(rc);
1051}
1052
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