translate-all: include guest address in out_asm output
RFC PATCH 1/1 translate-all: include guest address in out_asm output
This is a slightly hackish Friday afternoon attempt to include the guest address in our out_asm output in an effort to make it a little easier to see what is generating what final assembly.
--- accel/tcg/translate-all.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)
accel/tcg/translate-all.c +32 -6
@@ -1789,14 +1789,42 @@ TranslationBlock *tb_gen_code(CPUState *cpu,if (qemu_loglevel_mask (CPU_LOG_TB_OUT_ASM ) &&qemu_log_in_addr_range (tb->pc)) {FILE *logfile =qemu_log_lock (); +size_t code_size, data_size =0 ; +size_t insn_start; +int insn =0 ;qemu_log ("OUT: [size=%d]\n" , gen_code_size);if (tcg_ctx->data_gen_ptr) { -size_t code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr; -size_t data_size = gen_code_size - code_size; -size_t i; + code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr; + data_size = gen_code_size - code_size; + }else { + code_size = gen_code_size; + } + +/* first dump prologue */ + insn_start = tcg_ctx->gen_insn_end_off[0 ]; +if (insn_start >0 ) { +qemu_log (" prologue: [size=%ld]\n" , insn_start); +log_disas (tb->tc.ptr, insn_start); + } + +do { +size_t insn_end; +if (insn < (tb->icount -1 )) { + insn_end = tcg_ctx->gen_insn_end_off[insn +1 ]; + }else { + insn_end = code_size; + } +qemu_log (" for guest addr: " TARGET_FMT_lx":\n" , + tcg_ctx->gen_insn_data[insn][0 ]); + +log_disas (tb->tc.ptr + insn_start, insn_end - insn_start); -log_disas (tb->tc.ptr, code_size); + insn_start = insn_end; + }while (++insn < tb->icount && insn_start < code_size); +if (data_size) { +int i; +qemu_log (" data: [size=%ld]\n" , data_size);for (i =0 ; i < data_size; i +=sizeof (tcg_target_ulong)) {if (sizeof (tcg_target_ulong) ==8 ) { qemu_log("0x%08" PRIxPTR ": .quad 0x%016" PRIx64 "\n",
@@ -1808,8 +1836,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, *(uint32_t *)(tcg_ctx->data_gen_ptr + i)); } } - }else { -log_disas (tb->tc.ptr, gen_code_size); }qemu_log ("\n" );qemu_log_flush ();
Signature · 1 line
2.20.1
Quoted 6 lines · Alex Bennée
accel/tcg/translate-all.c +6
-0+/* first dump prologue */ + insn_start = tcg_ctx->gen_insn_end_off[0 ]; +if (insn_start >0 ) { +qemu_log (" prologue: [size=%ld]\n" , insn_start); +log_disas (tb->tc.ptr, insn_start); + }
accel/tcg/translate-all.c TranslationBlock *tb_gen_code(CPUState *cpu, · line 1818
Quoted 10 lines
accel/tcg/translate-all.c +10
-0+ + do { + size_t insn_end; + if (insn < (tb->icount - 1)) { + insn_end = tcg_ctx->gen_insn_end_off[insn + 1]; + } else { + insn_end = code_size; + } + qemu_log(" for guest addr: " TARGET_FMT_lx ":\n", + tcg_ctx->gen_insn_data[insn][0]);
The one thing you're missing here is when a given guest insn emits no host insns. E.g. an actual guest nop, or if two guest insns are optimized together.
So you need to search forward through empty insns til you find one that has contents. E.g. the very first TB that alpha-softmmu executes in its bios:
OP after optimization and liveness analysis:
ld_i32 tmp0,env,$0xfffffffffffffff0 dead: 1 pref=0xffff movi_i32 tmp1,$0x0 pref=0xffff brcond_i32 tmp0,tmp1,lt,$L0 dead: 0 1
---- fffffc0000000000
---- fffffc0000000004
---- fffffc0000000008
movi_i64 gp,$0xfffffc0000012f50 sync: 0 pref=0xffff
OUT: [size=280]
prologue: [size=11]
0x7fffa0000100: 8b 5d f0 movl -0x10(%rbp), %ebx 0x7fffa0000103: 85 db testl %ebx, %ebx 0x7fffa0000105: 0f 8c d6 00 00 00 jl 0x7fffa00001e1 for guest addr: fffffc0000000000: for guest addr: fffffc0000000004: 0x7fffa000010b: 48 bb 50 2f 01 00 00 fc movabsq $0xfffffc0000012f50, %rbx 0x7fffa0000113: ff ff 0x7fffa0000115: 48 89 9d e8 00 00 00 movq %rbx, 0xe8(%rbp)
for guest addr: fffffc0000000008:
So you've attributed to ...04 what actually belongs to ...08.
But it's a good idea.
r~
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===
CC aarch64-softmmu/hw/arm/pxa2xx_pic.o
CC aarch64-softmmu/hw/arm/digic.o/tmp/qemu-test/src/accel/tcg/translate-all.c: In function 'tb_gen_code':/tmp/qemu-test/src/accel/tcg/translate-all.c:1806:43: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'size_t' {aka 'long long unsigned int'} [-Werror=format=]
qemu_log(" prologue: [size=%ld]\n", insn_start);
~~^ ~~~~~~~~~~
%lld
/tmp/qemu-test/src/accel/tcg/translate-all.c:1827:39: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'size_t' {aka 'long long unsigned int'} [-Werror=format=]
qemu_log(" data: [size=%ld]\n", data_size);
~~^ ~~~~~~~~~
%lldcc1: all warnings being treated as errors
make[1]: *** [/tmp/qemu-test/src/rules.mak:69: accel/tcg/translate-all.o] Error 1
make[1]: *** Waiting for unfinished jobs....
CC aarch64-softmmu/hw/arm/omap1.o
CC x86_64-softmmu/gdbstub-xml.o/tmp/qemu-test/src/accel/tcg/translate-all.c: In function 'tb_gen_code':/tmp/qemu-test/src/accel/tcg/translate-all.c:1806:43: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'size_t' {aka 'long long unsigned int'} [-Werror=format=]
qemu_log(" prologue: [size=%ld]\n", insn_start);
~~^ ~~~~~~~~~~
%lld
/tmp/qemu-test/src/accel/tcg/translate-all.c:1827:39: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'size_t' {aka 'long long unsigned int'} [-Werror=format=]
qemu_log(" data: [size=%ld]\n", data_size);
~~^ ~~~~~~~~~
%lldcc1: all warnings being treated as errors
make[1]: *** [/tmp/qemu-test/src/rules.mak:69: accel/tcg/translate-all.o] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:527: x86_64-softmmu/all] Error 2
make: *** Waiting for unfinished jobs....
make: *** [Makefile:527: aarch64-softmmu/all] Error 2
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>
sys.exit(main())
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=710671f8720441949df423784981c162', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-frsoowsh/src/docker-src.2020-04-24-16.07.10.20709:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=710671f8720441949df423784981c162
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-frsoowsh/src'
make: *** [docker-run-test-mingw@fedora] Error 2
real 2m52.582s
user 0m8.929s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]