📄 bkendlog.c
字号:
/* bkendlog - back-end debug log library *//* Copyright 1994-1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02s,15oct98,dbt now, TSFS open mode is represented by a string instead of an hexadecimal value. Fixed several problems in TSFS request logs. Completed TSFS ioctl support (some ioctl requests were missing).02r,26jun98,dbt added the host type in the backend log file header (SPR #9965). fixed documentation.02q,06may98,pcn Added tgtsvr args in WDB & WTX log file.02p,25mar98,dbt fixed typo.02o,24mar98,dbt added WDB_CONTEXT_STATUS_GET02n,03mar98,dbt replaced (when possible) numbers with strings. added target server file system support. added user event and context start notification support. added hardware breakpoint support.02m,24feb98,pcn WTX 2: add a wdbLogMaxSize in bkendLogInit and create a backEndLog mutex.02l,04feb98,c_c Added debugFlagGet() for backward compatibility (WIN32).02k,14jan98,c_c Target Server multi threading and DLLisation integration. Get rid of EXT_FUNC definitions.02j,06dec96,dgp doc: correct spelling02i,21nov96,dgp doc: change Target-Server to Target Server02h,17oct96,elp replaced tgtSvrNameGet(), tgtNameGet() by their macros (SPR# 6943).02g,23sep96,dgp doc: final API Guide changes02f,05jul96,p_m added WDB_TARGET_MODE_GET (SPR# 6200)02e,28jun96,dgp doc: additional API Guide formatting02d,27jun96,dgp doc: API Guide formatting for bkendlog library & function02c,03may96,elp took care of the possible WDB_TO_BE_CONTINUED status, added include wdbP.h (SPR #6277).02b,28feb96,p_m updated documentation to reflect log output changes.02a,16jan96,elp WIN32 uses an external function structure to call dll external functions.01z,05jan96,p_m added better logging of errors (SPR# 4629). removed WIN32 dependency introduced by previous mod. added logging of time on every request. now print real Target Server name by using tgtSvrNameGet().01y,19nov95,p_m added check for null strings.01x,09oct95,wmd corrected (uint) to (UINT32) for WIN32.01w,11sep95,p_m added wpwrGetUserName() parameter.01v,25jul95,p_m documentation.01u,20jun95,tpr changed the fopen option from "w" to "a".01t,31may95,tpr added switch in bkendLogWdbEvtData() and cleanup.01s,30may95,p_m added Solaris-2 and HP-UX support.01r,27may95,p_m added bkendLogWdbMemScanDesc() and bkendLogWdbTGT_ADDR_T(). removed #include <syscall.h>.01q,02may95,tpr removed #include "wdb.h". reworked following new WDB protocole. changed bcknd by bkend.01p,20apr95,p_m added #include <rpc/rpc.h> for WIN32.01o,03apr95,pad small doc changes.01n,27mar95,p_m added WDB_MEM_MOVE support.01m,20mar95,c_s updated GOPHER log printing routines.01l,14mar95,p_m implemented bckndLogMode(). fixed bug in bckndLogEventNum() and bckndLogEventpointNum(). added WDB_TARGET_DISCONNECT support.01k,09mar95,p_m added loggin for new agent services.01j,08mar95,tpr changed some output format.01i,06mar95,p_m took care of latest agent version. passed u_int * to bckndLogStatus() and fixed a few alignement problems in the output.01h,22feb95,tpr added input argument tests. added bckndLogClode (). renamed bckndDebugInit() and bckndDebug() by bckndLogInit() and bckndLog().01g,10feb95,tpr removed strcpy () in bckndDebug().01f,26jan95,tpr re-work infrormation display.01e,24jan95,tpr added bckndLogStatus (), bckndLogEventpointNum (), bckndLogEventNum (), bckndLogGopherString(). code rework.01d,23jan95,jcf replaced #include "wdb/wdbtypes.h" with #include "wdbtypes.h". changed code following new structure definitions.01c,21jan95,jcf added #include "host.h".01b,20jan95,jcf updated includes.01a,14nov94,tpr written.*//*DESCRIPTIONThis library provides a routine to log the requests and the dataexchanged between the target server and the target agent. Log output issent to a file or device.Use this routine when you write a new target server back end to logthe data that is sent and received by the target server back end whenthe back-end debug option is ON.The back-end logging facility is turned OFF by default. It can be turnedon with the `-Bd' option to the target server. For example, underUNIX, log the back-end data to a console with:.CS% tgtsvr target -Bd /dev/tty.CEThe log file contains a header followed by the requests issued by thetarget server. The header gives information about the target server user,the start date and time of the log, the target server name, the targetname, the target server options, and host informations. It also gives theback-end timeout value and the maximum number of retries in case offailure.The following is an example of a log message header:.CS User Name : philm Started : Wed Feb 28 14:35:09 1998 Target Server Name : RueDuQuai@scorff Target Name : kerpc Target Server Options : tgtsvr kerpc -n RueDuQuai -V -Bd backend.log Host : HP-UX scorff B.10.20 A 9000/777 Timeout value : 1 second(s) Request re-send Max : 3.CEEach request is written to the log file with its sequence number, its name,the name of the input structure (labeled "In"), the value of the input structure, the name of the output structure (labeled "Out"), and its value.Example 1: WDB_TARGET_CONNECT request with sequence number 1 (first requestissued) and no retries (0). This request has no input parameter and the output is a WDB_TGT_INFO structure..CS1 WDB_TARGET_CONNECT Wed Feb 28 14:35:10 19980 Out status: Ok WDB_TGT_INFO WDB_AGENT_INFO agentVersion 2.0 mtu 1500 mode WDB_MODE_TASK WDB_RT_INFO rtType WDB_RT_VXWORKS rtVersion 5.3 cpuType 82 hasFpp 1 hasWriteProtect 1 pageSize 4096 endian 4321 bspName PC 486 bootline scorff:/folk/tornado/target/config/pc486/vxWorks memBase 0x0 memSize 0x7ff000 numRegions 0 hostPoolBase 0x7a3c0c hostPoolSize 0x40000.CEExample 2: WDB_MEM_WRITE request with sequence number 25 and no retries. The input parameter is WDB_MEM_XFER structure and the output is an integer giving the status of the request..CS25 WDB_MEM_WRITE Wed Feb 28 14:36:11 1998 In WDB_MEM_XFER numBytes 4 destination 0x17d144 source 0x4000e9300 Out status: Ok.CEFor the definitions of the structures exchanged between the target server andthe target, see the file $WIND_BASE/share/src/agents/wdb/wdb.h.WINDOWS HOSTSWhen creating a new back end on a Windows host, the developer creates a newproject under MicroSoft C++. It is necessary to go to the Link tab under theSettings menu of Project and add the required object/library modules manually.Adding `/Tornado/host/x86-win32/lib/backend.lib' provides the logging functionand `/Tornado/host/x86-win32/lib/libwpwr.lib' provides the WTX APIs.WARNINGOn average, 100 characters are used to log one request. When writtento a file, the back end transaction data can quickly reach hundreds ofkilobytes and fill a disk partition.INTERNALThe number of tabs before and after each field name is computed to have a right display. Take care of it when modifying this file.INCLUDE FILE: bkendlib.hSEE ALSO:.I API Programmer's Guide: Target Server Back End*//* includes */#include <stdio.h>#ifndef WIN32#include <pwd.h>#include <sys/param.h>#include <sys/time.h>#include <sys/types.h>#include <sys/utsname.h>#else /* WIN32 */#include <windows.h>#include <winbase.h>#endif /* WIN32 */#include <time.h>#include <rpc/rpc.h>#include <rpc/types.h>#ifdef SUN4_SOLARIS2 /* just for MAXHOSTNAMELEN def that was in sys/param */ /* XXX jco this may be defined in host.h ?? */#include <netdb.h>#endif /* SUN4_SOLARIS2 */#include "host.h"#include "tgtsvr.h"#include "tgtlib.h"#include "wdb.h"#include "wdbP.h"#include "wpwrutil.h"/* typedefs */typedef struct enumNameMap { int enumInt; /* int form of enum */ char * enumLongName; /* e.g., "ENUM_FOO_BAR" */ } ENUM_NAME_MAP;typedef struct enumTypeMap { char * enumType; /* type name */ int allowOr; /* 1: members can be OR'd */ ENUM_NAME_MAP * pEnumNameMap; /* map table */ } ENUM_TYPE_MAP;/* locals */LOCAL FILE * wdbLogFile = NULL; /* back end log file descriptor */LOCAL int maxSize = 0; /* Max size for the log file */SEM_ID backEndLogMutex = NULL; /* BackEnd guarding Mutex */LOCAL BOOL bkendLogEnable = FALSE; /* TRUE if turn on *//* strings corresponding to each context type */LOCAL ENUM_NAME_MAP contextTypeMap [] = { {WDB_CTX_SYSTEM, "WDB_CTX_SYSTEM"}, /* system mode */ {WDB_CTX_GROUP, "WDB_CTX_GROUP"}, /* process group */ {WDB_CTX_ANY, "WDB_CTX_ANY"}, /* any context */ {WDB_CTX_TASK, "WDB_CTX_TASK"}, /* specific task or processes */ {WDB_CTX_ANY_TASK, "WDB_CTX_ANY_TASK"}, /* any task */ {WDB_CTX_ISR, "WDB_CTX_ISR"}, /* specific ISR */ {WDB_CTX_ANY_ISR, "WDB_CTX_ANY_ISR"}, /* any ISR */ {0, 0}, /* sentinel */ };/* strings corresponding to each error type */LOCAL ENUM_NAME_MAP errorTypeMap [] = { {RPC_CANTENCODEARGS, "RPC_CANTENCODEARGS"}, {RPC_CANTDECODERES, "RPC_CANTDECODERES"}, {RPC_CANTSEND, "RPC_CANTSEND"}, {RPC_CANTRECV, "RPC_CANTRECV"}, {RPC_TIMEDOUT, "RPC_TIMEDOUT"}, {RPC_VERSMISMATCH, "RPC_VERSMISMATCH"}, {RPC_AUTHERROR, "RPC_AUTHERROR"}, {RPC_PROGUNAVAIL, "RPC_PROGUNAVAIL"}, {RPC_PROGVERSMISMATCH, "RPC_PROGVERSMISMATCH"}, {RPC_PROCUNAVAIL, "RPC_PROCUNAVAIL"}, {RPC_CANTDECODEARGS, "RPC_CANTDECODEARGS"}, {RPC_SYSTEMERROR, "RPC_SYSTEMERROR"}, {RPC_UNKNOWNHOST, "RPC_UNKNOWNHOST"}, {RPC_UNKNOWNPROTO, "RPC_UNKNOWNPROTO"}, {RPC_PMAPFAILURE, "RPC_PMAPFAILURE"}, {RPC_PROGNOTREGISTERED, "RPC_PROGNOTREGISTERED"}, {WDB_ERR_INVALID_PARAMS, "WDB_ERR_INVALID_PARAMS"}, {WDB_ERR_MEM_ACCES, "WDB_ERR_MEM_ACCES"}, {WDB_ERR_NOT_FOUND, "WDB_ERR_NOT_FOUND"}, {WDB_ERR_AGENT_MODE, "WDB_ERR_AGENT_MODE"}, {WDB_ERR_RT_ERROR, "WDB_ERR_RT_ERROR"}, {WDB_ERR_INVALID_CONTEXT, "WDB_ERR_INVALID_CONTEXT"}, {WDB_ERR_INVALID_VIO_CHANNEL,"WDB_ERR_INVALID_VIO_CHANNEL"}, {WDB_ERR_INVALID_EVENT, "WDB_ERR_INVALID_EVENT"}, {WDB_ERR_INVALID_EVENTPOINT,"WDB_ERR_INVALID_EVENTPOINT"}, {WDB_ERR_GOPHER_FAULT, "WDB_ERR_GOPHER_FAULT"}, {WDB_ERR_GOPHER_TRUNCATED, "WDB_ERR_GOPHER_TRUNCATED"}, {WDB_ERR_GOPHER_SYNTAX, "WDB_ERR_GOPHER_SYNTAX"}, {WDB_ERR_EVENTPOINT_TABLE_FULL,"WDB_ERR_EVENTPOINT_TABLE_FULL"}, {WDB_ERR_NO_AGENT_PROC, "WDB_ERR_NO_AGENT_PROC"}, {WDB_ERR_NO_RT_PROC, "WDB_ERR_NO_RT_PROC"}, {WDB_ERR_PROC_FAILED, "WDB_ERR_PROC_FAILED"}, {WDB_ERR_NO_CONNECTION, "WDB_ERR_NO_CONNECTION"}, {WDB_ERR_CONNECTION_BUSY, "WDB_ERR_CONNECTION_BUSY"}, {WDB_ERR_COMMUNICATION, "WDB_ERR_COMMUNICATION"}, {WDB_ERR_INVALID_HW_BP, "WDB_ERR_INVALID_HW_BP"}, {WDB_ERR_HW_REGS_EXHAUSTED, "WDB_ERR_HW_REGS_EXHAUSTED"}, {0, 0}, /* sentinel */ };/* strings corresponding to each event type */LOCAL ENUM_NAME_MAP eventTypeMap [] = { {WDB_EVT_NONE, "WDB_EVT_NONE"}, /* no event */ {WDB_EVT_CTX_START, "WDB_EVT_CTX_START"}, /* context creation */ {WDB_EVT_CTX_EXIT, "WDB_EVT_CTX_EXIT"}, /* context exit */ {WDB_EVT_BP, "WDB_EVT_BP"}, /* breakpoint */ {WDB_EVT_HW_BP, "WDB_EVT_HW_BP"}, /* hardware breakpoint */ {WDB_EVT_WP, "WDB_EVT_WP"}, /* watchpoint */ {WDB_EVT_EXC, "WDB_EVT_EXC"}, /* exception */ {WDB_EVT_VIO_WRITE, "WDB_EVT_VIO_WRITE"}, /* virtual I/O write */ {WDB_EVT_CALL_RET, "WDB_EVT_CALL_RET"}, /* function call finished */ {WDB_EVT_TSFS_OP, "WDB_EVT_TSFS_OP"}, /* VIO II operation */ {WDB_EVT_USER, "WDB_EVT_USER"}, /* user event */ {0, 0}, /* sentinel */ };/* strings corresponding to each action type */LOCAL ENUM_NAME_MAP actionTypeMap [] = { {WDB_ACTION_CALL, "WDB_ACTION_CALL"},/* condition the evtpt via a proc */ {WDB_ACTION_NOTIFY, "WDB_ACTION_NOTIFY"}, /* notify the host */ {WDB_ACTION_STOP, "WDB_ACTION_STOP"}, /* stop the context */ {0, 0}, /* sentinel */ };/* strings corresponding to each register set type */LOCAL ENUM_NAME_MAP regSetTypeMap [] = { {WDB_REG_SET_IU, "WDB_REG_SET_IU"}, /* integer unit reg set */ {WDB_REG_SET_FPU, "WDB_REG_SET_FPU"}, /* float. point unit reg set */ {WDB_REG_SET_MMU, "WDB_REG_SET_MMU"}, /* memory man. unit reg set */ {WDB_REG_SET_CU, "WDB_REG_SET_CU"}, /* cache unit register set */ {WDB_REG_SET_TPU, "WDB_REG_SET_TPU"}, /* timer processor unit reg. */ {WDB_REG_SET_SYS, "WDB_REG_SET_SYS"}, /* system registers */ {0, 0}, /* sentinel */ };/* strings corresponding to each run-time system type */LOCAL ENUM_NAME_MAP rtTypeMap [] = { {WDB_RT_NULL, "WDB_RT_NULL"}, /* standalone WDB agent */ {WDB_RT_VXWORKS, "WDB_RT_VXWORKS"}, /* vxWorks */ {0, 0}, /* sentinel */ };/* strings corresponding to call return type */LOCAL ENUM_NAME_MAP returnTypeMap [] = { {WDB_CALL_RET_INT, "WDB_CALL_RET_INT"}, /* integer */ {WDB_CALL_RET_DBL, "WDB_CALL_RET_DBL"}, /* double */ {0, 0}, /* sentinel */ };/* strings corresponding to agent mode type */LOCAL ENUM_NAME_MAP agentModeTypeMap [] = { {WDB_MODE_TASK, "WDB_MODE_TASK"}, /* task mode agent */ {WDB_MODE_EXTERN, "WDB_MODE_EXTERN"}, /* system mode agent */ {0, 0}, /* sentinel */ };/* strings corresponding to each tsfs ioct request */LOCAL ENUM_NAME_MAP tsfsIoctlReqMap [] = { {WDB_TSFS_IOCTL_FIOSEEK, "FIOSEEK"}, {WDB_TSFS_IOCTL_FIOWHERE, "FIOWHERE"}, {WDB_TSFS_IOCTL_FIONREAD, "FIONREAD"}, {WDB_TSFS_IOCTL_FIOFSTATGET, "FIOFSTATGET"}, {WDB_TSFS_IOCTL_FIOREADDIR, "FIOREADDIR"}, {WDB_TSFS_IOCTL_FIORENAME, "FIORENAME"}, {WDB_TSFS_IOCTL_SO_SNDURGB, "SO_SNDURGB"}, {WDB_TSFS_IOCTL_SO_SETDEBUG, "SO_SETDEBUG"}, {WDB_TSFS_IOCTL_SO_GETDEBUG, "SO_GETDEBUG"}, {WDB_TSFS_IOCTL_SO_SETSNDBUF, "SO_SETSNDBUF"}, {WDB_TSFS_IOCTL_SO_SETRCVBUF, "SO_SETRCVBUF"}, {WDB_TSFS_IOCTL_SO_SETDONTROUTE, "SO_SETDONTROUTE"}, {WDB_TSFS_IOCTL_SO_GETDONTROUTE, "SO_GETDONTROUTE"}, {WDB_TSFS_IOCTL_SO_SETOOBINLINE, "SO_SETOOBINLINE"}, {WDB_TSFS_IOCTL_SO_GETOOBINLINE, "SO_GETOOBINLINE"}, {0, 0}, /* sentinel */ };/* strings corresponding to each tsfs open mode */LOCAL ENUM_NAME_MAP tsfsOpenModeMap [] = { {WDB_TSFS_O_RDONLY, "O_RDONLY"}, {WDB_TSFS_O_WRONLY, "O_WRONLY"}, {WDB_TSFS_O_RDWR, "O_RDWR"}, {WDB_TSFS_O_CREAT, "O_CREAT"}, {WDB_TSFS_O_TRUNC, "O_TRUNC"}, {WDB_TSFS_O_APPEND, "O_APPEND"}, {WDB_TSFS_O_EXCL, "O_EXCL"}, {WDB_TSFS_O_TEXT, "O_TEXT"}, {0, 0}, /* sentinel */ };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -