disassemble: look only for exact symbol matches for operands.

This commit is contained in:
Daniel Beer 2013-01-31 15:31:42 +13:00
parent 2924dee3a2
commit 7113fd2e50
7 changed files with 34 additions and 20 deletions

View File

@ -70,7 +70,7 @@ static void event_print(const struct event *e)
{
char name[128];
print_address(e->addr, name, sizeof(name));
print_address(e->addr, name, sizeof(name), 0);
printc(" %10" LLFMT ": ", e->when);
switch (e->what) {

View File

@ -674,7 +674,7 @@ int cmd_break(char **arg)
if (bp->flags & DEVICE_BP_ENABLED) {
char name[128];
print_address(bp->addr, name, sizeof(name));
print_address(bp->addr, name, sizeof(name), 0);
printc(" %d. %s", i, name);
switch (bp->type) {

View File

@ -70,7 +70,7 @@ static void dump_session_data(powerbuf_t pb, unsigned int s,
idx = (idx + 1) % pb->max_samples;
}
print_address(mab, addr, sizeof(addr));
print_address(mab, addr, sizeof(addr), 0);
printc("%15d %15.01f %s\n", i * pb->interval_us,
((double)ua_tot) / (double)gran, addr);
}

View File

@ -812,7 +812,7 @@ static void cgraph_summary(struct call_graph *graph)
k++;
}
print_address(n->offset, name, sizeof(name));
print_address(n->offset, name, sizeof(name), 0);
printc("0x%04x [%3d ==> %3d] %s\n",
n->offset, to_count, from_count, name);
}
@ -845,7 +845,7 @@ static void cgraph_func_info(struct call_graph *graph, address_t addr)
CG_EDGE_TO(graph, k)->dst < n->offset)
k++;
print_address(n->offset, name, sizeof(name));
print_address(n->offset, name, sizeof(name), 0);
printc("0x%04x %s:\n", n->offset, name);
if (j < graph->edge_from.size &&
@ -857,7 +857,7 @@ static void cgraph_func_info(struct call_graph *graph, address_t addr)
if (e->src != n->offset)
break;
print_address(e->dst, name, sizeof(name));
print_address(e->dst, name, sizeof(name), 0);
printc(" %s%s\n",
e->is_tail_call ? "*" : "", name);
@ -875,7 +875,7 @@ static void cgraph_func_info(struct call_graph *graph, address_t addr)
if (e->dst != n->offset)
break;
print_address(e->src, name, sizeof(name));
print_address(e->src, name, sizeof(name), 0);
printc(" %s%s\n",
e->is_tail_call ? "*" : "", name);

View File

@ -44,7 +44,7 @@ int cmd_eval(char **arg)
return -1;
}
print_address(addr, name, sizeof(name));
print_address(addr, name, sizeof(name), 0);
printc("0x%05x = %s\n", addr, name);
return 0;

View File

@ -51,7 +51,7 @@ static int format_addr(msp430_amode_t amode, address_t addr)
break;
}
print_address(addr, name, sizeof(name));
print_address(addr, name, sizeof(name), PRINT_ADDRESS_EXACT);
return printc("%s\x1b[1m%s\x1b[0m", prefix, name);
}
@ -178,7 +178,8 @@ void disassemble(address_t offset, const uint8_t *data, int length,
(!stab_nearest(offset, obname, sizeof(obname), &oboff) &&
!oboff)) {
char buffer[MAX_SYMBOL_LENGTH];
print_address(offset, buffer, sizeof(buffer));
print_address(offset, buffer, sizeof(buffer), 0);
printc("\x1b[m%s\x1b[0m:\n", buffer);
}
first_line = 0;
@ -284,22 +285,30 @@ void show_regs(const address_t *regs)
}
}
int print_address(address_t addr, char *out, int max_len)
int print_address(address_t addr, char *out, int max_len,
print_address_flags_t f)
{
char name[MAX_SYMBOL_LENGTH];
address_t offset;
if (!stab_nearest(addr, name, sizeof(name), &offset)) {
int len;
if (offset)
len = snprintf(out, max_len, "%s+0x%x", name, offset);
else
len = snprintf(out, max_len, "%s", name);
char demangled[MAX_SYMBOL_LENGTH];
if (demangle(name, demangled, sizeof(demangled)) > 0) {
snprintf(out + len, max_len - len, " (%s)", demangled);
int len;
if (offset) {
if (f & PRINT_ADDRESS_EXACT) {
snprintf(out, max_len, "0x%04x", addr);
return 0;
}
len = snprintf(out, max_len, "%s+0x%x", name, offset);
} else {
len = snprintf(out, max_len, "%s", name);
}
if (demangle(name, demangled, sizeof(demangled)) > 0)
snprintf(out + len, max_len - len, " (%s)", demangled);
return 1;
}

View File

@ -37,7 +37,12 @@ void show_regs(const address_t *regs);
*
* Returns non-zero if the result is of the form sym+0x0offset.
*/
int print_address(address_t addr, char *buf, int max_len);
typedef enum {
PRINT_ADDRESS_EXACT = 0x01
} print_address_flags_t;
int print_address(address_t addr, char *buf, int max_len,
print_address_flags_t f);
/* Name lists. This function is used for printing multi-column sorted
* lists of constant strings. Expected is a vector of const char *.