Changeset 149


Ignore:
Timestamp:
Nov 1, 2006, 7:18:21 PM (19 years ago)
Author:
dmik
Message:

Common: System Exceptions:

  • Updated all comment and open/close parenthesis styles.
  • Changed the name of the trap file subdirectory to '.systraps' (preparing to create a LIBC patch); the full trap file name version now ends with '.trp.xml' (for easier file association setup).
File:
1 edited

Legend:

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

    r148 r149  
    6060//     contexts to the trap file when a real exception happens on one thread
    6161
    62 /*! \class QtOS2SysXcptMainHandler qt_os2.h
    63 
    64     @todo (r=dmik) describe...
    65     
    66     - must be instantiated on the stack of the main thread only
    67     - should be instantiated before a QAplication instance is created
    68       (does nothing otherwise)
    69     - note that callback can be called on any thread
    70 */
     62/** @class QtOS2SysXcptMainHandler qt_os2.h
     63 *
     64 *  @todo (r=dmik) describe...
     65 *
     66 *  - must be instantiated on the stack of the main thread only
     67 *  - should be instantiated before a QAplication instance is created
     68 *    (does nothing otherwise)
     69 *  - note that callback can be called on any thread
     70 */
    7171
    7272/* static */
     
    7575ERR QtOS2SysXcptMainHandler::libcHandler = NULL;
    7676
    77 /*!
    78     @todo (r=dmik) describe...       
    79 */
    80 QtOS2SysXcptMainHandler::QtOS2SysXcptMainHandler( QtOS2SysXcptCallback cb )
     77/**
     78 *  @todo (r=dmik) describe...       
     79 */
     80QtOS2SysXcptMainHandler::QtOS2SysXcptMainHandler (QtOS2SysXcptCallback cb)
    8181{
    8282    rec.prev_structure = NULL;
     
    8484   
    8585    PTIB ptib = NULL;
    86     DosGetInfoBlocks( &ptib, NULL );
    87     Q_ASSERT( ptib && ptib->tib_ptib2 );
    88 
    89     if ( ptib && ptib->tib_ptib2 )
    90     {
    91         // must be instantiated only on the main (first) thread
    92         Q_ASSERT( ptib->tib_ptib2->tib2_ultid == 1 );
    93         if ( ptib->tib_ptib2->tib2_ultid == 1 )
    94         {
    95             // must not be already instantiated
    96             Q_ASSERT( installed == FALSE );
    97             Q_ASSERT( libcHandler == NULL );
    98             if ( installed == FALSE && libcHandler == NULL )
     86    DosGetInfoBlocks (&ptib, NULL);
     87    Q_ASSERT (ptib && ptib->tib_ptib2);
     88
     89    if (ptib && ptib->tib_ptib2)
     90    {
     91        /* must be instantiated only on the main (first) thread */
     92        Q_ASSERT (ptib->tib_ptib2->tib2_ultid == 1);
     93        if (ptib->tib_ptib2->tib2_ultid == 1)
     94        {
     95            /* must not be already instantiated */
     96            Q_ASSERT (installed == FALSE);
     97            Q_ASSERT (libcHandler == NULL);
     98            if (installed == FALSE && libcHandler == NULL)
    9999            {
    100100                installed = TRUE;
    101101                callback = cb;
    102                 // install the exception handler for the main thread
     102                /* install the exception handler for the main thread */
    103103                rec.ExceptionHandler = handler;
    104                 DosSetExceptionHandler( &rec );
    105             }
    106         }
    107     }
    108 }
    109 
    110 /*!
    111     @todo (r=dmik) describe...       
    112 */
     104                DosSetExceptionHandler (&rec);
     105            }
     106        }
     107    }
     108}
     109
     110/**
     111 *  @todo (r=dmik) describe...       
     112 */
    113113QtOS2SysXcptMainHandler::~QtOS2SysXcptMainHandler()
    114114{
    115     Q_ASSERT( rec.ExceptionHandler == handler || rec.ExceptionHandler == NULL );
    116     if ( rec.ExceptionHandler == handler )
    117     {
    118         // uninstall the exception handler for the main thread
    119         DosUnsetExceptionHandler( &rec );
     115    Q_ASSERT (rec.ExceptionHandler == handler || rec.ExceptionHandler == NULL);
     116    if (rec.ExceptionHandler == handler)
     117    {
     118        /* uninstall the exception handler for the main thread */
     119        DosUnsetExceptionHandler (&rec);
    120120        rec.ExceptionHandler = NULL;
    121121        callback = NULL;
     
    124124}
    125125
    126 static void qt_excEscapeString( FILE *file, const char *pcszStr );
     126static void qt_excEscapeString (FILE *file, const char *pcszStr);
    127127
    128128#define XcptPvt QtOS2SysXcptMainHandler::Private
     
    131131{
    132132public:
    133     static void callbackWriter( const char *msg );
    134 
    135     static inline int askCallback( QtOS2SysXcptReq req )
    136     {
    137         if ( callback )
    138             return callback( req, NULL, 0 );
     133    static void callbackWriter (const char *msg);
     134
     135    static inline int askCallback (QtOS2SysXcptReq req)
     136    {
     137        if (callback)
     138            return callback (req, NULL, 0);
    139139        return FALSE;
    140140    }
    141141
    142     static inline int letCallback( QtOS2SysXcptReq req )
    143     {
    144         if ( callback )
    145             return callback( req, callbackWriter, 0 );
     142    static inline int letCallback (QtOS2SysXcptReq req)
     143    {
     144        if (callback)
     145            return callback (req, callbackWriter, 0);
    146146        return FALSE;
    147147    }
     
    154154
    155155/* static */
    156 void XcptPvt::callbackWriter( const char *msg )
    157 {
    158     if ( file )
    159         qt_excEscapeString( file, msg );
    160 }
    161 
    162 /*! \internal
    163     Writes the given string with [<>&'"] characters escaped for XML.
    164 */
    165 static void qt_excEscapeString( FILE *file, const char *pcszStr )
     156void XcptPvt::callbackWriter (const char *msg)
     157{
     158    if (file)
     159        qt_excEscapeString (file, msg);
     160}
     161
     162/** \internal
     163 *  Writes the given string with [<>&'"] characters escaped for XML.
     164 */
     165static void qt_excEscapeString (FILE *file, const char *pcszStr)
    166166{
    167167    const char *pcszChars = "<>&'\"";
     
    172172    size_t cbLen = 0;
    173173
    174     if ( !pcsz )
     174    if (!pcsz)
    175175        return;
    176176
    177     while( *pcsz )
    178     {
    179         cbLen = strcspn( pcsz, pcszChars );
    180         fwrite( pcsz, 1, cbLen, file );
     177    while (*pcsz)
     178    {
     179        cbLen = strcspn (pcsz, pcszChars);
     180        fwrite (pcsz, 1, cbLen, file);
    181181        pcsz += cbLen;
    182         if ( !*pcsz )
     182        if (!*pcsz)
    183183            break;
    184         cbLen = strchr( pcszChars, *pcsz ) - pcszChars;
     184        cbLen = strchr (pcszChars, *pcsz) - pcszChars;
    185185        pcszRepl = aszEntities[cbLen];
    186         fwrite( pcszRepl, 1, strlen(pcszRepl), file );
     186        fwrite (pcszRepl, 1, strlen(pcszRepl), file);
    187187        ++ pcsz;
    188188    }
    189189}
    190190
    191 /*! \internal
    192     Writes the given error message.
    193 */
    194 static void qt_excWriteErrorMsg( FILE *file, ULONG ulIndent, const char *pcszMsg,
    195                                  ... )
     191/** \internal
     192 *  Writes the given error message.
     193 */
     194static void qt_excWriteErrorMsg (FILE *file, ULONG ulIndent, const char *pcszMsg,
     195                                 ...)
    196196{
    197197    char szBuf[1024];
    198198    va_list args;
    199     va_start( args, pcszMsg );
    200     fprintf( file, "%*s<Error message=\"", ulIndent, "" );
    201     vsnprintf( szBuf, sizeof(szBuf), pcszMsg, args );
     199    va_start (args, pcszMsg);
     200    fprintf (file, "%*s<Error message=\"", ulIndent, "");
     201    vsnprintf (szBuf, sizeof(szBuf), pcszMsg, args);
    202202    szBuf[sizeof(szBuf) - 1] = '\0';
    203     qt_excEscapeString( file, szBuf );
    204     fprintf( file, "\"/>\n" );
    205     va_end( args );
    206 }
    207 
    208 /*! \internal
    209     Writes the register name, value and optionally memory flags
    210 */
    211 static void qt_excWriteReg( FILE *file, const char *pszName, ULONG ulValue,
    212                             BOOL bQueryMem = TRUE )
    213 {
    214     fprintf( file, "      <Register name=\"%s\" value=\"%08lX\"",
    215              pszName, ulValue );
    216 
    217     if ( bQueryMem )
     203    qt_excEscapeString (file, szBuf);
     204    fprintf (file, "\"/>\n");
     205    va_end (args);
     206}
     207
     208/** \internal
     209 *  Writes the register name, value and optionally memory flags
     210 */
     211static void qt_excWriteReg (FILE *file, const char *pszName, ULONG ulValue,
     212                            BOOL bQueryMem = TRUE)
     213{
     214    fprintf (file, "      <Register name=\"%s\" value=\"%08lX\"",
     215             pszName, ulValue);
     216
     217    if (bQueryMem)
    218218    {
    219219        APIRET arc;
    220220        ULONG ulCount = 4;
    221221        ULONG ulFlags = 0;
    222         arc = DosQueryMem( (PVOID) ulValue, &ulCount, &ulFlags );
    223    
    224         if ( arc == NO_ERROR || arc == ERROR_INVALID_ADDRESS )
    225         {
    226             if ( arc == NO_ERROR )
    227             {
    228                 fprintf( file, " flags=\"%08lX\"", ulFlags );
    229                 if ( ulFlags & (PAG_COMMIT | PAG_READ) == (PAG_COMMIT | PAG_READ) )
    230                     fprintf( file, " word=\"%08lX\"/>\n", *(ULONG *) ulValue );
     222        arc = DosQueryMem ((PVOID) ulValue, &ulCount, &ulFlags);
     223   
     224        if (arc == NO_ERROR || arc == ERROR_INVALID_ADDRESS)
     225        {
     226            if (arc == NO_ERROR)
     227            {
     228                fprintf (file, " flags=\"%08lX\"", ulFlags);
     229                if (ulFlags & (PAG_COMMIT | PAG_READ) == (PAG_COMMIT | PAG_READ))
     230                    fprintf (file, " word=\"%08lX\"/>\n", *(ULONG *) ulValue);
    231231                else
    232                     fprintf( file, "/>\n" );
     232                    fprintf (file, "/>\n");
    233233            }
    234234            else
    235                 fprintf( file, " flags=\"invalid\"/>\n" );
     235                fprintf (file, " flags=\"invalid\"/>\n");
    236236        }
    237237        else
    238238        {
    239             fprintf( file, ">\n" );
    240             qt_excWriteErrorMsg( file, 7, "DosQueryMem returned %lu"
    241                                  "and flags %08lX", arc, ulFlags );
    242             fprintf( file, "      </Register>\n" );
     239            fprintf (file, ">\n");
     240            qt_excWriteErrorMsg (file, 7, "DosQueryMem returned %lu"
     241                                 "and flags %08lX", arc, ulFlags);
     242            fprintf (file, "      </Register>\n");
    243243        }
    244244    }
    245245    else
    246         fprintf( file, "/>\n" );
    247 }
    248 
    249 /*! \internal
    250     Writes information about a signle stack frame.
    251 */
     246        fprintf (file, "/>\n");
     247}
     248
     249/** \internal
     250 *  Writes information about a signle stack frame.
     251 */
    252252static void qt_excWriteStackFrame (FILE *file, ULONG ulRegEbp, ULONG ulRegEip)
    253253{
     
    327327}
    328328
    329 /*! \internal
    330     Walks the stack and writes information about stack frames.
    331 */
     329/** \internal
     330 *  Walks the stack and writes information about stack frames.
     331 */
    332332static void qt_excWriteStackFrames (FILE *file, PTIB ptib,
    333333                                    PCONTEXTRECORD pContextRec)
     
    383383}
    384384
    385 /*! \internal
    386     Writes the thread information.
    387     If ptib is not NULL, the current thread's information is to be written.
    388     If ptib is NULL, pThrdRec is guaranted not to be NULL.
    389 */
     385/** \internal
     386 *  Writes the thread information.
     387 *  If ptib is not NULL, the current thread's information is to be written.
     388 *  If ptib is NULL, pThrdRec is guaranted not to be NULL.
     389 */
    390390static void qt_excWriteThreadInfo (FILE *file, PTIB ptib, QSTREC *pThrdRec,
    391391                                   PCONTEXTRECORD pContextRec)
     
    416416                   "     <Registers>\n");
    417417
    418     if  (pContextRec->ContextFlags & CONTEXT_SEGMENTS)
     418    if (pContextRec->ContextFlags & CONTEXT_SEGMENTS)
    419419    {
    420420        qt_excWriteReg (file, "DS", pContextRec->ctx_SegDs, FALSE);
     
    424424    }
    425425   
    426     if  (pContextRec->ContextFlags & CONTEXT_INTEGER)
     426    if (pContextRec->ContextFlags & CONTEXT_INTEGER)
    427427    {
    428428        qt_excWriteReg (file, "EAX", pContextRec->ctx_RegEax);
     
    434434    }
    435435
    436     if  (pContextRec->ContextFlags & CONTEXT_CONTROL)
     436    if (pContextRec->ContextFlags & CONTEXT_CONTROL)
    437437    {
    438438        qt_excWriteReg (file, "CS", pContextRec->ctx_SegCs, FALSE);
     
    561561}
    562562
    563 /*! \internal
    564     Writes module information to the log file.
    565     \a ulOrigin is 1 (self), 2 (imported), or 3 (loaded). Other values are
    566     ignored.
    567 */
     563/** \internal
     564 *  Writes module information to the log file.
     565 *  \a ulOrigin is 1 (self), 2 (imported), or 3 (loaded). Other values are
     566 *  ignored.
     567 */
    568568static void qt_excWriteModule (FILE *file, USHORT hmte, char *pszName,
    569569                               ULONG ulOrigin = 0)
     
    580580    arc = DosQueryPathInfo (pszName, FIL_STANDARD, &Status, sizeof (Status));
    581581
    582     if ((ulOrigin >= 1 && ulOrigin <= 3) || arc == NO_ERROR )
     582    if ((ulOrigin >= 1 && ulOrigin <= 3) || arc == NO_ERROR)
    583583    {
    584584        fprintf (file, "\n           ");
     
    599599}
    600600
    601 /*! \internal
    602     Writes module and all its imports information to the log file.
    603     \a ulOrigin is 1 (self), or 3 (loaded), other values are ignored.
    604 */
     601/** \internal
     602 *  Writes module and all its imports information to the log file.
     603 *  \a ulOrigin is 1 (self), or 3 (loaded), other values are ignored.
     604 */
    605605static void qt_excWriteModules (FILE *file, USHORT hmte, QSLREC *pFirstLibRec,
    606606                                ULONG ulOrigin)
     
    643643} WMOS_STATE;
    644644
    645 /*! \internal
    646     Walks the stack and writes information about all encountered modules.
    647     Used only when DosQuerySysState() fails (so qt_excWriteModules() is not
    648     applicable). We use recursiveness to avoid module record duplicates.
    649 */
     645/** \internal
     646 *  Walks the stack and writes information about all encountered modules.
     647 *  Used only when DosQuerySysState() fails (so qt_excWriteModules() is not
     648 *  applicable). We use recursiveness to avoid module record duplicates.
     649 */
    650650static void qt_excWriteModulesOnStack (WMOS_STATE *pState)
    651651{
     
    742742} PROCESSINFO;
    743743
    744 /*! \internal
    745     Writes exception information to the log file.
    746 */
     744/** \internal
     745 *  Writes exception information to the log file.
     746 */
    747747static void qt_excWriteException (FILE *file,
    748748                                  PROCESSINFO *pInfo,
     
    868868 *  log file. Note that \a pszFileName must be at least CCHMAXPATH bytes length.
    869869 */
    870 static FILE *qt_excOpenLogFile( const char *pcszBasePath, char *pszFileName )
     870static FILE *qt_excOpenLogFile (const char *pcszBasePath, char *pszFileName)
    871871{
    872872    FILE *file = NULL;
    873873
    874874    char szFileName[CCHMAXPATH];
    875     char szDir[] = "\\.qt3traps";
     875    char szDir[] = "\\.systrap";
    876876    char szFile[] = "\\12345678.123";
    877877    enum { cbFileName = sizeof(szFileName) };
     
    885885    char *pszStamp = NULL;
    886886   
    887     if ( pcszBasePath == NULL || pszFileName == NULL )
     887    if (pcszBasePath == NULL || pszFileName == NULL)
    888888        return NULL;
    889889   
    890     if ( access( pcszBasePath, F_OK ) != 0 )
     890    if (access (pcszBasePath, F_OK) != 0)
    891891        return NULL;
    892892   
    893     if ( strlen( pcszBasePath ) + cbDir + cbFile - 2 >= CCHMAXPATH )
     893    if (strlen (pcszBasePath) + cbDir + cbFile - 2 >= CCHMAXPATH)
    894894        return NULL;
    895895
    896     // get the full path if it's not 'X:'
    897     if ( strlen(pcszBasePath) != 2 ||
    898          pcszBasePath[1] != ':' )
    899     {
    900         if( DosQueryPathInfo( pcszBasePath, FIL_QUERYFULLNAME,
    901                               szFileName, cbFileName ) != NO_ERROR )
     896    /* get the full path if it's not 'X:' */
     897    if (strlen(pcszBasePath) != 2 ||
     898         pcszBasePath[1] != ':')
     899    {
     900        if (DosQueryPathInfo (pcszBasePath, FIL_QUERYFULLNAME,
     901                              szFileName, cbFileName) != NO_ERROR)
    902902            return NULL;
    903903    }
    904904    else
    905         strcpy( szFileName, pcszBasePath );
    906    
    907     strcat( szFileName, szDir );
    908     if ( access( szFileName, F_OK ) != 0 )
    909         if ( mkdir( szFileName, 0777 ) != 0 )
     905        strcpy (szFileName, pcszBasePath);
     906   
     907    strcat (szFileName, szDir);
     908    if (access (szFileName, F_OK) != 0)
     909        if (mkdir (szFileName, 0777) != 0)
    910910            return NULL;
    911911   
    912     cbDirLen = strlen( szFileName );
     912    cbDirLen = strlen (szFileName);
    913913       
    914     // first, try to use the desired base file name
    915 
    916     // we will append -NN to the file name to add some 'fraction of a
    917     // second' granularity to avoid name conflicts (0 <= NNN <= 99)
    918     cbLen = strlen( pszFileName );
    919     if ( cbDirLen + cbLen + 8 /* \-NN.xml */ < CCHMAXPATH )
    920     {
    921         strcat( szFileName, "\\" );
    922         strcat( szFileName, pszFileName );
     914    /* first, try to use the desired base file name */
     915
     916    /* we will append -NN to the file name to add some 'fraction of a
     917     * second' granularity to avoid name conflicts (0 <= NNN <= 99) */
     918    cbLen = strlen (pszFileName);
     919    if (cbDirLen + cbLen + 12 /* \-NN.trp.xml */ < CCHMAXPATH)
     920    {
     921        strcat (szFileName, "\\");
     922        strcat (szFileName, pszFileName);
    923923        cbLen += cbDirLen + 1 /* \ */;
    924         for( ul = 0; ul < 100; ++ul )
    925         {
    926             sprintf( szFileName + cbLen, "-%02ld.xml", ul );
    927             if ( access( szFileName, F_OK ) == 0 )
     924        for (ul = 0; ul < 100; ++ul)
     925        {
     926            sprintf (szFileName + cbLen, "-%02ld.trp.xml", ul);
     927            if (access (szFileName, F_OK) == 0)
    928928                continue;
    929             file = fopen( szFileName, "wt" );
    930             if ( file )
     929            file = fopen (szFileName, "wt");
     930            if (file)
    931931                break;
    932             if ( errno == ENAMETOOLONG )
     932            if (errno == ENAMETOOLONG)
    933933                break;
    934934        }
    935935    }
    936936
    937     // next, try a time stamp as a 8x3 file name
    938     if ( file == NULL )
     937    /* next, try a time stamp as a 8x3 file name */
     938
     939    if (file == NULL)
    939940    {
    940941        pszStamp = szFileName + cbDirLen + 1;
    941         strcat( szFileName, szFile );
     942        strcat (szFileName, szFile);
    942943       
    943         ulStamp = time( NULL );
    944    
    945         // In order to add some 'fraction of a second' granularity to the
    946         // timestamp, we shift it by 5 bits. This gives us 0x07FFFFFF seconds
    947         // which is a period of approx. 4,25 years. 5 bits in turn give us 32
    948         // fractions of a second.
     944        ulStamp = time (NULL);
     945   
     946        /* In order to add some 'fraction of a second' granularity to the
     947         * timestamp, we shift it by 5 bits. This gives us 0x07FFFFFF seconds
     948         * which is a period of approx. 4,25 years. 5 bits in turn give us 32
     949         * fractions of a second. */
    949950        ulStamp <<= 5;
    950951       
    951         // try some few adajcent stamps if the first one fails
    952         for ( ul = 0; ul < 32; ++ul, ++ulStamp )
    953         {
    954             sprintf( pszStamp, "%08lX.xml", ulStamp );
    955             if ( access( szFileName, F_OK ) == 0 )
     952        /* try some few next stamps if the first one fails */
     953        for (ul = 0; ul < 32; ++ul, ++ulStamp)
     954        {
     955            sprintf (pszStamp, "%08lX.xml", ulStamp);
     956            if (access (szFileName, F_OK) == 0)
    956957                continue;
    957             file = fopen( szFileName, "wt" );
    958             if ( file )
     958            file = fopen (szFileName, "wt");
     959            if (file)
    959960                break;
    960961        }
    961962    }
    962963   
    963     if ( file )
    964     {
    965         strncpy( pszFileName, szFileName, CCHMAXPATH - 1 );
     964    if (file)
     965    {
     966        strncpy (pszFileName, szFileName, CCHMAXPATH - 1);
    966967        pszFileName[CCHMAXPATH - 1] = '\0';
    967968    }
     
    970971}
    971972
    972 /*! \internal
    973     Qt Exception handler.
    974 */
     973/** \internal
     974 *  Qt Exception handler.
     975 */
    975976/* static */
    976977ULONG APIENTRY
    977 QtOS2SysXcptMainHandler::handler( PEXCEPTIONREPORTRECORD pReportRec,
     978QtOS2SysXcptMainHandler::handler (PEXCEPTIONREPORTRECORD pReportRec,
    978979                                  PEXCEPTIONREGISTRATIONRECORD pRegRec,
    979980                                  PCONTEXTRECORD pContextRec,
    980                                   PVOID pv )
     981                                  PVOID pv)
    981982{
    982983    PROCESSINFO Info = {0};
     
    10731074                /* find the base name (w/o path and extension) */
    10741075                char *psz = strrchr (szFullExeName, '\\');
    1075                 if ( psz )
     1076                if (psz)
    10761077                    ++ psz;
    1077                 if ( !psz )
     1078                if (!psz)
    10781079                    psz = szFullExeName;
    10791080                strcpy (szBaseExeName, psz);
     
    11151116                char szBootDrive[] = "\0:";
    11161117                ULONG ulBootDrive;
    1117                 DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
    1118                                  &ulBootDrive, sizeof(ulBootDrive) );
     1118                DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
     1119                                 &ulBootDrive, sizeof(ulBootDrive));
    11191120                szBootDrive[0] = (char) ulBootDrive + 'A' - 1;
    11201121                file = qt_excOpenLogFile (szBootDrive, szFileName);
Note: See TracChangeset for help on using the changeset viewer.