Changeset 148 for trunk


Ignore:
Timestamp:
Nov 1, 2006, 1:12:16 AM (19 years ago)
Author:
dmik
Message:

Common: System Exceptions:

  • Added reading out and writing the module description as the 'desc' attribute of the 'Module' element;
  • Added writing the module last modification date as the 'timestamp' attribute of the 'Module' element.
File:
1 edited

Legend:

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

    r147 r148  
    212212                            BOOL bQueryMem = TRUE )
    213213{
    214     fprintf( file, "     <Register name=\"%s\" value=\"%08lX\"",
     214    fprintf( file, "      <Register name=\"%s\" value=\"%08lX\"",
    215215             pszName, ulValue );
    216216
     
    238238        {
    239239            fprintf( file, ">\n" );
    240             qt_excWriteErrorMsg( file, 6, "DosQueryMem returned %lu"
     240            qt_excWriteErrorMsg( file, 7, "DosQueryMem returned %lu"
    241241                                 "and flags %08lX", arc, ulFlags );
    242             fprintf( file, "     </Register>\n" );
     242            fprintf( file, "      </Register>\n" );
    243243        }
    244244    }
     
    258258            ulOffset = 0;
    259259
    260     fprintf (file, "     <Frame pointer=\"%08lX\">\n", ulRegEbp);
    261     fprintf (file, "      <Location address=\"%08lX\">\n", ulRegEip);
     260    fprintf (file, "      <Frame pointer=\"%08lX\">\n", ulRegEbp);
     261    fprintf (file, "       <Location address=\"%08lX\">\n", ulRegEip);
    262262   
    263263    arc = DosQueryModFromEIP (&hMod, &ulObject,
     
    266266
    267267    if (arc != NO_ERROR)
    268         qt_excWriteErrorMsg (file, 7, "%s: DosQueryModFromEIP returned %lu",
     268        qt_excWriteErrorMsg (file, 8, "%s: DosQueryModFromEIP returned %lu",
    269269                             szMod, arc);
    270270    else
    271         fprintf (file, "       <Module ID=\"%04lX\" segment=\"%04lX\" "
    272                                       "offset=\"%08lX\"/>\n",
     271        fprintf (file, "        <Module ID=\"%04lX\" segment=\"%04lX\" "
     272                                       "offset=\"%08lX\"/>\n",
    273273                 hMod, ulObject + 1, ulOffset);
    274274
     
    308308            }
    309309        }
    310         fprintf (file, "       <Dump address=\"%08lX\">\n        ", pch);
     310        fprintf (file, "        <Dump address=\"%08lX\">\n         ", pch);
    311311        if (arc == NO_ERROR &&
    312312            ulFlags & (PAG_COMMIT|PAG_READ) == (PAG_COMMIT | PAG_READ))
     
    320320            qt_excWriteErrorMsg (file, 0, "%08lX: DosQueryMem returned %lu"
    321321                                 "and flags %08lX", pch, arc, ulFlags);
    322         fprintf (file, "       </Dump>\n");
    323     }
    324    
    325     fprintf (file, "      </Location>\n");
    326     fprintf (file, "     </Frame>\n");
     322        fprintf (file, "        </Dump>\n");
     323    }
     324   
     325    fprintf (file, "       </Location>\n");
     326    fprintf (file, "      </Frame>\n");
    327327}
    328328
     
    336336    ULONG ulRegEip = pContextRec->ctx_RegEip;
    337337
    338     fprintf (file, "    <Frames>\n");
     338    fprintf (file, "     <Frames>\n");
    339339
    340340    /* first the trapping address itself */
     
    362362                        != (PAG_COMMIT|PAG_READ)))
    363363            {
    364                 fprintf (file, "     <Frame pointer=\"%08lX\">\n", ulRegEbp);
    365                 qt_excWriteErrorMsg (file, 6, "DosQueryMem returned %lu "
     364                fprintf (file, "      <Frame pointer=\"%08lX\">\n", ulRegEbp);
     365                qt_excWriteErrorMsg (file, 7, "DosQueryMem returned %lu "
    366366                                     "and flags %08lX", arc, ulFlags);
    367                 fprintf (file, "     </Frame>\n");
     367                fprintf (file, "      </Frame>\n");
    368368                /* try go to the next page */
    369369                /// @todo (r=dmik) I don't know how much it is accurate,
     
    380380    }
    381381
    382     fprintf (file, "    </Frames>\n");
     382    fprintf (file, "     </Frames>\n");
    383383}
    384384
     
    393393    if (ptib)
    394394    {
    395         fprintf (file, "  <Thread ID=\"%04lX\" slot=\"%04lX\" "
    396                                  "priority=\"%04lX\" ",
     395        fprintf (file, "   <Thread ID=\"%04lX\" slot=\"%04lX\" "
     396                                  "priority=\"%04lX\" ",
    397397                 ptib->tib_ptib2->tib2_ultid, ptib->tib_ordinal,
    398398                 ptib->tib_ptib2->tib2_ulpri);
     
    405405    else
    406406    {
    407         fprintf (file, "  <Thread ID=\"%04lX\" slot=\"%04lX\" "
    408                                  "priority=\"%04lX\" state=\"%02lX\">\n",
     407        fprintf (file, "   <Thread ID=\"%04lX\" slot=\"%04lX\" "
     408                                  "priority=\"%04lX\" state=\"%02lX\">\n",
    409409                 pThrdRec->tid, pThrdRec->slot, pThrdRec->priority,
    410410                 pThrdRec->state);
     
    413413    /* *** registers */
    414414
    415     fprintf (file, "   <CPU>\n"
    416                    "    <Registers>\n");
     415    fprintf (file, "    <CPU>\n"
     416                   "     <Registers>\n");
    417417
    418418    if  (pContextRec->ContextFlags & CONTEXT_SEGMENTS)
     
    444444    }
    445445   
    446     fprintf (file, "    </Registers>\n"
    447                    "   </CPU>\n");
     446    fprintf (file, "     </Registers>\n"
     447                   "    </CPU>\n");
    448448
    449449    /* *** stack */
    450450
    451     fprintf (file, "   <Stack base=\"%08lX\" limit=\"%08lX\">\n",
     451    fprintf (file, "    <Stack base=\"%08lX\" limit=\"%08lX\">\n",
    452452             (ULONG) ptib->tib_pstack,
    453453             (ULONG) ptib->tib_pstacklimit);
     
    458458    }   
    459459   
    460     fprintf (file, "   </Stack>\n"
    461                    "  </Thread>\n");
    462 }
    463 
    464 typedef struct _PROCESSINFO
    465 {
    466     /* common values */
    467     char *pszFullName;
    468     char *pszBaseName;
    469     /* direct info pointers */
    470     PPIB ppib;
    471     PTIB ptib;
    472     BOOL bHaveSysState; /**< TRUE when both pProcRec and pLibRec are not NULL */
    473     QSPREC *pProcRec;   /**< NULL when bHaveSysState is FALSE */
    474     QSLREC *pLibRec;    /**< NULL when bHaveSysState is FALSE */
    475 } PROCESSINFO;
     460    fprintf (file, "    </Stack>\n"
     461                   "   </Thread>\n");
     462}
     463
     464#ifndef max
     465#define max(a,b) (((a) > (b)) ? (a) : (b))
     466#endif
     467
     468/** @internal
     469 *  Writes the module description string (if found) as the 'desciption'
     470 *  attribute. Returns TRUE if the description was found and written.
     471 */
     472static BOOL qt_excWriteModuleDesc (FILE *file, char *pszFileName)
     473{
     474    /* see OS2TK\h\exe.h, OS2TK\h\exe386.h and LXSPEC.INF for details */
     475    enum { EXEID = 0x5a4d, LXOffset = 0x3C, sizeof_exe = LXOffset + 4,
     476           E32MAGIC = 0x584c, e32_nrestab = 34 * 4,
     477           sizeof_e32 = e32_nrestab + 4,
     478           max_nresname = 255 + 1 /* trailing 0 */ };
     479           
     480    UCHAR achBuf [max (max_nresname, max (sizeof_e32, sizeof_exe))];
     481
     482    BOOL bFound = FALSE;
     483    ULONG ul1 = 0, ul2 = 0;
     484   
     485    HFILE hf = NULL;
     486    APIRET arc = NO_ERROR;
     487   
     488    arc = DosOpen (pszFileName, &hf, &ul1,
     489                   0, 0, OPEN_ACTION_OPEN_IF_EXISTS,
     490                   OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READONLY,
     491                   NULL);
     492    if (arc != NO_ERROR)
     493        return FALSE;
     494
     495    do
     496    {
     497        /* read the old EXE header plus the offset to the LX header */
     498        arc = DosRead (hf, achBuf, sizeof_exe, &ul1);
     499        if (arc != NO_ERROR || sizeof_exe != ul1)
     500            break;
     501       
     502        if (*(USHORT *) &achBuf == EXEID)
     503        {
     504            /* go to the LX header */
     505            ul1 = *(ULONG *) &achBuf [LXOffset];
     506            arc = DosSetFilePtr (hf, (LONG) ul1, FILE_BEGIN, &ul2);
     507            if (arc != NO_ERROR || ul1 != ul2)
     508                break;
     509
     510            /* read it upto the e32_nrestab field */
     511            arc = DosRead (hf, achBuf, sizeof_e32, &ul1);
     512            if (arc != NO_ERROR || sizeof_e32 != ul1 ||
     513                *(USHORT *) &achBuf != E32MAGIC)
     514                break;
     515        }
     516        else
     517        if (*(USHORT *) &achBuf == E32MAGIC)
     518        {
     519            /* there may be no old EXE header, but LX only,
     520             * read it upto the e32_nrestab field */
     521            if (sizeof_e32 > sizeof_exe)
     522            {
     523                arc = DosRead (hf, achBuf + sizeof_exe,
     524                               sizeof_e32 - sizeof_exe, &ul1);
     525                if (arc != NO_ERROR || sizeof_e32 - sizeof_exe != ul1)
     526                    break;
     527            }
     528        }
     529        else
     530            break;
     531       
     532        /* go to the beginning of the non-resident name table */
     533        ul1 = *(ULONG *) &achBuf [e32_nrestab];
     534        if (ul1)
     535        {
     536            arc = DosSetFilePtr (hf, (LONG) ul1, FILE_BEGIN, &ul2);
     537            if (arc != NO_ERROR || ul1 != ul2)
     538                break;
     539           
     540            /* read the first entry */
     541            arc = DosRead (hf, achBuf, max_nresname, &ul1);
     542            if (arc != NO_ERROR || max_nresname != ul1)
     543                break;
     544   
     545            /* if the ordinal is 0, then it's a description field (we don't do
     546             * the full table search, since it shoud be ordered by ordinals) */
     547            if (*(USHORT *) &achBuf [1 + *achBuf] == 0)
     548            {
     549                /* place the trailing zero */
     550                achBuf [1 + *achBuf] = 0;
     551                /* write the description attribute */
     552                fprintf (file, "\n           desc=\"%s\"", achBuf + 1);
     553                bFound = TRUE;
     554            }
     555        }
     556    }
     557    while (0);
     558   
     559    DosClose (hf);
     560    return bFound;
     561}
    476562
    477563/*! \internal
     
    484570{
    485571    static const char *apszOrigins[] = { "self", "imported", "loaded" };
     572   
     573    FILESTATUS3 Status;
     574    APIRET arc = NO_ERROR;
    486575
    487576    fprintf (file, "   <Module ID=%\"%04lX\" name=\"", hmte);
    488577    qt_excEscapeString (file, pszName);
    489     if (ulOrigin >= 1 && ulOrigin <= 3)
    490         fprintf (file, "\"\n"
    491                        "           origin=\"%s\"/>\n",
    492                        apszOrigins [ulOrigin - 1]);
    493     else
    494         fprintf (file, "\"/>\n");
     578    fprintf (file, "\"");
     579   
     580    arc = DosQueryPathInfo (pszName, FIL_STANDARD, &Status, sizeof (Status));
     581
     582    if ((ulOrigin >= 1 && ulOrigin <= 3) || arc == NO_ERROR )
     583    {
     584        fprintf (file, "\n           ");
     585        if (ulOrigin >= 1 && ulOrigin <= 3)
     586            fprintf (file, " origin=\"%s\"",
     587                           apszOrigins [ulOrigin - 1]);
     588        if (arc == NO_ERROR)
     589            fprintf (file, " timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d\"",
     590                     Status.fdateLastWrite.year + 1980,
     591                     Status.fdateLastWrite.month, Status.fdateLastWrite.day,
     592                     Status.ftimeLastWrite.hours, Status.ftimeLastWrite.minutes,
     593                     Status.ftimeLastWrite.twosecs * 2);
     594    }
     595
     596    qt_excWriteModuleDesc (file, pszName);
     597
     598    fprintf (file, "/>\n");
    495599}
    496600
     
    525629}
    526630
    527 /** Struct for recursive qt_excWriteModulesOnStack() to reduce stack usage */
     631/** @internal
     632 *  Struct for recursive qt_excWriteModulesOnStack() to reduce stack usage
     633 */
    528634typedef struct _WMOS_STATE
    529635{
     
    621727    }
    622728}
     729
     730/** @internal Simple process info struct */
     731typedef struct _PROCESSINFO
     732{
     733    /* common values */
     734    char *pszFullName;
     735    char *pszBaseName;
     736    /* direct info pointers */
     737    PPIB ppib;
     738    PTIB ptib;
     739    BOOL bHaveSysState; /**< TRUE when both pProcRec and pLibRec are not NULL */
     740    QSPREC *pProcRec;   /**< NULL when bHaveSysState is FALSE */
     741    QSLREC *pLibRec;    /**< NULL when bHaveSysState is FALSE */
     742} PROCESSINFO;
    623743
    624744/*! \internal
     
    10141134
    10151135                fprintf (file,
    1016                          "<Trap timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d\" "
    1017                                "version=\"1.0\"\n"
     1136                         "<Trap timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d\"" //%c%02d:%02d\""
     1137                              " version=\"1.0\"\n"
    10181138                         "      generator=\"Qt Library Version %s\"\n"
    10191139                         "      xmlns=\"http://db.hugaida.com/xml/os2/sys/Trap\">\n",
    10201140                         dt.year, dt.month, dt.day,
    10211141                         dt.hours, dt.minutes, dt.seconds,
    1022                          (dt.timezone > 0 ? '-' : '+'),
    1023                          abs (dt.timezone / 60),
    1024                          abs (dt.timezone % 60),
    1025                          QT_VERSION_STR );
     1142                         //(dt.timezone > 0 ? '-' : '+'),
     1143                         //abs (dt.timezone / 60),
     1144                         //abs (dt.timezone % 60),
     1145                         QT_VERSION_STR);
    10261146
    10271147                XcptPvt::file = file;
Note: See TracChangeset for help on using the changeset viewer.