Changeset 4130 for trunk/tools
- Timestamp:
- Aug 31, 2000, 5:02:28 AM (25 years ago)
- Location:
- trunk/tools/dbginfo
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/dbginfo/Sym2Hll.cpp
r3614 r4130 1 /* $Id: Sym2Hll.cpp,v 1. 6 2000-05-27 02:15:41bird Exp $1 /* $Id: Sym2Hll.cpp,v 1.7 2000-08-31 03:02:27 bird Exp $ 2 2 * 3 3 * Sym2Hll - Symbol file to HLL debuginfo converter. … … 34 34 35 35 #include "hll.h" 36 #include "sym.h" 36 37 #include "kHll.h" 37 #include "sym.h"38 38 39 39 /******************************************************************************* … … 159 159 " cSymbols 0x%04x count of symbols in list\n" 160 160 " pSymDef 0x%04x offset of symbol chain\n" 161 " w Reserved1 0x%04x reserved\n"161 " wSegNum 0x%04x segment number (1 based)\n" 162 162 " wReserved2 0x%04x reserved\n" 163 163 " wReserved3 0x%04x reserved\n" … … 173 173 pSegDef->cSymbols, 174 174 pSegDef->pSymDef, 175 pSegDef->w Reserved1,175 pSegDef->wSegNum, 176 176 pSegDef->wReserved2, 177 177 pSegDef->wReserved3, -
trunk/tools/dbginfo/kHll.cpp
r3630 r4130 1 /* $Id: kHll.cpp,v 1.1 4 2000-05-29 19:46:28bird Exp $1 /* $Id: kHll.cpp,v 1.15 2000-08-31 03:02:27 bird Exp $ 2 2 * 3 3 * kHll - Implementation of the class kHll. … … 35 35 #include <stddef.h> 36 36 #include <stdlib.h> 37 #include <assert.h>38 37 39 38 #include <kList.h> 40 39 #include <kFile.h> 40 #include <kFileFormatBase.h> 41 #include <kFileLX.h> 41 42 42 43 #include "hll.h" 44 #include "sym.h" 43 45 #include "kHll.h" 44 46 … … 153 155 * @param cchName Length of symbol name. 154 156 * @param off Offset into the object. 155 * @param iObject LX Object index. 157 * @param iObject LX Object index. (1 based) 156 158 * @param iType Type index. (index into type table) 157 159 */ … … 249 251 250 252 253 BOOL kHllPubSymEntry::operator==(const kHllPubSymEntry &entry) const 254 { 255 return pPubSym->iObject == entry.pPubSym->iObject 256 && pPubSym->off == entry.pPubSym->off; 257 } 258 259 BOOL kHllPubSymEntry::operator!=(const kHllPubSymEntry &entry) const 260 { 261 return pPubSym->iObject != entry.pPubSym->iObject 262 || pPubSym->off != entry.pPubSym->off; 263 } 264 265 BOOL kHllPubSymEntry::operator< (const kHllPubSymEntry &entry) const 266 { 267 return pPubSym->iObject < entry.pPubSym->iObject 268 || (pPubSym->iObject == entry.pPubSym->iObject && pPubSym->off < entry.pPubSym->off); 269 } 270 271 BOOL kHllPubSymEntry::operator<=(const kHllPubSymEntry &entry) const 272 { 273 return pPubSym->iObject < entry.pPubSym->iObject 274 || (pPubSym->iObject == entry.pPubSym->iObject && pPubSym->off <= entry.pPubSym->off); 275 } 276 277 BOOL kHllPubSymEntry::operator> (const kHllPubSymEntry &entry) const 278 { 279 return pPubSym->iObject > entry.pPubSym->iObject 280 || (pPubSym->iObject == entry.pPubSym->iObject && pPubSym->off > entry.pPubSym->off); 281 } 282 283 BOOL kHllPubSymEntry::operator>=(const kHllPubSymEntry &entry) const 284 { 285 return pPubSym->iObject > entry.pPubSym->iObject 286 || (pPubSym->iObject == entry.pPubSym->iObject && pPubSym->off >= entry.pPubSym->off); 287 } 251 288 252 289 … … 275 312 /** 276 313 * Constructor. 277 * @param iSeg Segment number for these linenumbers. 314 * @param iSeg Segment number for these linenumbers. (1 based) 278 315 * @param offBase Base offset for all line number offsets. (defaults to 0) 279 316 */ … … 488 525 * @returns Pointer to linenumber chunk which you may add linenumber info to. 489 526 * NULL on failiure. 490 * @param iSeg Segment number for these linenumbers. 527 * @param iSeg Segment number for these linenumbers. (1 based) 491 528 * @param offBase Base offset for all line number offsets. (defaults to 0) 492 529 */ … … 723 760 PHLLSEGINFO paSegInfo/*= NULL */ 724 761 ) 725 : fValidOffsetsAndSizes(FALSE) 762 : fValidOffsetsAndSizes(FALSE), iObjectMax(0) 726 763 { 727 764 int i; … … 757 794 if (cSegInfo != 0) 758 795 { 796 assert(paSegInfo->iObject != 0); 759 797 pModule->SegInfo0.iObject = paSegInfo->iObject; 760 798 pModule->SegInfo0.cb = paSegInfo->cb; 761 799 pModule->SegInfo0.off = paSegInfo->off; 800 iObjectMax = pModule->SegInfo0.iObject; 762 801 763 802 for (i = 1, pSegInfo = (PHLLSEGINFO)&pModule->achName[cchName]; i < cSegInfo; i++, pSegInfo++) 764 803 { 804 assert(paSegInfo->iObject != 0); 765 805 pSegInfo->iObject = paSegInfo[i].iObject; 766 806 pSegInfo->cb = paSegInfo[i].cb; 767 807 pSegInfo->off = paSegInfo[i].off; 808 if (pSegInfo->iObject > iObjectMax) 809 iObjectMax = pSegInfo->iObject; 768 810 } 769 811 } … … 786 828 * Adds an object to the module. 787 829 * @returns Success indicator. 788 * @param iObject LX Object index. 830 * @param iObject LX Object index. (1 based) 789 831 * @param off Offset into the object to the module data. 790 832 * @param cb Size of module data (in the object). … … 797 839 { 798 840 assert(pModule != NULL); 841 assert(iObject != 0); 799 842 800 843 /* … … 820 863 pModule->SegInfo0.off = off; 821 864 pModule->SegInfo0.iObject = iObject; 865 if (pModule->SegInfo0.iObject > iObjectMax) 866 iObjectMax = pModule->SegInfo0.iObject; 822 867 } 823 868 else … … 828 873 pSegInfo->off = off; 829 874 pSegInfo->iObject = iObject; 875 if (pSegInfo->iObject > iObjectMax) 876 iObjectMax = pSegInfo->iObject; 830 877 } 831 878 pModule->cSegInfo++; … … 841 888 * @param pszName Symbol name. 842 889 * @param off Offset into the LX Object of the symbol. 843 * @param iObject LX Object index. 890 * @param iObject LX Object index. (1 based) 844 891 * @param pvType Type handle. NULL if not type. 845 892 */ … … 852 899 { 853 900 assert(pszName != NULL); 901 if (iObject > iObjectMax) 902 iObjectMax = iObject; 854 903 return addPublicSymbol(pszName, strlen(pszName), off, iObject, pvType); 855 904 } … … 863 912 * @param cchName Name length. 864 913 * @param off Offset into the LX Object of the symbol. 865 * @param iObject LX Object index. 914 * @param iObject LX Object index. (1 based) 866 915 * @param pvType Type handle. NULL if not type. 867 916 */ … … 878 927 /* parameter assertion */ 879 928 assert(pachName != NULL); 929 assert(iObject != 0); 930 if (iObject > iObjectMax) 931 iObjectMax = iObject; 880 932 881 933 /* … … 1077 1129 1078 1130 /** 1131 * Converts and writes SYM seginfo a segment for this module entry. 1132 * @returns Count of bytes written on success. 1133 * -4 Out of memory. 1134 * -3 Invalid offsets. 1135 * -2 Seek error. 1136 * -1 Write error. 1137 * 0 no data written (this is an error condition!) 1138 * @param pFile Pointer to output file object. 1139 * @param iSeg Segment number which we processing. (1 based) 1140 * @param pSegDef Segment definition. This is to be updated (count). 1141 * @param paoffSyms Reference symbol offset table. 1142 * Insert 16 byte aligned symbol offsets. 1143 * This table should be reallocated when full. 1144 * @param coffsymsAllocated Reference to allocated size of the symbol offset table. 1145 * @param offSegDef Offset of the segement definition. 1146 * 1147 */ 1148 void kHllModuleEntry::writeSymSeg(kFile *pFile, int iSeg, PSEGDEF pSegDef, 1149 unsigned short * &paoffSyms, int &coffSymsAllocated, 1150 unsigned long offSegDef) throw(int) 1151 { 1152 kHllPubSymEntry* pPubSym; 1153 char achBuffer[CCHMAXPATH + sizeof(SYMDEF32)]; 1154 PSYMDEF32 pSym = (PSYMDEF32)&achBuffer[0]; 1155 int cbSym; 1156 long off = pFile->getPos(); 1157 1158 assert(iSeg > 0); 1159 1160 /* 1161 * Add module name symbol. 1162 * -see if this module has a segment info entry for the current segment. 1163 */ 1164 if (pModule->cSegInfo != 0) 1165 { 1166 PHLLSEGINFO pSegInfo; 1167 if (pModule->SegInfo0.iObject == iSeg) 1168 pSegInfo = &pModule->SegInfo0; 1169 else 1170 { 1171 int i; 1172 for (i = pModule->cSegInfo, 1173 pSegInfo = (PHLLSEGINFO)&pModule->achName[pModule->cchName]; 1174 i > 0 && pSegInfo->iObject != iSeg; 1175 i--, pSegInfo++ 1176 ) 1177 i = i; // 1178 if (i <= 0) 1179 pSegInfo = NULL; 1180 } 1181 1182 /* anything to write? */ 1183 if (pSegInfo) 1184 { 1185 pSym->wSymVal = pSegInfo->off; 1186 pSym->cbSymName = pModule->cchName; 1187 memcpy(pSym->achSymName, pModule->achName, pModule->cchName); 1188 pSym->cbSymName += sprintf(pSym->achSymName + pModule->cchName, "_Start_Seg%d", iSeg); 1189 cbSym = sizeof(SYMDEF32) + pSym->cbSymName - 1; 1190 pFile->write(pSym, cbSym); 1191 if (coffSymsAllocated <= pSegDef->cSymbols + 1) 1192 { 1193 void *pv; 1194 pv = realloc(paoffSyms, (coffSymsAllocated + 50) * sizeof(unsigned short)); 1195 if (pv == NULL) 1196 throw(ERROR_NOT_ENOUGH_MEMORY); 1197 paoffSyms = (unsigned short *)pv; 1198 coffSymsAllocated += 50; 1199 } 1200 paoffSyms[pSegDef->cSymbols] = (unsigned short)(off - offSegDef); 1201 pSegDef->cSymbols++; 1202 off += cbSym; 1203 } 1204 } 1205 1206 1207 /* 1208 * Add all public symbols. 1209 */ 1210 pPubSym = (kHllPubSymEntry*)PublicSymbols.getFirst(); 1211 while (pPubSym != NULL) 1212 { 1213 /* if the current segement then make a symbol entry */ 1214 if (pPubSym->getObjectIndex() == iSeg) 1215 { 1216 pSym->wSymVal = pPubSym->getOffset(); 1217 pSym->cbSymName = pPubSym->getNameLength(); 1218 memcpy(pSym->achSymName, pPubSym->getName(), pSym->cbSymName); 1219 cbSym = sizeof(SYMDEF32) + pSym->cbSymName - 1; 1220 pFile->write(pSym, cbSym); 1221 if (coffSymsAllocated <= pSegDef->cSymbols + 1) 1222 { 1223 void *pv; 1224 pv = realloc(paoffSyms, (coffSymsAllocated + 50) * sizeof(unsigned short)); 1225 if (pv == NULL) 1226 throw(ERROR_NOT_ENOUGH_MEMORY); 1227 paoffSyms = (unsigned short *)pv; 1228 coffSymsAllocated += 50; 1229 } 1230 paoffSyms[pSegDef->cSymbols] = (unsigned short)(off - offSegDef); 1231 pSegDef->cSymbols++; 1232 off += cbSym; 1233 } 1234 1235 /* next entry */ 1236 pPubSym = (kHllPubSymEntry*)pPubSym->getNext(); 1237 } 1238 } 1239 1240 1241 /** 1242 * Gets the highest object index. (ie. object count since it is 1 based.) 1243 * @returns Highest object index. 1244 */ 1245 int kHllModuleEntry::queryMaxObjectIndex() 1246 { 1247 return iObjectMax; 1248 } 1249 1250 1251 1252 /** 1079 1253 * Dumps this module entry to the given file. 1080 1254 * @param ph Filehandle to dump this module entry to. … … 1283 1457 * Constructor - Creates an empty HLL object. 1284 1458 */ 1285 kHll::kHll() 1459 kHll::kHll() : pszModName(NULL) 1286 1460 { 1287 1461 } … … 1295 1469 * Note. The file object is set to throw on errors. 1296 1470 */ 1297 kHll::kHll(kFile *pFile) throw (int) 1471 kHll::kHll(kFile *pFile) throw (int) : pszModName(NULL) 1298 1472 { 1299 1473 long offHllHdr; /* Offset of debug data in file. */ … … 1328 1502 * Loop thru the directory entries and add them we have implemented. 1329 1503 */ 1330 unsigned long ulHLLVersion = 0; /* HLL version of the last module. */1504 //unsigned long ulHLLVersion = 0; /* HLL version of the last module. */ 1331 1505 kHllModuleEntry *pCurMod = NULL; /* Current Module. */ 1332 1506 int iCurMod = 0; /* Current Module index (import). */ … … 1373 1547 pCurMod = this->addModule(szName, hllMod.cchName, NULL, hllMod.cSegInfo, paSegInfo); 1374 1548 iCurMod = pDirEntry->iMod; 1375 ulHLLVersion = HLLMAKEVER(hllMod.chVerMajor, hllMod.chVerMinor);1549 //ulHLLVersion = HLLMAKEVER(hllMod.chVerMajor, hllMod.chVerMinor); 1376 1550 1377 1551 if (paSegInfo != NULL) … … 1452 1626 kHll::~kHll() 1453 1627 { 1628 if (pszModName != NULL) 1629 free(pszModName); 1630 pszModName = NULL; 1454 1631 } 1455 1632 … … 1517 1694 } 1518 1695 1696 /** 1697 * Sets the modulename. 1698 * @returns Success indicator. 1699 * @param pszModName Pointer to modulename. 1700 * If a filename is given the path and extention is removed. 1701 */ 1702 BOOL kHll::setModName( 1703 const char * pszModName 1704 ) 1705 { 1706 const char *pszEnd = pszModName + strlen(pszModName) - 1; 1707 1708 /* remove path */ 1709 while (pszEnd >= pszModName && *pszEnd != '\\' && *pszEnd != '/') 1710 pszEnd--; 1711 pszModName = ++pszEnd; 1712 1713 /* find extention (if any) */ 1714 while (*pszEnd != '\0' && *pszEnd != '.') 1715 pszEnd++; 1716 return setModName(pszModName, pszEnd - pszModName); 1717 } 1718 1719 1720 /** 1721 * Sets the modulename. 1722 * @returns Success indicator. 1723 * @param pszModName Pointer to modulename. 1724 * @param cchModName Length of modulename. 1725 */ 1726 BOOL kHll::setModName( 1727 const char * pachModName, 1728 int cchModName 1729 ) 1730 { 1731 1732 /* allocate memory for the module name */ 1733 if (pszModName != NULL) 1734 free(this->pszModName); 1735 pszModName = (char*)malloc(cchModName + 1); 1736 if (pszModName == NULL) 1737 return FALSE; 1738 1739 /* copy the module name */ 1740 memcpy(pszModName, pachModName, cchModName); 1741 pszModName[cchModName] = '\0'; 1742 1743 return TRUE; 1744 } 1745 1746 1747 /** 1748 * Get the modulename. If not set we'll try make one... 1749 * @returns Const pointer to modulename. 1750 * NULL if no modulename. 1751 * @sketch 1752 */ 1753 const char * kHll::getModName() 1754 { 1755 if (pszModName != NULL) 1756 return pszModName; 1757 return NULL; 1758 } 1759 1519 1760 1520 1761 /** 1521 1762 * Dump the object in a human readable fashion to stdout. 1522 1763 */ 1523 void kHll::dump() 1524 { 1525 FILE *ph = stdout; 1526 1764 void kHll::dump(FILE *ph) 1765 { 1527 1766 fprintf(ph, 1528 1767 "------- start dumping kHll object 0x%08x --- %d modules -------\n", … … 1569 1808 1570 1809 pFile->printf("}\n\n"); 1810 pFile->setSize(); 1571 1811 } 1572 1812 … … 1618 1858 } 1619 1859 return NULL; 1860 } 1861 1862 1863 /** 1864 * Create a kHll object from an LX export table. 1865 * @returns Pointer to kHll object. 1866 * @param pFileLX Pointer to the LX file. 1867 */ 1868 kHll * kHll::readLXExports( 1869 kFileLX *pFileLX 1870 ) throw(int) 1871 { 1872 char szBuffer[CCHMAXPATH]; 1873 kHll * pHll = new kHll(); 1874 kHllModuleEntry * pModule; 1875 int i; 1876 1877 1878 /* 1879 * Set modulename. 1880 */ 1881 if (!pFileLX->queryModuleName(szBuffer)) 1882 strcpy(szBuffer, "HMM"); 1883 pHll->setModName(szBuffer); 1884 1885 1886 /* 1887 * Make fake module. 1888 */ 1889 pModule = pHll->addModule(szBuffer, NULL); 1890 if (pModule == NULL) 1891 { 1892 fprintf(stderr, "addModule failed\n"); 1893 delete pHll; 1894 return NULL; 1895 } 1896 pModule->getSourceEntry()->addFile(szBuffer); 1897 1898 1899 /* 1900 * Add segment to the module. 1901 */ 1902 for (i = 0; i < pFileLX->getObjectCount(); i++) 1903 { 1904 struct o32_obj *pLXObject = pFileLX->getObject((USHORT)i); 1905 if (pLXObject) 1906 { 1907 if (!pModule->addSegInfo((USHORT)(i+1), 0, pLXObject->o32_size)) 1908 fprintf(stderr, "warning: addseginfo failed!\n"); 1909 } 1910 else 1911 fprintf(stderr, "warning: pFileLX->getObject failed for Segment no.=%d (0 based)\n", i); 1912 } 1913 1914 1915 /* 1916 * Exports 1917 */ 1918 EXPORTENTRY export; 1919 if (pFileLX->findFirstExport(&export)) 1920 { 1921 do 1922 { 1923 if (export.achName[0] == '\0') 1924 sprintf(export.achName, "Ordinal%03d", export.ulOrdinal); 1925 pModule->addPublicSymbol(export.achName, export.offset, 1926 (unsigned short)export.iObject, NULL); 1927 } while (pFileLX->findNextExport(&export)); 1928 } 1929 1930 return pHll; 1931 } 1932 1933 1934 /** 1935 * Create a kHll object from a Symbol file. 1936 * @returns Pointer to kHll object. 1937 * @param pFile Pointer to Symbol file file object. 1938 * @param pFileLX Pointer to corresponding LX (only LX - FIXME!) file. [optional]. 1939 */ 1940 kHll * kHll::readSym( 1941 kFile *pFile, 1942 kFileLX *pFileLX /*= NULL */ 1943 ) 1944 { 1945 kHll *pHll = NULL; 1946 1947 /* 1948 * Start conversion. 1949 */ 1950 PBYTE pbSym = (PBYTE)pFile->readFile(); 1951 if (pbSym != NULL) 1952 { 1953 kHllModuleEntry * pModule; 1954 PMAPDEF pMapDef; /* Mapfile header */ 1955 1956 pHll = new kHll(); 1957 1958 pMapDef = (PMAPDEF)pbSym; 1959 while (pMapDef != NULL) 1960 { 1961 int iSeg; 1962 PSEGDEF pSegDef; /* Segment header */ 1963 1964 /* 1965 * Map definition. 1966 */ 1967 printf("- Map definition -\n" 1968 " ppNextMap 0x%04x paragraph pointer to next map\n" 1969 " bFlags 0x%02x symbol types\n" 1970 " bReserved1 0x%02x reserved\n" 1971 " pSegEntry 0x%04x segment entry point value\n" 1972 " cConsts 0x%04x count of constants in map\n" 1973 " pConstDef 0x%04x pointer to constant chain\n" 1974 " cSegs 0x%04x count of segments in map\n" 1975 " ppSegDef 0x%04x paragraph pointer to first segment\n" 1976 " cbMaxSym 0x%02x maximum symbol-name length\n" 1977 " cbModName 0x%02x length of module name\n" 1978 " achModName %.*s\n" 1979 "\n", 1980 pMapDef->ppNextMap, 1981 pMapDef->bFlags, 1982 pMapDef->bReserved1, 1983 pMapDef->pSegEntry, 1984 pMapDef->cConsts, 1985 pMapDef->pConstDef, 1986 pMapDef->cSegs, 1987 pMapDef->ppSegDef, 1988 pMapDef->cbMaxSym, 1989 pMapDef->cbModName, 1990 pMapDef->cbModName, 1991 pMapDef->achModName 1992 ); 1993 1994 /* 1995 * Add Module and modulename. 1996 */ 1997 pHll->setModName(pMapDef->achModName, pMapDef->cbModName); 1998 pModule = pHll->addModule(pMapDef->achModName, pMapDef->cbModName, NULL); 1999 if (pModule == NULL) 2000 { 2001 fprintf(stderr, "addModule failed\n"); 2002 delete pHll; 2003 return NULL; 2004 } 2005 pModule->getSourceEntry()->addFile(pMapDef->achModName, pMapDef->cbModName); 2006 2007 2008 /* 2009 * Read and convert segments with info. 2010 */ 2011 pSegDef = SEGDEFPTR(pbSym, *pMapDef); 2012 iSeg = 1; 2013 while (pSegDef != NULL) 2014 { 2015 struct o32_obj *pLXObject; 2016 PSYMDEF32 pSymDef32; /* Symbol definition 32-bit */ 2017 PSYMDEF16 pSymDef16; /* Symbol definition 16-bit */ 2018 int iSym; 2019 2020 2021 /* 2022 * Dump Segment definition. 2023 */ 2024 printf(" - Segment Definition -\n" 2025 " ppNextSeg 0x%04x paragraph pointer to next segment\n" 2026 " cSymbols 0x%04x count of symbols in list\n" 2027 " pSymDef 0x%04x offset of symbol chain\n" 2028 " wSegNum 0x%04x segment number (1-based)\n" 2029 " wReserved2 0x%04x reserved\n" 2030 " wReserved3 0x%04x reserved\n" 2031 " wReserved4 0x%04x reserved\n" 2032 " bFlags 0x%04x symbol types\n" 2033 " bReserved1 0x%04x reserved\n" 2034 " ppLineDef 0x%04x offset of line number record\n" 2035 " bReserved2 0x%04x reserved\n" 2036 " bReserved3 0x%04x reserved\n" 2037 " cbSegName 0x%04x length of segment name\n" 2038 " achSegName %.*s\n", 2039 pSegDef->ppNextSeg, 2040 pSegDef->cSymbols, 2041 pSegDef->pSymDef, 2042 pSegDef->wSegNum, 2043 pSegDef->wReserved2, 2044 pSegDef->wReserved3, 2045 pSegDef->wReserved4, 2046 pSegDef->bFlags, 2047 pSegDef->bReserved1, 2048 pSegDef->ppLineDef , 2049 pSegDef->bReserved2, 2050 pSegDef->bReserved3, 2051 pSegDef->cbSegName, 2052 pSegDef->cbSegName, 2053 pSegDef->achSegName 2054 ); 2055 2056 /* 2057 * Add segment to the module - FIXME - need info from the LX Object table... 2058 */ 2059 if (pFileLX) 2060 { 2061 pLXObject = pFileLX->getObject((USHORT)iSeg-1); 2062 if (pLXObject == NULL) 2063 fprintf(stderr, "warning: pFileLX->getObject failed for iSeg=%d\n", 2064 iSeg); 2065 } 2066 2067 if (pLXObject != NULL) 2068 { /* Make fake LX object info */ 2069 2070 } 2071 2072 if (pLXObject) 2073 { 2074 if (!pModule->addSegInfo((USHORT)iSeg, 0, pLXObject->o32_size)) 2075 fprintf(stderr, "warning: addseginfo failed!\n"); 2076 } 2077 2078 /* 2079 * Read and convert symbols 2080 */ 2081 for (iSym = 0; iSym < pSegDef->cSymbols; iSym++) 2082 { 2083 unsigned long offset; 2084 int cchName; 2085 const char * pachName; 2086 pSymDef32 = SYMDEFPTR32(pbSym, pSegDef, iSym); 2087 pSymDef16 = (PSYMDEF16)pSymDef32; 2088 2089 if (SEG32BitSegment(*pSegDef)) 2090 { /* pSymDef32 */ 2091 offset = pSymDef32->wSymVal; 2092 cchName = pSymDef32->cbSymName; 2093 pachName = pSymDef32->achSymName; 2094 } 2095 else 2096 { /* pSymDef16 */ 2097 offset = pSymDef16->wSymVal; 2098 cchName = pSymDef16->cbSymName; 2099 pachName = pSymDef16->achSymName; 2100 } 2101 2102 printf(" 0x%08x %.*s\n", 2103 offset, 2104 cchName, 2105 pachName); 2106 2107 /* 2108 * Add symbol - currently we define it as public - it's a symbol local to this module really. 2109 */ 2110 pModule->addPublicSymbol(pachName, cchName, offset, (USHORT)iSeg, 0); 2111 } 2112 2113 2114 /* 2115 * Next segment 2116 */ 2117 printf("\n"); 2118 pSegDef = NEXTSEGDEFPTR(pbSym, *pSegDef); 2119 iSeg++; 2120 } 2121 2122 2123 /* 2124 * Next map 2125 */ 2126 pMapDef = NEXTMAPDEFPTR(pbSym, *pMapDef); 2127 if (pMapDef != NULL) 2128 { 2129 if (pMapDef->ppNextMap == 0) 2130 { /* last map */ 2131 PLAST_MAPDEF pLastMapDef = (PLAST_MAPDEF)pMapDef; 2132 printf("- Last Map definition -\n" 2133 " ppNextMap 0x%04x always zero\n" 2134 " version 0x%02x release number (minor version number)\n" 2135 " release 0x%02x major version number\n", 2136 pLastMapDef->ppNextMap, 2137 pLastMapDef->release, 2138 pLastMapDef->version 2139 ); 2140 break; 2141 } 2142 } 2143 } /* Map loop */ 2144 } 2145 2146 return pHll; 1620 2147 } 1621 2148 … … 1778 2305 1779 2306 /** 2307 * Converts HLL info to a Sym file. 2308 * No backup is made. (sorry) 2309 * @returns OS2 return code. 2310 * @param pFile Pointer to output file object. 2311 */ 2312 void kHll::writeSym( 2313 kFile * pFile 2314 ) throw(int) 2315 { 2316 long off; 2317 int rc = 0; 2318 long offEndMap; 2319 int cbMapDef; 2320 PMAPDEF pMapDef = (PMAPDEF)malloc(sizeof(MAPDEF) + CCHMAXPATH); /* Mapfile header */ 2321 PLAST_MAPDEF pEndMapDef = (PLAST_MAPDEF)pMapDef; 2322 int iSeg; /* (1 based) */ 2323 int cSegs = queryMaxObjectIndex(); 2324 2325 /* If any I/O operation failes, it should throw errors to our caller. */ 2326 pFile->setThrowOnErrors(); 2327 2328 /* Ensure that there is a module name. */ 2329 if (getModName() == NULL) 2330 setModName(pFile->getFilename()); 2331 2332 /* Make mapdef. */ 2333 memset(pMapDef, 0, sizeof(MAPDEF) + CCHMAXPATH); 2334 pMapDef->bFlags = 2; //what's this? 2335 pMapDef->pSegEntry = 1; //dummy 2336 pMapDef->cbMaxSym = 64; 2337 strcpy(pMapDef->achModName, getModName()); 2338 pMapDef->cbModName = (unsigned char)strlen(pMapDef->achModName); 2339 cbMapDef = (int)((sizeof(MAPDEF) - 1 + pMapDef->cbModName + 15UL) & ~15UL); 2340 pMapDef->ppSegDef = (unsigned short)(cbMapDef >> 4); 2341 pMapDef->cSegs = (unsigned short)cSegs; 2342 pFile->write(pMapDef, cbMapDef); 2343 2344 2345 /* 2346 * Make segment info. 2347 * -determin number of segments 2348 * -loop thru every segment and write symbols. 2349 */ 2350 for (iSeg = 1; iSeg <= cSegs && rc == 0; iSeg++) 2351 { 2352 char achBufferSegDef[CCHMAXPATH + sizeof(SEGDEF)]; 2353 int cbSegDef; 2354 PSEGDEF pSegDef = (PSEGDEF)&achBufferSegDef[0]; 2355 long offSegDef = pFile->getPos(); 2356 kHllModuleEntry * pModule; 2357 int coffSymsAllocated = 100; 2358 unsigned short * paoffSyms = (unsigned short *)malloc(sizeof(unsigned short) * coffSymsAllocated); 2359 2360 /* Make and write segdef. */ 2361 memset(pSegDef, 0, sizeof(SEGDEF)); 2362 sprintf(pSegDef->achSegName, "Segment%d", iSeg); 2363 pSegDef->wSegNum = (unsigned short)iSeg; 2364 pSegDef->bReserved3 = (char)0xff; 2365 pSegDef->cbSegName = (unsigned char)strlen(pSegDef->achSegName); 2366 pSegDef->bFlags = SEG_FLAGS_32BIT; 2367 cbSegDef = (int)(((sizeof(SEGDEF) + pSegDef->cbSegName) + 15UL) & ~15UL); 2368 pFile->write(pSegDef, cbSegDef); 2369 2370 2371 /* Write symbols. */ 2372 pModule = (kHllModuleEntry*)Modules.getFirst(); 2373 while (pModule && rc == 0) 2374 { 2375 pModule->writeSymSeg(pFile, iSeg, pSegDef, paoffSyms, coffSymsAllocated, offSegDef); 2376 pModule = (kHllModuleEntry*)pModule->getNext(); 2377 } 2378 2379 2380 /* Write offset array */ 2381 off = pFile->getPos(); 2382 pSegDef->pSymDef = (unsigned short)(off - offSegDef); 2383 pFile->write(paoffSyms, pSegDef->cSymbols * sizeof(unsigned short)); 2384 pFile->write(pSegDef, (size_t)(16 - (pFile->getPos() % 16))); 2385 2386 2387 /* Write updated segdef. */ 2388 off = pFile->getPos(); 2389 assert((off % 16) == 0); 2390 if (iSeg < cSegs) 2391 pSegDef->ppNextSeg = (unsigned short)(off >> 4); 2392 pFile->writeAt(pSegDef, sizeof(SEGDEF), offSegDef); 2393 pFile->set(off); 2394 free(paoffSyms); 2395 } 2396 2397 2398 /* 2399 * Write the updated mapdef and the last mapdef entry. 2400 */ 2401 offEndMap = pFile->getPos(); 2402 assert((offEndMap % 16) == 0); 2403 pMapDef->ppNextMap = (unsigned short)(offEndMap >> 4); 2404 pFile->writeAt(pMapDef, sizeof(MAPDEF), 0); 2405 2406 pEndMapDef->ppNextMap = 0; 2407 pEndMapDef->release = 1; 2408 pEndMapDef->version = 5; 2409 pFile->writeAt(pEndMapDef, sizeof(LAST_MAPDEF), offEndMap); 2410 pFile->setSize(); 2411 2412 /* 2413 * Cleanup 2414 */ 2415 free(pMapDef); 2416 } 2417 2418 2419 /** 2420 * Gets the highest object index. 2421 * @returns Higest object index used. (1 based?) 2422 */ 2423 int kHll::queryMaxObjectIndex() 2424 { 2425 int iObjectMax = 0; 2426 kHllModuleEntry *pModule = (kHllModuleEntry*)Modules.getFirst(); 2427 while (pModule != NULL) 2428 { 2429 int iObject = pModule->queryMaxObjectIndex(); 2430 2431 if (iObject > iObjectMax) 2432 iObjectMax = iObject; 2433 2434 /* next */ 2435 pModule = (kHllModuleEntry*)pModule->getNext(); 2436 } 2437 return iObjectMax; 2438 } 2439 2440 2441 /** 1780 2442 * Find the size of a file. 1781 2443 * @returns Size of file. -1 on error. … … 1799 2461 } 1800 2462 1801 1802 1803 #if 11804 /**1805 * Debugging entry point for the readLX constructor.1806 * It reads this executable and dumps it.1807 * @param argc Argument count.1808 * @param argv Argument vector - only the first entry is used.1809 */1810 void main(int argc, char **argv)1811 {1812 kHll *pHll;1813 1814 /* read last argument */1815 pHll = kHll::readLX(argv[argc-1]);1816 if (pHll)1817 {1818 printf("Successfully read %s\n", argv[0]);1819 pHll->dump();1820 kFile kidc("dbg.idc", FALSE);1821 pHll->ida(&kidc);1822 }1823 argc = argc;1824 delete (pHll);1825 }1826 1827 #ifdef __IBMCPP__1828 #include "klist.cpp"1829 #endif1830 1831 #endif -
trunk/tools/dbginfo/kHll.h
r3630 r4130 1 /* $Id: kHll.h,v 1. 9 2000-05-29 19:46:29bird Exp $1 /* $Id: kHll.h,v 1.10 2000-08-31 03:02:27 bird Exp $ 2 2 * 3 3 * kHll - Declarations of the class kHll. … … 14 14 #define _kHll_h_ 15 15 16 //wrong placement! 17 #include <builtin.h> 18 #undef assert 19 #define assert(a) (!(a) ? \ 20 fprintf(stderr, "assert - %s(%d): %s\n", __FUNCTION__, __LINE__, #a), \ 21 __interrupt(3) \ 22 : \ 23 (void)0, (void)0) 16 24 17 25 /******************************************************************************* … … 24 32 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 25 33 */ 26 class kHllBaseEntry : public k ListEntry34 class kHllBaseEntry : public kSortedListEntry 27 35 { 28 36 public: … … 55 63 virtual void ida(kFile *pFile) throw(int) = 0; 56 64 static void idaList(kFile *pFile, kHllBaseEntry *pEntry) throw(int); 65 66 /* temp fix */ 67 BOOL operator==(const kSortedListEntry &entry) const { return TRUE; } 68 BOOL operator!=(const kSortedListEntry &entry) const { return FALSE; } 69 BOOL operator< (const kSortedListEntry &entry) const { return TRUE; } 70 BOOL operator<=(const kSortedListEntry &entry) const { return TRUE; } 71 BOOL operator> (const kSortedListEntry &entry) const { return FALSE; } 72 BOOL operator>=(const kSortedListEntry &entry) const { return FALSE; } 57 73 }; 58 74 … … 81 97 void dump(FILE *ph, int cchIndent); 82 98 void ida(kFile *pFile) throw(int); 99 100 /** @cat 101 * Get methods. 102 */ 103 /** Gets the offset of the symbol location relative to object start. */ 104 unsigned long getOffset() { return pPubSym->off; } 105 /** Gets the object (segment/section/what ever) index of the symbol location. */ 106 int getObjectIndex(){ return pPubSym->iObject; } 107 /** Gets the Type index of the symbol type. */ 108 int getTypeIndex() { return pPubSym->iType; } 109 /** Gets the length of the public symbol. */ 110 char getNameLength() { return pPubSym->cchName; } 111 /** Gets ASCIIZ public symbol name. */ 112 const char * getName() { return (const char *)&pPubSym->achName[0]; } 113 114 115 BOOL operator==(const kHllPubSymEntry &entry) const; 116 BOOL operator!=(const kHllPubSymEntry &entry) const; 117 BOOL operator< (const kHllPubSymEntry &entry) const; 118 BOOL operator<=(const kHllPubSymEntry &entry) const; 119 BOOL operator> (const kHllPubSymEntry &entry) const; 120 BOOL operator>=(const kHllPubSymEntry &entry) const; 83 121 }; 84 122 … … 169 207 PHLLMODULE pModule; 170 208 171 k List<kHllPubSymEntry>PublicSymbols;209 kSortedList<kHllPubSymEntry> PublicSymbols; 172 210 /* 173 211 kList<kHllTypeEntry> Types; … … 188 226 unsigned long cbSource; 189 227 228 unsigned long iObjectMax; 229 190 230 191 231 /** @cat … … 238 278 int write(FILE *phFile, unsigned long off); 239 279 int writeDirEntries(FILE *phFile, unsigned short iMod); 240 280 void writeSymSeg(kFile *pFile, int iSeg, PSEGDEF pSegDef, 281 unsigned short * &paoffSyms, int &coffSymsAllocated, 282 unsigned long offSegDef) throw (int); 283 284 /** @cat 285 * Get and queries. 286 */ 287 int queryMaxObjectIndex(); 241 288 242 289 /** @cat … … 260 307 * Internal data. 261 308 */ 262 kList<kHllModuleEntry> Modules;309 kList<kHllModuleEntry> Modules; 263 310 /* 264 kList<kHllLibraryEntry> Libraries;311 kList<kHllLibraryEntry> Libraries; 265 312 */ 313 char * pszModName; 266 314 267 315 /** @cat … … 295 343 PHLLSEGINFO paSegInfo = NULL 296 344 ); 345 BOOL setModName( 346 const char * pszModName 347 ); 348 BOOL setModName( 349 const char * pachModName, 350 int cchModName 351 ); 352 const char * getModName(); 297 353 298 354 … … 306 362 const char *pszFilename 307 363 ); 364 void writeSym( 365 kFile * pFile 366 ) throw(int); 367 308 368 309 369 /** @cat … … 314 374 ); 315 375 376 static kHll * readLXExports( 377 kFileLX *FileLX 378 ) throw(int); 379 380 static kHll * readSym( 381 kFile *pFile, 382 kFileLX *pFileLX = NULL 383 ) throw(int); 384 385 386 /** @cat 387 * Get and queries. 388 */ 389 int queryMaxObjectIndex(); 390 391 316 392 /** @cat 317 393 * Debug dump function. 318 394 */ 319 void dump( );395 void dump(FILE *ph); 320 396 void ida(kFile *pFile) throw(int); 321 397 }; -
trunk/tools/dbginfo/makefile
r3614 r4130 1 # $Id: makefile,v 1. 4 2000-05-27 02:15:42bird Exp $1 # $Id: makefile,v 1.5 2000-08-31 03:02:28 bird Exp $ 2 2 # 3 3 # Makefile for debug info convertes - experimental. … … 33 33 34 34 # All rule - build objs, target dll, copies dll to bin and makes libs. 35 all: kHll .exe #Sym2Hll.exe dbgLXDumper.exe35 all: kHll5.exe Sym2Hll.exe dbgLXDumper.exe 36 36 37 37 … … 41 41 Sym2Hll: 42 42 Sym2Hll.exe: Sym2Hll.obj kHll.obj $(COMMONLIB) 43 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC :$@ $** $(RTLLIB) os2386.lib43 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC /OUT:$@ $** $(RTLLIB) os2386.lib 44 44 45 45 # 46 46 # New LX debug info dumper. 47 47 # 48 kHll .exe: kHll.obj $(COMMONLIB)49 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC :$@ $** $(RTLLIB) os2386.lib48 kHll5.exe: kHll.obj kHllMain.obj $(COMMONLIB) 49 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC /OUT:$@ $** $(RTLLIB) os2386.lib 50 50 51 51 # … … 53 53 # 54 54 dbgLXDumper.exe: dbgLXDumper.obj dummy.obj 55 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC :$@ $** $(RTLLIB) os2386.lib55 $(LD2) $(LD2FLAGS) /PMTYPE:vio /EXEC /OUT:$@ $** $(RTLLIB) os2386.lib 56 56 57 57 # Dummy source file rule -
trunk/tools/dbginfo/sym.h
r3441 r4130 1 /* $Id: sym.h,v 1. 1 2000-04-24 21:38:12bird Exp $1 /* $Id: sym.h,v 1.2 2000-08-31 03:02:28 bird Exp $ 2 2 * 3 3 * Sym-file definitions and structs. … … 39 39 unsigned short int cSymbols; /* count of symbols in list */ 40 40 unsigned short int pSymDef; /* offset of symbol chain */ 41 unsigned short int w Reserved1; /* reserved*/41 unsigned short int wSegNum; /* segment number (1 based) */ 42 42 unsigned short int wReserved2; /* reserved */ 43 43 unsigned short int wReserved3; /* reserved */ … … 47 47 unsigned short int ppLineDef; /* offset of line number record */ 48 48 unsigned char bReserved2; /* reserved */ 49 unsigned char bReserved3; /* reserved 49 unsigned char bReserved3; /* reserved (0xff) */ 50 50 unsigned char cbSegName; /* length of segment name */ 51 51 char achSegName[1]; /* cbSegName Bytes of segment-name member*/ … … 124 124 ) 125 125 126 #pragma pack() 126 127 #endif
Note:
See TracChangeset
for help on using the changeset viewer.