Add debug tracing feature

It's disabled by default, use -DUNICORN_TRACER=on to enable it
This commit is contained in:
mio
2022-01-18 19:35:43 +01:00
parent abb958cac1
commit 28e791a37f
6 changed files with 149 additions and 1 deletions

28
uc.c
View File

@ -2196,3 +2196,31 @@ uc_err uc_ctl(uc_engine *uc, uc_control_type control, ...)
return err;
}
#ifdef UNICORN_TRACER
uc_tracer *get_tracer()
{
static uc_tracer tracer;
return &tracer;
}
void trace_start(uc_tracer *tracer, trace_loc loc)
{
tracer->starts[loc] = get_clock();
}
void trace_end(uc_tracer *tracer, trace_loc loc, const char *fmt, ...)
{
va_list args;
int64_t end = get_clock();
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "%.6fms\n",
(double)(end - tracer->starts[loc]) / (double)(1000000));
}
#endif