disas: Move host asm annotations to tb_gen_code
Instead of creating GStrings and passing them into log_disas, just print the annotations directly in tb_gen_code. Fix the annotations for the slow paths of the TB, after the part implementing the final guest instruction. Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
bcf368626c
commit
4c389f6edf
@ -1816,10 +1816,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
|||||||
qemu_log_in_addr_range(tb->pc)) {
|
qemu_log_in_addr_range(tb->pc)) {
|
||||||
FILE *logfile = qemu_log_lock();
|
FILE *logfile = qemu_log_lock();
|
||||||
int code_size, data_size = 0;
|
int code_size, data_size = 0;
|
||||||
g_autoptr(GString) note = g_string_new("[tb header & initial instruction]");
|
size_t chunk_start;
|
||||||
size_t chunk_start = 0;
|
|
||||||
int insn = 0;
|
int insn = 0;
|
||||||
qemu_log("OUT: [size=%d]\n", gen_code_size);
|
|
||||||
if (tcg_ctx->data_gen_ptr) {
|
if (tcg_ctx->data_gen_ptr) {
|
||||||
code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr;
|
code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr;
|
||||||
data_size = gen_code_size - code_size;
|
data_size = gen_code_size - code_size;
|
||||||
@ -1828,26 +1827,33 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dump header and the first instruction */
|
/* Dump header and the first instruction */
|
||||||
|
qemu_log("OUT: [size=%d]\n", gen_code_size);
|
||||||
|
qemu_log(" -- guest addr 0x" TARGET_FMT_lx " + tb prologue\n",
|
||||||
|
tcg_ctx->gen_insn_data[insn][0]);
|
||||||
chunk_start = tcg_ctx->gen_insn_end_off[insn];
|
chunk_start = tcg_ctx->gen_insn_end_off[insn];
|
||||||
log_disas(tb->tc.ptr, chunk_start, note->str);
|
log_disas(tb->tc.ptr, chunk_start);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dump each instruction chunk, wrapping up empty chunks into
|
* Dump each instruction chunk, wrapping up empty chunks into
|
||||||
* the next instruction. The whole array is offset so the
|
* the next instruction. The whole array is offset so the
|
||||||
* first entry is the beginning of the 2nd instruction.
|
* first entry is the beginning of the 2nd instruction.
|
||||||
*/
|
*/
|
||||||
while (insn <= tb->icount && chunk_start < code_size) {
|
while (insn < tb->icount) {
|
||||||
size_t chunk_end = tcg_ctx->gen_insn_end_off[insn];
|
size_t chunk_end = tcg_ctx->gen_insn_end_off[insn];
|
||||||
if (chunk_end > chunk_start) {
|
if (chunk_end > chunk_start) {
|
||||||
g_string_printf(note, "[guest addr: " TARGET_FMT_lx "]",
|
qemu_log(" -- guest addr 0x" TARGET_FMT_lx "\n",
|
||||||
tcg_ctx->gen_insn_data[insn][0]);
|
tcg_ctx->gen_insn_data[insn][0]);
|
||||||
log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_start,
|
log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_start);
|
||||||
note->str);
|
|
||||||
chunk_start = chunk_end;
|
chunk_start = chunk_end;
|
||||||
}
|
}
|
||||||
insn++;
|
insn++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chunk_start < code_size) {
|
||||||
|
qemu_log(" -- tb slow paths + alignment\n");
|
||||||
|
log_disas(tb->tc.ptr + chunk_start, code_size - chunk_start);
|
||||||
|
}
|
||||||
|
|
||||||
/* Finally dump any data we may have after the block */
|
/* Finally dump any data we may have after the block */
|
||||||
if (data_size) {
|
if (data_size) {
|
||||||
int i;
|
int i;
|
||||||
|
29
disas.c
29
disas.c
@ -262,8 +262,7 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cap_dump_insn(disassemble_info *info, cs_insn *insn,
|
static void cap_dump_insn(disassemble_info *info, cs_insn *insn)
|
||||||
const char *note)
|
|
||||||
{
|
{
|
||||||
fprintf_function print = info->fprintf_func;
|
fprintf_function print = info->fprintf_func;
|
||||||
int i, n, split;
|
int i, n, split;
|
||||||
@ -284,11 +283,7 @@ static void cap_dump_insn(disassemble_info *info, cs_insn *insn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Print the actual instruction. */
|
/* Print the actual instruction. */
|
||||||
print(info->stream, " %-8s %s", insn->mnemonic, insn->op_str);
|
print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str);
|
||||||
if (note) {
|
|
||||||
print(info->stream, "\t\t%s", note);
|
|
||||||
}
|
|
||||||
print(info->stream, "\n");
|
|
||||||
|
|
||||||
/* Dump any remaining part of the insn on subsequent lines. */
|
/* Dump any remaining part of the insn on subsequent lines. */
|
||||||
for (i = split; i < n; i += split) {
|
for (i = split; i < n; i += split) {
|
||||||
@ -320,7 +315,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
|
|||||||
size -= tsize;
|
size -= tsize;
|
||||||
|
|
||||||
while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
|
while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
|
||||||
cap_dump_insn(info, insn, NULL);
|
cap_dump_insn(info, insn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the target memory is not consumed, go back for more... */
|
/* If the target memory is not consumed, go back for more... */
|
||||||
@ -349,8 +344,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Disassemble SIZE bytes at CODE for the host. */
|
/* Disassemble SIZE bytes at CODE for the host. */
|
||||||
static bool cap_disas_host(disassemble_info *info, void *code, size_t size,
|
static bool cap_disas_host(disassemble_info *info, void *code, size_t size)
|
||||||
const char *note)
|
|
||||||
{
|
{
|
||||||
csh handle;
|
csh handle;
|
||||||
const uint8_t *cbuf;
|
const uint8_t *cbuf;
|
||||||
@ -366,8 +360,7 @@ static bool cap_disas_host(disassemble_info *info, void *code, size_t size,
|
|||||||
pc = (uintptr_t)code;
|
pc = (uintptr_t)code;
|
||||||
|
|
||||||
while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) {
|
while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) {
|
||||||
cap_dump_insn(info, insn, note);
|
cap_dump_insn(info, insn);
|
||||||
note = NULL;
|
|
||||||
}
|
}
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
(*info->fprintf_func)(info->stream,
|
(*info->fprintf_func)(info->stream,
|
||||||
@ -411,7 +404,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
|
|||||||
csize += tsize;
|
csize += tsize;
|
||||||
|
|
||||||
if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
|
if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
|
||||||
cap_dump_insn(info, insn, NULL);
|
cap_dump_insn(info, insn);
|
||||||
if (--count <= 0) {
|
if (--count <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -425,7 +418,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
|
|||||||
#endif /* !CONFIG_USER_ONLY */
|
#endif /* !CONFIG_USER_ONLY */
|
||||||
#else
|
#else
|
||||||
# define cap_disas_target(i, p, s) false
|
# define cap_disas_target(i, p, s) false
|
||||||
# define cap_disas_host(i, p, s, n) false
|
# define cap_disas_host(i, p, s) false
|
||||||
# define cap_disas_monitor(i, p, c) false
|
# define cap_disas_monitor(i, p, c) false
|
||||||
# define cap_disas_plugin(i, p, c) false
|
# define cap_disas_plugin(i, p, c) false
|
||||||
#endif /* CONFIG_CAPSTONE */
|
#endif /* CONFIG_CAPSTONE */
|
||||||
@ -595,7 +588,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Disassemble this for me please... (debugging). */
|
/* Disassemble this for me please... (debugging). */
|
||||||
void disas(FILE *out, void *code, unsigned long size, const char *note)
|
void disas(FILE *out, void *code, unsigned long size)
|
||||||
{
|
{
|
||||||
uintptr_t pc;
|
uintptr_t pc;
|
||||||
int count;
|
int count;
|
||||||
@ -673,7 +666,7 @@ void disas(FILE *out, void *code, unsigned long size, const char *note)
|
|||||||
print_insn = print_insn_hppa;
|
print_insn = print_insn_hppa;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size, note)) {
|
if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,10 +676,6 @@ void disas(FILE *out, void *code, unsigned long size, const char *note)
|
|||||||
for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) {
|
for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) {
|
||||||
fprintf(out, "0x%08" PRIxPTR ": ", pc);
|
fprintf(out, "0x%08" PRIxPTR ": ", pc);
|
||||||
count = print_insn(pc, &s.info);
|
count = print_insn(pc, &s.info);
|
||||||
if (note) {
|
|
||||||
fprintf(out, "\t\t%s", note);
|
|
||||||
note = NULL;
|
|
||||||
}
|
|
||||||
fprintf(out, "\n");
|
fprintf(out, "\n");
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|
||||||
/* Disassemble this for me please... (debugging). */
|
/* Disassemble this for me please... (debugging). */
|
||||||
void disas(FILE *out, void *code, unsigned long size, const char *note);
|
void disas(FILE *out, void *code, unsigned long size);
|
||||||
void target_disas(FILE *out, CPUState *cpu, target_ulong code,
|
void target_disas(FILE *out, CPUState *cpu, target_ulong code,
|
||||||
target_ulong size);
|
target_ulong size);
|
||||||
|
|
||||||
|
@ -56,13 +56,13 @@ static inline void log_target_disas(CPUState *cpu, target_ulong start,
|
|||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void log_disas(void *code, unsigned long size, const char *note)
|
static inline void log_disas(void *code, unsigned long size)
|
||||||
{
|
{
|
||||||
QemuLogFile *logfile;
|
QemuLogFile *logfile;
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
logfile = qatomic_rcu_read(&qemu_logfile);
|
logfile = qatomic_rcu_read(&qemu_logfile);
|
||||||
if (logfile) {
|
if (logfile) {
|
||||||
disas(logfile->fd, code, size, note);
|
disas(logfile->fd, code, size);
|
||||||
}
|
}
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
|
@ -1101,7 +1101,7 @@ void tcg_prologue_init(TCGContext *s)
|
|||||||
size_t data_size = prologue_size - code_size;
|
size_t data_size = prologue_size - code_size;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
log_disas(buf0, code_size, NULL);
|
log_disas(buf0, code_size);
|
||||||
|
|
||||||
for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) {
|
for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) {
|
||||||
if (sizeof(tcg_target_ulong) == 8) {
|
if (sizeof(tcg_target_ulong) == 8) {
|
||||||
@ -1115,7 +1115,7 @@ void tcg_prologue_init(TCGContext *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_disas(buf0, prologue_size, NULL);
|
log_disas(buf0, prologue_size);
|
||||||
}
|
}
|
||||||
qemu_log("\n");
|
qemu_log("\n");
|
||||||
qemu_log_flush();
|
qemu_log_flush();
|
||||||
|
Loading…
Reference in New Issue
Block a user