aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


client/runtime/recomp_trace.h (2683B)


      1 /*
      2  * Bring-up diagnostics for a statically recompiled program.
      3  *
      4  * recomp_types.h defines RECOMP_ENTER(va) to call recomp_trace_enter when the
      5  * generated code is built with -DRECOMP_TRACE. That is the one hook every
      6  * lifted function passes through, and it is where a debugger would put a
      7  * breakpoint if there were a debugger. This is the reference implementation of
      8  * what to hang off it, so a new target does not rewrite it:
      9  *
     10  *   --calltrace FILE     every entry, thread-tagged, to a file
     11  *   --firsthit LO HI     the FIRST entry to each distinct function in a window
     12  *   --argtrace VA        one line per entry to VA with its first three args
     13  *   --watch VA           registers, stack arguments and the object under ecx
     14  *   --watchspan LO HI    move or narrow the [ecx+..] window --watch dumps
     15  *   --poison ADDR        report every change of one target dword
     16  *   --poisonval V        ...only when it becomes V
     17  *   --poke ADDR VAL VA   write one byte the first time VA is entered
     18  *
     19  * Wire it up with three lines in the host:
     20  *
     21  *   for (i = 1; i < argc; i++) {
     22  *       int n = recomp_trace_arg(argc, argv, i);
     23  *       if (n) { i += n - 1; continue; }
     24  *       ... the host's own options ...
     25  *   }
     26  *
     27  * and call recomp_trace_flush() from the fault handler.
     28  *
     29  * A target with a diagnostic of its own -- a watch that knows a class layout,
     30  * a poison that follows a pointer -- sets recomp_trace_extra instead of
     31  * forking this file.
     32  */
     33 #ifndef RECOMP_TRACE_H
     34 #define RECOMP_TRACE_H
     35 
     36 #include <stdint.h>
     37 
     38 /* Consume one option at argv[i]. Returns how many argv entries it took (1 for
     39  * a flag, 2 for one argument, 4 for --poke), or 0 if it is not ours. */
     40 int  recomp_trace_arg(int argc, char** argv, int i);
     41 
     42 /* Flush the --calltrace file. Call before printing a fault report: the trace
     43  * is buffered, because unbuffered it is slower than the code it traces. */
     44 void recomp_trace_flush(void);
     45 
     46 /* Print the last RECOMP_ENTER_SIZE function entries, oldest first. Safe to
     47  * call without -DRECOMP_TRACE (prints nothing). Declared in recomp_types.h. */
     48 /* void recomp_dump_trace(const char* why); */
     49 
     50 /* Per-entry hook for a target's own diagnostics; called after the generic
     51  * work, with g_cur_func already set to va. NULL by default. */
     52 extern void (*recomp_trace_extra)(uint32_t va);
     53 
     54 /* The name of the import the machine is currently inside, or "(none)".
     55  * The host import bridge sets it; --poison prints it, because a host pointer
     56  * appearing in target memory was put there by whichever shim ran last. */
     57 extern const char* g_cur_import;
     58 
     59 /* One line per option, for a host's --help. */
     60 void recomp_trace_help(void);
     61 
     62 #endif /* RECOMP_TRACE_H */