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/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());
Note: See TracChangeset for help on using the changeset viewer.