Disassembler now looks up symbols for address operands.
This commit is contained in:
parent
597de3180f
commit
d3606d810d
29
dis.c
29
dis.c
|
@ -21,6 +21,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "dis.h"
|
#include "dis.h"
|
||||||
|
#include "stab.h"
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Disassembler
|
/* Disassembler
|
||||||
|
@ -516,6 +517,20 @@ static const char *const msp430_reg_names[] = {
|
||||||
"R12", "R13", "R14", "R15"
|
"R12", "R13", "R14", "R15"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int format_addr(char *buf, int max_len, const char *prefix,
|
||||||
|
u_int16_t addr)
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
if (stab_find(&addr, &name) < 0)
|
||||||
|
return snprintf(buf, max_len, "%s0x%04x", prefix, addr);
|
||||||
|
|
||||||
|
if (addr)
|
||||||
|
return snprintf(buf, max_len, "%s%s+0x%x", prefix, name, addr);
|
||||||
|
|
||||||
|
return snprintf(buf, max_len, "%s%s", prefix, name);
|
||||||
|
}
|
||||||
|
|
||||||
/* Given an operands addressing mode, value and associated register,
|
/* Given an operands addressing mode, value and associated register,
|
||||||
* print the canonical representation of it to stdout.
|
* print the canonical representation of it to stdout.
|
||||||
*
|
*
|
||||||
|
@ -532,23 +547,23 @@ static int format_operand(char *buf, int max_len,
|
||||||
return snprintf(buf, max_len, "%s", msp430_reg_names[reg]);
|
return snprintf(buf, max_len, "%s", msp430_reg_names[reg]);
|
||||||
|
|
||||||
case MSP430_AMODE_INDEXED:
|
case MSP430_AMODE_INDEXED:
|
||||||
return snprintf(buf, max_len, "%d(%s)", (int16_t)addr,
|
return snprintf(buf, max_len, "0x%x(%s)", (u_int16_t)addr,
|
||||||
msp430_reg_names[reg]);
|
msp430_reg_names[reg]);
|
||||||
|
|
||||||
case MSP430_AMODE_SYMBOLIC:
|
case MSP430_AMODE_SYMBOLIC:
|
||||||
return snprintf(buf, max_len, "0x%04x", addr);
|
return format_addr(buf, max_len, "", addr);
|
||||||
|
|
||||||
case MSP430_AMODE_ABSOLUTE:
|
case MSP430_AMODE_ABSOLUTE:
|
||||||
return snprintf(buf, max_len, "&0x%04x", addr);
|
return format_addr(buf, max_len, "&", addr);
|
||||||
|
|
||||||
case MSP430_AMODE_INDIRECT:
|
case MSP430_AMODE_INDIRECT:
|
||||||
return snprintf(buf, max_len, "@%s", msp430_reg_names[reg]);
|
return format_addr(buf, max_len, "@", addr);
|
||||||
|
|
||||||
case MSP430_AMODE_INDIRECT_INC:
|
case MSP430_AMODE_INDIRECT_INC:
|
||||||
return snprintf(buf, max_len, "@%s+", msp430_reg_names[reg]);
|
return snprintf(buf, max_len, "@%s+", msp430_reg_names[reg]);
|
||||||
|
|
||||||
case MSP430_AMODE_IMMEDIATE:
|
case MSP430_AMODE_IMMEDIATE:
|
||||||
return snprintf(buf, max_len, "#%d", (int16_t)addr);
|
return snprintf(buf, max_len, "#0x%x", (u_int16_t)addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return snprintf(buf, max_len, "???");
|
return snprintf(buf, max_len, "???");
|
||||||
|
@ -586,8 +601,8 @@ int dis_format(char *buf, int max_len,
|
||||||
if ((insn->op == MSP430_OP_CALL ||
|
if ((insn->op == MSP430_OP_CALL ||
|
||||||
insn->op == MSP430_OP_BR) &&
|
insn->op == MSP430_OP_BR) &&
|
||||||
insn->dst_mode == MSP430_AMODE_IMMEDIATE)
|
insn->dst_mode == MSP430_AMODE_IMMEDIATE)
|
||||||
count += snprintf(buf + count, max_len - count,
|
count += format_addr(buf + count, max_len - count,
|
||||||
"#0x%04x", insn->dst_addr);
|
"#", insn->dst_addr);
|
||||||
else
|
else
|
||||||
count += format_operand(buf + count,
|
count += format_operand(buf + count,
|
||||||
max_len - count,
|
max_len - count,
|
||||||
|
|
4
main.c
4
main.c
|
@ -194,7 +194,7 @@ static void disassemble(u_int16_t offset, u_int8_t *data, int length)
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
printf(" %02x", data[i]);
|
printf(" %02x", data[i]);
|
||||||
|
|
||||||
while (i < 8) {
|
while (i < 7) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ static int cmd_dis(char **arg)
|
||||||
char *len_text = get_arg(arg);
|
char *len_text = get_arg(arg);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int length = 0x40;
|
int length = 0x40;
|
||||||
u_int8_t buf[128];
|
u_int8_t buf[512];
|
||||||
|
|
||||||
if (!off_text) {
|
if (!off_text) {
|
||||||
fprintf(stderr, "md: offset must be specified\n");
|
fprintf(stderr, "md: offset must be specified\n");
|
||||||
|
|
Loading…
Reference in New Issue