Extracted print_address.
This commit is contained in:
parent
41375ba084
commit
7e1068334f
12
devcmd.c
12
devcmd.c
|
@ -622,17 +622,9 @@ int cmd_break(char **arg)
|
|||
|
||||
if (bp->flags & DEVICE_BP_ENABLED) {
|
||||
char name[128];
|
||||
address_t offset;
|
||||
|
||||
printc(" %d. 0x%05x", i, bp->addr);
|
||||
if (!stab_nearest(bp->addr, name,
|
||||
sizeof(name), &offset)) {
|
||||
printc(" (%s", name);
|
||||
if (offset)
|
||||
printc("+0x%x", offset);
|
||||
printc(")");
|
||||
}
|
||||
printc("\n");
|
||||
print_address(bp->addr, name, sizeof(name));
|
||||
printc(" %d. %s\n", i, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
static int format_addr(msp430_amode_t amode, uint16_t addr)
|
||||
{
|
||||
char name[64];
|
||||
address_t offset;
|
||||
int numeric = 0;
|
||||
const char *prefix = "";
|
||||
|
||||
|
@ -51,15 +50,8 @@ static int format_addr(msp430_amode_t amode, uint16_t addr)
|
|||
break;
|
||||
}
|
||||
|
||||
if ((!numeric ||
|
||||
(addr >= 0x200 && addr < 0xfff0)) &&
|
||||
!stab_nearest(addr, name, sizeof(name), &offset) &&
|
||||
!offset)
|
||||
print_address(addr, name, sizeof(name));
|
||||
return printc("%s\x1b[1m%s\x1b[0m", prefix, name);
|
||||
else if (numeric)
|
||||
return printc("%s\x1b[1m0x%x\x1b[0m", prefix, addr);
|
||||
else
|
||||
return printc("%s\x1b[1m0x%04x\x1b[0m", prefix, addr);
|
||||
}
|
||||
|
||||
static int format_reg(msp430_amode_t amode, msp430_reg_t reg)
|
||||
|
@ -178,13 +170,12 @@ void disassemble(address_t offset, const uint8_t *data, int length)
|
|||
address_t oboff;
|
||||
char obname[64];
|
||||
|
||||
if (!stab_nearest(offset, obname, sizeof(obname),
|
||||
&oboff)) {
|
||||
if (!oboff)
|
||||
printc("\x1b[m%s:\x1b[0m\n", obname);
|
||||
else if (first_line)
|
||||
printc("\x1b[m%s+0x%x:\x1b[0m\n",
|
||||
obname, oboff);
|
||||
if (!stab_nearest(offset, obname, sizeof(obname), &oboff) &&
|
||||
!oboff) {
|
||||
printc("\x1b[m%s\x1b[0m:\n", obname);
|
||||
} else if (first_line) {
|
||||
print_address(offset, obname, sizeof(obname));
|
||||
printc("\x1b[m%s\x1b[0m:\n", obname);
|
||||
}
|
||||
first_line = 0;
|
||||
|
||||
|
@ -262,3 +253,21 @@ void show_regs(const address_t *regs)
|
|||
printc("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int print_address(address_t addr, char *out, int max_len)
|
||||
{
|
||||
char name[128];
|
||||
address_t offset;
|
||||
|
||||
if (!stab_nearest(addr, name, sizeof(name), &offset)) {
|
||||
if (offset)
|
||||
snprintf(out, max_len, "%s+0x%x", name, offset);
|
||||
else
|
||||
snprintf(out, max_len, "%s", name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
snprintf(out, max_len, "0x%04x", addr);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,4 +31,10 @@ void hexdump(address_t addr, const uint8_t *buf, int len);
|
|||
/* Colorized register dump */
|
||||
void show_regs(const address_t *regs);
|
||||
|
||||
/* Given an address, format it either as sym+0x0offset or just 0x0offset.
|
||||
*
|
||||
* Returns non-zero if the result is of the form sym+0x0offset.
|
||||
*/
|
||||
int print_address(address_t addr, char *buf, int max_len);
|
||||
|
||||
#endif
|
||||
|
|
26
rtools.c
26
rtools.c
|
@ -785,7 +785,6 @@ static void cgraph_summary(struct call_graph *graph)
|
|||
int from_count = 0;
|
||||
int to_count = 0;
|
||||
char name[64];
|
||||
address_t o;
|
||||
|
||||
while (j < graph->edge_from.size &&
|
||||
CG_EDGE_FROM(graph, j)->src < n->offset)
|
||||
|
@ -807,11 +806,7 @@ static void cgraph_summary(struct call_graph *graph)
|
|||
k++;
|
||||
}
|
||||
|
||||
if (stab_nearest(n->offset,
|
||||
name, sizeof(name), &o) ||
|
||||
o)
|
||||
name[0] = 0;
|
||||
|
||||
print_address(n->offset, name, sizeof(name));
|
||||
printc("0x%04x [%3d ==> %3d] %s\n",
|
||||
n->offset, to_count, from_count, name);
|
||||
}
|
||||
|
@ -823,7 +818,6 @@ static void cgraph_func_info(struct call_graph *graph, address_t addr)
|
|||
int j = 0;
|
||||
int k = 0;
|
||||
char name[64];
|
||||
address_t offset;
|
||||
struct cg_node *n;
|
||||
|
||||
while (i + 1 < graph->node_list.size &&
|
||||
|
@ -845,11 +839,7 @@ static void cgraph_func_info(struct call_graph *graph, address_t addr)
|
|||
CG_EDGE_TO(graph, k)->dst < n->offset)
|
||||
k++;
|
||||
|
||||
if (stab_nearest(n->offset, name, sizeof(name), &offset))
|
||||
printc("0x%04x:\n", n->offset);
|
||||
else if (offset)
|
||||
printc("0x%04x %s+0x%x:\n", n->offset, name, offset);
|
||||
else
|
||||
print_address(n->offset, name, sizeof(name));
|
||||
printc("0x%04x %s:\n", n->offset, name);
|
||||
|
||||
if (j < graph->edge_from.size &&
|
||||
|
@ -861,11 +851,7 @@ static void cgraph_func_info(struct call_graph *graph, address_t addr)
|
|||
if (e->src != n->offset)
|
||||
break;
|
||||
|
||||
if (stab_nearest(e->dst,
|
||||
name, sizeof(name),
|
||||
&offset) ||
|
||||
offset)
|
||||
snprintf(name, sizeof(name), "0x%04x", e->dst);
|
||||
print_address(e->dst, name, sizeof(name));
|
||||
printc(" %s%s\n",
|
||||
e->is_tail_call ? "*" : "", name);
|
||||
|
||||
|
@ -883,11 +869,7 @@ static void cgraph_func_info(struct call_graph *graph, address_t addr)
|
|||
if (e->dst != n->offset)
|
||||
break;
|
||||
|
||||
if (stab_nearest(e->src,
|
||||
name, sizeof(name),
|
||||
&offset) ||
|
||||
offset)
|
||||
snprintf(name, sizeof(name), "0x%04x", e->src);
|
||||
print_address(e->src, name, sizeof(name));
|
||||
printc(" %s%s\n",
|
||||
e->is_tail_call ? "*" : "", name);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "simio_tracer.h"
|
||||
#include "expr.h"
|
||||
#include "output.h"
|
||||
#include "output_util.h"
|
||||
#include "dis.h"
|
||||
|
||||
#define DEFAULT_HISTORY 16
|
||||
|
@ -65,47 +66,28 @@ struct tracer {
|
|||
int verbose;
|
||||
};
|
||||
|
||||
static void print_address(address_t addr)
|
||||
{
|
||||
char name[64];
|
||||
address_t offset;
|
||||
|
||||
printc("0x%04x", addr);
|
||||
if (!stab_nearest(addr, name, sizeof(name), &offset)) {
|
||||
printc(" (%s", name);
|
||||
if (offset)
|
||||
printc("+0x%x", offset);
|
||||
printc(")");
|
||||
}
|
||||
}
|
||||
|
||||
static void event_print(const struct event *e)
|
||||
{
|
||||
char name[128];
|
||||
|
||||
print_address(e->addr, name, sizeof(name));
|
||||
printc(" %10lld: ", e->when);
|
||||
|
||||
switch (e->what) {
|
||||
case EVENT_WRITE_16:
|
||||
printc("write.w ");
|
||||
print_address(e->addr);
|
||||
printc(" => 0x%04x\n", e->data);
|
||||
printc("write.w => %s 0x%04x\n", name, e->data);
|
||||
break;
|
||||
|
||||
case EVENT_READ_16:
|
||||
printc("read.w ");
|
||||
print_address(e->addr);
|
||||
printc("\n");
|
||||
printc("read.w => %s 0x%04x\n", name);
|
||||
break;
|
||||
|
||||
case EVENT_WRITE_8:
|
||||
printc("write.b ");
|
||||
print_address(e->addr);
|
||||
printc(" => 0x%02x\n", e->data);
|
||||
printc("write.b => %s 0x%02x\n", name, e->data);
|
||||
break;
|
||||
|
||||
case EVENT_READ_8:
|
||||
printc("read.b ");
|
||||
print_address(e->addr);
|
||||
printc("\n");
|
||||
printc("read.b => %s\n", name);
|
||||
break;
|
||||
|
||||
case EVENT_IRQ_HANDLE:
|
||||
|
|
11
sym.c
11
sym.c
|
@ -28,6 +28,7 @@
|
|||
#include "binfile.h"
|
||||
#include "util.h"
|
||||
#include "output.h"
|
||||
#include "output_util.h"
|
||||
#include "vector.h"
|
||||
#include "sym.h"
|
||||
#include "reader.h"
|
||||
|
@ -35,7 +36,6 @@
|
|||
int cmd_eval(char **arg)
|
||||
{
|
||||
address_t addr;
|
||||
address_t offset;
|
||||
char name[64];
|
||||
|
||||
if (expr_eval(*arg, &addr) < 0) {
|
||||
|
@ -43,13 +43,8 @@ int cmd_eval(char **arg)
|
|||
return -1;
|
||||
}
|
||||
|
||||
printc("0x%05x", addr);
|
||||
if (!stab_nearest(addr, name, sizeof(name), &offset)) {
|
||||
printc(" = %s", name);
|
||||
if (offset)
|
||||
printc("+0x%x", offset);
|
||||
}
|
||||
printc("\n");
|
||||
print_address(addr, name, sizeof(name));
|
||||
printc("0x%05x = %s\n", addr, name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue