dbgmodcontainer.cpp revision 044af0d1e6474076366759db86f101778c5f20cc
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/strcache.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Symbol entry.
*/
typedef struct RTDBGMODCTNSYMBOL
{
/** The address core. */
/** The name space core. */
/** The ordinal number core. */
/** The segment index. */
/** The symbol flags. */
/** The symbol size.
* This may be zero while the range in AddrCore indicates 0. */
/** Pointer to a symbol entry in the debug info container. */
typedef RTDBGMODCTNSYMBOL *PRTDBGMODCTNSYMBOL;
/** Pointer to a const symbol entry in the debug info container. */
typedef RTDBGMODCTNSYMBOL const *PCRTDBGMODCTNSYMBOL;
/**
* Line number entry.
*/
typedef struct RTDBGMODCTNLINE
{
/** The address core.
* The Key is the address of the line number. */
/** The ordinal number core. */
/** Pointer to the file name (in string cache). */
const char *pszFile;
/** The line number. */
/** The segment index. */
/** Pointer to a line number entry. */
typedef RTDBGMODCTNLINE *PRTDBGMODCTNLINE;
/** Pointer to const a line number entry. */
typedef RTDBGMODCTNLINE const *PCRTDBGMODCTNLINE;
/**
* Segment entry.
*/
typedef struct RTDBGMODCTNSEGMENT
{
/** The symbol address space tree. */
/** The line number address space tree. */
/** The segment offset. */
/** The segment size. */
/** The segment name. */
const char *pszName;
/** Pointer to a segment entry in the debug info container. */
typedef RTDBGMODCTNSEGMENT *PRTDBGMODCTNSEGMENT;
/** Pointer to a const segment entry in the debug info container. */
typedef RTDBGMODCTNSEGMENT const *PCRTDBGMODCTNSEGMENT;
/**
* Instance data.
*/
typedef struct RTDBGMODCTN
{
/** The name space. */
/** Tree containing any absolute addresses. */
/** Tree organizing the symbols by ordinal number. */
/** Tree organizing the line numbers by ordinal number. */
/** Segment table. */
/** The number of segments in the segment table. */
/** The image size. 0 means unlimited. */
/** The next symbol ordinal. */
/** The next line number ordinal. */
} RTDBGMODCTN;
/** Pointer to instance data for the debug info container. */
typedef RTDBGMODCTN *PRTDBGMODCTN;
/**
* Fills in a RTDBGSYMBOL structure.
*
* @returns VINF_SUCCESS.
* @param pMySym Our internal symbol representation.
* @param pExtSym The external symbol representation.
*/
{
return VINF_SUCCESS;
}
/** @copydoc RTDBGMODVTDBG::pfnLineByAddr */
static DECLCALLBACK(int) rtDbgModContainer_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
{
/*
* Validate the input address.
*/
/*
* Lookup the nearest line number with an address less or equal to the specified address.
*/
PAVLUINTPTRNODECORE pAvlCore = RTAvlUIntPtrGetBestFit(&pThis->paSegs[iSeg].LineAddrTree, off, false /*fAbove*/);
if (!pAvlCore)
return pThis->iNextLineOrdinal
if (poffDisp)
return VINF_SUCCESS;
}
/** @copydoc RTDBGMODVTDBG::pfnLineByOrdinal */
static DECLCALLBACK(int) rtDbgModContainer_LineByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLine)
{
/*
* Look it up.
*/
return pThis->iNextLineOrdinal
return VINF_SUCCESS;
}
/** @copydoc RTDBGMODVTDBG::pfnLineCount */
{
/* Note! The ordinal numbers are 0-based. */
return pThis->iNextLineOrdinal;
}
/** @copydoc RTDBGMODVTDBG::pfnLineAdd */
static DECLCALLBACK(int) rtDbgModContainer_LineAdd(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
{
/*
* Validate the input address.
*/
AssertMsgReturn(pThis->paSegs[iSeg].cb < off, ("off=%RTptr cbSeg=%RTptr\n", off, pThis->paSegs[iSeg].cb),
/*
* Create a new entry.
*/
if (!pLine)
return VERR_NO_MEMORY;
int rc;
{
{
{
if (piOrdinal)
return VINF_SUCCESS;
}
}
/* bail out */
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/** @copydoc RTDBGMODVTDBG::pfnSymbolByAddr */
static DECLCALLBACK(int) rtDbgModContainer_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
{
/*
* Validate the input address.
*/
/*
* Lookup the nearest symbol with an address less or equal to the specified address.
*/
? &pThis->AbsAddrTree
off,
false /*fAbove*/);
if (!pAvlCore)
return VERR_SYMBOL_NOT_FOUND;
if (poffDisp)
}
/** @copydoc RTDBGMODVTDBG::pfnSymbolByName */
static DECLCALLBACK(int) rtDbgModContainer_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, PRTDBGSYMBOL pSymbol)
{
/*
* Look it up in the name space.
*/
if (!pStrCore)
return VERR_SYMBOL_NOT_FOUND;
}
/** @copydoc RTDBGMODVTDBG::pfnSymbolByOrdinal */
static DECLCALLBACK(int) rtDbgModContainer_SymbolByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymbol)
{
/*
* Look it up in the ordinal tree.
*/
return pThis->iNextSymbolOrdinal
}
/** @copydoc RTDBGMODVTDBG::pfnSymbolCount */
{
/* Note! The ordinal numbers are 0-based. */
return pThis->iNextSymbolOrdinal;
}
/** @copydoc RTDBGMODVTDBG::pfnSymbolAdd */
static DECLCALLBACK(int) rtDbgModContainer_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
{
/*
* Address validation. The other arguments have already been validated.
*/
/*
* Create a new entry.
*/
if (!pSymbol)
return VERR_NO_MEMORY;
int rc;
{
{
? &pThis->AbsAddrTree
{
{
if (piOrdinal)
return VINF_SUCCESS;
}
/* bail out */
}
else
}
else
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/** @copydoc RTDBGMODVTDBG::pfnRvaToSegOff */
static DECLCALLBACK(RTDBGSEGIDX) rtDbgModContainer_RvaToSegOff(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
{
if (cSegs <= 7)
{
/*
* Linear search.
*/
{
{
if (poffSeg)
return iSeg;
}
}
}
else
{
/*
* Binary search.
*/
for (;;)
{
{
if (poffSeg)
return iSeg;
}
/* advance */
{
/* between iFirst and iSeg. */
break;
}
else
{
/* between iSeg and iLast. */
break;
}
}
}
/* Invalid. */
return NIL_RTDBGSEGIDX;
}
/** Destroy a symbol node. */
static DECLCALLBACK(int) rtDbgModContainer_DestroyTreeNode(PAVLRUINTPTRNODECORE pNode, void *pvUser)
{
return 0;
}
/** @copydoc RTDBGMODVTDBG::pfnClose */
{
/*
* Destroy the symbols and instance data.
*/
{
}
return VINF_SUCCESS;
}
/** @copydoc RTDBGMODVTDBG::pfnTryOpen */
{
return VERR_INTERNAL_ERROR_5;
}
/** Virtual function table for the debug info container. */
static RTDBGMODVTDBG const g_rtDbgModVtDbgContainer =
{
/*.u32Magic = */ RTDBGMODVTDBG_MAGIC,
/*.pszName = */ "container",
/*.pfnTryOpen = */ rtDbgModContainer_TryOpen,
/*.pfnClose = */ rtDbgModContainer_Close,
/*.pfnRvaToSegOff = */ rtDbgModContainer_RvaToSegOff,
/*.pfnSymbolAdd = */ rtDbgModContainer_SymbolAdd,
/*.pfnSymbolCount = */ rtDbgModContainer_SymbolCount,
/*.pfnSymbolByOrdinal = */ rtDbgModContainer_SymbolByOrdinal,
/*.pfnSymbolByName = */ rtDbgModContainer_SymbolByName,
/*.pfnSymbolByAddr = */ rtDbgModContainer_SymbolByAddr,
/*.pfnLineAdd = */ rtDbgModContainer_LineAdd,
/*.pfnLineCount = */ rtDbgModContainer_LineCount,
/*.pfnLineByOrdinal = */ rtDbgModContainer_LineByOrdinal,
/*.pfnLineByAddr = */ rtDbgModContainer_LineByAddr,
/*.u32EndMagic = */ RTDBGMODVTDBG_MAGIC
};
/**
* Creates a generic debug info container and associates it with the module.
*
* @returns IPRT status code.
* @param pMod The module instance.
* @param cb The module size.
*/
{
if (!pThis)
return VERR_NO_MEMORY;
pThis->cb = cb; /** @todo the module size stuff doesn't quite make sense yet. Need to look at segments first, I guess. */
pThis->iNextSymbolOrdinal = 0;
pThis->iNextLineOrdinal = 0;
return VINF_SUCCESS;
}