home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / stubshack / HeapGraph_h_HeapGraph < prev    next >
Encoding:
Text File  |  1994-11-24  |  4.8 KB  |  140 lines

  1. #ifndef __HeapGraph_h
  2. #define __HeapGraph_h
  3.  
  4. #ifndef __stdio_h
  5. #include <stdio.h>
  6. #endif
  7.  
  8.  
  9. #ifdef HEAPGRAPH
  10.  
  11. #ifndef __HeapGraph_Sendf_h
  12. #include "Sendf.h"
  13. #endif
  14.  
  15. int    HeapGraph_RedirectAllocFns( const char *filename);
  16.     /* 
  17.     Use filename=NULL to send output to a unique file in Pipe:$.C_Debug
  18.     to be picked up by the displayer.
  19.  
  20.     Returns 0 if succesful, otherwise non-zero.
  21.  
  22.     After this function is called, all calls to the ANSI C functions
  23.     malloc, realloc, calloc and free will actually be redirected (by
  24.     altering stubs at runtime) to internal HeapGraph functions.
  25.  
  26.     These functions will call the standard ANSI C functions, but also send
  27.     data about the operation (malloc/free etc.) to 'filename', or a unique
  28.     file in Pipe:$.C_Debug.* if 'filename' is NULL.
  29.  
  30.     This data can be picked up by the StubsHack !Displayer application to
  31.     give a dynamic graphical display of your programs heap.
  32.  
  33.     If you want to call malloc/realloc/calloc/free directly, without sending
  34.     data to 'filename', you can always use the function-pointers
  35.     StubsHack_scl_malloc, StubsHack_scl_free, StubsHack_scl_realloc,
  36.     StubsHack_scl_calloc defined in "StubsHack.StubsHack.h".
  37.     
  38.     If, for some reason, you want to know where malloc calls et al were sent to 
  39.     before you called 'HeapGraph_RedirectAllocFns', #include "HeapGraph.OldMalloc,
  40.     and use HeapGraph_old_malloc etc.
  41.     Normally HeapGraph_old_malloc == StubsHack_scl_malloc, but it won't if malloc 
  42.     was intercepted before you called 'HeapGraph_RedirectAllocFns'.
  43.     */
  44.  
  45.  
  46.  
  47. #define HeapGraph_Sendf HeapGraph__Sendf
  48. /*void    HeapGraph_Sendf( char *fmt, ...);*/
  49.     /* Sends text to the output file, which will be displayed by the displayer    */
  50.     /* Don't even *think* about sending characters between 1 and 4 - these will be    */
  51.     /* interpreted as messages about the heap.                    */
  52.  
  53.     /* Also, don't send messages of more than 127 chrs from a taskwindow -         */
  54.     /* - writing to a pipe from a taskwindow seems to hang when the pipe file length*/
  55.     /* gets to 255. HeapGraph will wait until a pipe file is <128 bytes long    */
  56.     /* before writing to it if it is running in a taskwindow, giving you 127 bytes     */
  57.     /* grace...                                    */
  58.     /* You can call _Sendf without calling _RedirectAllocFns - this enables you to     */
  59.     /* send debugging data of your own without having all malloc's sent as well.    */
  60.  
  61.  
  62. void    HeapGraph_Init( const char *filename);
  63.     /* You don't have to call this function - it is automatically called by both     */
  64.     /* _RedirectAllocFns and _Sendf the first time they are used if you haven't     */
  65.     /* called _Init already.                            */
  66.     /* If filename==NULL (the usual), subsequent output will be sent to a unique     */
  67.     /* file in Pipe:$.C_Debug, otherwise 'filename' will be used.            */
  68.     /* You could use _Init to change the file to which subsequent data is sent.    */
  69.  
  70. extern int    HeapGraph_reference;
  71. #define HeapGraph_SetReference( ref)    HeapGraph_reference = (ref)
  72.     /* HeapGraph_SetReference( x) will set the colour of subsequently malloced     */
  73.     /* blocks displayed by !HeapDisp to be 8+(x && 7).                */
  74.  
  75. /* Other stuff - probably not much use, but included here just in case.    */
  76.  
  77. extern char    HeapGraph_filename[];
  78.     /* The name of the file to which all HeapCheck output is sent.        */
  79.     /* Don't try to open this file yourself - if you want to write to it,    */
  80.     /* use HeapGraph_Sendf.                            */
  81.     /* It is provided here in case you want to print it out or something,    */
  82.     /* *not* so you can open it etc.                    */
  83.  
  84. FILE    *HeapGraph_OpenPipeFile( void);
  85. void    HeapGraph_ClosePipeFile( FILE *file);
  86.     /* Use these if you really want to acess the pipe file yourself.    */
  87.     /* They check whether we are a task window etc.                */
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. #else
  95.  
  96. /* These are for when HEAPGRAPH is not #defined.    */
  97. /*
  98. They effectively remove all HeapGraph calls fom your source at the
  99. preprocess stage of compilation, so you can make HeapGraph or normal
  100. versions of your program simply by using cc ... -DHEAPGRAPH ...
  101. */
  102.  
  103. #ifndef __HeapGraph_Dummyf_h
  104. #include "Dummyf.h"
  105. #endif
  106.  
  107. #define HeapGraph_RedirectAllocFns( filename) 0
  108. #define HeapGraph_Init( filename)
  109. #define HeapGraph_SetReference( ref)
  110. #define HeapGraph_filename ""
  111. #define HeapGraph_OpenPipeFile()    NULL
  112. #define HeapGraph_ClosePipeFile( file)
  113.  
  114. #define HeapGraph_Sendf    if (0) HeapGraph_Dummyf
  115.     /* The file Dummyf contains the function 'Dummyf', which will only    */
  116.     /* be linked in if your compiler is performing no optimisations, eg    */
  117.     /* when you make a DDT version of your program.                */
  118.  
  119. #endif
  120.  
  121.  
  122.  
  123.  
  124. /* These are always used.    */
  125. #define HeapGraph_SetReferenceDefault( ref)    HeapGraph_SetReference( 0)
  126.  
  127. typedef enum    {
  128.     HeapGraph_COLOUR    = 1,    /* For compatibility with ACELibs's Debug.    */
  129.     HeapGraph_MALLOC    = 2,
  130.     HeapGraph_REALLOC    = 3,
  131.     HeapGraph_FREE        = 4
  132.     }
  133.     HeapGraph_codes;
  134.     /* These codes signify the start of heap data to !HeapDisp.    */
  135.     /* Have a look at StubsHack.Sources.c.HeapGraph if you're    */
  136.     /* interested in the actual data format.            */
  137.  
  138.  
  139. #endif
  140.