home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "register.h"
- #include "symtab.h"
- #include "diblock.h"
- #include "instrn.h"
- #include "process.h"
-
- extern char *calloc();
- extern void couldnot();
-
- extern FILE *outfp;
-
- int hist_length;
-
- static unsigned long *hist_buf;
- static int hist_i;
-
- int
- hist_init(n)
- int n;
- {
- if (n < 0)
- {
- couldnot("initialise history buffer to %d entries", n);
- return -1;
- }
-
- if ((hist_buf = (unsigned long *)calloc(n, sizeof(unsigned long))) == (unsigned long *)0)
- {
- couldnot("allocate memory for history buffer of %d entries", n);
- return -1;
- }
-
- hist_length = n;
-
- return 0;
- }
-
- void
- hist_log(addr)
- unsigned long addr;
- {
- if (hist_length > 0)
- {
- hist_buf[hist_i++] = addr;
-
- if (hist_i >= hist_length)
- hist_i = 0;
- }
- }
-
- void
- hist_dump()
- {
- int i;
-
- if (hist_length > 0)
- fprintf(outfp, "Backtrace:\n");
-
- for (i = 0; i < hist_length; i++)
- {
- fprintf(outfp, "%s\n", proc_text_address(hist_buf[hist_i++]));
-
- if (hist_i >= hist_length)
- hist_i = 0;
- }
- }
-