VirtualBox

Changeset 8820 in vbox


Ignore:
Timestamp:
May 14, 2008 7:49:42 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
30827
Message:

Dug out the solaris kernel symbols! Use the "detect" command in the debugger in order to do this.

Location:
trunk/src/VBox/Debugger
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/DBGPlugInSolaris.cpp

    r8800 r8820  
    2424*   Header Files                                                               *
    2525*******************************************************************************/
     26#define LOG_GROUP LOG_GROUP_DBGF ///@todo add new log group.
    2627#include "DBGPlugIns.h"
     28#include "DBGPlugInCommonELF.h"
    2729#include <VBox/dbgf.h>
    2830#include <iprt/string.h>
     31#include <iprt/mem.h>
     32#include <iprt/stream.h>
    2933
    3034
     
    6771AssertCompileSize(SOL32_modctl_t, 0x50);
    6872
     73typedef struct SOL32_module
     74{
     75    int32_t     total_allocated;        /**<  0 */
     76    Elf32_Ehdr  hdr;                    /**<  4 Easy to validate */
     77    uint32_t    shdrs;                  /**< 38 */
     78    uint32_t    symhdr;                 /**< 3c */
     79    uint32_t    strhdr;                 /**< 40 */
     80    uint32_t    depends_on;             /**< 44 */
     81    uint32_t    symsize;                /**< 48 */
     82    uint32_t    symspace;               /**< 4c */
     83    int32_t     flags;                  /**< 50 */
     84    uint32_t    text_size;              /**< 54 */
     85    uint32_t    data_size;              /**< 58 */
     86    uint32_t    text;                   /**< 5c */
     87    uint32_t    data;                   /**< 60 */
     88    uint32_t    symtbl_section;         /**< 64 */
     89    uint32_t    symtbl;                 /**< 68 */
     90    uint32_t    strings;                /**< 6c */
     91    uint32_t    hashsize;               /**< 70 */
     92    uint32_t    buckets;                /**< 74 */
     93    uint32_t    chains;                 /**< 78 */
     94    uint32_t    nsyms;                  /**< 7c */
     95    uint32_t    bss_align;              /**< 80 */
     96    uint32_t    bss_size;               /**< 84 */
     97    uint32_t    bss;                    /**< 88 */
     98    uint32_t    filename;               /**< 8c */
     99    uint32_t    head;                   /**< 90 */
     100    uint32_t    tail;                   /**< 94 */
     101    uint32_t    destination;            /**< 98 */
     102    uint32_t    machdata;               /**< 9c */
     103    uint32_t    ctfdata;                /**< a0 */
     104    uint32_t    ctfsize;                /**< a4 */
     105    uint32_t    fbt_tab;                /**< a8 */
     106    uint32_t    fbt_size;               /**< ac */
     107    uint32_t    fbt_nentries;           /**< b0 */
     108    uint32_t    textwin;                /**< b4 */
     109    uint32_t    textwin_base;           /**< b8 */
     110    uint32_t    sdt_probes;             /**< bc */
     111    uint32_t    sdt_nprobes;            /**< c0 */
     112    uint32_t    sdt_tab;                /**< c4 */
     113    uint32_t    sdt_size;               /**< c8 */
     114    uint32_t    sigdata;                /**< cc */
     115    uint32_t    sigsize;                /**< d0 */
     116} SOL32_module_t;
     117AssertCompileSize(Elf32_Ehdr, 0x34);
     118AssertCompileSize(SOL32_module_t, 0xd4);
     119
    69120/** @} */
    70121
     
    126177
    127178    return VERR_NOT_IMPLEMENTED;
     179}
     180
     181
     182
     183/**
     184 * Processes a modctl_t.
     185 *
     186 * @param   pVM     The VM handle.
     187 * @param   pThis   Our instance data.
     188 * @param   pModCtl Pointer to the modctl structure.
     189 */
     190static void dbgDiggerSolarisProcessModCtl(PVM pVM, PDBGDIGGERSOLARIS pThis, SOL32_modctl_t const *pModCtl)
     191{
     192    /* skip it if it's not loaded and installed */
     193    if (    !pModCtl->mod_loaded
     194        ||  !pModCtl->mod_installed)
     195        return;
     196
     197    /*
     198     * Read the module and file names first
     199     */
     200    char szModName[64];
     201    DBGFADDRESS Addr;
     202    int rc = DBGFR3MemReadString(pVM, DBGFR3AddrFromFlat(pVM, &Addr, pModCtl->mod_modname), szModName, sizeof(szModName));
     203    if (RT_FAILURE(rc))
     204        return;
     205    if (!memchr(szModName, '\0', sizeof(szModName)))
     206        szModName[sizeof(szModName) - 1] = '\0';
     207
     208    char szFilename[256];
     209    rc = DBGFR3MemReadString(pVM, DBGFR3AddrFromFlat(pVM, &Addr, pModCtl->mod_filename), szFilename, sizeof(szFilename));
     210    if (RT_FAILURE(rc))
     211        strcpy(szFilename, szModName);
     212    else if (!memchr(szFilename, '\0', sizeof(szFilename)))
     213        szFilename[sizeof(szFilename) - 1] = '\0';
     214
     215    /*
     216     * Then read the module struct and validate it.
     217     */
     218    struct SOL32_module Module;
     219    rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, pModCtl->mod_mp), &Module, sizeof(Module));
     220    if (RT_FAILURE(rc))
     221        return;
     222
     223    /* Basic validations of the elf header. */
     224    if (    Module.hdr.e_ident[EI_MAG0] != ELFMAG0
     225        ||  Module.hdr.e_ident[EI_MAG1] != ELFMAG1
     226        ||  Module.hdr.e_ident[EI_MAG2] != ELFMAG2
     227        ||  Module.hdr.e_ident[EI_MAG3] != ELFMAG3
     228        ||  Module.hdr.e_ident[EI_CLASS] != ELFCLASS32
     229        ||  Module.hdr.e_ident[EI_DATA] != ELFDATA2LSB
     230        ||  Module.hdr.e_ident[EI_VERSION] != EV_CURRENT
     231        ||  ASMMemIsAll8(&Module.hdr.e_ident[EI_PAD], EI_NIDENT - EI_PAD, 0) != NULL
     232        )
     233        return;
     234    if (Module.hdr.e_version != EV_CURRENT)
     235        return;
     236    if (Module.hdr.e_ehsize != sizeof(Module.hdr))
     237        return;
     238    if (    Module.hdr.e_type != ET_DYN
     239        &&  Module.hdr.e_type != ET_REL
     240        &&  Module.hdr.e_type != ET_EXEC) //??
     241        return;
     242    if (    Module.hdr.e_machine != EM_386
     243        &&  Module.hdr.e_machine != EM_486)
     244        return;
     245    if (    Module.hdr.e_phentsize != sizeof(Elf32_Phdr)
     246        &&  Module.hdr.e_phentsize) //??
     247        return;
     248    if (Module.hdr.e_shentsize != sizeof(Elf32_Shdr))
     249        return;
     250
     251    if (Module.hdr.e_shentsize != sizeof(Elf32_Shdr))
     252        return;
     253
     254    /* Basic validations of the rest of the stuff. */
     255    if (    !SOL32_VALID_ADDRESS(Module.shdrs)
     256        ||  !SOL32_VALID_ADDRESS(Module.symhdr)
     257        ||  !SOL32_VALID_ADDRESS(Module.strhdr)
     258        ||  (!SOL32_VALID_ADDRESS(Module.symspace) && Module.symspace)
     259        ||  !SOL32_VALID_ADDRESS(Module.text)
     260        ||  !SOL32_VALID_ADDRESS(Module.data)
     261        ||  (!SOL32_VALID_ADDRESS(Module.symtbl) && Module.symtbl)
     262        ||  (!SOL32_VALID_ADDRESS(Module.strings) && Module.strings)
     263        ||  (!SOL32_VALID_ADDRESS(Module.head) && Module.head)
     264        ||  (!SOL32_VALID_ADDRESS(Module.tail) && Module.tail)
     265        ||  !SOL32_VALID_ADDRESS(Module.filename))
     266        return;
     267    if (    Module.symsize > _4M
     268        ||  Module.hdr.e_shnum > 4096
     269        ||  Module.nsyms > _256K)
     270        return;
     271
     272    /* Ignore modules without symbols. */
     273    if (!Module.symtbl || !Module.strings || !Module.symspace || !Module.symspace)
     274        return;
     275
     276    /* Check that the symtbl and strings points inside the symspace. */
     277    if (Module.strings - Module.symspace >= Module.symsize)
     278        return;
     279    if (Module.symtbl - Module.symspace >= Module.symsize)
     280        return;
     281
     282    /*
     283     * Read the section headers, symbol table and string tables.
     284     */
     285    size_t cb = Module.hdr.e_shnum * sizeof(Elf32_Shdr);
     286    Elf32_Shdr *paShdrs = (Elf32_Shdr *)RTMemTmpAlloc(cb);
     287    if (!paShdrs)
     288        return;
     289    rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, Module.shdrs), paShdrs, cb);
     290    if (RT_SUCCESS(rc))
     291    {
     292        void *pvSymSpace = RTMemTmpAlloc(Module.symsize + 1);
     293        if (pvSymSpace)
     294        {
     295            rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, Module.shdrs), pvSymSpace, Module.symsize);
     296            if (RT_SUCCESS(rc))
     297            {
     298                ((uint8_t *)pvSymSpace)[Module.symsize] = 0;
     299
     300                /*
     301                 * Hand it over to the common ELF32 module parser.
     302                 */
     303                char const *pbStrings = (char const *)pvSymSpace + (Module.strings - Module.symspace);
     304                size_t cbMaxStrings = Module.symsize - (Module.strings - Module.symspace);
     305
     306                Elf32_Sym const *paSyms = (Elf32_Sym const *)((uintptr_t)pvSymSpace + (Module.symtbl - Module.symspace));
     307                size_t cMaxSyms = (Module.symsize - (Module.symtbl - Module.symspace)) / sizeof(Elf32_Sym);
     308                cMaxSyms = RT_MIN(cMaxSyms, Module.nsyms);
     309
     310                DBGDiggerCommonParseElf32Mod(pVM, szModName, szFilename, DBG_DIGGER_ELF_FUNNY_SHDRS,
     311                                             &Module.hdr, paShdrs, paSyms, cMaxSyms, pbStrings, cbMaxStrings);
     312            }
     313            RTMemTmpFree(pvSymSpace);
     314        }
     315    }
     316
     317    RTMemTmpFree(paShdrs);
     318    return;
    128319}
    129320
     
    247438
    248439            /* process it. */
    249 
     440            dbgDiggerSolarisProcessModCtl(pVM, pThis, &ModCtl);
    250441
    251442            /* next */
  • trunk/src/VBox/Debugger/Makefile.kmk

    r8800 r8820  
    5757        DBGCOps.cpp \
    5858        DBGCTcp.cpp \
    59         DBGPlugInSolaris.cpp
     59        DBGPlugInSolaris.cpp \
     60        DBGPlugInCommonELF.cpp
    6061
    6162
  • trunk/src/VBox/Debugger/testcase/tstDBGCStubs.cpp

    r8800 r8820  
    159159
    160160#include <VBox/dbgf.h>
    161 DBGFR3DECL(void) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr)
     161DBGFR3DECL(PDBGFADDRESS) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr)
    162162{
    163163}
     
    286286    return VERR_INTERNAL_ERROR;
    287287}
     288DBGFR3DECL(int) DBGFR3MemReadString(PVM pVM, PCDBGFADDRESS pAddress, char *pszBuf, size_t cchBuf)
     289{
     290    return VERR_INTERNAL_ERROR;
     291}
    288292DBGFR3DECL(void) DBGFR3AddrFromPhys(PVM pVM, PDBGFADDRESS pAddress, RTGCPHYS PhysAddr)
    289293{
     
    301305    return VERR_INTERNAL_ERROR;
    302306}
     307DBGFR3DECL(int) DBGFR3SymbolAdd(PVM pVM, RTGCUINTPTR ModuleAddress, RTGCUINTPTR SymbolAddress, RTUINT cbSymbol, const char *pszSymbol)
     308{
     309    return VERR_INTERNAL_ERROR;
     310}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette