Ignore:
Timestamp:
Aug 20, 2007, 5:42:03 AM (18 years ago)
Author:
bird
Message:

Made the generic pe module build too.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/kDbg/kDbgModWinDbgHelp.cpp

    r3529 r3530  
    6363 * A dbghelp based PE debug reader.
    6464 */
    65 typedef struct KDBGMODPE
     65typedef struct KDBGMODDBGHELP
    6666{
    6767    /** The common module core. */
    68     KDBGMOD    Core;
     68    KDBGMOD     Core;
    6969    /** The image base. */
    7070    DWORD64     ImageBase;
     
    7878     * implicit header section.*/
    7979    IMAGE_SECTION_HEADER    aSections[1];
    80 } KDBGMODPE, *PKDBGMODPE;
     80} KDBGMODDBGHELP, *PKDBGMODDBGHELP;
    8181
    8282
     
    102102 * @returns IPRT status code.
    103103 *
    104  * @param   pModPe      The PE debug module instance.
     104 * @param   pModDH      The PE debug module instance.
    105105 * @param   iSegment    The segment number. Special segments are dealt with as well.
    106106 * @param   off         The segment offset.
    107107 * @param   puRVA       Where to store the RVA on success.
    108108 */
    109 static int kDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
     109static int kDbgModPeSegOffToRVA(PKDBGMODDBGHELP pModDH, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
    110110{
    111111    if (iSegment >= 0)
    112112    {
    113         kDbgAssertMsgReturn(iSegment < pModPe->cSections, ("iSegment=%x cSections=%x\n", iSegment, pModPe->cSections),
     113        kDbgAssertMsgReturn(iSegment < pModDH->cSections, ("iSegment=%x cSections=%x\n", iSegment, pModDH->cSections),
    114114                            KDBG_ERR_INVALID_ADDRESS);
    115         kDbgAssertMsgReturn(off < pModPe->aSections[iSegment].Misc.VirtualSize,
    116                             ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModPe->aSections[iSegment].Misc.VirtualSize),
     115        kDbgAssertMsgReturn(off < pModDH->aSections[iSegment].Misc.VirtualSize,
     116                            ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModDH->aSections[iSegment].Misc.VirtualSize),
    117117                            KDBG_ERR_INVALID_ADDRESS);
    118         *puRVA = pModPe->aSections[iSegment].VirtualAddress + (uint32_t)off;
     118        *puRVA = pModDH->aSections[iSegment].VirtualAddress + (uint32_t)off;
    119119        return 0;
    120120    }
     
    122122    if (iSegment == KDBGSEG_RVA)
    123123    {
    124         kDbgAssertMsgReturn(off < pModPe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage),
     124        kDbgAssertMsgReturn(off < pModDH->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModDH->cbImage),
    125125                            KDBG_ERR_INVALID_ADDRESS);
    126126        *puRVA = (uint32_t)off;
     
    136136 * @returns IPRT status code.
    137137 *
    138  * @param   pModPe      The PE debug module instance.
     138 * @param   pModDH      The PE debug module instance.
    139139 * @param   uRVA        The RVA.
    140140 * @param   piSegment   Where to store the segment number.
    141141 * @param   poff        Where to store the segment offset.
    142142 */
    143 static int kDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
    144 {
    145     kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage),
    146                     KDBG_ERR_INVALID_ADDRESS);
    147     for (int32_t iSegment = 0; iSegment < pModPe->cSections; iSegment++)
     143static int kDbgModPeRVAToSegOff(PKDBGMODDBGHELP pModDH, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
     144{
     145    kDbgAssertMsgReturn(uRVA < pModDH->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModDH->cbImage),
     146                        KDBG_ERR_INVALID_ADDRESS);
     147    for (int32_t iSegment = 0; iSegment < pModDH->cSections; iSegment++)
    148148    {
    149149        /** @todo should probably be less strict about address in the alignment gaps. */
    150         uint32_t off = uRVA - pModPe->aSections[iSegment].VirtualAddress;
    151         if (off < pModPe->aSections[iSegment].Misc.VirtualSize)
     150        uint32_t off = uRVA - pModDH->aSections[iSegment].VirtualAddress;
     151        if (off < pModDH->aSections[iSegment].Misc.VirtualSize)
    152152        {
    153153            *poff = off;
     
    163163 * @copydoc KDBGMODOPS::pfnQueryLine
    164164 */
    165 static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
    166 {
    167     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     165static int kdbgModDHQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
     166{
     167    PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod;
    168168
    169169    /*
     
    171171     */
    172172    uint32_t uRVA;
    173     int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     173    int rc = kDbgModPeSegOffToRVA(pModDH, iSegment, off, &uRVA);
    174174    if (!rc)
    175175    {
     
    177177        IMAGEHLP_LINE64 Line;
    178178        Line.SizeOfStruct = sizeof(Line);
    179         if (g_pfnSymGetLineFromAddr64(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Line))
    180         {
    181             pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase);
    182             rc = kDbgModPeRVAToSegOff(pModPe, (uint32_t)pLine->RVA, &pLine->iSegment, &pLine->offSegment);
     179        if (g_pfnSymGetLineFromAddr64(pModDH->hSymInst, pModDH->ImageBase + uRVA, &off, &Line))
     180        {
     181            pLine->RVA = (KDBGADDR)(Line.Address - pModDH->ImageBase);
     182            rc = kDbgModPeRVAToSegOff(pModDH, (uint32_t)pLine->RVA, &pLine->iSegment, &pLine->offSegment);
    183183            pLine->iLine = Line.LineNumber;
    184184            size_t cchFile = strlen(Line.FileName);
     
    202202 * @copydoc KDBGMODOPS::pfnQuerySymbol
    203203 */
    204 static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
    205 {
    206     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
     204static int kdbgModDHQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
     205{
     206    PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod;
    207207
    208208    /*
     
    210210     */
    211211    uint32_t uRVA;
    212     int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     212    int rc = kDbgModPeSegOffToRVA(pModDH, iSegment, off, &uRVA);
    213213    if (!rc)
    214214    {
     
    221221        Buf.Sym.SizeOfStruct = sizeof(SYMBOL_INFO);
    222222        Buf.Sym.MaxNameLen = KDBG_SYMBOL_MAX;
    223         if (g_pfnSymFromAddr(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Buf.Sym))
     223        if (g_pfnSymFromAddr(pModDH->hSymInst, pModDH->ImageBase + uRVA, &off, &Buf.Sym))
    224224        {
    225225            pSym->cb     = Buf.Sym.Size;
     
    241241            else
    242242            {
    243                 pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase);
    244                 rc = kDbgModPeRVAToSegOff(pModPe, (uint32_t)pSym->RVA, &pSym->iSegment, &pSym->offSegment);
     243                pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModDH->ImageBase);
     244                rc = kDbgModPeRVAToSegOff(pModDH, (uint32_t)pSym->RVA, &pSym->iSegment, &pSym->offSegment);
    245245            }
    246246            pSym->cchName = (uint16_t)Buf.Sym.NameLen;
     
    263263 * @copydoc KDBGMODOPS::pfnClose
    264264 */
    265 static int rtDbgModPEClose(PKDBGMOD pMod)
    266 {
    267     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
    268 
    269     if (g_pfnSymCleanup(pModPe->hSymInst))
     265static int kdbgModDHClose(PKDBGMOD pMod)
     266{
     267    PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod;
     268
     269    if (g_pfnSymCleanup(pModDH->hSymInst))
    270270        return 0;
    271271
     
    280280 * Methods for a PE module.
    281281 */
    282 static const KDBGMODOPS g_rtDbgModPEOps =
     282static const KDBGMODOPS g_kdbgModDHOps =
    283283{
    284284    "PE (dbghelp)",
    285     rtDbgModPEClose,
    286     rtDbgModPEQuerySymbol,
    287     rtDbgModPEQueryLine
     285    kdbgModDHClose,
     286    kdbgModDHQuerySymbol,
     287    kdbgModDHQueryLine
    288288};
    289289
     
    296296 * @param   pszPath     the path to the dbghelp.dll.
    297297 */
    298 static int rtDbgModPETryDbgHelp(const char *pszPath, uint32_t *pu32FileVersionMS, uint32_t *pu32FileVersionLS)
     298static int kdbgModDHTryDbgHelp(const char *pszPath, uint32_t *pu32FileVersionMS, uint32_t *pu32FileVersionLS)
    299299{
    300300    int rc;
     
    337337 * Find the dbghelp.dll
    338338 */
    339 static int rtDbgModPEFindDbgHelp(char *pszPath, size_t cchPath)
     339static int kdbgModDHFindDbgHelp(char *pszPath, size_t cchPath)
    340340{
    341341    /*
     
    349349    {
    350350        strcat(pszPath, s_szDbgHelp);
    351         int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
     351        int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    352352        if (!rc2)
    353353            return rc2;
     
    362362    {
    363363        strcat(strrchr(pszPath, '\\'), s_szDbgHelp);
    364         int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
     364        int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    365365        if (!rc)
    366366            return rc2;
     
    375375    {
    376376        strcat(pszPath, s_szDbgHelp);
    377         int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
     377        int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    378378        if (!rc2)
    379379            return rc2;
     
    388388    {
    389389        strcat(pszPath, s_szDbgHelp);
    390         int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
     390        int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    391391        if (!rc2)
    392392            return rc2;
     
    415415                memcpy(pszPath, psz, pszEnd - psz);
    416416                memcpy(&pszPath[pszEnd - psz], s_szDbgHelp, sizeof(s_szDbgHelp));
    417                 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
     417                int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    418418                if (!rc2)
    419419                    return rc2;
     
    447447 * @returns IPRT status code.
    448448 */
    449 static int rtDbgModPELoadDbgHelp(void)
     449static int kdbgModDHLoadDbgHelp(void)
    450450{
    451451    if (g_hDbgHelp)
     
    467467     */
    468468    char szPath[260];
    469     int rc = rtDbgModPEFindDbgHelp(szPath, sizeof(szPath));
     469    int rc = kdbgModDHFindDbgHelp(szPath, sizeof(szPath));
    470470    if (rc)
    471471    {
     
    566566 *
    567567 */
    568 int kdbgModPEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
     568int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
    569569{
    570570    /*
     
    589589     * Load dbghelp.dll.
    590590     */
    591     rc = rtDbgModPELoadDbgHelp();
     591    rc = kdbgModDHLoadDbgHelp();
    592592    if (rc)
    593593        return rc;
     
    596596     * Allocate the module and read/construct the section headers.
    597597     */
    598     PKDBGMODPE pModPe = (PKDBGMODPE)kDbgHlpAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2]));
    599     kDbgAssertReturn(pModPe, KDBG_ERR_NO_MEMORY);
    600     pModPe->Core.u32Magic   = KDBGMOD_MAGIC;
    601     pModPe->Core.pOps       = &g_rtDbgModPEOps;
    602     pModPe->Core.pFile      = pFile;
    603     pModPe->cbImage         = cbImage;
    604     pModPe->cSections       = 1 + FHdr.NumberOfSections;
     598    PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)kDbgHlpAlloc(KDBG_OFFSETOF(KDBGMODDBGHELP, aSections[FHdr.NumberOfSections + 2]));
     599    kDbgAssertReturn(pModDH, KDBG_ERR_NO_MEMORY);
     600    pModDH->Core.u32Magic   = KDBGMOD_MAGIC;
     601    pModDH->Core.pOps       = &g_kdbgModDHOps;
     602    pModDH->Core.pFile      = pFile;
     603    pModDH->cbImage         = cbImage;
     604    pModDH->cSections       = 1 + FHdr.NumberOfSections;
    605605    rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,
    606                        &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections);
     606                       &pModDH->aSections[1], sizeof(pModDH->aSections[0]) * FHdr.NumberOfSections);
    607607    if (!rc)
    608608    {
    609         PIMAGE_SECTION_HEADER pSH = &pModPe->aSections[0];
     609        PIMAGE_SECTION_HEADER pSH = &pModDH->aSections[0];
    610610        memcpy(pSH->Name, "headers", sizeof(pSH->Name));
    611         pSH->Misc.VirtualSize       = pModPe->aSections[1].VirtualAddress;
     611        pSH->Misc.VirtualSize       = pModDH->aSections[1].VirtualAddress;
    612612        pSH->VirtualAddress         = 0;
    613613        pSH->SizeOfRawData          = pSH->Misc.VirtualSize;
     
    619619        pSH->Characteristics        = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ;
    620620
    621         uint32_t uTheEnd = pModPe->aSections[FHdr.NumberOfSections].VirtualAddress
    622                          + pModPe->aSections[FHdr.NumberOfSections].Misc.VirtualSize;
     621        uint32_t uTheEnd = pModDH->aSections[FHdr.NumberOfSections].VirtualAddress
     622                         + pModDH->aSections[FHdr.NumberOfSections].Misc.VirtualSize;
    623623        if (uTheEnd < cbImage)
    624624        {
    625             pSH = &pModPe->aSections[pModPe->cSections++];
     625            pSH = &pModDH->aSections[pModDH->cSections++];
    626626            memcpy(pSH->Name, "tail\0\0\0", sizeof(pSH->Name));
    627627            pSH->Misc.VirtualSize       = cbImage - uTheEnd;
     
    661661            if (ImageBase)
    662662            {
    663                 pModPe->hSymInst    = hSymInst;
    664                 pModPe->ImageBase   = ImageBase;
    665                 *ppDbgMod = &pModPe->Core;
     663                pModDH->hSymInst    = hSymInst;
     664                pModDH->ImageBase   = ImageBase;
     665                *ppDbgMod = &pModDH->Core;
    666666                return rc;
    667667            }
     
    682682        kDbgAssertRC(rc);
    683683
    684     kDbgHlpFree(pModPe);
     684    kDbgHlpFree(pModDH);
    685685    return rc;
    686686}
Note: See TracChangeset for help on using the changeset viewer.