Improving TCG debug output
cover Improving TCG debug output
From: Alex Bennée <[email protected]>
Hi,
These two patches have been sitting in my personal tree for a while and I thought it was worth soliciting feedback as to their wider usefulness.
The first is simply an attempt to make tcg abort failures a little less terse.
The second I found useful when I was debugging a complex set of TCG ops for a round, shift and narrow implementation. The alternative was to set up GDB and step through the generated target code (or just infer from the copious dumps). The macro magic might be a bit much though.
Alex Bennée (2):
tcg: add tcg_abort_dbg() for additional debug info
tcg: add debug helpers tcg_debug_dump_i(32|64)
Makefile.target | 2 +- target-arm/helper.h | 2 ++ tcg/i386/tcg-target.c | 4 ++-- tcg/optimize.c | 2 +- tcg/tcg-helpers.c | 32 +++++++++++++++++++++++++++++ tcg/tcg-helpers.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg.h | 7 +++++-- 7 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 tcg/tcg-helpers.c create mode 100644 tcg/tcg-helpers.h
Signature · 1 line
1.9.0
PATCH 1/2 tcg: add tcg_abort_dbg() for additional debug info
From: Alex Bennée <[email protected]>
There are times the tcg aborts with a fatal but terse error which isn't overly helpful. This adds an alternative macro that can be used to show a little more helper information when an abort occurs.
tcg/i386/tcg-target.c +2 -2
@@ -1342,7 +1342,7 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) }break ;default : -tcg_abort (); +tcg_abort_dbg ("bad opc:%x" , opc); }/* Jump to the code corresponding to next IR of qemu_st */
@@ -1519,7 +1519,7 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, }break ;default : -tcg_abort (); +tcg_abort_dbg ("bad memop=%x" , memop); } }
tcg/optimize.c +1 -1
@@ -407,7 +407,7 @@ static bool do_constant_folding_cond_eq(TCGCond c)case TCG_COND_EQ :return 1 ;default : -tcg_abort (); +tcg_abort_dbg ("bad condition:%d" , c); } }
tcg/tcg.h +5 -2
@@ -657,12 +657,15 @@ typedef struct TCGTargetOpDef {const char *args_ct_str[TCG_MAX_OP_ARGS ]; } TCGTargetOpDef; -#define tcg_abort () \ +#define tcg_abort_dbg (fmt, ...)\ do {\ - fprintf(stderr, "%s:%d: tcg fatal error\n", __FILE__, __LINE__);\ + fprintf(stderr, "%s:%d: tcg fatal error " fmt "\n",\ + __FILE__, __LINE__, ## __VA_ARGS__);\ abort();\ } while (0) +#define tcg_abort () tcg_abort_dbg("") +#ifdef CONFIG_DEBUG_TCG # define tcg_debug_assert (X ) do { assert(X); } while (0)#elif QEMU_GNUC_PREREQ (4 ,5 )
Signature · 1 line
1.9.0
Re: [Qemu-devel] [RCF PATCH 1/2] tcg: add tcg_abort_dbg() for additional debug info
Quoted 33 lines · On 12 March 2014 14:12, <[email protected]> wrote:
From: Alex Bennée <[email protected]>
There are times the tcg aborts with a fatal but terse error which isn't overly helpful. This adds an alternative macro that can be used to show a little more helper information when an abort occurs.
tcg/i386/tcg-target.c +2
-2@@ -1342,7 +1342,7 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) }break ;default : -tcg_abort (); +tcg_abort_dbg ("bad opc:%x" , opc); }/* Jump to the code corresponding to next IR of qemu_st */ @@ -1519,7 +1519,7 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, }break ;default : -tcg_abort (); +tcg_abort_dbg ("bad memop=%x" , memop); } }tcg/optimize.c +0
-0
tcg/optimize.c static bool do_constant_folding_cond_eq(TCGCond c) · line 410
Quoted 5 lines
tcg/optimize.c +1
-1@@ -407,7 +407,7 @@ static bool do_constant_folding_cond_eq(TCGCond c)case TCG_COND_EQ :return 1 ;default : -tcg_abort (); +tcg_abort_dbg ("bad condition:%d" , c);
This is the wrong place to be diagnosing this. We should be (when TCG debug is enabled) checking the condition when the tcg_gen_setcond or tcg_set_brcond function is called, so that you get a useful backtrace that points directly at the buggy frontend code. I suspect the other two cases are similar.
thanks
-- PMM
Re: [Qemu-devel] [RCF PATCH 1/2] tcg: add tcg_abort_dbg() for additional debug info
Quoted 5 lines · Peter Maydell
This is the wrong place to be diagnosing this. We should be (when TCG debug is enabled) checking the condition when the
tcg_gen_setcondortcg_set_brcondfunction is called, so that you get a useful backtrace that points directly at the buggy frontend code. I suspect the other two cases are similar.
Indeed. See the asserts in tcg_gen_deposit_i32 for example.
r~
PATCH 2/2 tcg: add debug helpers tcg_debug_dump_i(32|64)
In reply to [email protected]From: Alex Bennée <[email protected]>
The helpers are useful for debugging if you want to inspect interim values of tcg temp variables while executing TCG generated code. This is an alternative to tracing with logs or inspecting with GDB.
The functions do take format strings but to prevent massive memory loss it will default to a constant string after a short number of uses.
create mode 100644 tcg/tcg-helpers.c create mode 100644 tcg/tcg-helpers.h
Makefile.target +1 -1
@@ -73,7 +73,7 @@ all: $(PROGS) stap ######################################################### # cpu emulator library obj-y = exec.o translate-all.o cpu-exec.o -obj-y += tcg/tcg.o tcg/optimize.o +obj-y += tcg/tcg.o tcg/optimize.o tcg/tcg-helpers.o obj-$(CONFIG_TCG_INTERPRETER) += tci.o obj-$(CONFIG_TCG_INTERPRETER) += disas/tci.o obj-y += fpu/softfloat.o
target-arm/helper.h +2 -0
@@ -507,4 +507,6 @@ DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)#include "helper-a64.h" #endif +#include "tcg/tcg-helpers.h" +#include "exec/def-helper.h"
tcg/tcg-helpers.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* TCG Common Helper Functions +* +* Copyright (c) 2014 +* Written by Alex Bennée <[email protected]> +* +* This code is licensed under the GNU GPL v2. +* +* This file contains common non-architecture specific helper +* functions that can be used from TCG generated code. Currently these +* are mainly helpful for debugging. +*/ + +#include <stdlib.h> +#include <stdio.h> + +#include "cpu.h" +#include "exec/exec-all.h" +#include "helper.h" + +/* TCG Value Dumpers */ +uint32_t HELPER (dump_u32 )(uint32_t val,void *string) +{ +fprintf (stderr,"%s %x\n" , (char *) string, val); +return val; +} + +uint64_t HELPER (dump_u64 )(uint64_t val,void *string) +{ +fprintf (stderr,"%s %lx\n" , (char *) string, val); +return val; +}
tcg/tcg-helpers.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
1.9.0