Changeset 3236 for trunk/tools


Ignore:
Timestamp:
Mar 25, 2000, 10:10:00 PM (25 years ago)
Author:
bird
Message:

Backup checkin.

Location:
trunk/tools/dbginfo
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/dbginfo/dbgLXDumper.c

    r3222 r3236  
    1 /* $Id: dbgLXDumper.c,v 1.1 2000-03-24 18:13:44 bird Exp $
     1/* $Id: dbgLXDumper.c,v 1.2 2000-03-25 21:09:58 bird Exp $
    22 *
    33 * dbgLXDumper - reads and interprets the debuginfo found in an LX executable.
     
    1515#define INCL_DOSERRORS
    1616#define FOR_EXEHDR          1           /* exe386.h flag */
    17 #define DWORD ULONG
    18 #define WORD USHORT
     17#define DWORD               ULONG       /* Used by exe386.h / newexe.h */
     18#define WORD                USHORT      /* Used by exe386.h / newexe.h */
    1919
    2020/*******************************************************************************
     
    2424#include <newexe.h>
    2525#include <exe386.h>
     26
     27#include <malloc.h>
    2628#include <string.h>
    2729#include <stdio.h>
    28 #include <malloc.h>
     30#include <stddef.h>
    2931#include <ctype.h>
    3032
     
    3638*   Internal Functions                                                         *
    3739*******************************************************************************/
    38 static int          dbgLXDump(void *pvFile);
    39 static int          dumpHLL(FILE *phOut, PBYTE pb, int cb);
    40 static void         dumpHex(FILE *phOut, PBYTE pb, int cb);
    41 static void *       readfile(const char *pszFilename);
    42 static signed long  fsize(FILE *phFile);
    43 
    44 
    45 
    46 
     40int          dbgLXDump(void *pvFile);
     41int          dumpHLL(FILE *phOut, PBYTE pb, int cb);
     42void         dumpHex(FILE *phOut, PBYTE pb, int cb);
     43void *       readfile(const char *pszFilename);
     44signed long  fsize(FILE *phFile);
     45
     46
     47
     48/*******************************************************************************
     49*   Global Variables                                                           *
     50*******************************************************************************/
     51static char achBufferDummy64[0x10000] = {0};
     52char achBufferDummy128[0x20000] = {0};
    4753
    4854int main(int argc, char **argv)
     
    7480 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    7581 */
    76 static int dbgLXDump(void *pvFile)
     82int dbgLXDump(void *pvFile)
    7783{
    7884    struct exe_hdr * pehdr = (struct exe_hdr *) pvFile;
     
    133139                case '4':
    134140                    printf("Found 32-bit OS/2 PM Debugger format (HLL)\n");
    135                     return dumpHLL(stdout, pbDbg + 4, pe32->e32_debuglen - 4);
     141                    return dumpHLL(stdout, pbDbg, pe32->e32_debuglen);
    136142
    137143                default:
     
    162168 * Dumps binary data to file handle.
    163169 * @param     phOut  Output file handle.
    164  * @param     pb     Pointer to debug data.
     170 * @param     pb     Pointer to debug data. (Starts with signature ('NB04').)
    165171 * @param     cb     Size of debug data.
    166172 *
     
    171177 *
    172178 */
    173 static int dumpHLL(FILE *phOut, PBYTE pb, int cb)
     179int dumpHLL(FILE *phOut, PBYTE pb, int cb)
    174180{
    175181    PHLLDIR     pDir;
    176     ULONG       offDir;
    177182    int         i;
     183    PHLLHDR     pHdr = (PHLLHDR)pb;
    178184
    179185    /*
    180      * Get number of entries.
     186     * Dump header.
    181187     */
    182     offDir = *(PULONG)pb;
    183     if (offDir + 4 >= cb)
     188    fprintf(phOut,
     189            "- HLL header -\n"
     190            "    Signature          %.4s\n"
     191            "    Directory offset   0x%08x (%d)\n"
     192            "    reserved           0x%08x (%d)\n"
     193            "\n",
     194            pHdr->achSignature,
     195            pHdr->offDirectory,
     196            pHdr->offDirectory,
     197            pHdr->ulReserved,
     198            pHdr->ulReserved);
     199
     200
     201    /*
     202     * Get and Dump directory
     203     */
     204    if (pHdr->offDirectory + sizeof(HLLDIR) >= cb)
    184205    {
    185206        fprintf(phOut, "error: offcEntries is incorrect!\n");
    186207        return ERROR_INVALID_DATA;
    187208    }
    188     pDir = (PHLLDIR)(pb + offDir);
    189     fprintf(phOut, "Directory offset=0x%08x  cEntries=%d(0x%x)\n",
    190             offDir, pDir->cEntries, pDir->cEntries);
     209    pDir = (PHLLDIR)(pb + pHdr->offDirectory);
     210    fprintf(phOut,
     211            "- HLL Directory -\n"
     212            "    Reserved           0x%08x (%d)\n"
     213            "    Number of entries  0x%08x (%d)\n",
     214            pDir->ulReserved,
     215            pDir->ulReserved,
     216            pDir->cEntries,
     217            pDir->cEntries);
    191218
    192219
    193220    /*
    194      * Directory sanity check.
     221     * Directory sanity check - check that it's not too big
    195222     */
    196223    if ((PBYTE)&pDir->aEntries[pDir->cEntries] - pb >= cb)
     
    207234    for (i = 0; i < pDir->cEntries; i++)
    208235    {
    209         fprintf(phOut, "Directory Entry %d (0x%x):\n", i, i);
    210         fprintf(phOut, "    usType  0x%08x (%d)\n"
     236        /*
     237         * Directory entry type descriptions.
     238         */
     239        static const char * apsz[] =
     240        {
     241            "HLL_DE_MODULES",
     242            "HLL_DE_PUBLICS",
     243            "HLL_DE_TYPES",
     244            "HLL_DE_SYMBOLS",
     245            "HLL_DE_SRCLINES",
     246            "HLL_DE_LIBRARIES",
     247            "unknown",
     248            "unknown",
     249            "HLL_DE_SRCLNSEG",
     250            "unknown",
     251            "HLL_DE_IBMSRC"
     252        };
     253        const char *pszType = pDir->aEntries[i].usType >= HLL_DE_MODULES
     254                              && pDir->aEntries[i].usType <= HLL_DE_IBMSRC
     255                              ? apsz[pDir->aEntries[i].usType - HLL_DE_MODULES]
     256                              : "unknown";
     257
     258        /*
     259         * Dump directroy info.
     260         */
     261        fprintf(phOut, "\n"
     262                       "- HLL Directory Entry %d (0x%x): -\n", i, i);
     263        fprintf(phOut, "    usType  0x%08x (%d) %s\n"
    211264                       "    iMod    0x%08x (%d)\n"
    212265                       "    off     0x%08x (%d)\n"
     
    214267                       pDir->aEntries[i].usType,
    215268                       pDir->aEntries[i].usType,
     269                       pszType,
    216270                       pDir->aEntries[i].iMod,
    217271                       pDir->aEntries[i].iMod,
     
    222276                );
    223277
     278
     279
     280        /*
     281         * Switch between the different entry types to do individual
     282         * processing.
     283         */
    224284        switch (pDir->aEntries[i].usType)
    225285        {
    226             case HLL_DE_MODULES:        /* Filename */
    227                 printf("    Modulename:     %*.s\n",
    228                        pDir->aEntries[i].cb,
    229                        pDir->aEntries[i].off + pb);
    230                 dumpHex(phOut, pDir->aEntries[i].off + pb, pDir->aEntries[i].cb);
    231                 break;
     286            /*
     287             * Module - debuginfo on an object/source module.
     288             */
     289            case HLL_DE_MODULES:
     290            {
     291                PHLLMODULE  pModule = (PHLLMODULE)(pDir->aEntries[i].off + pb);
     292                PHLLOBJECT  paObjects;
     293                int         j, c;
     294
     295                /*
     296                 * Dump module entry data.
     297                 */
     298                fprintf(phOut,
     299                        "    Modulename:   %.*s\n"
     300                        "    overlay       %d\n"
     301                        "    ilib          %d\n"
     302                        "    pad           %d\n"
     303                        "    usDebugStyle  %#04x %c%c\n"
     304                        "    HLL Version   %d.%d\n"
     305                        "    cchName       %d\n"
     306                        ,
     307                        pModule->cchName,
     308                        &pModule->achName[0],
     309                        pModule->overlay,
     310                        pModule->iLib,
     311                        pModule->pad,
     312                        pModule->usDebugStyle,
     313                        pModule->usDebugStyle & 0xFF,
     314                        pModule->usDebugStyle >> 8,
     315                        pModule->chVerMajor,
     316                        pModule->chVerMinor,
     317                        pModule->cchName
     318                        );
     319
     320
     321                /*
     322                 * Dump object data
     323                 */
     324                fprintf(phOut,
     325                        "    Object %d\n"
     326                        "      iObj %#x\n"
     327                        "      off  %#x\n"
     328                        "      cb   %#x\n",
     329                        0,
     330                        pModule->Object.iObj,
     331                        pModule->Object.off,
     332                        pModule->Object.cb);
     333
     334                c = pModule->cObjects > 0 ? pModule->cObjects : 0;
     335                paObjects = (PHLLOBJECT)((void*)&pModule->achName[pModule->cchName]);
     336                for (j = 0; j < c; j++)
     337                {
     338                    fprintf(phOut,
     339                        "    Object %d\n"
     340                        "      iObj %#x\n"
     341                        "      off  %#x\n"
     342                        "      cb   %#x\n",
     343                        j + 1,
     344                        paObjects[j].iObj,
     345                        paObjects[j].off,
     346                        paObjects[j].cb);
     347                }
     348                break;
     349            }
     350
    232351
    233352            case HLL_DE_PUBLICS:        /* Public symbols */
    234                 break;
     353            {
     354                PHLLPUBLICSYM   pPubSym = (PHLLPUBLICSYM)(pDir->aEntries[i].off + pb);
     355
     356                while ((char *)pPubSym - pb - pDir->aEntries[i].off < pDir->aEntries[i].cb)
     357                {
     358                    fprintf(phOut,
     359                            "    %#03x:%#08x iType=%#2x  name=%.*s\n",
     360                            pPubSym->iObj,
     361                            pPubSym->off,
     362                            pPubSym->iType,
     363                            pPubSym->cchName,
     364                            pPubSym->achName);
     365
     366                    /* next */
     367                    pPubSym = (PHLLPUBLICSYM)&pPubSym->achName[pPubSym->cchName];
     368                }
     369                break;
     370            }
     371
    235372
    236373            case HLL_DE_TYPES:          /* Types */
     
    274411 * @param     cb     Count of bytes to dump.
    275412 */
    276 static void dumpHex(FILE *phOut, PBYTE pb, int cb)
     413void dumpHex(FILE *phOut, PBYTE pb, int cb)
    277414{
    278415    int i;
     
    324461 *            time (DosRead + DosOpen) - about 70% of the execution time!
    325462 */
    326 static void *readfile(const char *pszFilename)
     463void *readfile(const char *pszFilename)
    327464{
    328465    void *pvFile = NULL;
     
    360497 * @param     phFile  File handle.
    361498 */
    362 static signed long fsize(FILE *phFile)
     499signed long fsize(FILE *phFile)
    363500{
    364501    int ipos;
  • trunk/tools/dbginfo/hll.h

    r3222 r3236  
    1 /* $Id: hll.h,v 1.1 2000-03-24 18:13:45 bird Exp $
     1/* $Id: hll.h,v 1.2 2000-03-25 21:09:59 bird Exp $
    22 *
    33 * HLL definitions.
     
    1919
    2020/*
    21  * Directory entry types.
     21 * HLL Directory entry types.
    2222 */
    2323#define HLL_DE_MODULES          0x0101  /* Filename */
     
    3131
    3232
     33/*
     34 * HLL Module debug style
     35 */
     36#define HLL_MOD_STYLE           0x4C48  /* 'HL' */
     37
     38
     39/*
     40 * HLL Public symbol wide flag.
     41 */
     42#define HLL_PFS_WIDE            0x6e    /* Wide flag. */
     43
     44
    3345
    3446/*******************************************************************************
     
    3749
    3850/*
    39  * HLL HDR Entry.
     51 * HLL Header
     52 */
     53typedef struct _HLLHdr
     54{
     55    unsigned char   achSignature[4];    /* LX Debug Info Signature, 'NB04' */
     56    unsigned long   offDirectory;       /* Offset to the HLL Directory.
     57                                         * (Relative to start of this header.) */
     58    unsigned long   ulReserved;         /* Unknown field. Seems to be 1. */
     59} HLLHDR, *PHLLHDR;
     60
     61
     62/*
     63 * HLL Directory Entry.
    4064 */
    4165typedef struct _HLLDirEntry
    4266{
    43     unsigned short  usType;
    44     unsigned short  iMod;
    45     unsigned long   off;
    46     unsigned long   cb;
     67    unsigned short  usType;             /* Entry type. HLL_DE_* flag. */
     68    unsigned short  iMod;               /* Module number data applies to. */
     69    unsigned long   off;                /* Offset to data. This is based at
     70                                         * the start of the start of the debug
     71                                         * info. */
     72    unsigned long   cb;                 /* Size of data. */
    4773} HLLDIRENTRY, *PHLLDIRENTRY;
    4874
     
    5480typedef struct _HLLDirectory
    5581{
    56     unsigned long   cEntries;
    57     HLLDIRENTRY     aEntries[1];
     82    unsigned long   ulReserved;         /* Unknown. */
     83    unsigned long   cEntries;           /* Count of directory entires. */
     84    HLLDIRENTRY     aEntries[1];        /* Directory. */
    5885} HLLDIR, *PHLLDIR;
    5986
     87
     88/*
     89 * HLL Object (LX Object = NE/OMF Segment)
     90 */
     91typedef struct _HLLObject /*segment*/
     92{
     93    unsigned short  iObj;               /* LX Object number. */
     94    unsigned long   off;                /* Offset into the load image. */
     95    unsigned long   cb;                 /* Object length. */
     96} HLLOBJECT, *PHLLOBJECT;
     97
     98
     99/*
     100 * HLL Module (file)
     101 */
     102typedef struct _HLLModule
     103{
     104    HLLOBJECT       Object;             /* Description of an object. */
     105    unsigned short  overlay;            /* unused. */
     106    unsigned short  iLib;               /* Library number it came from. */
     107    unsigned char   cObjects;           /* Number of objects.*/
     108    unsigned char   pad;                /* 1 byte padding. */
     109    unsigned short  usDebugStyle;       /* Debug style -'HL' */
     110    unsigned char   chVerMinor;         /* HLL version - minor number. */
     111    unsigned char   chVerMajor;         /* HLL version - major number. */
     112    unsigned char   cchName;            /* Filename length. */
     113    unsigned char   achName[1];         /* Filename. (*) */
     114    /* HLLOBJECT     aObjects[] */      /* Array of object descriptions. (Starts at achName[cchName+1]) */
     115} HLLMODULE, *PHLLMODULE;
     116
     117
     118/*
     119 * HLL Public Symbols
     120 */
     121typedef struct _HLLPublicSymbol
     122{
     123    unsigned long   off;                /* 32-bit offset (into the LX object) of the symbol location. */
     124    unsigned short  iObj;               /* LX Object number. */
     125    unsigned short  iType;              /* Symbol type index (into the type info data). */
     126    unsigned char   cchName;            /* Size of name. */
     127    unsigned char   achName[1];         /* Name (*) */
     128} HLLPUBLICSYM, *PHLLPUBLICSYM;
    60129
    61130
Note: See TracChangeset for help on using the changeset viewer.