Changeset 60258 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Mar 30, 2016 11:34:54 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgmodcodeview.cpp
r59974 r60258 153 153 /** The size of the segment names. */ 154 154 uint32_t cbSegNames; 155 156 /** Size of the block pchSrcStrings points to. */ 157 size_t cbSrcStrings; 158 /** Buffer space allocated for the source string table. */ 159 size_t cbSrcStringsAlloc; 160 /** Copy of the last CV8 source string table. */ 161 char *pchSrcStrings; 162 163 /** The size of the current source information table. */ 164 size_t cbSrcInfo; 165 /** Buffer space allocated for the source information table. */ 166 size_t cbSrcInfoAlloc; 167 /** Copy of the last CV8 source information table. */ 168 uint8_t *pbSrcInfo; 155 169 156 170 /** @} */ … … 754 768 755 769 /** 770 * Makes a copy of the CV8 source string table. 771 * 772 * It will be references in a subsequent source information table, and again by 773 * line number tables thru that. 774 * 775 * @returns IPRT status code 776 * @param pThis The CodeView debug info reader instance. 777 * @param pvSrcStrings The source string table. 778 * @param cbSrcStrings The size of the source strings. 779 * @param fFlags Flags reserved for future exploits, MBZ. 780 */ 781 static int rtDbgModCvSsProcessV8SrcStrings(PRTDBGMODCV pThis, void const *pvSrcStrings, size_t cbSrcStrings, uint32_t fFlags) 782 { 783 if (cbSrcStrings >= pThis->cbSrcStringsAlloc) 784 { 785 void *pvNew = RTMemRealloc(pThis->pchSrcStrings, cbSrcStrings + 1); 786 AssertReturn(pvNew, VERR_NO_MEMORY); 787 pThis->pchSrcStrings = (char *)pvNew; 788 pThis->cbSrcStrings = cbSrcStrings; 789 pThis->cbSrcStringsAlloc = cbSrcStrings + 1; 790 } 791 memcpy(pThis->pchSrcStrings, pvSrcStrings, cbSrcStrings); 792 pThis->pchSrcStrings[cbSrcStrings] = '\0'; 793 794 if (LogIs3Enabled()) 795 { 796 size_t iFile = 0; 797 size_t off = pThis->pchSrcStrings[0] != '\0' ? 0 : 1; 798 while (off < cbSrcStrings) 799 { 800 size_t cch = strlen(&pThis->pchSrcStrings[off]); 801 Log3((" %010zx #%03zu: %s\n", off, iFile, &pThis->pchSrcStrings[off])); 802 off += cch + 1; 803 iFile++; 804 } 805 } 806 807 return VINF_SUCCESS; 808 } 809 810 811 /** 812 * Makes a copy of the CV8 source information table. 813 * 814 * It will be references in subsequent line number tables. 815 * 816 * @returns IPRT status code 817 * @param pThis The CodeView debug info reader instance. 818 * @param pvSrcInfo The source information table. 819 * @param cbSrcInfo The size of the source information table (bytes). 820 * @param fFlags Flags reserved for future exploits, MBZ. 821 */ 822 static int rtDbgModCvSsProcessV8SrcInfo(PRTDBGMODCV pThis, void const *pvSrcInfo, size_t cbSrcInfo, uint32_t fFlags) 823 { 824 if (cbSrcInfo + sizeof(RTCV8SRCINFO) > pThis->cbSrcInfoAlloc) 825 { 826 void *pvNew = RTMemRealloc(pThis->pbSrcInfo, cbSrcInfo + sizeof(RTCV8SRCINFO)); 827 AssertReturn(pvNew, VERR_NO_MEMORY); 828 pThis->pbSrcInfo = (uint8_t *)pvNew; 829 pThis->cbSrcInfo = cbSrcInfo; 830 pThis->cbSrcInfoAlloc = cbSrcInfo + sizeof(RTCV8SRCINFO); 831 } 832 memcpy(pThis->pbSrcInfo, pvSrcInfo, cbSrcInfo); 833 memset(&pThis->pbSrcInfo[cbSrcInfo], 0, sizeof(RTCV8SRCINFO)); 834 835 if (LogIs3Enabled()) 836 { 837 size_t iFile = 0; 838 size_t off = 0; 839 while (off + 4 <= cbSrcInfo) 840 { 841 PCRTCV8SRCINFO pSrcInfo = (PCRTCV8SRCINFO)&pThis->pbSrcInfo[off]; 842 const char *pszName; 843 if (pSrcInfo->offSourceName < pThis->cbDbgInfo) 844 pszName = &pThis->pchSrcStrings[pSrcInfo->offSourceName]; 845 else 846 pszName = "out-of-bounds.c!"; 847 if (pSrcInfo->uDigestType == RTCV8SRCINFO_DIGEST_TYPE_MD5) 848 { 849 Log3((" %010zx #%03zu: %RTuuid %#x=%s\n", off, iFile, &pSrcInfo->Digest.md5, pSrcInfo->offSourceName, pszName)); 850 off += sizeof(*pSrcInfo); 851 } 852 else 853 { 854 if (pSrcInfo->uDigestType == RTCV8SRCINFO_DIGEST_TYPE_NONE) 855 Log3((" %010zx #%03zu: <none> %#x=%s\n", off, iFile, pSrcInfo->offSourceName, pszName)); 856 else 857 Log3((" %010zx #%03zu: !%#x! %#x=%s\n", off, iFile, pSrcInfo->uDigestType, pSrcInfo->offSourceName, pszName)); 858 off += 8; 859 } 860 iFile++; 861 } 862 } 863 864 return VINF_SUCCESS; 865 } 866 867 868 /** 869 * Makes a copy of the CV8 source string table. 870 * 871 * It will be references in subsequent line number tables. 872 * 873 * @returns IPRT status code 874 * @param pThis The CodeView debug info reader instance. 875 * @param pvSectLines The section source line table. 876 * @param cbSectLines The size of the section source line table. 877 * @param fFlags Flags reserved for future exploits, MBZ. 878 */ 879 static int rtDbgModCvSsProcessV8SectLines(PRTDBGMODCV pThis, void const *pvSectLines, size_t cbSectLines, uint32_t fFlags) 880 { 881 /* 882 * Starts with header. 883 */ 884 PCRTCV8LINESHDR pHdr = (PCRTCV8LINESHDR)pvSectLines; 885 RTDBGMODCV_CHECK_NOMSG_RET_BF(cbSectLines >= sizeof(*pHdr)); 886 cbSectLines -= sizeof(*pHdr); 887 Log2(("RTDbgModCv: seg #%u, off %#x LB %#x \n", pHdr->iSection, pHdr->offSection, pHdr->cbSectionCovered)); 888 889 RTCPTRUNION uCursor; 890 uCursor.pv = pHdr + 1; 891 while (cbSectLines > 0) 892 { 893 /* Source file header. */ 894 PCRTCV8LINESSRCMAP pSrcHdr = (PCRTCV8LINESSRCMAP)uCursor.pv; 895 RTDBGMODCV_CHECK_NOMSG_RET_BF(cbSectLines >= sizeof(*pSrcHdr)); 896 RTDBGMODCV_CHECK_NOMSG_RET_BF(pSrcHdr->cb == pSrcHdr->cLines * sizeof(RTCV8LINEPAIR) + sizeof(RTCV8LINESSRCMAP)); 897 RTDBGMODCV_CHECK_RET_BF(!(pSrcHdr->offSourceInfo & 3), ("offSourceInfo=%#x\n", pSrcHdr->offSourceInfo)); 898 if (pSrcHdr->offSourceInfo + sizeof(uint32_t) <= pThis->cbSrcInfo) 899 { 900 PCRTCV8SRCINFO pSrcInfo = (PCRTCV8SRCINFO)&pThis->pbSrcInfo[pSrcHdr->offSourceInfo]; 901 const char *pszName = pSrcInfo->offSourceName < pThis->cbSrcStrings 902 ? &pThis->pchSrcStrings[pSrcInfo->offSourceName] : "unknown.c"; 903 pszName = rtDbgModCvAddSanitizedStringToCache(pszName, RTSTR_MAX); 904 Log2(("RTDbgModCv: #%u lines, %#x bytes, %#x=%s\n", pSrcHdr->cLines, pSrcHdr->cb, pSrcHdr->offSourceInfo, pszName)); 905 906 if (pszName) 907 { 908 /* Process the line/offset pairs. */ 909 uint32_t cLeft = pSrcHdr->cLines; 910 PCRTCV8LINEPAIR pPair = (PCRTCV8LINEPAIR)(pSrcHdr + 1); 911 while (cLeft-- > 0) 912 { 913 uint32_t idxSeg = pHdr->iSection; 914 uint64_t off = pPair->offSection + pHdr->offSection; 915 int rc = rtDbgModCvAdjustSegAndOffset(pThis, &idxSeg, &off); 916 if (RT_SUCCESS(rc)) 917 rc = RTDbgModLineAdd(pThis->hCnt, pszName, pPair->uLineNumber, idxSeg, off, NULL); 918 if (RT_SUCCESS(rc)) 919 Log3(("RTDbgModCv: %#x:%#010llx %0u\n", idxSeg, off, pPair->uLineNumber)); 920 else 921 Log(( "RTDbgModCv: %#x:%#010llx %0u - rc=%Rrc!! (org: idxSeg=%#x off=%#x)\n", 922 idxSeg, off, pPair->uLineNumber, rc, pHdr->iSection, pPair->offSection)); 923 924 /* next */ 925 pPair++; 926 } 927 Assert((uintptr_t)pPair - (uintptr_t)pSrcHdr == pSrcHdr->cb); 928 } 929 } 930 else 931 Log(("RTDbgModCv: offSourceInfo=%#x cbSrcInfo=%#x!\n", pSrcHdr->offSourceInfo, pThis->cbSrcInfo)); 932 933 /* next */ 934 cbSectLines -= pSrcHdr->cb; 935 uCursor.pu8 += pSrcHdr->cb; 936 } 937 938 return VINF_SUCCESS; 939 } 940 941 942 943 /** 756 944 * Parses a CV8 symbol table, adding symbols to the container. 757 945 * … … 783 971 784 972 case RTCV8SYMBLOCK_TYPE_SRC_STR: 785 /** @todo would have to cache the string table as the line numbers using it 786 * may be in a different .debug$S section and wlinking will therefore 787 * issue two sstSymbols entries for the module. */ 973 rc = rtDbgModCvSsProcessV8SrcStrings(pThis, pBlockHdr + 1, pBlockHdr->cb, fFlags); 788 974 break; 789 975 790 976 case RTCV8SYMBLOCK_TYPE_SECT_LINES: 977 rc = rtDbgModCvSsProcessV8SectLines(pThis, pBlockHdr + 1, pBlockHdr->cb, fFlags); 791 978 break; 792 979 793 980 case RTCV8SYMBLOCK_TYPE_SRC_INFO: 794 /* Not something we currently care about. Could be useful later 795 for checking if a source file has changed. */ 981 rc = rtDbgModCvSsProcessV8SrcInfo(pThis, pBlockHdr + 1, pBlockHdr->cb, fFlags); 796 982 break; 797 983 default: … … 855 1041 pThis->uCurStyle = RT_MAKE_U16('C', 'V'); 856 1042 pThis->uCurStyleVer = 0; 1043 pThis->cbSrcInfo = 0; 1044 pThis->cbSrcStrings = 0; 857 1045 uint8_t cchName = uCursor.pu8[cSegs * 12]; 858 1046 RTDBGMODCV_CHECK_NOMSG_RET_BF(cbSubSect >= 2 + 2 + 2 + 2 + cSegs * 12U + 1 + cchName); … … 1669 1857 { 1670 1858 PCRTCVDIRENT32 pDirEnt = &pThis->paDirEnts[i]; 1671 Log3(("Processing subsection %#u %s\n", i, rtDbgModCvGetSubSectionName(pDirEnt->uSubSectType)));1859 Log3(("Processing module %#06x subsection #%04u %s\n", pDirEnt->iMod, i, rtDbgModCvGetSubSectionName(pDirEnt->uSubSectType))); 1672 1860 PFNDBGMODCVSUBSECTCALLBACK pfnCallback = NULL; 1673 1861 switch (pDirEnt->uSubSectType) … … 1738 1926 } 1739 1927 } 1928 } 1929 1930 /* 1931 * Free temporary parsing objects. 1932 */ 1933 if (pThis->pbSrcInfo) 1934 { 1935 RTMemFree(pThis->pbSrcInfo); 1936 pThis->pbSrcInfo = NULL; 1937 pThis->cbSrcInfo = 0; 1938 pThis->cbSrcInfoAlloc = 0; 1939 } 1940 if (pThis->pchSrcStrings) 1941 { 1942 RTMemFree(pThis->pchSrcStrings); 1943 pThis->pchSrcStrings = NULL; 1944 pThis->cbSrcStrings = 0; 1945 pThis->cbSrcStringsAlloc = 0; 1740 1946 } 1741 1947
Note:
See TracChangeset
for help on using the changeset viewer.