dbgmoddwarf.cpp revision b26e5b503baa3dffc58048982eaf17ad1b53f207
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * IPRT - Debug Info Reader For DWARF.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * Copyright (C) 2011 Oracle Corporation
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * available from http://www.virtualbox.org. This file is free software;
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * you can redistribute it and/or modify it under the terms of the GNU
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * General Public License (GPL) as published by the Free Software
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * The contents of this file may alternatively be used under the terms
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * of the Common Development and Distribution License Version 1.0
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * VirtualBox OSE distribution, in which case the provisions of the
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * CDDL are applicable instead of those of the GPL.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * You may elect to license modified versions of this file under the
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * terms and conditions of either the GPL or the CDDL or both.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync/*******************************************************************************
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync* Header Files *
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync*******************************************************************************/
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync/*******************************************************************************
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync* Structures and Typedefs *
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync*******************************************************************************/
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * DWARF sections.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** End of valid parts (exclusive). */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * The instance data of the DWARF reader.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The debug container containing doing the real work. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** Pointer to back to the debug info module (no reference ofc). */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** DWARF debug info sections. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The file offset of the part. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The size of the part. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The memory mapping of the part. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync void const *pv;
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** Set if present. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync/** Pointer to instance data of the DWARF reader. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * Section reader instance.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The DWARF debug info reader instance. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The section we're reading. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The current position. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** The number of bytes left to read. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** Set if this is 64-bit DWARF, clear if 32-bit. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync /** Set if the format endian is native, clear if endian needs to be
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * inverted. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync/** Pointer to a DWARF section reader. */
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * Loads a DWARF section from the image file.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * @returns IPRT status code.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * @param pThis The DWARF instance.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * @param enmSect The section to load.
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsyncstatic int rtDbgModDwarfLoadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
96a93b5e6bd7da64f6be955c9fd7569b80c8ae2evboxsync * Don't load stuff twice.
return VINF_SUCCESS;
return VINF_SUCCESS;
return VINF_SUCCESS;
return VERR_OUT_OF_RANGE;
return pThis->pMod->pImgVt->pfnMapPart(pThis->pMod, pThis->aSections[enmSect].offFile, pThis->aSections[enmSect].cb,
return VINF_SUCCESS;
int rc = pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv);
return rc;
return *pu32;
return *pu64;
return uErrValue;
return u8;
return uErrValue;
return u16;
return uErrValue;
uint32_t u32 = RT_MAKE_U32_FROM_U8(pSectRdr->pb[0], pSectRdr->pb[1], pSectRdr->pb[2], pSectRdr->pb[3]);
return u32;
uint64_t u64 = RT_MAKE_U64_FROM_U8(pSectRdr->pb[0], pSectRdr->pb[1], pSectRdr->pb[2], pSectRdr->pb[3],
return u64;
static int rtDwarfSectRdrInit(PRTDWARFSECTRDR pSectRdr, PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
return rc;
return VINF_SUCCESS;
static DECLCALLBACK(int) rtDbgModDwarf_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
static DECLCALLBACK(int) rtDbgModDwarf_LineByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
static DECLCALLBACK(int) rtDbgModDwarf_LineAdd(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
static DECLCALLBACK(int) rtDbgModDwarf_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
static DECLCALLBACK(int) rtDbgModDwarf_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
static DECLCALLBACK(int) rtDbgModDwarf_SymbolByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
static DECLCALLBACK(int) rtDbgModDwarf_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
static DECLCALLBACK(int) rtDbgModDwarf_SegmentByIndex(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
static DECLCALLBACK(int) rtDbgModDwarf_SegmentAdd(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
static DECLCALLBACK(RTDBGSEGIDX) rtDbgModDwarf_RvaToSegOff(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[iSect].cb, &pThis->aSections[iSect].pv);
return VINF_SUCCESS;
return VINF_SUCCESS;
return rc;
return rc;
return rc;
return rc;
return rc;
while (cbLeft > 0)
return rc;
static DECLCALLBACK(int) rtDbgModHlpAddSegmentCallback(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser)
return pMod->pDbgVt->pfnSegmentAdd(pMod, pSeg->RVA, pSeg->cb, pSeg->pchName, pSeg->cchName, 0 /*fFlags*/, NULL);
static DECLCALLBACK(int) rtDbgModDwarfEnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType,
|| !pszPartNm
|| pszExtFile)
return VINF_SUCCESS;
#define ELSE_IF_STRCMP_SET(a_Name) else if (!strcmp(pszPartNm, #a_Name)) enmSect = krtDbgModDwarfSect_ ## a_Name
return VINF_SUCCESS;
AssertMsgReturn(!pThis->aSections[enmSect].fPresent, ("duplicate %s\n", pszPartNm), VINF_SUCCESS /*ignore*/);
return VINF_SUCCESS;
return VERR_DBG_NO_MATCHING_INTERPRETER;
if (!pThis)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
return rc;