⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logging.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* -*-C-*- * * $Revision: 1.1.6.19 $ *   $Author: rivimey $ *     $Date: 1998/02/24 15:56:14 $ * * Copyright (c) 1995 Advanced RISC Machines Limited * All Rights Reserved. * * logging.c - methods for logging warnings, errors and trace info * */#include <stdarg.h>             /* ANSI varargs support */#ifdef TARGET#include "angel.h"#include "devconf.h"#else #include "host.h"#include "dbg_hif.h"/* there are no other options for this: */#define DEBUG_METHOD logarmdbg#ifdef __unix#include <sys/time.h>#if defined(sun) && !defined(__svr4__)int gettimeofday(struct timeval *tp, struct timezone *tzp);#endif#endif#endif#include "logging.h"            /* Header file for this source code */#include "logpriv.h"            /* Private Header info */#include "adp.h"#include "sys.h"#if DEBUG == 1/****************************************************************************/#ifdef TARGET#include "support.h"#define strcpy(s, t)   __rt_strcpy(s, t)#define strcmp(s, t)   __rt_strcmp(s, t)#define strcat(s, t)   __rt_strcat(s, t)#else#include <string.h>#endif#ifdef DEBUG_METHOD#  define  DEBUG_METHOD_HEADER        STRINGIFY(DEBUG_METHOD##.h)#  include DEBUG_METHOD_HEADER#  define  METHOD_EXPAND_2(m, p, c) m##p(c)#  define  METHOD_EXPAND(m, p, c)   METHOD_EXPAND_2(m, p, c)#  define  CHAROUT(c)    METHOD_EXPAND(DEBUG_METHOD, _PutChar,  (c))#  define  PRE_DEBUG(l)  METHOD_EXPAND(DEBUG_METHOD, _PreWarn,  (l))#  define  POST_DEBUG(n) METHOD_EXPAND(DEBUG_METHOD, _PostWarn, (n))#else#error Must define DEBUG_METHOD#endif /* DEBUG_METHOD */#pragma no_check_stack/****************************************************************************//*                      P R O T O T Y P E S                                 *//****************************************************************************/static int log_vprintf(char *format, va_list args);static void log_log(WarnLevel level, char *format, ...);/* static int log_printf(char *format, ...);*/static int buf_itoh(char *buf, unsigned long uval, int width, int padzero);/****************************************************************************//*                      L O C A L   D A T A                                 *//****************************************************************************/static const char hextab1[] = "0123456789ABCDEF";static const char hextab2[] = "0123456789abcdef";/****************************************************************************//*                        F U N C T I O N S                                 *//****************************************************************************/#ifdef TARGETstatic int log_logging_options = WL_PRINTMSG | WL_SAVEMSG;#elsestatic int log_logging_options = WL_PRINTMSG;#endifunsigned char log_logging_flags[(int)LOG_ALWAYS];static char log_formatstring[48] = "%w: %m %l: ";static bool log_fasttrace = FALSE;   /* must be set true in debugger if req'd *//* details of the file and line .. set by Log_logmsginfo, which should * be called before every log_log(info,warning,error) to indicate the source of * the message. * Recorded so we can print it only at the start of a line. */ static char *log_filename = 0; /* remember file & line info; printed only at start of lines */static int log_line = 0;static log_id log_module = LOG_NEVER;static WarnLevel log_min_level = WL_INFO;staticchar *log_tracenames[] ={    "(none)",    "buffer",    "channel",    "debug",    "debughwi",    "debugos",    "boot",    "ctrl",    "devclnt",    "serlock",    "devmisc",    "devraw",    "rx",    "tx",    "params",    "sys",    "pcmcia",    "st16c552",    "serpkt",    "serraw",    "dccdrv",    "devshare",    "info",    "param",    "prof",    "ether",    "rdi",    "devsw",    "comm",    "serdrv",    "olicom",    "fusion",    "serial",    "ardi",    "eice",    "82595",    "appl",    "chanhb",    "chanto",    "chanasp",    "wire",    "jtag",    "common",    NULL /* always */};static struct {    ChannelID chan;    char *str;    int reason;} log_adpnames[] ={    { CI_TBOOT, "ADP_Booted", ADP_Booted },    /* { "ADP_TargetResetIndication", ADP_TargetResetIndication }, */    /* { "ADP_HostResetIndication", ADP_HostResetIndication }, */    { CI_HBOOT, "ADP_Reboot", ADP_Reboot },    { CI_HBOOT, "ADP_Reset", ADP_Reset },    { CI_HBOOT, "ADP_ParamNegotiate", ADP_ParamNegotiate },    { CI_HBOOT, "ADP_LinkCheck", ADP_LinkCheck },    { CI_HADP,  "ADP_HADPUnrecognised", ADP_HADPUnrecognised },    { CI_HADP,  "ADP_Info", ADP_Info },    { CI_HADP,  "ADP_Control", ADP_Control },    { CI_HADP,  "ADP_Read", ADP_Read },    { CI_HADP,  "ADP_Write", ADP_Write },    { CI_HADP,  "ADP_CPUread", ADP_CPUread },    { CI_HADP,  "ADP_CPUwrite", ADP_CPUwrite },    { CI_HADP,  "ADP_CPread", ADP_CPread },    { CI_HADP,  "ADP_CPwrite", ADP_CPwrite },    { CI_HADP,  "ADP_SetBreak", ADP_SetBreak },    { CI_HADP,  "ADP_ClearBreak", ADP_ClearBreak },    { CI_HADP,  "ADP_SetWatch", ADP_SetWatch },    { CI_HADP,  "ADP_ClearWatch", ADP_ClearWatch },    { CI_HADP,  "ADP_Execute", ADP_Execute },    { CI_HADP,  "ADP_Step", ADP_Step },    { CI_HADP,  "ADP_InterruptRequest", ADP_InterruptRequest },    { CI_HADP,  "ADP_HW_Emulation", ADP_HW_Emulation },    { CI_HADP,  "ADP_ICEbreakerHADP", ADP_ICEbreakerHADP },    { CI_HADP,  "ADP_ICEman", ADP_ICEman },    { CI_HADP,  "ADP_Profile", ADP_Profile },    { CI_HADP,  "ADP_InitialiseApplication", ADP_InitialiseApplication },    { CI_HADP,  "ADP_End", ADP_End },    { CI_TADP,  "ADP_TADPUnrecognised", ADP_TADPUnrecognised },    { CI_TADP,  "ADP_Stopped", ADP_Stopped },    { CI_TTDCC, "ADP_TDCC_ToHost", ADP_TDCC_ToHost },    { CI_TTDCC, "ADP_TDCC_FromHost", ADP_TDCC_FromHost },    { CI_CLIB,  "CL_Unrecognised", CL_Unrecognised },    { CI_CLIB,  "CL_WriteC", CL_WriteC },    { CI_CLIB,  "CL_Write0", CL_Write0 },    { CI_CLIB,  "CL_ReadC", CL_ReadC },    { CI_CLIB,  "CL_System", CL_System },    { CI_CLIB,  "CL_GetCmdLine", CL_GetCmdLine },    { CI_CLIB,  "CL_Clock", CL_Clock },    { CI_CLIB,  "CL_Time", CL_Time },    { CI_CLIB,  "CL_Remove", CL_Remove },    { CI_CLIB,  "CL_Rename", CL_Rename },    { CI_CLIB,  "CL_Open", CL_Open },    { CI_CLIB,  "CL_Close", CL_Close },    { CI_CLIB,  "CL_Write", CL_Write },    { CI_CLIB,  "CL_WriteX", CL_WriteX },    { CI_CLIB,  "CL_Read", CL_Read },    { CI_CLIB,  "CL_ReadX", CL_ReadX },    { CI_CLIB,  "CL_Seek", CL_Seek },    { CI_CLIB,  "CL_Flen", CL_Flen },    { CI_CLIB,  "CL_IsTTY", CL_IsTTY },    { CI_CLIB,  "CL_TmpNam", CL_TmpNam },    { 0,  NULL, 0 }};staticchar *swicalls[] ={    "(Unknown)"    "SYS_OPEN",    "SYS_CLOSE",    "SYS_WRITEC",    "SYS_WRITE0",    "SYS_WRITE",    "SYS_READ",    "SYS_READC",    "SYS_ISERROR",    "SYS_ISTTY",    "SYS_SEEK",    "SYS_ENSURE",    "SYS_FLEN",    "SYS_TMPNAM",    "SYS_REMOVE",    "SYS_RENAME",    "SYS_CLOCK",    "SYS_TIME",    "SYS_SYSTEM",    "SYS_ERRNO",    "SYS_INSTALL_RAISE",    "SYS_GET",    "SYS_HEAPINFO",};#if !defined(TARGET) && !defined(COMPILING_ON_WINDOWS)static struct timeval start_time = {0,0};#endif/* Flag: True if log_vprintf etc should print the recorded file/line info before * the first line, False if printf is still in middle of a line... * * The flag is kept up-to-date even if no file/line has been set (and so will * not be printed, either). *  * Initially true, so first line gets printed too.. */static int log_perline = TRUE;   void log_set_begin(void){#if !defined(TARGET) && !defined(COMPILING_ON_WINDOWS)    gettimeofday(&start_time, NULL);#endif}/* * set the log mask; this defines the set of log messages * which will appear in the recorded trace and/or the * console. * * Mask values should be taken from the LOG_xxx values). */void log_set_log_id(log_id id, int onoff){    int i;        if (id == LOG_ALWAYS)    {        for(i = 0; i < LOG_ALWAYS; i++)        {            log_logging_flags[i] = onoff;        }            }    else if (id == LOG_COMMON)    {        for(i = 0; i < LOG_ALWAYS; i++)        {            if (i != LOG_CHANTO && i != LOG_CHANHB && i != LOG_CHANASP && i != LOG_SERLOCK)                log_logging_flags[i] = onoff;        }            }    else        log_logging_flags[(int)id] = onoff;}/* * get the log id. */int log_get_log_id(log_id id){    return log_logging_flags[(int)id];}/* */void log_set_log_minlevel(WarnLevel level){    log_min_level = level;}/* */WarnLevel log_get_log_minlevel(){    return log_min_level;}int log_get_num_ids(void){    return (int)LOG_ALWAYS;}/* * get logging options * */int log_get_logging_options(){    return log_logging_options;}/* * set logging options (from one of the flags WL_xx) and return the * old options. New options take immediate effect. */int log_set_logging_options(int opts){    int oldopt = log_logging_options;    log_logging_options = opts;    return oldopt;}/* * get format string */char *log_get_format_string(){    return log_formatstring;}/* * set format string */void log_set_format_string(char * str){    strcpy(log_formatstring, str);}/* *  Function: log_tracebit *   Purpose: Return the bit number of the module which has trace name 'name'; * *  Pre-conditions: none. * *    Params: *       Input: name   - a string from the tracenames[] array above * *   Returns: the corresponding bit value. */log_id log_tracebit(char *name){    int j;    if (name == NULL || name[0] == 0)        return (log_id)0;    if (strcmp(name, "all") == 0)        return LOG_ALWAYS;    if (strcmp(name, "common") == 0)        return LOG_COMMON;        for(j = 0; log_tracenames[j] != NULL; j++)    {        if (strcmp(name, log_tracenames[j]) == 0)        {            return (log_id)j;        }    }    return (log_id)0;}/* *  Function: log_tracename *   Purpose: Return the name of the module which has trace id 'id'; *            note that this must be a LOG_xxx value. * *  Pre-conditions: none. * *    Params: *       Input: id - a value from the log_id enum. * *   Returns: char * name - the enum name as a string. */char *log_tracename(log_id id){    if (id < LOG_ALWAYS)        return log_tracenames[(int)id];    return "(none)";}/* *  Function: log_adpname *   Purpose: Return the name of the module which has adp reason 'reason'; *            note that this is the LOG_xxx value. * *  Pre-conditions: none. * *    Params: *       Input: bit   - a 32 bit word with one bit set corresponding to *                      a LOG_xxx value from logging.h * *   Returns: char * name */char *log_adpname(int reason){    int j;    long r;        reason &= 0xffffff;    for(j = 0; log_adpnames[j].str != NULL; j++)    {        r = log_adpnames[j].reason;        if (reason == r)        {            return log_adpnames[j].str;        }    }    return "(none)";}/* *  Function: log_swiname *   Purpose: Return the name of the module which has adp reason 'reason'; *            note that this is the LOG_xxx value. * *  Pre-conditions: none. * *    Params: *       Input: bit   - a 32 bit word with one bit set corresponding to *                      a LOG_xxx value from logging.h * *   Returns: char * name */char *log_swiname(int reason){    if (reason < (int)((sizeof(swicalls) / sizeof(swicalls[0]))))        return swicalls[reason];    else        return "(unknown)";}#ifdef NO_LOG_INFOvoid log_dump_buffer(WarnLevel lvl, log_id mod, unsigned int bpl, char *buffer, unsigned int length){}#elsevoid log_dump_buffer(WarnLevel lvl, log_id mod, unsigned int bpl, char *buffer, unsigned int length){    unsigned int i;    unsigned int j;    char b[128];    Log_logmsginfo( log_file, __LINE__, mod);    if (length > 256)    {        log_log(lvl, "Buffer %x, length %d (truncated to 256)\n", buffer, length);        length = 256;    }    else    {        log_log(lvl, "Buffer %x, length %d\n", buffer, length);    }        for (i = 0; i < length; i += bpl)    {        char *p = b;                p += buf_itoh(p, i, 3, 1);        *p++ = ':';        *p++ = ' ';                for (j = 0; j < 16 && (i + j) < length; j++)        {            p += buf_itoh(p, buffer[i + j] & 0xff, 2, 1);            *p++ = ' ';        }        for (; j <= bpl; j++)        {            *p++ = ' ';            *p++ = ' ';            *p++ = ' ';        }        for (j = 0; j < bpl && (i + j) < length; j++)        {            unsigned char c = buffer[i + j];            *p++ = (c >= 0x20 && c < 0x7F) ? c : '.';        }        *p++ = '\0';        Log_logmsginfo( log_file, __LINE__, mod);        log_log(lvl, "%s\n", b);    }}#endif/* * Parse the initial segment of a printf % specifier, returning the * base code (d, x, s etc) to the caller and updating format to point * to that character in the source string. *format should point to the * initial %. * * width is the field width (the precision is not supported), padzero is * TRUE if field width began with a 0, longval is TRUE if (ld, lx etc) * was seen. * * A leading '-' on the field width (%-8s etc) is ignored. */static char log_readformat(char **format, int *width, int *padzero, int *longval){    char fch = *(++(*format));    /*     * Check if the format has a width specified. NOTE: We do     * not use the "isdigit" function here, since it will     * require run-time support. The current ARM Ltd header     * defines "isdigit" as a macro, that uses a fixed     * character description table.     */    if (fch == '-')        fch = *(++(*format));   /* ignore right-adjust flag */    if ((fch >= '0') && (fch <= '9'))    {        if (fch == '0')        {            /* Leading zeroes padding */            *padzero = TRUE;            fch = *(++(*format));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -