On 7/18/23 02:35, Matt Borgerson wrote:
If CF_PCREL is enabled, generated host assembly logging (command line
option `-d out_asm`) may incorrectly report guest instruction virtual
addresses as page offsets instead of absolute addresses. This patch
corrects the reported guest address.

Signed-off-by: Matt Borgerson <cont...@mborgerson.com>
---
  accel/tcg/translate-all.c | 22 ++++++++++++++++++++--
  1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index a1782db5dd..859db95cf7 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -283,6 +283,24 @@ static int setjmp_gen_code(CPUArchState *env, 
TranslationBlock *tb,
      return tcg_gen_code(tcg_ctx, tb, pc);
  }
+static vaddr get_guest_insn_vaddr(TranslationBlock *tb, vaddr pc, size_t insn)
+{
+    g_assert(insn < tb->icount);
+
+    /* FIXME: This replicates the restore_state_to_opc() logic. */
+    vaddr addr = tcg_ctx->gen_insn_data[insn * TARGET_INSN_START_WORDS];
+
+    if (tb_cflags(tb) & CF_PCREL) {
+        addr |= (pc & TARGET_PAGE_MASK);
+    } else {
+#if defined(TARGET_I386)
+        addr -= tb->cs_base;
+#endif
+    }

I disagree with this.  The only bug I see is

                      "  -- guest addr 0x%016" PRIx64 " + tb prologue\n",

"guest addr", which makes you believe this to be a guest virtual address.

I think it is important to log what is actually in the data structures, which is the page offset.

Why are you so keen to have the virtual address? Why is this more reasonable than the physical address, or anything else?


r~

Reply via email to