Ejemplo n.º 1
0
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)) {
		char demangled[MAX_SYMBOL_LENGTH];
		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;
	}

	snprintf(out, max_len, "0x%04x", addr);
	return 0;
}
Ejemplo n.º 2
0
static int cmd_break(cproc_t cp, char **arg)
{
    device_t dev = cproc_device(cp);
    stab_t stab = cproc_stab(cp);
    int i;

    printf("%d breakpoints available:\n", dev->max_breakpoints);
    for (i = 0; i < dev->max_breakpoints; i++) {
        int enabled;
        uint16_t addr;

        if (!dev->getbrk(dev, i, &enabled, &addr) && enabled) {
            char name[128];
            uint16_t offset;

            printf("    %d. 0x%04x", i, addr);
            if (!stab_nearest(stab, addr, name,
                              sizeof(name), &offset)) {
                printf(" (%s", name);
                if (offset)
                    printf("+0x%x", offset);
                printf(")");
            }
            printf("\n");
        }
    }

    return 0;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
void disassemble(address_t offset, const uint8_t *data, int length)
{
	int first_line = 1;

	while (length) {
		struct msp430_instruction insn = {0};
		int retval;
		int count;
		int i;
		address_t oboff;
		char obname[64];

		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;

		retval = dis_decode(data, offset, length, &insn);
		count = retval > 0 ? retval : 2;
		if (count > length)
			count = length;

		printc("    \x1b[36m%05x\x1b[0m:", offset);

		for (i = 0; i < count; i++)
			printc(" %02x", data[i]);

		while (i < 9) {
			printc("   ");
			i++;
		}

		if (retval >= 0)
			dis_format(&insn);
		printc("\n");

		offset += count;
		length -= count;
		data += count;
	}
}
Ejemplo n.º 5
0
void disassemble(address_t offset, const uint8_t *data, int length,
		 powerbuf_t power)
{
	int first_line = 1;
	unsigned long long ua_total = 0;
	int samples_total = 0;

	while (length) {
		struct msp430_instruction insn = {0};
		int retval;
		int count;
		int i;
		address_t oboff;
		char obname[MAX_SYMBOL_LENGTH];

		if (first_line ||
			(!stab_nearest(offset, obname, sizeof(obname), &oboff) &&
			 !oboff)) {
			char buffer[MAX_SYMBOL_LENGTH];

			print_address(offset, buffer, sizeof(buffer), 0);
			printc("\x1b[m%s\x1b[0m:\n", buffer);
		}
		first_line = 0;

		retval = dis_decode(data, offset, length, &insn);
		count = retval > 0 ? retval : 2;
		if (count > length)
			count = length;

		printc("    \x1b[36m%05x\x1b[0m:", offset);

		for (i = 0; i < count; i++)
			printc(" %02x", data[i]);

		while (i < 9) {
			printc("   ");
			i++;
		}

		if (retval >= 0)
			i = dis_format(&insn);

		if (power) {
			unsigned long long ua;
			int samples;

			while (i < 40) {
				printc(" ");
				i++;
			}

			samples = powerbuf_get_by_mab(power, offset, &ua);
			if (samples) {
				printc(" ;; %.01f uA",
					(double)ua / (double)samples);
				ua_total += ua;
				samples_total += samples;
			}
		}

		printc("\n");

		offset += count;
		length -= count;
		data += count;
	}

	if (power && samples_total)
		printc(";; Total over this block: "
			"%.01f uAs in %.01f ms (%.01f uA avg)\n",
		       (double)(ua_total * power->interval_us) / 1000000.0,
		       (double)(samples_total * power->interval_us) / 1000.0,
		       (double)ua_total / (double)samples_total);
}