dbgmod.cpp revision ca3da10d05961c339b5180fbd40a54587d6bad35
/* $Id$ */
/** @file
* IPRT - Debug Module Interpreter.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
#include <iprt/semaphore.h>
#include <iprt/strcache.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** Debug info interpreter regisration record. */
typedef struct RTDBGMODREGDBG
{
/** Pointer to the next record. */
struct RTDBGMODREGDBG *pNext;
/** Pointer to the virtual function table for the interpreter. */
/** Usage counter. */
typedef RTDBGMODREGDBG *PRTDBGMODREGDBG;
/** Image interpreter regisration record. */
typedef struct RTDBGMODREGIMG
{
/** Pointer to the next record. */
struct RTDBGMODREGIMG *pNext;
/** Pointer to the virtual function table for the interpreter. */
/** Usage counter. */
typedef RTDBGMODREGIMG *PRTDBGMODREGIMG;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Validates a debug module handle and returns rc if not valid. */
do { \
} while (0)
/** Locks the debug module. */
#define RTDBGMOD_LOCK(pDbgMod) \
do { \
} while (0)
/** Unlocks the debug module. */
#define RTDBGMOD_UNLOCK(pDbgMod) \
do { \
} while (0)
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Init once object for lazy registration of the built-in image and debug
* info interpreters. */
/** List of registered image interpreters. */
static RTDBGMODREGIMG g_pImgHead;
/** List of registered debug infor interpreters. */
static RTDBGMODREGDBG g_pDbgHead;
/** String cache for the debug info interpreters.
* RTSTRCACHE is thread safe. */
/**
* Cleanup debug info interpreter globals.
*
* @param enmReason The cause of the termination.
* @param iStatus The meaning of this depends on enmReason.
* @param pvUser User argument, unused.
*/
static DECLCALLBACK(void) rtDbgModTermCallback(RTTERMREASON enmReason, int32_t iStatus, void *pvUser)
{
if (enmReason == RTTERMREASON_UNLOAD)
{
/** @todo deregister interpreters. */
}
}
/**
* the built-in interpreters.
*
* @returns IPRT status code.
* @param pvUser1 NULL.
* @param pvUser2 NULL.
*/
{
/*
* Create the semaphore and string cache.
*/
if (RT_SUCCESS(rc))
{
/*
* Register the interpreters.
*/
/** @todo */
if (RT_SUCCESS(rc))
{
/*
* Finally, register the IPRT cleanup callback.
*/
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
}
}
return rc;
}
DECLINLINE(int) rtDbgModLazyInit(void)
{
}
/**
* Creates a module based on the default debug info container.
*
* This can be used to manually load a module and its symbol.
*
* @returns IPRT status code.
*
* @param phDbgMod Where to return the module handle.
* @param pszName The name of the module (mandatory).
* @param cb The size of the module. Must be greater than zero.
* @param fFlags Flags reserved for future extensions, MBZ for now.
*/
{
/*
* Input validation and lazy initialization.
*/
*phDbgMod = NIL_RTDBGMOD;
int rc = rtDbgModLazyInit();
if (RT_FAILURE(rc))
return rc;
/*
* Allocate a new module instance.
*/
if (!pDbgMod)
return VERR_NO_MEMORY;
if (RT_SUCCESS(rc))
{
{
if (RT_SUCCESS(rc))
{
return rc;
}
}
}
return rc;
}
RTDECL(int) RTDbgModCreateDeferred(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR cb, uint32_t fFlags)
{
return VERR_NOT_IMPLEMENTED;
}
RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags)
{
return VERR_NOT_IMPLEMENTED;
}
RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend, uint32_t fFlags)
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Destroys an module after the reference count has reached zero.
*
* @param pDbgMod The module instance.
*/
{
/*
* Close the debug info interpreter first, then the image interpret.
*/
{
}
{
}
/*
* Free the resources.
*/
}
/**
* Retains another reference to the module.
*
* @returns New reference count, UINT32_MAX on invalid handle (asserted).
*
* @param hDbgMod The module handle.
*
* @remarks Will not take any locks.
*/
{
}
/**
* Release a reference to the module.
*
* When the reference count reaches zero, the module is destroyed.
*
* @returns New reference count, UINT32_MAX on invalid handle (asserted).
*
* @param hDbgMod The module handle. The NIL handle is quietly ignored
* and 0 is returned.
*
* @remarks Will not take any locks.
*/
{
if (hDbgMod == NIL_RTDBGMOD)
return 0;
if (!cRefs)
return cRefs;
}
/**
* Gets the module name.
*
* @returns Pointer to a read only string containing the name.
*
* @param hDbgMod The module handle.
*/
{
}
{
return 1;
}
{
return 1;
}
{
return 0;
}
{
return 1;
}
/**
* Adds a line number to the module.
*
* @returns IPRT status code.
* @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
* @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
* custom symbols.
* @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE
* @retval VERR_DBG_INVALID_RVA
* @retval VERR_DBG_INVALID_SEGMENT_INDEX
* @retval VERR_DBG_INVALID_SEGMENT_OFFSET
* @retval VERR_INVALID_PARAMETER
*
* @param hDbgMod The module handle.
* @param pszSymbol The symbol name.
* @param iSeg The segment index.
* @param off The segment offset.
* @param cb The size of the symbol.
* @param fFlags Symbol flags.
*/
RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off, RTUINTPTR cb, uint32_t fFlags)
{
/*
* Validate input.
*/
|| ( iSeg >= RTDBGSEGIDX_SPECIAL_FIRST
&& iSeg <= RTDBGSEGIDX_SPECIAL_LAST),
("%#x\n", iSeg),
/*
* Convert RVAs.
*/
if (iSeg == RTDBGSEGIDX_RVA)
{
if (iSeg == NIL_RTDBGSEGIDX)
{
return VERR_DBG_INVALID_RVA;
}
}
/*
* Get down to business.
*/
return rc;
}
{
return 1;
}
{
return VERR_NOT_IMPLEMENTED;
}
RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL pSymbol)
{
return VERR_NOT_IMPLEMENTED;
}
RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymbol)
{
return VERR_NOT_IMPLEMENTED;
}
{
return VERR_NOT_IMPLEMENTED;
}
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Adds a line number to the module.
*
* @returns IPRT status code.
* @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
* @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
* custom symbols.
* @retval VERR_DBG_FILE_NAME_OUT_OF_RANGE
* @retval VERR_DBG_INVALID_RVA
* @retval VERR_DBG_INVALID_SEGMENT_INDEX
* @retval VERR_DBG_INVALID_SEGMENT_OFFSET
* @retval VERR_INVALID_PARAMETER
*
* @param hDbgMod The module handle.
* @param pszFile The file name.
* @param uLineNo The line number.
* @param iSeg The segment index.
* @param off The segment offset.
*/
RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo, RTDBGSEGIDX iSeg, RTUINTPTR off)
{
/*
* Validate input.
*/
|| iSeg == RTDBGSEGIDX_RVA,
("%#x\n", iSeg),
/*
* Convert RVAs.
*/
if (iSeg == RTDBGSEGIDX_RVA)
{
if (iSeg == NIL_RTDBGSEGIDX)
{
return VERR_DBG_INVALID_RVA;
}
}
/*
* Get down to business.
*/
return rc;
}
RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLine)
{
return VERR_NOT_IMPLEMENTED;
}
RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLine)
{
return VERR_NOT_IMPLEMENTED;
}