home *** CD-ROM | disk | FTP | other *** search
- HeapGraph version 1.10 01 24 Nov 1994
- -------------------------------------
-
-
-
- Introduction
- ------------
-
- This is a C library which uses my StubsHack library to provide a
- very simple way of making your program send information on every block
- of memory allocated/freed to a file in pipe:$.C_Debug. This is scanned
- by the included application !HeapDisp, which displays your program's
- heap graphically in real time.
-
- Also provided is a simple way of sending diagnostic text to !HeapDisp.
-
-
-
- Installation
- ------------
-
- You should move the HeapGraph directory into your C path. Don't move any
- headers into an existing .h. directory, as they are refered to as
- 'HeapGraph.<headername>.h' in the source.
-
- I find this to be a much simpler way of organising C libraries than
- changing C$Path etc. It also protects against problems when header files
- from different libraries have the same name.
-
- The actual library is 'HeapGraph.o.HGLib'.
-
- Please note that HeapGraph needs my 'StubsHack' library to work.
-
-
-
- To use in your own programs
- ---------------------------
-
- HeapGraph is dead easy to use. Just include "HeapGraph.HeapGraph.h" in
- the source-file which contains your main() function and then, at the
- start of main, put a 'HeapGraph_RedirectAllocFns( NULL);'.
-
- Then predefine HEAPGRAPH by putting '-DHEAPGRAPH' as one of the
- arguments to the C compiler (if you don't do this, the preprocessor will
- remove any HeapGraphRedirectAllocFns() statements).
-
- Link with HeapGraph.o.HGLib and StubsHack.o.SHLib (in that order, since
- HeapGraph refers to things in StubsHack).
-
- Compile/link your program, run the program !Displayer, and start your
- program. Your program's heap will be dynamically displayed in one of
- !Displayer's windows.
-
- If you do a '*Filer_OpenDir Pipe:$.C_Debug' from the command line, you
- will see the pipe file being created/emptied as the program runs.
-
- An example program is provided which uses HeapGraph - it runs a program
- in a TaskWindow which continuously allocates/frees memory. !Displayer
- will show the blocks of memory moving around. HeapGraph also works
- perfectly with Wimp programs - in fact it should work with anything that
- can write to the pipe filing system.
-
-
-
- Sending diagnostic info
- -----------------------
-
- To send text to !HeapDisp, #include "HeapGraph.Debug.h" and use
- 'Debug_Printf(...)'. Also, you should predefine 'HEAPGRAPH_DEBUG' with
- -DHEAPGRAPH_DEBUG as a parameter to your C compiler.
-
- If you don't predefine HEAPGRAPH_DEBUG, all Debuf_Printf()'s will be
- removed by the preprocessor.
-
- HeapGraph_Sendf is identical to Debug_Printf, except whether or not it
- works depends on whether you predefine HEAPGRAPH, rather than
- HEAPGRAPH_DEBUG.
-
-
-
- HEAPGRAPH and HEAPGRAPH_DEBUG
- -----------------------------
-
- It may seem a pain to have to predefine HEAPGRAPH and HEAPGRAPH_DEBUG in
- order to use the HeapGraph library. However, this enables you to put
- 'HeapGraph_RedirectAllocFns()' and lots of 'Debug_Printf's in your code,
- and link with C:HeapGraph.o.HGLib, safe in the knowledge that all the
- HeapGraph stuff will completely disapear during pre-processing when you
- compile (and the linker will not link in the HeapGraph library), unless
- you specifically predefine HEAPGRAPH and/or HEAPGRAPH_DEBUG.
-
- Hence you can make different versions of a program without changing the
- source, or messing around with '#ifdef HEAPGRAPH_DEBUG's in your code.
- All this sort of stuff is in HeapGraph.h - have a look to convince
- yourself that not predefining HEAPGRAPH(_DEBUG) will result in a
- completely 'clean' compile.
-
- There is one slight exception to this if you're making a DDT-version of
- your program, as CC will turn off all optimisations. In this case,
- Debug_Sendf/Printf(...) will be compiled as 'if (0)
- HeapGraph_Dummyf(...)' and this won't be optimsed out. Because of this,
- your program will be linked with the tiny HeapGraph.Sources.c.Dummyf
- file.
-
- The reason this happens is that there's no way that I know of having
- macros which take a variable number of arguments.
-
-
-
- !HeapDisp
- ---------
-
- This uses my Shell library and DeskLib, and is not particulaly polished.
- If you would like to improve it, it's made available under the GNU
- licence, so you must release the source with any released improved
- version.
-
- !HeapDisp will continuously scan Pipe:$.C_Debug.*. When it finds a file,
- it will open a separate window for it - !HeapDisp can display the heap
- of any number of programs at the same time.
-
- Text sent with HeapGraph_Sendf/Debugf will be displayed along with the
- heap display.
-
- Pressing <Shift>-Menu will bring up a save box. If the click was over
- text, this text will be saved. If the click was over the picture of the
- heap, it will be saved as a sprite. This isn't particulaly useful, but
- Shell has the code in it aready, so there's no harm done or programming
- time wasted!
-
- Pressing Menu will bring up a menu with which you can set the vertical
- size of the heap display.
-
- The colour of malloc blocks displayed by !HeapDisp can be changed with
- HeapGraph_SetReference() - see HeapGraph.h for details.
-
-
-
- Random thought...
- -----------------
-
- It should be possible to display the malloc heap of any program which
- uses the Shared C Library, *without* re-linking. A module could
- intercept the SharedCLibrary_LibInitAPCS_R SWI, which is called whenever
- a sharedclib-using application starts up, and find, from the SWI
- parameters, the address of the vector table used to implement the
- various SCL functions. Then it should be fairly straightforward to patch
- the malloc/calloc/free/realloc branchs to go to a routine in the module
- which sends appropriate data to pipefs and then returns to the
- application.
-
-
-
-
- Other
- -----
-
- All the contents of the HeapGraph directory are © Julian Smith, 1994.
- Feel free to distribute it, but only distribute the original version. If
- you make any changes, please send them to me and I'll send them out with
- the next release.
-
- Any suggestions/comments/bug fixes etc are very much welcomed.
-
-
-
- - Julian Smith
-
-
- ------------------------
- julians@cogsci.ed.ac.uk
- ------------------------
-
- or:
-
- ------------------------
- Department of Psychology
- University of Edinburgh
- 7 George Square
- Edinburgh
- EH8 9JZ
- UK
- ------------------------
-