diff --git a/docs/USAGE.md b/docs/USAGE.md index c41bbd39f..cc41714a2 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -239,6 +239,11 @@ Behavior with FillBlock is not available (FillBlock build Dynarec blocks and is * 0 : Dynarec will not wait for FillBlock to ready and use Interpreter instead (might speedup a bit massive multithread or JIT programs) * 1 : Dynarec will wait for FillBlock to be ready (Default) +#### BOX64_DYNAREC_GDBJIT * +The GDBJIT debugging support, only available with the compilation option GDBJIT=ON, enable it with gdb command: jit-reader-load /usr/local/lib/libbox64gdbjitreader.so. +* 0 : Dynarec will not generate GDBJIT debuginfo. (Default) +* 1 : Dynarec will generate GDBJIT debuginfo. + #### BOX64_DYNAREC_MISSING * Dynarec print the missing opcodes * 0 : not print the missing opcode (Default, unless DYNAREC_LOG>=1 or DYNAREC_DUMP>=1 is used) diff --git a/docs/box64.pod b/docs/box64.pod index e450a4bd1..f57fdfac6 100644 --- a/docs/box64.pod +++ b/docs/box64.pod @@ -367,6 +367,13 @@ Behavior with FillBlock is not available (FillBlock build Dynarec blocks and is * 0 : Dynarec will not wait for FillBlock to ready and use Interpreter instead (might speedup a bit massive multithread or JIT programs) * 1 : Dynarec will wait for FillBlock to be ready (Default) +=item B=I<0|1> + +The GDBJIT debugging support, only available with the compilation option GDBJIT=ON, enable it with gdb command: jit-reader-load /usr/local/lib/libbox64gdbjitreader.so. + + * 0 : Dynarec will not generate GDBJIT debuginfo. (Default) + * 1 : Dynarec will generate GDBJIT debuginfo. + =item B=I<0|1> Handling of SSE Flush to 0 flags diff --git a/gdbjit/reader.c b/gdbjit/reader.c index 024e88ea5..f2f944d00 100644 --- a/gdbjit/reader.c +++ b/gdbjit/reader.c @@ -1,4 +1,7 @@ #include "gdbjit.h" +#include + +static char block_name_buffer[16]; static enum gdb_status read_debug_info(struct gdb_reader_funcs* self, struct gdb_symbol_callbacks* cbs, void* memory, long memory_sz) { @@ -6,7 +9,8 @@ static enum gdb_status read_debug_info(struct gdb_reader_funcs* self, struct gdb struct gdb_object* object = cbs->object_open(cbs); struct gdb_symtab* symtab = cbs->symtab_open(cbs, object, block->filename); - cbs->block_open(cbs, symtab, NULL, block->start, block->end, "(block)"); + sprintf(block_name_buffer, "%x", block->x64start); + cbs->block_open(cbs, symtab, NULL, block->start, block->end, block_name_buffer); cbs->line_mapping_add(cbs, symtab, block->nlines, block->lines); diff --git a/src/core.c b/src/core.c index ddb83ce2d..5d7666b65 100644 --- a/src/core.c +++ b/src/core.c @@ -72,7 +72,6 @@ int box64_rdtsc_1ghz = 0; uint8_t box64_rdtsc_shift = 0; char* box64_insert_args = NULL; char* box64_new_args = NULL; -int box64_dynarec_gdbjit = 1; #ifdef DYNAREC int box64_dynarec = 1; int box64_dynarec_dump = 0; @@ -98,6 +97,7 @@ uintptr_t box64_nodynarec_start = 0; uintptr_t box64_nodynarec_end = 0; uintptr_t box64_dynarec_test_start = 0; uintptr_t box64_dynarec_test_end = 0; +int box64_dynarec_gdbjit = 0; #ifdef ARM64 int arm64_asimd = 0; int arm64_aes = 0; @@ -901,6 +901,15 @@ void LoadLogEnv() if(!box64_dynarec_wait) printf_log(LOG_INFO, "Dynarec will not wait for FillBlock to ready and use Interpreter instead\n"); } + p = getenv("BOX64_DYNAREC_GDBJIT"); + if(p) { + if(strlen(p)==1) { + if(p[0]>='0' && p[0]<='1') + box64_dynarec_gdbjit = p[0]-'0'; + } + if(box64_dynarec_gdbjit) + printf_log(LOG_INFO, "Dynarec will generate debuginfo for gdbjit\n"); + } p = getenv("BOX64_DYNAREC_ALIGNED_ATOMICS"); if(p) { if(strlen(p)==1) { diff --git a/src/dynarec/dynarec_native.c b/src/dynarec/dynarec_native.c index 011815bc3..3b761a197 100644 --- a/src/dynarec/dynarec_native.c +++ b/src/dynarec/dynarec_native.c @@ -754,7 +754,7 @@ void* FillBlock64(dynablock_t* block, uintptr_t addr, int alternate, int is32bit dynarec_log(LOG_NONE, "%s\n", (box64_dynarec_dump>1)?"\e[m":""); } if (box64_dynarec_gdbjit) { - GdbJITNewBlock(helper.gdbjit_block, (GDB_CORE_ADDR)block->actual_block, (GDB_CORE_ADDR)block->actual_block + native_size); + GdbJITNewBlock(helper.gdbjit_block, (GDB_CORE_ADDR)block->actual_block, (GDB_CORE_ADDR)block->actual_block + native_size, helper.start); } int oldtable64size = helper.table64size; size_t oldnativesize = helper.native_size; diff --git a/src/include/gdbjit.h b/src/include/gdbjit.h index 70405d3e4..40f1ad583 100644 --- a/src/include/gdbjit.h +++ b/src/include/gdbjit.h @@ -11,19 +11,20 @@ typedef struct gdbjit_block_s { FILE* file; GDB_CORE_ADDR start; GDB_CORE_ADDR end; - uintptr_t alloced; + uintptr_t x64start; + size_t alloced; size_t nlines; struct gdb_line_mapping lines[0]; } gdbjit_block_t; -void GdbJITNewBlock(gdbjit_block_t* block, GDB_CORE_ADDR start, GDB_CORE_ADDR end); +void GdbJITNewBlock(gdbjit_block_t* block, GDB_CORE_ADDR start, GDB_CORE_ADDR end, uintptr_t x64start); gdbjit_block_t* GdbJITBlockAddLine(gdbjit_block_t* block, GDB_CORE_ADDR addr, const char* line); void GdbJITBlockReady(gdbjit_block_t* block); #else -#define GdbJITNewBlock(a, b, c) +#define GdbJITNewBlock(a, b, c, d) #define GdbJITBlockAddLine(a, b, c) NULL #define GdbJITBlockReady(a) diff --git a/src/tools/gdbjit.c b/src/tools/gdbjit.c index d91c4c058..baf45fe6f 100644 --- a/src/tools/gdbjit.c +++ b/src/tools/gdbjit.c @@ -46,7 +46,7 @@ gdbjit_descriptor_t __jit_debug_descriptor = { 1, GDBJIT_NOACTION, NULL, NULL }; /* --------------------------------------------------------------------------- */ -void GdbJITNewBlock(gdbjit_block_t* block, GDB_CORE_ADDR start, GDB_CORE_ADDR end) +void GdbJITNewBlock(gdbjit_block_t* block, GDB_CORE_ADDR start, GDB_CORE_ADDR end, uintptr_t x64start) { if (!block) return; @@ -59,6 +59,7 @@ void GdbJITNewBlock(gdbjit_block_t* block, GDB_CORE_ADDR start, GDB_CORE_ADDR en block->start = start; block->end = end; + block->x64start = x64start; block->alloced = block->nlines = 0; }