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

📄 r2protos.c

📁 这是一个C程序分析工具
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (SLEntry == NULL)
               R2Err(R2srcfile_ptr, line, "Out of memory for switches");

            SLEntry->Line        = line;
            SLEntry->Index       = index;

            gCurrentTrace->SwitchList =
            SwitchListAdd(gCurrentTrace->SwitchList, index,
                                  line, switchValue, SLEntry);
#else
            sprintf(TraceData, "S %d %d %d %s\n", switchValue, line,
                                     strlen(R2srcfile_ptr), R2srcfile_ptr);
            err = WriteTrace(TraceData);
            if (err == FILE_ERR)
               R2Err(R2srcfile_ptr, line, "Error writing trace file.");
            if (err == QUEUE_ERR)
               R2Err(R2srcfile_ptr, line, "Error writing to message buffer");
#endif
         break;

/*-------------------------------------------------------------------------*/
/*  If the trace is suspended, return without writing or saving anything   */
/*-------------------------------------------------------------------------*/
      case R2SUSPENDED:
         break;

/*-------------------------------------------------------------------------*/
/*  If the trace is closed, issue an error message.                        */
/*-------------------------------------------------------------------------*/
      case R2CLOSED:
         R2Err(R2srcfile_ptr, line, "Attempt to write to a closed trace");
         break;
   }
   return switchValue;
}

/*=========================================================================*/
/* FUNCTION: R2Close                                                       */
/*=========================================================================*/
/* PURPOSE : Closes the current trace file or message queue.  If MIN_TRACE */
/*           is defined, calls the function to write out the saved         */
/*           MIN_TRACE data before closing the trace.                      */
/*                                                                         */
/*           Function is entered when an instrumented exit statement is    */
/*           encountered.  An example statement is as follows:             */
/*                 Before:                                                 */
/*                    exit(expression)                                     */
/*                 After:                                                  */
/*                    exit(R2Close(expression))                            */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : r2OpenDefaultFile, r2OpenDefaultMessageQ, OutputMinTraceData, */
/*           R2Err                                                         */
/*                                                                         */
/* USED BY : TBD                                                           */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 2.00  23 Mar 97   J. Ward    Re-write per Tisk 17.                      */
/*-------------------------------------------------------------------------*/
int R2Close(int RtnValue)
{

/*-------------------------------------------------------------------------*/
/*  If the global trace does not exist, create it now and open it in case  */
/*  an error message needs to be sent to it.                               */
/*-------------------------------------------------------------------------*/
  if( gCurrentTrace == NULL )
  {
      gCurrentTrace = (R2TRACE *) malloc(sizeof(R2TRACE));
#ifdef MESSAGE_Q
      gCurrentTrace = r2OpenDefaultMessageQ();
#else
      gCurrentTrace = r2OpenDefaultFile();
#endif
  }

/*-------------------------------------------------------------------------*/
/*  If the trace is already closed, issue an error message                 */
/*-------------------------------------------------------------------------*/
	if (gCurrentTrace->r2status == R2CLOSED)
          R2Err(NullFilePath, -1, "Recon attempted to close trace file twice.");

/*-------------------------------------------------------------------------*/
/*  If MIN_TRACE is defined, output the MIN_TRACE data before closing      */
/*-------------------------------------------------------------------------*/
#ifdef MIN_TRACE
	OutputMinTraceData();
#endif

/*-------------------------------------------------------------------------*/
/*  Call the lower case funciton to actually close the trace file.         */
/*-------------------------------------------------------------------------*/
RtnValue = r2close(gCurrentTrace, RtnValue);
return RtnValue;
}

int r2close(R2TRACE_PTR theTrace, int RtnValue)
{
/*-------------------------------------------------------------------------*/
/*  Close the trace file and set the status of the trace to R2CLOSED       */
/*-------------------------------------------------------------------------*/
#ifndef MESSAGE_Q
   if (0 != fclose(theTrace->tracefile))
    R2Err(NullFilePath, -1, "An error occured while closing Recon trace file.");
#endif

   gCurrentTrace->r2status = R2CLOSED;

   return RtnValue;
}

/*=========================================================================*/
/* FUNCTION: R2Entry                                                       */
/*=========================================================================*/
/* PURPOSE : If MIN_TRACE is not defined, writes the 'E' 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, R2Entry sets the bit in EntryArray corresponding to  */
/*           the file index and line number.                               */
/*                                                                         */
/*           Function is entered when an instrumented entry point in a     */
/*           function is encountered.  Example statements are as follows:  */
/*                                                                         */
/*                    Before:                                              */
/*                       MyFunction()                                      */
/*                       {                                                 */
/*                         int flag;                                       */
/*                         ...                                             */
/*                       }                                                 */
/*                    After:                                               */
/*                       MyFunction()                                      */
/*                       {int R2InstrumentEntryPointFlag = R2Entry(exp);   */
/*                         int flag;                                       */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : R2OpenDefaultFile, R2OpenDefaultMessageQ, ValidateInput,      */
/*           TFListBitSet, R2Err                                           */
/*                                                                         */
/* USED BY : Instrumented user source code                                 */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 1.00   3 Mar 99 D. Fralish   Create file.                               */
/*-------------------------------------------------------------------------*/
int R2Entry(char * R2srcfile_ptr, int line)
{
/*-------------------------------------------------------------------------*/
/* Check if the global current trace exists.  If not, create one and       */
/* open the corresponding trace file.                                      */
/*-------------------------------------------------------------------------*/
  if( gCurrentTrace == NULL )
  {
      gCurrentTrace = (R2TRACE *) malloc(sizeof(R2TRACE));
#ifdef MESSAGE_Q
      gCurrentTrace = r2OpenDefaultMessageQ();
#else
      gCurrentTrace = r2OpenDefaultFile();
#endif
  }

/*-------------------------------------------------------------------------*/
/*  If tracing is suspended, return.                                       */
/*-------------------------------------------------------------------------*/
  if(R2SUSPENDED == gCurrentTrace->r2status)
  {
     return 1;
  }

/*-------------------------------------------------------------------------*/
/*  Check the input.                                                       */
/*-------------------------------------------------------------------------*/
  ValidateInput(R2srcfile_ptr, line, 1);

/*-------------------------------------------------------------------------*/
/*  Call the lower case function to actually write/save the trace info     */
/*-------------------------------------------------------------------------*/
  return r2entry(gCurrentTrace, R2srcfile_ptr, line);
}

int r2entry(R2TRACE_PTR theTrace, char *R2srcfile_ptr, int line)
{
char TraceData[MAX_CHARS];
int err, index;

   switch (theTrace->r2status) {
/*-------------------------------------------------------------------------*/
/*  If the trace is open, either set the correspondig bit (MIN_TRACE) or   */
/*  write the line to the trace file.                                      */
/*-------------------------------------------------------------------------*/
      case R2OPEN:
#ifdef MIN_TRACE
            index = R2PathToIndex(R2srcfile_ptr);
            gCurrentTrace->EntryList = 
                        TFListBitSet(theTrace->EntryList, index, line,
                                              &(theTrace->EntryListEntries));
#else
            sprintf(TraceData, "E %d %d %s\n", line, strlen(R2srcfile_ptr),
                                               R2srcfile_ptr);
            err = WriteTrace(TraceData);
            if (err == FILE_ERR)
            R2Err(R2srcfile_ptr, line, "Error writing trace file.");
            if (err == QUEUE_ERR)
               R2Err(R2srcfile_ptr, line, "Error writing to message buffer");
#endif
         break;

/*-------------------------------------------------------------------------*/
/*  If the trace is suspended, return without writing or saving anything   */
/*-------------------------------------------------------------------------*/
      case R2SUSPENDED:
         break;

/*-------------------------------------------------------------------------*/
/*  If the trace is closed, issue an error message.                        */
/*-------------------------------------------------------------------------*/
      case R2CLOSED:
         R2Err(R2srcfile_ptr,line, "Attempt to write to a closed trace");
         break;
   }
   return 1;
}


/*=========================================================================*/
/* FUNCTION: r2OpenDefaultFile                                             */
/*=========================================================================*/
/* PURPOSE : Open the trace file.  First, reads r2tmp.dat (created by      */
/*           r2test) to get the name of the trace file and a comment, if   */
/*           any.  Then it opens the trace file and places the comment     */
/*           as the first line of the file.  If r2tmp.dat does not exist,  */
/*           opens a trace file named unknown.r2t.                         */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : R2Open, R2Err                                                 */
/*                                                                         */
/* USED BY : TBD                                                           */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 2.00  23 Mar 97   J. Ward    Created function.  Many parts were         */
/*                              originally in R2Open, whose functionality  */
/*                              is now split between 2 functions.          */
/*-------------------------------------------------------------------------*/
R2TRACE_PTR r2OpenDefaultFile(void)
{
FILE *TmpData;
int i;
char TestDesc[132];

/*-------------------------------------------------------------------------*/
/*  Open r2tmp.dat, written by r2test.  If the file does not exist, issue  */
/*  a warning message to the standard error output and set the name of     */
/*  the trace file to 'unknown.r2t'.                                       */
/*-------------------------------------------------------------------------*/
   if (NULL == (TmpData = fopen("r2tmp.dat", "r"))) {
      fprintf(stderr, "r2protos: could not find r2tmp.dat in current");
      fprintf(stderr, " working directory.\n");
      fprintf(stderr, "Writing trace to file unknown.r2t.\n");
      strcpy(gFilePath, "unknown.r2t");
      strcpy(TestDesc, "NO COMMENT");
   }

⌨️ 快捷键说明

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