home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trash / part01 / history.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-22  |  981 b   |  68 lines

  1. #include    <stdio.h>
  2. #include    "register.h"
  3. #include    "symtab.h"
  4. #include    "diblock.h"
  5. #include    "instrn.h"
  6. #include    "process.h"
  7.  
  8. extern char        *calloc();
  9. extern void        couldnot();
  10.  
  11. extern FILE        *outfp;
  12.  
  13. int            hist_length;
  14.  
  15. static unsigned long    *hist_buf;
  16. static int        hist_i;
  17.  
  18. int
  19. hist_init(n)
  20. int    n;
  21. {
  22.     if (n < 0)
  23.     {
  24.         couldnot("initialise history buffer to %d entries", n);
  25.         return -1;
  26.     }
  27.  
  28.     if ((hist_buf = (unsigned long *)calloc(n, sizeof(unsigned long))) == (unsigned long *)0)
  29.     {
  30.         couldnot("allocate memory for history buffer of %d entries", n);
  31.         return -1;
  32.     }
  33.  
  34.     hist_length = n;
  35.  
  36.     return 0;
  37. }
  38.  
  39. void
  40. hist_log(addr)
  41. unsigned long    addr;
  42. {
  43.     if (hist_length > 0)
  44.     {
  45.         hist_buf[hist_i++] = addr;
  46.  
  47.         if (hist_i >= hist_length)
  48.             hist_i = 0;
  49.     }
  50. }
  51.  
  52. void
  53. hist_dump()
  54. {
  55.     int    i;
  56.  
  57.     if (hist_length > 0)
  58.         fprintf(outfp, "Backtrace:\n");
  59.  
  60.     for (i = 0; i < hist_length; i++)
  61.     {
  62.         fprintf(outfp, "%s\n", proc_text_address(hist_buf[hist_i++]));
  63.  
  64.         if (hist_i >= hist_length)
  65.             hist_i = 0;
  66.     }
  67. }
  68.