about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-06-18 16:36:11 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-06-18 16:36:11 +0200
commit9ca5e13d7f03d76bf06ad1baafb99e12cf053694 (patch)
treed7e758b6f84bc8a4bb83c893b68e7c92362c5ad6 /src
parente1825e0ff27d2f663d27aebcbd73dce617e985c6 (diff)
downloadbox64-9ca5e13d7f03d76bf06ad1baafb99e12cf053694.tar.gz
box64-9ca5e13d7f03d76bf06ad1baafb99e12cf053694.zip
[TRACE] Improve trace for 32bits part
Diffstat (limited to 'src')
-rwxr-xr-xsrc/emu/x64run_private.c20
-rwxr-xr-xsrc/include/x64emu.h2
2 files changed, 15 insertions, 7 deletions
diff --git a/src/emu/x64run_private.c b/src/emu/x64run_private.c
index 1aa02b2f..d191fd02 100755
--- a/src/emu/x64run_private.c
+++ b/src/emu/x64run_private.c
@@ -1010,7 +1010,7 @@ const char* getAddrFunctionName(uintptr_t addr)
     return ret;
 }
 
-void printFunctionAddr(uintptr_t nextaddr, const char* text)
+int printFunctionAddr(uintptr_t nextaddr, const char* text)
 {
     uint64_t sz = 0;
     uintptr_t start = 0;
@@ -1021,7 +1021,9 @@ void printFunctionAddr(uintptr_t nextaddr, const char* text)
             printf_log(LOG_NONE, " (%s%s:%s)", text, ElfName(FindElfAddress(my_context, nextaddr)), symbname);
         else
             printf_log(LOG_NONE, " (%s%s:%s + %ld)", text, ElfName(FindElfAddress(my_context, nextaddr)), symbname, nextaddr - start);
+        return 1;
     }
+    return 0;
 }
 
 #ifdef HAVE_TRACE
@@ -1076,20 +1078,26 @@ void PrintTrace(x64emu_t* emu, uintptr_t ip, int dynarec)
             }
             if(peek==0xC3 || peek==0xC2 || (peek==0xF3 && PK(1)==0xC3)) {
                 printf_log(LOG_NONE, " => %p", *(void**)(R_RSP));
-                printFunctionAddr(*(uintptr_t*)(R_RSP), "=> ");
+                if(is32bits)
+                    printFunctionAddr(*(uint32_t*)(R_RSP), "=> ");
+                else
+                    printFunctionAddr(*(uintptr_t*)(R_RSP), "=> ");
             } else if(peek==0x57 && rex.b) {
                 printf_log(LOG_NONE, " => STACK_TOP: %p", *(void**)(R_RSP));
                 printFunctionAddr(ip, "here: ");
-            } else if(peek==0x55 || peek==0x53) {
+            } else if((peek==0x55 || peek==0x53) && !is32bits) {
                 printFunctionAddr(*(uintptr_t*)(R_RSP), " STACK_TOP: ");
-            } else if(peek==0xF3 && PK(1)==0x0F && PK(2)==0x1E && PK(3)==0xFA) {
+            } else if((peek==0x55 || peek==0x56) && is32bits) {
+                if(!printFunctionAddr(*(uint32_t*)(R_RSP), " STACK_TOP: "))
+                    printf_log(LOG_NONE, " STACK_TOP: %p ", (void*)(uintptr_t)*(uint32_t*)(R_RSP));
+            } else if(peek==0xF3 && PK(1)==0x0F && PK(2)==0x1E && PK(3)==0xFA && !is32bits) {
                 printFunctionAddr(*(uintptr_t*)(R_RSP), " STACK_TOP: ");
             } else if(peek==0xE8) { // Call
-                uintptr_t nextaddr = ip + 5 + PK64(1);
+                uintptr_t nextaddr = ip + 5 + PK32(1);
                 printFunctionAddr(nextaddr, "=> ");
             } else if(peek==0xFF) {
                 if(PK(1)==0x25) {
-                    uintptr_t nextaddr = ip + 6 + PK64(2);
+                    uintptr_t nextaddr = ip + 6 + PK32(2);
                     printFunctionAddr(nextaddr, "=> ");
                 }
             }
diff --git a/src/include/x64emu.h b/src/include/x64emu.h
index e9ad201c..355c7fa1 100755
--- a/src/include/x64emu.h
+++ b/src/include/x64emu.h
@@ -58,7 +58,7 @@ long double LD2localLD(void* ld);        // long double (80bits pointer) -> long
 void LD2D(void* ld, void* d);   // long double (80bits) -> double (64bits)
 void D2LD(void* d, void* ld);   // double (64bits) -> long double (64bits)
 
-void printFunctionAddr(uintptr_t nextaddr, const char* text);
+int printFunctionAddr(uintptr_t nextaddr, const char* text); // 0 if nothing was found
 const char* getAddrFunctionName(uintptr_t addr);
 
 #endif //__X86EMU_H_
\ No newline at end of file