From: alex.bennee@linaro.org
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RCF PATCH 2/2] tcg: add debug helpers tcg_debug_dump_i(32|64)
Date: Wed, 12 Mar 2014 13:50:00 +0000 [thread overview]
Message-ID: <1394632200-15633-3-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1394632200-15633-1-git-send-email-alex.bennee@linaro.org>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=true, Size: 4956 bytes --]
From: Alex Bennée <alex.bennee@linaro.org>
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
diff --git a/Makefile.target b/Makefile.target
index ba12340..a87b7d7 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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
diff --git a/target-arm/helper.h b/target-arm/helper.h
index 8923f8a..7600c21 100644
--- a/target-arm/helper.h
+++ b/target-arm/helper.h
@@ -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"
diff --git a/tcg/tcg-helpers.c b/tcg/tcg-helpers.c
new file mode 100644
index 0000000..83bfee6
--- /dev/null
+++ b/tcg/tcg-helpers.c
@@ -0,0 +1,32 @@
+/*
+ * TCG Common Helper Functions
+ *
+ * Copyright (c) 2014
+ * Written by Alex Bennée <alex.bennee@linaro.org>
+ *
+ * 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;
+}
diff --git a/tcg/tcg-helpers.h b/tcg/tcg-helpers.h
new file mode 100644
index 0000000..510d8b5
--- /dev/null
+++ b/tcg/tcg-helpers.h
@@ -0,0 +1,57 @@
+/*
+ * TCG Common Helpers
+ *
+ * Copyright (c) 2014
+ * Written by Alex Bennée <alex.bennee@linaro.org>
+ *
+ * This code is licensed under the GNU GPL v2.
+ *
+ * WARNING: intended to be included in $ARCH/helper.h
+ */
+
+DEF_HELPER_2(dump_u32, i32, i32, ptr)
+DEF_HELPER_2(dump_u64, i64, i64, ptr)
+
+
+/*
+ * Formatting macros
+ *
+ * To be useful we would like to format a string with a message to be
+ * associated with this dump. As these strings have to live the
+ * lifetime of the generated code we are essentially leaking memory so
+ * the more times a given dump call is generated the more memory is
+ * consumed (not so for each time the TCG code itself is called)
+ */
+
+/* This limits the number of malloc'ed strings *per call site* */
+#define TCG_DEBUG_DUMP_MAX_STRINGS 10
+
+/* String macro magic */
+#define STRINGIFY_DETAIL(x) #x
+#define STRINGIFY(x) STRINGIFY_DETAIL(x)
+
+#define tcg_debug_dump_i32(tcg32, fmt, ...) \
+do { \
+ static int tcg_debug_alloc_strings = 0; \
+ gchar *debug_string = (gchar *) __FILE__ ":" STRINGIFY(__LINE__) ":"; \
+ TCGv_ptr tcg_string; \
+ if (tcg_debug_alloc_strings++ < TCG_DEBUG_DUMP_MAX_STRINGS) { \
+ debug_string = g_strdup_printf(fmt ":", ## __VA_ARGS__); \
+ } \
+ tcg_string = tcg_const_ptr(debug_string); \
+ gen_helper_dump_u32(tcg32, tcg32, tcg_string); \
+ tcg_temp_free_ptr(tcg_string); \
+} while (0);
+
+#define tcg_debug_dump_i64(tcg64, fmt, ...) \
+do { \
+ static int tcg_debug_alloc_strings = 0; \
+ gchar *debug_string = (gchar *) __FILE__ ":" STRINGIFY(__LINE__) ":"; \
+ TCGv_ptr tcg_string; \
+ if (tcg_debug_alloc_strings++ < TCG_DEBUG_DUMP_MAX_STRINGS) { \
+ debug_string = g_strdup_printf(fmt ":", ## __VA_ARGS__); \
+ } \
+ tcg_string = tcg_const_ptr(debug_string); \
+ gen_helper_dump_u64(tcg64, tcg64, tcg_string); \
+ tcg_temp_free_ptr(tcg_string); \
+} while (0);
--
1.9.0
next prev parent reply other threads:[~2014-03-12 13:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-12 13:49 [Qemu-devel] [RCF PATCH 0/2] Improving TCG debug output alex.bennee
2014-03-12 13:49 ` [Qemu-devel] [RCF PATCH 1/2] tcg: add tcg_abort_dbg() for additional debug info alex.bennee
2014-03-12 13:50 ` alex.bennee [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-03-12 14:12 [Qemu-devel] [RCF PATCH 0/2] Improving TCG debug output alex.bennee
2014-03-12 14:12 ` [Qemu-devel] [RCF PATCH 2/2] tcg: add debug helpers tcg_debug_dump_i(32|64) alex.bennee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394632200-15633-3-git-send-email-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).