dbgmoddbghelp.cpp revision 64eea8161bef2aa3c6516481383c830bca27abfe
/* $Id$ */
/** @file
* IPRT - Debug Info Reader Using DbgHelp.dll if Present.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_DBG
#include <Windows.h>
#include <Dbghelp.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** For passing arguments to DbgHelp.dll callback. */
typedef struct RTDBGMODBGHELPARGS
{
/** UTF-8 version of the previous file name. */
char *pszPrev;
/** Copy of the previous file name. */
/** Number of bytes pwszPrev points to. */
/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByAddr} */
static DECLCALLBACK(int) rtDbgModDbgHelp_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByOrdinal} */
static DECLCALLBACK(int) rtDbgModDbgHelp_LineByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnLineCount} */
{
return RTDbgModLineCount(hCnt);
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnLineAdd} */
static DECLCALLBACK(int) rtDbgModDbgHelp_LineAdd(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByAddr} */
static DECLCALLBACK(int) rtDbgModDbgHelp_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByName} */
static DECLCALLBACK(int) rtDbgModDbgHelp_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByOrdinal} */
static DECLCALLBACK(int) rtDbgModDbgHelp_SymbolByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolCount} */
{
return RTDbgModSymbolCount(hCnt);
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolAdd} */
static DECLCALLBACK(int) rtDbgModDbgHelp_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentByIndex} */
static DECLCALLBACK(int) rtDbgModDbgHelp_SegmentByIndex(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentCount} */
{
return RTDbgModSegmentCount(hCnt);
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentAdd} */
static DECLCALLBACK(int) rtDbgModDbgHelp_SegmentAdd(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnImageSize} */
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnRvaToSegOff} */
static DECLCALLBACK(RTDBGSEGIDX) rtDbgModDbgHelp_RvaToSegOff(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
{
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnClose} */
{
return VINF_SUCCESS;
}
/**
* SymEnumLinesW callback that adds a line number to the container.
*
* @returns TRUE, FALSE if we're out of memory.
* @param pLineInfo Line number information.
* @param pvUser Pointer to a RTDBGMODBGHELPARGS structure.
*/
{
{
return TRUE;
}
/*
* To save having to call RTUtf16ToUtf8 every time, we keep a copy of the
* previous file name both as UTF-8 and UTF-16.
*/
/** @todo we could combine RTUtf16Len and memcmp... */
{
else
{
pArgs->pwszPrev = (PRTUTF16)RTMemDupEx(pLineInfo->FileName, cbLen, pArgs->cbPrevUtf16Alloc - cbLen);
pArgs->cbPrevUtf16Alloc = 0;
}
if (RT_FAILURE(rc))
{
Log(("rtDbgModDbgHelpCopyLineNumberCallback: Out of memory\n"));
return FALSE;
}
}
/*
* Add the line number to the container.
*/
return TRUE;
}
/**
* Copies the line numbers into the container.
*
* @returns IPRT status code.
* @param pMod The debug module.
* @param hCnt The container that will keep the symbols.
* @param hFake The fake process handle.
* @param uModAddr The module load address.
*/
static int rtDbgModDbgHelpCopyLineNumbers(PRTDBGMODINT pMod, RTDBGMOD hCnt, HANDLE hFake, uint64_t uModAddr)
{
Args.cbPrevUtf16Alloc = 0;
int rc;
if (SymEnumLinesW(hFake, uModAddr, NULL /*pszObj*/, NULL /*pszFile*/, rtDbgModDbgHelpCopyLineNumberCallback, &Args))
rc = VINF_SUCCESS;
else
{
if (rc == VERR_NOT_SUPPORTED)
rc = VINF_SUCCESS;
}
return rc;
}
/**
* SymEnumSymbols callback that adds a symbol to the container.
*
* @returns TRUE
* @param pSymInfo The symbol information.
* @param cbSymbol The symbol size (estimated).
* @param pvUser Pointer to a RTDBGMODBGHELPARGS structure.
*/
static BOOL CALLBACK rtDbgModDbgHelpCopySymbolsCallback(PSYMBOL_INFO pSymInfo, ULONG cbSymbol, PVOID pvUser)
{
{
Log((" %#018x LB %#07x %s [SKIPPED - INVALID ADDRESS!]\n", pSymInfo->Address, cbSymbol, pSymInfo->Name));
return TRUE;
}
{
Log((" %#018x LB %#07x %s [SKIPPED - TOO LONG (%u > %u)!]\n", pSymInfo->Address, cbSymbol, pSymInfo->Name,
return TRUE;
}
/* ASSUMES the symbol name is ASCII. */
return TRUE;
}
/**
* Copies the symbols into the container.
*
* @returns IPRT status code.
* @param pMod The debug module.
* @param hCnt The container that will keep the symbols.
* @param hFake The fake process handle.
* @param uModAddr The module load address.
*/
static int rtDbgModDbgHelpCopySymbols(PRTDBGMODINT pMod, RTDBGMOD hCnt, HANDLE hFake, uint64_t uModAddr)
{
int rc;
rc = VINF_SUCCESS;
else
{
}
return rc;
}
/** @callback_method_impl{FNRTLDRENUMSEGS, Copies the PE segments over into
* the container.} */
static DECLCALLBACK(int) rtDbgModDbgHelpAddSegmentsCallback(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser)
{
Log(("Segment %.*s: LinkAddress=%#llx RVA=%#llx cb=%#llx\n",
}
/** @interface_method_impl{RTDBGMODVTDBG,pfnTryOpen} */
{
/*
* Currently only support external files with a executable already present.
*/
if (!pMod->pszDbgFile)
return VERR_DBG_NO_MATCHING_INTERPRETER;
return VERR_DBG_NO_MATCHING_INTERPRETER;
/*
* Create a container for copying the information into. We do this early
* so we can determine the image base address.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* Try load the module into an empty address space.
*/
do
LogFlow(("rtDbgModDbgHelp_TryOpen: \n"));
{
if (RT_SUCCESS(rc))
{
if (uModAddr != 0)
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
hCnt = NIL_RTDBGMOD;
LogFlow(("rtDbgModDbgHelp_TryOpen: Successfully loaded '%s' at %#llx\n",
}
}
else
{
LogFlow(("rtDbgModDbgHelp_TryOpen: Error loading the module '%s' at %#llx: %Rrc (%u)\n",
}
}
else
}
else
{
}
}
}
return rc;
}
/** Virtual function table for the DBGHELP debug info reader. */
{
/*.u32Magic = */ RTDBGMODVTDBG_MAGIC,
/*.fSupports = */ RT_DBGTYPE_CODEVIEW,
/*.pszName = */ "dbghelp",
/*.pfnTryOpen = */ rtDbgModDbgHelp_TryOpen,
/*.pfnClose = */ rtDbgModDbgHelp_Close,
/*.pfnRvaToSegOff = */ rtDbgModDbgHelp_RvaToSegOff,
/*.pfnImageSize = */ rtDbgModDbgHelp_ImageSize,
/*.pfnSegmentAdd = */ rtDbgModDbgHelp_SegmentAdd,
/*.pfnSegmentCount = */ rtDbgModDbgHelp_SegmentCount,
/*.pfnSegmentByIndex = */ rtDbgModDbgHelp_SegmentByIndex,
/*.pfnSymbolAdd = */ rtDbgModDbgHelp_SymbolAdd,
/*.pfnSymbolCount = */ rtDbgModDbgHelp_SymbolCount,
/*.pfnSymbolByOrdinal = */ rtDbgModDbgHelp_SymbolByOrdinal,
/*.pfnSymbolByName = */ rtDbgModDbgHelp_SymbolByName,
/*.pfnSymbolByAddr = */ rtDbgModDbgHelp_SymbolByAddr,
/*.pfnLineAdd = */ rtDbgModDbgHelp_LineAdd,
/*.pfnLineCount = */ rtDbgModDbgHelp_LineCount,
/*.pfnLineByOrdinal = */ rtDbgModDbgHelp_LineByOrdinal,
/*.pfnLineByAddr = */ rtDbgModDbgHelp_LineByAddr,
/*.u32EndMagic = */ RTDBGMODVTDBG_MAGIC
};