VirtualBox

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

Last change on this file since 45728 was 44399, checked in by vboxsync, 12 years ago

DBGF,DBGC,++: PVM -> PUVM. Some refactoring and cleanup as well.

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