#include <stdio.h>

#include "ptrace.h"

// i77 run-time tracing facility, intended to be enabled by compiling with i77 --trace
// This is *not* the backtrace mechanism, it's more like a subset of profiling but
// without the stats.  Which may be added later.

static int _imp_trace_depth = 0;
int _imp_trace_enter(int line, char *file, char *funcname) {
  for (int i = _imp_trace_depth; i > 0; i--) fputc(' ', stderr);
  fprintf(stderr, "\"%s\", %d: > %s\n", file, line, funcname);
  _imp_trace_depth += 1;
  return 0; // I've forgotten how the return value of these is used
}

int _imp_trace_exit(int line, char *file, char *funcname) {
  _imp_trace_depth -= 1;
  for (int i = _imp_trace_depth; i > 0; i--) fputc(' ', stderr);
  fprintf(stderr, "\"%s\", %d: < %s\n", file, line, funcname);
  return 0; // I've forgotten how the return value of these is used
}

