Changeset 1444


Ignore:
Timestamp:
May 16, 2004, 11:20:36 PM (21 years ago)
Author:
bird
Message:

libc_LogDumpHex.

Location:
trunk/src/emx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/InnoTekLIBC/logstrict.h

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1443 r1444  
    44 * InnoTek LIBC - Debug Logging and Strict Checking Features.
    55 *
    6  * InnoTek Systemberatung GmbH confidential
     6 * InnoTek Systemberatung GmbH
    77 *
    88 * Copyright (c) 2004 InnoTek Systemberatung GmbH
     
    486486
    487487/**
     488 * Dumps a byte block.
     489 *
     490 * @param   uEnterTS        The timestamp returned by LogEnter.
     491 * @param   pvInstance      Logger instance. If NULL the message goes to the
     492 *                          default log instance.
     493 * @param   fGroupAndFlags  Logging group and logging flags.
     494 * @param   pszFunction     Name of the function which was entered.
     495 * @param   pvData          Pointer to the bytes to dump.
     496 * @param   cbData          Number of bytes to dump.
     497 * @param   pszFormat       Format string for the message to log.
     498 * @param   ...             Arguments to the format string.
     499 */
     500extern void     __libc_LogDumpHex(unsigned uEnterTS, void *pvInstance, unsigned fGroupAndFlags, const char *pszFunction, void *pvData, unsigned cbData, const char *pszFormat, ...);
     501
     502/**
    488503 * Assertion helper.
    489504 * Logs and displays (stderr) an assertion failed message.
  • trunk/src/emx/src/lib/sys/logstrict.c

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1443 r1444  
    9393} __LIBC_XCPTREG, *__LIBC_PXCPTREG;
    9494
     95
     96/*******************************************************************************
     97*   Global Variables                                                           *
     98*******************************************************************************/
     99/** Hex digits. */
     100static const char gszHexDigits[17] = "0123456789abcdef";
     101/** Uppercase hex digits. */
     102static const char gszHexDigitsUpper[17] = "0123456789ABCDEF";
    95103
    96104
     
    920928
    921929/**
     930 * Dumps a byte block.
     931 *
     932 * @param   uEnterTS        The timestamp returned by LogEnter.
     933 * @param   pvInstance      Logger instance. If NULL the message goes to the
     934 *                          default log instance.
     935 * @param   fGroupAndFlags  Logging group and logging flags.
     936 * @param   pszFunction     Name of the function which was entered.
     937 * @param   pvData          Pointer to the bytes to dump.
     938 * @param   cbData          Number of bytes to dump.
     939 * @param   pszFormat       Format string for the message to log.
     940 * @param   ...             Arguments to the format string.
     941 */
     942void     __libc_LogDumpHex(unsigned uEnterTS, void *pvInstance, unsigned fGroupAndFlags, const char *pszFunction, void *pvData, unsigned cbData, const char *pszFormat, ...)
     943{
     944    unsigned        uTS = getTimestamp();
     945    __LIBC_PTHREAD  pThread = __libc_threadCurrentNoAuto();
     946    char           *pszMsg;
     947    int             cch;
     948    va_list         args;
     949    __LIBC_PLOGINST pInst;
     950    unsigned        cDepth = 0xff;
     951    char           *pszOffset;
     952    char           *pbData;
     953    unsigned        off;
     954
     955    /*
     956     * Check instance, get default.
     957     */
     958    if (!pvInstance)
     959    {
     960        pvInstance = __libc_logDefault();
     961        if (!pvInstance)
     962            return;
     963        if (pThread)
     964            cDepth = pThread->cDefLoggerDepth;
     965    }
     966    pInst = (__LIBC_PLOGINST)pvInstance;
     967
     968    /*
     969     * Check if this group is enabled.
     970     */
     971    if (pInst->pGroups)
     972    {
     973        int iGroup = __LIBC_LOG_GETGROUP(fGroupAndFlags);
     974        if (    iGroup >= 0
     975            &&  iGroup < pInst->pGroups->cGroups
     976            &&  !pInst->pGroups->paGroups[iGroup].fEnabled)
     977            return;
     978    }
     979
     980    /*
     981     * Allocate logging buffer and format the message.
     982     */
     983    pszMsg = alloca(CCHTMPMSGBUFFER);
     984    if (!pszMsg)
     985        return;
     986
     987    va_start(args, pszFormat);
     988    if (uEnterTS != ~0)
     989        cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Dump %04x %s (%2d ms): ",
     990                                 uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags),
     991                                 pThread ? pThread->iErrNo : 0xface, pszFunction, uTS - uEnterTS);
     992    else
     993        cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Dump %04x %s: ",
     994                                 uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags),
     995                                 pThread ? pThread->iErrNo : 0xface, pszFunction);
     996    va_end(args);
     997
     998    /*
     999     * Write the message.
     1000     */
     1001    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, 0);
     1002
     1003
     1004    /*
     1005     * Init the dumping.
     1006     *  (Reusing the first part of the message, skipping past the 'Dump' here.)
     1007     */
     1008    pszOffset = pszMsg;
     1009    while (pszOffset[0] != 'D' && pszOffset[1] != 'u')
     1010        pszOffset++;
     1011    pszOffset += 4;
     1012    *pszOffset++ = ':';
     1013    *pszOffset++ = ' ';
     1014
     1015    /*
     1016     * Do the dumping.
     1017     */
     1018    off = 0;
     1019    pbData = (char *)pvData;
     1020    while (cbData > 0)
     1021    {
     1022        char *pszHex, *pszChar, *pszHexEnd;
     1023        /* print offsets. */
     1024        pszHex = pszOffset + __libc_logSNPrintf(pszOffset, 64, "%08x %08x  ", (unsigned)pvData, off); /* !portability! */
     1025        pszHexEnd = pszChar = pszHex + 16 * 3 + 2;  /* 16 chars with on space, two space before chars column. */
     1026
     1027        /* output chars. */
     1028        while (cbData > 0)
     1029        {
     1030            char ch = *pbData++;
     1031            cbData--;
     1032            *pszHex++ = gszHexDigits[(unsigned)ch >> 4];
     1033            *pszHex++ = gszHexDigits[(unsigned)ch & 4];
     1034            *pszHex++ = ' ';
     1035            if (ch < 0x30 /*|| more unprintables */)
     1036                *pszChar++ = '.';
     1037            else
     1038                *pszChar++ = ch;
     1039        }
     1040
     1041        /* finish it */
     1042        while (pszHex < pszHexEnd)
     1043            *pszHex++ = ' ';
     1044        pszHexEnd[-(8 * 3)] = '-';
     1045        *pszChar++ = '\n';
     1046        *pszChar = '\0';
     1047
     1048        /* write line */
     1049        __libc_logWrite(pInst, fGroupAndFlags, pszMsg, pszChar - pszMsg, 0);
     1050       
     1051        /* next */
     1052        off += 16;
     1053    }
     1054}
     1055
     1056
     1057/**
    9221058 * Assertion helper.
    9231059 * Logs and displays (stderr) an assertion failed message.
     
    12271363                       int cchWidth, int cchPrecision, unsigned int fFlags)
    12281364{
    1229     char *          achDigits = "0123456789abcdef";
     1365    const char     *pszDigits = gszHexDigits;
    12301366    int             cchValue;
    12311367    unsigned long   ul;
     
    12361372        return NULL;
    12371373    if (fFlags & NTSF_CAPITAL)
    1238         achDigits = "0123456789ABCDEF";
     1374        pszDigits = gszHexDigitsUpper;
    12391375    if (fFlags & NTSF_LEFT)
    12401376        fFlags &= ~NTSF_ZEROPAD;
     
    12971433    do
    12981434    {
    1299         psz[i--] = achDigits[lValue % uiBase];
     1435        psz[i--] = pszDigits[lValue % uiBase];
    13001436        lValue /= uiBase;
    13011437    } while (lValue > 0);
     
    13251461                         int cchWidth, int cchPrecision, unsigned int fFlags)
    13261462{
    1327     char *              achDigits = "0123456789abcdef";
     1463    const char         *pszDigits = gszHexDigits;
    13281464    int                 cchValue;
    13291465    unsigned long long  ull;
     
    13341470        return NULL;
    13351471    if (fFlags & NTSF_CAPITAL)
    1336         achDigits = "0123456789ABCDEF";
     1472        pszDigits = gszHexDigitsUpper;
    13371473    if (fFlags & NTSF_LEFT)
    13381474        fFlags &= ~NTSF_ZEROPAD;
     
    13971533    do
    13981534    {
    1399         psz[i--] = achDigits[llValue % uiBase];
     1535        psz[i--] = pszDigits[llValue % uiBase];
    14001536        llValue /= uiBase;
    14011537    } while (llValue > 0);
     
    14211557static int      __libc_logVSNPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args)
    14221558{
    1423     static const char szHexChars[17] = "0123456789abcdef";
    14241559    int             rc;
    14251560    char           *pszBufferIn = pszBuffer;
     
    16831818                                        {
    16841819                                            char ch = *pb++;
    1685                                             *pszBuffer++ = szHexChars[(unsigned)ch >> 4];
    1686                                             *pszBuffer++ = szHexChars[(unsigned)ch & 0xf];
     1820                                            *pszBuffer++ = gszHexDigits[(unsigned)ch >> 4];
     1821                                            *pszBuffer++ = gszHexDigits[(unsigned)ch & 0xf];
    16871822                                            cb--;
    16881823                                            cchBuffer -= 2;
     
    16941829                                                cb--;
    16951830                                                *pszBuffer++ = ' ';
    1696                                                 *pszBuffer++ = szHexChars[(unsigned)ch >> 4];
    1697                                                 *pszBuffer++ = szHexChars[(unsigned)ch & 0xf];
     1831                                                *pszBuffer++ = gszHexDigits[(unsigned)ch >> 4];
     1832                                                *pszBuffer++ = gszHexDigits[(unsigned)ch & 0xf];
    16981833                                                cchBuffer -= 3;
    16991834                                                cch += 3;
Note: See TracChangeset for help on using the changeset viewer.