Changeset 145 for trunk


Ignore:
Timestamp:
Oct 26, 2006, 1:30:27 AM (19 years ago)
Author:
dmik
Message:

Common: System Exceptions:

  • Added recording the word the register value points to in the <Register> tag.
  • Added recording memory dump around EIP for every stack frame using the <Dump> tag inside <Location>.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tools/qsysxcpt_pm.cpp

    r143 r145  
    216216    {
    217217        APIRET arc;
    218         ULONG ulCountPages = 1;
    219         ULONG ulFlagsPage = 0;
    220         arc = DosQueryMem( (PVOID) ulValue, &ulCountPages, &ulFlagsPage );
     218        ULONG ulCount = 4;
     219        ULONG ulFlags = 0;
     220        arc = DosQueryMem( (PVOID) ulValue, &ulCount, &ulFlags );
    221221   
    222222        if ( arc == NO_ERROR || arc == ERROR_INVALID_ADDRESS )
    223223        {
    224224            if ( arc == NO_ERROR )
    225                 fprintf( file, " flags=\"%08lX\"/>\n", ulFlagsPage );
     225            {
     226                fprintf( file, " flags=\"%08lX\"", ulFlags );
     227                if ( ulFlags & (PAG_COMMIT | PAG_READ) == (PAG_COMMIT | PAG_READ) )
     228                    fprintf( file, " word=\"%08lX\"/>\n", *(ULONG *) ulValue );
     229                else
     230                    fprintf( file, "/>\n" );
     231            }
    226232            else
    227233                fprintf( file, " flags=\"invalid\"/>\n" );
     234        }
     235        else
     236        {
     237            fprintf( file, ">\n" );
     238            qt_excWriteErrorMsg( file, 6, "DosQueryMem returned %lu"
     239                                 "and flags %08lX", arc, ulFlags );
     240            fprintf( file, "     </Register>\n" );
    228241        }
    229242    }
     
    247260    else
    248261        fprintf( file, "     <Frame pointer=\"current\">\n" );
    249            
    250     if ( ulAddress )
    251     {
    252         fprintf( file, "      <Location address=\"%08lX\">\n", ulAddress );
    253    
    254         arc = DosQueryModFromEIP( &hMod, &ulObject,
    255                                   sizeof(szMod), szMod, &ulOffset,
    256                                   ulAddress );
    257    
    258         if (arc != NO_ERROR)
    259             qt_excWriteErrorMsg( file, 6, "%s: DosQueryModFromEIP returned %lu",
    260                                  szMod, arc );
    261         else
    262         {
    263             DosQueryModuleName( hMod, sizeof(szMod), szMod );
    264             fprintf( file, "       <Module ID=\"%04lX\" name=\"", hMod );
    265             qt_excEscapeString( file, szMod );
    266             fprintf( file, "\" \n"
    267                            "               segment=\"%04lX\" offset=\"%08lX\"/>\n",
    268                      ulObject + 1, ulOffset );
     262
     263    fprintf( file, "      <Location address=\"%08lX\">\n", ulAddress );
     264   
     265    arc = DosQueryModFromEIP( &hMod, &ulObject,
     266                              sizeof(szMod), szMod, &ulOffset,
     267                              ulAddress );
     268
     269    if (arc != NO_ERROR)
     270        qt_excWriteErrorMsg( file, 7, "%s: DosQueryModFromEIP returned %lu",
     271                             szMod, arc );
     272    else
     273    {
     274        DosQueryModuleName( hMod, sizeof(szMod), szMod );
     275        fprintf( file, "       <Module ID=\"%04lX\" name=\"", hMod );
     276        qt_excEscapeString( file, szMod );
     277        fprintf( file, "\" \n"
     278                       "               segment=\"%04lX\" offset=\"%08lX\"/>\n",
     279                 ulObject + 1, ulOffset );
    269280/// @todo (r=dmik) use .DBG and .SYM files to get symbols
    270281//  (see debug.h and debug.c from the xwphelpers package)
     
    273284//                           ulObject,
    274285//                           ulOffset);
    275         }
    276     }
    277     else
    278         qt_excWriteErrorMsg( file, 5, "Unable to access stack frame" );
     286    }
     287
     288    {
     289        enum { enmDelta = 8 };
     290        UCHAR *pch = (UCHAR *) ulAddress - enmDelta;
     291        UCHAR *pchEnd = (UCHAR *) ulAddress + enmDelta - 1;
     292        ULONG ulCount = enmDelta * 2;
     293        ULONG ulFlags = 0;
     294        APIRET arc = NO_ERROR;
     295        while ( 1 )
     296        {
     297            arc = DosQueryMem( (void *) (ULONG) pch, &ulCount, &ulFlags );
     298            if ( arc == NO_ERROR )
     299            {
     300                if ( ulCount >= enmDelta * 2 )
     301                    break;
     302                if ( pch + ulCount <= (UCHAR *) ulAddress )
     303                {   // ulAddress is outside the pch object
     304                    pch += ulCount;
     305                    ulCount = enmDelta * 2 - ulCount;
     306                }
     307                else
     308                {   // ulAddress is within the pch object
     309                    pchEnd = pch += ulCount;
     310                    break;
     311                }
     312            }
     313            else if ( arc == ERROR_INVALID_ADDRESS )
     314            {
     315                if ( ((ULONG) pch) & 0xFFFFF000 == ulAddress & 0xFFFFF000 )
     316                    break; // the same page, ulAddress inaccessible
     317                pch = (UCHAR *) (ulAddress & 0xFFFFF000);
     318            }
     319        }
     320        fprintf( file, "       <Dump address=\"%08lX\">\n        ", pch );
     321        if ( arc == NO_ERROR &&
     322             ulFlags & (PAG_COMMIT|PAG_READ) == (PAG_COMMIT | PAG_READ) )
     323        {
     324            for ( ; pch < pchEnd; ++pch )
     325                fprintf( file, "%02lX%c", (ULONG) *pch,
     326                         ulAddress - (ULONG) pch == 1 ? '-' : ' ' );
     327            fprintf( file, "\n" );
     328        }
     329        else
     330            qt_excWriteErrorMsg( file, 0, "%08lX: DosQueryMem returned %lu"
     331                                 "and flags %08lX", pch, arc, ulFlags );
     332        fprintf( file, "       </Dump>\n" );
     333    }
    279334   
    280335    fprintf( file, "      </Location>\n"
     
    303358        {
    304359            // we're on a page boundary: check access
    305             ULONG ulCountPages = 0x1000;
    306             ULONG ulFlagsPage = 0;
    307             APIRET arc = DosQueryMem( (void *)pulStackWord,
    308                                       &ulCountPages, &ulFlagsPage );
     360            ULONG ulCount = 0x1000;
     361            ULONG ulFlags = 0;
     362            APIRET arc = DosQueryMem( (void *) pulStackWord,
     363                                      &ulCount, &ulFlags );
    309364            if (    (arc != NO_ERROR)
    310365                 || (   arc == NO_ERROR
    311                      && (ulFlagsPage & (PAG_COMMIT|PAG_READ))
     366                     && (ulFlags & (PAG_COMMIT|PAG_READ))
    312367                         != (PAG_COMMIT|PAG_READ)) )
    313368            {
    314369                fprintf( file, "     <Frame pointer=\"%08lX\">\n",
    315370                         (ULONG) pulStackWord );
    316                 qt_excWriteErrorMsg( file, 6,
    317                                      "Unable to access stack frame, DosQueryMem "
    318                                      "returned %lu and flags %08lX",
    319                                      arc, ulFlagsPage );
     371                qt_excWriteErrorMsg( file, 6, "DosQueryMem returned %lu "
     372                                     "and flags %08lX", arc, ulFlags );
    320373                fprintf( file, "     </Frame>\n" );
    321374                pulStackWord += 0x1000;
Note: See TracChangeset for help on using the changeset viewer.