From patchwork Wed Mar 12 13:50:00 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: 26113 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 09E19236AC for ; Wed, 12 Mar 2014 13:50:59 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id e16sf24211978qcx.2 for ; Wed, 12 Mar 2014 06:50:59 -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: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=GdHdnaHIzTG6STha7ZlCDROrCMCd5Vt20TI6EauBY/slSgHUy6/+7e+PKon68u/JZb 05qqRgQqWwU01TggAxOfuR75pMQawddGEP2z/zDKfL0aP6hRlJ/7tG7Et/REHQi+bXmq MGgYQyG7ltjMoSje0cTIrfo2Jhuin8GXJSCUZITPcPy3VZbftqRcu89fxU+5THmQeIax n50KOqIrWVRhjW+1f/iuDrapkZVFOzG9+Odr4AKCs9XTHamYtB/bErfRorNq1aaf2G84 Sp6rx1whkHTeHoVkdQCs3eny9YLB6nm6jhc/OYC3if2C/+FoUcyo07ZI8Y6AvqMtLu+3 e1Ng== X-Gm-Message-State: ALoCoQlzQ2Mo7/zAs/1ghbPRTVstBTwr4qdi4M+W1236Qj4RmIQWj93kbrKAY4Jfb0AxVQUEV0xc X-Received: by 10.236.78.70 with SMTP id f46mr17359755yhe.19.1394632259768; Wed, 12 Mar 2014 06:50:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.169 with SMTP id j38ls2920677qgd.10.gmail; Wed, 12 Mar 2014 06:50:59 -0700 (PDT) X-Received: by 10.58.37.232 with SMTP id b8mr1077971vek.27.1394632259558; Wed, 12 Mar 2014 06:50:59 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id a15si6828542vew.83.2014.03.12.06.50.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Mar 2014 06:50:59 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 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.170; Received: by mail-vc0-f170.google.com with SMTP id hu19so573267vcb.1 for ; Wed, 12 Mar 2014 06:50:59 -0700 (PDT) X-Received: by 10.58.187.161 with SMTP id ft1mr124586vec.54.1394632259472; Wed, 12 Mar 2014 06:50:59 -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 i9csp290032vck; Wed, 12 Mar 2014 06:50:59 -0700 (PDT) X-Received: by 10.224.11.136 with SMTP id t8mr55480109qat.26.1394632258978; Wed, 12 Mar 2014 06:50:58 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v93si12933615qge.182.2014.03.12.06.50.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 12 Mar 2014 06:50:58 -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]:60700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNjYg-00032s-K1 for patch@linaro.org; Wed, 12 Mar 2014 09:50:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNjXn-0001uj-Kf for qemu-devel@nongnu.org; Wed, 12 Mar 2014 09:50:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNjXi-0004Wa-Rd for qemu-devel@nongnu.org; Wed, 12 Mar 2014 09:50:03 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:33503 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNjXi-0004WL-JA for qemu-devel@nongnu.org; Wed, 12 Mar 2014 09:49:58 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1WNjXw-00033k-5c for qemu-devel@nongnu.org; Wed, 12 Mar 2014 14:50:12 +0100 From: alex.bennee@linaro.org To: qemu-devel@nongnu.org Date: Wed, 12 Mar 2014 13:50:00 +0000 Message-Id: <1394632200-15633-3-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394632200-15633-1-git-send-email-alex.bennee@linaro.org> References: <1394632200-15633-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 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.170 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);