dbgmoddwarf.cpp revision c553cea6bfe2ce63ff5517ca4ec288502a890e99
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * IPRT - Debug Info Reader For DWARF.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Copyright (C) 2011 Oracle Corporation
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * available from http://www.virtualbox.org. This file is free software;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * General Public License (GPL) as published by the Free Software
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * The contents of this file may alternatively be used under the terms
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * of the Common Development and Distribution License Version 1.0
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * CDDL are applicable instead of those of the GPL.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * You may elect to license modified versions of this file under the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * terms and conditions of either the GPL or the CDDL or both.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*******************************************************************************
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync* Header Files *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync*******************************************************************************/
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/*******************************************************************************
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync* Defined Constants And Macros *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync*******************************************************************************/
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/** @name Standard DWARF Line Number Opcodes
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/** @name Extended DWARF Line Number Opcodes
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** @name DIE Tags.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_imported_declaration UINT16_C(0x0008)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_unspecified_parameters UINT16_C(0x0018)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_template_type_parameter UINT16_C(0x002f)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_template_value_parameter UINT16_C(0x0030)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_rvalue_reference_type UINT16_C(0x0042)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*******************************************************************************
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync* Structures and Typedefs *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync*******************************************************************************/
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * DWARF sections.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** End of valid parts (exclusive). */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Abbreviation cache entry.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Whether this entry is filled in or not. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Whether there are children or not. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The tag. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Offset into the abbrev section of the specification pairs. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/** Pointer to an abbreviation cache entry. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/** Pointer to a const abbreviation cache entry. */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * The instance data of the DWARF reader.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The debug container containing doing the real work. */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** Pointer to back to the debug info module (no reference ofc). */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** DWARF debug info sections. */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The file offset of the part. */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The size of the part. */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The memory mapping of the part. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync void const *pv;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** Set if present. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The offset into the abbreviation section of the current cache. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The number of cached abbreviations we've allocated space for. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Used for range checking cache lookups. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Array of cached abbreviations, indexed by code. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Used by rtDwarfAbbrev_Lookup when the result is uncachable. */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** Pointer to instance data of the DWARF reader. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF cursor for reading byte data.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** The current position. */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** The number of bytes left to read. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The number of bytes left to read in the current unit. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The DWARF debug info reader instance. */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** Set if this is 64-bit DWARF, clear if 32-bit. */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** Set if the format endian is native, clear if endian needs to be
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * inverted. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The size of a native address. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The cursor status code. This is VINF_SUCCESS until some error
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * occurs. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** The start of the area covered by the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Used for repositioning the cursor relative to the start of a section. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The section. */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/** Pointer to a DWARF section reader. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF line number program state.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** Virtual Line Number Machine Registers. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** Header. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** @name Include Path Table (0-based)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** @name File Name Table (0-based, dummy zero entry)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** The DWARF debug info reader instance. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** Pointer to a DWARF line number program state. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @callback_method_impl{FNRTLDRENUMSEGS} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModHlpAddSegmentCallback(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync Log(("Segment %.*s: LinkAddress=%#llx RVA=%#llx cb=%#llx\n",
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pSeg->cchName, pSeg->pchName, (uint64_t)pSeg->LinkAddress, (uint64_t)pSeg->RVA, pSeg->cb));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pMod->pDbgVt->pfnSegmentAdd(pMod, pSeg->RVA, cb, pSeg->pchName, pSeg->cchName, 0 /*fFlags*/, NULL);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pMod->pDbgVt->pfnSegmentAdd(pMod, pSeg->LinkAddress, cb, pSeg->pchName, pSeg->cchName, 0 /*fFlags*/, NULL);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Calls pfnSegmentAdd for each segment in the executable image.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pMod The debug module.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncDECLHIDDEN(int) rtDbgModHlpAddSegmentsFromImage(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pMod->pImgVt->pfnEnumSegments(pMod, rtDbgModHlpAddSegmentCallback, pMod);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Loads a DWARF section from the image file.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @returns IPRT status code.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param pThis The DWARF instance.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param enmSect The section to load.
5b0a093ca572a855886faa6747ad46df859dd041vboxsyncstatic int rtDbgModDwarfLoadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Don't load stuff twice.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Sections that are not present cannot be loaded, treat them like they
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * are empty
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Sections must be readable with the current image interface.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Do the job.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return pThis->pMod->pImgVt->pfnMapPart(pThis->pMod, pThis->aSections[enmSect].offFile, pThis->aSections[enmSect].cb,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Unloads a DWARF section previously mapped by rtDbgModDwarfLoadSection.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @returns IPRT status code.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param pThis The DWARF instance.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param enmSect The section to unload.
5b0a093ca572a855886faa6747ad46df859dd041vboxsyncstatic int rtDbgModDwarfUnloadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync int rc = pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Converts to UTF-8 or otherwise makes sure it's valid UTF-8.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pThis The DWARF instance.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param ppsz Pointer to the string pointer. May be
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * reallocated (RTStr*).
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDbgModDwarfStringToUtf8(PRTDBGMODDWARF pThis, char **ppsz)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Convers a link address into a segment+offset or RVA.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pThis The DWARF instance.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param LinkAddress The address to convert..
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param piSeg The segment index.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param poffSeg Where to return the segment offset.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDbgModDwarfLinkAddressToSegOffset(PRTDBGMODDWARF pThis, uint64_t LinkAddress,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pThis->pMod->pImgVt->pfnLinkAddressToSegOffset(pThis->pMod, LinkAddress, piSeg, poffSeg);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 8-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 8-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint8_t rtDwarfCursor_GetU8(PRTDWARFCURSOR pCursor, uint8_t uErrValue)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 16-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 16-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint16_t rtDwarfCursor_GetU16(PRTDWARFCURSOR pCursor, uint16_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint16_t u16 = RT_MAKE_U16(pCursor->pb[0], pCursor->pb[1]);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 32-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 32-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint32_t rtDwarfCursor_GetU32(PRTDWARFCURSOR pCursor, uint32_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint32_t u32 = RT_MAKE_U32_FROM_U8(pCursor->pb[0], pCursor->pb[1], pCursor->pb[2], pCursor->pb[3]);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 64-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 64-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetU64(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64 = RT_MAKE_U64_FROM_U8(pCursor->pb[0], pCursor->pb[1], pCursor->pb[2], pCursor->pb[3],
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb[4], pCursor->pb[5], pCursor->pb[6], pCursor->pb[7]);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned LEB128 encoded number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns unsigned 64-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param uErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetULeb128(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Special case - single byte.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!(b & 0x80))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Generic case.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Decode. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync } while (b & 0x80);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Update the cursor. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Check the range. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a signed LEB128 encoded number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns signed 64-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param sErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int64_t rtDwarfCursor_GetSLeb128(PRTDWARFCURSOR pCursor, int64_t sErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Special case - single byte.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!(b & 0x80))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (b & 0x40)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Generic case.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Decode it. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync } while (b & 0x80);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Update cursor. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Check the range. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Sign extend the value. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned LEB128 encoded number, max 32-bit width.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns unsigned 32-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param uErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint32_t rtDwarfCursor_GetULeb128AsU32(PRTDWARFCURSOR pCursor, uint32_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64 = rtDwarfCursor_GetULeb128(pCursor, uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a signed LEB128 encoded number, max 32-bit width.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns signed 32-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param sErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int32_t rtDwarfCursor_GetSLeb128AsS32(PRTDWARFCURSOR pCursor, int32_t sErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync int64_t s64 = rtDwarfCursor_GetSLeb128(pCursor, sErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Skips a LEB128 encoded number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfCursor_SkipLeb128(PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reads a zero terminated string, advancing the cursor beyond the terminator.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns Pointer to the string.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pszErrValue What to return if the string isn't terminated
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * before the end of the unit.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic const char *rtDwarfCursor_GetSZ(PRTDWARFCURSOR pCursor, const char *pszErrValue)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned DWARF half number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint16_t rtDwarfCursor_GetUHalf(PRTDWARFCURSOR pCursor, uint16_t uErrValue)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned DWARF byte number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint8_t rtDwarfCursor_GetUByte(PRTDWARFCURSOR pCursor, uint8_t uErrValue)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a signed DWARF byte number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int8_t rtDwarfCursor_GetSByte(PRTDWARFCURSOR pCursor, int8_t iErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return (int8_t)rtDwarfCursor_GetU8(pCursor, (uint8_t)iErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a unsigned DWARF offset value.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The value. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetUOff(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rtDwarfCursor_GetU32(pCursor, (uint32_t)uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a unsigned DWARF native offset value.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The value. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic uint64_t rtDwarfCursor_GetNativeUOff(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 1: return rtDwarfCursor_GetU8(pCursor, (uint8_t )uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 2: return rtDwarfCursor_GetU16(pCursor, (uint16_t)uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 4: return rtDwarfCursor_GetU32(pCursor, (uint32_t)uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 8: return rtDwarfCursor_GetU64(pCursor, uErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Gets the unit length, updating the unit length member and DWARF bitness
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * members of the cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns The unit length.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetInitalLength(PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Read the initial length.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t cbUnit = rtDwarfCursor_GetU32(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Set the unit length, quitely fixing bad lengths.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Calculates the section offset corresponding to the current cursor position.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns 32-bit section offset. If out of range, RTDWARFCURSOR::rc will be
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * set and UINT32_MAX returned.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pCursor The cursor.
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic uint32_t rtDwarfCursor_CalcSectOffsetU32(PRTDWARFCURSOR pCursor)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync size_t off = (uint8_t const *)pCursor->pDwarfMod->aSections[pCursor->enmSect].pv - pCursor->pb;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * Calculates an absolute cursor position from one relative to the current
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * cursor position.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @returns The absolute cursor position.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param pCursor The cursor.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param offRelative The relative position. Must be a positive
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsyncstatic uint8_t const *rtDwarfCursor_CalcPos(PRTDWARFCURSOR pCursor, size_t offRelative)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * Advances the cursor to the given position.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @returns IPRT status code.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param pCursor The cursor.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param pbNewPos The new position - returned by
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * rtDwarfCursor_CalcPos().
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsyncstatic int rtDwarfCursor_AdvanceToPos(PRTDWARFCURSOR pCursor, uint8_t const *pbNewPos)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uintptr_t cbAdj = (uintptr_t)pbNewPos - (uintptr_t)pCursor->pb;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Check if the cursor is at the end of the current DWARF unit.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c true if at the end or a cursor error is pending.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c false if not.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic bool rtDwarfCursor_IsAtEndOfUnit(PRTDWARFCURSOR pCursor)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return !pCursor->cbUnitLeft || RT_FAILURE(pCursor->rc);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Skips to the end of the current unit.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfCursor_SkipUnit(PRTDWARFCURSOR pCursor)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Check if the cursor is at the end of the section (or whatever the cursor is
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * processing).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c true if at the end or a cursor error is pending.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c false if not.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic bool rtDwarfCursor_IsAtEnd(PRTDWARFCURSOR pCursor)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return !pCursor->cbLeft || RT_FAILURE(pCursor->rc);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Initialize a section reader cursor.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * @param pThis The dwarf module.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param enmSect The name of the section to read.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfCursor_Init(PRTDWARFCURSOR pCursor, PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->pbStart = (uint8_t const *)pThis->aSections[enmSect].pv;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** @todo ask the image about the endian used as well as the address
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * width. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Initialize a section reader cursor with an offset.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns IPRT status code.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pCursor The cursor.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pThis The dwarf module.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param enmSect The name of the section to read.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param offSect The offset into the section.
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic int rtDwarfCursor_InitWithOffset(PRTDWARFCURSOR pCursor, PRTDBGMODDWARF pThis,
ad66a27959d7085aa31760f63ce082943be60e89vboxsync int rc = rtDwarfCursor_Init(pCursor, pThis, enmSect);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Deletes a section reader initialized by rtDwarfCursor_Init.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @returns @a rcOther or RTDWARCURSOR::rc.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pCursor The section reader.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param rcOther Other error code to be returned if it indicates
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * error or if the cursor status is OK.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfCursor_Delete(PRTDWARFCURSOR pCursor, int rcOther)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /* ... and a drop of poison. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (RT_FAILURE(pCursor->rc) && RT_SUCCESS(rcOther))
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Line Numbers.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Line Numbers.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Line Numbers.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Defines a file name.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pLnState The line number program state.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pszFilename The name of the file.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param idxInc The include path index.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_DefineFileName(PRTDWARFLINESTATE pLnState, const char *pszFilename, uint64_t idxInc)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Resize the array if necessary.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync void *pv = RTMemRealloc(pLnState->papszFileNames, sizeof(pLnState->papszFileNames[0]) * (iFileName + 2));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Add the file name.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync || (RT_C_IS_ALPHA(pszFilename[0]) && pszFilename[1] == ':') )
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->papszFileNames[iFileName] = RTStrDup(pszFilename);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->papszFileNames[iFileName] = RTPathJoinA(pLnState->papszIncPaths[idxInc], pszFilename);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Sanitize the name.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync int rc = rtDbgModDwarfStringToUtf8(pLnState->pDwarfMod, &pLnState->papszFileNames[iFileName]);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync Log((" File #%02u = '%s'\n", iFileName, pLnState->papszFileNames[iFileName]));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Adds a line to the table and resets parts of the state (DW_LNS_copy).
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pLnState The line number program state.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_AddLine(PRTDWARFLINESTATE pLnState)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync const char *pszFile = pLnState->Regs.iFile < pLnState->cFileNames
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync : "<bad file name index>";
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync int rc = rtDbgModDwarfLinkAddressToSegOffset(pLnState->pDwarfMod, pLnState->Regs.uAddress, &iSeg, &offSeg);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync Log2(("rtDwarfLine_AddLine: %x:%08llx (%#llx) %s(%d)\n", iSeg, offSeg, pLnState->Regs.uAddress, pszFile, pLnState->Regs.uLine));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = RTDbgModLineAdd(pLnState->pDwarfMod->hCnt, pszFile, pLnState->Regs.uLine, iSeg, offSeg, NULL);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /* Ignore address conflicts for now. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reset the program to the start-of-sequence state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic void rtDwarfLine_ResetState(PRTDWARFLINESTATE pLnState)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.fIsStatement = RT_BOOL(pLnState->Hdr.u8DefIsStmt);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Runs the line number program.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfLine_RunProgram(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LogFlow(("rtDwarfLine_RunProgram: cbUnitLeft=%zu\n", pCursor->cbUnitLeft));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t bOpCode = rtDwarfCursor_GetUByte(pCursor, DW_LNS_extended);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Special opcode.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t const bLogOpCode = bOpCode; NOREF(bLogOpCode);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int32_t const cLineDelta = bOpCode % pLnState->Hdr.u8LineRange + (int32_t)pLnState->Hdr.s8LineBase;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint64_t uTmp = bOpCode + pLnState->Regs.idxOp + bOpCode;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint64_t const cAddressDelta = uTmp / pLnState->Hdr.cMaxOpsPerInstr * pLnState->Hdr.cbMinInstr;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint64_t const cOpIndexDelta = uTmp % pLnState->Hdr.cMaxOpsPerInstr;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW Special Opcode %#04x: uLine + %d => %u; uAddress + %#llx => %#llx; idxOp + %#llx => %#llx\n",
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync bLogOpCode, cLineDelta, pLnState->Regs.uLine, cAddressDelta, pLnState->Regs.uAddress,
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Standard opcode.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64Adv = rtDwarfCursor_GetULeb128(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uAddress += (pLnState->Regs.idxOp + u64Adv) / pLnState->Hdr.cMaxOpsPerInstr
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.idxOp += (pLnState->Regs.idxOp + u64Adv) % pLnState->Hdr.cMaxOpsPerInstr;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int32_t cLineDelta = rtDwarfCursor_GetSLeb128AsS32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_advance_line: uLine + %d => %u\n", cLineDelta, pLnState->Regs.uLine));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.iFile = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_file: iFile=%u\n", pLnState->Regs.iFile));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uColumn = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fIsStatement = !pLnState->Regs.fIsStatement;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uAddress += (pLnState->Regs.idxOp + 255) / pLnState->Hdr.cMaxOpsPerInstr
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.idxOp += (pLnState->Regs.idxOp + 255) % pLnState->Hdr.cMaxOpsPerInstr;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uAddress += rtDwarfCursor_GetUHalf(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uIsa = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_isa %#x\n", pLnState->Regs.uIsa));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync unsigned cOpsToSkip = pLnState->Hdr.pacStdOperands[bOpCode - 1];
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("rtDwarfLine_RunProgram: Unknown standard opcode %#x, %#x operands\n", bOpCode, cOpsToSkip));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync while (cOpsToSkip-- > 0)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Extended opcode.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync /* The instruction has a length prefix. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t cbInstr = rtDwarfCursor_GetULeb128(pCursor, UINT64_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t const * const pbEndOfInstr = rtDwarfCursor_CalcPos(pCursor, cbInstr);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync /* Get the opcode and deal with it if we know it. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#if 0 /* No need for this, I think. */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync case 2: pLnState->Regs.uAddress = rtDwarfCursor_GetU16(pCursor, UINT16_MAX); break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync case 4: pLnState->Regs.uAddress = rtDwarfCursor_GetU32(pCursor, UINT32_MAX); break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync case 8: pLnState->Regs.uAddress = rtDwarfCursor_GetU64(pCursor, UINT64_MAX); break;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->Regs.uAddress = rtDwarfCursor_GetNativeUOff(pCursor, UINT64_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNE_set_address: %#llx\n", pLnState->Regs.uAddress));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync const char *pszFilename = rtDwarfCursor_GetSZ(pCursor, NULL);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint32_t idxInc = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNE_define_file: {%d}/%s\n", idxInc, pszFilename));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfLine_DefineFileName(pLnState, pszFilename, idxInc);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uDiscriminator = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNE_set_descriminator: %u\n", pLnState->Regs.uDiscriminator));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("rtDwarfLine_RunProgram: Unknown extended opcode %#x, length %#x\n", bOpCode, cbInstr));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync /* Advance the cursor to the end of the instruction . */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * Check the status before looping.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reads the include directories for a line number unit.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfLine_ReadFileNames(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int rc = rtDwarfLine_DefineFileName(pLnState, "/<bad-zero-file-name-entry>", 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync const char *psz = rtDwarfCursor_GetSZ(pCursor, NULL);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t idxInc = rtDwarfCursor_GetULeb128(pCursor, UINT64_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfLine_DefineFileName(pLnState, psz, idxInc);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reads the include directories for a line number unit.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfLine_ReadIncludePaths(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync const char *psz = ""; /* The zeroth is the unit dir. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync void *pv = RTMemRealloc(pLnState->papszIncPaths, sizeof(pLnState->papszIncPaths[0]) * (pLnState->cIncPaths + 2));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log((" Path #%02u = '%s'\n", pLnState->cIncPaths, psz));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->papszIncPaths[pLnState->cIncPaths] = psz;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Explodes the line number table for a compilation unit.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pThis The DWARF instance.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor to read the line number information
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_ExplodeUnit(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Parse the header.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.uVer = rtDwarfCursor_GetUHalf(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.offFirstOpcode = rtDwarfCursor_GetUOff(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t const * const pbFirstOpcode = rtDwarfCursor_CalcPos(pCursor, LnState.Hdr.offFirstOpcode);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.cbMinInstr = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.cMaxOpsPerInstr = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8DefIsStmt = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.s8LineBase = rtDwarfCursor_GetSByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8LineRange = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8OpcodeBase = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " uVer %d\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " offFirstOpcode %#llx\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " cbMinInstr %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " cMaxOpsPerInstr %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " u8DefIsStmt %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " s8LineBase %d\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " u8LineRange %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " u8OpcodeBase %u\n",
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.uVer, LnState.Hdr.offFirstOpcode, LnState.Hdr.cbMinInstr, LnState.Hdr.cMaxOpsPerInstr,
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8DefIsStmt, LnState.Hdr.s8LineBase, LnState.Hdr.u8LineRange, LnState.Hdr.u8OpcodeBase));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync for (uint8_t iStdOpcode = 1; iStdOpcode < LnState.Hdr.u8OpcodeBase; iStdOpcode++)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfLine_ReadIncludePaths(&LnState, pCursor);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Run the program....
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfCursor_AdvanceToPos(pCursor, pbFirstOpcode);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Clean up.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync while (i-- > 0)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync Assert(rtDwarfCursor_IsAtEndOfUnit(pCursor) || RT_FAILURE(rc));
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * Explodes the line number table.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * The line numbers are insered into the debug info container.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @returns IPRT status code
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @param pThis The DWARF instance.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_ExplodeAll(PRTDBGMODDWARF pThis)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync if (!pThis->aSections[krtDbgModDwarfSect_line].fPresent)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync int rc = rtDwarfCursor_Init(&Cursor, pThis, krtDbgModDwarfSect_line);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF Abbreviations.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF Abbreviations.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF Abbreviations.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Deals with a cache miss in rtDwarfAbbrev_Lookup.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns Pointer to abbreviation cache entry (read only). May be rendered
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * invalid by subsequent calls to this function.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param uCode The abbreviation code to lookup.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic PCRTDWARFABBREV rtDwarfAbbrev_LookupMiss(PRTDBGMODDWARF pThis, uint32_t uCode)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * There is no entry with code zero.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Resize the cache array if the code is considered cachable.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync void *pv = RTMemRealloc(pThis->paCachedAbbrevs, sizeof(pThis->paCachedAbbrevs[0]) * cNew);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Walk the abbreviations till we find the desired code.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync int rc = rtDwarfCursor_InitWithOffset(&Cursor, pThis, krtDbgModDwarfSect_abbrev, pThis->offCachedAbbrev);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Search for the entry and fill the cache while doing so.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Read the 'header'. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurCode = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurTag = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint8_t const uChildren = rtDwarfCursor_GetU8(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Cache it? */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PRTDWARFABBREV pEntry = &pThis->paCachedAbbrevs[uCurCode - 1];
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->paCachedAbbrevs[pThis->cCachedAbbrevs].fFilled = false;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pEntry->offSpec = rtDwarfCursor_CalcSectOffsetU32(&Cursor);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Skip the specification. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Done? (Maximize cache filling.) */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Search for the entry with the desired code, no cache filling.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Read the 'header'. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurCode = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurTag = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint8_t const uChildren = rtDwarfCursor_GetU8(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Do we have a match? */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pRet->offSpec = rtDwarfCursor_CalcSectOffsetU32(&Cursor);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Skip the specification. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Looks up an abbreviation.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns Pointer to abbreviation cache entry (read only). May be rendered
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * invalid by subsequent calls to this function.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param uCode The abbreviation code to lookup.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic PCRTDWARFABBREV rtDwarfAbbrev_Lookup(PRTDBGMODDWARF pThis, uint32_t uCode)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Sets the abbreviation offset of the current unit.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * This will flush the cached abbreviation entries if the offset differs from
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * the previous unit.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param offAbbrev The offset into the abbreviation section.
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic void rtDwarfAbbrev_SetUnitOffset(PRTDBGMODDWARF pThis, uint32_t offAbbrev)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack (used by the debug_info parser).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack (used by the debug_info parser).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack (used by the debug_info parser).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack entry.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The abbreviation code. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The tag. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The offset into the debug_info section of the data. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The associated name. (Points into some dwarf section.) */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync const char *pszName;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Pointer to a DIE stack entry. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef RTDWARFDIESTACKENTRY *PRTDWARFDIESTACKENTRY;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The number of items on the stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The number of stack entries we've allocated. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** Pointer to the stack entries. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Pointer to a DIE stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Pointer to a const DIE stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfDieStack_SetName(PRTDWARFDIESTACK pStack, const char *pszName)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (i == 0)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfDieStack_Push(PRTDWARFDIESTACK pStack, uint32_t uAbbrCode, uint16_t uTag, uint32_t offData)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync size_t cNewSize = pStack->cAlloced ? pStack->cAlloced * 2 : 1 /*16*/;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync void *pv = RTMemRealloc(pStack->paEntries, sizeof(pStack->paEntries[0]) * cNewSize);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfDieStack_Pop(PRTDWARFDIESTACK pStack)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic void rtDwarfDieStack_Init(PRTDWARFDIESTACK pStack)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic void rtDwarfDieStack_Delete(PRTDWARFDIESTACK pStack)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF debug_info parser
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF debug_info parser
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF debug_info parser
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Parse a DIE.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @returns IPRT status code.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pThis The DWARF instance.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pCursor The debug_info cursor.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pAbbrev The abbreviation entry.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pAbbrevCursor The abbreviation cursor.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pStack The DIE stack.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfInfo_ParseDie(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor,
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PCRTDWARFABBREV pAbbrev, PRTDWARFCURSOR pAbbrevCursor,
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic int rtDwarfInfo_LoadUnit(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Read the compilation unit header.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint16_t const uVer = rtDwarfCursor_GetUHalf(pCursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint64_t const offAbbrev = rtDwarfCursor_GetUOff(pCursor, UINT64_MAX);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint8_t const cbNativeAddr = rtDwarfCursor_GetU8(pCursor, UINT8_MAX);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Set up the abbreviation cache and store the native address size in the cursor.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * We want a DIE stack as well.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Parse DIEs.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t uAbbrCode = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /* End of siblings, pop the stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Look up the abbreviation.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PCRTDWARFABBREV pAbbrev = rtDwarfAbbrev_Lookup(pThis, uAbbrCode);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * If this DIE has children, push it onto the stack.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfDieStack_Push(&Stack, uAbbrCode, pAbbrev->uTag, rtDwarfCursor_CalcSectOffsetU32(pCursor));
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Parse it.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfCursor_InitWithOffset(&AbbrevCursor, pThis, krtDbgModDwarfSect_abbrev, pAbbrev->offSpec);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfInfo_ParseDie(pThis, pCursor, pAbbrev, &AbbrevCursor, &Stack);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Extracts the symbols.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * The symbols are insered into the debug info container.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns IPRT status code
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic int rtDwarfInfo_LoadAll(PRTDBGMODDWARF pThis)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync int rc = rtDwarfCursor_Init(&Cursor, pThis, krtDbgModDwarfSect_info);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Debug module implementation.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Debug module implementation.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Debug module implementation.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByAddr} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineByAddr(pThis->hCnt, iSeg, off, poffDisp, pLineInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByOrdinal} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_LineByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineByOrdinal(pThis->hCnt, iOrdinal, pLineInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineCount} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(uint32_t) rtDbgModDwarf_LineCount(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineAdd} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_LineAdd(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineAdd(pThis->hCnt, pszFile, uLineNo, iSeg, off, piOrdinal);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByAddr} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolByAddr(pThis->hCnt, iSeg, off, poffDisp, pSymInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByName} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolByName(pThis->hCnt, pszSymbol/*, cchSymbol*/, pSymInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByOrdinal} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolByOrdinal(pThis->hCnt, iOrdinal, pSymInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolCount} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(uint32_t) rtDbgModDwarf_SymbolCount(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolAdd} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTDBGSEGIDX iSeg, RTUINTPTR off, RTUINTPTR cb, uint32_t fFlags,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolAdd(pThis->hCnt, pszSymbol, iSeg, off, cb, fFlags, piOrdinal);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentByIndex} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SegmentByIndex(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSegmentByIndex(pThis->hCnt, iSeg, pSegInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentCount} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(RTDBGSEGIDX) rtDbgModDwarf_SegmentCount(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentAdd} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SegmentAdd(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSegmentAdd(pThis->hCnt, uRva, cb, pszName, fFlags, piSeg);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnImageSize} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(RTUINTPTR) rtDbgModDwarf_ImageSize(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnRvaToSegOff} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(RTDBGSEGIDX) rtDbgModDwarf_RvaToSegOff(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModRvaToSegOff(pThis->hCnt, uRva, poffSeg);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnClose} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_Close(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync for (unsigned iSect = 0; iSect < RT_ELEMENTS(pThis->aSections); iSect++)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[iSect].cb, &pThis->aSections[iSect].pv);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @callback_method_impl{FNRTLDRENUMDBG} */
5b0a093ca572a855886faa6747ad46df859dd041vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarfEnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync uint16_t iMajorVer, uint16_t iMinorVer, const char *pszPartNm,
d3dea25ec07f6546715fe3af943ea863294b392evboxsync RTFOFF offFile, RTLDRADDR LinkAddress, RTLDRADDR cb,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Skip stuff we can't handle.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Must have a part name starting with debug_ and possibly prefixed by dots
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * or underscores.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync if (!strncmp(pszPartNm, ".debug_", sizeof(".debug_") - 1)) /* ELF */
d3dea25ec07f6546715fe3af943ea863294b392evboxsync else if (!strncmp(pszPartNm, "__debug_", sizeof("__debug_") - 1)) /* Mach-O */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync AssertMsgFailedReturn(("%s\n", pszPartNm), VINF_SUCCESS /*ignore*/);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Figure out which part we're talking about.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (0) { /* dummy */ }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define ELSE_IF_STRCMP_SET(a_Name) else if (!strcmp(pszPartNm, #a_Name)) enmSect = krtDbgModDwarfSect_ ## a_Name
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Record the section.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync AssertMsgReturn(!pThis->aSections[enmSect].fPresent, ("duplicate %s\n", pszPartNm), VINF_SUCCESS /*ignore*/);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnTryOpen} */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_TryOpen(PRTDBGMODINT pMod)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * DWARF is only supported when part of an image.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Enumerate the debug info in the module, looking for DWARF bits.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)RTMemAllocZ(sizeof(*pThis));
5b0a093ca572a855886faa6747ad46df859dd041vboxsync int rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, rtDbgModDwarfEnumCallback, pThis);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (pThis->aSections[krtDbgModDwarfSect_info].fPresent)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Extract / explode the data we want (symbols and line numbers)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * storing them in a container module.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync rc = RTDbgModCreate(&pThis->hCnt, pMod->pszName, 0 /*cbSeg*/, 0 /*fFlags*/);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Free the cached abbreviations and unload all sections.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->cCachedAbbrevs = pThis->cCachedAbbrevsAlloced = 0;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync for (unsigned iSect = 0; iSect < RT_ELEMENTS(pThis->aSections); iSect++)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[iSect].cb,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /* bail out. */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** Virtual function table for the DWARF debug info reader. */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsyncDECL_HIDDEN_CONST(RTDBGMODVTDBG) const g_rtDbgModVtDbgDwarf =
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSegmentCount = */ rtDbgModDwarf_SegmentCount,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSegmentByIndex = */ rtDbgModDwarf_SegmentByIndex,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolByOrdinal = */ rtDbgModDwarf_SymbolByOrdinal,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolByName = */ rtDbgModDwarf_SymbolByName,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolByAddr = */ rtDbgModDwarf_SymbolByAddr,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnLineByOrdinal = */ rtDbgModDwarf_LineByOrdinal,