Tool Idea - locating software errors

renes@microsoft.com
Tue, 26 Apr 1994 06:33:00 GMT

          From comp.compilers

Related articles
Tool Idea - locating software errors renes@microsoft.com (1994-04-26)
Re: Tool Idea - locating software errors ukola@kastor.ccsf.caltech.edu (1994-04-28)
| List of all articles for this month |

Newsgroups: comp.compilers
From: renes@microsoft.com
Keywords: tools, debug
Organization: Compilers Central
Date: Tue, 26 Apr 1994 06:33:00 GMT

This tool is most useful if one or more types have been defined for function
return codes.


The following information would be logged (to the debugger, a file, etc...)
for every function call which returns an error without having to manually
change a line of source code in your project:


          - function type
          - function name
          - function return code
          - source file name
          - source file line number


Because the function type is available, the developer can check if the
return code is an error (when one or more types have been defined for
return codes to functions).


I've hacked a copy of INDENT.EXE to produce a working prototype (for C
source code) and tried this suggestion out - so I know it works.


If anyone is seriously interested in this being developed for C/C++,
please let your favourite compiler vendor know -- or, just implement it. :)


I don't have access to USENET at the moment - if you have any comments,
suggestions etc..., please include me in any replies.




Thank you,


Rene Sugar
renes@microsoft.com


DESCRIPTION:
  -----------


This file gets linked with every executable:
=====_snoopy.c=========================================================
#include <stdio.h>
#include <windows.h>


//
// NOTE: The implementation of this function is provided by
// the developer.
//


void _snoopy(
        char *szReturnType,
        void *pvReturnCode,
        char *szFunctionName,
        char *szFileName,
        unsigned long ulLineNumber)
{
        char sz[BUFSIZ];


        sprintf(
                sz,
                "%s %s() returned [%08lx] in file %s at line %ul\n",
                szReturnType,
                szFunctionName,
                pvReturnCode,
                szFileName,
                ulLineNumber);


        OutputDebugString(sz);
}
=======================================================================


This file gets added to the beginning of every source file:
=====_snoopy.h=========================================================
#ifndef _SNOOPY_H
#define _SNOOPY_H


void _snoopy(
        char *szReturnType,
        void *pvReturnCode,
        char *szFunctionName,
        char *szFileName,
        unsigned long ulLineNumber);


#define return(X) \
        { \
                __TYPE__ __rcode; \
                                                                \
                __rcode = (X); \
                                                                \
                _snoopy( \
                        __DECL__ , \
                        (void *)__rcode, \
                        __FUNC__, \
                        __FILE__, \
                        __LINE__); \
                                                                \
                return(__rcode); \
        }


#endif
=======================================================================


This is a sample input file:
=====demo.c (input)====================================================
#include <stdio.h>


int foo()
{
          int x;


          return x;
}


void main(int argc, char *argv[])
{
          int y;


          y = foo();


          printf("y=%d\n", y);
}
=======================================================================


This is the sample output file:
=====demo.c (output)===================================================
#include <_snoopy.h>


#include <stdio.h>


int foo()
{
#define __TYPE__ int
#define __DECL__ "int"
#define __FUNC__ "foo"


          int x;


          return(x);


#undef __TYPE__
#undef __DECL__
#undef __FUNC__
}


void main(int argc, char *argv[])
{
#define __TYPE__ void
#define __DECL__ "void"
#define __FUNC__ "main"


          int y;


          y = foo();


          printf("y=%d\n", y);


#undef __TYPE__
#undef __DECL__
#undef __FUNC__
}
=======================================================================


NOTES:
  ------


1) For each return statement in the source code, brackets are added if they
are missing. This allows a macro to be defined that wraps each return
statement.


2) #line directives should probably added to the output file so that the
original line numbers are preserved.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.