Made Trace a build option

This commit is contained in:
ptitSeb 2019-01-31 11:48:25 +01:00
parent da2eed5875
commit ef7ed3b16d
3 changed files with 17 additions and 5 deletions

View File

@ -8,6 +8,7 @@ option(PANDORA "Set to ON if targeting an OpenPandora device" ${PANDORA})
option(USE_CCACHE "Set to ON to use ccache if present in the system" ${USE_CCACHE})
option(LD80BITS "Set to ON if host device have 80bits long double (i.e. i386)" ${LD80BITS})
option(NOALIGN "Set to ON if host device doesn't need re-align (i.e. i386)" ${NOALIGN})
option(HAVE_TRACE "Set to ON to have Trace ability (needs ZydisInfo library)" ${HAVE_TRACE})
# Pandora
@ -24,6 +25,10 @@ if(NOALIGN)
add_definitions(-DNOALIGN)
endif()
if(HAVE_TRACE)
add_definitions(-DHAVE_TRACE)
endif()
add_definitions(-g -std=gnu99 -funwind-tables -O3 -fvisibility=hidden -no-pie -fjump-tables)
if(USE_CCACHE)

View File

@ -37,6 +37,7 @@ void LoadLogEnv()
}
printf_log(LOG_INFO, "Debug level is %d\n", box86_log);
}
#ifdef HAVE_TRACE
p = getenv("BOX86_TRACE_XMM");
if(p) {
if(strlen(p)==1) {
@ -44,6 +45,7 @@ void LoadLogEnv()
trace_xmm = p[0]-'0';
}
}
#endif
}
void LoadEnvPath(path_collection_t *col, const char* defpath, const char* env)
@ -124,7 +126,9 @@ void PrintHelp() {
printf(" BOX86_PATH to set the PATH used by box86 to find x86 programs (default is '.:bin')\n");
printf(" BOX86_LD_LIBRARY_PATH to set the path were x86 lib are searched (default is '.:lib')\n");
printf(" BOX86_LOG with 0/1/2/3 or NONE/INFO/DEBUG/DUMP to set printed debug info\n");
#ifdef HAVE_TRACE
printf(" BOX86_TRACE with 1 to enable x86 execution trace\n");
#endif
}
int main(int argc, const char **argv, const char **env) {
@ -160,7 +164,7 @@ int main(int argc, const char **argv, const char **env) {
for (int i=0; i<context->envc; ++i)
printf_log(LOG_DUMP, " Env[%02d]: %s\n", i, context->envv[i]);
}
#ifdef HAVE_TRACE
p = getenv("BOX86_TRACE");
if(p) {
if (strcmp(p, "0"))
@ -178,7 +182,7 @@ int main(int argc, const char **argv, const char **env) {
context->x86trace = 0;
}
}
#endif
// lets build argc/argv stuff
printf_log(LOG_INFO, "Looking for %s\n", prog);
if(strchr(prog, '/'))
@ -253,6 +257,7 @@ int main(int argc, const char **argv, const char **env) {
SetupX86Emu(context->emu, NULL, NULL);
SetEAX(context->emu, context->argc);
SetEBX(context->emu, (uint32_t)context->argv);
#ifdef HAVE_TRACE
p = getenv("BOX86_TRACE");
if(p) {
setbuf(stdout, NULL);
@ -276,7 +281,7 @@ int main(int argc, const char **argv, const char **env) {
}
}
}
#endif
// export symbols
AddGlobalsSymbols(context->maplib, GetMapSymbol(context->maplib), elf_header);
// Call librarian to load all dependant elf
@ -296,7 +301,7 @@ int main(int argc, const char **argv, const char **env) {
RelocateElfPlt(context, context->maplib, elf_header);
// init...
RunElfInit(elf_header, context->emu);
#ifdef HAVE_TRACE
p = getenv("BOX86_TRACE_NOINIT");
if(p) {
setbuf(stdout, NULL);
@ -320,7 +325,7 @@ int main(int argc, const char **argv, const char **env) {
}
}
}
#endif
// get entrypoint
context->ep = GetEntryPoint(context->maplib, elf_header);

View File

@ -25,6 +25,7 @@ x86emurun:
while (1)
{
emu->old_ip = R_EIP;
#ifdef HAVE_TRACE
if(emu->dec && (
(emu->trace_end == 0)
|| ((R_EIP >= emu->trace_start) && (R_EIP < emu->trace_end))) ) {
@ -47,6 +48,7 @@ x86emurun:
printf_log(LOG_NONE, "\n");
}
}
#endif
uint32_t fetched = *(uint32_t*)(R_EIP); // get a char or a uint32 should be roughly the same on arm
uint8_t opcode = fetched&0xff;
R_EIP++;