Changeset 3236 for trunk/tools
- Timestamp:
- Mar 25, 2000, 10:10:00 PM (25 years ago)
- 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:44bird Exp $1 /* $Id: dbgLXDumper.c,v 1.2 2000-03-25 21:09:58 bird Exp $ 2 2 * 3 3 * dbgLXDumper - reads and interprets the debuginfo found in an LX executable. … … 15 15 #define INCL_DOSERRORS 16 16 #define FOR_EXEHDR 1 /* exe386.h flag */ 17 #define DWORD ULONG18 #define WORD USHORT17 #define DWORD ULONG /* Used by exe386.h / newexe.h */ 18 #define WORD USHORT /* Used by exe386.h / newexe.h */ 19 19 20 20 /******************************************************************************* … … 24 24 #include <newexe.h> 25 25 #include <exe386.h> 26 27 #include <malloc.h> 26 28 #include <string.h> 27 29 #include <stdio.h> 28 #include < malloc.h>30 #include <stddef.h> 29 31 #include <ctype.h> 30 32 … … 36 38 * Internal Functions * 37 39 *******************************************************************************/ 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 40 int dbgLXDump(void *pvFile); 41 int dumpHLL(FILE *phOut, PBYTE pb, int cb); 42 void dumpHex(FILE *phOut, PBYTE pb, int cb); 43 void * readfile(const char *pszFilename); 44 signed long fsize(FILE *phFile); 45 46 47 48 /******************************************************************************* 49 * Global Variables * 50 *******************************************************************************/ 51 static char achBufferDummy64[0x10000] = {0}; 52 char achBufferDummy128[0x20000] = {0}; 47 53 48 54 int main(int argc, char **argv) … … 74 80 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 75 81 */ 76 staticint dbgLXDump(void *pvFile)82 int dbgLXDump(void *pvFile) 77 83 { 78 84 struct exe_hdr * pehdr = (struct exe_hdr *) pvFile; … … 133 139 case '4': 134 140 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); 136 142 137 143 default: … … 162 168 * Dumps binary data to file handle. 163 169 * @param phOut Output file handle. 164 * @param pb Pointer to debug data. 170 * @param pb Pointer to debug data. (Starts with signature ('NB04').) 165 171 * @param cb Size of debug data. 166 172 * … … 171 177 * 172 178 */ 173 staticint dumpHLL(FILE *phOut, PBYTE pb, int cb)179 int dumpHLL(FILE *phOut, PBYTE pb, int cb) 174 180 { 175 181 PHLLDIR pDir; 176 ULONG offDir;177 182 int i; 183 PHLLHDR pHdr = (PHLLHDR)pb; 178 184 179 185 /* 180 * Get number of entries.186 * Dump header. 181 187 */ 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) 184 205 { 185 206 fprintf(phOut, "error: offcEntries is incorrect!\n"); 186 207 return ERROR_INVALID_DATA; 187 208 } 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); 191 218 192 219 193 220 /* 194 * Directory sanity check .221 * Directory sanity check - check that it's not too big 195 222 */ 196 223 if ((PBYTE)&pDir->aEntries[pDir->cEntries] - pb >= cb) … … 207 234 for (i = 0; i < pDir->cEntries; i++) 208 235 { 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" 211 264 " iMod 0x%08x (%d)\n" 212 265 " off 0x%08x (%d)\n" … … 214 267 pDir->aEntries[i].usType, 215 268 pDir->aEntries[i].usType, 269 pszType, 216 270 pDir->aEntries[i].iMod, 217 271 pDir->aEntries[i].iMod, … … 222 276 ); 223 277 278 279 280 /* 281 * Switch between the different entry types to do individual 282 * processing. 283 */ 224 284 switch (pDir->aEntries[i].usType) 225 285 { 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 232 351 233 352 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 235 372 236 373 case HLL_DE_TYPES: /* Types */ … … 274 411 * @param cb Count of bytes to dump. 275 412 */ 276 staticvoid dumpHex(FILE *phOut, PBYTE pb, int cb)413 void dumpHex(FILE *phOut, PBYTE pb, int cb) 277 414 { 278 415 int i; … … 324 461 * time (DosRead + DosOpen) - about 70% of the execution time! 325 462 */ 326 staticvoid *readfile(const char *pszFilename)463 void *readfile(const char *pszFilename) 327 464 { 328 465 void *pvFile = NULL; … … 360 497 * @param phFile File handle. 361 498 */ 362 s tatic signed long fsize(FILE *phFile)499 signed long fsize(FILE *phFile) 363 500 { 364 501 int ipos; -
trunk/tools/dbginfo/hll.h
r3222 r3236 1 /* $Id: hll.h,v 1. 1 2000-03-24 18:13:45bird Exp $1 /* $Id: hll.h,v 1.2 2000-03-25 21:09:59 bird Exp $ 2 2 * 3 3 * HLL definitions. … … 19 19 20 20 /* 21 * Directory entry types.21 * HLL Directory entry types. 22 22 */ 23 23 #define HLL_DE_MODULES 0x0101 /* Filename */ … … 31 31 32 32 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 33 45 34 46 /******************************************************************************* … … 37 49 38 50 /* 39 * HLL HDR Entry. 51 * HLL Header 52 */ 53 typedef 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. 40 64 */ 41 65 typedef struct _HLLDirEntry 42 66 { 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. */ 47 73 } HLLDIRENTRY, *PHLLDIRENTRY; 48 74 … … 54 80 typedef struct _HLLDirectory 55 81 { 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. */ 58 85 } HLLDIR, *PHLLDIR; 59 86 87 88 /* 89 * HLL Object (LX Object = NE/OMF Segment) 90 */ 91 typedef 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 */ 102 typedef 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 */ 121 typedef 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; 60 129 61 130
Note:
See TracChangeset
for help on using the changeset viewer.