about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-07-30 14:18:53 +0200
committerptitSeb <sebastien.chev@gmail.com>2022-07-30 14:18:53 +0200
commit8bc9baefd688945327e2b01d257f656d622f33f1 (patch)
tree4db1db5ca66c4b1a44f18d3e0770fe5d032b7382 /src
parent0fe835e0871b42104218c9440f599d7a9e2b1f2f (diff)
downloadbox64-8bc9baefd688945327e2b01d257f656d622f33f1.tar.gz
box64-8bc9baefd688945327e2b01d257f656d622f33f1.zip
Added BOX64_ROLLING_LOG=1 for a 'Just in Time LOG=2' on signal
Diffstat (limited to 'src')
-rwxr-xr-xsrc/box64context.c12
-rwxr-xr-xsrc/dynarec/arm64/dynarec_arm64_00.c4
-rwxr-xr-xsrc/emu/x64int3.c16
-rwxr-xr-xsrc/include/box64context.h7
-rwxr-xr-xsrc/include/debug.h1
-rwxr-xr-xsrc/libtools/signals.c9
-rwxr-xr-xsrc/main.c14
7 files changed, 57 insertions, 6 deletions
diff --git a/src/box64context.c b/src/box64context.c
index ef5b6c54..1d940b39 100755
--- a/src/box64context.c
+++ b/src/box64context.c
@@ -154,6 +154,12 @@ box64context_t *NewBox64Context(int argc)
     // init and put default values
     box64context_t *context = my_context = (box64context_t*)calloc(1, sizeof(box64context_t));
 
+    if(cycle_log)
+        for(int i=0; i<CYCLE_LOG; ++i) {
+            context->log_call[i] = (char*)calloc(256, 1);
+            context->log_ret[i] = (char*)calloc(128, 1);
+        }
+
     context->deferedInit = 1;
     context->sel_serial = 1;
 
@@ -293,6 +299,12 @@ void FreeBox64Context(box64context_t** context)
     pthread_mutex_destroy(&ctx->mutex_thread);
     pthread_mutex_destroy(&ctx->mutex_bridge);
 
+    if(cycle_log)
+        for(int i=0; i<CYCLE_LOG; ++i) {
+            free(ctx->log_call[i]);
+            free(ctx->log_ret[i]);
+        }
+
     free(ctx);
 }
 
diff --git a/src/dynarec/arm64/dynarec_arm64_00.c b/src/dynarec/arm64/dynarec_arm64_00.c
index 37ec3fa8..423fa821 100755
--- a/src/dynarec/arm64/dynarec_arm64_00.c
+++ b/src/dynarec/arm64/dynarec_arm64_00.c
@@ -1645,7 +1645,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
                     x87_forget(dyn, ninst, x3, x4, 0);
                     sse_purge07cache(dyn, ninst, x3);
                     tmp = isSimpleWrapper(*(wrapper_t*)(addr));
-                    if(box64_log<2 && tmp) {
+                    if((box64_log<2 || !cycle_log) && tmp) {
                         //GETIP(ip+3+8+8); // read the 0xCC
                         call_n(dyn, ninst, *(void**)(addr+8), tmp);
                         addr+=8+8;
@@ -2091,7 +2091,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
                     MESSAGE(LOG_DUMP, "Native Call to %s (retn=%d)\n", GetNativeName(GetNativeFnc(dyn->insts[ninst].natcall-1)), dyn->insts[ninst].retn);
                     // calling a native function
                     sse_purge07cache(dyn, ninst, x3);
-                    if(box64_log<2 && dyn->insts[ninst].natcall && (tmp=isSimpleWrapper(*(wrapper_t*)(dyn->insts[ninst].natcall+2)))) {
+                    if((box64_log<2 || !cycle_log) && dyn->insts[ninst].natcall && (tmp=isSimpleWrapper(*(wrapper_t*)(dyn->insts[ninst].natcall+2)))) {
                         //GETIP(ip+3+8+8); // read the 0xCC
                         call_n(dyn, ninst, *(void**)(dyn->insts[ninst].natcall+2+8), tmp);
                         POP1(xRIP);   // pop the return address
diff --git a/src/emu/x64int3.c b/src/emu/x64int3.c
index 1cac5cdc..50afa366 100755
--- a/src/emu/x64int3.c
+++ b/src/emu/x64int3.c
@@ -83,12 +83,17 @@ void x64Int3(x64emu_t* emu)
             elfheader_t *h = FindElfAddress(my_context, *(uintptr_t*)(R_ESP));
             int have_trace = 0;
             if(h && strstr(ElfName(h), "libMiles")) have_trace = 1;*/
-            if(box64_log>=LOG_DEBUG /*|| have_trace*/) {
+            if(box64_log>=LOG_DEBUG || cycle_log) {
                 pthread_mutex_lock(&emu->context->mutex_trace);
                 int tid = GetTID();
-                char buff[256] = "\0";
+                char t_buff[256] = "\0";
                 char buff2[64] = "\0";
                 char buff3[64] = "\0";
+                char* buff = cycle_log?my_context->log_call[my_context->current_line]:t_buff;
+                char* buffret = cycle_log?my_context->log_ret[my_context->current_line]:NULL;
+                if(buffret) buffret[0] = '\0';
+                if(cycle_log)
+                    my_context->current_line = (my_context->current_line+1)&(CYCLE_LOG-1);
                 char *tmp;
                 int post = 0;
                 int perr = 0;
@@ -223,7 +228,7 @@ void x64Int3(x64emu_t* emu)
                 } else {
                     snprintf(buff, 255, "%04d|%p: Calling %s(0x%lX, 0x%lX, 0x%lX, ...)", tid, *(void**)(R_RSP), s, R_RDI, R_RSI, R_RDX);
                 }
-                printf_log(LOG_NONE, "%s =>", buff);
+                if(!cycle_log) printf_log(LOG_NONE, "%s =>", buff);
                 pthread_mutex_unlock(&emu->context->mutex_trace);
                 w(emu, addr);   // some function never come back, so unlock the mutex first!
                 pthread_mutex_lock(&emu->context->mutex_trace);
@@ -252,7 +257,10 @@ void x64Int3(x64emu_t* emu)
                     snprintf(buff3, 63, " (errno=%d:\"%s\")", errno, strerror(errno));
                 else if(perr==2 && R_EAX==0)
                     snprintf(buff3, 63, " (errno=%d:\"%s\")", errno, strerror(errno));
-                printf_log(LOG_NONE, " return 0x%lX%s%s\n", R_RAX, buff2, buff3);
+                if(cycle_log)
+                    snprintf(buffret, 127, "0x%lX%s%s\n", R_RAX, buff2, buff3);
+                else
+                    printf_log(LOG_NONE, " return 0x%lX%s%s\n", R_RAX, buff2, buff3);
                 pthread_mutex_unlock(&emu->context->mutex_trace);
             } else
                 w(emu, addr);
diff --git a/src/include/box64context.h b/src/include/box64context.h
index 1ec9855e..1e7f5efc 100755
--- a/src/include/box64context.h
+++ b/src/include/box64context.h
@@ -64,6 +64,8 @@ typedef struct base_segment_s {
     pthread_key_t   key;
 } base_segment_t;
 
+#define CYCLE_LOG   8
+
 typedef struct box64context_s {
     path_collection_t   box64_path;     // PATH env. variable
     path_collection_t   box64_ld_lib;   // LD_LIBRARY_PATH env. variable
@@ -187,6 +189,11 @@ typedef struct box64context_s {
     void*               stack_clone;
     int                 stack_clone_used;
 
+    // rolling logs
+    char*               log_call[CYCLE_LOG];
+    char*               log_ret[CYCLE_LOG];
+    int                 current_line;
+
 } box64context_t;
 
 extern box64context_t *my_context; // global context
diff --git a/src/include/debug.h b/src/include/debug.h
index 6d5ce616..48103d3a 100755
--- a/src/include/debug.h
+++ b/src/include/debug.h
@@ -27,6 +27,7 @@ extern int arm64_atomics;
 #endif
 #endif
 extern int dlsym_error;    // log dlsym error
+extern int cycle_log;      // if using rolling logs
 #ifdef HAVE_TRACE
 extern int trace_xmm;      // include XMM reg in trace?
 extern int trace_emm;      // include EMM reg in trace?
diff --git a/src/libtools/signals.c b/src/libtools/signals.c
index 88e5052f..d212d1b4 100755
--- a/src/libtools/signals.c
+++ b/src/libtools/signals.c
@@ -990,6 +990,15 @@ exit(-1);
                 exit(-1);
             }
         }
+        if(cycle_log) {
+            int j = (my_context->current_line+1)&(CYCLE_LOG-1);
+            for (int i=0; i<CYCLE_LOG; ++i) {
+                int k = (i+j)&(CYCLE_LOG-1);
+                if(my_context->log_call[k][0]) {
+                    printf_log(log_minimum, "%s => return %s\n", my_context->log_call[k], my_context->log_ret[k]);
+                }
+            }
+        }
 #ifdef DYNAREC
         uint32_t hash = 0;
         if(db)
diff --git a/src/main.c b/src/main.c
index 0f770db6..7baba053 100755
--- a/src/main.c
+++ b/src/main.c
@@ -62,6 +62,7 @@ int arm64_atomics = 0;
 int box64_dynarec = 0;
 #endif
 int dlsym_error = 0;
+int cycle_log = 0;
 #ifdef HAVE_TRACE
 int trace_xmm = 0;
 int trace_emm = 0;
@@ -351,6 +352,19 @@ void LoadLogEnv()
         if(!box64_nobanner)
             printf_log(LOG_INFO, "Debug level is %d\n", box64_log);
     }
+    p = getenv("BOX64_ROLLING_LOG");
+    if(p) {
+        if(strlen(p)==1) {
+            if(p[0]>='0' && p[0]<='1')
+                cycle_log = p[0]-'0';
+        }
+        if(cycle_log && box64_log>LOG_INFO) {
+            cycle_log = 0;
+            printf_log(LOG_NONE, "Incompatible Rolling log and Debug Log, disabling Rolling log\n");
+        }
+    }
+    if(!box64_nobanner && cycle_log)
+        printf_log(LOG_INFO, "Rolling log, showing last %d function call on signals\n", CYCLE_LOG);
     p = getenv("BOX64_DUMP");
     if(p) {
         if(strlen(p)==1) {