fix symbols display within disasm for new disassember, integrate new disasm with GUI debugger properly

This commit is contained in:
Stanislav Shwartsman 2020-12-30 12:23:19 +00:00
parent 79db3896d4
commit 72db10d766
4 changed files with 28 additions and 36 deletions

View File

@ -123,6 +123,7 @@ static struct {
static disassembler bx_disassemble;
static Bit8u bx_disasm_ibuf[32];
static char bx_disasm_tbuf[512];
unsigned bx_dbg_disasm_wrapper(bx_bool is_32, bx_bool is_64, bx_address cs_base, bx_address ip, const Bit8u *instr, char *disbuf);
static bx_bool watchpoint_continue = 0;
unsigned num_write_watchpoints = 0;
@ -2107,22 +2108,10 @@ void bx_dbg_disassemble_current(int which_cpu, int print_time)
if (bx_dbg_read_linear(which_cpu, BX_CPU(which_cpu)->guard_found.laddr, 16, bx_disasm_ibuf))
{
#if 1
unsigned ilen = bx_disassemble.disasm(IS_CODE_32(BX_CPU(which_cpu)->guard_found.code_32_64),
unsigned ilen = bx_dbg_disasm_wrapper(IS_CODE_32(BX_CPU(which_cpu)->guard_found.code_32_64),
IS_CODE_64(BX_CPU(which_cpu)->guard_found.code_32_64),
BX_CPU(which_cpu)->get_segment_base(BX_SEG_REG_CS),
BX_CPU(which_cpu)->guard_found.eip, bx_disasm_ibuf, bx_disasm_tbuf);
#else
extern char* disasm(const Bit8u *opcode, bool is_32, bool is_64, char *disbufptr, bxInstruction_c *i, bx_address cs_base = 0, bx_address rip = 0);
bxInstruction_c i;
disasm(bx_disasm_ibuf, IS_CODE_32(BX_CPU(which_cpu)->guard_found.code_32_64),
IS_CODE_64(BX_CPU(which_cpu)->guard_found.code_32_64),
bx_disasm_tbuf, &i,
BX_CPU(which_cpu)->get_segment_base(BX_SEG_REG_CS), BX_CPU(which_cpu)->guard_found.eip);
unsigned ilen = i.ilen();
#endif
// Note: it would be nice to display only the modified registers here, the easy
// way out I have thought of would be to keep a prev_eax, prev_ebx, etc copies
@ -2847,7 +2836,7 @@ void bx_dbg_disassemble_command(const char *format, Bit64u from, Bit64u to)
if (! bx_dbg_read_linear(dbg_cpu, from, 16, bx_disasm_ibuf)) break;
unsigned ilen = bx_disassemble.disasm(dis_size==32, dis_size==64,
unsigned ilen = bx_dbg_disasm_wrapper(dis_size==32, dis_size==64,
0/*(bx_address)(-1)*/, from/*(bx_address)(-1)*/, bx_disasm_ibuf, bx_disasm_tbuf);
const char *Sym=bx_dbg_disasm_symbolic_address(from, 0);
@ -4028,4 +4017,17 @@ void bx_dbg_step_over_command()
bx_dbg_breakpoint_changed();
}
unsigned bx_dbg_disasm_wrapper(bx_bool is_32, bx_bool is_64, bx_address cs_base, bx_address ip, const Bit8u *instr, char *disbuf)
{
#if 1
unsigned ilen = bx_disassemble.disasm(is_32, is_64, cs_base, ip, instr, disbuf);
#else
bxInstruction_c i;
extern char* disasm(const Bit8u *opcode, bool is_32, bool is_64, char *disbufptr, bxInstruction_c *i, bx_address cs_base = 0, bx_address rip = 0);
disasm(instr, is_32, is_64, disbuf, &i, cs_base, ip);
unsigned ilen = i.ilen();
#endif
return ilen;
}
#endif /* if BX_DEBUGGER */

View File

@ -491,38 +491,39 @@ char *disasm_immediate(char *disbufptr, const bxInstruction_c *i, unsigned src_t
char *disasm_branch_target(char *disbufptr, const bxInstruction_c *i, unsigned src_type, bx_address cs_base, bx_address rip)
{
bx_address target;
Bit16s imm16;
Bit32s imm32;
const char *sym = "";
switch(src_type) {
case BX_IMMW:
case BX_IMMBW_SE: // 8-bit signed value sign extended to 16-bit size
imm32 = (Bit32s) (Bit16s) i->Iw();
disbufptr = dis_sprintf(disbufptr, ".%+d", imm32);
target = (rip + i->ilen() + (Bit16s) i->Iw()) & 0xffff;
target = (cs_base != BX_JUMP_TARGET_NOT_REQ) ? Bit32u(cs_base + target) : target;
imm16 = (Bit16s) i->Iw();
target = (rip + i->ilen() + imm16) & 0xffff; // do not add CS_BASE in 16-bit
sym = GET_SYMBOL(target);
sym = sym ? sym : "";
dis_sprintf(disbufptr, SYMBOLIC_JUMP(".+0x%8x"), (unsigned) imm32, sym);
// disbufptr = dis_sprintf(disbufptr, SYMBOLIC_JUMP(".+0x%04x"), (unsigned) imm16, sym); // hex offset
disbufptr = dis_sprintf(disbufptr, SYMBOLIC_JUMP(".%+d"), (unsigned) imm16, sym);
if (cs_base != BX_JUMP_TARGET_NOT_REQ) {
dis_sprintf(disbufptr, " (0x%08x)", target);
disbufptr = dis_sprintf(disbufptr, " (0x%08x)", Bit32u(cs_base + target));
}
break;
case BX_IMMD:
case BX_IMMBD_SE: // 8-bit signed value sign extended to 32-bit size
imm32 = (Bit32s) i->Id();
disbufptr = dis_sprintf(disbufptr, ".%+d", imm32);
target = rip + i->ilen() + (Bit32s) i->Id();
target = (cs_base != BX_JUMP_TARGET_NOT_REQ) ? bx_address(cs_base + target) : target;
sym = GET_SYMBOL(target);
sym = sym ? sym : "";
dis_sprintf(disbufptr, SYMBOLIC_JUMP(".+0x" FMT_ADDRX64), (unsigned) imm32, sym);
// disbufptr = dis_sprintf(disbufptr, SYMBOLIC_JUMP(".+0x" FMT_ADDRX64), (unsigned) imm32, sym); // hex offset
disbufptr = dis_sprintf(disbufptr, SYMBOLIC_JUMP(".%+d"), (unsigned) imm32, sym);
if (cs_base != BX_JUMP_TARGET_NOT_REQ) {
disbufptr = dis_sprintf(disbufptr, " (0x" FMT_ADDRX ")", target);
}
break;
default:

View File

@ -765,6 +765,7 @@ void disassembler::Jw(const x86_insn *insn)
Bit16u target = (db_eip + imm16) & 0xffff;
sym = GET_SYMBOL(target);
sym = sym ? sym : "";
if (offset_mode_hex) {
dis_sprintf(SYMBOLIC_JUMP(".+0x%04x"),
(unsigned) (Bit16u) imm16, sym);

View File

@ -36,6 +36,7 @@ extern char* disasm(const Bit8u *opcode, bool is_32, bool is_64, char *disbufptr
// Note; any instance has access to all the member functions -- that is enough!
// -- i.e. No further initialization necessary.
static disassembler bx_disassemble;
unsigned bx_dbg_disasm_wrapper(bx_bool is_32, bx_bool is_64, bx_address cs_base, bx_address ip, const Bit8u *instr, char *disbuf);
const char* DC0txt[2] = {"P.Address","L.Address"}; // DumpMode definitions in text
@ -961,21 +962,8 @@ void FillAsm(Bit64u LAddr, int MaxLines)
while (AsmLineCount < MaxLines && BufEmpty == FALSE)
{
// disassemble 1 line with a direct call, into asmtxt
/*
if (1) {
extern char* disasm(const Bit8u *opcode, bool is_32, bool is_64, char *disbufptr, bxInstruction_c *i, bx_address cs_base, bx_address rip);
bxInstruction_c i;
disasm((const Bit8u *) p, In32Mode, In64Mode,
cols[2], &i, (bx_address) 0, (bx_address) LAddr);
len = i.ilen();
}
else
*/
{
len = bx_disassemble.disasm(In32Mode, In64Mode, (bx_address) 0,
len = bx_dbg_disasm_wrapper(In32Mode, In64Mode, (bx_address) 0,
(bx_address) LAddr, (Bit8u *) p, cols[2]);
}
if (len <= BufLen) // disassembly was successful?
{