DBGFSym.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A * available from http://www.virtualbox.org. This file is free software;
0N/A#if defined(__WIN32__) && defined(DEBUG_bird) // enabled this is you want to debug win32 guests or the hypervisor.
0N/A# define _IMAGEHLP64
0N/A/** @todo Only use DBGHELP for reading modules since it doesn't do all we want (relocations), or is way to slow in some cases (add symbol)! */
0N/A#include "DBGFInternal.h"
0N/A#ifndef HAVE_DBGHELP
0N/A#ifdef HAVE_DBGHELP
0N/Astatic DECLCALLBACK(int) dbgfR3EnumModules(PVM pVM, const char *pszFilename, const char *pszName, RTUINTPTR ImageBase, unsigned cbImage, bool fGC);
0N/A#ifndef HAVE_DBGHELP
typedef struct DBGFSYMSPACE
#ifndef HAVE_DBGHELP
if (pSym)
return VINF_SUCCESS;
return VERR_INTERNAL_ERROR;
return VERR_NO_MEMORY;
static int dbgfR3SymbolInsert(PVM pVM, const char *pszName, RTGCPTR Address, size_t cb, PDBGFMOD pModule)
PDBGFSYM pSym = (PDBGFSYM)MMR3HeapAlloc(pVM, MM_TAG_DBGF_SYMBOL, RT_OFFSETOF(DBGFSYM, szName[cchName]));
if (pSym)
if (pOld)
if (!pName)
PDBGFSYMSPACE pName = (PDBGFSYMSPACE)MMR3HeapAlloc(pVM, MM_TAG_DBGF_SYMBOL, sizeof(*pName) + cchName);
if (pName)
return VINF_SUCCESS;
return VINF_SUCCESS;
return VINF_SUCCESS;
return VERR_INTERNAL_ERROR;
return VERR_NO_MEMORY;
return pSym;
return NULL;
if (pName)
return NULL;
psz++;
return psz;
int rc;
pVM->dbgf.s.pSymbolSpace = (PRTSTRSPACE)MMR3HeapAllocZ(pVM, MM_TAG_DBGF_SYMBOL, sizeof(*pVM->dbgf.s.pSymbolSpace));
#ifndef HAVE_DBGHELP
return rc;
if (pNode)
char *pszFilename;
AssertMsgRCReturn(rc, ("rc=%Vrc querying the 'File' attribute of '/DBGF/loadsyms/%s'!\n", rc, szCmdName), rc);
offDelta = 0;
AssertMsgRCReturn(rc, ("rc=%Vrc querying the 'Delta' attribute of '/DBGF/loadsyms/%s'!\n", rc, szCmdName), rc);
char *pszModule;
AssertMsgRCReturn(rc, ("rc=%Vrc querying the 'Module' attribute of '/DBGF/loadsyms/%s'!\n", rc, szCmdName), rc);
ModuleAddress = 0;
AssertMsgRCReturn(rc, ("rc=%Vrc querying the 'ModuleAddress' attribute of '/DBGF/loadsyms/%s'!\n", rc, szCmdName), rc);
cbModule = 0;
AssertMsgRCReturn(rc, ("rc=%Vrc querying the 'ModuleAddress' attribute of '/DBGF/loadsyms/%s'!\n", rc, szCmdName), rc);
AssertMsgRCReturn(rc, ("pszFilename=%s offDelta=%RGv pszModule=%s ModuleAddress=%RGv cbModule=%RGv\n",
return VINF_SUCCESS;
return VINF_SUCCESS;
#ifdef HAVE_DBGHELP
return VINF_SUCCESS;
return VINF_SUCCESS;
#ifdef HAVE_DBGHELP
static DECLCALLBACK(int) dbgfR3EnumModules(PVM pVM, const char *pszFilename, const char *pszName, RTUINTPTR ImageBase, unsigned cbImage, bool fGC)
if (fGC)
DWORD64 LoadedImageBase = SymLoadModule64(pVM, NULL, (char *)(void *)pszFilename, (char *)(void *)pszName, ImageBase, cbImage);
if (!LoadedImageBase)
return VINF_SUCCESS;
#ifdef HAVE_DBGHELP
return VINF_SUCCESS;
return VINF_SUCCESS;
typedef enum SYMFILETYPE
if (cchHead > 0)
return SYMFILETYPE_MS_MAP;
return SYMFILETYPE_LD_MAP;
return SYMFILETYPE_LINUX_SYSTEM_MAP;
return SYMFILETYPE_PDB;
return SYMFILETYPE_ELF;
return SYMFILETYPE_MZ;
return SYMFILETYPE_OBJDUMP;
return SYMFILETYPE_UNKNOWN;
static int dbgfR3LoadLinuxSystemMap(PVM pVM, FILE *pFile, RTGCUINTPTR ModuleAddress, RTGCUINTPTR AddressDelta)
&& Address != 0
pszEnd++;
if (*psz)
return VINF_SUCCESS;
* @param ModuleAddress Address which the image is loaded at. This will be used to reference the module other places in the api.
DBGFR3DECL(int) DBGFR3ModuleLoad(PVM pVM, const char *pszFilename, RTGCUINTPTR AddressDelta, const char *pszName, RTGCUINTPTR ModuleAddress, unsigned cbImage)
return rc;
if (pFile)
if (pszName)
#ifdef HAVE_DBGHELP
/** @todo arg! checkout the inserting of modules and then loading them again.... Or just the module representation.... */
DWORD64 ImageBase = SymLoadModule64(pVM, NULL, (char *)(void *)pszFilename, (char *)(void *)pszName, ModuleAddress, cbImage);
if (!ImageBase)
ImageBase = SymLoadModule64(pVM, NULL, (char *)(void *)pszName, (char *)(void *)pszName, ModuleAddress, cbImage);
if (ImageBase)
AssertMsg(ModuleAddress == 0 || ModuleAddress == ImageBase, ("ModuleAddres=%VGv ImageBase=%llx\n", ModuleAddress, ImageBase));
switch (enmType)
case SYMFILETYPE_PDB:
case SYMFILETYPE_DBG:
case SYMFILETYPE_MZ:
#ifdef HAVE_DBGHELP
case SYMFILETYPE_LD_MAP:
case SYMFILETYPE_MS_MAP:
case SYMFILETYPE_OBJDUMP:
case SYMFILETYPE_ELF:
AssertFailed();
return rc;
DBGFR3DECL(void) DBGFR3ModuleRelocate(PVM pVM, RTGCUINTPTR OldImageBase, RTGCUINTPTR NewImageBase, unsigned cbImage,
#ifdef HAVE_DBGHELP
DWORD64 LoadedImageBase = SymLoadModule64(pVM, NULL, (char *)(void *)pszFilename, (char *)(void *)pszName, NewImageBase, cbImage);
if (!LoadedImageBase)
DBGFR3DECL(int) DBGFR3SymbolAdd(PVM pVM, RTGCUINTPTR ModuleAddress, RTGCUINTPTR SymbolAddress, RTUINT cbSymbol, const char *pszSymbol)
return VERR_INVALID_PARAMETER;
return rc;
#ifdef HAVE_DBGHELP
return VINF_SUCCESS;
DBGFR3DECL(int) DBGFR3SymbolByAddr(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement, PDBGFSYMBOL pSymbol)
return rc;
#ifdef HAVE_DBGHELP
char achBuffer[sizeof(IMAGEHLP_SYMBOL64) + DBGF_SYMBOL_NAME_LENGTH * sizeof(TCHAR) + sizeof(ULONG64)];
return VINF_SUCCESS;
if (pSym)
if (poffDisplacement)
return VINF_SUCCESS;
if (poffDisplacement)
return VINF_SUCCESS;
return VERR_SYMBOL_NOT_FOUND;
return rc;
#ifdef HAVE_DBGHELP
char achBuffer[sizeof(IMAGEHLP_SYMBOL64) + DBGF_SYMBOL_NAME_LENGTH * sizeof(TCHAR) + sizeof(ULONG64)];
return VINF_SUCCESS;
if (pSym)
return VINF_SUCCESS;
return VERR_SYMBOL_NOT_FOUND;
if (pDup)
return pDup;
DBGFR3DECL(PDBGFSYMBOL) DBGFR3SymbolByAddrAlloc(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement)
return NULL;
return NULL;
if (pSymbol)
DBGFR3DECL(int) DBGFR3LineByAddr(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement, PDBGFLINE pLine)
return rc;
#ifdef HAVE_DBGHELP
if (poffDisplacement)
return VINF_SUCCESS;
return VERR_NOT_IMPLEMENTED;
if (pDup)
return pDup;
DBGFR3DECL(PDBGFLINE) DBGFR3LineByAddrAlloc(PVM pVM, RTGCUINTPTR Address, PRTGCINTPTR poffDisplacement)
return NULL;
if (pLine)
#ifdef HAVE_DBGHELP
//static BOOL CALLBACK win32EnumModulesCallback(PSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext)
return VERR_GENERAL_FAILURE;