Ignore:
Timestamp:
Apr 7, 2011, 2:28:29 AM (14 years ago)
Author:
dmik
Message:

kernel32: Fixed: Parsing .SYM files when printing the stack trace in debug mode was not thread safe which caused garbage and nested crashes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/exceptions.cpp

    r21568 r21610  
    116116static void sprintfException(PEXCEPTIONREPORTRECORD pERepRec, PEXCEPTIONREGISTRATIONRECORD pERegRec, PCONTEXTRECORD pCtxRec, PVOID p, PSZ szTrapDump);
    117117
    118 static char szTrapDump[2048] = {0};
    119 
    120118#ifdef DEBUG
    121119void PrintWin32ExceptionChain(PWINEXCEPTION_FRAME pframe);
     
    709707                             PSZ                          szTrapDump)
    710708{
    711 // @@VP20040507: This function uses a static buffer szTrapDump, therefore
    712 //               any local buffers also can be made static to save
    713 //               stack space and possibly avoid out of stack exception.
    714709    if(pERepRec->ExceptionNum == XCPT_GUARD_PAGE_VIOLATION)
    715710    {
     
    727722    ULONG  ulModule;                                          /* module number */
    728723    ULONG  ulObject;                        /* object number within the module */
    729 static    CHAR   szModule[260];                        /* buffer for the module name */
     724    CHAR   szModule[260];                        /* buffer for the module name */
    730725    ULONG  ulOffset;             /* offset within the object within the module */
    731 static    char   szLineException[128];
    732 static    char   szLineExceptionType[128];
     726    char   szLineException[512];
     727    char   szLineExceptionType[128];
    733728
    734729    szLineException[0]  = 0;                                              /* initialize */
     
    952947        sprintf(szTrapDump + strlen(szTrapDump), "   %s\n", szLineExceptionType);
    953948
     949    sprintf(szLineException, "   Exception Address = %08x ", pERepRec->ExceptionAddress);
     950    strcat(szTrapDump, szLineException);
     951
    954952    rc = DosQueryModFromEIP(&ulModule, &ulObject, sizeof(szModule),
    955953                            szModule, &ulOffset, (ULONG)pERepRec->ExceptionAddress);
    956954
    957     sprintf(szLineException, "   Exception Address = %08x ", pERepRec->ExceptionAddress);
    958     strcat(szTrapDump, szLineException);
    959 
    960955    if(rc == NO_ERROR && ulObject != -1)
    961956    {
    962         sprintf(szLineException, "<%.*s> (#%u) obj #%u:%08x", 64, szModule, ulModule, ulObject, ulOffset);
     957        sprintf(szLineException, "<%8.8s> (%04X) obj %04X:%08X", szModule, ulModule, ulObject + 1, ulOffset);
    963958#ifdef RAS
    964         static char szSYMInfo[260];
    965         static char Name[260];
    966 
    967         DosQueryModuleName(ulModule, sizeof(Name), Name);
    968 
    969         int namelen = strlen(Name);
     959        char szSYMInfo[260];
     960
     961        DosQueryModuleName(ulModule, sizeof(szModule), szModule);
     962
     963        int namelen = strlen(szModule);
    970964        if(namelen > 3)
    971965        {
    972                 strcpy(Name + namelen - 3, "SYM");
    973                 dbgGetSYMInfo(Name, ulObject, ulOffset, szSYMInfo, sizeof (szSYMInfo));
    974                 strcat(szLineException, " ");
    975                 strcat(szLineException, szSYMInfo);
    976         }
     966                strcpy(szModule + namelen - 3, "SYM");
     967                dbgGetSYMInfo(szModule, ulObject, ulOffset, szSYMInfo, sizeof (szSYMInfo),
     968                          FALSE);
     969            strcat(szLineException, " ");
     970            strcat(szLineException, szSYMInfo);
     971        }
    977972#else
    978973        strcat(szLineException, "\n");
     
    993988            ulObject = 0xFF;
    994989            ulOffset = (ULONG)pERepRec->ExceptionAddress - (ULONG)pMod->getInstanceHandle();
    995             sprintf(szLineException, "<%.*s> (#%u) obj #%u:%08x\n", 64, szModule, ulModule, ulObject, ulOffset);
     990            sprintf(szLineException, "<%8.8s> (%04X) obj %04X:%08X", szModule, ulModule, ulObject, ulOffset);
    996991        }
    997992        else sprintf(szLineException, "<unknown win32 module>\n");
     
    10791074                             PVOID                        p)
    10801075{
     1076    char szTrapDump[2048];
     1077    szTrapDump[0] = '\0';
    10811078    sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump);
    10821079#ifdef RAS
     
    11541151            DosWrite(hFile, lpszTime, strlen(lpszTime), &ulBytesWritten);
    11551152        }
     1153
     1154        char szTrapDump[2048];
     1155        szTrapDump[0] = '\0';
    11561156        sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump);
    11571157#ifdef RAS
     
    17571757 PEXCEPTIONREGISTRATIONRECORD pExceptRec = (PEXCEPTIONREGISTRATIONRECORD)QueryExceptionChain();
    17581758
    1759   dprintf(("Exception chain list:"));
    1760   while(pExceptRec != 0 && (ULONG)pExceptRec != -1) {
    1761         dprintf(("record %x", pExceptRec));
     1759  dprintf(("OS/2 Exception chain:"));
     1760  while(pExceptRec != 0 && (ULONG)pExceptRec != -1)
     1761  {
     1762      char szBuf[512];
     1763      ULONG ulModule;
     1764      ULONG ulObject, ulOffset;
     1765      CHAR szModule[260];
     1766
     1767      *szBuf = '\0';
     1768      APIRET rc = DosQueryModFromEIP(&ulModule, &ulObject, sizeof(szModule),
     1769                                     szModule, &ulOffset, (ULONG)pExceptRec->ExceptionHandler);
     1770      if(rc == NO_ERROR && ulObject != -1)
     1771      {
     1772        sprintf(szBuf, " <%8.8s> (%04X) obj %04X:%08X", szModule, ulModule, ulObject + 1, ulOffset);
     1773#ifdef RAS
     1774        char szSYMInfo[260];
     1775
     1776        DosQueryModuleName(ulModule, sizeof(szModule), szModule);
     1777
     1778        int namelen = strlen(szModule);
     1779        if(namelen > 3)
     1780        {
     1781            strcpy(szModule + namelen - 3, "SYM");
     1782            dbgGetSYMInfo(szModule, ulObject, ulOffset,
     1783                          szSYMInfo, sizeof (szSYMInfo), TRUE);
     1784            strcat(szBuf, " ");
     1785            strcat(szBuf, szSYMInfo);
     1786            // remove trailing \n or space
     1787            szBuf[strlen(szBuf) - 1] = '\0';
     1788        }
     1789#endif
     1790      }
     1791      else
     1792      {
     1793          *szBuf = '\0';
     1794      }
     1795
     1796        dprintf(("  record %08X, prev %08X, handler %08X%s",
     1797                 pExceptRec, pExceptRec->prev_structure, pExceptRec->ExceptionHandler,
     1798                 szBuf));
     1799
    17621800        pExceptRec = pExceptRec->prev_structure;
    17631801  }
     1802  dprintf(("END of OS/2 Exception chain."));
    17641803  SetFS(sel);
    17651804}
     
    17701809  dprintf(("Win32 exception chain:"));
    17711810  while ((pframe != NULL) && ((ULONG)pframe != 0xFFFFFFFF)) {
    1772         dprintf(("Record at %08X, Prev at %08X, handler at %08X", pframe, pframe->Prev, pframe->Handler));
     1811        dprintf(("  Record at %08X, Prev at %08X, handler at %08X", pframe, pframe->Prev, pframe->Handler));
    17731812        if (pframe == pframe->Prev) {
    17741813            dprintf(("Chain corrupted! Record at %08X pointing to itself!", pframe));
     
    17771816        pframe = pframe->Prev;
    17781817  }
     1818  dprintf(("END of Win32 exception chain."));
    17791819}
    17801820
Note: See TracChangeset for help on using the changeset viewer.