dbgmod.cpp revision 6805ae4b939ad0646ed7d4a52696b828e6554bf5
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync/* $Id$ */
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync/** @file
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * IPRT - Debug Module Interpreter.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync */
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync/*
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Copyright (C) 2009-2012 Oracle Corporation
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync *
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * available from http://www.virtualbox.org. This file is free software;
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * General Public License (GPL) as published by the Free Software
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync *
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * The contents of this file may alternatively be used under the terms
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * of the Common Development and Distribution License Version 1.0
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * CDDL are applicable instead of those of the GPL.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync *
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * You may elect to license modified versions of this file under the
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * terms and conditions of either the GPL or the CDDL or both.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync */
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync/*******************************************************************************
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync* Header Files *
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync*******************************************************************************/
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync#define LOG_GROUP RTLOGGROUP_DBG
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync#include <iprt/dbg.h>
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync#include "internal/iprt.h"
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync#include <iprt/alloca.h>
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync#include <iprt/asm.h>
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync#include <iprt/assert.h>
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync#include <iprt/avl.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/err.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/initterm.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/log.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/mem.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/once.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/param.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/path.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/semaphore.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/strcache.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include <iprt/string.h>
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include "internal/dbgmod.h"
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#include "internal/magics.h"
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/*******************************************************************************
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync* Structures and Typedefs *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync*******************************************************************************/
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/** Debug info interpreter registration record. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsynctypedef struct RTDBGMODREGDBG
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync{
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /** Pointer to the next record. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync struct RTDBGMODREGDBG *pNext;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /** Pointer to the virtual function table for the interpreter. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PCRTDBGMODVTDBG pVt;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /** Usage counter. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync uint32_t volatile cUsers;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync} RTDBGMODREGDBG;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsynctypedef RTDBGMODREGDBG *PRTDBGMODREGDBG;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/** Image interpreter registration record. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsynctypedef struct RTDBGMODREGIMG
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync{
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /** Pointer to the next record. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync struct RTDBGMODREGIMG *pNext;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /** Pointer to the virtual function table for the interpreter. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PCRTDBGMODVTIMG pVt;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /** Usage counter. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync uint32_t volatile cUsers;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync} RTDBGMODREGIMG;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsynctypedef RTDBGMODREGIMG *PRTDBGMODREGIMG;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/*******************************************************************************
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync* Defined Constants And Macros *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync*******************************************************************************/
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/** Validates a debug module handle and returns rc if not valid. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#define RTDBGMOD_VALID_RETURN_RC(pDbgMod, rc) \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync do { \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertPtrReturn((pDbgMod), (rc)); \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertReturn((pDbgMod)->u32Magic == RTDBGMOD_MAGIC, (rc)); \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertReturn((pDbgMod)->cRefs > 0, (rc)); \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync } while (0)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/** Locks the debug module. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#define RTDBGMOD_LOCK(pDbgMod) \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync do { \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync int rcLock = RTCritSectEnter(&(pDbgMod)->CritSect); \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertRC(rcLock); \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync } while (0)
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync/** Unlocks the debug module. */
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync#define RTDBGMOD_UNLOCK(pDbgMod) \
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync do { \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync int rcLock = RTCritSectLeave(&(pDbgMod)->CritSect); \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertRC(rcLock); \
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync } while (0)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync/*******************************************************************************
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync* Global Variables *
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync*******************************************************************************/
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync/** Init once object for lazy registration of the built-in image and debug
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * info interpreters. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic RTONCE g_rtDbgModOnce = RTONCE_INITIALIZER;
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync/** Read/Write semaphore protecting the list of registered interpreters. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic RTSEMRW g_hDbgModRWSem = NIL_RTSEMRW;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/** List of registered image interpreters. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic PRTDBGMODREGIMG g_pImgHead;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/** List of registered debug infor interpreters. */
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsyncstatic PRTDBGMODREGDBG g_pDbgHead;
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync/** String cache for the debug info interpreters.
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync * RTSTRCACHE is thread safe. */
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsyncDECLHIDDEN(RTSTRCACHE) g_hDbgModStrCache = NIL_RTSTRCACHE;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/**
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Cleanup debug info interpreter globals.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @param enmReason The cause of the termination.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @param iStatus The meaning of this depends on enmReason.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @param pvUser User argument, unused.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic DECLCALLBACK(void) rtDbgModTermCallback(RTTERMREASON enmReason, int32_t iStatus, void *pvUser)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync{
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync NOREF(iStatus); NOREF(pvUser);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (enmReason == RTTERMREASON_UNLOAD)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync {
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync RTSemRWDestroy(g_hDbgModRWSem);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync g_hDbgModRWSem = NIL_RTSEMRW;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync RTStrCacheDestroy(g_hDbgModStrCache);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync g_hDbgModStrCache = NIL_RTSTRCACHE;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PRTDBGMODREGDBG pDbg = g_pDbgHead;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync g_pDbgHead = NULL;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync while (pDbg)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync {
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PRTDBGMODREGDBG pNext = pDbg->pNext;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertMsg(pDbg->cUsers == 0, ("%#x %s\n", pDbg->cUsers, pDbg->pVt->pszName));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync RTMemFree(pDbg);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pDbg = pNext;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync }
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PRTDBGMODREGIMG pImg = g_pImgHead;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync g_pImgHead = NULL;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync while (pImg)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync {
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PRTDBGMODREGIMG pNext = pImg->pNext;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertMsg(pImg->cUsers == 0, ("%#x %s\n", pImg->cUsers, pImg->pVt->pszName));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync RTMemFree(pImg);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pImg = pNext;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync }
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync }
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync}
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/**
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Internal worker for register a debug interpreter.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Called while owning the write lock or when locking isn't required.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @returns IPRT status code.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @retval VERR_NO_MEMORY
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @retval VERR_ALREADY_EXISTS
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @param pVt The virtual function table of the debug
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * module interpreter.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic int rtDbgModDebugInterpreterRegister(PCRTDBGMODVTDBG pVt)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync{
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /*
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Search or duplicate registration.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PRTDBGMODREGDBG pPrev = NULL;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync for (PRTDBGMODREGDBG pCur = g_pDbgHead; pCur; pCur = pCur->pNext)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync {
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (pCur->pVt == pVt)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync return VERR_ALREADY_EXISTS;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (!strcmp(pCur->pVt->pszName, pVt->pszName))
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync return VERR_ALREADY_EXISTS;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pPrev = pCur;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync }
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /*
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Create a new record and add it to the end of the list.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PRTDBGMODREGDBG pReg = (PRTDBGMODREGDBG)RTMemAlloc(sizeof(*pReg));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (!pReg)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync return VERR_NO_MEMORY;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pReg->pVt = pVt;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pReg->cUsers = 0;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pReg->pNext = NULL;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (pPrev)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pPrev->pNext = pReg;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync else
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync g_pDbgHead = pReg;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync return VINF_SUCCESS;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync}
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/**
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * Internal worker for register a image interpreter.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync *
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * Called while owning the write lock or when locking isn't required.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync *
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @returns IPRT status code.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @retval VERR_NO_MEMORY
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @retval VERR_ALREADY_EXISTS
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync *
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @param pVt The virtual function table of the image
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * interpreter.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync */
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsyncstatic int rtDbgModImageInterpreterRegister(PCRTDBGMODVTIMG pVt)
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync{
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync /*
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * Search or duplicate registration.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync */
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync PRTDBGMODREGIMG pPrev = NULL;
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync for (PRTDBGMODREGIMG pCur = g_pImgHead; pCur; pCur = pCur->pNext)
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync {
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync if (pCur->pVt == pVt)
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync return VERR_ALREADY_EXISTS;
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync if (!strcmp(pCur->pVt->pszName, pVt->pszName))
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync return VERR_ALREADY_EXISTS;
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync pPrev = pCur;
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync }
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync /*
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * Create a new record and add it to the end of the list.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PRTDBGMODREGIMG pReg = (PRTDBGMODREGIMG)RTMemAlloc(sizeof(*pReg));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (!pReg)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync return VERR_NO_MEMORY;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pReg->pVt = pVt;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pReg->cUsers = 0;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pReg->pNext = NULL;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (pPrev)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync pPrev->pNext = pReg;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync else
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync g_pImgHead = pReg;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync return VINF_SUCCESS;
4d45842309f5db66367ef1c4a701fc37619b0ec0vboxsync}
4d45842309f5db66367ef1c4a701fc37619b0ec0vboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/**
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Do-once callback that initializes the read/write semaphore and registers
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * the built-in interpreters.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @returns IPRT status code.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @param pvUser NULL.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic DECLCALLBACK(int) rtDbgModInitOnce(void *pvUser)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync{
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync NOREF(pvUser);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /*
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Create the semaphore and string cache.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync int rc = RTSemRWCreate(&g_hDbgModRWSem);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertRCReturn(rc, rc);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync rc = RTStrCacheCreate(&g_hDbgModStrCache, "RTDBGMOD");
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (RT_SUCCESS(rc))
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync {
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /*
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Register the interpreters.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgNm);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (RT_SUCCESS(rc))
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgDwarf);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (RT_SUCCESS(rc))
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgCodeView);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#ifdef RT_OS_WINDOWS
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync if (RT_SUCCESS(rc))
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgDbgHelp);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync#endif
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync if (RT_SUCCESS(rc))
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync rc = rtDbgModImageInterpreterRegister(&g_rtDbgModVtImgLdr);
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync if (RT_SUCCESS(rc))
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync {
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync /*
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Finally, register the IPRT cleanup callback.
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync */
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync rc = RTTermRegisterCallback(rtDbgModTermCallback, NULL);
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync if (RT_SUCCESS(rc))
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync return VINF_SUCCESS;
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync /* bail out: use the termination callback. */
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync }
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync }
510dd1bd989d25f95680fc2a3b51bf11854bc6a4vboxsync else
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync g_hDbgModStrCache = NIL_RTSTRCACHE;
ac1200e63b58a0451085add197084e5a4a1bb4cavboxsync rtDbgModTermCallback(RTTERMREASON_UNLOAD, 0, NULL);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync return rc;
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync}
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync/**
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Performs lazy init of our global variables.
d960e43fb3727c884b5f7eca3c920c9549839881vboxsync * @returns IPRT status code.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync */
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsyncDECLINLINE(int) rtDbgModLazyInit(void)
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync{
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync return RTOnce(&g_rtDbgModOnce, rtDbgModInitOnce, NULL);
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync}
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsyncRTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags)
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync{
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync /*
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Input validation and lazy initialization.
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync */
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync *phDbgMod = NIL_RTDBGMOD;
d960e43fb3727c884b5f7eca3c920c9549839881vboxsync AssertPtrReturn(pszName, VERR_INVALID_POINTER);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync AssertReturn(*pszName, VERR_INVALID_PARAMETER);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync
ac1200e63b58a0451085add197084e5a4a1bb4cavboxsync int rc = rtDbgModLazyInit();
ac1200e63b58a0451085add197084e5a4a1bb4cavboxsync if (RT_FAILURE(rc))
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync return rc;
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
510dd1bd989d25f95680fc2a3b51bf11854bc6a4vboxsync /*
510dd1bd989d25f95680fc2a3b51bf11854bc6a4vboxsync * Allocate a new module instance.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync */
44918d7b9fb45f0d3e2ba56bf6d2cede9a2ae566vboxsync PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
44918d7b9fb45f0d3e2ba56bf6d2cede9a2ae566vboxsync if (!pDbgMod)
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync return VERR_NO_MEMORY;
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync pDbgMod->u32Magic = RTDBGMOD_MAGIC;
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync pDbgMod->cRefs = 1;
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync rc = RTCritSectInit(&pDbgMod->CritSect);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync if (RT_SUCCESS(rc))
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync {
d960e43fb3727c884b5f7eca3c920c9549839881vboxsync pDbgMod->pszImgFileSpecified = RTStrCacheEnter(g_hDbgModStrCache, pszName);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, RTPathFilenameEx(pszName, RTPATH_STR_F_STYLE_DOS));
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync if (pDbgMod->pszName)
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync {
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync rc = rtDbgModContainerCreate(pDbgMod, cbSeg);
510dd1bd989d25f95680fc2a3b51bf11854bc6a4vboxsync if (RT_SUCCESS(rc))
510dd1bd989d25f95680fc2a3b51bf11854bc6a4vboxsync {
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync *phDbgMod = pDbgMod;
44918d7b9fb45f0d3e2ba56bf6d2cede9a2ae566vboxsync return rc;
44918d7b9fb45f0d3e2ba56bf6d2cede9a2ae566vboxsync }
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync }
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync RTCritSectDelete(&pDbgMod->CritSect);
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync }
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync RTMemFree(pDbgMod);
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync return rc;
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync}
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsyncRT_EXPORT_SYMBOL(RTDbgModCreate);
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsyncRTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync RTUINTPTR uSubtrahend, RTDBGCFG hDbgCfg)
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync{
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync /*
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync * Input validation and lazy initialization.
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync */
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync *phDbgMod = NIL_RTDBGMOD;
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync AssertReturn(*pszFilename, VERR_INVALID_PARAMETER);
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync AssertReturn(uSubtrahend == 0, VERR_NOT_IMPLEMENTED); /** @todo implement uSubtrahend. */
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync int rc = rtDbgModLazyInit();
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync if (RT_FAILURE(rc))
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync return rc;
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync if (!pszName)
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync /*
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Allocate a new module instance.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync */
44918d7b9fb45f0d3e2ba56bf6d2cede9a2ae566vboxsync PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync if (!pDbgMod)
return VERR_NO_MEMORY;
pDbgMod->u32Magic = RTDBGMOD_MAGIC;
pDbgMod->cRefs = 1;
rc = RTCritSectInit(&pDbgMod->CritSect);
if (RT_SUCCESS(rc))
{
pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, pszName);
if (pDbgMod->pszName)
{
pDbgMod->pszDbgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
if (pDbgMod->pszDbgFile)
{
/*
* Try the map file readers.
*/
rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
if (RT_SUCCESS(rc))
{
rc = VERR_DBG_NO_MATCHING_INTERPRETER;
for (PRTDBGMODREGDBG pCur = g_pDbgHead; pCur; pCur = pCur->pNext)
{
if (pCur->pVt->fSupports & RT_DBGTYPE_MAP)
{
pDbgMod->pDbgVt = pCur->pVt;
pDbgMod->pvDbgPriv = NULL;
rc = pCur->pVt->pfnTryOpen(pDbgMod, RTLDRARCH_WHATEVER);
if (RT_SUCCESS(rc))
{
ASMAtomicIncU32(&pCur->cUsers);
RTSemRWReleaseRead(g_hDbgModRWSem);
*phDbgMod = pDbgMod;
return rc;
}
}
}
/* bail out */
RTSemRWReleaseRead(g_hDbgModRWSem);
}
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
}
else
rc = VERR_NO_STR_MEMORY;
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
}
else
rc = VERR_NO_STR_MEMORY;
RTCritSectDelete(&pDbgMod->CritSect);
}
RTMemFree(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModCreateFromMap);
/*
*
* E x e c u t a b l e I m a g e F i l e s
* E x e c u t a b l e I m a g e F i l e s
* E x e c u t a b l e I m a g e F i l e s
*
*/
/**
* Opens debug information for an image.
*
* @returns IPRT status code
* @param pDbgMod The debug module structure.
*
* @note This will generally not look for debug info stored in external
* files. rtDbgModFromPeImageExtDbgInfoCallback can help with that.
*/
static int rtDbgModOpenDebugInfoInsideImage(PRTDBGMODINT pDbgMod)
{
AssertReturn(!pDbgMod->pDbgVt, VERR_DBG_MOD_IPE);
AssertReturn(pDbgMod->pImgVt, VERR_DBG_MOD_IPE);
int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
if (RT_SUCCESS(rc))
{
for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
{
pDbgMod->pDbgVt = pDbg->pVt;
pDbgMod->pvDbgPriv = NULL;
rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod));
if (RT_SUCCESS(rc))
{
/*
* That's it!
*/
ASMAtomicIncU32(&pDbg->cUsers);
RTSemRWReleaseRead(g_hDbgModRWSem);
return VINF_SUCCESS;
}
pDbgMod->pDbgVt = NULL;
Assert(pDbgMod->pvDbgPriv == NULL);
}
RTSemRWReleaseRead(g_hDbgModRWSem);
}
return VERR_DBG_NO_MATCHING_INTERPRETER;
}
/** @callback_method_impl{FNRTDBGCFGOPEN} */
static DECLCALLBACK(int) rtDbgModExtDbgInfoOpenCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
{
PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1;
PCRTLDRDBGINFO pDbgInfo = (PCRTLDRDBGINFO)pvUser2;
NOREF(pDbgInfo); /** @todo consider a more direct search for a interpreter. */
Assert(!pDbgMod->pDbgVt);
Assert(!pDbgMod->pvDbgPriv);
Assert(!pDbgMod->pszDbgFile);
Assert(pDbgMod->pImgVt);
/*
* Set the debug file name and try possible interpreters.
*/
pDbgMod->pszDbgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
if (RT_SUCCESS(rc))
{
for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
{
pDbgMod->pDbgVt = pDbg->pVt;
pDbgMod->pvDbgPriv = NULL;
rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod));
if (RT_SUCCESS(rc))
{
/*
* Got it!
*/
ASMAtomicIncU32(&pDbg->cUsers);
RTSemRWReleaseRead(g_hDbgModRWSem);
return VINF_CALLBACK_RETURN;
}
pDbgMod->pDbgVt = NULL;
Assert(pDbgMod->pvDbgPriv == NULL);
}
RTSemRWReleaseRead(g_hDbgModRWSem);
}
/* No joy. */
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
pDbgMod->pszDbgFile = NULL;
return rc;
}
/**
* Argument package used by rtDbgModOpenDebugInfoExternalToImage.
*/
typedef struct RTDBGMODOPENDIETI
{
PRTDBGMODINT pDbgMod;
RTDBGCFG hDbgCfg;
} RTDBGMODOPENDIETI;
/** @callback_method_impl{FNRTLDRENUMDBG} */
static DECLCALLBACK(int)
rtDbgModOpenDebugInfoExternalToImageCallback(RTLDRMOD hLdrMod, PCRTLDRDBGINFO pDbgInfo, void *pvUser)
{
RTDBGMODOPENDIETI *pArgs = (RTDBGMODOPENDIETI *)pvUser;
Assert(pDbgInfo->enmType > RTLDRDBGINFOTYPE_INVALID && pDbgInfo->enmType < RTLDRDBGINFOTYPE_END);
const char *pszExtFile = pDbgInfo->pszExtFile;
if (!pszExtFile)
{
/*
* If a external debug type comes without a file name, calculate a
* likely debug filename for it. (Hack for NT4 drivers.)
*/
const char *pszExt = NULL;
if (pDbgInfo->enmType == RTLDRDBGINFOTYPE_CODEVIEW_DBG)
pszExt = ".dbg";
else if ( pDbgInfo->enmType == RTLDRDBGINFOTYPE_CODEVIEW_PDB20
|| pDbgInfo->enmType == RTLDRDBGINFOTYPE_CODEVIEW_PDB70)
pszExt = ".pdb";
if (pszExt && pArgs->pDbgMod->pszName)
{
size_t cchName = strlen(pArgs->pDbgMod->pszName);
char *psz = (char *)alloca(cchName + strlen(pszExt) + 1);
if (psz)
{
memcpy(psz, pArgs->pDbgMod->pszName, cchName + 1);
RTPathStripSuffix(psz);
pszExtFile = strcat(psz, pszExt);
}
}
if (!pszExtFile)
{
Log2(("rtDbgModOpenDebugInfoExternalToImageCallback: enmType=%d\n", pDbgInfo->enmType));
return VINF_SUCCESS;
}
}
/*
* Switch on type and call the appropriate search function.
*/
int rc;
switch (pDbgInfo->enmType)
{
case RTLDRDBGINFOTYPE_CODEVIEW_PDB70:
rc = RTDbgCfgOpenPdb70(pArgs->hDbgCfg, pszExtFile,
&pDbgInfo->u.Pdb70.Uuid,
pDbgInfo->u.Pdb70.uAge,
rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
break;
case RTLDRDBGINFOTYPE_CODEVIEW_PDB20:
rc = RTDbgCfgOpenPdb20(pArgs->hDbgCfg, pszExtFile,
pDbgInfo->u.Pdb20.cbImage,
pDbgInfo->u.Pdb20.uTimestamp,
pDbgInfo->u.Pdb20.uAge,
rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
break;
case RTLDRDBGINFOTYPE_CODEVIEW_DBG:
rc = RTDbgCfgOpenDbg(pArgs->hDbgCfg, pszExtFile,
pDbgInfo->u.Dbg.cbImage,
pDbgInfo->u.Dbg.uTimestamp,
rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
break;
case RTLDRDBGINFOTYPE_DWARF_DWO:
rc = RTDbgCfgOpenDwo(pArgs->hDbgCfg, pszExtFile,
pDbgInfo->u.Dwo.uCrc32,
rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
break;
default:
Log(("rtDbgModOpenDebugInfoExternalToImageCallback: Don't know how to handle enmType=%d and pszFileExt=%s\n",
pDbgInfo->enmType, pszExtFile));
return VERR_DBG_TODO;
}
if (RT_SUCCESS(rc))
{
LogFlow(("RTDbgMod: Successfully opened external debug info '%s' for '%s'\n",
pArgs->pDbgMod->pszDbgFile, pArgs->pDbgMod->pszImgFile));
return VINF_CALLBACK_RETURN;
}
Log(("rtDbgModOpenDebugInfoExternalToImageCallback: '%s' (enmType=%d) for '%s' -> %Rrc\n",
pszExtFile, pDbgInfo->enmType, pArgs->pDbgMod->pszImgFile, rc));
return rc;
}
/**
* Opens debug info listed in the image that is stored in a separate file.
*
* @returns IPRT status code
* @param pDbgMod The debug module.
* @param hDbgCfg The debug config. Can be NIL.
*/
static int rtDbgModOpenDebugInfoExternalToImage(PRTDBGMODINT pDbgMod, RTDBGCFG hDbgCfg)
{
Assert(!pDbgMod->pDbgVt);
RTDBGMODOPENDIETI Args;
Args.pDbgMod = pDbgMod;
Args.hDbgCfg = hDbgCfg;
int rc = pDbgMod->pImgVt->pfnEnumDbgInfo(pDbgMod, rtDbgModOpenDebugInfoExternalToImageCallback, &Args);
if (RT_SUCCESS(rc) && pDbgMod->pDbgVt)
return VINF_SUCCESS;
LogFlow(("rtDbgModOpenDebugInfoExternalToImage: rc=%Rrc\n", rc));
return VERR_NOT_FOUND;
}
/** @callback_method_impl{FNRTDBGCFGOPEN} */
static DECLCALLBACK(int) rtDbgModExtDbgInfoOpenCallback2(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
{
PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1;
NOREF(pvUser2); /** @todo image matching string or smth. */
Assert(!pDbgMod->pDbgVt);
Assert(!pDbgMod->pvDbgPriv);
Assert(!pDbgMod->pszDbgFile);
Assert(pDbgMod->pImgVt);
/*
* Set the debug file name and try possible interpreters.
*/
pDbgMod->pszDbgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
if (RT_SUCCESS(rc))
{
for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
{
pDbgMod->pDbgVt = pDbg->pVt;
pDbgMod->pvDbgPriv = NULL;
rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod));
if (RT_SUCCESS(rc))
{
/*
* Got it!
*/
ASMAtomicIncU32(&pDbg->cUsers);
RTSemRWReleaseRead(g_hDbgModRWSem);
return VINF_CALLBACK_RETURN;
}
pDbgMod->pDbgVt = NULL;
Assert(pDbgMod->pvDbgPriv == NULL);
}
}
/* No joy. */
RTSemRWReleaseRead(g_hDbgModRWSem);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
pDbgMod->pszDbgFile = NULL;
return rc;
}
/**
* Opens external debug info that is not listed in the image.
*
* @returns IPRT status code
* @param pDbgMod The debug module.
* @param hDbgCfg The debug config. Can be NIL.
*/
static int rtDbgModOpenDebugInfoExternalToImage2(PRTDBGMODINT pDbgMod, RTDBGCFG hDbgCfg)
{
int rc;
Assert(!pDbgMod->pDbgVt);
Assert(pDbgMod->pImgVt);
/*
* Figure out what to search for based on the image format.
*/
const char *pszzExts = NULL;
RTLDRFMT enmFmt = pDbgMod->pImgVt->pfnGetFormat(pDbgMod);
switch (enmFmt)
{
case RTLDRFMT_MACHO:
{
rc = RTDbgCfgOpenDsymBundle(hDbgCfg, pDbgMod->pszImgFile, NULL /**@todo pUuid*/,
rtDbgModExtDbgInfoOpenCallback2, pDbgMod, NULL /*pvUser2*/);
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
break;
}
#if 0 /* Will be links in the image if these apply. .map readers for PE or ELF we don't have. */
case RTLDRFMT_ELF:
pszzExts = ".debug\0.dwo\0";
break;
case RTLDRFMT_PE:
pszzExts = ".map\0";
break;
#endif
#if 0 /* Haven't implemented .sym or .map file readers for OS/2 yet. */
case RTLDRFMT_LX:
pszzExts = ".sym\0.map\0";
break;
#endif
default:
rc = VERR_NOT_IMPLEMENTED;
break;
}
NOREF(pszzExts);
#if 0 /* Later */
if (pszzExts)
{
}
#endif
LogFlow(("rtDbgModOpenDebugInfoExternalToImage2: rc=%Rrc\n", rc));
return VERR_NOT_FOUND;
}
RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
RTLDRARCH enmArch, RTDBGCFG hDbgCfg)
{
/*
* Input validation and lazy initialization.
*/
AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
*phDbgMod = NIL_RTDBGMOD;
AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
AssertReturn(*pszFilename, VERR_INVALID_PARAMETER);
AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
AssertReturn(enmArch > RTLDRARCH_INVALID && enmArch < RTLDRARCH_END, VERR_INVALID_PARAMETER);
int rc = rtDbgModLazyInit();
if (RT_FAILURE(rc))
return rc;
if (!pszName)
pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS);
/*
* Allocate a new module instance.
*/
PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
if (!pDbgMod)
return VERR_NO_MEMORY;
pDbgMod->u32Magic = RTDBGMOD_MAGIC;
pDbgMod->cRefs = 1;
rc = RTCritSectInit(&pDbgMod->CritSect);
if (RT_SUCCESS(rc))
{
pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, pszName);
if (pDbgMod->pszName)
{
pDbgMod->pszImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
if (pDbgMod->pszImgFile)
{
RTStrCacheRetain(pDbgMod->pszImgFile);
pDbgMod->pszImgFileSpecified = pDbgMod->pszImgFile;
/*
* Find an image reader which groks the file.
*/
rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
if (RT_SUCCESS(rc))
{
rc = VERR_DBG_NO_MATCHING_INTERPRETER;
PRTDBGMODREGIMG pImg;
for (pImg = g_pImgHead; pImg; pImg = pImg->pNext)
{
pDbgMod->pImgVt = pImg->pVt;
pDbgMod->pvImgPriv = NULL;
/** @todo need to specify some arch stuff here. */
rc = pImg->pVt->pfnTryOpen(pDbgMod, enmArch);
if (RT_SUCCESS(rc))
{
/*
* Image detected, but found no debug info we were
* able to understand.
*/
/** @todo some generic way of matching image and debug info, flexible signature
* of some kind. Apple uses UUIDs, microsoft uses a UUID+age or a
* size+timestamp, and GNU a CRC32 (last time I checked). */
rc = rtDbgModOpenDebugInfoExternalToImage(pDbgMod, hDbgCfg);
if (RT_FAILURE(rc))
rc = rtDbgModOpenDebugInfoInsideImage(pDbgMod);
if (RT_FAILURE(rc))
rc = rtDbgModOpenDebugInfoExternalToImage2(pDbgMod, hDbgCfg);
if (RT_FAILURE(rc))
rc = rtDbgModCreateForExports(pDbgMod);
if (RT_SUCCESS(rc))
{
/*
* We're done!
*/
ASMAtomicIncU32(&pImg->cUsers);
RTSemRWReleaseRead(g_hDbgModRWSem);
*phDbgMod = pDbgMod;
return VINF_SUCCESS;
}
/* Failed, close up the shop. */
pDbgMod->pImgVt->pfnClose(pDbgMod);
pDbgMod->pImgVt = NULL;
pDbgMod->pvImgPriv = NULL;
break;
}
}
/*
* Could it be a file containing raw debug info?
*/
if (!pImg)
{
pDbgMod->pImgVt = NULL;
pDbgMod->pvImgPriv = NULL;
pDbgMod->pszDbgFile = pDbgMod->pszImgFile;
pDbgMod->pszImgFile = NULL;
for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
{
pDbgMod->pDbgVt = pDbg->pVt;
pDbgMod->pvDbgPriv = NULL;
rc = pDbg->pVt->pfnTryOpen(pDbgMod, enmArch);
if (RT_SUCCESS(rc))
{
/*
* That's it!
*/
ASMAtomicIncU32(&pDbg->cUsers);
RTSemRWReleaseRead(g_hDbgModRWSem);
*phDbgMod = pDbgMod;
return rc;
}
}
pDbgMod->pszImgFile = pDbgMod->pszDbgFile;
pDbgMod->pszDbgFile = NULL;
}
/* bail out */
RTSemRWReleaseRead(g_hDbgModRWSem);
}
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFileSpecified);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
}
else
rc = VERR_NO_STR_MEMORY;
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
}
else
rc = VERR_NO_STR_MEMORY;
RTCritSectDelete(&pDbgMod->CritSect);
}
RTMemFree(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModCreateFromImage);
/*
*
* P E I M A G E
* P E I M A G E
* P E I M A G E
*
*/
/** @callback_method_impl{FNRTDBGCFGOPEN} */
static DECLCALLBACK(int) rtDbgModFromPeImageOpenCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
{
PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1;
PRTDBGMODDEFERRED pDeferred = (PRTDBGMODDEFERRED)pvUser2;
LogFlow(("rtDbgModFromPeImageOpenCallback: %s\n", pszFilename));
Assert(pDbgMod->pImgVt == NULL);
Assert(pDbgMod->pvImgPriv == NULL);
Assert(pDbgMod->pDbgVt == NULL);
Assert(pDbgMod->pvDbgPriv == NULL);
/*
* Replace the image file name while probing it.
*/
const char *pszNewImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
if (!pszNewImgFile)
return VERR_NO_STR_MEMORY;
const char *pszOldImgFile = pDbgMod->pszImgFile;
pDbgMod->pszImgFile = pszNewImgFile;
/*
* Find an image reader which groks the file.
*/
int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
if (RT_SUCCESS(rc))
{
rc = VERR_DBG_NO_MATCHING_INTERPRETER;
PRTDBGMODREGIMG pImg;
for (pImg = g_pImgHead; pImg; pImg = pImg->pNext)
{
pDbgMod->pImgVt = pImg->pVt;
pDbgMod->pvImgPriv = NULL;
rc = pImg->pVt->pfnTryOpen(pDbgMod, RTLDRARCH_WHATEVER);
if (RT_SUCCESS(rc))
break;
pDbgMod->pImgVt = NULL;
Assert(pDbgMod->pvImgPriv == NULL);
}
RTSemRWReleaseRead(g_hDbgModRWSem);
if (RT_SUCCESS(rc))
{
/*
* Check the deferred info.
*/
RTUINTPTR cbImage = pDbgMod->pImgVt->pfnImageSize(pDbgMod);
if ( pDeferred->cbImage == 0
|| pDeferred->cbImage == cbImage)
{
uint32_t uTimestamp = pDeferred->u.PeImage.uTimestamp; /** @todo add method for getting the timestamp. */
if ( pDeferred->u.PeImage.uTimestamp == 0
|| pDeferred->u.PeImage.uTimestamp == uTimestamp)
{
Log(("RTDbgMod: Found matching PE image '%s'\n", pszFilename));
/*
* We found the executable image we need, now go find any
* debug info associated with it. For PE images, this is
* generally found in an external file, so we do a sweep
* for that first.
*
* Then try open debug inside the module, and finally
* falling back on exports.
*/
rc = rtDbgModOpenDebugInfoExternalToImage(pDbgMod, pDeferred->hDbgCfg);
if (RT_FAILURE(rc))
rc = rtDbgModOpenDebugInfoInsideImage(pDbgMod);
if (RT_FAILURE(rc))
rc = rtDbgModCreateForExports(pDbgMod);
if (RT_SUCCESS(rc))
{
RTStrCacheRelease(g_hDbgModStrCache, pszOldImgFile);
return VINF_CALLBACK_RETURN;
}
/* Something bad happened, just give up. */
Log(("rtDbgModFromPeImageOpenCallback: rtDbgModCreateForExports failed: %Rrc\n", rc));
}
else
{
LogFlow(("rtDbgModFromPeImageOpenCallback: uTimestamp mismatch (found %#x, expected %#x) - %s\n",
uTimestamp, pDeferred->u.PeImage.uTimestamp, pszFilename));
rc = VERR_DBG_FILE_MISMATCH;
}
}
else
{
LogFlow(("rtDbgModFromPeImageOpenCallback: cbImage mismatch (found %#x, expected %#x) - %s\n",
cbImage, pDeferred->cbImage, pszFilename));
rc = VERR_DBG_FILE_MISMATCH;
}
pDbgMod->pImgVt->pfnClose(pDbgMod);
pDbgMod->pImgVt = NULL;
pDbgMod->pvImgPriv = NULL;
}
else
LogFlow(("rtDbgModFromPeImageOpenCallback: Failed %Rrc - %s\n", rc, pszFilename));
}
/* Restore image name. */
pDbgMod->pszImgFile = pszOldImgFile;
RTStrCacheRelease(g_hDbgModStrCache, pszNewImgFile);
return rc;
}
/** @callback_method_impl{FNRTDBGMODDEFERRED} */
static DECLCALLBACK(int) rtDbgModFromPeImageDeferredCallback(PRTDBGMODINT pDbgMod, PRTDBGMODDEFERRED pDeferred)
{
int rc;
Assert(pDbgMod->pszImgFile);
if (!pDbgMod->pImgVt)
rc = RTDbgCfgOpenPeImage(pDeferred->hDbgCfg, pDbgMod->pszImgFile,
pDeferred->cbImage, pDeferred->u.PeImage.uTimestamp,
rtDbgModFromPeImageOpenCallback, pDbgMod, pDeferred);
else
{
rc = rtDbgModOpenDebugInfoExternalToImage(pDbgMod, pDeferred->hDbgCfg);
if (RT_FAILURE(rc))
rc = rtDbgModOpenDebugInfoInsideImage(pDbgMod);
if (RT_FAILURE(rc))
rc = rtDbgModCreateForExports(pDbgMod);
}
return rc;
}
RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTLDRMOD hLdrMod,
uint32_t cbImage, uint32_t uTimestamp, RTDBGCFG hDbgCfg)
{
/*
* Input validation and lazy initialization.
*/
AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
*phDbgMod = NIL_RTDBGMOD;
AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
AssertReturn(*pszFilename, VERR_INVALID_PARAMETER);
if (!pszName)
pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS);
AssertPtrReturn(pszName, VERR_INVALID_POINTER);
AssertReturn(hLdrMod == NIL_RTLDRMOD || RTLdrSize(hLdrMod) != ~(size_t)0, VERR_INVALID_HANDLE);
int rc = rtDbgModLazyInit();
if (RT_FAILURE(rc))
return rc;
uint64_t fDbgCfg = 0;
if (hDbgCfg)
{
rc = RTDbgCfgQueryUInt(hDbgCfg, RTDBGCFGPROP_FLAGS, &fDbgCfg);
AssertRCReturn(rc, rc);
}
/*
* Allocate a new module instance.
*/
PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
if (!pDbgMod)
return VERR_NO_MEMORY;
pDbgMod->u32Magic = RTDBGMOD_MAGIC;
pDbgMod->cRefs = 1;
rc = RTCritSectInit(&pDbgMod->CritSect);
if (RT_SUCCESS(rc))
{
pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, pszName);
if (pDbgMod->pszName)
{
pDbgMod->pszImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
if (pDbgMod->pszImgFile)
{
RTStrCacheRetain(pDbgMod->pszImgFile);
pDbgMod->pszImgFileSpecified = pDbgMod->pszImgFile;
/*
* If we have a loader module, we must instantiate the loader
* side of things regardless of the deferred setting.
*/
if (hLdrMod != NIL_RTLDRMOD)
{
if (!cbImage)
cbImage = (uint32_t)RTLdrSize(hLdrMod);
pDbgMod->pImgVt = &g_rtDbgModVtImgLdr;
rc = rtDbgModLdrOpenFromHandle(pDbgMod, hLdrMod);
}
if (RT_SUCCESS(rc))
{
/*
* Do it now or procrastinate?
*/
if (!(fDbgCfg & RTDBGCFG_FLAGS_DEFERRED) || !cbImage)
{
RTDBGMODDEFERRED Deferred;
Deferred.cbImage = cbImage;
Deferred.hDbgCfg = hDbgCfg;
Deferred.u.PeImage.uTimestamp = uTimestamp;
rc = rtDbgModFromPeImageDeferredCallback(pDbgMod, &Deferred);
}
else
{
PRTDBGMODDEFERRED pDeferred;
rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromPeImageDeferredCallback, cbImage, hDbgCfg, &pDeferred);
if (RT_SUCCESS(rc))
pDeferred->u.PeImage.uTimestamp = uTimestamp;
}
if (RT_SUCCESS(rc))
{
*phDbgMod = pDbgMod;
return VINF_SUCCESS;
}
/* Failed, bail out. */
if (hLdrMod != NIL_RTLDRMOD)
{
Assert(pDbgMod->pImgVt);
pDbgMod->pImgVt->pfnClose(pDbgMod);
}
}
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
}
else
rc = VERR_NO_STR_MEMORY;
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFileSpecified);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
}
else
rc = VERR_NO_STR_MEMORY;
RTCritSectDelete(&pDbgMod->CritSect);
}
RTMemFree(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModCreateFromPeImage);
/**
* Destroys an module after the reference count has reached zero.
*
* @param pDbgMod The module instance.
*/
static void rtDbgModDestroy(PRTDBGMODINT pDbgMod)
{
/*
* Close the debug info interpreter first, then the image interpret.
*/
RTCritSectEnter(&pDbgMod->CritSect); /* paranoia */
if (pDbgMod->pDbgVt)
{
pDbgMod->pDbgVt->pfnClose(pDbgMod);
pDbgMod->pDbgVt = NULL;
pDbgMod->pvDbgPriv = NULL;
}
if (pDbgMod->pImgVt)
{
pDbgMod->pImgVt->pfnClose(pDbgMod);
pDbgMod->pImgVt = NULL;
pDbgMod->pvImgPriv = NULL;
}
/*
* Free the resources.
*/
ASMAtomicWriteU32(&pDbgMod->u32Magic, ~RTDBGMOD_MAGIC);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFileSpecified);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
RTCritSectLeave(&pDbgMod->CritSect); /* paranoia */
RTCritSectDelete(&pDbgMod->CritSect);
RTMemFree(pDbgMod);
}
RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
return ASMAtomicIncU32(&pDbgMod->cRefs);
}
RT_EXPORT_SYMBOL(RTDbgModRetain);
RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod)
{
if (hDbgMod == NIL_RTDBGMOD)
return 0;
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
uint32_t cRefs = ASMAtomicDecU32(&pDbgMod->cRefs);
if (!cRefs)
rtDbgModDestroy(pDbgMod);
return cRefs;
}
RT_EXPORT_SYMBOL(RTDbgModRelease);
RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
return pDbgMod->pszName;
}
RT_EXPORT_SYMBOL(RTDbgModName);
RTDECL(const char *) RTDbgModDebugFile(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
if (pDbgMod->fDeferred || pDbgMod->fExports)
return NULL;
return pDbgMod->pszDbgFile;
}
RT_EXPORT_SYMBOL(RTDbgModDebugFile);
RTDECL(const char *) RTDbgModImageFile(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
return pDbgMod->pszImgFileSpecified;
}
RT_EXPORT_SYMBOL(RTDbgModImageFile);
RTDECL(const char *) RTDbgModImageFileUsed(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
return pDbgMod->pszImgFile == pDbgMod->pszImgFileSpecified ? NULL : pDbgMod->pszImgFile;
}
RT_EXPORT_SYMBOL(RTDbgModImageFileUsed);
RTDECL(bool) RTDbgModIsDeferred(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, false);
return pDbgMod->fDeferred;
}
RTDECL(bool) RTDbgModIsExports(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, false);
return pDbgMod->fExports;
}
RTDECL(int) RTDbgModRemoveAll(RTDBGMOD hDbgMod, bool fLeaveSegments)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
RTDBGMOD_LOCK(pDbgMod);
/* Only possible on container modules. */
int rc = VINF_SUCCESS;
if (pDbgMod->pDbgVt != &g_rtDbgModVtDbgContainer)
{
if (fLeaveSegments)
{
rc = rtDbgModContainer_LineRemoveAll(pDbgMod);
if (RT_SUCCESS(rc))
rc = rtDbgModContainer_SymbolRemoveAll(pDbgMod);
}
else
rc = rtDbgModContainer_RemoveAll(pDbgMod);
}
else
rc = VERR_ACCESS_DENIED;
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, NIL_RTDBGSEGIDX);
RTDBGMOD_LOCK(pDbgMod);
RTDBGSEGIDX iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, uRva, poffSeg);
RTDBGMOD_UNLOCK(pDbgMod);
return iSeg;
}
RT_EXPORT_SYMBOL(RTDbgModRvaToSegOff);
RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, RTUINTPTR_MAX);
RTDBGMOD_LOCK(pDbgMod);
RTUINTPTR cbImage = pDbgMod->pDbgVt->pfnImageSize(pDbgMod);
RTDBGMOD_UNLOCK(pDbgMod);
return cbImage;
}
RT_EXPORT_SYMBOL(RTDbgModImageSize);
RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, 0);
return pDbgMod->uTag;
}
RT_EXPORT_SYMBOL(RTDbgModGetTag);
RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
RTDBGMOD_LOCK(pDbgMod);
pDbgMod->uTag = uTag;
RTDBGMOD_UNLOCK(pDbgMod);
return VINF_SUCCESS;
}
RT_EXPORT_SYMBOL(RTDbgModSetTag);
RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
uint32_t fFlags, PRTDBGSEGIDX piSeg)
{
/*
* Validate input.
*/
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
AssertMsgReturn(uRva + cb >= uRva, ("uRva=%RTptr cb=%RTptr\n", uRva, cb), VERR_DBG_ADDRESS_WRAP);
Assert(*pszName);
size_t cchName = strlen(pszName);
AssertReturn(cchName > 0, VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE);
AssertReturn(cchName < RTDBG_SEGMENT_NAME_LENGTH, VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE);
AssertMsgReturn(!fFlags, ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
AssertPtrNull(piSeg);
AssertMsgReturn(!piSeg || *piSeg == NIL_RTDBGSEGIDX || *piSeg <= RTDBGSEGIDX_LAST, ("%#x\n", *piSeg), VERR_DBG_SPECIAL_SEGMENT);
/*
* Do the deed.
*/
RTDBGMOD_LOCK(pDbgMod);
int rc = pDbgMod->pDbgVt->pfnSegmentAdd(pDbgMod, uRva, cb, pszName, cchName, fFlags, piSeg);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSegmentAdd);
RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, NIL_RTDBGSEGIDX);
RTDBGMOD_LOCK(pDbgMod);
RTDBGSEGIDX cSegs = pDbgMod->pDbgVt->pfnSegmentCount(pDbgMod);
RTDBGMOD_UNLOCK(pDbgMod);
return cSegs;
}
RT_EXPORT_SYMBOL(RTDbgModSegmentCount);
RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
{
AssertMsgReturn(iSeg <= RTDBGSEGIDX_LAST, ("%#x\n", iSeg), VERR_DBG_SPECIAL_SEGMENT);
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
RTDBGMOD_LOCK(pDbgMod);
int rc = pDbgMod->pDbgVt->pfnSegmentByIndex(pDbgMod, iSeg, pSegInfo);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSegmentByIndex);
RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
{
if (iSeg == RTDBGSEGIDX_RVA)
return RTDbgModImageSize(hDbgMod);
RTDBGSEGMENT SegInfo;
int rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo);
return RT_SUCCESS(rc) ? SegInfo.cb : RTUINTPTR_MAX;
}
RT_EXPORT_SYMBOL(RTDbgModSegmentSize);
RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
{
RTDBGSEGMENT SegInfo;
int rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo);
return RT_SUCCESS(rc) ? SegInfo.uRva : RTUINTPTR_MAX;
}
RT_EXPORT_SYMBOL(RTDbgModSegmentRva);
RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off,
RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal)
{
/*
* Validate input.
*/
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
AssertPtr(pszSymbol);
size_t cchSymbol = strlen(pszSymbol);
AssertReturn(cchSymbol, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
AssertReturn(cchSymbol < RTDBG_SYMBOL_NAME_LENGTH, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
AssertMsgReturn( iSeg <= RTDBGSEGIDX_LAST
|| ( iSeg >= RTDBGSEGIDX_SPECIAL_FIRST
&& iSeg <= RTDBGSEGIDX_SPECIAL_LAST),
("%#x\n", iSeg),
VERR_DBG_INVALID_SEGMENT_INDEX);
AssertMsgReturn(off + cb >= off, ("off=%RTptr cb=%RTptr\n", off, cb), VERR_DBG_ADDRESS_WRAP);
AssertReturn(!fFlags, VERR_INVALID_PARAMETER); /* currently reserved. */
RTDBGMOD_LOCK(pDbgMod);
/*
* Convert RVAs.
*/
if (iSeg == RTDBGSEGIDX_RVA)
{
iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
if (iSeg == NIL_RTDBGSEGIDX)
{
RTDBGMOD_UNLOCK(pDbgMod);
return VERR_DBG_INVALID_RVA;
}
}
/*
* Get down to business.
*/
int rc = pDbgMod->pDbgVt->pfnSymbolAdd(pDbgMod, pszSymbol, cchSymbol, iSeg, off, cb, fFlags, piOrdinal);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolAdd);
RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
RTDBGMOD_LOCK(pDbgMod);
uint32_t cSymbols = pDbgMod->pDbgVt->pfnSymbolCount(pDbgMod);
RTDBGMOD_UNLOCK(pDbgMod);
return cSymbols;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolCount);
RTDECL(int) RTDbgModSymbolByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
RTDBGMOD_LOCK(pDbgMod);
int rc = pDbgMod->pDbgVt->pfnSymbolByOrdinal(pDbgMod, iOrdinal, pSymInfo);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolByOrdinal);
RTDECL(int) RTDbgModSymbolByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL *ppSymInfo)
{
AssertPtr(ppSymInfo);
*ppSymInfo = NULL;
PRTDBGSYMBOL pSymInfo = RTDbgSymbolAlloc();
if (!pSymInfo)
return VERR_NO_MEMORY;
int rc = RTDbgModSymbolByOrdinal(hDbgMod, iOrdinal, pSymInfo);
if (RT_SUCCESS(rc))
*ppSymInfo = pSymInfo;
else
RTDbgSymbolFree(pSymInfo);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolByOrdinalA);
RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo)
{
/*
* Validate input.
*/
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
AssertPtrNull(poffDisp);
AssertPtr(pSymInfo);
AssertReturn(!(fFlags & ~RTDBGSYMADDR_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
RTDBGMOD_LOCK(pDbgMod);
/*
* Convert RVAs.
*/
if (iSeg == RTDBGSEGIDX_RVA)
{
iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
if (iSeg == NIL_RTDBGSEGIDX)
{
RTDBGMOD_UNLOCK(pDbgMod);
return VERR_DBG_INVALID_RVA;
}
}
/*
* Get down to business.
*/
int rc = pDbgMod->pDbgVt->pfnSymbolByAddr(pDbgMod, iSeg, off, fFlags, poffDisp, pSymInfo);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolByAddr);
RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo)
{
AssertPtr(ppSymInfo);
*ppSymInfo = NULL;
PRTDBGSYMBOL pSymInfo = RTDbgSymbolAlloc();
if (!pSymInfo)
return VERR_NO_MEMORY;
int rc = RTDbgModSymbolByAddr(hDbgMod, iSeg, off, fFlags, poffDisp, pSymInfo);
if (RT_SUCCESS(rc))
*ppSymInfo = pSymInfo;
else
RTDbgSymbolFree(pSymInfo);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolByAddrA);
RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymInfo)
{
/*
* Validate input.
*/
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
AssertPtr(pszSymbol);
size_t cchSymbol = strlen(pszSymbol);
AssertReturn(cchSymbol, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
AssertReturn(cchSymbol < RTDBG_SYMBOL_NAME_LENGTH, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
AssertPtr(pSymInfo);
/*
* Make the query.
*/
RTDBGMOD_LOCK(pDbgMod);
int rc = pDbgMod->pDbgVt->pfnSymbolByName(pDbgMod, pszSymbol, cchSymbol, pSymInfo);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolByName);
RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymInfo)
{
AssertPtr(ppSymInfo);
*ppSymInfo = NULL;
PRTDBGSYMBOL pSymInfo = RTDbgSymbolAlloc();
if (!pSymInfo)
return VERR_NO_MEMORY;
int rc = RTDbgModSymbolByName(hDbgMod, pszSymbol, pSymInfo);
if (RT_SUCCESS(rc))
*ppSymInfo = pSymInfo;
else
RTDbgSymbolFree(pSymInfo);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModSymbolByNameA);
RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal)
{
/*
* Validate input.
*/
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
AssertPtr(pszFile);
size_t cchFile = strlen(pszFile);
AssertReturn(cchFile, VERR_DBG_FILE_NAME_OUT_OF_RANGE);
AssertReturn(cchFile < RTDBG_FILE_NAME_LENGTH, VERR_DBG_FILE_NAME_OUT_OF_RANGE);
AssertMsgReturn( iSeg <= RTDBGSEGIDX_LAST
|| iSeg == RTDBGSEGIDX_RVA,
("%#x\n", iSeg),
VERR_DBG_INVALID_SEGMENT_INDEX);
AssertReturn(uLineNo > 0 && uLineNo < UINT32_MAX, VERR_INVALID_PARAMETER);
RTDBGMOD_LOCK(pDbgMod);
/*
* Convert RVAs.
*/
if (iSeg == RTDBGSEGIDX_RVA)
{
iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
if (iSeg == NIL_RTDBGSEGIDX)
{
RTDBGMOD_UNLOCK(pDbgMod);
return VERR_DBG_INVALID_RVA;
}
}
/*
* Get down to business.
*/
int rc = pDbgMod->pDbgVt->pfnLineAdd(pDbgMod, pszFile, cchFile, uLineNo, iSeg, off, piOrdinal);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModLineAdd);
RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
RTDBGMOD_LOCK(pDbgMod);
uint32_t cLineNumbers = pDbgMod->pDbgVt->pfnLineCount(pDbgMod);
RTDBGMOD_UNLOCK(pDbgMod);
return cLineNumbers;
}
RT_EXPORT_SYMBOL(RTDbgModLineCount);
RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
{
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
RTDBGMOD_LOCK(pDbgMod);
int rc = pDbgMod->pDbgVt->pfnLineByOrdinal(pDbgMod, iOrdinal, pLineInfo);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModLineByOrdinal);
RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo)
{
AssertPtr(ppLineInfo);
*ppLineInfo = NULL;
PRTDBGLINE pLineInfo = RTDbgLineAlloc();
if (!pLineInfo)
return VERR_NO_MEMORY;
int rc = RTDbgModLineByOrdinal(hDbgMod, iOrdinal, pLineInfo);
if (RT_SUCCESS(rc))
*ppLineInfo = pLineInfo;
else
RTDbgLineFree(pLineInfo);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModLineByOrdinalA);
RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo)
{
/*
* Validate input.
*/
PRTDBGMODINT pDbgMod = hDbgMod;
RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
AssertPtrNull(poffDisp);
AssertPtr(pLineInfo);
RTDBGMOD_LOCK(pDbgMod);
/*
* Convert RVAs.
*/
if (iSeg == RTDBGSEGIDX_RVA)
{
iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
if (iSeg == NIL_RTDBGSEGIDX)
{
RTDBGMOD_UNLOCK(pDbgMod);
return VERR_DBG_INVALID_RVA;
}
}
int rc = pDbgMod->pDbgVt->pfnLineByAddr(pDbgMod, iSeg, off, poffDisp, pLineInfo);
RTDBGMOD_UNLOCK(pDbgMod);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModLineByAddr);
RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo)
{
AssertPtr(ppLineInfo);
*ppLineInfo = NULL;
PRTDBGLINE pLineInfo = RTDbgLineAlloc();
if (!pLineInfo)
return VERR_NO_MEMORY;
int rc = RTDbgModLineByAddr(hDbgMod, iSeg, off, poffDisp, pLineInfo);
if (RT_SUCCESS(rc))
*ppLineInfo = pLineInfo;
else
RTDbgLineFree(pLineInfo);
return rc;
}
RT_EXPORT_SYMBOL(RTDbgModLineByAddrA);