Changeset 21610 for trunk/src


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.

Location:
trunk/src/kernel32
Files:
3 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
  • trunk/src/kernel32/exceptstackdump.cpp

    r21302 r21610  
    7171 */
    7272
    73 BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset, CHAR *Info, ULONG cbInfo)
     73BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset,
     74                   CHAR *Info, ULONG cbInfo, BOOL fExactMatch)
    7475{
    75     static FILE    *SymFile;
    76     static MAPDEF   MapDef;
    77     static SEGDEF   SegDef;
    78     static SEGDEF  *pSegDef;
    79     static SYMDEF32 SymDef32;
    80     static SYMDEF16 SymDef16;
    81     static char     Buffer[256];
    82     static int      SegNum, SymNum, LastVal;
    83     static unsigned long int SegOffset,
     76    FILE    *SymFile;
     77    MAPDEF   MapDef;
     78    SEGDEF   SegDef;
     79    SEGDEF  *pSegDef;
     80    SYMDEF32 SymDef32;
     81    SYMDEF16 SymDef16;
     82    char     Buffer[256];
     83    int      SegNum, SymNum, LastVal;
     84    unsigned long int SegOffset,
    8485                    SymOffset, SymPtrOffset;
    8586    int rc = FALSE;
     
    9091    {
    9192//        dprintf(("Could not open symbol file %s", SymFileName));
    92         goto endofprintsym;
     93        goto endofprintsym;
    9394    }                           // endif
    9495
     
    128129            // extract symbol by symbol from the file instead of using
    129130            // symbol table that is far further 64K fence.
    130            
     131
    131132            // Offset of first symbol
    132133            SymOffset = sizeof (SEGDEF) - 1 + SegDef.cbSegName;
     
    150151                    // 32-bit symbol:
    151152                    fread(&SymDef32, sizeof(SYMDEF32), 1, SymFile);
    152 #if 0
    153                     if (SymDef32.wSymVal == TrapOffset)
    154                     {
    155                         Buffer[0] = SymDef32.achSymName[0];
    156                         fread(&Buffer[1], 1, SymDef32.cbSymName, SymFile);
    157                         Buffer[SymDef32.cbSymName] = 0x00;
    158 //                        dprintf(("%s\n", Buffer));
    159                         strcpy (Info, Buffer);
    160                         rc = TRUE;
    161                         break;
    162                     }
    163 #endif
    164                     //SvL: If it's an exact match, then the app put a procedure
    165                     //     address on the stack; ignore that
    166                     if (LastVal == TrapOffset) {
    167                         break;
    168                     }
     153
     154                    if (fExactMatch)
     155                    {
     156                        if (SymDef32.wSymVal == TrapOffset)
     157                        {
     158                            Buffer[0] = SymDef32.achSymName[0];
     159                            fread(&Buffer[1], 1, SymDef32.cbSymName, SymFile);
     160                            Buffer[SymDef32.cbSymName] = 0x00;
     161//                            dprintf(("%s\n", Buffer));
     162#ifdef RAS
     163                            strncpy(Info, Buffer, cbInfo);
     164#else
     165                            strcpy (Info, Buffer);
     166#endif
     167                            rc = TRUE;
     168                            break;
     169                        }
     170                    }
     171                    else
     172                    {
     173                        //SvL: If it's an exact match, then the app put a procedure
     174                        //     address on the stack; ignore that
     175                        if (LastVal == TrapOffset) {
     176                            break;
     177                        }
     178                    }
     179
    169180                    if (SymDef32.wSymVal > TrapOffset)
    170181                    {
     
    185196                        // symbol found, as above
    186197#ifdef RAS
    187                         snprintf(&Info[strlen(Info)], cbInfo - strlen(Info),  "  and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
    188 #else
    189                         sprintf(&Info[strlen(Info)], "  and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
    190 #endif
    191                         rc = TRUE;
     198                        snprintf(&Info[strlen(Info)], cbInfo - strlen(Info),  " and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
     199#else
     200                        sprintf(&Info[strlen(Info)], " and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
     201#endif
     202                        rc = TRUE;
    192203                        break;
    193                     }
     204                    }
    194205                    /*printf("32 Bit Symbol <%s> Address %p",Buffer,SymDef32.wSymVal); */
    195206#ifdef FIX64KLIMIT
     
    202213                    fread(&SymDef16, sizeof(SYMDEF16), 1, SymFile);
    203214
    204                     //SvL: If it's an exact match, then the app put a procedure
    205                     //     address on the stack; ignore that
    206                     if (LastVal == TrapOffset) {
    207                         break;
    208                     }
     215                    if (fExactMatch)
     216                    {
     217                        if (SymDef16.wSymVal == TrapOffset)
     218                        {
     219                            Buffer[0] = SymDef16.achSymName[0];
     220                            fread(&Buffer[1], 1, SymDef16.cbSymName, SymFile);
     221                            Buffer[SymDef16.cbSymName] = 0x00;
     222//                            dprintf(("%s\n", Buffer));
     223#ifdef RAS
     224                            strncpy(Info, Buffer, cbInfo);
     225#else
     226                            strcpy (Info, Buffer);
     227#endif
     228                            rc = TRUE;
     229                            break;
     230                        }
     231                    }
     232                    else
     233                    {
     234                            //SvL: If it's an exact match, then the app put a procedure
     235                                //     address on the stack; ignore that
     236                            if (LastVal == TrapOffset) {
     237                            break;
     238                            }
     239                    }
    209240
    210241                    if (SymDef16.wSymVal > TrapOffset)
     
    223254                    {
    224255#ifdef RAS
    225                         snprintf(&Info[strlen(Info)], cbInfo - strlen(Info),  "  and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
    226 #else
    227                         sprintf(&Info[strlen(Info)], "  and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
    228 #endif
    229                         rc = TRUE;
     256                        snprintf(&Info[strlen(Info)], cbInfo - strlen(Info),  " and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
     257#else
     258                        sprintf(&Info[strlen(Info)], " and %s - 0x%X\n", Buffer, LastVal - TrapOffset);
     259#endif
     260                        rc = TRUE;
    230261                        break;
    231262                    }
     
    253284    return rc;
    254285}
    255 BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset)
     286BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset,
     287                     BOOL fExactMatch)
    256288{
    257289    static char szInfo[256];
    258     BOOL rc = dbgGetSYMInfo (SymFileName, Object, TrapOffset, szInfo, sizeof (szInfo));
     290    BOOL rc = dbgGetSYMInfo (SymFileName, Object, TrapOffset,
     291                             szInfo, sizeof (szInfo), fExactMatch);
    259292    dprintf(("%s", szInfo));
    260293    return rc;
     
    299332
    300333  dprintf(("** BEGIN STACK DUMP **\n"));
    301   while(stacktop > stackbase) 
     334  while(stacktop > stackbase)
    302335  {
    303336        Size = 10;
     
    355388
    356389                                strcpy(Name + namelen - 3, "SYM");
    357                                 dbgPrintSYMInfo(Name, ObjNum, Offset);
     390                                dbgPrintSYMInfo(Name, ObjNum, Offset, FALSE);
    358391                        }
    359392                }
     
    381414  } //while
    382415
    383   addr = pCtxRec->ctx_RegEip;   
     416  addr = pCtxRec->ctx_RegEip;
    384417  if(WinExe && WinExe->insideModule(addr) && WinExe->insideModuleCode(addr)) {
    385418     sprintf(Name, "%s", WinExe->getModuleName());
  • trunk/src/kernel32/exceptstackdump.h

    r21302 r21610  
    541541    #pragma pack()
    542542
    543     BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset, char *Info, ULONG cbInfo);
    544     BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset);
    545    
     543    BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset,
     544                       CHAR *Info, ULONG cbInfo, BOOL fExactMatch);
     545    BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset,
     546                         BOOL fExactMatch);
     547
    546548    /*
    547549     * dbgPrintStack:
Note: See TracChangeset for help on using the changeset viewer.