forked from xemu-project/xemu
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disas: use result of ->read_memory_func
This gets especially confusing if you start plugging in host addresses from a trace and you wonder why the output keeps changing. Report when read_memory_func fails instead of blindly disassembling the buffer contents. Signed-off-by: Alex Bennée <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,37 +191,43 @@ bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) | |
size_t tsize = MIN(sizeof(cap_buf) - csize, size); | ||
const uint8_t *cbuf = cap_buf; | ||
|
||
info->read_memory_func(pc + csize, cap_buf + csize, tsize, info); | ||
csize += tsize; | ||
size -= tsize; | ||
if (info->read_memory_func(pc + csize, cap_buf + csize, tsize, info) == 0) { | ||
csize += tsize; | ||
size -= tsize; | ||
|
||
while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { | ||
cap_dump_insn(info, insn); | ||
} | ||
while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { | ||
cap_dump_insn(info, insn); | ||
} | ||
|
||
/* If the target memory is not consumed, go back for more... */ | ||
if (size != 0) { | ||
/* | ||
* ... taking care to move any remaining fractional insn | ||
* to the beginning of the buffer. | ||
*/ | ||
if (csize != 0) { | ||
memmove(cap_buf, cbuf, csize); | ||
} | ||
continue; | ||
} | ||
|
||
/* If the target memory is not consumed, go back for more... */ | ||
if (size != 0) { | ||
/* | ||
* ... taking care to move any remaining fractional insn | ||
* to the beginning of the buffer. | ||
* Since the target memory is consumed, we should not have | ||
* a remaining fractional insn. | ||
*/ | ||
if (csize != 0) { | ||
memmove(cap_buf, cbuf, csize); | ||
info->fprintf_func(info->stream, | ||
"Disassembler disagrees with translator " | ||
"over instruction decoding\n" | ||
"Please report this to [email protected]\n"); | ||
} | ||
continue; | ||
} | ||
break; | ||
|
||
/* | ||
* Since the target memory is consumed, we should not have | ||
* a remaining fractional insn. | ||
*/ | ||
if (csize != 0) { | ||
} else { | ||
info->fprintf_func(info->stream, | ||
"Disassembler disagrees with translator " | ||
"over instruction decoding\n" | ||
"Please report this to [email protected]\n"); | ||
"0x%08" PRIx64 ": unable to read memory\n", pc); | ||
break; | ||
} | ||
break; | ||
} | ||
|
||
cs_close(&handle); | ||
|
@@ -286,16 +292,23 @@ bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) | |
|
||
/* Make certain that we can make progress. */ | ||
assert(tsize != 0); | ||
info->read_memory_func(pc + csize, cap_buf + csize, tsize, info); | ||
csize += tsize; | ||
|
||
if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { | ||
cap_dump_insn(info, insn); | ||
if (--count <= 0) { | ||
break; | ||
if (info->read_memory_func(pc + csize, cap_buf + csize, | ||
tsize, info) == 0) | ||
{ | ||
csize += tsize; | ||
|
||
if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { | ||
cap_dump_insn(info, insn); | ||
if (--count <= 0) { | ||
break; | ||
} | ||
} | ||
memmove(cap_buf, cbuf, csize); | ||
} else { | ||
info->fprintf_func(info->stream, | ||
"0x%08" PRIx64 ": unable to read memory\n", pc); | ||
break; | ||
} | ||
memmove(cap_buf, cbuf, csize); | ||
} | ||
|
||
cs_close(&handle); | ||
|