From patchwork Wed Mar 12 14:12:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 26124 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EF957236AC for ; Wed, 12 Mar 2014 14:14:12 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf39213979iec.6 for ; Wed, 12 Mar 2014 07:14:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=6m15z5FKkN0vqwh9KcpshHMGr6qEwnyjaniaNs6Xcrw=; b=PWPU3+ZcXwCAn+AcAu3iVv6a0hqiJo3/mgZzVoLrqkwzOmO4zXWWkadTNjE3yv7uuW pcWCMvkHrUWM2MbTU47YBXQdWYLThJjBFtMpLq1J6oq/rPRgeGecgv82UXHgS+Fzsljk HV3SLxyqdZ0yAzoQUMgS4eWMN/hbWCIEZrxTF3XhakCNh8mTfi0SxvbMB3kAacE5XCD2 KqRvzOh3Jm3GIAWxk+0/W7qKB+INdMUBU7iYwE714kAXcuPhnxszQNEhxHPk5FF9DJAK koSW4F2wZZKDx7pw2LB+mn24YzzMv5E7XncT7fG5qPvqzANowqrBqpzuUROYsgeDIwfT QJSA== X-Gm-Message-State: ALoCoQnEsQ3ezJkbalm2m8WDHT9k/C7tQwKUuQd1mVKhXs57ed5ifTG5X9O29ewSWq6yQ+iVDxbi X-Received: by 10.43.126.2 with SMTP id gu2mr17718469icc.0.1394633652384; Wed, 12 Mar 2014 07:14:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.161 with SMTP id o30ls2975905qga.94.gmail; Wed, 12 Mar 2014 07:14:12 -0700 (PDT) X-Received: by 10.221.39.138 with SMTP id tm10mr32800949vcb.7.1394633652088; Wed, 12 Mar 2014 07:14:12 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id tz5si7505101vdc.124.2014.03.12.07.14.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Mar 2014 07:14:12 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id if17so7262292vcb.8 for ; Wed, 12 Mar 2014 07:14:12 -0700 (PDT) X-Received: by 10.220.109.1 with SMTP id h1mr32599815vcp.20.1394633652003; Wed, 12 Mar 2014 07:14:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp291599vck; Wed, 12 Mar 2014 07:14:11 -0700 (PDT) X-Received: by 10.140.101.101 with SMTP id t92mr1703125qge.115.1394633651598; Wed, 12 Mar 2014 07:14:11 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 4si13007773qat.18.2014.03.12.07.14.11 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 12 Mar 2014 07:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:60864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNjv9-0000ja-2E for patch@linaro.org; Wed, 12 Mar 2014 10:14:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNjuF-0008BZ-SY for qemu-devel@nongnu.org; Wed, 12 Mar 2014 10:13:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNjuA-0004TW-6h for qemu-devel@nongnu.org; Wed, 12 Mar 2014 10:13:15 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:33624 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNju9-0004TD-UT for qemu-devel@nongnu.org; Wed, 12 Mar 2014 10:13:10 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1WNjuN-0003E8-Fc; Wed, 12 Mar 2014 15:13:23 +0100 From: alex.bennee@linaro.org To: qemu-devel@nongnu.org Date: Wed, 12 Mar 2014 14:12:57 +0000 Message-Id: <1394633577-18053-3-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394633577-18053-1-git-send-email-alex.bennee@linaro.org> References: <1394633577-18053-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 88.198.71.155 Cc: Peter Maydell , =?UTF-8?q?=C3=81kos=20Kov=C3=A1cs?= , Fam Zheng , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Subject: [Qemu-devel] [RCF PATCH 2/2] tcg: add debug helpers tcg_debug_dump_i(32|64) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Alex Bennée 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 + * + * 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 +#include + +#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 + * + * 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);