diff --git a/simio/simio_tracer.c b/simio/simio_tracer.c index e235cac..14febe6 100644 --- a/simio/simio_tracer.c +++ b/simio/simio_tracer.c @@ -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) { diff --git a/ui/devcmd.c b/ui/devcmd.c index 8730161..7dfca0f 100644 --- a/ui/devcmd.c +++ b/ui/devcmd.c @@ -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) { diff --git a/ui/power.c b/ui/power.c index 05e656a..b710127 100644 --- a/ui/power.c +++ b/ui/power.c @@ -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); } diff --git a/ui/rtools.c b/ui/rtools.c index ad051b5..552f741 100644 --- a/ui/rtools.c +++ b/ui/rtools.c @@ -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); diff --git a/ui/sym.c b/ui/sym.c index 6aa7879..9ff9268 100644 --- a/ui/sym.c +++ b/ui/sym.c @@ -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; diff --git a/util/output_util.c b/util/output_util.c index 324741d..940cc17 100644 --- a/util/output_util.c +++ b/util/output_util.c @@ -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; } diff --git a/util/output_util.h b/util/output_util.h index ac6add9..46f6eeb 100644 --- a/util/output_util.h +++ b/util/output_util.h @@ -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 *.