Changeset 3614 for trunk/tools
- Timestamp:
- May 27, 2000, 4:15:42 AM (25 years ago)
- Location:
- trunk/tools/dbginfo
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/dbginfo/Sym2Hll.cpp
r3441 r3614 1 /* $Id: Sym2Hll.cpp,v 1. 5 2000-04-24 21:38:11 bird Exp $1 /* $Id: Sym2Hll.cpp,v 1.6 2000-05-27 02:15:41 bird Exp $ 2 2 * 3 3 * Sym2Hll - Symbol file to HLL debuginfo converter. … … 28 28 #include <assert.h> 29 29 30 #include <kList.h> 31 #include <kFile.h> 32 #include <kFileFormatBase.h> 33 #include <kFileLX.h> 34 30 35 #include "hll.h" 31 #include "kList.h"32 36 #include "kHll.h" 33 37 #include "sym.h" 34 #include "kFileFormatBase.h"35 #include "kFileLX.h"36 38 37 39 /******************************************************************************* -
trunk/tools/dbginfo/hll.h
r3286 r3614 1 /* $Id: hll.h,v 1. 5 2000-03-31 15:35:09bird Exp $1 /* $Id: hll.h,v 1.6 2000-05-27 02:15:41 bird Exp $ 2 2 * 3 3 * HLL definitions. … … 17 17 * Defined Constants And Macros * 18 18 *******************************************************************************/ 19 /* 20 * HLL version macros 21 */ 22 #define HLLVERSION100 0x0100 23 #define HLLVERSION300 0x0300 24 #define HLLVERSION400 0x0400 25 #define HLLVERSION500 0x0500 26 #define HLLMAKEVER(major, minor) (int)( ((int)(char)(major) << 8) | (int)(char)(minor) ) 19 27 20 28 /* -
trunk/tools/dbginfo/kHll.cpp
r3441 r3614 1 /* $Id: kHll.cpp,v 1.1 2 2000-04-24 21:38:12bird Exp $1 /* $Id: kHll.cpp,v 1.13 2000-05-27 02:15:41 bird Exp $ 2 2 * 3 3 * kHll - Implementation of the class kHll. … … 29 29 30 30 #include <malloc.h> 31 #define free(a) memset(a, '7', _msize(a)) //overload free for debugging purposes. 32 #define malloc(a) memset(malloc(a), '3', a) //overload free for debugging purposes. 31 33 #include <stdio.h> 32 34 #include <string.h> … … 35 37 #include <assert.h> 36 38 39 #include <kList.h> 40 #include <kFile.h> 41 37 42 #include "hll.h" 38 #include "kList.h"39 43 #include "kHll.h" 40 44 … … 90 94 91 95 96 /** 97 * Loops thru the given list and call the dump function for each 98 * node with the passed in parameters. 99 * @param ph Dump file handle. 100 * @param cchIndent Indent. 101 * @param pEntry Indent. 102 */ 103 void kHllBaseEntry::dumpList(FILE *ph, int cchIndent, kHllBaseEntry *pEntry) 104 { 105 /* 106 * Loop thru the list staring at pEntry and call dump for each entry. 107 */ 108 while (pEntry != NULL) 109 { 110 pEntry->dump(ph, cchIndent); 111 pEntry = (kHllBaseEntry*)pEntry->getNext(); 112 } 113 } 114 115 116 92 117 93 118 … … 100 125 * * 101 126 *******************************************************************************/ 127 128 102 129 103 130 … … 160 187 offsetof(HLLPUBLICSYM, achName) + pPubSym->cchName, 161 188 phFile); 189 } 190 191 192 /** 193 * Dumps the HLL entry to ph in a human readable fashion. 194 * @param ph Output file handle the dump is to be written to. 195 * @param cchIndent Number of char to indents the output dump. 196 */ 197 void kHllPubSymEntry::dump(FILE *ph, int cchIndent) 198 { 199 /* 200 * Dump public symbol entry 201 */ 202 fprintf(ph, "%*.s0x%04x:0x%08x type:%04d(0x%04) name: %.*s\n", 203 cchIndent, "", 204 pPubSym->iObject, 205 pPubSym->off, 206 pPubSym->iType, 207 pPubSym->iType, 208 pPubSym->cchName, pPubSym->achName 209 ); 162 210 } 163 211 … … 283 331 return cbWritten + sizeof(FirstEntry.hll04); 284 332 } 333 334 335 336 /** 337 * Dumps the HLL entry to ph in a human readable fashion. 338 * @param ph Output file handle the dump is to be written to. 339 * @param cchIndent Number of char to indents the output dump. 340 */ 341 void kHllLineNumberChunk::dump(FILE *ph, int cchIndent) 342 { 343 int i; 344 345 /* 346 * Write header. 347 * Dump first entry. 348 * Dump linenumbers. 349 * Write footer. 350 */ 351 fprintf(ph, "%*.s------- start kHllLineNumberChunk object 0x%08x -------\n", 352 cchIndent, "", this); 353 354 /* ASSUMES - TODO - FIXME: HLL version 3 or 4. */ 355 fprintf(ph, "%*.sBaseLine: %04d Type: 0x%02x Entries: 0x%04(%d) iSeg: 0x04x(%d) ", 356 cchIndent, "", 357 FirstEntry.hll04.usLine, 358 FirstEntry.hll04.uchType, 359 FirstEntry.hll04.cEntries, 360 FirstEntry.hll04.cEntries, 361 FirstEntry.hll04.iSeg, 362 FirstEntry.hll04.iSeg 363 ); 364 if (FirstEntry.hll04.uchType == 0) 365 fprintf(ph, "offBase: 0x%08x\n", FirstEntry.hll04.u1.offBase); 366 else 367 fprintf(ph, "u1: 0x%08x\n", FirstEntry.hll04.u1.offBase); 368 369 370 /* ASSUMES - TODO - FIXME: HLL version 3 or 4. */ 371 for (i = 0; i < FirstEntry.hll04.cEntries; i++) 372 fprintf(ph, "%*.sFile: %04d Line: %04d Offset: 0x%08x\n", 373 cchIndent, "", 374 paLines[i].hll04.iusSourceFile, 375 paLines[i].hll04.usLine, 376 paLines[i].hll04.off 377 ); 378 379 380 fprintf(ph, "%*.s------- end kHllLineNumberChunk object 0x%08x -------\n", 381 cchIndent, "", this); 382 } 383 384 285 385 286 386 … … 494 594 495 595 596 /** 597 * Dumps the HLL entry to ph in a human readable fashion. 598 * @param ph Output file handle the dump is to be written to. 599 * @param cchIndent Number of char to indents the output dump. 600 */ 601 void kHllSrcEntry::dump(FILE *ph, int cchIndent) 602 { 603 int i; 604 char * pach; 605 606 /* 607 * Write header with filename count. 608 * Write filenames. 609 * Dump linenumber list. 610 * Write footer with filename count. 611 */ 612 fprintf(ph, "%*.s------- start kHllSrcEntry object 0x%08x --- %d -------\n", 613 cchIndent, "", this, cFilenames); 614 615 for (i = 0, pach = pachFilenames; i < cFilenames; i++, pach += 1 + *pach) 616 fprintf(ph, "%*.s%.2d - %.*s\n", 617 cchIndent, "", 618 i, *pach, pach + 1); 619 620 kHllBaseEntry::dumpList(ph, cchIndent + 4, Lines.getFirst()); 621 622 fprintf(ph, "%*.s------- end kHllSrcEntry object 0x%08x --- %d -------\n", 623 cchIndent, "", this, cFilenames); 624 } 625 626 627 628 496 629 497 630 … … 539 672 */ 540 673 cchName = strlen(pszName); 674 cchName = min(cchName, 255); 541 675 pModule = (PHLLMODULE)malloc(sizeof(HLLMODULE) + cchName + 542 sizeof(HLLSEGINFO) * max((cSegInfo - 1), 3));676 (sizeof(HLLSEGINFO) * max((cSegInfo - 1), 3))); 543 677 assert(pModule != NULL); 544 678 memset(pModule, 0, sizeof(*pModule)); 545 679 pModule->cchName = (unsigned char)cchName; 546 strcpy((char*)&pModule->achName[0], pszName);680 memcpy(&pModule->achName[0], pszName, cchName); 547 681 pModule->chVerMajor = 4; 548 682 pModule->chVerMinor = 0; … … 875 1009 876 1010 877 878 1011 /** 1012 * Dumps this module entry to the given file. 1013 * @param ph Filehandle to dump this module entry to. 1014 */ 1015 void kHllModuleEntry::dump(FILE *ph) 1016 { 1017 PHLLSEGINFO pSegInfo; 1018 int i; 1019 1020 fprintf(ph, " ------- start dumping kHllModuleEntry object 0x%08x -------\n", this); 1021 1022 /* 1023 * Dump HLL module entry. 1024 */ 1025 fprintf(ph, " Modulename: %.*s Style: %.2s HLL ver: %d.%d #SegInfos: %d\n", 1026 pModule->cchName, pModule->achName, 1027 &pModule->usDebugStyle, 1028 pModule->chVerMajor, pModule->chVerMinor, 1029 pModule->cSegInfo 1030 ); 1031 1032 for (i = 0, pSegInfo = &pModule->SegInfo0; i < pModule->cSegInfo; i++) 1033 { 1034 fprintf(ph, " Obj.no.: 0x%04x Offset: 0x%08x Size: 0x%08x(%d)\n", 1035 pSegInfo->iObject, pSegInfo->off, pSegInfo->cb, pSegInfo->cb); 1036 1037 /* next */ 1038 if (i == 0) 1039 pSegInfo = (PHLLSEGINFO)&pModule->achName[pModule->cchName]; 1040 else 1041 pSegInfo++; 1042 } 1043 1044 1045 /* 1046 * Dump the sub-entries. 1047 */ 1048 kHllBaseEntry::dumpList(ph, 8, PublicSymbols.getFirst()); 1049 /* 1050 kHllBaseEntry::dumpList(ph, 8, Types.getFirst()); 1051 kHllBaseEntry::dumpList(ph, 8, Symbols.getFirst()); 1052 kHllBaseEntry::dumpList(ph, 8, Source.getFirst()); 1053 */ 1054 Source.dump(ph, 8); 1055 1056 1057 fprintf(ph, " ------- end dumping kHllModuleEntry object 0x%08x -------\n", this); 1058 } 879 1059 880 1060 … … 1020 1200 1021 1201 1202 /** 1203 * Creates a kHll object from debugdata found in a file (LX layout). 1204 * @param pFile Pointer to file object which the data is to be read from. 1205 * The file object is positioned at the start of the debuginfo. 1206 * start of the debuginfo. 1207 * Note. The file object is set to throw on errors. 1208 */ 1209 kHll::kHll(kFile *pFile) throw (int) 1210 { 1211 long offHllHdr; /* Offset of debug data in file. */ 1212 HLLHDR hllHdr; /* HLL data header. */ 1213 HLLDIR hllDir; /* HLL directory (header only) */ 1214 PHLLDIR pHllDir; /* HLL directory (all) */ 1215 PHLLDIRENTRY pDirEntry; /* Current HLL directory entry. */ 1216 int iDir; 1217 1218 /* auto throw */ 1219 pFile->setThrowOnErrors(); 1220 1221 /* Save file offset of debugdata. */ 1222 offHllHdr = pFile->getPos(); 1223 1224 /* Read HLL header */ 1225 pFile->read(&hllHdr, sizeof(hllHdr)); 1226 if (memcmp(hllHdr.achSignature, "NB04", 4) != 0) 1227 throw(ERROR_INVALID_EXE_SIGNATURE); 1228 1229 /* 1230 * Read the Directory head to get the directory size. 1231 * Allocate memory for the entire directory and read it. 1232 */ 1233 pFile->readAt(&hllDir, sizeof(hllDir), offHllHdr + hllHdr.offDirectory); 1234 pHllDir = (PHLLDIR)malloc((size_t)(hllDir.cbEntry * hllDir.cEntries + hllDir.cb)); 1235 if (pHllDir == NULL) throw(ERROR_NOT_ENOUGH_MEMORY); 1236 pFile->readAt(pHllDir, hllDir.cbEntry * hllDir.cEntries + hllDir.cb, offHllHdr + hllHdr.offDirectory); 1237 1238 1239 /* 1240 * Loop thru the directory entries and add them we have implemented. 1241 */ 1242 unsigned long ulHLLVersion = 0; /* HLL version of the last module. */ 1243 kHllModuleEntry *pCurMod = NULL; /* Current Module. */ 1244 int iCurMod = 0; /* Current Module index (import). */ 1245 1246 for (iDir = 0, pDirEntry = (PHLLDIRENTRY)((char*)pHllDir + hllDir.cb); 1247 iDir < pHllDir->cEntries; 1248 iDir++, pDirEntry = (PHLLDIRENTRY)((char*)pDirEntry + hllDir.cbEntry) 1249 ) 1250 { 1251 CHAR szName[1024]; 1252 1253 switch (pDirEntry->usType) 1254 { 1255 /* 1256 * Source filename(=Module) entry. 1257 */ 1258 case HLL_DE_MODULES: 1259 { 1260 HLLMODULE hllMod; 1261 PHLLSEGINFO paSegInfo; 1262 1263 /* 1264 * Read hllmod, filename and seginfo table if any. 1265 */ 1266 pFile->readAt(&hllMod, sizeof(hllMod), offHllHdr + pDirEntry->off); 1267 pFile->move(-1); 1268 pFile->read(szName, hllMod.cchName); 1269 szName[hllMod.cchName] = '\0'; 1270 if (hllMod.cSegInfo != 0) 1271 { 1272 paSegInfo = (PHLLSEGINFO)malloc(sizeof(HLLSEGINFO) * hllMod.cSegInfo); 1273 if (pHllDir == NULL) throw(ERROR_NOT_ENOUGH_MEMORY); 1274 memcpy(paSegInfo, &hllMod.SegInfo0, sizeof(HLLSEGINFO)); 1275 if (hllMod.cSegInfo > 1) 1276 pFile->read(&paSegInfo[1], sizeof(HLLSEGINFO) * (hllMod.cSegInfo - 1)); 1277 } 1278 else 1279 paSegInfo = NULL; 1280 1281 /* 1282 * Add the module and save module data for later use. 1283 * Cleanup seginfo. 1284 */ 1285 pCurMod = this->addModule(szName, hllMod.cchName, NULL, hllMod.cSegInfo, paSegInfo); 1286 iCurMod = pDirEntry->iMod; 1287 ulHLLVersion = HLLMAKEVER(hllMod.chVerMajor, hllMod.chVerMinor); 1288 1289 if (paSegInfo != NULL) 1290 free(paSegInfo); 1291 fprintf(stderr, "Module directory entry: %s\n", szName); 1292 break; 1293 } 1294 1295 case HLL_DE_PUBLICS: /* Public symbols */ 1296 fprintf(stderr, "Publics directory entry\n"); 1297 break; 1298 1299 case HLL_DE_TYPES: /* Types */ 1300 fprintf(stderr, "Types directory entry\n"); 1301 break; 1302 1303 case HLL_DE_SYMBOLS: /* Symbols */ 1304 fprintf(stderr, "Symbols directory entry\n"); 1305 break; 1306 1307 case HLL_DE_LIBRARIES: /* Libraries */ 1308 fprintf(stderr, "Libraries directory entry\n"); 1309 break; 1310 1311 case HLL_DE_SRCLINES: /* Line numbers - (IBM C/2 1.1) */ 1312 fprintf(stderr, "SRCLINES directory entry\n"); 1313 break; 1314 1315 case HLL_DE_SRCLNSEG: /* Line numbers - (MSC 6.00) */ 1316 fprintf(stderr, "SRCLNSEG directory entry\n"); 1317 break; 1318 1319 case HLL_DE_IBMSRC: /* Line numbers - (IBM HLL) */ 1320 fprintf(stderr, "IBMSRC directory entry\n"); 1321 break; 1322 1323 default: 1324 /* Unsupported directory entry - ignore */ 1325 fprintf(stderr, "Unsupported directory entry %d\n", pDirEntry->usType); 1326 break; 1327 } 1328 } 1329 1330 /* cleanup */ 1331 free(pHllDir); 1332 } 1333 1022 1334 1023 1335 /** … … 1091 1403 } 1092 1404 1405 1406 /** 1407 * Dump the object in a human readable fashion to stdout. 1408 */ 1409 void kHll::dump() 1410 { 1411 FILE *ph = stdout; 1412 1413 fprintf(ph, 1414 "------- start dumping kHll object 0x%08x --- %d modules -------\n", 1415 this, Modules.getCount()); 1416 1417 kHllModuleEntry * pMod = Modules.getFirst(); 1418 while (pMod != NULL) 1419 { 1420 /* Dump it */ 1421 pMod->dump(ph); 1422 1423 /* Next module */ 1424 pMod = (kHllModuleEntry*)pMod->getNext(); 1425 } 1426 1427 fprintf(ph, 1428 "------- end dumping kHll object 0x%08x --- %d modules -------\n", 1429 this, Modules.getCount()); 1430 } 1431 1432 1433 /** 1434 * Creates a kHll object of the HLL debug information found a LX file. 1435 * (An empty object is returned when no info is found.) 1436 * @return Pointer to kHll object on success. 1437 * NULL on error. Message is printed. 1438 */ 1439 kHll * kHll::readLX( 1440 const char *pszFilename 1441 ) 1442 { 1443 try 1444 { 1445 struct exe_hdr ehdr; 1446 struct e32_exe e32; 1447 long offLXHdr; 1448 1449 kFile file(pszFilename); 1450 1451 /* 1452 * Find and read the LX header. 1453 */ 1454 file.read(&ehdr, sizeof(ehdr)); 1455 if (ehdr.e_magic == EMAGIC) 1456 offLXHdr = ehdr.e_lfanew; 1457 else 1458 offLXHdr = 0; 1459 file.readAt(&e32, sizeof(e32), offLXHdr); 1460 if (*(PSHORT)&e32.e32_magic[0] != E32MAGIC) 1461 throw (ERROR_INVALID_EXE_SIGNATURE); 1462 1463 /* 1464 * Is there any debug info in this LX header? 1465 */ 1466 if (e32.e32_debuginfo != 0UL && e32.e32_debuglen != 0UL 1467 && file.set(e32.e32_debuginfo)) 1468 return new kHll(&file); 1469 else 1470 return new kHll(); 1471 } 1472 catch (int iOS2Error) 1473 { 1474 fprintf(stderr, "failed to create kHll object for file %s. Failed with OS2 error %d.\n", 1475 pszFilename, iOS2Error); 1476 } 1477 return NULL; 1478 } 1093 1479 1094 1480 … … 1271 1657 } 1272 1658 1659 1660 1661 #if 1 1662 /** 1663 * Debugging entry point for the readLX constructor. 1664 * It reads this executable and dumps it. 1665 * @param argc Argument count. 1666 * @param argv Argument vector - only the first entry is used. 1667 */ 1668 void main(int argc, char **argv) 1669 { 1670 kHll *pHll; 1671 1672 /* read my self */ 1673 pHll = kHll::readLX(argv[0]); 1674 if (pHll) 1675 { 1676 printf("Successfully read %s\n", argv[0]); 1677 pHll->dump(); 1678 } 1679 argc = argc; 1680 delete (pHll); 1681 } 1682 1683 #ifdef __IBMCPP__ 1684 #include "klist.cpp" 1685 #endif 1686 1687 #endif -
trunk/tools/dbginfo/kHll.h
r3332 r3614 1 /* $Id: kHll.h,v 1. 7 2000-04-07 02:47:01bird Exp $1 /* $Id: kHll.h,v 1.8 2000-05-27 02:15:42 bird Exp $ 2 2 * 3 3 * kHll - Declarations of the class kHll. … … 38 38 virtual int write(FILE *phFile) = 0; 39 39 static int writeList(FILE *phFile, kHllBaseEntry *pEntry); 40 41 /** 42 * Dumps the HLL entry to ph in a human readable fashion. 43 * @param ph Output file handle the dump is to be written to. 44 * @param cchIndent Number of char to indents the output dump. 45 */ 46 virtual void dump(FILE *ph, int cchIndent) = 0; 47 static void dumpList(FILE *ph, int cchIndent, kHllBaseEntry *pEntry); 40 48 }; 41 49 … … 62 70 63 71 int write(FILE *phFile); 72 void dump(FILE *ph, int cchIndent); 64 73 }; 65 74 … … 90 99 91 100 int write(FILE *phFile); 101 void dump(FILE *ph, int cchIndent); 102 92 103 int getSeg() { return FirstEntry.hll04.iSeg; } 93 104 }; … … 126 137 ); 127 138 int write(FILE *phFile); 139 void dump(FILE *ph, int cchIndent); 128 140 }; 129 141 … … 212 224 * Output. 213 225 */ 214 int write(FILE *phFile, unsigned long off); 215 int writeDirEntries(FILE *phFile, unsigned short iMod); 226 int write(FILE *phFile, unsigned long off); 227 int writeDirEntries(FILE *phFile, unsigned short iMod); 228 229 230 /** @cat 231 * Debug dump function. 232 */ 233 void dump(FILE *ph); 216 234 }; 217 235 … … 245 263 */ 246 264 kHll(); 265 kHll(kFile *pFile) throw (int); 247 266 ~kHll(); 248 267 … … 275 294 ); 276 295 277 296 /** @cat 297 * Static read function(s). 298 */ 299 static kHll * readLX( 300 const char *pszFilename 301 ); 302 303 /** @cat 304 * Debug dump function. 305 */ 306 void dump(); 278 307 }; 279 308 -
trunk/tools/dbginfo/makefile
r3441 r3614 1 # $Id: makefile,v 1. 3 2000-04-24 21:38:12 bird Exp $1 # $Id: makefile,v 1.4 2000-05-27 02:15:42 bird Exp $ 2 2 # 3 3 # Makefile for debug info convertes - experimental. … … 14 14 PDWIN32_BIN = ..\..\$(OBJDIR) 15 15 PDWIN32_TOOLS = ..\..\tools\bin 16 PDWIN32_TCOMMON = ..\common 16 17 17 18 18 19 # Compiler, tools, and interference rules. 19 20 EXETARGET=1 20 !include $(PDWIN32_INCLUDE)/pdwin32.mk 21 !include $(PDWIN32_INCLUDE)\pdwin32.mk 22 !include $(PDWIN32_TCOMMON)\common.mk 21 23 22 24 23 25 # Flag overloads and local macros. 24 CINCLUDES = -I ..\common26 CINCLUDES = -I$(PDWIN32_TCOMMON) 25 27 26 28 CFLAGS = $(CINCLUDES) $(CFLAGS) -DRING3 \ … … 31 33 32 34 # All rule - build objs, target dll, copies dll to bin and makes libs. 33 all: Sym2Hll.exe dbgLXDumper.exe35 all: kHll.exe # Sym2Hll.exe dbgLXDumper.exe 34 36 35 37 … … 38 40 # 39 41 Sym2Hll: 40 Sym2Hll.exe: Sym2Hll.obj kHll.obj ..\common\commonicc.lib42 Sym2Hll.exe: Sym2Hll.obj kHll.obj $(COMMONLIB) 41 43 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC:$@ $** $(RTLLIB) os2386.lib 42 44 45 # 46 # New LX debug info dumper. 47 # 48 kHll.exe: kHll.obj $(COMMONLIB) 49 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC:$@ $** $(RTLLIB) os2386.lib 43 50 44 51 # … … 69 76 70 77 # Includes the common rules. 71 !include $(PDWIN32_INCLUDE)/pdwin32.post 78 !include $(PDWIN32_INCLUDE)\pdwin32.post 79 !include $(PDWIN32_TCOMMON)\common.mk.post 72 80 73 81
Note:
See TracChangeset
for help on using the changeset viewer.