diff mbox

[RCF,1/2] tcg: add tcg_abort_dbg() for additional debug info

Message ID 1394633577-18053-2-git-send-email-alex.bennee@linaro.org
State RFC
Headers show

Commit Message

Alex Bennée March 12, 2014, 2:12 p.m. UTC
From: Alex Bennée <alex.bennee@linaro.org>

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.

Comments

Peter Maydell March 12, 2014, 3:02 p.m. UTC | #1
On 12 March 2014 14:12,  <alex.bennee@linaro.org> wrote:
> From: Alex Bennée <alex.bennee@linaro.org>
>
> 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.
>
> diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
> index f832282..1a6c565 100644
> --- a/tcg/i386/tcg-target.c
> +++ b/tcg/i386/tcg-target.c
> @@ -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);
>      }
>  }
>
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index 7777743..ae1a3f8 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -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
Richard Henderson March 12, 2014, 3:05 p.m. UTC | #2
On 03/12/2014 08:02 AM, Peter Maydell wrote:
> 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.

Indeed.  See the asserts in tcg_gen_deposit_i32 for example.


r~
diff mbox

Patch

diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
index f832282..1a6c565 100644
--- a/tcg/i386/tcg-target.c
+++ b/tcg/i386/tcg-target.c
@@ -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);
     }
 }
 
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 7777743..ae1a3f8 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -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);
     }
 }
 
diff --git a/tcg/tcg.h b/tcg/tcg.h
index f7efcb4..bfde09f 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -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)