DBGPlugInCommonELFTmpl.cpp.h revision c58f1213e628a545081c70e26c6b67a841cff880
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * DBGPlugInCommonELF - Code Template for dealing with one kind of ELF.
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * Copyright (C) 2008-2013 Oracle Corporation
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * available from http://www.virtualbox.org. This file is free software;
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * you can redistribute it and/or modify it under the terms of the GNU
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * General Public License (GPL) as published by the Free Software
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
eb3a3435bb6f3ad6a38085912929372669c498favboxsync# define DBGDiggerCommonParseElfMod DBGDiggerCommonParseElf32Mod
eb3a3435bb6f3ad6a38085912929372669c498favboxsync# define DBGDiggerCommonParseElfMod DBGDiggerCommonParseElf64Mod
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * Common ELF module parser.
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * It takes the essential bits of the ELF module (elf header, section headers,
eb3a3435bb6f3ad6a38085912929372669c498favboxsync * symbol table and string table), and inserts/updates the module and symbols.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @returns VBox status code.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param pUVM The user mode VM handle.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param pszModName The module name.
4b783d68e6d569ab798901917ace422a4810edf0vboxsync * @param pszFilename The filename. optional.
4b783d68e6d569ab798901917ace422a4810edf0vboxsync * @param fFlags Flags.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param pEhdr Pointer to the ELF header.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param paShdrs Pointer to the section headers. The caller must verify that
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * the e_shnum member of the ELF header is within the bounds of
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * this table. The caller should also adjust the section addresses
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * so these correspond to actual load addresses.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param paSyms Pointer to the symbol table.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param cMaxSyms The maximum number of symbols paSyms may hold. This isn't
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * the exact count, it's just a cap for avoiding SIGSEGVs
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * and general corruption.
4b783d68e6d569ab798901917ace422a4810edf0vboxsync * @param pbStrings Pointer to the string table.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param cbMaxStrings The size of the memory pbStrings points to. This doesn't
4b783d68e6d569ab798901917ace422a4810edf0vboxsync * have to match the string table size exactly, it's just to
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * avoid SIGSEGV when a bad string index is encountered.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * @param MinAddr Min address to care about.
4b783d68e6d569ab798901917ace422a4810edf0vboxsync * @param MaxAddr Max address to care about (inclusive). Together
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * with MinAddr this forms a valid address range for
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * symbols and sections that we care about. Anything
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * outside the range is ignored, except when doing
4b783d68e6d569ab798901917ace422a4810edf0vboxsync * sanity checks..
4b783d68e6d569ab798901917ace422a4810edf0vboxsync * @param uModTag Module tag. Pass 0 if tagging is of no interest.
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsyncint DBGDiggerCommonParseElfMod(PUVM pUVM, const char *pszModName, const char *pszFilename, uint32_t fFlags,
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync RTGCPTR MinAddr, RTGCPTR MaxAddr, uint64_t uModTag)
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync AssertReturn(!(fFlags & ~DBG_DIGGER_ELF_MASK), VERR_INVALID_PARAMETER);
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync AssertReturn((fFlags & (DBG_DIGGER_ELF_FUNNY_SHDRS | DBG_DIGGER_ELF_ADJUST_SYM_VALUE))
4b783d68e6d569ab798901917ace422a4810edf0vboxsync != (DBG_DIGGER_ELF_FUNNY_SHDRS | DBG_DIGGER_ELF_ADJUST_SYM_VALUE), VERR_INVALID_PARAMETER);
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * Validate the ELF header.
eb3a3435bb6f3ad6a38085912929372669c498favboxsync if (ASMMemIsAll8(&pEhdr->e_ident[EI_PAD], EI_NIDENT - EI_PAD, 0) != NULL) //??
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * Validate the section headers, finding the string and symbol table
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync * headers and the load address while at it.
eb3a3435bb6f3ad6a38085912929372669c498favboxsync for (unsigned iSh = fFlags & DBG_DIGGER_ELF_FUNNY_SHDRS ? 1 : 0; iSh < pEhdr->e_shnum; iSh++)
eb3a3435bb6f3ad6a38085912929372669c498favboxsync /* Minimal validation. */
29e50fce8a16b6c8955f48b7d1e19cb7aa3694ddvboxsync /* Is it the symbol table?*/
: cMaxSyms;
return VERR_BAD_EXE_FORMAT;
return VERR_BAD_EXE_FORMAT;
return rc;
for (unsigned i = 0; i < cSegs; i++)
for (unsigned i = 0; i < cSegs; i++)
rc = RTDbgModSegmentAdd(hMod, paShdrs[i].sh_addr - uLoadAddr, paShdrs[i].sh_size, szSeg, 0 /*fFlags*/, &paSegs[i].iSeg);
return rc;
if (!*pszSymbol)
Log(("%02x:%RGv %RGv %s!%s (rc=%Rrc)\n", paSyms[iSym].st_shndx, offSeg, cbSym, pszModName, pszSymbol, rc));
return rc;