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

📄 r2protos.c

📁 这是一个C程序分析工具
💻 C
📖 第 1 页 / 共 5 页
字号:
/*=========================================================================*/
/* UNIT   :   @(#)r2protos.c	2.8  -  08/04/99  */
/*=========================================================================*/
/* PURPOSE: The declarations and functions in this file are used by        */
/*          instrumented source code created by the r2inst.exe program.    */
/*          This file must be compiled and linked with the instrumented    */
/*          source code.                                                   */
/*                                                                         */
/* SYSTEM : RECON II                                                       */
/*                                                                         */
/* HISTORY:                                                                */
/*                                                                         */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 1.00   6 Feb 93 L. McCallie  Create file.                               */
/* 1.10  20 Feb 93 L. McCallie  Modified user entry method.                */
/* 1.11   3 Mar 93 L. McCallie  Capitalized r2 functions and variables     */
/* 2.00  28 Jun 93 L. McCallie  Modified code for ANSI compatibility       */
/* 3.00  25 Mar 97 J. Ward      Implemented Tisk 17                        */
/* Put under SCCS as version 1.1, 1 Oct 93 by N. Wilde. Use the            */
/*   command "sccs prs ..." for later history.                             */
/*-------------------------------------------------------------------------*/

/*==[ INCLUDES ]===========================================================*/
#include "r2.h"
#include "r2protos.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <time.h>

#ifdef MESSAGE_Q
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#endif

/*==[ DEFINES ]============================================================*/
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif

#define NO_ERR             0
#define FILE_ERR           -1
#define QUEUE_ERR          -2
#define FILE_CLOSED        2

/* Maximum number of allowed source files */
#define MAX_SOURCE_FILES   1000

/* Maximum number of allowed lines per file */
#define MAX_LINE_NUMBER    INT_MAX - 1

/* Maximum length of entries in r2tmp.dat */
#define BUF_SIZE           (MAXLENGTH + 50)

/* Max length of a trace file record +1 */
#define MAX_CHARS          158

#ifdef MESSAGE_Q
   /* Arbitrary long used to name message queue consistently */
   #define MESSAGE_Q_ID       2391245

   /* Message queue string length                            */
   #define MESSAGE_SIZE       158
#endif

/*==[ GLOBAL VARIABLE TYPES ]==============================================*/
/* the trace file mode of operation */
typedef enum {NORMAL, MINTRACE } R2MODE;

/* the trace file current trace status */
typedef enum {R2OPEN, R2SUSPENDED, R2CLOSED } R2STATUS;

#ifdef MIN_TRACE
   /* Components of ADT used for keeping switches in memory. */
   typedef struct SwitchList{
	int Index;
	int Line;
	struct SwitchValueList *ValuesFound;
	struct SwitchList *next;
	struct SwitchList *prev;
   } SwitchListADT;

   typedef struct SwitchValueList {
	int value;
	struct SwitchValueList * next;
   } SwitchValueListADT;

   /* ADT used for keeping True and False branchs in memory. */
   typedef struct LineStruct {
        int Index;
	int Line;
	struct LineStruct *next;
        struct LineStruct *prev;
   } TFListADT;
#endif

#ifdef MESSAGE_Q
   struct msgbuffer {
	long mtype;
	char mtext[MESSAGE_SIZE];
   };
#endif

/* ADT used to write to trace file */
typedef struct trace {
      FILE * tracefile;
      R2STATUS r2status;
   #ifdef MIN_TRACE
      char *filePath[MAX_SOURCE_FILES];
      SwitchListADT *SwitchList;                  /* replaces *gSwitchList,*/
      TFListADT *TrueList;                        /*  *gTrueArray,         */
      TFListADT *FalseList;                       /*  *gFalseArray,        */
      TFListADT *EntryList;                       /*  *gEntryArray         */
      int TrueListEntries;                        /*  gSwitchListEntries,  */
      int FalseListEntries;                       /*  gSwitchListEntries,  */
      int EntryListEntries;                       /*  gSwitchListEntries,  */
      int SwitchListEntries;                      /*  gSwitchListEntries,  */
   #endif
   #ifdef MESSAGE_Q
      int MessageQueueId;                            /* and gMessageQueueId*/
   #endif
}
R2TRACE, *R2TRACE_PTR;


/*==[ GLOBAL VARIABLES ]===================================================*/

/* State of tracing. Can be one of:
   FALSE       - tracing has not started
   TRUE        - tracing has started
   FILE_CLOSED - tracing has been terminated */

char gFilePath[BUF_SIZE];
char *NullFilePath = NULL;

R2TRACE_PTR gCurrentTrace = NULL;

/*==[ PRIVATE FUNCTION PROTOTYPES ]===========================================*/

static void ValidateInput(char *R2srcfile_ptr, int line, int switchValue);

static int WriteTrace(char *TraceData);

static void R2Err(char *FilePath, int Line, char *ErrMessage);

/*  Writes to the trace specified by the parameter theTrace. Inputs */
/*  include the source file and the line number of the instrumented if,*/
/*  for, or while statement. */
int r2true(R2TRACE_PTR theTrace, char *R2srcfile_ptr, int line);

/*  Writes to the trace specified by the parameter theTrace. Inputs*/
/*  include the source file and the line number of the instrumented if, */
/*  for, or while statement.*/
int r2false(R2TRACE_PTR theTrace, char *R2srcfile_ptr, int line);

/*  Writes to the trace specified by the parameter theTrace. Inputs*/
/*  include the source file and the line number of the instrumented*/
/*  entry point for the function.*/
int r2entry(R2TRACE_PTR theTrace, char *R2srcfile_ptr, int line);

/*  Writes to the trace specified by the parameter theTrace. Inputs*/
/*  include the source file, the line number, and the switch value for the */
/*  instrumented switch. */
int r2switch(R2TRACE_PTR theTrace,char *R2srcfile_ptr,int line,int switchValue);

/*  Creates a R2TRACE struct, and opens the "default" trace file based on*/
/*  r2test.dat. Returns a pointer to the struct.*/
R2TRACE_PTR r2OpenDefaultFile(void);

/*  Creates a R2TRACE struct and sets it up for writing to the usual*/
/*  message queue.*/
R2TRACE_PTR r2OpenDefaultMessageQ(void);

/*  Close a trace specified by the parameter theTrace.*/
int r2close(R2TRACE_PTR theTrace, int RtnValue);

/*  Sets R2STATUS to suspend for the trace specified by the parameter */
/*  theTrace */
int r2suspend(R2TRACE_PTR theTrace);

/*  If R2STATUS is currently in R2SUSPEND then status will be changed to*/
/*  R2OPEN for the trace specified by the parameter theTrace. */
int r2resume(R2TRACE_PTR theTrace);

/*  Writes the message to the current trace file, gCurrentTrace. */
int r2comment(R2TRACE_PTR theTrace, char * msg_ptr);

/*  Closes the trace theTrace if R2STATUS not R2CLOSED already.  Then calls */
/*  R2Open to open the new trace file r2newfile.*/
int r2newtrace(R2TRACE_PTR theTrace, char *r2newfile);

/*  Creates a R2TRACE struct, and opens the trace file r2newfile. Returns*/
/*  a pointer to the struct. */
R2TRACE_PTR R2Open(char *r2newfile);

/*  Frees the memory allocated to store the names of the user's source   */
/*  files in the hash table. */
void FreeHashTable (R2TRACE_PTR theTrace);


#ifdef MIN_TRACE
   static TFListADT *TFListBitSet(TFListADT *head, int Index, int Line,
                                                         int *ListEntries);
   static SwitchListADT *NewSwitch(void);
   static SwitchListADT *SwitchListAdd(SwitchListADT *head, int Index,
                                    int Line, int switchvalue,
                                    SwitchListADT *sladtentry);
   static void OutputMinTraceData(void);
   static SwitchValueListADT *NewSwitchValue(void);
   static SwitchValueListADT *SwitchValueListAdd(SwitchValueListADT *head,
                                              SwitchValueListADT *NewEntry);
   static void OutputTFList(TFListADT *head, char *valuestring);
   static void OutputSwitchList(SwitchListADT *head);
   static void FreeSwitchList(SwitchListADT *head);
   static void OutputSwitchValues(SwitchValueListADT *head, int Index,int Line);
   static void FreeSwitchValues(SwitchValueListADT *head);

   /*  If filePath is in gR2FileTable, returns the corresponding fileIndex.   */
   /*  Otherwise, adds filePath to table, assigning next available fileIndex  */
   int R2PathToIndex (char *filePath);

   /*  Returns the hash index of a given file name.                           */
   unsigned int R2GetHashIndex(char *string);

#endif

/*=========================================================================*/
/* FUNCTION: R2True                                                        */
/*=========================================================================*/
/* PURPOSE : If MIN_TRACE is not defined, writes the 'T' character, line   */
/*           number, number of characters in the source file name, and     */
/*           the source file name to the trace file.  If MIN_TRACE is      */
/*           defined, R2True sets the bit in TrueArray corresponding to    */
/*           the file index and line number.                               */
/*                                                                         */
/*           Function is entered when an instrumented 'if', 'for', or      */
/*           'while' statement is encountered.  Example statements are as  */
/*           follows:                                                      */
/*                    Before:                                              */
/*                       if (exp)                                          */
/*                       for (exp;exp;exp)                                 */
/*                       while (exp)                                       */
/*                    After:                                               */
/*                       if ((exp)?R2True:R2False)                         */
/*                       for (exp;(exp)?R2True:R2False;exp)                */
/*                       while ((exp)?R2True:R2False)                      */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : R2OpenDefaultFile, R2OpenDefaultMessageQ, ValidateInput,      */
/*           TFListBitSet, R2Err                                          */
/*                                                                         */
/* USED BY : Instrumented user source code                                 */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 1.00   6 Feb 93 L. McCallie  Create file.                               */
/* 2.00  23 Mar 97 J. Ward      Modify per Tisk 17 to write file name ILO  */
/*                              file index.                                */
/*-------------------------------------------------------------------------*/
int R2True(char * R2srcfile_ptr, int line)
{
/*-------------------------------------------------------------------------*/

⌨️ 快捷键说明

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