DBGFLog.cpp revision 1939436fa43cbf7f5cdc05a3830ed624d5fe4a6a
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* $Id$ */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/** @file
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * DBGF - Debugger Facility, Log Manager.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/*
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2006-2013 Oracle Corporation
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * General Public License (GPL) as published by the Free Software
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/*******************************************************************************
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync* Header Files *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync*******************************************************************************/
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/vmm/vmapi.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/vmm/vmm.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/vmm/dbgf.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/vmm/uvm.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/vmm/vm.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/log.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <VBox/err.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <iprt/assert.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <iprt/param.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <iprt/string.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Checkes for logger prefixes and selects the right logger.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns Target logger.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppsz Pointer to the string pointer.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic PRTLOGGER dbgfR3LogResolvedLogger(const char **ppsz)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync PRTLOGGER pLogger;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync const char *psz = *ppsz;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (!strncmp(psz, RT_STR_TUPLE("release:")))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *ppsz += sizeof("release:") - 1;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync pLogger = RTLogRelDefaultInstance();
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync else
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (!strncmp(psz, RT_STR_TUPLE("debug:")))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *ppsz += sizeof("debug:") - 1;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync pLogger = RTLogDefaultInstance();
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return pLogger;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync}
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * EMT worker for DBGFR3LogModifyGroups.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns VBox status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param pUVM The user mode VM handle.
* @param pszGroupSettings The group settings string. (VBOX_LOG)
*/
static DECLCALLBACK(int) dbgfR3LogModifyGroups(PUVM pUVM, const char *pszGroupSettings)
{
PRTLOGGER pLogger = dbgfR3LogResolvedLogger(&pszGroupSettings);
if (!pLogger)
return VINF_SUCCESS;
int rc = RTLogGroupSettings(pLogger, pszGroupSettings);
if (RT_SUCCESS(rc) && pUVM->pVM)
{
VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
rc = VMMR3UpdateLoggers(pUVM->pVM);
}
return rc;
}
/**
* Changes the logger group settings.
*
* @returns VBox status code.
* @param pUVM The user mode VM handle.
* @param pszGroupSettings The group settings string. (VBOX_LOG)
* By prefixing the string with \"release:\" the
* changes will be applied to the release log
* instead of the debug log. The prefix \"debug:\"
* is also recognized.
*/
VMMR3DECL(int) DBGFR3LogModifyGroups(PUVM pUVM, const char *pszGroupSettings)
{
UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
AssertPtrReturn(pszGroupSettings, VERR_INVALID_POINTER);
return VMR3ReqPriorityCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)dbgfR3LogModifyGroups, 2, pUVM, pszGroupSettings);
}
/**
* EMT worker for DBGFR3LogModifyFlags.
*
* @returns VBox status code.
* @param pUVM The user mode VM handle.
* @param pszFlagSettings The group settings string. (VBOX_LOG_FLAGS)
*/
static DECLCALLBACK(int) dbgfR3LogModifyFlags(PUVM pUVM, const char *pszFlagSettings)
{
PRTLOGGER pLogger = dbgfR3LogResolvedLogger(&pszFlagSettings);
if (!pLogger)
return VINF_SUCCESS;
int rc = RTLogFlags(pLogger, pszFlagSettings);
if (RT_SUCCESS(rc) && pUVM->pVM)
{
VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
rc = VMMR3UpdateLoggers(pUVM->pVM);
}
return rc;
}
/**
* Changes the logger flag settings.
*
* @returns VBox status code.
* @param pUVM The user mode VM handle.
* @param pszFlagSettings The group settings string. (VBOX_LOG_FLAGS)
* By prefixing the string with \"release:\" the
* changes will be applied to the release log
* instead of the debug log. The prefix \"debug:\"
* is also recognized.
*/
VMMR3DECL(int) DBGFR3LogModifyFlags(PUVM pUVM, const char *pszFlagSettings)
{
UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
AssertPtrReturn(pszFlagSettings, VERR_INVALID_POINTER);
return VMR3ReqPriorityCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)dbgfR3LogModifyFlags, 2, pUVM, pszFlagSettings);
}
/**
* EMT worker for DBGFR3LogModifyFlags.
*
* @returns VBox status code.
* @param pUVM The user mode VM handle.
* @param pszDestSettings The destination settings string. (VBOX_LOG_DEST)
*/
static DECLCALLBACK(int) dbgfR3LogModifyDestinations(PUVM pUVM, const char *pszDestSettings)
{
PRTLOGGER pLogger = dbgfR3LogResolvedLogger(&pszDestSettings);
if (!pLogger)
return VINF_SUCCESS;
int rc = RTLogDestinations(NULL, pszDestSettings);
if (RT_SUCCESS(rc) && pUVM->pVM)
{
VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
rc = VMMR3UpdateLoggers(pUVM->pVM);
}
return rc;
}
/**
* Changes the logger destination settings.
*
* @returns VBox status code.
* @param pUVM The user mode VM handle.
* @param pszDestSettings The destination settings string. (VBOX_LOG_DEST)
* By prefixing the string with \"release:\" the
* changes will be applied to the release log
* instead of the debug log. The prefix \"debug:\"
* is also recognized.
*/
VMMR3DECL(int) DBGFR3LogModifyDestinations(PUVM pUVM, const char *pszDestSettings)
{
UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
AssertPtrReturn(pszDestSettings, VERR_INVALID_POINTER);
return VMR3ReqPriorityCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)dbgfR3LogModifyDestinations, 2, pUVM, pszDestSettings);
}