Merge pull request #71 from tgtakaoka/fix-disassemble

Fix repeated disassemble
This commit is contained in:
Daniel Beer 2018-07-18 08:02:26 +12:00 committed by GitHub
commit 844c322721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -399,7 +399,9 @@ int cmd_dis(char **arg)
len_text); len_text);
return -1; return -1;
} }
} else if (offset < 0x10000 && offset + length > 0x10000) { }
length += (length & 1);
if (offset < 0x10000 && offset + length > 0x10000) {
length = 0x10000 - offset; length = 0x10000 - offset;
} }
@ -414,8 +416,8 @@ int cmd_dis(char **arg)
return -1; return -1;
} }
reader_set_repeat("dis 0x%x 0x%x", offset + length, length); offset = disassemble(offset, buf, length, device_default->power_buf);
disassemble(offset, buf, length, device_default->power_buf); reader_set_repeat("dis 0x%x 0x%x", offset, length);
free(buf); free(buf);
return 0; return 0;
} }

View File

@ -205,12 +205,13 @@ static int dis_format(const struct msp430_instruction *insn)
return len; return len;
} }
void disassemble(address_t offset, const uint8_t *data, int length, address_t disassemble(address_t offset, const uint8_t *data, int length,
powerbuf_t power) powerbuf_t power)
{ {
int first_line = 1; int first_line = 1;
unsigned long long ua_total = 0; unsigned long long ua_total = 0;
int samples_total = 0; int samples_total = 0;
address_t next_offset = offset;
while (length) { while (length) {
struct msp430_instruction insn = {0}; struct msp430_instruction insn = {0};
@ -231,6 +232,8 @@ void disassemble(address_t offset, const uint8_t *data, int length,
first_line = 0; first_line = 0;
retval = dis_decode(data, offset, length, &insn); retval = dis_decode(data, offset, length, &insn);
if (retval > 0)
next_offset = offset + retval;
count = retval > 0 ? retval : 2; count = retval > 0 ? retval : 2;
if (count > length) if (count > length)
count = length; count = length;
@ -279,6 +282,8 @@ void disassemble(address_t offset, const uint8_t *data, int length,
(double)(ua_total * power->interval_us) / 1000000.0, (double)(ua_total * power->interval_us) / 1000000.0,
(double)(samples_total * power->interval_us) / 1000.0, (double)(samples_total * power->interval_us) / 1000.0,
(double)ua_total / (double)samples_total); (double)ua_total / (double)samples_total);
return next_offset;
} }
void hexdump(address_t addr, const uint8_t *data, int data_len) void hexdump(address_t addr, const uint8_t *data, int data_len)

View File

@ -23,8 +23,11 @@
#include "util.h" #include "util.h"
#include "powerbuf.h" #include "powerbuf.h"
/* Print colorized disassembly on command processor standard output */ /* Print colorized disassembly on command processor standard output.
void disassemble(address_t addr, const uint8_t *buf, int len, *
* Returns the next possible instruction address.
*/
address_t disassemble(address_t addr, const uint8_t *buf, int len,
powerbuf_t power); powerbuf_t power);
/* Print colorized hexdump on standard output */ /* Print colorized hexdump on standard output */