Changeset 431 for branches


Ignore:
Timestamp:
Nov 29, 2017, 5:52:24 AM (8 years ago)
Author:
rlwalsh
Message:

exception handler: update exception report to show function that set
the handler; optionally, print a debug message with up to 4 arguments

Location:
branches/branch-1-0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1-0/include/helpers/except.h

    r264 r431  
    7070     *      struct for thread exception handling.
    7171     *
    72      *@@changed V0.9.0 (99-10-22) [umoeller]: pfnOnKill added
    73      *@@changed V0.9.0 (99-10-22) [umoeller]: renamed from REGREC2
     72     *      Note: code within a TRY{}CATCH block can change
     73     *      pszFmt and ulArgX whenever needed to help identify
     74     *      the cause of an exception
    7475     */
    7576
     
    8081        jmp_buf         jmpThread;          // additional buffer for setjmp
    8182        EXCEPTIONREPORTRECORD err;          // exception handlers copy the report rec here
    82         PVOID           pvUser;             // user ptr
     83        PVOID           pvUser;             // user ptr - set to &pszSetBy by TRY_V2
     84        PSZ             pszSetBy;           // the file & function that set the handler
     85        PSZ             pszFmt;             // format string for fprintf() - can be null
     86        ULONG           ulArg1;             // arg1 for pszFmt
     87        ULONG           ulArg2;             // arg2 for pszFmt
     88        ULONG           ulArg3;             // arg3 for pszFmt
     89        ULONG           ulArg4;             // arg4 for pszFmt
    8390    } EXCEPTIONREGISTRATIONRECORD2;
    8491
     
    123130                                      PCONTEXTRECORD pContextRec);
    124131
     132    VOID _Optlink excExplainException2(FILE *file,
     133                                       PSZ pszHandlerName,
     134                                       PEXCEPTIONREPORTRECORD pReportRec,
     135                                       PCONTEXTRECORD pContextRec,
     136                                       PEXCEPTIONREGISTRATIONRECORD2 pRegRec2);
     137
    125138    VOID excRegisterHooks(PFNEXCOPENFILE pfnExcOpenFileNew,
    126139                          PFNEXCHOOK pfnExcHookNew,
     
    152165    #ifdef __NO_EXCEPTION_HANDLERS__
    153166        // exception handlers can completely be disabled
     167        #define TRY_LOUD6(excptstruct, fmt, arg1, arg2, arg3, arg4)
    154168        #define TRY_LOUD(excptstruct)
    155     #else
     169        #define FMT_WNDPROC
     170    #else
     171        // avoid problems if header and source are different versions
     172        #define TRY_V2  1
     173
    156174        #ifdef __NO_LOUD_EXCEPTION_HANDLERS__
    157             #define TRY_LOUD(e) TRY_QUIET(e)
     175            #define TRY_LOUD6   TRY_QUIET6
    158176        #else // __NO_LOUD_EXCEPTION_HANDLERS__
    159         #define TRY_LOUD(excptstruct)                                           \
     177            #define TRY_LOUD6(excptstruct, fmt, arg1, arg2, arg3, arg4)         \
    160178                {                                                               \
    161179                    EXCEPTSTRUCT          excptstruct = {0};                    \
    162180                    excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud;       \
     181                    excptstruct.RegRec2.pvUser = &excptstruct.RegRec2.pszSetBy; \
     182                    excptstruct.RegRec2.pszSetBy = __FILE__##"::"##__FUNCTION__##"()";  \
     183                    excptstruct.RegRec2.pszFmt = fmt;                           \
     184                    excptstruct.RegRec2.ulArg1 = (ULONG)arg1;                   \
     185                    excptstruct.RegRec2.ulArg2 = (ULONG)arg2;                   \
     186                    excptstruct.RegRec2.ulArg3 = (ULONG)arg3;                   \
     187                    excptstruct.RegRec2.ulArg4 = (ULONG)arg4;                   \
    163188                    excptstruct.arc = DosSetExceptionHandler(                   \
    164189                                (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
     
    173198
    174199        #endif // __NO_LOUD_EXCEPTION_HANDLERS__
    175     #endif
    176 
    177     #ifdef __NO_EXCEPTION_HANDLERS__
    178         // exception handlers can completely be disabled
     200
     201        #define TRY_LOUD(excptstruct) \
     202            TRY_LOUD6(excptstruct, 0, 0, 0, 0, 0)
     203
     204        #define TRY_LOUD2(excptstruct, fmt) \
     205            TRY_LOUD6(excptstruct, fmt, 0, 0, 0, 0)
     206
     207        #define TRY_LOUD3(excptstruct, fmt, arg1) \
     208            TRY_LOUD6(excptstruct, fmt, arg1, 0, 0, 0)
     209
     210        #define TRY_LOUD4(excptstruct, fmt, arg1, arg2) \
     211            TRY_LOUD6(excptstruct, fmt, arg1, arg2, 0, 0)
     212
     213        #define TRY_LOUD5(excptstruct, fmt, arg1, arg2, arg3) \
     214            TRY_LOUD6(excptstruct, fmt, arg1, arg2, arg3, 0)
     215
     216        #define TRY_WNDPROC_FMT     "hwnd= %08x  msg= %04x  mp1= %08x  mp2= %08x\n"
     217
     218        #define TRY_WNDPROC(excptstruct, hwd) \
     219            TRY_LOUD6(excptstruct, TRY_WNDPROC_FMT, hwd, msg, mp1, mp2)
     220
     221    #endif
     222
     223    #ifdef __NO_EXCEPTION_HANDLERS__
     224        // exception handlers can completely be disabled
     225        #define TRY_QUIET6(excptstruct, fmt, arg1, arg2, arg3, arg4)
    179226        #define TRY_QUIET(excptstruct)
    180227    #else
    181         #define TRY_QUIET(excptstruct)                                          \
     228        #define TRY_QUIET6(excptstruct, fmt, arg1, arg2, arg3, arg4)            \
    182229                {                                                               \
    183230                    EXCEPTSTRUCT          excptstruct = {0};                    \
    184231                    excptstruct.RegRec2.pfnHandler = (PFN)excHandlerQuiet;      \
     232                    excptstruct.RegRec2.pvUser = &excptstruct.RegRec2.pszSetBy; \
     233                    excptstruct.RegRec2.pszSetBy = __FILE__##"::"##__FUNCTION__##"()";  \
     234                    excptstruct.RegRec2.pszFmt = fmt;                           \
     235                    excptstruct.RegRec2.ulArg1 = arg1;                          \
     236                    excptstruct.RegRec2.ulArg2 = arg2;                          \
     237                    excptstruct.RegRec2.ulArg3 = arg3;                          \
     238                    excptstruct.RegRec2.ulArg4 = arg4;                          \
    185239                    excptstruct.arc = DosSetExceptionHandler(                   \
    186240                                (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
     
    194248                    {
    195249
     250        #define TRY_QUIET(excptstruct) \
     251            TRY_QUIET6(excptstruct, 0, 0, 0, 0, 0)
     252
    196253    #endif
    197254
  • branches/branch-1-0/src/helpers/except.c

    r384 r431  
    300300    }
    301301    else if (arc == ERROR_INVALID_ADDRESS)
    302         fprintf(file, "invalid");
     302    {
     303        if (ulCheck < 0x10000)
     304            fprintf(file, "not an address");
     305        else
     306            fprintf(file, "invalid address");
     307    }
    303308}
    304309
     
    443448 *      This calls excPrintStackFrame for each stack frame.
    444449 *
    445  *@@changed V0.9.0 [umoeller]: added support for application hook
    446  *@@changed V0.9.0 (99-11-02) [umoeller]: added TID to dump
    447  *@@changed V0.9.2 (2000-03-10) [umoeller]: now using excPrintStackFrame
    448  *@@changed V0.9.3 (2000-05-03) [umoeller]: fixed crashes
    449  *@@changed V0.9.6 (2000-11-06) [umoeller]: added more register dumps
    450  *@@changed V0.9.13 (2001-06-19) [umoeller]: added global flag for whether this is running
    451  *@@changed V0.9.16 (2001-11-02) [pr]: make object display signed
    452  *@@changed V0.9.19 (2002-03-28) [umoeller]: added thread ordinal
    453  *@@changed V1.0.0 (2002-08-28) [umoeller]: added OS revision to dump
    454450 *@@changed XWP V1.0.9 (2010-04-16) [pr]: add variable initialisation
    455451 */
    456452
    457 VOID excExplainException(FILE *file,                   // in: logfile from fopen()
    458                          PSZ pszHandlerName,           // in: descriptive string
    459                          PEXCEPTIONREPORTRECORD pReportRec, // in: excpt info
    460                          PCONTEXTRECORD pContextRec)   // in: excpt info
     453VOID excExplainException2(FILE *file,                               // in: logfile from fopen()
     454                          PSZ pszHandlerName,                       // in: descriptive string
     455                          PEXCEPTIONREPORTRECORD pReportRec,        // in: excpt info
     456                          PCONTEXTRECORD pContextRec,               // in: excpt info
     457                          PEXCEPTIONREGISTRATIONRECORD2 pRegRec2)   // in: reg info
    461458{
    462459    ULONG       aulBuf[3];
     
    666663            fprintf(file, "\nProcess information was not available.");
    667664
     665        // avoid trouble if the developer is using an older version of except.h
     666#ifdef TRY_V2
     667        if (pRegRec2 &&
     668            pRegRec2->pvUser == &(pRegRec2->pszSetBy) &&
     669            pRegRec2->pszSetBy)
     670        {
     671            fprintf(file,
     672                    "\nException handler:"
     673                    "\n    Set by:          %s\n",
     674                    pRegRec2->pszSetBy ? pRegRec2->pszSetBy : "unknown");
     675
     676            if (pRegRec2->pszFmt)
     677            {
     678                fprintf(file, "    Details:         ");
     679                fprintf(file, pRegRec2->pszFmt,
     680                        pRegRec2->ulArg1, pRegRec2->ulArg2,
     681                        pRegRec2->ulArg3, pRegRec2->ulArg4);
     682            }
     683        }
     684#endif
     685
     686        fprintf(file, "\n");
     687
    668688        /*
    669689         *  now call the hook, if one has been defined,
     
    680700        if (pContextRec->ContextFlags & CONTEXT_INTEGER)
    681701        {
    682             // DS the following 4 added V0.9.6 (2000-11-06) [umoeller]
    683702            fprintf(file, "\n    DS  = %08lX  ", pContextRec->ctx_SegDs);
    684             excDescribePage(file, pContextRec->ctx_SegDs);
    685             // ES
    686703            fprintf(file, "\n    ES  = %08lX  ", pContextRec->ctx_SegEs);
    687             excDescribePage(file, pContextRec->ctx_SegEs);
    688             // FS
    689704            fprintf(file, "\n    FS  = %08lX  ", pContextRec->ctx_SegFs);
    690             excDescribePage(file, pContextRec->ctx_SegFs);
    691             // GS
    692705            fprintf(file, "\n    GS  = %08lX  ", pContextRec->ctx_SegGs);
    693             excDescribePage(file, pContextRec->ctx_SegGs);
    694706
    695707            // EAX
     
    721733            // *** instruction
    722734
    723             fprintf(file, "Instruction pointer (where exception occurred):\n    CS:EIP = %04lX:%08lX  ",
     735            fprintf(file, "\nInstruction pointer (where exception occurred):\n    CS:EIP = %04lX:%08lX  ",
    724736                    pContextRec->ctx_SegCs,
    725737                    pContextRec->ctx_RegEip);
     
    728740            // *** CPU flags
    729741
    730             fprintf(file, "\n    EFLAGS = %08lX", pContextRec->ctx_EFlags);
     742            fprintf(file, "\n    EFLAGS = %08lX\n", pContextRec->ctx_EFlags);
    731743
    732744            /*
     
    766778    // lower global flag again V0.9.13 (2001-06-19) [umoeller]
    767779    G_ulExplainExceptionRunning--;
     780}
     781
     782VOID excExplainException(FILE *file,                   // in: logfile from fopen()
     783                         PSZ pszHandlerName,           // in: descriptive string
     784                         PEXCEPTIONREPORTRECORD pReportRec, // in: excpt info
     785                         PCONTEXTRECORD pContextRec)   // in: excpt info
     786{
     787    excExplainException2(file, pszHandlerName, pReportRec, pContextRec, 0);
    768788}
    769789
     
    962982            {
    963983                // write error log
    964                 excExplainException(file,
    965                                     "excHandlerLoud",
    966                                     pReportRec,
    967                                     pContextRec);
     984                excExplainException2(file,
     985                                     "excHandlerLoud",
     986                                     pReportRec,
     987                                     pContextRec,
     988                                     pRegRec2);
    968989                fclose(file);
    969990            }
     
    10311052                                    "excHandlerQuiet",
    10321053                                    pReportRec,
    1033                                     pContextRec);
     1054                                    pContextRec
     1055                                    pRegRec2);
    10341056                fclose(file);
    10351057            }
Note: See TracChangeset for help on using the changeset viewer.