Changeset 3534


Ignore:
Timestamp:
Aug 23, 2007, 2:28:15 AM (18 years ago)
Author:
bird
Message:

hacking

Location:
trunk/kDbg
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/kDbg/Makefile.kmk

    r3530 r3534  
    6161## kDbgDump - Test program which dumps whatever is thrown at it.
    6262##
    63 #PROGRAMS += kDbgDump
     63PROGRAMS += kDbgDump
    6464kDbgDump_TEMPLATE = kStuffEXE
    6565kDbgDump_SOURCES = kDbgDump.cpp
    66 kDbgDump_LIBS = $(TARGET_kDbgStatic)
     66kDbgDump_LIBS = \
     67        $(TARGET_kDbgStatic) \
     68        $(TARGET_kDbgStatic:kDbgStatic=kLdrStatic)
    6769
    6870# Generate the rules
  • trunk/kDbg/kDbgHlp.h

    r3529 r3534  
    278278#else   /* !KDBG_STRICT */
    279279# define kDbgAssert(expr)                       do { } while (0)
    280 # define kDbgAssertReturn(expr, rcRet)          return (rcRet)
     280# define kDbgAssertReturn(expr, rcRet)          do { if (!(expr)) return (rcRet); } while (0)
    281281# define kDbgAssertMsg(expr, msg)               do { } while (0)
    282 # define kDbgAssertMsgReturn(expr, msg, rcRet)  return (rcRet)
     282# define kDbgAssertMsgReturn(expr, msg, rcRet)  do { if (!(expr)) return (rcRet); } while (0)
    283283#endif  /* !KDBG_STRICT */
    284284
    285 #define kDbgAssertPtr(ptr)                      kDbgAssertMsg(VALID_PTR(expr), ("%s = %p\n", #ptr, (ptr)))
    286 #define kDbgAssertPtrReturn(ptr, rcRet)         kDbgAssertMsgReturn(VALID_PTR(expr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet))
     285#define kDbgAssertPtr(ptr)                      kDbgAssertMsg(KDBG_VALID_PTR(ptr), ("%s = %p\n", #ptr, (ptr)))
     286#define kDbgAssertPtrReturn(ptr, rcRet)         kDbgAssertMsgReturn(KDBG_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet))
    287287#define kDbgAssertRC(rc)                        kDbgAssertMsg((rc) == 0, ("%s = %d\n", #rc, (rc)))
    288288#define kDbgAssertRCReturn(rc, rcRet)           kDbgAssertMsgReturn((rc) == 0, ("%s = %d -> %d\n", #rc, (rc), (rcRet)), (rcRet))
  • trunk/kDbg/kDbgInternal.h

    r3530 r3534  
    4343    const char *pszName;
    4444
     45    /** Pointer to the next debug module readers.
     46     * This is only used for dynamically registered readers. */
     47    struct KDBGMODOPS  *pNext;
     48
     49    /**
     50     * Tries to open the module.
     51     *
     52     * @returns 0 on success, KDBG_ERR on failure.
     53     * @param   pFile           The file
     54     * @param   off             The file offset of the debug info. This is 0 if there isn't
     55     *                          any specfic debug info section and the reader should start
     56     *                          looking for debug info at the start of the file.
     57     * @param   cb              The size of the debug info in the file. INT64_MAX if we don't
     58     *                          know or there isn't any particular debug info section in the file.
     59     * @param   pLdrMod         The associated loader module. This can be NULL.
     60     * @param   ppMod           Where to store the module that's been opened.
     61     *
     62     * @remark  This is NULL for the builtin readers.
     63     */
     64    int (*pfnOpen)(PKDBGHLPFILE pFile, int64_t off, int64_t cb, PKLDRMOD pLdrMod, PKDBGMOD pMod);
     65
    4566    /**
    4667     * Closes the module.
     
    5879     * This will be approximated to the nearest symbol if there is no exact match.
    5980     *
    60      * @returns IPRT status code.
     81     * @returns 0 on success. KLDR_ERR_* on failure.
    6182     * @param   pMod        The module.
    6283     * @param   iSegment    The segment this offset is relative to.
     
    7394     * This will be approximated to the nearest line number there is no exact match.
    7495     *
    75      * @returns IPRT status code.
     96     * @returns 0 on success. KLDR_ERR_* on failure.
    7697     * @param   pMod        The module.
    7798     * @param   iSegment    The segment this offset is relative to.
     
    112133
    113134int kdbgModPEOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod);
    114 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod);
     135int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, const char *pszModulePath, PKDBGMOD *ppDbgMod);
    115136
    116137#ifdef __cplusplus
  • trunk/kDbg/kDbgModPE.cpp

    r3530 r3534  
    101101{
    102102    kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage),
    103                     KDBG_ERR_INVALID_ADDRESS);
     103                        KDBG_ERR_INVALID_ADDRESS);
    104104    for (int32_t iSegment = 0; iSegment < pModPe->cSections; iSegment++)
    105105    {
  • trunk/kDbg/kDbgModWinDbgHelp.cpp

    r3531 r3534  
    431431    if (rc == KDBG_ERR_DBGHLP_VERSION_MISMATCH)
    432432        kDbgAssertMsgFailed(("dbghelp.dll found, but it was ancient! The highest file version found was 0x%08x'%08x.\n"
    433                          "This program require a file version of at least 0x00060004'00000000. Please download\n"
    434                          "the latest windbg and use the dbghelp.dll from that package. Just put it somewhere in\n"
    435                          "the PATH and we'll find it.\n", FileVersionMS, FileVersionLS));
     433                             "This program require a file version of at least 0x00060004'00000000. Please download\n"
     434                             "the latest windbg and use the dbghelp.dll from that package. Just put it somewhere in\n"
     435                             "the PATH and we'll find it.\n", FileVersionMS, FileVersionLS));
    436436    else
    437437        kDbgAssertMsgFailed(("dbghelp.dll was not found! Download the latest windbg and use the dbghelp.dll\n"
    438                          "from that package - just put it somewhere in the PATH and we'll find it.\n"));
     438                             "from that package - just put it somewhere in the PATH and we'll find it.\n"));
    439439    return rc;
    440440}
     
    566566 *
    567567 */
    568 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
     568int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, PKDBGMOD *ppDbgMod)
    569569{
    570570    /*
  • trunk/kDbg/kDbgModule.cpp

    r3530 r3534  
    3030*******************************************************************************/
    3131#include "kDbg.h"
     32#include "kLdr.h"
    3233#include "kDbgInternal.h"
    3334
     
    3536#include <kLdrModPE.h>
    3637
     38
     39/*******************************************************************************
     40*   Global Variables                                                           *
     41*******************************************************************************/
     42
     43
     44
     45KDBG_DECL(int) kDbgModuleOpenFilePart(PKDBGHLPFILE pFile, int64_t off, int64_t cb, PKDBGMOD *ppDbgMod)
     46{
     47#if KOS_WINDOWS
     48    /*
     49     * If we're on Windows, let DbgHelp have a go first.
     50     */
     51    if (!off)
     52    {
     53        int rc = kdbgModWinDbgHelpOpen(pFile, ppDbgMod);
     54        if (!rc)
     55            return 0;
     56    }
     57#endif
     58
     59    /*
     60     * Probe the file for signatures we recognize.
     61     */
     62    int64_t offHdr = 0;
     63    union
     64    {
     65        uint32_t    au32[4];
     66        uint16_t    au16[8];
     67        uint8_t     ab[16];
     68        char
     69    } Buf;
     70    rc = kDbgHlpReadAt(pFile, &Buf, sizeof(Buf), off);
     71
     72}
     73
     74
     75KDBG_DECL(int) kDbgModuleOpenFile(PKDBGHLPFILE pFile, PKDBGMOD *ppDbgMod)
     76{
     77    return kDbgModuleOpenFilePart(pFile, 0, INT64_MAX, ppDbgMod);
     78}
     79
     80
     81KDBG_DECL(int) kDbgModuleOpenkLdrMod(PKLDRMOD pLdrMod, PKDBGMOD *ppDbgMod)
     82{
     83    /*
     84     * Enumerate the debug info, if nothing found check for a matching .pdb,
     85     * .dbg, .sym or .map file.
     86     */
     87
     88}
    3789
    3890
     
    55107
    56108    /*
    57      * The file and try figure out the format.
     109     * Open the file and see if we can read it.
    58110     */
    59111    PKDBGHLPFILE pFile;
     
    61113    if (rc)
    62114        return rc;
    63 
    64     int64_t offHdr = 0;
    65     union
    66     {
    67         uint32_t    au32[4];
    68         uint16_t    au16[8];
    69         uint8_t     ab[16];
    70     } Buf;
    71     rc = kDbgHlpRead(pFile, &Buf, sizeof(Buf));
    72     if (    !rc
    73         &&  Buf.au16[0] == IMAGE_DOS_SIGNATURE)
    74     {
    75         /* new header? */
    76         uint32_t offNewHeader;
    77         rc = kDbgHlpReadAt(pFile, KDBG_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew), &offNewHeader, sizeof(offNewHeader));
    78         if (!rc && offNewHeader)
     115    rc = kDbgModuleOpenFile(pFile, ppDbgMod);
     116    if (rc)
     117    {
     118        kDbgHlpClose(pFile);
     119
     120        /*
     121         * Let kLdr have a shot at it, if it's a binary it may contain
     122         * some debug sections or a link to an external debug file.
     123         */
     124        PKLDRMOD pLdrMod;
     125        int rc2 = kLdrModOpen(pszModulePath, *pLdrMod);
     126        if (!rc2)
    79127        {
    80             offHdr = offNewHeader;
    81             rc = kDbgHlpReadAt(pFile, offNewHeader, &Buf, sizeof(Buf));
     128            rc = kDbgModuleOpenkLdrMod(pLdrMod, ppDbgMod);
     129            if (rc)
     130                kLdrModClose(pLdrMod);
    82131        }
    83132    }
    84     if (!rc)
    85     {
    86         if (Buf.au16[0] == IMAGE_DOS_SIGNATURE)
    87             rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    88 #ifdef IMAGE_NE_SIGNATURE
    89         else if (Buf.au16[0] == IMAGE_NE_SIGNATURE)
    90             rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    91 #endif
    92 #ifdef IMAGE_LX_SIGNATURE
    93         else if (Buf.au16[0] == IMAGE_LX_SIGNATURE)
    94             rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    95 #endif
    96 #ifdef IMAGE_LE_SIGNATURE
    97         else if (Buf.au16[0] == IMAGE_LE_SIGNATURE)
    98             rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    99 #endif
    100 #ifdef IMAGE_ELF_SIGNATURE
    101         else if (Buf.au32[0] == IMAGE_ELF_SIGNATURE)
    102             rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    103 #endif
    104 #ifdef IMAGE_NT_SIGNATURE
    105         else if (Buf.au32[0] == IMAGE_NT_SIGNATURE)
    106         {
    107 # ifdef KS_OS_WINDOWS
    108             rc = kdbgModWinDbgHelpOpen(pFile, offHdr, pszModulePath, ppDbgMod);
    109             if (    rc
    110                 &&  !kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod))
    111                 rc = 0;
    112 # endif
    113             rc = kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod);
    114         }
    115 #endif
    116         /** @todo there are a number of text file formats too which I want to support. */
    117         else
    118             rc = KDBG_ERR_UNKOWN_FORMAT;
    119     }
    120 
    121     if (rc)
    122         kDbgHlpClose(pFile);
     133
    123134    return rc;
    124135}
Note: See TracChangeset for help on using the changeset viewer.